U_clsld.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:15k
- unit U_clsld;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, DBCtrls, Buttons, Mask, Grids, DBGrids, ExtCtrls, Db, DBClient,
- ComCtrls, Menus, ImgList, QuickRpt, Qrctrls, variants;
- type
- TfrmClsld = class(TForm)
- ScrollBox2: TScrollBox;
- pnl_detail: TPanel;
- DBGrid: TDBGrid;
- pnl_operate: TPanel;
- btn_insert: TSpeedButton;
- btn_find: TSpeedButton;
- btn_save: TSpeedButton;
- btn_cancel: TSpeedButton;
- btn_delete: TSpeedButton;
- btn_edit: TSpeedButton;
- btn_refresh: TSpeedButton;
- DBNavigator: TDBNavigator;
- pnl_Main: TPanel;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- Label5: TLabel;
- Label6: TLabel;
- Label7: TLabel;
- Label8: TLabel;
- Label9: TLabel;
- Label10: TLabel;
- Label14: TLabel;
- Label15: TLabel;
- Label39: TLabel;
- edtSlzh: TDBEdit;
- edtZdrq: TDBEdit;
- edtGycj: TDBEdit;
- edtWzly: TDBEdit;
- edtCgr: TDBEdit;
- edtHtbh: TDBEdit;
- edtFpje: TDBEdit;
- edtQzyzf: TDBEdit;
- edtFph: TDBEdit;
- edtShr: TDBEdit;
- edtDjbz: TDBEdit;
- cbSfsh: TDBCheckBox;
- cmbCkmc: TDBComboBox;
- pnl_Main1: TPanel;
- Label11: TLabel;
- Label12: TLabel;
- Label13: TLabel;
- edtZg: TDBEdit;
- edtZdr: TDBEdit;
- edtYsr: TDBEdit;
- DataSource_Main: TDataSource;
- DataSource_Detail: TDataSource;
- StatusBar1: TStatusBar;
- btn_cgr: TBitBtn;
- btn_zg: TBitBtn;
- btn_zdr: TBitBtn;
- btn_ysr: TBitBtn;
- Timer1: TTimer;
- pm_Detail: TPopupMenu;
- ImageList1: TImageList;
- pmi_Insert: TMenuItem;
- pmi_Delete: TMenuItem;
- btn_print: TSpeedButton;
- PopupMenu2: TPopupMenu;
- N_Passed: TMenuItem;
- N_NotPassed: TMenuItem;
- N_All: TMenuItem;
- QuickRep: TQuickRep;
- QRBand1: TQRBand;
- QRLabel1: TQRLabel;
- QRLabel2: TQRLabel;
- QRLabel3: TQRLabel;
- QRDBText1: TQRDBText;
- QRDBText2: TQRDBText;
- QRDBText3: TQRDBText;
- QRLabel7: TQRLabel;
- QRLabel8: TQRLabel;
- QRLabel9: TQRLabel;
- QRDBText7: TQRDBText;
- QRDBText8: TQRDBText;
- QRDBText9: TQRDBText;
- QRLabel10: TQRLabel;
- QRDBText10: TQRDBText;
- QRLabel4: TQRLabel;
- QRLabel5: TQRLabel;
- QRLabel6: TQRLabel;
- QRDBText4: TQRDBText;
- QRDBText5: TQRDBText;
- QRDBText6: TQRDBText;
- QRLabel11: TQRLabel;
- QRLabel12: TQRLabel;
- QRLabel13: TQRLabel;
- QRDBText11: TQRDBText;
- QRDBText12: TQRDBText;
- QRDBText13: TQRDBText;
- PageHeaderBand1: TQRBand;
- QRLabel14: TQRLabel;
- QRLabel22: TQRLabel;
- QRSysData1: TQRSysData;
- QRShape1: TQRShape;
- QRSubDetail1: TQRSubDetail;
- QRDBText14: TQRDBText;
- QRDBText15: TQRDBText;
- QRDBText16: TQRDBText;
- QRDBText17: TQRDBText;
- QRDBText18: TQRDBText;
- QRDBText19: TQRDBText;
- QRShape2: TQRShape;
- SummaryBand1: TQRBand;
- QRDBText22: TQRDBText;
- QRDBText24: TQRDBText;
- QRLabel21: TQRLabel;
- QRLabel23: TQRLabel;
- QRLabel24: TQRLabel;
- QRDBText25: TQRDBText;
- QRDBText26: TQRDBText;
- QRDBText27: TQRDBText;
- QRDBText28: TQRDBText;
- QRLabel25: TQRLabel;
- QRLabel26: TQRLabel;
- QRLabel27: TQRLabel;
- PageFooterBand1: TQRBand;
- QRLabel28: TQRLabel;
- QRLabel29: TQRLabel;
- QRSysData2: TQRSysData;
- ColumnHeaderBand1: TQRBand;
- QRLabel15: TQRLabel;
- QRLabel16: TQRLabel;
- QRLabel17: TQRLabel;
- QRLabel18: TQRLabel;
- QRLabel19: TQRLabel;
- QRLabel20: TQRLabel;
- btn_gycj: TBitBtn;
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure btn_insertClick(Sender: TObject);
- procedure btn_editClick(Sender: TObject);
- procedure btn_cancelClick(Sender: TObject);
- procedure btn_saveClick(Sender: TObject);
- procedure btn_cgrClick(Sender: TObject);
- procedure btn_zgClick(Sender: TObject);
- procedure btn_zdrClick(Sender: TObject);
- procedure btn_ysrClick(Sender: TObject);
- procedure btn_refreshClick(Sender: TObject);
- procedure btn_findClick(Sender: TObject);
- procedure btn_deleteClick(Sender: TObject);
- procedure DBGridDblClick(Sender: TObject);
- procedure Timer1Timer(Sender: TObject);
- procedure pmi_InsertClick(Sender: TObject);
- procedure pmi_DeleteClick(Sender: TObject);
- procedure btn_printClick(Sender: TObject);
- procedure FormShow(Sender: TObject);
- procedure N_PassedClick(Sender: TObject);
- procedure N_NotPassedClick(Sender: TObject);
- procedure N_AllClick(Sender: TObject);
- private
- procedure btn_valid;
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- frmClsld: TfrmClsld;
- implementation
- uses U_mainform, WzglDB, u_public, U_fzlr_clbm, GenQ3;
- {$R *.DFM}
- procedure TfrmClsld.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- action := cafree;
- frmClsld := nil;
- end;
- procedure TfrmClsld.btn_insertClick(Sender: TObject);
- begin
- //取消过滤
- DM.CDS_CLSLD.filter := '';
- DM.CDS_CLSLD.filtered := true;
- //数据集处于添加状态
- DM.CDS_CLSLD.Insert;
- edtSlzh.enabled := true;
- //改变组件的有效性
- btn_valid;
- cmbCkmc.SetFocus;
- end;
- procedure TfrmClsld.btn_valid;
- begin
- DBNavigator.enabled := not dbnavigator.enabled;
- btn_insert.enabled := not btn_insert.enabled;
- btn_delete.enabled := not btn_delete.enabled;
- btn_edit.enabled := not btn_edit.enabled;
- btn_cancel.enabled := not btn_cancel.enabled;
- btn_Save.enabled := not btn_Save.enabled;
- btn_find.enabled := not btn_find.enabled;
- btn_refresh.enabled := not btn_refresh.enabled;
- btn_print.enabled := not btn_print.enabled;
- //显示区的切换
- pnl_Main.enabled := not pnl_Main.enabled;
- pnl_Main1.enabled := not pnl_Main1.enabled;
- //DBGrid中2、3、4、5字段状态切换,其他字段仍是只读
- dbgrid.Columns[2].readonly := not dbgrid.Columns[2].readonly;
- dbgrid.Columns[3].readonly := not dbgrid.Columns[3].readonly;
- dbgrid.Columns[4].readonly := not dbgrid.Columns[4].readonly;
- dbgrid.Columns[5].readonly := not dbgrid.Columns[5].readonly;
- //辅助录入按钮的可见性切换
- btn_gycj.visible := not btn_gycj.visible;
- btn_cgr.visible := not btn_cgr.visible;
- btn_zg.visible := not btn_zg.visible;
- btn_zdr.visible := not btn_zdr.visible;
- btn_ysr.visible := not btn_ysr.visible;
- end;
- procedure TfrmClsld.btn_editClick(Sender: TObject);
- begin
- //先判断是否有记录可编辑
- if DM.CDS_CLSLD.recordcount = 0 then
- begin
- application.MessageBox('没有记录不能编辑', '物资管理系统', mb_iconinformation + mb_defbutton1);
- exit;
- end;
- //判断此单据是否已审核过了,如已审核,就不能修改
- if DM.CDS_CLSLD.FieldByName('是否审核').value = true then
- begin
- application.messagebox('此单据已审核,不能编辑', '物资管理系统', mb_iconinformation + mb_defbutton1);
- exit;
- end;
- //使数据集处于编辑状态
- DM.CDS_CLSLD.edit;
- edtSlzh.enabled := false;
- //设置组件有效性
- btn_valid;
- cmbckmc.setfocus;
- end;
- procedure TfrmClsld.btn_cancelClick(Sender: TObject);
- begin
- //撤消刚才的操作
- DM.CDS_CLSLD.CancelUpdates;
- //设置数据显示组件为不可用状态
- btn_valid;
- end;
- procedure TfrmClsld.btn_saveClick(Sender: TObject);
- var
- s_slzh: string;
- begin
- //检查数据的有效性
- if cmbCkmc.text = '' then
- begin
- application.MessageBox('仓库名称不能为空', '物资管理系统', mb_iconinformation + mb_defbutton1);
- cmbCkmc.SetFocus;
- exit;
- end;
- if length(trim(edtSlzh.text)) <> 9 then
- begin
- application.MessageBox('收料字号应为九位', '物资管理系统', mb_iconinformation + mb_defbutton1);
- edtSlzh.SetFocus;
- exit;
- end;
- //判断关键字是否重复
- s_slzh := edtSlzh.Text;
- DM.CDS_CLSLD_INDEX.IndexFieldNames := '收料字号';
- DM.CDS_CLSLD_INDEX.Refresh;
- if DM.CDS_CLSLD.state = dsinsert then
- begin
- if DM.CDS_CLSLD_INDEX.FindKey([s_slzh]) then
- begin
- application.MessageBox('收料字号已重复', '物资管理系统', mb_iconinformation + mb_defbutton1);
- edtSlzh.SetFocus;
- exit;
- end;
- end;
- //提交、保存数据库
- DM.CDS_CLSLD.Post;
- DM.CDS_CLSLD.ApplyUpdates(0);
- //设置数据显示组件为不可用状态
- btn_valid;
- end;
- procedure TfrmClsld.btn_cgrClick(Sender: TObject);
- begin
- DM.CDS_CLSLD.FieldByName('采购人').value := GetEmployeeName;
- end;
- procedure TfrmClsld.btn_zgClick(Sender: TObject);
- begin
- DM.CDS_CLSLD.FieldByName('主管').value := GetEmployeeName;
- end;
- procedure TfrmClsld.btn_zdrClick(Sender: TObject);
- begin
- DM.CDS_CLSLD.FieldByName('制单人').value := GetEmployeeName;
- end;
- procedure TfrmClsld.btn_ysrClick(Sender: TObject);
- begin
- DM.CDS_CLSLD.FieldByName('验收人').value := GetEmployeeName;
- end;
- procedure TfrmClsld.btn_refreshClick(Sender: TObject);
- begin
- DM.CDS_CLSLD.Refresh;
- end;
- procedure TfrmClsld.btn_findClick(Sender: TObject);
- var
- GenQuery: TGenQ3;
- begin
- GenQuery := TGenQ3.Create(self);
- GenQuery.v_TableName := 'WZ_CLSLD_MAIN'; //设置表名
- GenQuery.v_AppServName := frmMain.SocketConnection; //设置应用服务器连接
- GenQuery.v_ProviderName := 'P_General'; //设置获取数据集的提供者
- //==添加定位字段,“;”前表示实际字段名,‘;’后表示实际字段的别名
- GenQuery.v_fieldsstrings.Add('收料字号;收料字号');
- GenQuery.v_fieldsstrings.Add('仓库名称;仓库名称');
- GenQuery.v_fieldsstrings.Add('制单日期;制单日期');
- GenQuery.v_fieldsstrings.Add('供应厂家;供应厂家');
- GenQuery.v_fieldsstrings.Add('物资来源;物资来源');
- GenQuery.v_fieldsstrings.Add('采购人;采购人');
- GenQuery.v_fieldsstrings.Add('合同编号;合同编号');
- GenQuery.v_fieldsstrings.Add('发票金额;发票金额');
- GenQuery.v_fieldsstrings.Add('主管;主管');
- GenQuery.v_fieldsstrings.Add('制单人;制单人');
- GenQuery.v_fieldsstrings.Add('验收人;验收人');
- GenQuery.v_fieldsstrings.Add('审核人;审核人');
- //打开窗口
- if GenQuery.execute then
- begin
- //给CDS_CLSLD_CX的过滤条件赋值
- DM.CDS_CLSLD.filter := GenQuery.V_filtervalue;
- DM.CDS_CLSLD.filtered := true;
- end;
- end;
- procedure TfrmClsld.btn_deleteClick(Sender: TObject);
- begin
- //判断是否有记录可删除
- if DM.CDS_CLSLD.recordcount = 0 then
- begin
- application.MessageBox('没有记录可删除', '物资管理系统', mb_iconinformation + mb_defbutton1);
- exit;
- end;
- //确认删除
- if application.messagebox('请确认是否要删除', '物资管理系统', mb_iconinformation + mb_yesno) = idyes then
- begin
- DM.CDS_CLSLD.delete;
- DM.CDS_CLSLD.applyupdates(0);
- end;
- end;
- procedure TfrmClsld.DBGridDblClick(Sender: TObject);
- begin
- pmi_Insert.click;
- end;
- procedure TfrmClsld.Timer1Timer(Sender: TObject);
- begin
- statusbar1.Panels[2].text := '共有:' + inttostr(DM.CDS_CLSLD.recordcount) + '条记录';
- if DM.CDS_CLSLD.recordcount = 0 then
- statusbar1.panels[1].text := ''
- else if DM.CDS_CLSLD.fieldbyname('是否审核').value = true then
- statusbar1.panels[1].text := '此单据已审核'
- else if (DM.CDS_CLSLD.fieldbyname('是否审核').value = null) or (DM.CDS_CLSLD.fieldbyname('是否审核').value = false) then
- statusbar1.panels[1].text := '此单据未审核';
- statusbar1.refresh;
- end;
- procedure TfrmClsld.pmi_InsertClick(Sender: TObject);
- var
- i: integer;
- s_hint: string;
- begin
- //判断是否在编辑状态下
- if btn_edit.Enabled = true then
- begin
- application.MessageBox('请在编辑或添加状态下添加物资', '物资管理系统', mb_iconinformation + mb_defbutton1);
- exit;
- end;
- //创建辅助录入窗口
- application.createform(TfrmClbm_Fzlr, frmClbm_Fzlr);
- try
- frmClbm_Fzlr.showmodal;
- finally
- frmClbm_Fzlr.free;
- //将选中的材料加到DBGrid中
- for i := Low(ClbmRec) to High(clbmRec) do
- begin
- DM.CDS_CLSLD_DETAIL_INDEX.Active := True;
- DM.CDS_CLSLD_DETAIL_INDEX.refresh;
- DM.CDS_CLSLD_DETAIL_INDEX.Filter := '收料字号=' + '''' + DM.CDS_CLSLD.fieldbyname('收料字号').asstring + '''';
- DM.CDS_CLSLD_DETAIL_INDEX.filtered := true;
- DM.CDS_CLSLD_DETAIL_INDEX.IndexFieldNames := '材料编号';
- //判断是否有重复的物资
- if DM.CDS_CLSLD_DETAIL_INDEX.FindKey([clbmRec[i].clbm]) then
- begin
- s_hint := '已有材料编号为' + clbmRec[i].clbm + '的物资';
- application.MessageBox(Pchar(s_hint), '物资管理系统', mb_iconinformation + mb_defbutton1);
- continue;
- end;
- //添加进DM.CDS_CLSLD_DETAIL
- DM.CDS_CLSLD_DETAIL.insert;
- DM.CDS_CLSLD_DETAIL.fieldbyname('材料编号').value := ClbmRec[i].clbm;
- DM.CDS_CLSLD_DETAIL.fieldbyname('材料名称').value := ClbmRec[i].clmc;
- DM.CDS_CLSLD_DETAIL.fieldbyname('规格型号').value := ClbmRec[i].ggxh;
- DM.CDS_CLSLD_DETAIL.fieldbyname('计量单位').value := ClbmRec[i].jldw;
- DM.CDS_CLSLD_DETAIL.fieldbyname('计划单价').value := ClbmRec[i].jhdj;
- DM.CDS_CLSLD_DETAIL.fieldbyname('单价单位').value := ClbmRec[i].djdw;
- DM.CDS_CLSLD_DETAIL.fieldbyname('凭证数量').value := 0.0;
- DM.CDS_CLSLD_DETAIL.fieldbyname('实收数量').value := 0.0;
- DM.CDS_CLSLD_DETAIL.post;
- end;
- end;
- dbgrid.Refresh;
- end;
- procedure TfrmClsld.pmi_DeleteClick(Sender: TObject);
- begin
- //判断是否有记录可删除
- if DM.CDS_CLSLD_DETAIL.recordcount = 0 then
- begin
- application.MessageBox('没有记录可删除', '物资管理系统', mb_iconinformation + mb_defbutton1);
- exit;
- end;
- //判断是否在浏览状态下
- if (btn_edit.enabled = false) then
- begin
- application.MessageBox('请在浏览状态下删除物资', '物资管理系统', mb_iconinformation + mb_defbutton1);
- exit;
- end;
- if application.messagebox('请确认是否要删除', '物资管理系统', mb_iconinformation + mb_yesno) = idyes then
- begin
- DM.CDS_CLSLD_DETAIL.delete;
- end;
- DM.CDS_CLSLD.applyupdates(0);
- end;
- procedure TfrmClsld.btn_printClick(Sender: TObject);
- var
- s_filter: string;
- my_bookmark: Tbookmark;
- begin
- s_filter := DM.CDS_CLSLD.Filter;
- my_bookmark := DM.CDS_CLSLD.GetBookmark;
- DM.CDS_CLSLD.Filter := '收料字号=' + '''' + DM.CDS_CLSLD.fieldbyname('收料字号').asstring + '''';
- DM.CDS_CLSLD.Filtered := true;
- quickrep.Preview;
- DM.CDS_CLSLD.Filter := s_filter;
- DM.CDS_CLSLD.Filtered := true;
- DM.CDS_CLSLD.GotoBookmark(my_bookmark);
- end;
- procedure TfrmClsld.FormShow(Sender: TObject);
- var
- s_value: string;
- begin
- //激活仓库信息表
- DM.CDS_CKXX_INDEX.Active := True;
- DM.CDS_CKXX_INDEX.First;
- cmbCkmc.Items.Clear ;
- //循环向下拉框写入仓库名称
- while not DM.CDS_CKXX_INDEX.eof do
- begin
- s_value := DM.CDS_CKXX_INDEX.fieldbyname('仓库名称').asstring;
- cmbCkmc.Items.Add(s_value);
- DM.CDS_CKXX_INDEX.next;
- end;
- with DM do
- begin
- CDS_CLSLD_DETAIL.Close;
- CDS_CLSLD.Close;
- CDS_CLSLD_INDEX.Close;
- CDS_CLSLD_DETAIL_INDEX.Close;
- CDS_CLSLD.Open;
- CDS_CLSLD_DETAIL.Open;
- CDS_CLSLD_INDEX.Open;
- CDS_CLSLD_DETAIL.Open;
- end;
- end;
- procedure TfrmClsld.N_PassedClick(Sender: TObject);
- begin
- DM.CDS_CLSLD.DisableControls;
- DM.CDS_CLSLD.Filtered := False;
- DM.CDS_CLSLD.Filter := '是否审核=True';
- DM.CDS_CLSLD.Filtered := True;
- DM.CDS_CLSLD.EnableControls;
- end;
- procedure TfrmClsld.N_NotPassedClick(Sender: TObject);
- begin
- DM.CDS_CLSLD.DisableControls;
- DM.CDS_CLSLD.Filtered := False;
- DM.CDS_CLSLD.Filter := '是否审核=False';
- DM.CDS_CLSLD.Filtered := True;
- DM.CDS_CLSLD.EnableControls;
- end;
- procedure TfrmClsld.N_AllClick(Sender: TObject);
- begin
- DM.CDS_CLSLD.Filtered := False;
- end;
- end.