sz_ajlbs.~pas
资源名称:挡案管理系统.rar [点击查看]
上传用户:szruida
上传日期:2007-06-01
资源大小:6518k
文件大小:18k
源码类别:
Delphi控件源码
开发平台:
Delphi
- unit sz_ajlbs;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, Menus, ActnList, DB, XPBarMenu, Grids, DBGridEh, StdCtrls, Mask,
- DBCtrls, ComCtrls, ExtCtrls, ToolWin, DBCtrlsEh,
- DBLookupEh, DBClient;
- type
- Tsz_ajlb = class(TForm)
- CoolBar1: TCoolBar;
- ToolBar1: TToolBar;
- add1: TToolButton;
- xiugai: TToolButton;
- dele1: TToolButton;
- save1: TToolButton;
- Refresh1: TToolButton;
- ToolButton3: TToolButton;
- Panel1: TPanel;
- Splitter1: TSplitter;
- Panel2: TPanel;
- Tree: TTreeView;
- Panel3: TPanel;
- Splitter2: TSplitter;
- Panel4: TPanel;
- Label8: TLabel;
- Label9: TLabel;
- Label10: TLabel;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- Edit1: TEdit;
- Panel5: TPanel;
- GroupBox2: TGroupBox;
- DBGridEh1: TDBGridEh;
- XPBarMenu1: TXPBarMenu;
- ActionList1: TActionList;
- Add: TAction;
- Edit: TAction;
- Delete: TAction;
- Save: TAction;
- Refresh: TAction;
- Print: TAction;
- Quit: TAction;
- PopupMenu1: TPopupMenu;
- A1: TMenuItem;
- D1: TMenuItem;
- E1: TMenuItem;
- N5: TMenuItem;
- N6: TMenuItem;
- Label5: TLabel;
- ajlb: TDataSource;
- Label6: TLabel;
- sz_qz: TDataSource;
- sz_xtajlb: TDataSource;
- DBEdit1: TDBEdit;
- DBEdit2: TDBEdit;
- DBEdit3: TDBEdit;
- DBEdit4: TDBEdit;
- DBLookupComboBox1: TDBLookupComboBox;
- procedure QuitExecute(Sender: TObject);
- procedure N5Click(Sender: TObject);
- procedure N6Click(Sender: TObject);
- procedure AddExecute(Sender: TObject);
- procedure EditExecute(Sender: TObject);
- procedure DeleteExecute(Sender: TObject);
- procedure SaveExecute(Sender: TObject);
- procedure RefreshExecute(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure TreeClick(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure DBEdit1KeyPress(Sender: TObject; var Key: Char);
- procedure DBEdit2KeyPress(Sender: TObject; var Key: Char);
- procedure DBGridEh1CellClick(Column: TColumnEh);
- procedure TreeChange(Sender: TObject; Node: TTreeNode);
- private
- { Private declarations }
- public
- { Public declarations }
- procedure BtnState();//增,改时的按钮变化
- procedure SaveData(TreeView:TtreeView;dbedit1,dbedit2,dbedit4:Tdbedit);//保存数据
- procedure loadTree1(treeDb1,treeDb2:TClientDataSet);//初始化树
- end;
- var
- sz_ajlb: Tsz_ajlb;
- gnode:TtreeNode;//当前节点
- lbjs_sm1,lbjs_sm2:string;//类别级数
- lb_dmgz1,lb_dmgz2:string;//代码规则
- dsState:string;//增删改的状态
- implementation
- uses dms,u_public;
- {$R *.dfm}
- procedure Tsz_ajlb.BtnState();
- begin
- if add1.Enabled=true or xiugai.Enabled=true then
- begin
- add1.Enabled:=false;A1.Enabled:=false;
- xiugai.Enabled:=false;E1.Enabled:=false;
- dele1.Enabled:=false;D1.Enabled:=false;
- save1.Enabled:=true;
- //refresh1.Enabled:=false;
- end
- else
- begin
- add1.Enabled:=true;A1.Enabled:=true;
- xiugai.Enabled:=true;E1.Enabled:=true;
- dele1.Enabled:=true;D1.Enabled:=true;
- save1.Enabled:=false;
- refresh1.Enabled:=true;
- end;
- end;
- //***********************************************
- procedure Tsz_ajlb.SaveData(TreeView:TtreeView;dbedit1,dbedit2,dbedit4:Tdbedit);//保存数据
- var
- curnode:TTreenode;//已选树节点
- s_xtdm,Pnodetxt,Pnodetxt2,nodetxt:string;//Pnodetxt:取出树上级节点节点的代码;nodetxt:要在树节点上增加的值
- n,n_xtdm:integer;//取出'-'在已选树节点中的位置
- s_dm:string;
- begin
- dm.sz_ajlb.edit;
- n:=pos('-',TreeView.Selected.Text)-1;
- Pnodetxt:=copy(TreeView.Selected.Text,1,n);
- //查找当前节点
- n_xtdm:=StrToInt(copy(lbjs_sm2,1,1));
- s_xtdm:=copy(tree.Selected.Text,1,n_xtdm);
- nodetxt:=Pnodetxt+dbedit1.Text+'-'+dbedit2.Text;//现在节点等于原来的加上现在的
- s_dm:=PnodeTxt+dbedit1.Text;
- //增加数据到节点
- dm.sz_ajlb.FieldByName('ajlb_dm').AsString:=s_dm;
- //dm.sz_ajlb.FieldByName('ajlb_mc').AsString:=dbedit2.Text;
- dm.sz_ajlb.FieldByName('ajlb_js').AsInteger:=tree.Selected.Level;
- //dm.sz_ajlb.FieldByName('ajlb_sm').AsString:=dbEdit4.Text;
- dm.sz_ajlb.FieldByName('ajlb_sjlbdm').AsString:=Pnodetxt;
- dm.sz_ajlb.FieldByName('qz_dm').AsString:=s_xtdm;//将一级表的代码赋给二级表
- //dm.sz_ajlb.FieldByName('xt_dm').AsString:=dbLookupcomboboxeh1.DataField;
- //给数组赋值
- dm.sz_ajlb.ApplyUpdates(0);
- if dm.sz_ajlb.ApplyUpdates(0)=0 then
- begin
- application.MessageBox('数据保存成功','提示',mb_ok+mb_iconinformation);
- curnode:=TreeView.Items.AddChild(tree.Selected,nodetxt);//增加新的节点
- curnode.ImageIndex:=0;
- curnode.SelectedIndex:=1;
- //-------按钮状态
- end
- else
- application.MessageBox('数据保存失败','提示',mb_ok+mb_iconinformation);
- end;
- //**************************************************
- procedure Tsz_ajlb.loadTree1(treeDb1,treeDb2:TClientDataSet);//初始化树
- var
- nodeId1,nodeTxt1,nodeId2,nodeTxt2:string;
- SCodeFormat1,SCodeFormat2,SFirstNodeTxt:string;
- level1,level2:integer;
- mynode:array[0..6] of Ttreenode;
- i,j:integer;//循环标志
- begin
- //初始化变量
- SCodeFormat1:=lbjs_sm1 ;//系统案卷类别代码结构
- SCodeFormat2:=lbjs_sm2;//文件类别代码结构
- SFirstNodeTxt:= '案卷类别';//首节点显示的文字
- Screen.Cursor:=crHourGlass;
- Tree.enabled:=true;
- Tree.Items.Clear;
- level1:=0;
- //设置根节点
- mynode[level1]:=Tree.Items.Add(Tree.TopItem,SFirstNodeTxt);
- mynode[level1].ImageIndex:=0;
- mynode[level1].SelectedIndex:=1;
- //遍历数据表,利用编码字段记录排序规律,依次添加树节点
- for i:=0 to treedb1.RecordCount-1 do
- begin
- nodeId1:=trim(treedb1.fieldbyname('qz_dm').AsString);
- nodeTxt1:=nodeId1+'-'+trim(treedb1.fieldbyname('qz_mc').AsString);
- level1:=GetNodeLevel(SCodeFormat1,nodeId1);//获得节点层树
- if level1>0 then
- begin
- mynode[level1]:=tree.Items.AddChild(mynode[level1-1],nodeTxt1);
- mynode[level1].ImageIndex:=0;
- mynode[level1].SelectedIndex:=1;
- //----------
- end;
- //增加第一层主表
- treedb2.close;
- treedb2.commandtext:='select * from sz_ajlb where qz_dm='+''''+nodeId1+''''+'';
- treedb2.open;
- if trim(treedb2.FieldByName('qz_dm').AsString)<>'' then
- begin
- for j:=0 to treedb2.recordcount-1 do
- begin
- nodeId2:=trim(treedb2.fieldbyname('ajlb_dm').asstring);
- nodeTxt2:=NodeId2+'-'+trim(treedb2.fieldbyname('ajlb_mc').asstring);
- level2:=getNodeLevel(SCodeFormat2,nodeId2);//从表的层数
- if level2>1 then
- begin
- mynode[level2]:=tree.Items.AddChild(mynode[level2-1],nodeTxt2);
- mynode[level2].ImageIndex:=0;
- mynode[level2].SelectedIndex:=1;
- end;
- treedb2.Next;
- end;
- end
- else
- treedb2.Next;//不是符合条件的纪录
- treedb1.Next;//下一条纪录
- end;//end for
- mynode[0].Expand(false);
- screen.Cursor:=crdefault;
- end;
- //**************************************************************
- procedure Tsz_ajlb.QuitExecute(Sender: TObject);
- begin
- close;
- end;
- procedure Tsz_ajlb.N5Click(Sender: TObject);
- begin
- tree.Selected.Expand(true);
- end;
- procedure Tsz_ajlb.N6Click(Sender: TObject);
- begin
- tree.Selected.Collapse(true);
- end;
- procedure Tsz_ajlb.AddExecute(Sender: TObject);
- begin
- if tree.Selected=nil then exit//为空退出
- else
- //dm.sz_ajlb.Close;
- //dm.sz_ajlb.CommandText:='select * from sz_ajlb where ajlb_dm='+''''+''+''''+'';
- //dm.sz_ajlb.Open;//增加
- dm.sz_ajlb.Append;
- if tree.Selected.level=length(trim(lbjs_sm2)) then
- begin
- application.MessageBox('已经到达最底层的节点'+#13#10+'不能再增加','提示',mb_ok+mb_iconinformation);
- exit;
- end;
- dbedit1.SetFocus;
- dbedit3.Text:=inttostr(tree.Selected.level);
- BtnState();//调用按钮的状态参数
- dsState:='add';
- end;
- procedure Tsz_ajlb.EditExecute(Sender: TObject);
- var s1,s2:string;
- Epos:integer;
- begin
- if tree.selected=nil then
- exit
- else
- if tree.Items.Count<>0 then
- if Tree.Items[0].HasChildren<>false then
- begin
- BtnState();//调用按钮的状态参数
- s1:=Tree.Selected.Text;
- Epos:=pos('-',s1);//取得'-'在节点名中的位置
- s2:=copy(s1,0,Epos-1);//
- dm.sz_ajlb.Close;
- dm.sz_ajlb.CommandText:='select * from sz_ajlb where ajlb_dm='+''''+s2+''''+'';
- dm.sz_ajlb.Open;
- //dbedit1.Text:=dm.sz_ajlb.fieldbyname('ajlb_dm').AsString;
- Dbedit1.Enabled:=false;
- DBEdit1.Color:=cl3DLight;
- dm.sz_ajlb.edit;
- add1.Enabled:=false;xiugai.Enabled:=false;dele1.Enabled:=false;
- save.Enabled:=true;A1.Enabled:=false;E1.Enabled:=false;D1.Enabled:=false;
- end
- else
- begin
- application.MessageBox('当前表中没有数据,不能修改','提示',mb_ok+mb_iconinformation);
- exit;
- end;
- end;
- procedure Tsz_ajlb.DeleteExecute(Sender: TObject);
- var
- epos:integer;
- s1,s2:string;
- begin
- if tree.Selected=nil then exit
- else if tree.Selected.Level=1 then exit
- else if tree.Selected.HasChildren=true then
- begin
- application.messagebox('该部门包含下级,不能删除','提示',MB_OKCANCEL+mb_iconinformation );
- end
- else
- begin
- if application.messagebox('你确实要删除当前纪录吗?','提示',MB_OKCANCEL+mb_iconinformation )=IDOK then
- begin
- s1:=Tree.Selected.Text;
- Epos:=pos('-',s1);//取得'-'在节点名中的位置
- s2:=copy(s1,0,Epos-1);//
- tree.Selected.Delete;//删除树形表中数据
- dm.sz_ajlb.Close;
- dm.sz_ajlb.CommandText:='delete from sz_ajlb where ajlb_dm='+''''+s2+''''+'';
- dm.sz_ajlb.execute;
- dm.sz_ajlb.Close;
- dm.sz_ajlb.CommandText:='select * from sz_ajlb';
- dm.sz_ajlb.Open;
- refresh.Execute;
- //删除表中数据
- end;
- end;
- end;
- procedure Tsz_ajlb.SaveExecute(Sender: TObject);
- var
- yanzheng:string;//yangzheng查找数据库中是否有重复记录存在
- i:integer;
- hint:string;
- s1,s2:string;
- Epos:integer;
- begin
- if dbedit1.Text='' then
- begin
- application.MessageBox('文件类别代码不能为空','提示',mb_ok+mb_iconinformation);
- exit;
- end;
- if dbedit2.Text='' then
- begin
- application.MessageBox('文件类别名称不能为空','提示',mb_ok+mb_iconinformation);
- exit;
- end;
- //-----------------------------------
- //判断是增加还是修改*****************************************************
- if dbedit1.Enabled=true then
- begin
- if tree.Selected.Level=length(lbjs_sm2) then
- begin
- application.MessageBox('已经到达最底层节点'+#13#10+'不能增加','提示',mb_ok+mb_iconinformation);
- exit;
- end else
- for i:=0 to tree.Selected.Level do
- begin
- if tree.Selected.Level=i then
- begin//&&&&
- if length(dbedit1.Text)<>strtoInt(copy(lbjs_sm2,i+1,1)) then
- begin
- hint:='请输入'+copy(lbjs_sm2,i+1,1)+'位代码';
- application.MessageBox(Pchar(hint),'提示',mb_okcancel+mb_iconinformation);
- exit;
- end
- else//
- begin
- {s1:=Tree.Selected.Text;
- Epos:=pos('-',s1);//取得'-'在节点名中的位置
- s2:=copy(s1,0,Epos-1);//
- yanzheng:=s2+dbedit1.Text;
- dm.sz_ajlb.Close;
- dm.sz_ajlb.CommandText:='select * from sz_ajlb where ajlb_dm='+''''+yanzheng+''''+'';
- dm.sz_ajlb.Open;
- if dm.sz_ajlb.FieldByName('ajlb_dm').AsString<>'' then
- begin
- application.MessageBox('已经有重复纪录存在','提示',mb_ok+mb_iconinformation);
- BtnState();
- exit;
- end
- else}
- begin
- SaveData(tree,dbedit1,dbedit2,dbedit4);//调用保存过程
- //refresh.Execute;
- BtnState();//调用按钮的状态参数
- break;//成功则退出循环
- end;
- end;//end if 0
- end//&&&&
- else continue;
- end;//end for
- end//end 结束增加
- else
- begin //修改后的情况
- dm.sz_ajlb.Edit;
- Tree.Selected.EditText;//修改节点
- Tree.Selected.Text:=Dbedit1.text+'-'+DbEdit2.Text;
- tree.Selected.ImageIndex:=0;
- tree.Selected.SelectedIndex:=1;
- //增加数据到节点
- dm.sz_ajlb.FieldByName('ajlb_dm').AsString:=dbedit1.Text;
- dm.sz_ajlb.FieldByName('ajlb_mc').AsString:=dbedit2.Text;
- dm.sz_ajlb.FieldByName('ajlb_js').AsInteger:=StrToInt(dbedit3.text);
- dm.sz_ajlb.FieldByName('ajlb_sm').AsString:=dbEdit4.Text;
- //给数组赋值
- dm.sz_ajlb.ApplyUpdates(0);
- application.MessageBox('数据保存成功','提示',mb_ok+mb_iconinformation);
- BtnState();
- dbedit1.Enabled:=true;
- dbedit1.Color:=clwindow;
- end;
- end;
- procedure Tsz_ajlb.RefreshExecute(Sender: TObject);
- begin
- dm.sz_ajlb.close;
- dm.sz_ajlb.CommandText:='select * from sz_ajlb';
- dm.sz_ajlb.Open;
- if dm.sz_ajlb.RecordCount<>0 then
- begin
- Add1.Enabled:=true;xiugai.Enabled:=true;dele1.Enabled:=true;
- A1.Enabled:=true;E1.Enabled:=true;D1.Enabled:=true;save.Enabled:=false;
- end
- else
- begin
- Add1.Enabled:=true;xiugai.Enabled:=false;dele1.Enabled:=false;
- A1.Enabled:=true;E1.Enabled:=false;D1.Enabled:=false;save.Enabled:=false;
- end;
- end;
- procedure Tsz_ajlb.FormCreate(Sender: TObject);
- begin
- dm.sz_qz.Close;
- dm.sz_qz.CommandText:='select * from sz_qz';
- dm.sz_qz.Open;
- dm.sz_ajlb.Close;
- dm.sz_ajlb.CommandText:='Select * from sz_ajlb';
- dm.sz_ajlb.Open;
- //设立主从表关系
- //dm.sz_ajlb.MasterSource:=sz_qz;
- //dm.sz_ajlb.MasterFields:='qz_dm';
- //dm.sz_ajlb.MasterSource:=sz_xtajlb;
- //dm.sz_ajlb.MasterFields:='xt_dm';
- dm.sz_xtajlb.close;
- dm.sz_xtajlb.CommandText:='select * from sz_xtajlb';
- dm.sz_xtajlb.Open;
- //刷新两个表
- dm.xt_lbjs.Close;
- dm.xt_lbjs.CommandText:='select * from xt_lbjs where lb_dm='+''''+'sz_qz'+''''+'';
- dm.xt_lbjs.Open;
- lbjs_sm1:=dm.xt_lbjs.fieldbyname('lbjs_sm').AsString;
- //调出主表的编码规则
- dm.xt_lbjs.Close;
- dm.xt_lbjs.CommandText:='select * from xt_lbjs where lb_dm='+''''+'sz_ajlb'+''''+'';
- dm.xt_lbjs.Open;
- lbjs_sm2:=dm.xt_lbjs.fieldbyname('lbjs_sm').asstring;
- //调出二级表的编码规则
- loadtree1(dm.sz_qz,dm.sz_ajlb);
- //调用系统案卷类别表
- dm.sz_qz.Close;
- dm.sz_qz.CommandText:='select * from sz_qz';
- dm.sz_qz.Open;
- dm.sz_ajlb.Close;
- dm.sz_ajlb.CommandText:='Select * from sz_ajlb';
- dm.sz_ajlb.Open;
- //刷新两个表
- dm.xt_lbjs.Close;
- dm.xt_lbjs.CommandText:='select * from xt_lbjs where lb_dm='+''''+'sz_ajlb'+''''+'';
- dm.xt_lbjs.Open;
- lb_dmgz2:=dm.xt_lbjs.fieldbyname('lb_dmgz').AsString;
- //调用文件类别表
- edit1.Text:=lb_dmgz2;
- end;
- procedure Tsz_ajlb.TreeClick(Sender: TObject);
- var
- s1,s2:string;
- i,Epos:integer;
- begin
- if tree.selected=nil then
- exit
- else if tree.Selected.Level=1 then
- begin
- dele1.Enabled:=false;D1.Enabled:=false;
- xiugai.Enabled:=false;E1.Enabled:=false;
- add1.Enabled:=true;A1.Enabled:=true;
- end else if tree.Selected.Level=0 then
- begin
- dele1.Enabled:=false;D1.Enabled:=false;
- xiugai.Enabled:=false;E1.Enabled:=false;
- add1.Enabled:=false;A1.Enabled:=false;
- save1.Enabled:=false;
- end else
- begin
- add1.Enabled:=true;A1.Enabled:=true;
- dele1.Enabled:=true;D1.Enabled:=true;
- xiugai.Enabled:=true;E1.Enabled:=true;
- end;
- if Tree.Items[0].HasChildren<>false then
- begin //选中和不选中的图片显示
- for i:=0 to Tree.items.count-1 do
- begin
- Tree.Items[i].ImageIndex:=0;
- Tree.Items[i].SelectedIndex:=1;
- s1:=Tree.Selected.Text;
- Epos:=pos('-',s1);
- s2:=copy(s1,0,Epos-1);
- dm.sz_ajlb.Close;
- dm.sz_ajlb.CommandText:='select * from sz_ajlb where ajlb_dm='+''''+s2+''''+'';
- dm.sz_ajlb.Open;
- dbedit1.Text:=dm.sz_ajlb.fieldbyname('ajlb_dm').AsString;
- dbedit2.Text:=dm.sz_ajlb.fieldbyname('ajlb_mc').AsString;
- dbedit3.Text:=dm.sz_ajlb.fieldbyname('ajlb_js').AsString;
- dbedit4.Text:=dm.sz_ajlb.fieldbyname('ajlb_sm').AsString;
- end;
- end;
- end;
- procedure Tsz_ajlb.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- dm.sz_qz.Active:=false;
- dm.sz_ajlb.Active:=false;
- dm.sz_xtajlb.Active:=false;
- tree.Free;
- action:=cafree;
- sz_ajlb:=Nil;
- end;
- procedure Tsz_ajlb.DBEdit1KeyPress(Sender: TObject; var Key: Char);
- begin
- if key=#13 then
- begin
- key:=#0;
- selectNext(activeControl,true,true);
- end;
- end;
- procedure Tsz_ajlb.DBEdit2KeyPress(Sender: TObject; var Key: Char);
- begin
- dbEdit1keyPress(Nil,key);
- end;
- procedure Tsz_ajlb.DBGridEh1CellClick(Column: TColumnEh);
- var
- s1,s2:string;
- i:integer;
- begin//--1单击每一行时,使树形控件也变化
- s1:=DBGridEh1.Columns[2].DisplayText;
- s2:=DBGridEh1.Columns[3].DisplayText;
- dm.sz_ajlb.Locate('ajlb_dm','+''''+s1+''''+',[]);
- //过滤要搜索的数据
- //dbedit1.Text:=dm.sz_wjlb.fieldbyname('wjlb_dm').AsString;
- //dbedit2.Text:=dm.sz_wjlb.fieldbyname('wjlb_mc').AsString;
- //dbedit3.Text:=dm.sz_wjlb.fieldbyname('wjlb_js').AsString;
- //dbedit4.Text:=dm.sz_wjlb.fieldbyname('wjlb_sm').AsString;
- Add1.Enabled:=false;xiugai.Enabled:=false;
- dele1.Enabled:=false;save.Enabled:=false;
- if Tree.Items[0].HasChildren<>false then
- begin//end if
- for i:=0 to Tree.items.count-1 do
- if Tree.Items[i].Text=s1+'-'+s2 then
- begin
- Tree.Items[i].Selected:=true;
- break;
- end;//end for
- end;//end if
- end;//--1
- procedure Tsz_ajlb.TreeChange(Sender: TObject; Node: TTreeNode);
- begin
- //BtnState();
- end;
- end.