U_dqflb.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:12k
- unit U_dqflb;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ComCtrls, ExtCtrls, Db, DBClient, StdCtrls, Mask, DBCtrls, Menus, ImgList,
- Grids, DBGrids;
- type
- TfrmDqflb = class(TForm)
- Panel1: TPanel;
- StatusBar1: TStatusBar;
- Splitter1: TSplitter;
- TreeView1: TTreeView;
- DataSource1: TDataSource;
- PopupMenu1: TPopupMenu;
- ImageList1: TImageList;
- N_refresh: TMenuItem;
- N_insert: TMenuItem;
- N_edit: TMenuItem;
- N_delete: TMenuItem;
- N_cancel: TMenuItem;
- N_save: TMenuItem;
- N7: TMenuItem;
- Panel2: TPanel;
- PageControl1: TPageControl;
- TabSheet1: TTabSheet;
- TabSheet2: TTabSheet;
- Panel3: TPanel;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- DBEdit1: TDBEdit;
- DBEdit2: TDBEdit;
- DBGrid1: TDBGrid;
- ImageList2: TImageList;
- PopupMenu2: TPopupMenu;
- N1: TMenuItem;
- procedure FormShow(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure N_insertClick(Sender: TObject);
- procedure N_saveClick(Sender: TObject);
- procedure N_refreshClick(Sender: TObject);
- procedure N_editClick(Sender: TObject);
- procedure N_cancelClick(Sender: TObject);
- procedure N_deleteClick(Sender: TObject);
- procedure TreeView1Click(Sender: TObject);
- procedure N1Click(Sender: TObject);
- procedure DBGrid1TitleClick(Column: TColumn);
- procedure FormCreate(Sender: TObject);
- private
- procedure button_valid();
- { Private declarations }
- public
- procedure refresh;
- { Public declarations }
- end;
- var
- frmDqflb: TfrmDqflb;
- mynode_global, mynode_global1: Ttreenode;
- gs_global: string;
- b_pd: bool; //用于判断是电击添加还是编辑
- implementation
- uses U_mainform, U_general_print, WzglDB, u_public;
- {$R *.DFM}
- procedure TfrmDqflb.refresh;
- var
- mynode_1, mynode_2, mynode_3, mynode_4: Ttreenode;
- s_bm_1, s_bm_2, s_bm_3, s_bm_4: string;
- s_mc_1, s_mc_2, s_mc_3, s_mc_4: string;
- begin
- statusbar1.panels[0].text := '正在进行数据处理...';
- statusbar1.refresh;
- treeview1.Items.clear;
- mynode_1 := treeview1.Items.Add(treeview1.topitem, '地区分类');
- mynode_1.imageindex := 0;
- mynode_1.stateindex := -1;
- mynode_1.Selectedindex := 1;
- DM.CDS_DQFLB.indexfieldnames := '类别编码';
- DM.CDS_DQFLB.First;
- while not DM.CDS_DQFLB.Eof do
- begin
- s_bm_1 := DM.CDS_DQFLB.fieldbyname('类别编码').asstring;
- s_mc_1 := DM.CDS_DQFLB.fieldbyname('类别名称').asstring;
- if length(trim(s_bm_1)) = 2 then
- begin
- mynode_2 := treeview1.items.addchild(mynode_1, '(' + s_bm_1 + ') ' + s_mc_1);
- mynode_2.imageindex := 0;
- mynode_2.stateindex := -1;
- mynode_2.Selectedindex := 1;
- end;
- if length(trim(s_bm_1)) = 6 then
- begin
- mynode_3 := treeview1.items.addchild(mynode_2, '(' + s_bm_1 + ') ' + s_mc_1);
- mynode_3.imageindex := 0;
- mynode_3.stateindex := -1;
- mynode_3.Selectedindex := 1;
- end;
- if length(trim(s_bm_1)) = 11 then
- begin
- mynode_4 := treeview1.items.addchild(mynode_3, '(' + s_bm_1 + ') ' + s_mc_1);
- mynode_4.imageindex := 0;
- mynode_4.stateindex := -1;
- mynode_4.Selectedindex := 1;
- end;
- DM.CDS_DQFLB.next;
- end;
- statusbar1.panels[0].text := '';
- statusbar1.refresh;
- end;
- procedure TfrmDqflb.FormShow(Sender: TObject);
- begin
- refresh;
- treeview1.topitem.Selected := true;
- end;
- procedure TfrmDqflb.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- action := cafree;
- frmDqflb := nil;
- end;
- procedure TfrmDqflb.N_insertClick(Sender: TObject);
- begin
- b_pd := true;
- mynode_global := treeview1.selected;
- if mynode_global.level = 3 then
- begin
- Application.messagebox('最底层不能添加,请在上层添加', '物资管理系统', mb_iconinformation + mb_defbutton1);
- exit;
- end;
- button_valid();
- if mynode_global.level = 0 then
- begin
- DM.CDS_DQFLB.Insert;
- DM.CDS_DQFLB.FieldByName('类别编码').editmask := '99;1;_';
- pagecontrol1.ActivePageIndex := 0;
- dbedit1.setfocus;
- end;
- if mynode_global.level = 1 then
- begin
- gs_global := copy(mynode_global.text, 2, 2);
- DM.CDS_DQFLB.insert;
- DM.CDS_DQFLB.FieldByName('类别编码').editmask := '99-999;1;_';
- pagecontrol1.ActivePageIndex := 0;
- dbedit1.setfocus;
- dbedit1.text := gs_global;
- end;
- if mynode_global.level = 2 then
- begin
- DM.CDS_DQFLB.FieldByName('类别编码').editmask := '99-999-9999;1;_';
- gs_global := copy(mynode_global.text, 2, 6);
- DM.CDS_DQFLB.insert;
- pagecontrol1.ActivePageIndex := 0;
- dbedit1.setfocus;
- dbedit1.text := gs_global;
- end;
- end;
- procedure TfrmDqflb.button_valid;
- begin
- dbedit1.enabled := not dbedit1.enabled;
- dbedit2.enabled := not dbedit2.enabled;
- n_insert.enabled := not n_insert.enabled;
- n_delete.enabled := not n_delete.enabled;
- n_edit.enabled := not n_edit.enabled;
- n_cancel.enabled := not n_cancel.enabled;
- n_save.enabled := not n_save.enabled;
- n_refresh.enabled := not n_refresh.enabled;
- treeview1.enabled := not treeview1.Enabled;
- end;
- procedure TfrmDqflb.N_saveClick(Sender: TObject);
- var
- s_bm, s_mc: string;
- begin
- if mynode_global.level = 0 then
- begin
- if length(trim(dbedit1.text)) <> 2 then
- begin
- Application.messagebox('编码应为两位', '物资管理系统', mb_iconinformation + mb_defbutton1);
- exit;
- end;
- end;
- if mynode_global.level = 1 then
- begin
- if copy(dbedit1.text, 1, 2) <> copy(mynode_global.text, 2, 2) then
- begin
- Application.messagebox('前面两位不能变,请确认!', '物资管理系统', mb_iconinformation + mb_defbutton1);
- dbedit1.text := copy(mynode_global.text, 2, 2);
- exit;
- end;
- if length(trim(dbedit1.text)) <> 6 then
- begin
- Application.messagebox('编码应为六位', '物资管理系统', mb_iconinformation + mb_defbutton1);
- exit;
- end;
- end;
- if mynode_global.level = 2 then
- begin
- if copy(dbedit1.text, 1, 6) <> copy(mynode_global.text, 2, 6) then
- begin
- Application.messagebox('前面六位不能变,请确认!', '物资管理系统', mb_iconinformation + mb_defbutton1);
- dbedit1.text := copy(mynode_global.text, 2, 6);
- exit;
- end;
- if length(trim(dbedit1.text)) <> 11 then
- begin
- Application.messagebox('编码应为十一位', '物资管理系统', mb_iconinformation + mb_defbutton1);
- exit;
- end;
- end;
- s_bm := dbedit1.text;
- s_mc := dbedit2.text;
- DM.CDS_DQFLB_INDEX.IndexFieldNames := '类别编码';
- DM.CDS_DQFLB_INDEX.Refresh;
- if DM.CDS_DQFLB.state = dsinsert then
- begin
- if DM.CDS_DQFLB_INDEX.FindKey([s_bm]) then
- begin
- application.MessageBox('类别编码已重复', '物资管理系统', mb_iconinformation + mb_defbutton1);
- pagecontrol1.ActivePageIndex := 0;
- dbedit1.SetFocus;
- exit;
- end;
- end;
- if b_pd = true then
- treeview1.items.addchild(mynode_global, '(' + s_bm + ') ' + s_mc)
- else
- begin
- treeview1.Items.Delete(mynode_global1);
- treeview1.items.addchild(mynode_global, '(' + s_bm + ') ' + s_mc);
- end;
- DM.CDS_DQFLB.post;
- DM.CDS_DQFLB.applyupdates(0);
- button_valid;
- end;
- procedure TfrmDqflb.N_refreshClick(Sender: TObject);
- begin
- refresh;
- treeview1.TopItem.selected := true;
- end;
- procedure TfrmDqflb.N_editClick(Sender: TObject);
- begin
- b_pd := false;
- mynode_global1 := treeview1.selected;
- if mynode_global1.level = 0 then
- begin
- Application.messagebox('最顶层不能添加,请在上层添加', '物资管理系统', mb_iconinformation + mb_defbutton1);
- exit;
- end;
- button_valid();
- mynode_global := mynode_global1.parent;
- if mynode_global.level = 0 then
- begin
- DM.CDS_DQFLB.edit;
- DM.CDS_DQFLB.FieldByName('类别编码').editmask := '99;1;_';
- pagecontrol1.ActivePageIndex := 0;
- dbedit1.setfocus;
- end;
- if mynode_global.level = 1 then
- begin
- gs_global := copy(mynode_global.text, 2, 2);
- DM.CDS_DQFLB.edit;
- DM.CDS_DQFLB.FieldByName('类别编码').editmask := '99-999;1;_';
- pagecontrol1.ActivePageIndex := 0;
- dbedit1.setfocus;
- end;
- if mynode_global.level = 2 then
- begin
- DM.CDS_DQFLB.FieldByName('类别编码').editmask := '99-999-9999;1;_';
- gs_global := copy(mynode_global.text, 2, 6);
- DM.CDS_DQFLB.edit;
- pagecontrol1.ActivePageIndex := 0;
- dbedit1.setfocus;
- end;
- end;
- procedure TfrmDqflb.N_cancelClick(Sender: TObject);
- begin
- DM.CDS_DQFLB.cancel;
- button_valid();
- end;
- procedure TfrmDqflb.N_deleteClick(Sender: TObject);
- var
- mynode_1: Ttreenode;
- begin
- mynode_1 := treeview1.selected;
- if mynode_1.level = 0 then
- exit;
- if mynode_1.level = 3 then
- begin
- if Application.messagebox('请确认是否要删除', '物资管理系统', mb_iconinformation + mb_yesno) = idyes then
- begin
- DM.CDS_DQFLB.Delete;
- DM.CDS_DQFLB.ApplyUpdates(0);
- treeview1.Items.delete(mynode_1);
- end;
- end;
- if mynode_1.level = 2 then
- begin
- if Application.messagebox('请确认是否要删除,并且子目录也将被删除', '物资管理系统', mb_iconinformation + mb_yesno) = idyes then
- begin
- DM.CDS_DQFLB.filter := 'substring(类别编码,1,6)=' + '''' + copy(mynode_1.text, 2, 6) + '''';
- DM.CDS_DQFLB.filtered := true;
- DM.CDS_DQFLB.first;
- while not DM.CDS_DQFLB.eof do
- begin
- DM.CDS_DQFLB.Delete;
- end;
- DM.CDS_DQFLB.ApplyUpdates(0);
- treeview1.Items.delete(mynode_1);
- DM.CDS_DQFLB.filtered := false;
- end;
- end;
- if mynode_1.level = 1 then
- begin
- if Application.messagebox('请确认是否要删除,并且子目录也将被删除', '物资管理系统', mb_iconinformation + mb_yesno) = idyes then
- begin
- DM.CDS_DQFLB.filter := 'substring(类别编码,1,2)=' + '''' + copy(mynode_1.text, 2, 2) + '''';
- DM.CDS_DQFLB.filtered := true;
- DM.CDS_DQFLB.first;
- while not DM.CDS_DQFLB.eof do
- begin
- DM.CDS_DQFLB.Delete;
- end;
- DM.CDS_DQFLB.ApplyUpdates(0);
- treeview1.Items.delete(mynode_1);
- DM.CDS_DQFLB.filtered := false;
- end;
- end;
- end;
- procedure TfrmDqflb.TreeView1Click(Sender: TObject);
- var
- mynode: Ttreenode;
- s_value_1, s_value_2, s_value_3, s_value_4: string;
- begin
- if treeview1.Items.Count = 0 then
- exit;
- mynode := treeview1.selected;
- if mynode.Level = 1 then
- begin
- s_value_1 := copy(mynode.text, 2, 2);
- DM.CDS_DQFLB.IndexFieldNames := '类别编码';
- DM.CDS_DQFLB.findkey([s_value_1]);
- DM.CDS_DQFLB.FieldByName('类别编码').editmask := '99;1;_';
- end;
- if mynode.Level = 2 then
- begin
- s_value_1 := copy(mynode.text, 2, 6);
- DM.CDS_DQFLB.IndexFieldNames := '类别编码';
- DM.CDS_DQFLB.FindKey([s_value_1]);
- DM.CDS_DQFLB.FieldByName('类别编码').editmask := '99-999;1;_';
- end;
- if mynode.Level = 3 then
- begin
- s_value_1 := copy(mynode.text, 2, 11);
- DM.CDS_DQFLB.IndexFieldNames := '类别编码';
- DM.CDS_DQFLB.FindKey([s_value_1]);
- DM.CDS_DQFLB.FieldByName('类别编码').editmask := '99-999-9999;1;_';
- end;
- end;
- procedure TfrmDqflb.N1Click(Sender: TObject);
- begin
- application.createform(TfrmPrint, frmPrint);
- frmPrint.srclist.items.add('类别编码');
- frmPrint.srclist.items.add('类别名称');
- frmPrint.vps_tablename := 'WZ_Dqflb';
- frmPrint.vps_filter := DM.CDS_DQFLB.Filter;
- frmPrint.vps_index := DM.CDS_DQFLB.IndexFieldNames;
- frmPrint.edtPrintTitle.Text := '地区分类表';
- try
- frmPrint.showmodal;
- finally
- frmPrint.free;
- end;
- end;
- procedure TfrmDqflb.DBGrid1TitleClick(Column: TColumn);
- begin
- dbGridSort(dbgrid1,column);
- end;
- procedure TfrmDqflb.FormCreate(Sender: TObject);
- begin
- With DM do
- begin
- CDS_DQFLB.Active := True;
- CDS_DQFLB_INDEX.Active := True;
- end;
- end;
- end.