Am_kwgls.pas
资源名称:挡案管理系统.rar [点击查看]
上传用户:szruida
上传日期:2007-06-01
资源大小:6518k
文件大小:12k
源码类别:
Delphi控件源码
开发平台:
Delphi
- unit Am_kwgls;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, Menus, ActnList, DB, XPBarMenu, Grids, DBGridEh, StdCtrls, Mask,
- DBCtrls, ComCtrls, ExtCtrls, ToolWin, DBClient, DBCtrlsEh, DBLookupEh;
- type
- TAm_kwgl = class(TForm)
- CoolBar1: TCoolBar;
- ToolBar1: TToolBar;
- add1: TToolButton;
- xiugai: TToolButton;
- dele1: TToolButton;
- save1: TToolButton;
- Refresh1: TToolButton;
- Print1: TToolButton;
- Quit1: TToolButton;
- Panel1: TPanel;
- Splitter1: TSplitter;
- Panel2: TPanel;
- Tree: TTreeView;
- Panel3: TPanel;
- Splitter2: TSplitter;
- Panel4: TPanel;
- Panel5: TPanel;
- GroupBox2: TGroupBox;
- DBGridEh1: TDBGridEh;
- XPBarMenu1: TXPBarMenu;
- sz_kw: TDataSource;
- ActionList1: TActionList;
- Add: TAction;
- Edit: TAction;
- Delete: TAction;
- Save: TAction;
- Refresh: TAction;
- Print: TAction;
- Quit: TAction;
- PopupMenu1: TPopupMenu;
- A1: TMenuItem;
- E1: TMenuItem;
- N5: TMenuItem;
- N6: TMenuItem;
- Label1: TLabel;
- DBEdit1: TDBEdit;
- Label2: TLabel;
- Label3: TLabel;
- DBEdit3: TDBEdit;
- Label4: TLabel;
- DBEdit4: TDBEdit;
- Label5: TLabel;
- am_kwzk: TDataSource;
- Label6: TLabel;
- DBMemo1: TDBMemo;
- DeleS: TMenuItem;
- DBEditEh1: TDBEditEh;
- procedure TreeChange(Sender: TObject; Node: TTreeNode);
- procedure AddExecute(Sender: TObject);
- procedure EditExecute(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure TreeClick(Sender: TObject);
- procedure QuitExecute(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure RefreshExecute(Sender: TObject);
- procedure SaveExecute(Sender: TObject);
- procedure DeleteExecute(Sender: TObject);
- procedure DBGridEh1CellClick(Column: TColumnEh);
- procedure N6Click(Sender: TObject);
- procedure N5Click(Sender: TObject);
- procedure DeleSClick(Sender: TObject);
- procedure PrintExecute(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- procedure BtnState();
- procedure loadTree(treeDb:TClientDataSet);//初始化树
- end;
- var
- Am_kwgl: TAm_kwgl;
- gnode:TtreeNode;//当前节点
- lbjs_sm:string;//类别级数
- lb_dmgz:string;//代码规则
- dsState:string;//确定是增,删,改
- implementation
- uses dms,u_public, Am_Kwgl_Ps, am_kwzk_ps, am_kwzkps;
- {$R *.dfm}
- procedure TAm_kwgl.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;DeleS.Enabled:=false;
- save1.Enabled:=true;
- refresh1.Enabled:=true;
- end
- else
- begin
- add1.Enabled:=true;A1.Enabled:=true;
- xiugai.Enabled:=true;E1.Enabled:=true;
- dele1.Enabled:=true;DeleS.Enabled:=true;
- save1.Enabled:=false;
- refresh1.Enabled:=true;
- end;
- end;
- //********************************************************************
- procedure TAm_kwgl.loadTree(treeDb:TClientDataSet);//初始化树
- var
- nodeId,nodeTxt:string;
- SCodeFormat,SFirstNodeTxt:string;
- level:integer;
- mynode:array[0..6] of Ttreenode;
- begin
- //初始化变量
- SCodeFormat:=lbjs_sm ; //库位代码结构
- SFirstNodeTxt:= '库位'; //首节点显示的文字
- Screen.Cursor:=crHourGlass;
- Tree.enabled:=true;
- tree.Items.Clear;
- level:=0;
- //设置根节点
- 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('kw_dm').AsString);
- nodeTxt:=nodeId+'-'+trim(fieldbyname('kw_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 TAm_kwgl.TreeChange(Sender: TObject; Node: TTreeNode);
- begin
- {if dsState='add' then
- if application.MessageBox('请输入数据','提示',mb_okcancel+mb_iconinformation)=idOk then
- //dbedit1.SetFocus
- add.Execute
- else
- begin
- BtnState();//确定按钮变回来
- end; }
- dbediteh1.Text:='';
- end;
- procedure TAm_kwgl.AddExecute(Sender: TObject);
- var s1,s2:string;
- Epos:integer;
- begin
- if tree.Selected.HasChildren then
- begin
- APPLICATION.MessageBox('必须在最底层增加','提示',MB_ok+mb_iconinformation);
- exit;
- end
- else
- s1:=Tree.Selected.Text;
- Epos:=pos('-',s1)-1;//取得'-'在节点名中的位置
- s2:=copy(s1,0,Epos);//
- dm.sz_kw.Close;
- dm.sz_kw.CommandText:='select kw_mc,kw_dm from sz_kw where kw_dm='+''''+s2+''''+'';
- dm.sz_kw.Open;
- DbEditEh1.Text:=dm.sz_kw.fieldbyname('kw_mc').AsString;
- //-------------------------------------
- dm.Am_kwzk.Append;
- dbedit3.SetFocus;
- dbedit1.Text:=formatdatetime('yyyy-mm-dd hh:mm:ss',now());
- BtnState();//调用按钮的状态参数
- dsState:='add';
- end;
- procedure TAm_kwgl.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)-1;//取得'-'在节点名中的位置
- s2:=copy(s1,0,Epos);//
- dm.sz_kw.Close;
- dm.sz_kw.CommandText:='select * from sz_kw where kw_dm='+''''+s2+''''+'';
- dm.sz_kw.Open;
- DbEditEh1.Text:=dm.sz_kw.fieldbyname('kw_mc').AsString;
- dm.am_kwzk.edit;
- end
- else
- begin
- application.MessageBox('当前表中没有数据,不能修改','提示',mb_ok+mb_iconinformation);
- exit;
- end;
- end;
- procedure TAm_kwgl.FormCreate(Sender: TObject);
- begin
- dm.sz_kw.Close;
- dm.sz_kw.CommandText:='select * from sz_kw';
- dm.sz_kw.Open;
- //-----------------------------------------------
- dm.xt_lbjs.close;
- dm.xt_lbjs.CommandText:='select * from xt_lbjs where lb_dm='+''''+'sz_kw'+''''+'';
- dm.xt_lbjs.Open;
- lbjs_sm:=dm.xt_lbjs.fieldbyname('lbjs_sm').AsString;
- loadTree(dm.sz_kw);//初始化树
- dm.sz_kw.Close;
- dm.sz_kw.CommandText:='select * from sz_kw';
- dm.sz_kw.Open;
- {dm.Am_kwzk.Close;
- dm.Am_kwzk.CommandText:='select * from am_kwzk';
- dm.Am_kwzk.Open; }
- Print1.Enabled:=true;
- end;
- procedure TAm_kwgl.TreeClick(Sender: TObject);
- var
- s1,s2,s3:string;
- i,Epos:integer;
- begin
- if tree.selected=nil then
- exit
- else
- 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);
- s3:=copy(s1,Epos+1,length(s1));
- dm.Am_kwzk.Close;
- dm.Am_kwzk.CommandText:='select * from Am_kwzk where kw_dm='+''''+s2+''''+'';
- dm.Am_kwzk.Open;
- if tree.Selected.HasChildren then
- begin
- xiugai.Enabled:=false;E1.Enabled:=false;
- dele1.Enabled:=false;DeleS.Enabled:=false;
- end
- else
- begin
- if trim(dm.Am_kwzk.FieldByName('kw_dm').AsString)='' then
- begin
- DbEditEh1.Text:='';
- xiugai.Enabled:=false;E1.Enabled:=false;
- dele1.Enabled:=false;DeleS.Enabled:=false;
- end
- else
- begin
- DbEditEh1.Text:=s3;
- xiugai.Enabled:=true;E1.Enabled:=true;
- dele1.Enabled:=true;DeleS.Enabled:=true;
- end;
- end;
- end;
- end;
- end;
- procedure TAm_kwgl.QuitExecute(Sender: TObject);
- begin
- close;
- end;
- procedure TAm_kwgl.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- dm.Am_kwzk.active:=false;
- dm.sz_kw.Active:=false;
- tree.Free;
- action:=cafree;
- am_kwgl:=nil;
- end;
- procedure TAm_kwgl.RefreshExecute(Sender: TObject);
- begin
- dm.Am_kwzk.Close;
- dm.Am_kwzk.CommandText:='select * from am_kwzk';
- dm.Am_kwzk.Open;
- if dm.Am_kwzk.RecordCount=0 then
- begin
- add1.Enabled:=true;A1.Enabled:=true;
- xiugai.Enabled:=false;e1.Enabled:=false;
- dele1.Enabled:=false;DeleS.Enabled:=false;
- save1.Enabled:=false;
- end
- else
- begin
- add1.Enabled:=true;A1.Enabled:=true;
- xiugai.Enabled:=true;e1.Enabled:=true;
- dele1.Enabled:=true;DeleS.Enabled:=true;
- save1.Enabled:=false;
- end;
- end;
- procedure TAm_kwgl.SaveExecute(Sender: TObject);
- var n,errorI:integer;
- s_kwmc:string;
- begin
- dm.am_kwzk.edit;
- n:=pos('-',tree.Selected.Text)-1;
- s_kwmc:=copy(tree.Selected.Text,0,n);
- dm.sz_kw.Close;
- dm.sz_kw.CommandText:='select kw_dm from sz_kw where kw_dm='+''''+s_kwmc+''''+'';
- dm.sz_kw.Open;
- dm.Am_kwzk.FieldByName('kw_dm').AsString:=dm.sz_kw.fieldbyname('kw_dm').AsString;
- dm.Am_kwzk.ApplyUpdates(0);
- errorI:=dm.Am_kwzk.ApplyUpdates(0);
- if errorI=0 then
- begin
- application.MessageBox('数据保存成功','提示',mb_ok+mb_iconinformation);
- BtnState();
- exit;
- end
- else
- begin
- application.MessageBox('数据保存失败','提示',mb_ok+mb_iconinformation);
- BtnState();
- exit;
- end;
- end;
- procedure TAm_kwgl.DeleteExecute(Sender: TObject);
- var
- epos:integer;
- s1,s2,s:string;
- begin
- if tree.Selected=nil then
- exit
- else
- if tree.Items[0].HasChildren then
- if tree.Selected.HasChildren=true then
- begin
- application.messagebox('该部门包含下级,不能删除','提示',MB_OKCANCEL+mb_iconinformation);
- end
- else
- begin
- s1:=Tree.Selected.Text;
- Epos:=pos('-',s1);//取得'-'在节点名中的位置
- s2:=copy(s1,0,Epos-1);//
- dm.Am_kwzk.Close;
- dm.Am_kwzk.CommandText:='select * from Am_kwzk where kw_dm='+''''+s2+''''+'';
- dm.Am_kwzk.open;
- if dm.Am_kwzk.FieldByName('kw_dm').AsString='' then
- application.MessageBox('当前表中没有数据'+#13#10+'不能删除','提示',mb_ok+mb_iconinformation)
- else
- if application.messagebox('您确实要删除当前记录吗?','提示',MB_OKCANCEL+mb_iconquestion )=IDOK then
- begin
- //-----------------
- s:=dm.am_kwzk.fieldbyname('kwzk_xh').AsString;
- dm.Am_kwzk.Close;
- dm.Am_kwzk.CommandText:='delete from Am_kwzk where kwzk_xh='+''''+s+''''+'';
- dm.Am_kwzk.execute;
- dm.Am_kwzk.Close;
- dm.Am_kwzk.CommandText:='select * from Am_kwzk where kw_dm='+''''+s2+''''+'';
- dm.Am_kwzk.Open;
- //删除表中数据
- end;
- end;
- end;
- //******************************************************************************
- procedure TAm_kwgl.DBGridEh1CellClick(Column: TColumnEh);
- var
- s1:string;
- i:integer;
- begin//--1单击每一行时,使树形控件也变化
- s1:=DBGridEh1.Columns[0].DisplayText;//易犯错误是表格的Columns弄错0,1,2
- dm.sz_kw.Close;
- dm.sz_kw.CommandText:='select * from sz_kw where kw_dm='+''''+s1+''''+'';
- dm.sz_kw.Open;
- Dbediteh1.Text:=dm.sz_kw.fieldbyname('kw_mc').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+'-'+DbEditEh1.text then
- begin
- Tree.Items[i].Selected:=true;
- break;
- end;//end for
- end;//end if
- end;//--1
- procedure TAm_kwgl.N6Click(Sender: TObject);
- begin
- tree.Selected.Collapse(true);
- end;
- procedure TAm_kwgl.N5Click(Sender: TObject);
- begin
- tree.Selected.Expand(true);
- end;
- procedure TAm_kwgl.DeleSClick(Sender: TObject);
- begin
- dele1.Click;
- end;
- procedure TAm_kwgl.PrintExecute(Sender: TObject);
- begin
- am_kwzkp:=Tam_kwzkp.create(self);
- am_kwzkp.quickrep1.preview;
- end;
- end.