📄 unperplan.pas
字号:
unit UnPerPlan;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, ComCtrls,AdoDb, DB, ExtCtrls, Menus;
type
T_itemData=record
a:array[0..12] of string;
end;
TPerPlan_frm = class(TForm)
ListView1: TListView;
DS: TDataSource;
PopupMenu1: TPopupMenu;
PopupMenu2: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
N8: TMenuItem;
N9: TMenuItem;
N10: TMenuItem;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Cbx_Specialty: TComboBox;
Cbx_Plan: TComboBox;
Button1: TButton;
Button3: TButton;
Button7: TButton;
Label4: TLabel;
ListView2: TListView;
N11: TMenuItem;
N12: TMenuItem;
N13: TMenuItem;
N14: TMenuItem;
Label6: TLabel;
N15: TMenuItem;
Button2: TButton;
Splitter1: TSplitter;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure Cbx_SpecialtyClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Cbx_PlanClick(Sender: TObject);
procedure ListView1DblClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button4Click(Sender: TObject);
procedure N6Click(Sender: TObject);
procedure N7Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure N9Click(Sender: TObject);
procedure N11Click(Sender: TObject);
procedure N12Click(Sender: TObject);
procedure N13Click(Sender: TObject);
procedure N14Click(Sender: TObject);
procedure N10Click(Sender: TObject);
procedure N15Click(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
AdoConPlan:TADOConnection;
AdoQPlan:TADOQuery;
item_data:T_itemData;
procedure FillDept();
procedure InitLv();
procedure SelectPlan();
procedure AddPerPlan(sMsrno:string);
public
{ Public declarations }
procedure FillMsr(sSql:String);
end;
var
PerPlan_frm: TPerPlan_frm;
implementation
uses Undm, UnFuntion, Math, USelMsr;
{$R *.dfm}
procedure TPerPlan_frm.FillDept;
var
adotmp:TADOQuery;
begin
Cbx_Specialty.Clear;
adotmp:=TADOQuery.Create(self);
try
with adotmp do
begin
Connection:=DM.AdoConn;
SQL.Text:='select * from T_dept order by deptno';
Open;
while not eof do
begin
Cbx_Specialty.Items.Add(fieldbyname('deptno').AsString+'-'+fieldbyname('deptname').AsString);
Next;
end;
Free;
end;
except
adotmp.Free;
end;
end;
procedure TPerPlan_frm.FormCreate(Sender: TObject);
begin
FillDept; Top:=0;Left:=8;Width:=998;Height:=610;
InitLv; //初始化表头
AdoConPlan:=TADOConnection.Create(self);
AdoQPlan:=TADOQuery.Create(self);
AdoQPlan.Connection:=AdoConPlan;
with AdoConPlan do
begin
ConnectionString:=Connstr;LoginPrompt:=False;
Connected:=True;
end;
{ with AdoQPlan do
begin
Connection:=AdoConPlan;
SQL.Text:='select * from T_perplan';
Prepared:=True;
Open;
end; }
end;
procedure TPerPlan_frm.Cbx_SpecialtyClick(Sender: TObject);
var
adotmp:TADOQuery;
begin
Cbx_Plan.Clear;
adotmp:=TADOQuery.Create(self);
try
with adotmp do
begin
Connection:=DM.AdoConn;
SQL.Text:='select distinct planNo from T_PerPlan where specialty='+quotedstr(copy(Cbx_Specialty.Text,1,pos('-',Cbx_Specialty.Text)-1))+' order by PlanNo';
Open;
while not eof do
begin
Cbx_Plan.Items.Add('DJ'+fieldbyname('PlanNo').AsString);
Next;
end;
Free;
end;
except
adotmp.Free;
end;
end;
procedure TPerPlan_frm.Button1Click(Sender: TObject);
var
tmpi:integer;
begin
with Cbx_Plan do
begin
if Cbx_Plan.Items.Count<=0 then
BEGIN Items.Add('DJ01');
EXIT;
END;
tmpi:=strtoint(copy(Items[Items.count-1],3,length(Items[Items.count-1])))+1;
Items.Add('DJ'+FormatMe(tmpi,2));
end;
end;
procedure TPerPlan_frm.Button3Click(Sender: TObject);
var
ado_tmp:TADOCommand;
tmpstr:string;
begin
ado_tmp:=TADOCommand.Create(self);
tmpstr:=Cbx_Plan.Text;
if tmpstr='' then exit;
with ado_tmp do begin
Try
Connection:=DM.AdoConn;
CommandText:='delete from T_perplan where specialty='+quotedstr(copy(Cbx_Specialty.Text,1,2))+' and PlanNo='+quotedstr(copy(Cbx_Plan.Text,3,4));
CommandType:=cmdUnknown;
Execute;
if Cbx_Plan.Items.Count>0 then
Cbx_Plan.Items.Delete(Cbx_Plan.ItemIndex);
Free;
ListView1.Clear;
if Cbx_Plan.Items.Count>0 then
begin
Cbx_Plan.ItemIndex:=0;
Cbx_PlanClick(nil);
end
else
Cbx_Plan.ItemIndex:=-1;
Cbx_Plan.Refresh;
Application.MessageBox(pchar(tmpstr+'计划删除成功!'),'',MB_OK+MB_ICONINFORMATION);
except
Cancel;
Free;
end;
end;
end;
procedure TPerPlan_frm.Cbx_PlanClick(Sender: TObject);
begin
Label4.Caption:='当前计划:'+Cbx_Plan.Text+' 计划总数:'+inttostr(Cbx_Plan.Items.Count);
SelectPlan;
end;
procedure TPerPlan_frm.InitLv;
//var
// lv:TListItem;
// Colu:TListColumn;
begin
Listview1.Items.Clear;
{ listview1.Columns.Clear;
colu:=ListView1.Columns.Add;
colu.Caption:='序号';colu.Width:=55;
colu:=ListView1.Columns.Add;
colu.Caption:='测点编号'; colu.Width:=80;
colu:=ListView1.Columns.Add;
colu.Caption:='测点名称'; colu.Width:=130;
colu:=ListView1.Columns.Add;
colu.Caption:='测量项目'; colu.Width:=80;
colu:=ListView1.Columns.Add;
colu.Caption:='机组名称';colu.Width:=90;
colu:=ListView1.Columns.Add;
colu.Caption:='设备名称';colu.Width:=180;
colu:=ListView1.Columns.Add;
colu.Caption:='下限报警值';colu.Width:=75;
colu:=ListView1.Columns.Add;
colu.Caption:='上限报警值'; colu.Width:=75;
colu:=ListView1.Columns.Add;
colu.Caption:='信息钮'; colu.Width:=120;
colu:=ListView1.Columns.Add;
colu.Caption:='点检日期'; colu.Width:=100; }
end;
procedure TPerPlan_frm.ListView1DblClick(Sender: TObject);
var
i,j,seli:integer;
begin
try
if (ListView1.SelCount<0) then exit;
except
end;
Screen.Cursor:=crHourGlass;
listview1.Items.BeginUpdate;
j:=ListView1.Items.Count-1;
seli:=ListView1.SelCount;
while seli>0 do
begin
if ListView1.Items[j].Selected then
begin
ListView1.Items[j].Delete;
seli:=seli-1;
end;
j:=j-1;
end;
listview1.Items.EndUpdate;
{这样可以提高效率
for i:=0 to ListView1.Items.Count-1 do
begin
ListView1.Items[I].Caption:='No.'+IntToStr(i+1);
Application.ProcessMessages;
end; }
Screen.Cursor:=crDefault;
end;
procedure TPerPlan_frm.Button2Click(Sender: TObject);
var
str1,str2:string;
lv:TListItem;
i:integer;
begin
if (Cbx_Specialty.Text='') or (Cbx_Plan.Text='') then
begin
Application.MessageBox('对不起,专业,管理计划不能为空!','',MB_OK+MB_ICONERROR);
exit;
end else begin
str1:=copy(Cbx_Specialty.Text,1,pos('-',Cbx_Specialty.Text)-1); //专业
str2:=copy(Cbx_Plan.Text,3,length(Cbx_Plan.Text));
end;
with AdoQPlan do begin
try
Screen.Cursor:=crHourGlass;
AdoConPlan.BeginTrans;
sql.Text:='delete from t_perplan where specialty='+quotedstr(str1)+' and PlanNo='+quotedstr(str2);
ExecSQL;
sql.Text:='select * from T_perplan';
Prepared:=True;
Open;
for I:=0 to ListView1.Items.Count-1 do
begin
Application.ProcessMessages;
Append;
FieldByName('msrNo').AsString:=ListView1.Items[i].SubItems[3];
FieldByName('specialty').AsString:=str1;
FieldByName('Planno').AsString:=str2;
FieldByName('Plansortid').AsInteger:=i+1;
FieldByName('PerDate').AsString:= ListView1.Items[i].SubItems[9] ;
UpdateRecord;
end;
Refresh;
//sql.Text:='select * from T_employee where No='+quotedstr(copy(Cbx_Name.Text,1,4));//edit1.Text:=sql.Text;
//Prepared:=True;
Close;
sql.Text:='update T_employee set planno='+quotedstr(copy(Cbx_Plan.Text,3,4))+' where deptno='+quotedstr(copy(Cbx_Specialty.Text,1,2));
ExecSQL; // edit1.Text:=edit1.Text + ' '+sql.Text;
sql.Text:='select * from T_perplan';
Prepared:=True;
Open;
AdoConPlan.CommitTrans;Screen.Cursor:=crDefault;
Application.MessageBox('计划保存成功!','',MB_OK+MB_ICONINFORMATION);
except
AdoQPlan.Cancel;Screen.Cursor:=crDefault;
AdoConPlan.RollbackTrans;
Application.MessageBox('对不起,保存错误!','',MB_OK+MB_ICONERROR);
end;
end;
end;
procedure TPerPlan_frm.SelectPlan;
var
str1,str2:string;
lv:TListItem;
i:integer;
ado_tmp:TADOQuery;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -