sz_qzs.pas
资源名称:挡案管理系统.rar [点击查看]
上传用户:szruida
上传日期:2007-06-01
资源大小:6518k
文件大小:12k
源码类别:
Delphi控件源码
开发平台:
Delphi
- unit sz_qzs;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, DB, XPBarMenu, Grids, DBGrids, StdCtrls, ComCtrls, ExtCtrls,
- ToolWin, Mask, DBCtrls, ActnList, Menus, DBActns,
- PrnDbgeh, DBGridEh, DBClient, XPMenu;
- type
- Tsz_qz = class(TForm)
- CoolBar1: TCoolBar;
- ToolBar1: TToolBar;
- add1: TToolButton;
- ToolButton5: TToolButton;
- ToolButton6: TToolButton;
- ToolButton4: TToolButton;
- Panel1: TPanel;
- Splitter1: TSplitter;
- Panel2: TPanel;
- Tree: TTreeView;
- Panel3: TPanel;
- Splitter2: TSplitter;
- Panel4: TPanel;
- Panel5: TPanel;
- GroupBox2: TGroupBox;
- DataSource1: TDataSource;
- ToolButton3: TToolButton;
- Label1: TLabel;
- DBEdit1: TDBEdit;
- Label2: TLabel;
- DBEdit2: TDBEdit;
- Label3: TLabel;
- DBEdit3: TDBEdit;
- Label4: TLabel;
- DBEdit4: TDBEdit;
- Label5: TLabel;
- DBEdit5: TDBEdit;
- Label6: TLabel;
- DBEdit6: TDBEdit;
- Label7: TLabel;
- DBEdit7: TDBEdit;
- Label8: TLabel;
- Label9: TLabel;
- ActionList1: TActionList;
- Add: TAction;
- Edit: TAction;
- Delete: TAction;
- Refresh: TAction;
- Print: TAction;
- Quit: TAction;
- ToolButton7: TToolButton;
- Save: TAction;
- Edit1: TEdit;
- Label10: TLabel;
- PopupMenu1: TPopupMenu;
- N1: TMenuItem;
- N3: TMenuItem;
- N2: TMenuItem;
- N5: TMenuItem;
- N6: TMenuItem;
- PrintDBGridEh1: TPrintDBGridEh;
- DBGridEh1: TDBGridEh;
- xt_jbls: TDataSource;
- XPBarMenu1: TXPBarMenu;
- procedure ToolButton4Click(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure QuitExecute(Sender: TObject);
- procedure SaveExecute(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure DeleteExecute(Sender: TObject);
- procedure AddExecute(Sender: TObject);
- procedure DBEdit1KeyPress(Sender: TObject; var Key: Char);
- procedure DBEdit2KeyPress(Sender: TObject; var Key: Char);
- procedure DBEdit3KeyPress(Sender: TObject; var Key: Char);
- procedure DBEdit4KeyPress(Sender: TObject; var Key: Char);
- procedure DBEdit5KeyPress(Sender: TObject; var Key: Char);
- procedure DBEdit6KeyPress(Sender: TObject; var Key: Char);
- procedure RefreshExecute(Sender: TObject);
- procedure EditExecute(Sender: TObject);
- procedure N5Click(Sender: TObject);
- procedure N6Click(Sender: TObject);
- procedure TreeClick(Sender: TObject);
- procedure DBGridEh1CellClick(Column: TColumnEh);
- procedure PrintExecute(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- procedure loadTree(treeDB:TClientDataSet);//初始化树
- end;
- var
- sz_qz: Tsz_qz;
- SCodeFormat:string; //库位代码结构
- lbjs:string;
- SFirstNodeTxt:string; //首节点显示的文字
- lb_dmgz:string;//代码规则
- implementation
- uses Dms,mainfrms,U_public;
- {$R *.dfm}
- //以下过程为装载树
- procedure Tsz_qz.loadTree(treeDb:TClientDataSet);//初始化树
- var
- nodeId,nodeTxt:string;
- level,chindex,cnode,num:integer;
- mynode:array[0..6] of Ttreenode;
- begin
- //初始化变量
- SCodeFormat:=lbjs ; //库位代码结构
- SFirstNodeTxt:= '库位'; //首节点显示的文字
- Screen.Cursor:=crHourGlass;
- Tree.enabled:=true;
- Tree.Items.Clear;
- level:=0;
- num:=1;
- //设置根节点
- mynode[level]:=Tree.Items.Add(Tree.TopItem,'全宗');
- mynode[level].ImageIndex:=0;
- mynode[level].SelectedIndex:=1;
- //遍历数据表,利用编码字段记录排序规律,依次添加树节点
- with treeDB do
- begin
- try
- if not active then open;
- first;
- while not treedb.Eof do
- begin
- nodeId:=trim(fieldbyname('qz_dm').AsString);
- nodeTxt:=nodeId+'-'+trim(fieldbyname('qz_mc').AsString);
- level:=GetNodeLevel(SCodeFormat,nodeId);//获得节点层树
- //再这里返回代码的层次数
- if level>0 then
- begin
- //增加下一节点时,用添加子节点的方法可以轻松实现节点的层次关系
- //注意,这里的父节点是用当前节点的上一级节点mynode[level-1]
- mynode[level]:=tree.Items.AddChild(mynode[level-1],nodeTxt);
- mynode[level].ImageIndex:=0;
- mynode[level].SelectedIndex:=1;
- end;//end if
- next;//下一条纪录
- end;//end while
- finally;
- close;
- end;
- mynode[0].Expand(false);
- screen.Cursor:=crdefault;
- end;//end with
- end;
- //--------------------------------装载树
- procedure Tsz_qz.ToolButton4Click(Sender: TObject);
- begin
- if Tree.Selected.Text='全宗' then
- Tree.Selected.Delete;
- end;
- procedure Tsz_qz.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- dm.sz_qz.Active:=false;
- dm.xt_lbjs.Active:=false;
- action:=cafree;
- sz_qz:=nil;
- Tree.Free;
- end;
- procedure Tsz_qz.QuitExecute(Sender: TObject);
- begin
- close;
- end;
- procedure Tsz_qz.SaveExecute(Sender: TObject);
- var
- i,j:integer;
- s1,s2:string;
- subnode:TTreenode;//先建立一个TReeview使用的子对象
- begin
- i:=length(edit1.Text);//编码规则
- s1:=trim(dbedit1.Text);
- s2:=s1+'-'+trim(dbedit2.Text);
- if length(s1)<> i then
- begin
- application.MessageBox('编码规则不合要求','提示',mb_ok+mb_iconinformation);
- exit;
- end;
- if trim(dbedit1.Text)='' then
- begin
- application.MessageBox('全宗代码不能为空','提示',mb_ok+mb_iconinformation);
- exit;
- end;
- if trim(dbedit1.Text)='' then
- begin
- application.MessageBox('全宗代码不能为空','提示',mb_ok+mb_iconinformation);
- exit;
- end;
- //以上对数据进行有效性验证
- //-----------------
- dm.sz_qz.ApplyUpdates(0);
- j:=dm.sz_qz.ApplyUpdates(0);
- if j<>0 then
- begin
- application.MessageBox('数据保存失败','提示',mb_ok+mb_iconinformation);
- exit;
- end
- else
- begin
- application.MessageBox('数据保存成功','提示',mb_ok+mb_iconinformation);
- //------------------
- tree.SetFocus;//在根目录下新建一个子标题
- if DbEdit1.Color<>cl3dLight then
- begin
- subnode:=Tree.Items.AddChild(Tree.Items.GetFirstNode,s2);
- //在根节点添加子节点
- subnode.ImageIndex:=0;
- subnode.SelectedIndex:=1;
- //----------------
- end
- else
- begin
- Tree.Selected.EditText;//修改节点
- Tree.Selected.Text:=DbEdit1.Text+'-'+DbEdit2.Text;
- end;
- dm.sz_qz.Close;
- dm.sz_qz.CommandText:='select * from sz_qz';
- dm.sz_qz.Open;
- Dbedit1.Enabled:=true;
- Dbedit1.Color:=clHighlightText;
- add1.Enabled:=true;
- ToolButton4.Enabled:=true;ToolButton5.Enabled:=true;
- ToolButton6.Enabled:=true;ToolButton7.Enabled:=false;
- N2.Enabled:=true;N1.Enabled:=true;N3.Enabled:=true;
- end;
- end;
- procedure Tsz_qz.FormCreate(Sender: TObject);
- var i:integer;
- begin
- Dm.sz_qz.Close;
- dm.sz_qz.CommandText:='select * from sz_qz';
- dm.sz_qz.Open;
- Dm.xt_lbjs.Close;
- Dm.xt_lbjs.CommandText:='Select lb_dmgz,lbjs_sm from xt_lbjs where lb_dm='+''''+'sz_qz'+''''+'';
- Dm.xt_lbjs.Open;
- lbjs:=dm.xt_lbjs.fieldbyname('lbjs_sm').AsString;
- Lb_dmgz:=dm.xt_lbjs.fieldbyname('lb_dmgz').asstring;
- edit1.Text:=lb_dmgz;
- loadtree(dm.sz_qz);
- end;
- procedure Tsz_qz.DeleteExecute(Sender: TObject);
- var s1,s2:string;
- Epos:integer;
- begin
- if Tree.Items[0].HasChildren<>false then
- 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_qz.Close;
- dm.sz_qz.CommandText:='delete from sz_qz where qz_dm='+''''+s2+''''+'';
- dm.sz_qz.execute;
- dm.sz_qz.Close;
- dm.sz_qz.CommandText:='select * from sz_qz';
- dm.sz_qz.Open;
- end;
- end
- else
- begin
- application.MessageBox('当前表中没有数据,不能删除','提示',mb_ok+mb_iconinformation);
- exit;
- end;
- end;
- procedure Tsz_qz.AddExecute(Sender: TObject);
- begin
- Toolbutton5.Enabled:=false;//修改
- Toolbutton6.Enabled:=false;//删除
- Toolbutton7.Enabled:=true;//保存
- N2.Enabled:=false;N1.Enabled:=false;N3.Enabled:=false;
- dm.sz_qz.Close;
- dm.sz_qz.CommandText:='select * from sz_qz where qz_dm='+''''+''''+'';
- dm.sz_qz.Open;
- tree.Enabled:=true;
- end;
- procedure Tsz_qz.DBEdit1KeyPress(Sender: TObject; var Key: Char);
- begin
- if key=#13 then
- dbedit2.SetFocus;
- end;
- procedure Tsz_qz.DBEdit2KeyPress(Sender: TObject; var Key: Char);
- begin
- if key=#13 then
- dbedit3.SetFocus;
- end;
- procedure Tsz_qz.DBEdit3KeyPress(Sender: TObject; var Key: Char);
- begin
- if key=#13 then
- dbedit4.SetFocus;
- end;
- procedure Tsz_qz.DBEdit4KeyPress(Sender: TObject; var Key: Char);
- begin
- if key=#13 then
- dbedit5.SetFocus;
- end;
- procedure Tsz_qz.DBEdit5KeyPress(Sender: TObject; var Key: Char);
- begin
- if key=#13 then
- dbedit6.SetFocus;
- end;
- procedure Tsz_qz.DBEdit6KeyPress(Sender: TObject; var Key: Char);
- begin
- if key=#13 then
- dbedit7.SetFocus;
- end;
- procedure Tsz_qz.RefreshExecute(Sender: TObject);
- begin
- dm.sz_qz.Close;
- dm.sz_qz.CommandText:='select * from sz_qz';
- dm.sz_qz.Open;
- if dm.sz_qz.RecordCount<>0 then
- begin
- Add1.Enabled:=true;ToolButton7.Enabled:=false;
- ToolButton5.Enabled:=true;ToolButton6.Enabled:=true;
- end
- else
- begin
- add1.Enabled:=true;N1.Enabled:=true;
- end;
- end;
- procedure Tsz_qz.EditExecute(Sender: TObject);
- var s1,s2:string;
- Epos:integer;
- begin
- ToolButton7.Enabled:=true;toolbutton6.Enabled:=false;
- Add1.Enabled:=false;Toolbutton5.enabled:=false;
- N1.Enabled:=false;N3.Enabled:=false;N2.enabled:=false;
- if tree.Items.Count<>0 then
- if Tree.Items[0].HasChildren<>false then
- begin
- s1:=Tree.Selected.Text;
- Epos:=pos('-',s1);//取得'-'在节点名中的位置
- s2:=copy(s1,0,Epos-1);//
- dm.sz_qz.Close;
- dm.sz_qz.CommandText:='select * from sz_qz where qz_dm='+''''+s2+''''+'';
- dm.sz_qz.Open;
- Dbedit1.Enabled:=false;
- DBEdit1.Color:=cl3DLight;
- end
- else
- begin
- application.MessageBox('当前表中没有数据,不能修改','提示',mb_ok+mb_iconinformation);
- exit;
- end;
- end;
- procedure Tsz_qz.N5Click(Sender: TObject);
- begin
- if tree.Selected.HasChildren then
- begin
- if tree.Selected.Expanded then
- application.MessageBox('已经处于展开状态','提示',mb_OK+mb_iconinformation)
- else
- tree.Selected.Expand(true);
- end
- else
- application.MessageBox('当前节点没有子节点,不能展开','提示',mb_OK+mb_iconinformation);
- end;
- procedure Tsz_qz.N6Click(Sender: TObject);
- begin
- if tree.Selected.HasChildren then
- tree.Selected.Collapse(true)
- else
- application.MessageBox('当前节点没有子节点,不能叠起','提示',mb_OK+mb_iconinformation);
- end;
- procedure Tsz_qz.TreeClick(Sender: TObject);
- var
- s1,s2:string;
- i,Epos:integer;
- begin
- if Tree.Items[0].HasChildren<>false then
- begin //选中和不选中的图片显示
- for i:=0 to Tree.items.count-1 do
- begin
- s1:=Tree.Selected.Text;
- Epos:=pos('-',s1);
- s2:=copy(s1,0,Epos-1);
- dm.sz_qz.Close;
- dm.sz_qz.CommandText:='select * from sz_qz where qz_dm='+''''+s2+''''+'';
- dm.sz_qz.Open;
- ToolButton7.Enabled:=false;
- ToolButton6.Enabled:=true;
- ToolButton5.Enabled:=true;
- end;
- end;//end if
- end;
- procedure Tsz_qz.DBGridEh1CellClick(Column: TColumnEh);
- var
- s1,s2:string;
- i:integer;
- begin//--1单击每一行时,使树形控件也变化
- s1:=DBGridEh1.Columns[0].DisplayText;
- s2:=DBGridEh1.Columns[1].DisplayText;
- Tree.FullExpand;
- Tree.AlphaSort(true);
- 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_qz.PrintExecute(Sender: TObject);
- begin
- PrintDBGridEh1.Title.Text:='全宗管理';
- PrintDBGridEh1.Preview;
- printDBgridEh1.AfterGridText.text:=datetostr(date);
- end;
- end.