sz_wjlbs.~pas
资源名称:挡案管理系统.rar [点击查看]
上传用户:szruida
上传日期:2007-06-01
资源大小:6518k
文件大小:16k
源码类别:
Delphi控件源码
开发平台:
Delphi
- unit sz_wjlbs;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, Menus, ActnList, XPBarMenu, Grids, DBGridEh, StdCtrls, Mask,
- DBCtrls, ComCtrls, ExtCtrls, ToolWin, DB, DBClient, PrnDbgeh;
- type
- Tsz_wjlb = class(TForm)
- StatusBar1: TStatusBar;
- CoolBar1: TCoolBar;
- ToolBar1: TToolBar;
- add1: TToolButton;
- xiugai: TToolButton;
- dele1: TToolButton;
- save1: TToolButton;
- Refresh1: TToolButton;
- ToolButton2: 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;
- DataSource1: TDataSource;
- sz_xtajlb: TDataSource;
- DbEdit2: TEdit;
- DbEdit3: TEdit;
- DbEdit4: TEdit;
- DbEdit1: TEdit;
- PrintDBGridEh1: TPrintDBGridEh;
- procedure N5Click(Sender: TObject);
- procedure N6Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure QuitExecute(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure AddExecute(Sender: TObject);
- procedure SaveExecute(Sender: TObject);
- procedure EditExecute(Sender: TObject);
- procedure DeleteExecute(Sender: TObject);
- procedure TreeClick(Sender: TObject);
- procedure RefreshExecute(Sender: TObject);
- procedure DBGridEh1CellClick(Column: TColumnEh);
- procedure PrintExecute(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- procedure BtnState();//增,改时的按钮变化
- procedure SaveData(TreeView:TtreeView;edit1,edit2,edit4:Tedit);//保存数据
- procedure loadTree1(treeDb1,treeDb2:TClientDataSet);//初始化树
- end;
- var
- sz_wjlb: Tsz_wjlb;
- gnode:TtreeNode;//当前节点
- lbjs_sm1,lbjs_sm2:string;//类别级数
- lb_dmgz1,lb_dmgz2:string;//代码规则
- dsState:string;//增删改的状态
- implementation
- uses dms,u_public;
- {$R *.dfm}
- procedure Tsz_wjlb.BtnState();
- begin
- if (add1.Enabled=true)or(xiugai.Enabled=true) then
- begin
- add1.Enabled:=false;
- xiugai.Enabled:=false;
- dele1.Enabled:=false;
- save1.Enabled:=true;
- refresh1.Enabled:=true;
- end
- else
- begin
- add1.Enabled:=true;
- xiugai.Enabled:=true;
- dele1.Enabled:=true;
- save1.Enabled:=false;
- refresh1.Enabled:=true;
- end;
- end;
- //***********************************************
- procedure Tsz_wjlb.SaveData(TreeView:TtreeView;edit1,edit2,edit4:Tedit);//保存数据
- var
- curnode:TTreenode;//已选树节点
- s_xtdm,Pnodetxt,Pnodetxt2,nodetxt:string;//Pnodetxt:取出树上级节点节点的代码;nodetxt:要在树节点上增加的值
- n,n_xtdm:integer;//取出'-'在已选树节点中的位置
- begin
- dm.sz_wjlb.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;//现在节点等于原来的加上现在的
- //增加数据到节点
- dm.sz_wjlb.FieldByName('wjlb_dm').AsString:=Pnodetxt+dbedit1.Text;
- dm.sz_wjlb.FieldByName('wjlb_mc').AsString:=dbedit2.Text;
- dm.sz_wjlb.FieldByName('wjlb_js').AsInteger:=tree.Selected.Level;
- dm.sz_wjlb.FieldByName('wjlb_sm').AsString:=dbEdit4.Text;
- dm.sz_wjlb.FieldByName('wjlb_sjlbdm').AsString:=Pnodetxt;
- dm.sz_wjlb.FieldByName('xt_dm').AsString:=s_xtdm;//将一级表的代码赋给二级表
- //给数组赋值
- dm.sz_wjlb.ApplyUpdates(0);
- application.MessageBox('数据保存成功','提示',mb_ok+mb_iconinformation);
- curnode:=TreeView.Items.AddChild(tree.Selected,nodetxt);//增加新的节点
- curnode.ImageIndex:=0;
- curnode.SelectedIndex:=1;
- //-------按钮状态
- end;
- //**************************************************
- procedure Tsz_wjlb.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('xt_dm').AsString);
- nodeTxt1:=nodeId1+'-'+trim(treedb1.fieldbyname('xt_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_wjlb where xt_dm='+''''+nodeId1+''''+'';
- treedb2.open;
- if trim(treedb2.FieldByName('xt_dm').AsString)<>'' then
- begin
- for j:=0 to treedb2.recordcount-1 do
- begin
- nodeId2:=trim(treedb2.fieldbyname('wjlb_dm').asstring);
- nodeTxt2:=NodeId2+'-'+trim(treedb2.fieldbyname('wjlb_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_wjlb.N5Click(Sender: TObject);
- begin
- tree.Selected.expand(true);
- end;
- procedure Tsz_wjlb.N6Click(Sender: TObject);
- begin
- tree.Selected.Collapse(true);
- end;
- procedure Tsz_wjlb.FormCreate(Sender: TObject);
- begin
- dm.sz_xtajlb.Close;
- dm.sz_xtajlb.CommandText:='select * from sz_xtajlb';
- dm.sz_xtajlb.Open;
- dm.sz_wjlb.Close;
- dm.sz_wjlb.CommandText:='Select * from sz_wjlb';
- dm.sz_wjlb.Open;
- //刷新两个表
- dm.xt_lbjs.Close;
- dm.xt_lbjs.CommandText:='select * from xt_lbjs where lb_dm='+''''+'sz_xtajlb'+''''+'';
- 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_wjlb'+''''+'';
- dm.xt_lbjs.Open;
- lbjs_sm2:=dm.xt_lbjs.fieldbyname('lbjs_sm').asstring;
- //调出二级表的编码规则
- loadtree1(dm.sz_xtajlb,dm.sz_wjlb);
- //调用系统案卷类别表
- dm.sz_xtajlb.Close;
- dm.sz_xtajlb.CommandText:='select * from sz_xtajlb';
- dm.sz_xtajlb.Open;
- dm.sz_wjlb.Close;
- dm.sz_wjlb.CommandText:='Select * from sz_wjlb';
- dm.sz_wjlb.Open;
- //刷新两个表
- dm.xt_lbjs.Close;
- dm.xt_lbjs.CommandText:='select * from xt_lbjs where lb_dm='+''''+'sz_wjlb'+''''+'';
- dm.xt_lbjs.Open;
- lb_dmgz2:=dm.xt_lbjs.fieldbyname('lb_dmgz').AsString;
- //调用文件类别表
- edit1.Text:=lb_dmgz2;
- end;
- procedure Tsz_wjlb.QuitExecute(Sender: TObject);
- begin
- close;
- end;
- procedure Tsz_wjlb.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- dm.sz_xtajlb.Active:=false;
- dm.sz_wjlb.Active:=false;
- tree.Free;
- action:=cafree;
- sz_wjlb:=nil;
- end;
- procedure Tsz_wjlb.AddExecute(Sender: TObject);
- begin
- if tree.Selected=nil then exit//为空退出
- else
- dm.sz_wjlb.Close;
- dm.sz_wjlb.CommandText:='select * from sz_wjlb where wjlb_dm='+''''+''''+'';
- dm.sz_wjlb.Open;//增加
- if tree.Selected.level=length(trim(lbjs_sm2)) then
- begin
- application.MessageBox('已经到达最底层的节点'+#13#10+'不能再增加','提示',mb_ok+mb_iconinformation);
- exit;
- end;
- dbedit1.SetFocus;
- dbedit2.Text:='';
- dbedit4.Text:='';
- dbedit3.Text:=IntToStr(tree.Selected.level);
- BtnState();//调用按钮的状态参数
- dsState:='add';
- end;
- procedure Tsz_wjlb.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);
- Dbedit1.SetFocus;
- exit;
- end;
- if dbedit2.Text='' then
- begin
- application.MessageBox('文件类别名称不能为空','提示',mb_ok+mb_iconinformation);
- Dbedit2.SetFocus;
- 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);
- Dbedit1.SetFocus;
- exit;
- end
- else//
- begin
- s1:=Tree.Selected.Text;
- Epos:=pos('-',s1);//取得'-'在节点名中的位置
- s2:=copy(s1,0,Epos-1);//
- yanzheng:=s2+dbedit1.Text;
- dm.sz_wjlb.Close;
- dm.sz_wjlb.CommandText:='select * from sz_wjlb where wjlb_dm='+''''+yanzheng+''''+'';
- dm.sz_wjlb.Open;
- if dm.sz_wjlb.FieldByName('wjlb_dm').AsString<>'' then
- begin
- application.MessageBox('已经有重复纪录存在','提示',mb_ok+mb_iconinformation);
- BtnState();
- exit;
- end
- else
- begin
- SaveData(tree,dbedit1,dbedit2,dbedit4);//调用保存过程
- //refresh1.Click;
- BtnState();//调用按钮的状态参数
- break;//成功则退出循环
- end;
- end;//end if 0
- end//&&&&
- else continue;
- end;//end for
- end//end 结束增加
- else
- begin //修改后的情况
- dm.sz_wjlb.Edit;
- Tree.Selected.EditText;//修改节点
- Tree.Selected.Text:=Dbedit1.text+'-'+DbEdit2.Text;
- tree.Selected.ImageIndex:=0;
- tree.Selected.SelectedIndex:=1;
- //增加数据到节点
- dm.sz_wjlb.FieldByName('wjlb_dm').AsString:=dbedit1.Text;
- dm.sz_wjlb.FieldByName('wjlb_mc').AsString:=dbedit2.Text;
- dm.sz_wjlb.FieldByName('wjlb_js').AsInteger:=StrToInt(dbedit3.text);
- dm.sz_wjlb.FieldByName('wjlb_sm').AsString:=dbEdit4.Text;
- //给数组赋值
- dm.sz_wjlb.ApplyUpdates(0);
- application.MessageBox('数据保存成功','提示',mb_ok+mb_iconinformation);
- BtnState();
- dbedit1.Enabled:=true;
- dbedit1.Color:=clwindow;
- end;
- end;
- procedure Tsz_wjlb.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_wjlb.Close;
- dm.sz_wjlb.CommandText:='select * from sz_wjlb where wjlb_dm='+''''+s2+''''+'';
- dm.sz_wjlb.Open;
- dbedit1.Text:=dm.sz_wjlb.fieldbyname('wjlb_dm').AsString;
- Dbedit1.Enabled:=false;
- DBEdit1.Color:=cl3DLight;
- dm.sz_wjlb.edit;
- end
- else
- begin
- application.MessageBox('当前表中没有数据,不能修改','提示',mb_ok+mb_iconinformation);
- exit;
- end;
- end;
- procedure Tsz_wjlb.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_iconquestion )=IDOK then
- begin
- s1:=Tree.Selected.Text;
- Epos:=pos('-',s1);//取得'-'在节点名中的位置
- s2:=copy(s1,0,Epos-1);//
- tree.Selected.Delete;//删除树形表中数据
- dm.sz_wjlb.Close;
- dm.sz_wjlb.CommandText:='delete from sz_wjlb where wjlb_dm='+''''+s2+''''+'';
- dm.sz_wjlb.execute;
- dm.sz_wjlb.Close;
- dm.sz_wjlb.CommandText:='select * from sz_wjlb';
- dm.sz_wjlb.Open;
- //删除表中数据
- end;
- end;
- end;
- procedure Tsz_wjlb.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:=false;
- 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;
- 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_wjlb.Close;
- dm.sz_wjlb.CommandText:='select * from sz_wjlb where wjlb_dm='+''''+s2+''''+'';
- dm.sz_wjlb.Open;
- 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;
- end;
- end;
- end;
- procedure Tsz_wjlb.RefreshExecute(Sender: TObject);
- begin
- tree.Selected.Expand(true);
- dm.sz_wjlb.close;
- dm.sz_wjlb.CommandText:='select * from sz_wjlb';
- dm.sz_wjlb.Open;
- end;
- procedure Tsz_wjlb.DBGridEh1CellClick(Column: TColumnEh);
- var
- s1,s2:string;
- i:integer;
- begin//--1单击每一行时,使树形控件也变化
- s1:=DBGridEh1.Columns[0].DisplayText;
- s2:=DBGridEh1.Columns[1].DisplayText;
- dm.sz_wjlb.Locate('wjlb_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;
- 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_wjlb.PrintExecute(Sender: TObject);
- begin
- PrintDBGridEh1.Preview;
- PrintDbGridEh1.AfterGridText.Text:=datetoStr(date);
- end;
- end.