📄 u_gwzl.pas
字号:
unit U_gwzl;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBTables, Grids, DBGrids, StdCtrls, Buttons;
type
Tfrm_gwzl = class(TForm)
GroupBox1: TGroupBox;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Label4: TLabel;
DBGrid1: TDBGrid;
tbl_gwzl: TTable;
tbl_zy: TTable;
tbl_gwlb: TTable;
DataSource1: TDataSource;
tbl_gwzlGWZLMC: TStringField;
tbl_gwzlGWZLXH: TSmallintField;
tbl_gwzlZYXH: TSmallintField;
tbl_gwzlzymc: TStringField;
tbl_gwzlzylbmc: TStringField;
tbl_gwzlGWLBXH: TSmallintField;
ComboBox3: TComboBox;
tbl_gwjblx: TTable;
tbl_gwzlGWJBLXXH: TSmallintField;
tbl_gwzlgwjblx: TStringField;
Label3: TLabel;
tbl_khdx: TTable;
Query1: TQuery;
btn_insert: TButton;
btn_delete: TButton;
btn_edit: TButton;
btn_save: TButton;
btn_cancel: TButton;
procedure FormCreate(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure ComboBox2Change(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure btn_insertClick(Sender: TObject);
procedure tbl_gwzlAfterScroll(DataSet: TDataSet);
procedure FormShow(Sender: TObject);
procedure btn_deleteClick(Sender: TObject);
procedure btn_closeClick(Sender: TObject);
procedure btn_editClick(Sender: TObject);
procedure btn_saveClick(Sender: TObject);
procedure btn_cancelClick(Sender: TObject);
private
{ Private declarations }
xh:integer;
appending:boolean;
public
{ Public declarations }
end;
var
frm_gwzl: Tfrm_gwzl;
implementation
{$R *.dfm}
procedure Tfrm_gwzl.FormCreate(Sender: TObject);
begin
tbl_zy.First;
while not tbl_zy.Eof do
begin
ComboBox1.Items.AddObject(tbl_zy.fieldbyname('zymc').AsString,TObject(tbl_zy.fieldbyname('zyxh').AsInteger));
tbl_zy.Next;
end;
tbl_gwjblx.First;
while not tbl_gwjblx.Eof do
begin
ComboBox3.Items.AddObject(tbl_gwjblx.fieldbyname('gwjblx').AsString,TObject(tbl_gwjblx.fieldbyname('gwjblxxh').AsInteger));
tbl_gwjblx.Next;
end;
ComboBox1.ItemIndex:=0;
ComboBox1Change(self);
end;
procedure Tfrm_gwzl.ComboBox1Change(Sender: TObject);
begin
ComboBox2.Clear;
tbl_gwlb.Filter:='zyxh='+inttostr(integer(ComboBox1.Items.Objects[ComboBox1.ItemIndex]));
tbl_gwlb.First;
while not tbl_gwlb.Eof do
begin
ComboBox2.Items.AddObject(tbl_gwlb.fieldbyname('gwlbmc').AsString,TObject(tbl_gwlb.fieldbyname('gwlbxh').AsInteger));
tbl_gwlb.Next;
end;
ComboBox3.Clear;
tbl_gwjblx.First;
while not tbl_gwjblx.Eof do
begin
ComboBox3.Items.AddObject(tbl_gwjblx.fieldbyname('gwjblx').AsString,TObject(tbl_gwjblx.fieldbyname('gwjblxxh').AsInteger));
tbl_gwjblx.Next;
end;
ComboBox3.ItemIndex:=0;
if ComboBox2.ItemIndex=-1 then
begin
ComboBox2.ItemIndex:=0;
ComboBox2Change(self);
end
else
tbl_gwzl.Filter:='zyxh='+inttostr(integer(ComboBox1.Items.Objects[ComboBox1.ItemIndex]));
end;
procedure Tfrm_gwzl.ComboBox2Change(Sender: TObject);
begin
ComboBox3.Clear;
if ComboBox2.Text='单兵' then
ComboBox3.Items.AddObject('单兵',TObject(1))
else
if ComboBox2.Text='技术军官' then
ComboBox3.Items.AddObject('技术军官',TObject(2))
else
ComboBox3.Items.AddObject('无级别',TObject(0));
ComboBox3.ItemIndex:=0;
tbl_gwzl.Filter:='zyxh='+inttostr(integer(ComboBox1.Items.Objects[ComboBox1.ItemIndex]))
+' and gwlbxh='+inttostr(integer(ComboBox2.Items.Objects[ComboBox2.ItemIndex]));
end;
procedure Tfrm_gwzl.FormClose(Sender: TObject; var Action: TCloseAction);
begin
tbl_gwzl.Close;
tbl_gwlb.Close;
tbl_zy.Close;
tbl_gwjblx.Close;
tbl_khdx.Close;
end;
procedure Tfrm_gwzl.btn_insertClick(Sender: TObject);
var
n,max,i:integer;
begin
n:=tbl_gwzl.RecordCount;
max:=0;
tbl_gwzl.First;
while not tbl_gwzl.Eof do
begin
if max<tbl_gwzl.fieldbyname('gwzlxh').AsInteger then max:=tbl_gwzl.fieldbyname('gwzlxh').AsInteger;
tbl_gwzl.Next;
end;
xh:=1;
if n<max then
begin
for i:=1 to max do
begin
if not tbl_gwzl.Locate('gwzlxh',i,[]) then
begin
xh:=i;
break;
end;
end;
end
else
xh:=n+1;
btn_insert.Enabled:=false;
btn_save.Enabled:=true;
btn_cancel.Enabled:=true;
appending:=true;
ComboBox3.ItemIndex:=0;
Edit1.SetFocus;
tbl_gwzl.Append;
end;
procedure Tfrm_gwzl.tbl_gwzlAfterScroll(DataSet: TDataSet);
var
i:integer;
begin
if appending then exit;
if tbl_gwzl.RecordCount=0 then
begin
Edit1.Text:='';
exit;
end;
Edit1.Text:=tbl_gwzl.fieldbyname('gwzlmc').AsString;
for i:=0 to ComboBox3.Items.Count-1 do
begin
if integer(ComboBox3.Items.Objects[i])=tbl_gwzl.FieldByName('gwjblxxh').AsInteger then
begin
ComboBox3.ItemIndex:=i;
break;
end;
end;
end;
procedure Tfrm_gwzl.FormShow(Sender: TObject);
begin
Edit1.SetFocus;
end;
procedure Tfrm_gwzl.btn_deleteClick(Sender: TObject);
var
s:string;
begin
if tbl_gwzl.RecordCount=0 then exit;
query1.SQL.Clear;
if ComboBox2.ItemIndex=-1 then
s:='delete from khdx where zyxh='+inttostr(integer(ComboBox1.Items.Objects[ComboBox1.ItemIndex]))+' and gwlbxh='+inttostr(integer(ComboBox2.Items.Objects[ComboBox2.ItemIndex]))+' and gwzlxh='+inttostr(tbl_gwzl.FieldByName('gwzlxh').AsInteger)
else
s:='delete from khdx where zyxh='+inttostr(integer(ComboBox1.Items.Objects[ComboBox1.ItemIndex]))+' and gwzlxh='+inttostr(tbl_gwzl.FieldByName('gwzlxh').AsInteger);
query1.SQL.Add(s);
query1.ExecSQL;
query1.Close;
tbl_gwzl.Delete;
end;
procedure Tfrm_gwzl.btn_closeClick(Sender: TObject);
begin
close;
end;
procedure Tfrm_gwzl.btn_editClick(Sender: TObject);
begin
if tbl_gwzl.RecordCount=0 then exit;
btn_edit.Enabled:=false;
btn_save.Enabled:=true;
btn_cancel.Enabled:=true;
tbl_gwzl.Edit;
Edit1.SetFocus;
end;
procedure Tfrm_gwzl.btn_saveClick(Sender: TObject);
var
n,lg:integer;
s,gw:string;
begin
s:=trim(Edit1.Text);
lg:=length(s);
if lg=0 then
begin
MessageBox(0,'岗位种类名称不能为空!','岗位种类',MB_OK+MB_ICONSTOP);
tbl_gwzl.EnableControls;
Edit1.SetFocus;
exit;
end
else
if lg>60 then
begin
MessageBox(0,'岗位种类名称不能超过30个汉字!','岗位种类',MB_OK+MB_ICONSTOP);
tbl_gwzl.EnableControls;
Edit1.SetFocus;
exit;
end;
if appending then
begin
if tbl_gwzl.Locate('gwzlmc',s,[loCaseInsensitive]) then
begin
MessageBox(0,'岗位种类名称重复!','岗位种类',MB_OK+MB_ICONSTOP);
tbl_gwzl.EnableControls;
Edit1.SetFocus;
exit;
end;
appending:=false;
tbl_gwzl.Append;
tbl_gwzl.FieldByName('gwzlxh').AsInteger:=xh;
tbl_gwzl.FieldByName('zyxh').AsInteger:=integer(ComboBox1.Items.Objects[ComboBox1.ItemIndex]);
if ComboBox2.ItemIndex=-1 then
tbl_gwzl.FieldByName('gwlbxh').AsInteger:=integer(ComboBox2.Items.Objects[ComboBox2.ItemIndex]);
end
else
tbl_gwzl.Edit;
tbl_gwzl.FieldByName('gwzlmc').AsString:=s;
tbl_gwzl.FieldByName('gwjblxxh').AsInteger:=integer(ComboBox3.Items.Objects[ComboBox3.ItemIndex]);
tbl_gwzl.Post;
query1.SQL.Clear;
if ComboBox2.ItemIndex=-1 then
query1.SQL.Add('delete from khdx where zyxh='+inttostr(integer(ComboBox1.Items.Objects[ComboBox1.ItemIndex]))+' and gwlbxh='+inttostr(integer(ComboBox2.Items.Objects[ComboBox2.ItemIndex]))+' and gwzlxh='+inttostr(tbl_gwzl.FieldByName('gwzlxh').AsInteger))
else
query1.SQL.Add('delete from khdx where zyxh='+inttostr(integer(ComboBox1.Items.Objects[ComboBox1.ItemIndex]))+' and gwzlxh='+inttostr(tbl_gwzl.FieldByName('gwzlxh').AsInteger));
query1.ExecSQL;
query1.Close;
n:=integer(ComboBox3.Items.Objects[ComboBox3.ItemIndex]);//级别类型序号
if n<>0 then//有级别
begin
//jb1
tbl_khdx.Append;
tbl_khdx.FieldByName('zyxh').AsInteger:=integer(ComboBox1.Items.Objects[ComboBox1.ItemIndex]);
if appending then
tbl_khdx.FieldByName('gwzlxh').AsInteger:=xh
else
tbl_khdx.FieldByName('gwzlxh').AsInteger:=tbl_gwzl.FieldByName('gwzlxh').AsInteger;
if ComboBox2.ItemIndex=-1 then
tbl_khdx.FieldByName('gwlbxh').AsInteger:=integer(ComboBox2.Items.Objects[ComboBox2.ItemIndex])
else
tbl_khdx.FieldByName('gwlbxh').AsInteger:=0;
tbl_khdx.FieldByName('gwjblxxh').AsInteger:=n;
tbl_gwjblx.Locate('gwjblxxh',n,[]);
if n=1 then //单兵
tbl_khdx.FieldByName('khdxmc').AsString:=s+'('+trim(tbl_gwjblx.fieldbyname('jb1').AsString)+')'
else
if n=2 then//技术军官
begin
if StrPos(pChar('技术军官'),pChar(s))<>nil then
begin
gw:=Copy(s,0,lg-8);
tbl_khdx.FieldByName('khdxmc').AsString:=gw+'('+trim(tbl_gwjblx.fieldbyname('jb1').AsString)+')';
end
else
tbl_khdx.FieldByName('khdxmc').AsString:=s+'('+trim(tbl_gwjblx.fieldbyname('jb1').AsString)+')';
end;
tbl_khdx.FieldByName('khdxxh').AsInteger:=1;
tbl_khdx.Post;
//jb2
tbl_khdx.Append;
tbl_khdx.FieldByName('zyxh').AsInteger:=integer(ComboBox1.Items.Objects[ComboBox1.ItemIndex]);
if appending then
tbl_khdx.FieldByName('gwzlxh').AsInteger:=xh
else
tbl_khdx.FieldByName('gwzlxh').AsInteger:=tbl_gwzl.FieldByName('gwzlxh').AsInteger;
if ComboBox2.ItemIndex=-1 then
tbl_khdx.FieldByName('gwlbxh').AsInteger:=integer(ComboBox2.Items.Objects[ComboBox2.ItemIndex])
else
tbl_khdx.FieldByName('gwlbxh').AsInteger:=0;
tbl_khdx.FieldByName('gwjblxxh').AsInteger:=n;
tbl_gwjblx.Locate('gwjblxxh',n,[]);
if n=1 then //单兵
tbl_khdx.FieldByName('khdxmc').AsString:=s+'('+trim(tbl_gwjblx.fieldbyname('jb2').AsString)+')'
else
if n=2 then//技术军官
begin
if StrPos(pChar('技术军官'),pChar(s))<>nil then
begin
gw:=Copy(s,0,lg-8);
tbl_khdx.FieldByName('khdxmc').AsString:=gw+'('+trim(tbl_gwjblx.fieldbyname('jb2').AsString)+')';
end
else
tbl_khdx.FieldByName('khdxmc').AsString:=s+'('+trim(tbl_gwjblx.fieldbyname('jb2').AsString)+')';
end;
tbl_khdx.FieldByName('khdxxh').AsInteger:=2;
tbl_khdx.Post;
//jb3
tbl_khdx.Append;
tbl_khdx.FieldByName('zyxh').AsInteger:=integer(ComboBox1.Items.Objects[ComboBox1.ItemIndex]);
if appending then
tbl_khdx.FieldByName('gwzlxh').AsInteger:=xh
else
tbl_khdx.FieldByName('gwzlxh').AsInteger:=tbl_gwzl.FieldByName('gwzlxh').AsInteger;
if ComboBox2.ItemIndex=-1 then
tbl_khdx.FieldByName('gwlbxh').AsInteger:=integer(ComboBox2.Items.Objects[ComboBox2.ItemIndex])
else
tbl_khdx.FieldByName('gwlbxh').AsInteger:=0;
tbl_khdx.FieldByName('gwjblxxh').AsInteger:=n;
tbl_gwjblx.Locate('gwjblxxh',n,[]);
if n=1 then //单兵
tbl_khdx.FieldByName('khdxmc').AsString:=s+'('+trim(tbl_gwjblx.fieldbyname('jb3').AsString)+')'
else
if n=2 then//技术军官
begin
if StrPos(pChar('技术军官'),pChar(s))<>nil then
begin
gw:=Copy(s,0,lg-8);
tbl_khdx.FieldByName('khdxmc').AsString:=gw+'('+trim(tbl_gwjblx.fieldbyname('jb3').AsString)+')';
end
else
tbl_khdx.FieldByName('khdxmc').AsString:=s+'('+trim(tbl_gwjblx.fieldbyname('jb3').AsString)+')';
end;
tbl_khdx.FieldByName('khdxxh').AsInteger:=3;
tbl_khdx.Post;
end
else//无级别
begin
tbl_khdx.Append;
tbl_khdx.FieldByName('zyxh').AsInteger:=integer(ComboBox1.Items.Objects[ComboBox1.ItemIndex]);
if appending then
tbl_khdx.FieldByName('gwzlxh').AsInteger:=xh
else
tbl_khdx.FieldByName('gwzlxh').AsInteger:=tbl_gwzl.FieldByName('gwzlxh').AsInteger;
if ComboBox2.ItemIndex=-1 then
tbl_khdx.FieldByName('gwlbxh').AsInteger:=integer(ComboBox2.Items.Objects[ComboBox2.ItemIndex])
else
tbl_khdx.FieldByName('gwlbxh').AsInteger:=0;
tbl_khdx.FieldByName('gwjblxxh').AsInteger:=n;
tbl_khdx.FieldByName('khdxmc').AsString:=s;
tbl_khdx.FieldByName('khdxxh').AsInteger:=1;
tbl_khdx.Post;
end;
btn_insert.Enabled:=true;
btn_edit.Enabled:=true;
btn_save.Enabled:=false;
btn_cancel.Enabled:=false;
Edit1.SetFocus;
tbl_gwzlAfterScroll(tbl_gwzl);
end;
procedure Tfrm_gwzl.btn_cancelClick(Sender: TObject);
begin
tbl_gwzl.Cancel;
btn_insert.Enabled:=true;
btn_edit.Enabled:=true;
btn_save.Enabled:=false;
btn_cancel.Enabled:=false;
appending:=false;
tbl_gwzlAfterScroll(tbl_gwzl);
Edit1.SetFocus;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -