📄 unit_main.pas
字号:
else
tabsheetcount:=0; //没有页数应该exit
end;
setlength(tabsheet,tabsheetcount);
setlength(labelcaption,tabsheetcount);
setlength(editbox,tabsheetcount);
setlength(combobox,tabsheetcount);
setlength(maskedit,tabsheetcount);
setlength(checkbox,tabsheetcount);
setlength(memo,tabsheetcount);
setlength(updown,tabsheetcount);
for i:=1 to tabsheetcount do //根据页面来添加控件
begin
//====创建一个页标签
comboboxcount:=0;
editboxcount:=0;
tabsheet[i-1]:=TTabSheet.Create(PageControl1);
tabsheet[i-1].Visible:=true;
tabsheet[i-1].PageControl:=PageControl1;//pag;
tabsheet[i-1].Caption:=inttostr(i);
tabsheet[i-1].Font.size:=10;
itop:=tabsheet[i-1].Top;
ileft:=tabsheet[i-1].Left;
//找出相应页上的控件的个数
sqlstr:='select * from field_info where yn=''1'' and page='+inttostr(i);//'select * from field_info where yn=''1''';
with dm.ADOQuery1 do
begin
close;
sql.Clear;
sql.Add(sqlstr);
open;
labcount:=recordcount;
end;
sqlstr:='select page_name from page_def where page_no='+inttostr(i);//+' and field='+quotedstr(tmpname);
with dm.ADOQuery1 do
begin
close;
sql.Clear;
sql.Add(sqlstr);
open;
tabsheet[i-1].Caption:=fieldbyname('page_name').AsString;
end;
setlength(labelcaption[i-1],labcount);
setlength(editbox[i-1],labcount);//editboxcount);
setlength(combobox[i-1],labcount);//comboboxcount);
setlength(maskedit[i-1],labcount);
setlength(checkbox[i-1],labcount);
setlength(updown[i-1],labcount);
setlength(memo[i-1],labcount);
sqlstr:='select * from field_info where yn=''1'' and page='+inttostr(i)+' order by field';
with dm.ADOQuery3 do //内循环
begin
close;
sql.Clear;
sql.Add(sqlstr);
open;
first;
while not eof do //创建label,之后编辑框
begin
index:=fieldbyname('ord').AsInteger-1;
labelcaption[i-1][index]:=tlabel.Create(self);
labelcaption[i-1][index].Visible:=true;
tabsheet[i-1].InsertControl(labelcaption[i-1][index]);
labelcaption[i-1][index].Font.Size:=8;
labelcaption[i-1][index].Caption:=fieldbyname('lab_name').AsString;
labelcaption[i-1][index].Top:=strtoint(fieldbyname('x').asstring);//iTop+15;
labelcaption[i-1][index].Left:=strtoint(fieldbyname('y').asstring);//ileft;
labelcaption[i-1][index].WordWrap:=true;
labelcaption[i-1][index].Width:=100;
if (fieldbyname('type').AsString='E') OR (fieldbyname('type').AsString='UE') or (fieldbyname('type').AsString='N') then //UE表示任职单位,其不能让用户输入内容,必须从树状图中读出数据
begin
if index <=labCount then
begin
editbox[i-1][index]:=tedit.Create(self);
editbox[i-1][index].ReadOnly:=editflag;
editbox[i-1][index].Visible:=true;
tabsheet[i-1].InsertControl(editbox[i-1][index]);
editbox[i-1][index].OnKeyDown:= MyButtonOnClick;
if fieldbyname('type').AsString='UE' then
begin
editbox[i-1][index].ReadOnly:=true;
//editbox[i-1][index].OnEnter:=OnNotice;
end else
editbox[i-1][index].OnEnter:=OnEnter;
editbox[i-1][index].OnExit:=OnExit;
editbox[i-1][index].OnMouseDown:=mousedown;
editbox[i-1][index].Top:=strtoint(fieldbyname('compx').asstring);//labelcaption[i-1][index].Top;
editbox[i-1][index].Left:=strtoint(fieldbyname('compy').asstring);//labelcaption[i-1][index].Left+labelcaption[i-1][index].Width+10;
editbox[i-1][index].TabOrder:=taborder;
editbox[i-1][index].Font.Name:= '宋体';
if fieldbyname('notnull').AsVariant=true then
editbox[i-1][index].Color:=rgb(255,224,192);
if fieldbyname('type').AsString='N' then //为序号类型的控件
begin
updown[i-1][index]:=tupdown.create(self);
updown[i-1][index].Enabled:=comflag;
tabsheet[i-1].InsertControl(updown[i-1][index]);
updown[i-1][index].Visible:=true;
updown[i-1][index].Associate:=editbox[i-1][index];
end;
end
else
raise Exception.Create('EditBox创建出现错误!');
end;
if fieldbyname('type').AsString='B' then
begin
if index<=labcount then
begin
checkbox[i-1][index]:=tcheckbox.Create(self);
checkbox[i-1][index].Enabled:=comflag;
checkbox[i-1][index].Visible:=true;
tabsheet[i-1].InsertControl(checkbox[i-1][index]);
checkbox[i-1][index].OnKeyDown:= MyButtonOnClick;
checkbox[i-1][index].OnMouseDown:= mousedown;
checkbox[i-1][index].OnClick:=ckonchange;
checkbox[i-1][index].Top:=strtoint(fieldbyname('compx').asstring);//labelcaption[i-1][index].Top;
checkbox[i-1][index].Left:=strtoint(fieldbyname('compy').asstring);//labelcaption[i-1][index].Left+labelcaption[i-1][index].Width+10;
checkbox[i-1][index].TabOrder:=taborder;
end
else
raise Exception.Create('Checkbox创建出现错误!');
end;
if fieldbyname('type').AsString='D' then
begin
if index<=labcount then
begin
maskedit[i-1][index]:=tmaskedit.Create(self);
maskedit[i-1][index].ReadOnly:=editflag;//zhujx
maskedit[i-1][index].Enabled:=comflag;
maskedit[i-1][index].Visible:=true;
tabsheet[i-1].InsertControl(maskedit[i-1][index]);//maskedit[i-1][index]
maskedit[i-1][index].OnKeyDown:=MyButtonOnClick;
maskedit[i-1][index].OnEnter:=OnEnter;
maskedit[i-1][index].OnExit:=OnExit;
maskedit[i-1][index].OnClick:=onclick;
maskedit[i-1][index].Top:=strtoint(fieldbyname('compx').asstring);//labelcaption[i-1][index].Top;
maskedit[i-1][index].Left:=strtoint(fieldbyname('compy').asstring);//labelcaption[i-1][index].Left+labelcaption[i-1][index].Width+10;
maskedit[i-1][index].Width:=121;
maskedit[i-1][index].EditMask:='9999-99-99';
maskedit[i-1][index].TabOrder:=taborder;
if fieldbyname('notnull').AsVariant=true then
maskedit[i-1][index].Color:=rgb(255,224,192);
end
else
raise Exception.Create('MaskEdit创建出现错误!');
end;
if fieldbyname('type').AsString='M' then
begin
if index<=labcount then
begin
memo[i-1][index]:=tmemo.Create(self);
memo[i-1][index].ReadOnly:=editflag;//zhujx
memo[i-1][index].Visible:=true;
memo[i-1][index].ScrollBars:=ssBoth;
tabsheet[i-1].InsertControl(memo[i-1][index]);//maskedit[i-1][index]
memo[i-1][index].OnKeyDown:= MyButtonOnClick;
memo[i-1][index].OnEnter:=OnEnter;
memo[i-1][index].OnExit:=OnExit;
memo[i-1][index].OnMouseDown:= MouseDown;
memo[i-1][index].Top:=strtoint(fieldbyname('compx').asstring);//labelcaption[i-1][index].Top;
memo[i-1][index].Left:=strtoint(fieldbyname('compy').asstring);//labelcaption[i-1][index].Left+labelcaption[i-1][index].Width+10;
//memo[i-1][index].ScrollBars:=ssvertical;
memo[i-1][index].Font.Name:= '宋体';
memo[i-1][index].Width:=350;
memo[i-1][index].Height:=120;
memo[i-1][index].TabOrder:=taborder;
if fieldbyname('notnull').AsVariant=true then
memo[i-1][index].Color:=rgb(255,224,192);
end
else
raise Exception.Create('Mmemo创建出现错误!');
end;
if (fieldbyname('type').AsString='C') then
begin
if index<=labcount then
begin
combobox[i-1][index]:=tcombobox.Create(self);
combobox[i-1][index].Enabled:=comflag;//zhujx
combobox[i-1][index].Visible:=true;
tabsheet[i-1].InsertControl(combobox[i-1][index]);
combobox[i-1][index].OnKeyDown:=MyButtonOnClick;
combobox[i-1][index].OnClick:=onclick;
combobox[i-1][index].OnChange:=cbonchange;
combobox[i-1][index].Width:=121;
combobox[i-1][index].TabOrder:=taborder;
combobox[i-1][index].Font.Name:='宋体';
combobox[i-1][index].Top:=strtoint(fieldbyname('compx').asstring);//labelcaption[i-1][index].Top;
combobox[i-1][index].Left:=strtoint(fieldbyname('compy').asstring);//labelcaption[i-1][index].Left+labelcaption[i-1][index].Width+10;
if fieldbyname('notnull').AsVariant =true then
combobox[i-1][index].Color:=rgb(255,224,192);
fieldname:=fieldbyname('field').AsString;
if fieldbyname('lab_name').AsString='民族' then
fieldname:='a0104';
if fieldbyname('lab_name').AsString='拟任单位' then
begin
sqltmp:='select dept from b01';
tmpfield:='dept';// where field_name
end
else
begin
sqltmp:='select code from code where field_name='+quotedstr(fieldname);
tmpfield:='code';
end;
with dm.ADOQuery2 do
begin
close;
sql.Clear;
sql.Add(sqltmp);
open;
first;
while not eof do
begin
combobox[i-1][index].AddItem(dm.ADOQuery2.FieldValues[tmpfield],combobox[i-1][index]);
next;
end;
end;
end
else
raise Exception.Create('comboboxBox创建出现错误!');
end;
taborder:=taborder+1;
itop:=itop+30;
if itop>(tabsheet[i-1].Height+tabsheet[i-1].Top+50) then
begin
itop:=tabsheet[i-1].Top+10;
ileft:=ileft+220;
end;
next;
tabsheet[i-1].Update;
end; // while not eof do的结束
PageControl1.ActivePage:=tabsheet[2];
PageControl1.ActivePage:=tabsheet[0];
end;
end;
end;
///////////////////////////////////////////////
procedure Tfrm_main.OnEnter(sender:TObject);
begin
if sender is tedit then
if (sender as tedit).Modified then
begin
is_mod:=true;
(sender as tedit).Modified:=false;
end;
if sender is tmaskedit then
if (sender as tmaskedit).Modified then
begin
is_mod:=true;
(sender as tmaskedit).Modified:=false;
end;
if sender is tmemo then
if (sender as tmemo).Modified then
begin
is_mod:=true;
(sender as tmemo).Modified:=false;
end;
end;
//////////////////////////////////////////////
procedure Tfrm_main.FormCreate(Sender: TObject); //776,483
begin
ComposeCreate(true,false);
//=============================================
// CreateSubMenu(true,N_Single);
// CreateSubMenu(false,N_MC);
end;
procedure Tfrm_main.N_2_newClick(Sender: TObject);//新增人员,数据库中添加记录
var
sqlstr:string;
index:integer;
DefPath:string;
prescode:string;// addperscode
maxpres:integer;
tempcode:string;
i:integer;
begin
///////////////////2006-03//////////////////////////////////////////////////
ChangeComposeState(false,true);//组建内容可修改
///////////////////////////////////////////////////////////////////////////
with frame61 do
begin
for i:=0 to TreeView1.Items.Count-1 do
begin
if treeview1.Items[i].Selected then
begin
Company_name:=treeview1.Selected.Text;
Company_code:=PMyRec(treeview1.Selected.Data)^.dm;
break;
end;
end;
end;
apppath:=ExtractFilePath(Application.ExeName); //照片刷新
DefPath:=AppPath+'defaultbmp.bmp';
image1.picture.loadfromfile(defpath);
n_2_save.Enabled:=true;
tbn_saveall.Enabled:=true;
n_2_del.Enabled:=true;
tbn_delall.Enabled:=true;
tbn_delzxx.Enabled:=true;
tbn_mod.Enabled:=false;
if is_addnew and (is_save=false ) then
begin
if application.MessageBox('还未保存当前增加的基本信息,是否要保存','注意!',MB_OKCANCEL+ mb_iconexclamation)=IDOK then
begin
N_2_saveClick(Sender);//(Sender);
exit; //回到浏览状态
end else
begin
///////////////////2006-03//////////////////////////////////////////////////
ChangeComposeState(true,false);//组建内容不可修改
///////////////////////////////////////////////////////////////////////////
DelAllTable;
addstate:=false;
is_addnew:=false;
gencode:='';
pagecontrol1.ActivePageIndex:=0;
is_mult:=false;
end;
end;
if is_update then
begin
if Application.Messagebox('你还未保存修改信息,是否终止当前新增人员操作!','注意!',MB_OKCANCEL+ mb_iconexclamation)=IDOK then
exit;
end;
pagecontrol1.ActivePageIndex:=0;
is_mult:=false;
groupbox1.Visible:=true;
b_add.Visible:=true;
b_del.Visible:=true;
stringgrid1.Visible:=false;
is_update:=false;
is_save:=false;
addstate:=true;
upstate:=false;
is_addnew:=true;
is_csadd:=false;
unit3.ClearAllComp;
gencode:='';
end;
procedure Tfrm_main.N_2_saveClick(Sender: TObject); //保存当前激活页得信息
var
values:string;
table_name,field:string;
code:string;
i,j:integer;
sqlstr:string;
tabsheetnum:integer;
index:integer;
tmpyear,tmpmonth:integer;
Year,Month,Day:word;
temp:string;
fieldstr,valuestr:string;
companycode:string;
begin
companycode:='';
if unit3.Checkfield=true then
exit;
if is_csadd=false then //保存新增人员信息和从属信息
begin
if Application.Messagebox('确定要保存当前页的成员信息!','注意!',MB_OKCANCEL+ mb_iconexclamation)=IDOK then
begin
///////////////////2006-03/////////////////////////////////////////////////////
//if addstate then
// code:=addperscode;//根据addperscode作为导入数据库的标签
if upstate then
code:=upperscode;
code:=gencode;//##############3
i:=PageControl1.ActivePageIndex+1;
tabsheetnum:=PageControl1.ActivePageIndex+1;
//************************************8
if unit3.SaveRecord(tabsheetnum,code) then
begin
is_addnew:=false;
is_update:=false;
is_mod:=false;
addstate:=false;
upstate:=false;
is_save:=true;
is_csadd:=false;
is_mod:=false;
if (PageControl1.ActivePageIndex=0) or (PageControl1.ActivePageIndex=1) then //只有第一页保存的时候才更新工作单位和人员列表
begin
//@@@@@@@@@@20053.11屏蔽 unit3.Updatelistbox(listbox1,listbox2); //$$$$$$$$$$$$$$$$$$$
unit3.Updatelistbox(prescodelist,listbox2);
end;
end;
end;//if application结束
end
else
begin
if Application.Messagebox('确定要保存当前新增从属子信息!','注意!',MB_OKCANCEL+ mb_iconexclamation)=IDOK then
begin
code:=gencode;
i:=PageControl1.ActivePageIndex;
sqlstr:='select * from field_info where yn=''1'' and page='+inttostr(pagecontrol1.ActivePageindex+1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -