unit u_cw_kemu; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, ADODB, dxExEdtr, dxCntner, dxTL, dxDBCtrl, dxDBGrid, bsSkinCtrls, StdCtrls, RxLookup, ExtCtrls, ComCtrls, bsSkinTabs, Mask, wwdbedit, Wwdotdot, Wwdbcomb, bsSkinBoxCtrls, CheckLst, DBCtrls, bsdbctrls, Grids, DBGridEh, Menus, dxDBTLCl, dxGrClms; type Tfrm_cw_kemu = class(TForm) t_crm_client: TADOQuery; t_crm_client1: TDataSource; t_sys_bank: TADOQuery; t_sys_bank1: TDataSource; bsSkinPageControl1: TbsSkinPageControl; bsSkinTabSheet1: TbsSkinTabSheet; bsSkinTabSheet2: TbsSkinTabSheet; Label4: TLabel; bsSkinTabSheet3: TbsSkinTabSheet; DBGridEh2: TDBGridEh; bsSkinTabSheet4: TbsSkinTabSheet; t_sys_department: TADOQuery; t_sys_department1: TDataSource; DBGridEh3: TDBGridEh; t_sys_employee: TADOQuery; t_sys_employee1: TDataSource; DBGridEh4: TDBGridEh; bsSkinTabSheet5: TbsSkinTabSheet; ACCITEMS: TADOQuery; DataSource1: TDataSource; DBGridEh5: TDBGridEh; bsSkinPanel1: TbsSkinPanel; bsSkinButton5: TbsSkinButton; Label1: TLabel; bsSkinPanel2: TbsSkinPanel; bsSkinTabSheet6: TbsSkinTabSheet; t_code_currency: TADOQuery; t_code_currency1: TDataSource; DBGridEh6: TDBGridEh; bsSkinButton9: TbsSkinButton; bsSkinPanel3: TbsSkinPanel; lbl1: TLabel; t_cw_design1: TDataSource; t_cw_design: TADOQuery; DBEdit5: TDBEdit; Label2: TLabel; DBEdit1: TDBEdit; DBEdit2: TDBEdit; Label3: TLabel; DBEdit3: TDBEdit; Label5: TLabel; dxDBGrid1: TdxDBGrid; dxDBGrid1Column1: TdxDBGridColumn; dxDBGrid1Column2: TdxDBGridColumn; dxDBGrid1Column3: TdxDBGridColumn; dxDBGrid1Column4: TdxDBGridColumn; dxDBGrid1Column5: TdxDBGridColumn; bsSkinTabSheet7: TbsSkinTabSheet; DBGridEh1: TDBGridEh; t_code_stlmode: TADOQuery; t_code_stlmode1: TDataSource; Edit1: TEdit; Label15: TLabel; Label16: TLabel; Edit2: TEdit; Label17: TLabel; Edit3: TEdit; bsSkinButton8: TbsSkinButton; bsSkinButton1: TbsSkinButton; DBNavigator1: TDBNavigator; bsSkinComboBox1: TbsSkinComboBox; Label6: TLabel; PopupMenu1: TPopupMenu; N1: TMenuItem; bsSkinTabSheet8: TbsSkinTabSheet; dxDBGrid2: TdxDBGrid; dxDBGridColumn1: TdxDBGridColumn; dxDBGridColumn2: TdxDBGridColumn; t_crm_client_acc1: TDataSource; t_crm_client_acc: TADOQuery; dxDBGrid2Column3: TdxDBGridColumn; bsSkinTabSheet9: TbsSkinTabSheet; DBGridEh7: TDBGridEh; t_code_fee: TADOQuery; t_code_fee1: TDataSource; dxDBGrid1Column6: TdxDBGridPickColumn; dxDBGrid1Column7: TdxDBGridColumn; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure bsSkinButton5Click(Sender: TObject); procedure bsSkinButton1Click(Sender: TObject); procedure bsSkinButton2Click(Sender: TObject); procedure bsSkinButton6Click(Sender: TObject); procedure t_cw_kemu_seaeAfterInsert(DataSet: TDataSet); procedure t_cw_kemu_seaiAfterInsert(DataSet: TDataSet); procedure t_cw_kemu_aireAfterInsert(DataSet: TDataSet); procedure t_cw_kemu_airiAfterInsert(DataSet: TDataSet); procedure t_cw_kemu_seaeBeforeInsert(DataSet: TDataSet); procedure bsSkinButton4Click(Sender: TObject); procedure bsSkinButton7Click(Sender: TObject); procedure bsSkinButton3Click(Sender: TObject); procedure wwDBComboBox1Enter(Sender: TObject); procedure bsSkinButton10Click(Sender: TObject); procedure bsSkinButton12Click(Sender: TObject); procedure bsSkinButton18Click(Sender: TObject); procedure bsSkinButton14Click(Sender: TObject); procedure bsSkinButton9Click(Sender: TObject); procedure bsSkinButton11Click(Sender: TObject); procedure bsSkinButton17Click(Sender: TObject); procedure bsSkinButton13Click(Sender: TObject); procedure t_cw_kemuPostError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); procedure t_cw_kemu_seaePostError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); procedure t_cw_kemu_seaiPostError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); procedure t_cw_kemu_airePostError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); procedure t_cw_kemu_airiPostError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); procedure FormShow(Sender: TObject); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure ACCITEMSAfterInsert(DataSet: TDataSet); procedure bsSkinButton8Click(Sender: TObject); procedure dxDBGrid1CustomDraw(Sender: TObject; ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxDBTreeListColumn; const AText: String; AFont: TFont; var AColor: TColor; ASelected, AFocused: Boolean; var ADone: Boolean); procedure N1Click(Sender: TObject); procedure t_crm_client_accAfterInsert(DataSet: TDataSet); procedure DBGridEh5DblClick(Sender: TObject); procedure t_crm_client_accBeforeDelete(DataSet: TDataSet); procedure t_crm_clientBeforePost(DataSet: TDataSet); private { Private declarations } public { Public declarations } function GetCorpUseStatus(sname:string):boolean; function GetAccCorpUseStatus(CORPID:string):boolean; end; var frm_cw_kemu: Tfrm_cw_kemu; implementation uses u_main, my_sys_function, u_data_share; {$R *.dfm} function Tfrm_cw_kemu.GetCorpUseStatus(sname:string):boolean; var aAdoQuery:TAdoQuery; begin Result:=false; aAdoQuery:=CreateAdoQuery; with aAdoQuery do try Close;SQL.Clear; SQL.Add('select top 1 客户名称 from t_ch_fee'); SQL.Add('where 客户名称='+''''+sname+''''); Open; Result:=RecordCount>=1; finally Free; end; end; function Tfrm_cw_kemu.GetAccCorpUseStatus(CORPID:string):boolean; var aAdoQuery:TAdoQuery; begin Result:=false; aAdoQuery:=CreateAdoQuery; with aAdoQuery do try Close;SQL.Clear; SQL.Add('select top 1 CORPID from vouItems'); SQL.Add('where CORPID='+''''+CORPID+''''); Open; Result:=RecordCount>=1; finally Free; end; end; procedure Tfrm_cw_kemu.FormClose(Sender: TObject; var Action: TCloseAction); begin frm_cw_kemu.Hide; frm_cw_kemu.ManualFloat(frm_cw_kemu.BoundsRect ); frm_main.freeTabs('frm_cw_kemu'); action:=cafree; frm_cw_kemu:=nil; end; procedure Tfrm_cw_kemu.bsSkinButton5Click(Sender: TObject); begin close; end; procedure Tfrm_cw_kemu.bsSkinButton1Click(Sender: TObject); begin sys_print('客户财务代码',2,nil,nil, nil,nil,nil,t_crm_client1,nil,nil,nil,nil,nil); // table_post(t_cw_design); end; procedure Tfrm_cw_kemu.bsSkinButton2Click(Sender: TObject); begin // table_cancel(t_cw_design); end; procedure Tfrm_cw_kemu.bsSkinButton6Click(Sender: TObject); begin // table_delete(t_cw_kemu); end; procedure Tfrm_cw_kemu.t_cw_kemu_seaeAfterInsert(DataSet: TDataSet); begin { t_cw_kemu_seae['业务种类']:='海运出口'; t_cw_kemu_seae['科目类别']:=t_cw_kemu['科目类别']; } end; procedure Tfrm_cw_kemu.t_cw_kemu_seaiAfterInsert(DataSet: TDataSet); begin { t_cw_kemu_seai['业务种类']:='海运进口'; t_cw_kemu_seai['科目类别']:=t_cw_kemu['科目类别']; } end; procedure Tfrm_cw_kemu.t_cw_kemu_aireAfterInsert(DataSet: TDataSet); begin { t_cw_kemu_aire['业务种类']:='空运出口'; t_cw_kemu_aire['科目类别']:=t_cw_kemu['科目类别']; } end; procedure Tfrm_cw_kemu.t_cw_kemu_airiAfterInsert(DataSet: TDataSet); begin { t_cw_kemu_airi['业务种类']:='空运进口'; t_cw_kemu_airi['科目类别']:=t_cw_kemu['科目类别']; } end; procedure Tfrm_cw_kemu.t_cw_kemu_seaeBeforeInsert(DataSet: TDataSet); begin { if t_cw_kemu.IsEmpty then exit; table_post(t_cw_kemu); } end; procedure Tfrm_cw_kemu.bsSkinButton4Click(Sender: TObject); begin // table_post(t_cw_kemu); end; procedure Tfrm_cw_kemu.bsSkinButton7Click(Sender: TObject); begin // table_cancel(t_cw_kemu); end; procedure Tfrm_cw_kemu.bsSkinButton3Click(Sender: TObject); begin // t_cw_kemu.insert; end; procedure Tfrm_cw_kemu.wwDBComboBox1Enter(Sender: TObject); begin { if t_cw_kemu_seae.IsEmpty and t_cw_kemu_seai.IsEmpty and t_cw_kemu_aire.IsEmpty and t_cw_kemu_airi.IsEmpty then begin wwDBComboBox1.ReadOnly:=false; end else begin wwDBComboBox1.ReadOnly:=true; end; } end; procedure Tfrm_cw_kemu.bsSkinButton10Click(Sender: TObject); begin //table_delete(t_cw_kemu_seae); end; procedure Tfrm_cw_kemu.bsSkinButton12Click(Sender: TObject); begin // table_delete(t_cw_kemu_seai); end; procedure Tfrm_cw_kemu.bsSkinButton18Click(Sender: TObject); begin // table_delete(t_cw_kemu_aire); end; procedure Tfrm_cw_kemu.bsSkinButton14Click(Sender: TObject); begin // table_delete(t_cw_kemu_airi); end; procedure Tfrm_cw_kemu.bsSkinButton9Click(Sender: TObject); begin if t_crm_client.state in [dsedit,dsinsert] then t_crm_client.post; { if not t_cw_kemu_seae.Locate('费用类别',frm_data_share.t_code_fee_type.fieldbyname('费用类别').asstring,[])then begin t_cw_kemu_seae.insert; t_cw_kemu_seae['费用类别']:=frm_data_share.t_code_fee_type.fieldbyname('费用类别').asstring; t_cw_kemu_seae.post; end; } end; procedure Tfrm_cw_kemu.bsSkinButton11Click(Sender: TObject); begin { if not t_cw_kemu_seai.Locate('费用类别',frm_data_share.t_code_fee_type.fieldbyname('费用类别').asstring,[])then begin t_cw_kemu_seai.insert; t_cw_kemu_seai['费用类别']:=frm_data_share.t_code_fee_type.fieldbyname('费用类别').asstring; t_cw_kemu_seai.post; end; } end; procedure Tfrm_cw_kemu.bsSkinButton17Click(Sender: TObject); begin { if not t_cw_kemu_aire.Locate('费用类别',frm_data_share.t_code_fee_type.fieldbyname('费用类别').asstring,[])then begin t_cw_kemu_aire.insert; t_cw_kemu_aire['费用类别']:=frm_data_share.t_code_fee_type.fieldbyname('费用类别').asstring; t_cw_kemu_aire.post; end; } end; procedure Tfrm_cw_kemu.bsSkinButton13Click(Sender: TObject); begin { if not t_cw_kemu_airi.Locate('费用类别',frm_data_share.t_code_fee_type.fieldbyname('费用类别').asstring,[])then begin t_cw_kemu_airi.insert; t_cw_kemu_airi['费用类别']:=frm_data_share.t_code_fee_type.fieldbyname('费用类别').asstring; t_cw_kemu_airi.post; end; } end; procedure Tfrm_cw_kemu.t_cw_kemuPostError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); begin if pos('科目代码',UpperCase(E.Message))<>0 then begin showmessage('你所输入的科目代码重复请重新输入!'); abort; end; end; procedure Tfrm_cw_kemu.t_cw_kemu_seaePostError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); begin { if pos('PRIMARY',UpperCase(E.Message))<>0 then begin showmessage('你所输入的费用类别重复请重新输入!'); t_cw_kemu_seae.cancel; abort; end; } end; procedure Tfrm_cw_kemu.t_cw_kemu_seaiPostError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); begin { if pos('PRIMARY',UpperCase(E.Message))<>0 then begin showmessage('你所输入的费用类别重复请重新输入!'); t_cw_kemu_seai.cancel; abort; end; } end; procedure Tfrm_cw_kemu.t_cw_kemu_airePostError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); begin { if pos('PRIMARY',UpperCase(E.Message))<>0 then begin showmessage('你所输入的费用类别重复请重新输入!'); t_cw_kemu_aire.cancel; abort; end; } end; procedure Tfrm_cw_kemu.t_cw_kemu_airiPostError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); begin { if pos('PRIMARY',UpperCase(E.Message))<>0 then begin showmessage('你所输入的费用类别重复请重新输入!'); t_cw_kemu_airi.cancel; abort; end; } end; procedure Tfrm_cw_kemu.FormShow(Sender: TObject); begin if not t_crm_client.Active then t_crm_client.open; if not t_sys_department.Active then t_sys_department.open; if not t_sys_employee.Active then t_sys_employee.open; if not t_sys_bank.Active then t_sys_bank.open; if not accitems.Active then accitems.open; if not t_sys_bank.Active then t_sys_bank.open; if not t_code_currency.Active then t_code_currency.Open; if not t_cw_design.Active then t_cw_design.Open; if not t_code_stlmode.Active then t_code_stlmode.Open; if not t_code_fee.Active then t_code_fee.Open; if not t_crm_client_acc.Active then t_crm_client_acc.Open; { with t_crm_client do begin First; while not eof do begin if not FieldByName('是否使用').AsBoolean then begin if GetCorpUseStatus(FieldByName('客户简称').asstring) then begin Edit; FieldByName('是否使用').AsBoolean:=true; post; end; end; Next; end; end; } dxDBGrid1Column1.ReadOnly:=true; dxDBGrid1Column2.ReadOnly:=true; dxDBGrid1Column3.ReadOnly:=true; dxDBGrid2Column3.ReadOnly:=true; end; procedure Tfrm_cw_kemu.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin if t_crm_client.state in [dsedit] then t_crm_client.post; t_crm_client.close; if t_sys_department.state in [dsedit] then t_sys_department.post; t_sys_department.close; if t_sys_employee.state in [dsedit] then t_sys_employee.post; t_sys_employee.close; if t_sys_bank.state in [dsedit] then t_sys_bank.post; t_sys_bank.close; if accitems.state in [dsedit] then accitems.post; accitems.close; if t_sys_bank.state in [dsedit] then t_sys_bank.post; t_sys_bank.close; if t_code_currency.state in [dsedit] then t_code_currency.post; t_code_currency.close; if t_cw_design.state in [dsedit] then t_cw_design.post; t_cw_design.close; if t_code_stlmode.state in [dsedit] then t_code_stlmode.post; t_code_stlmode.close; if t_code_fee.state in [dsedit] then t_code_fee.post; t_code_fee.close; CanClose:=true; end; procedure Tfrm_cw_kemu.ACCITEMSAfterInsert(DataSet: TDataSet); begin ACCITEMS['DETAILED']:='T'; ACCITEMS['DC']:='D'; ACCITEMS['FCY']:='F'; ACCITEMS['DEPTACC']:='F'; ACCITEMS['EMPLACC']:='F'; ACCITEMS['CORPACC']:='F'; ACCITEMS['ITEMACC']:='F'; end; procedure Tfrm_cw_kemu.bsSkinButton8Click(Sender: TObject); var str:widestring; begin if t_crm_client.state in [dsedit,dsinsert] then t_crm_client.post; str:='where 客户性质<>'+''''+'目标'+''''; if Edit1.text<>''then begin str:=str+' and 代码 like '+''''+'%'+Edit1.text+'%'+''''; end; if Edit2.text<>''then begin str:=str+' and 客户简称 like '+''''+'%'+Edit2.text+'%'+''''; end; if Edit3.text<>''then begin str:=str+' and 客户全称 like '+''''+'%'+Edit3.text+'%'+''''; end; case bsSkinComboBox1.ItemIndex of 0: begin str:=str+' and (((财务应收帐款代码='''') or (财务应收帐款代码 is null)) and 客户简称 in (select 客户名称 from t_ch_fee where 类型=''收''))'; end; 1: begin str:=str+' and (((财务应付帐款代码='''') or (财务应付帐款代码 is null)) and 客户简称 in (select 客户名称 from t_ch_fee where 类型=''付''))'; end; end; t_crm_client.close; t_crm_client.sql.clear; t_crm_client.sql.add('select * from t_crm_client '+str+' order by 代码'); t_crm_client.open; end; procedure Tfrm_cw_kemu.dxDBGrid1CustomDraw(Sender: TObject; ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxDBTreeListColumn; const AText: String; AFont: TFont; var AColor: TColor; ASelected, AFocused: Boolean; var ADone: Boolean); begin { if UpperCase(ANode.Strings[dxDBGrid1Column6.Index])='TRUE' then begin if (trim(ANode.Strings[dxDBGrid1Column4.Index])='') and (trim(ANode.Strings[dxDBGrid1Column4.Index])='') then AFont.Color:=clRed; end else AFont.Color:=clblack; } end; procedure Tfrm_cw_kemu.N1Click(Sender: TObject); begin grid_save_xls(dxdbgrid1); end; procedure Tfrm_cw_kemu.t_crm_client_accAfterInsert(DataSet: TDataSet); begin if Trim(ACCITEMS.FieldByName('ACCID').AsString)<>'' then begin t_crm_client_acc['Accid']:=Trim(ACCITEMS.FieldByName('ACCID').AsString); end else begin ShowMessage('对应的科目代码为空,不能新增'); Abort; end; end; procedure Tfrm_cw_kemu.DBGridEh5DblClick(Sender: TObject); begin bsSkinPageControl1.ActivePageIndex:=6; end; procedure Tfrm_cw_kemu.t_crm_client_accBeforeDelete(DataSet: TDataSet); begin if GetAccCorpUseStatus(t_crm_client_acc.FieldByName('代码').AsString) then begin Showmessage('客户:'+t_crm_client_acc.FieldByName('客户简称').AsString+'已经使用,不能修改或删除'); Abort; end; end; procedure Tfrm_cw_kemu.t_crm_clientBeforePost(DataSet: TDataSet); begin { if (length(t_crm_client.fieldbyname('财务应收帐款代码').AsString)>6) then begin Showmessage('客户:'+t_crm_client.FieldByName('客户简称').AsString+',财务应收帐款代码不能超过6位'); Abort; end; if (length(t_crm_client.fieldbyname('财务应付帐款代码').AsString)>6) then begin Showmessage('客户:'+t_crm_client.FieldByName('客户简称').AsString+',财务应付帐款代码不能超过6位'); Abort; end; } end; end.