unit u_crm_client; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, bsSkinCtrls, dxExEdtr, dxCntner, dxTL, dxDBCtrl, dxDBGrid, dxDBTLCl, dxGrClms, StdCtrls, DBCtrls, wwdblook, Mask, RxLookup, bsdbctrls, BusinessSkinForm, DB, ADODB, ComCtrls, bsSkinTabs, ExtCtrls, wwdbedit, Wwdotdot, Wwdbcomb, wwdbdatetimepicker, Menus; type Tfrm_crm_client = class(TForm) bsSkinPanel2: TbsSkinPanel; bsSkinButton1: TbsSkinButton; bsSkinButton2: TbsSkinButton; bsSkinButton4: TbsSkinButton; bsSkinButton3: TbsSkinButton; bsSkinButton5: TbsSkinButton; bsSkinPanel1: TbsSkinPanel; t_crm_client1: TDataSource; t_crm_client: TADOQuery; v_all_client: TADOQuery; dxDBGrid1: TdxDBGrid; dxDBGrid1Column1: TdxDBGridMaskColumn; dxDBGrid1Column2: TdxDBGridMaskColumn; dxDBGrid1Column3: TdxDBGridMaskColumn; t_crm_client_limited: TADOQuery; t_crm_client_limited1: TDataSource; bsSkinButton8: TbsSkinButton; bsSkinButton9: TbsSkinButton; bsSkinGroupBox1: TbsSkinGroupBox; Label14: TLabel; wwDBComboBox1: TwwDBComboBox; Label15: TLabel; Edit1: TEdit; Edit2: TEdit; Label16: TLabel; Label17: TLabel; Edit3: TEdit; Label18: TLabel; RxDBLookupCombo2: TRxDBLookupCombo; t_crm_client_linkman1: TDataSource; t_crm_client_linkman: TADOQuery; bsSkinPageControl1: TbsSkinPageControl; bskntbsht1: TbsSkinTabSheet; bskntbsht2: TbsSkinTabSheet; bsSkinPanel3: TbsSkinPanel; Label4: TLabel; Label12: TLabel; Label5: TLabel; Label2: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel; Label10: TLabel; Label11: TLabel; Label3: TLabel; Label13: TLabel; DBEdit4: TDBEdit; DBEdit1: TDBEdit; DBEdit5: TDBEdit; DBEdit2: TDBEdit; DBEdit6: TDBEdit; DBEdit7: TDBEdit; DBEdit8: TDBEdit; DBEdit10: TDBEdit; DBEdit9: TDBEdit; RxDBLookupCombo14: TRxDBLookupCombo; RxDBLookupCombo1: TRxDBLookupCombo; bsSkinDBCheckRadioBox1: TbsSkinDBCheckRadioBox; bsSkinDBCheckRadioBox2: TbsSkinDBCheckRadioBox; bsSkinDBCheckRadioBox3: TbsSkinDBCheckRadioBox; bsSkinDBCheckRadioBox4: TbsSkinDBCheckRadioBox; bsSkinDBCheckRadioBox11: TbsSkinDBCheckRadioBox; bsSkinDBCheckRadioBox9: TbsSkinDBCheckRadioBox; bsSkinDBCheckRadioBox8: TbsSkinDBCheckRadioBox; bsSkinDBCheckRadioBox7: TbsSkinDBCheckRadioBox; bsSkinDBCheckRadioBox6: TbsSkinDBCheckRadioBox; bsSkinDBCheckRadioBox5: TbsSkinDBCheckRadioBox; bsSkinDBCheckRadioBox12: TbsSkinDBCheckRadioBox; bsSkinDBCheckRadioBox10: TbsSkinDBCheckRadioBox; bsSkinPageControl2: TbsSkinPageControl; bsSkinTabSheet1: TbsSkinTabSheet; Label1: TLabel; Label9: TLabel; DBMemo2: TDBMemo; DBMemo1: TDBMemo; bsSkinTabSheet2: TbsSkinTabSheet; bsSkinPanel4: TbsSkinPanel; dxDBGrid2: TdxDBGrid; dxDBGrid2Column1: TdxDBGridMaskColumn; bsSkinPanel5: TbsSkinPanel; bsSkinButton10: TbsSkinButton; bsSkinButton11: TbsSkinButton; bsSkinButton6: TbsSkinButton; dxDBGrid3: TdxDBGrid; dxDBGridMaskColumn1: TdxDBGridMaskColumn; bsSkinDBCheckRadioBox13: TbsSkinDBCheckRadioBox; bsSkinPanel6: TbsSkinPanel; Label36: TLabel; Label37: TLabel; Label38: TLabel; Label40: TLabel; Label39: TLabel; Label41: TLabel; Label42: TLabel; Label43: TLabel; Label44: TLabel; Label47: TLabel; Label48: TLabel; Label49: TLabel; Label50: TLabel; Label52: TLabel; Label51: TLabel; Label53: TLabel; dxDBGrid4: TdxDBGrid; dxDBGridMaskColumn2: TdxDBGridMaskColumn; dxDBGrid2Column2: TdxDBGridMaskColumn; dxDBGrid4Column4: TdxDBGridColumn; dxDBGrid2Column3: TdxDBGridMaskColumn; bsSkinButton7: TbsSkinButton; bsSkinButton12: TbsSkinButton; bsSkinButton13: TbsSkinButton; bsSkinButton14: TbsSkinButton; DBEdit35: TDBEdit; wwDBComboBox2: TwwDBComboBox; DBEdit37: TDBEdit; DBEdit39: TDBEdit; DBEdit38: TDBEdit; DBEdit36: TDBEdit; DBEdit40: TDBEdit; DBEdit41: TDBEdit; DBEdit42: TDBEdit; DBEdit43: TDBEdit; DBEdit44: TDBEdit; wwDBDateTimePicker1: TwwDBDateTimePicker; wwDBDateTimePicker2: TwwDBDateTimePicker; wwDBDateTimePicker4: TwwDBDateTimePicker; wwDBDateTimePicker3: TwwDBDateTimePicker; DBMemo3: TDBMemo; Label19: TLabel; Edit4: TEdit; Label20: TLabel; Edit5: TEdit; Label21: TLabel; DBEdit3: TDBEdit; bsSkinGroupBox2: TbsSkinGroupBox; lbl1: TLabel; lbl2: TLabel; lbl3: TLabel; lbl4: TLabel; lbl5: TLabel; lbl6: TLabel; dbedt1: TDBEdit; dbedt2: TDBEdit; dbedt3: TDBEdit; dbedt4: TDBEdit; dbedt5: TDBEdit; dbedt6: TDBEdit; DBEdit11: TDBEdit; Label22: TLabel; Label23: TLabel; DBEdit12: TDBEdit; Label24: TLabel; DBEdit13: TDBEdit; Label25: TLabel; DBEdit14: TDBEdit; bsSkinDBCheckRadioBox14: TbsSkinDBCheckRadioBox; bsSkinButton15: TbsSkinButton; dxDBGrid1Column4: TdxDBGridColumn; PopupMenu1: TPopupMenu; N1: TMenuItem; Label26: TLabel; DBEdit15: TDBEdit; bsSkinButton16: TbsSkinButton; Label27: TLabel; DBEdit16: TDBEdit; Label28: TLabel; DBEdit17: TDBEdit; Label29: TLabel; DBEdit18: TDBEdit; Label30: TLabel; DBEdit19: TDBEdit; Label31: TLabel; DBEdit20: TDBEdit; Label63: TLabel; DBEdit78: TDBEdit; Label32: TLabel; bsSkinButton65: TbsSkinButton; bsSkinButton17: TbsSkinButton; DBEdit21: TDBEdit; Label33: TLabel; DBEdit22: TDBEdit; DBEdit23: TDBEdit; Label34: TLabel; bsSkinButton93: TbsSkinButton; bsSkinTabSheet3: TbsSkinTabSheet; dxDBGrid5: TdxDBGrid; dxDBGridMaskColumn3: TdxDBGridMaskColumn; dxDBGridMaskColumn4: TdxDBGridMaskColumn; dxDBGridColumn1: TdxDBGridColumn; dxDBGridMaskColumn5: TdxDBGridMaskColumn; CustAccount1: TDataSource; CustAccount: TADOQuery; dxDBGrid5Column5: TdxDBGridColumn; dxDBGrid5Column6: TdxDBGridColumn; dxDBGrid5Column7: TdxDBGridColumn; dxDBGrid5Column8: TdxDBGridColumn; CustInvoice: TADOQuery; CustInvoice1: TDataSource; bsSkinTabSheet4: TbsSkinTabSheet; dxDBGrid6: TdxDBGrid; dxDBGridMaskColumn6: TdxDBGridMaskColumn; dxDBGridMaskColumn7: TdxDBGridMaskColumn; dxDBGridColumn2: TdxDBGridColumn; dxDBGridMaskColumn8: TdxDBGridMaskColumn; dxDBGridColumn5: TdxDBGridColumn; dxDBGridColumn6: TdxDBGridColumn; CustContact1: TDataSource; CustContact: TADOQuery; bsSkinTabSheet5: TbsSkinTabSheet; dxDBGrid7: TdxDBGrid; dxDBGridMaskColumn9: TdxDBGridMaskColumn; dxDBGridMaskColumn10: TdxDBGridMaskColumn; dxDBGridColumn3: TdxDBGridColumn; dxDBGridMaskColumn11: TdxDBGridMaskColumn; dxDBGridColumn4: TdxDBGridColumn; dxDBGridColumn7: TdxDBGridColumn; dxDBGrid7Column7: TdxDBGridColumn; dxDBGrid7Column8: TdxDBGridColumn; dxDBGrid7Column9: TdxDBGridColumn; dxDBGrid7Column10: TdxDBGridColumn; dxDBGrid7Column11: TdxDBGridColumn; dxDBGrid7Column12: TdxDBGridColumn; Label35: TLabel; DBEdit24: TDBEdit; Label45: TLabel; wwDBComboBox4: TwwDBComboBox; bsSkinButton18: TbsSkinButton; dxDBGrid1Column5: TdxDBGridColumn; dxDBGrid1Column6: TdxDBGridColumn; dxDBGrid1Column7: TdxDBGridColumn; bsSkinSplitter1: TbsSkinSplitter; bsSkinTabSheet6: TbsSkinTabSheet; dxDBGrid8: TdxDBGrid; dxDBGridMaskColumn12: TdxDBGridMaskColumn; dxDBGridMaskColumn13: TdxDBGridMaskColumn; dxDBGridColumn8: TdxDBGridColumn; dxDBGridMaskColumn14: TdxDBGridMaskColumn; dxDBGridColumn9: TdxDBGridColumn; dxDBGridColumn10: TdxDBGridColumn; dxDBGridColumn11: TdxDBGridColumn; dxDBGridColumn12: TdxDBGridColumn; dxDBGridColumn13: TdxDBGridColumn; t_crm_client_sales: TADOQuery; ds_crm_client_sales1: TDataSource; Label46: TLabel; DBEdit25: TDBEdit; bsSkinDBCheckRadioBox15: TbsSkinDBCheckRadioBox; procedure bsSkinButton5Click(Sender: TObject); procedure bsSkinButton1Click(Sender: TObject); procedure bsSkinButton2Click(Sender: TObject); procedure bsSkinButton4Click(Sender: TObject); procedure bsSkinButton3Click(Sender: TObject); procedure client_filtered(str:string); procedure bsSkinCheckRadioBox2Click(Sender: TObject); procedure OnShow(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure t_crm_clientAfterInsert(DataSet: TDataSet); procedure t_crm_clientBeforePost(DataSet: TDataSet); procedure DBEdit4KeyPress(Sender: TObject; var Key: Char); procedure DBEdit5KeyPress(Sender: TObject; var Key: Char); procedure DBEdit2KeyPress(Sender: TObject; var Key: Char); procedure DBEdit6KeyPress(Sender: TObject; var Key: Char); procedure DBEdit7KeyPress(Sender: TObject; var Key: Char); procedure DBEdit8KeyPress(Sender: TObject; var Key: Char); procedure DBEdit10KeyPress(Sender: TObject; var Key: Char); procedure DBEdit9KeyPress(Sender: TObject; var Key: Char); procedure RxDBLookupCombo14KeyPress(Sender: TObject; var Key: Char); procedure bsSkinDBCheckRadioBox1KeyPress(Sender: TObject; var Key: Char); procedure bsSkinDBCheckRadioBox2KeyPress(Sender: TObject; var Key: Char); procedure bsSkinDBCheckRadioBox3KeyPress(Sender: TObject; var Key: Char); procedure bsSkinDBCheckRadioBox4KeyPress(Sender: TObject; var Key: Char); procedure bsSkinDBCheckRadioBox11KeyPress(Sender: TObject; var Key: Char); procedure bsSkinDBCheckRadioBox9KeyPress(Sender: TObject; var Key: Char); procedure bsSkinDBCheckRadioBox8KeyPress(Sender: TObject; var Key: Char); procedure bsSkinDBCheckRadioBox7KeyPress(Sender: TObject; var Key: Char); procedure bsSkinDBCheckRadioBox6KeyPress(Sender: TObject; var Key: Char); procedure bsSkinDBCheckRadioBox5KeyPress(Sender: TObject; var Key: Char); procedure bsSkinDBCheckRadioBox12KeyPress(Sender: TObject; var Key: Char); procedure bsSkinDBCheckRadioBox10KeyPress(Sender: TObject; var Key: Char); procedure t_crm_clientDeleteError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); procedure t_crm_clientPostError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); procedure t_crm_clientAfterScroll(DataSet: TDataSet); procedure dxDBGrid1ColumnSorting(Sender: TObject; Column: TdxDBTreeListColumn; var Allow: Boolean); procedure t_crm_clientBeforeDelete(DataSet: TDataSet); procedure DBEdit1KeyPress(Sender: TObject; var Key: Char); procedure RxDBLookupCombo1KeyPress(Sender: TObject; var Key: Char); procedure bsSkinButton6Click(Sender: TObject); procedure bsSkinButton10Click(Sender: TObject); procedure bsSkinButton11Click(Sender: TObject); procedure bsSkinPanel2Resize(Sender: TObject); procedure t_crm_client_limitedAfterInsert(DataSet: TDataSet); procedure t_crm_client_limitedBeforeInsert(DataSet: TDataSet); procedure bsSkinDBCheckRadioBox13KeyPress(Sender: TObject; var Key: Char); procedure bsSkinButton9Click(Sender: TObject); procedure bsSkinButton8Click(Sender: TObject); procedure wwDBComboBox1KeyPress(Sender: TObject; var Key: Char); procedure t_crm_clientAfterPost(DataSet: TDataSet); procedure t_crm_clientBeforeCancel(DataSet: TDataSet); procedure t_crm_clientBeforeEdit(DataSet: TDataSet); procedure t_crm_clientBeforeInsert(DataSet: TDataSet); procedure bsSkinButton7Click(Sender: TObject); procedure bsSkinButton12Click(Sender: TObject); procedure bsSkinButton13Click(Sender: TObject); procedure bsSkinButton14Click(Sender: TObject); procedure bsSkinButton15Click(Sender: TObject); procedure N1Click(Sender: TObject); procedure bsSkinButton16Click(Sender: TObject); procedure bsSkinButton17Click(Sender: TObject); procedure bsSkinButton65Click(Sender: TObject); procedure DBEdit21Change(Sender: TObject); procedure bsSkinButton93Click(Sender: TObject); procedure bsSkinButton18Click(Sender: TObject); private function CreateNewDjyCustStr():string; { Private declarations } public { Public declarations } end; var frm_crm_client: Tfrm_crm_client; frm_crm_client_num:integer; implementation uses u_main, my_sys_function, u_data_share, my_sys_chat, u_crm_import; {$R *.dfm} procedure Tfrm_crm_client.client_filtered(str:string); begin t_crm_client.Filtered:=false; t_crm_client.Filter:=str+'=1'; t_crm_client.Filtered:=true; end; procedure Tfrm_crm_client.bsSkinButton5Click(Sender: TObject); begin close; end; procedure Tfrm_crm_client.bsSkinButton1Click(Sender: TObject); begin t_crm_client.Insert; end; procedure Tfrm_crm_client.bsSkinButton2Click(Sender: TObject); begin table_post(t_crm_client); end; procedure Tfrm_crm_client.bsSkinButton4Click(Sender: TObject); begin t_crm_client.Edit; t_crm_client.FieldByName('isdelete').AsString:='1'; t_crm_client.Post; InsertSysLog('客户删除',t_crm_client.FieldByName('客户简称').asstring); table_delete(t_crm_client); end; procedure Tfrm_crm_client.bsSkinButton3Click(Sender: TObject); begin table_cancel(t_crm_client); end; procedure Tfrm_crm_client.bsSkinCheckRadioBox2Click(Sender: TObject); begin t_crm_client.Filtered:=false; end; procedure Tfrm_crm_client.OnShow(Sender: TObject); begin t_crm_client.open; ShowMessage('1'); // v_all_client.open; ShowMessage('2'); t_crm_client_linkman.Open; ShowMessage('3'); CustAccount.Open; ShowMessage('4'); CustInvoice.Open; ShowMessage('5'); CustContact.Open; t_crm_client_sales.Open; ShowMessage('6'); if employee='陈冠宇' then bsSkinButton16.Visible:=true else bsSkinButton16.Visible:=false; frm_data_share.t_sys_employee.Requery(); ShowMessage('7'); frm_data_share.t_sys_department.Requery(); ShowMessage('8'); if not strtobool(get_parameters_value(4,'false')) then begin bsSkinTabSheet2.TabVisible:=false; end else begin bsSkinTabSheet2.TabVisible:=true; t_crm_client_limited.open; end; if if_open('511') then begin bsSkinButton17.Enabled:=True; bsSkinButton65.Enabled:=True; end else begin bsSkinButton17.Enabled:=false; bsSkinButton65.Enabled:=false; end; end; procedure Tfrm_crm_client.FormClose(Sender: TObject; var Action: TCloseAction); begin with frm_data_share do begin t_crm_client.requery; t_crm_client_all.requery; t_crm_client_ship.requery; t_crm_client_changzhan.requery; t_crm_client_truck.requery; t_crm_client_hangkong.requery; t_crm_client_baoguan.requery; t_crm_client_weituo.requery; t_crm_client_daili.requery; t_crm_client_huodai.requery; t_crm_client_shiper.requery; t_crm_client_shouhuo.requery; t_crm_client_tongzhi.requery; t_crm_client_other.requery; end; frm_crm_client.Hide; frm_crm_client.ManualFloat(frm_crm_client.BoundsRect ); frm_main.freeTabs('frm_crm_client'); action:=cafree; frm_crm_client:=nil; end; procedure Tfrm_crm_client.t_crm_clientAfterInsert(DataSet: TDataSet); begin t_crm_client['客户性质']:='其他'; frm_crm_client_num:=1; t_crm_client['结费类型']:='约定天数'; end; procedure Tfrm_crm_client.t_crm_clientBeforePost(DataSet: TDataSet); var aQuery:TADOQuery; begin table_before_post(t_crm_client,'代码'); table_before_post(t_crm_client,'客户简称'); table_before_post(t_crm_client,'客户全称'); aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('select * from t_crm_client where (客户简称='''+t_crm_client.fieldbyname('客户简称').AsString+''') and clientid<>'''+t_crm_client.fieldbyname('CLIENTID').AsString+''''); Open; if not IsEmpty then begin ShowMessage('系统中已存在此客户简称,代码:'+fieldbyname('代码').AsString+';简称:'+fieldbyname('客户简称').AsString+',不允许重复'); abort; end; Close;SQL.Clear; SQL.Add('select * from t_crm_client where (代码='''+t_crm_client.fieldbyname('代码').AsString+''') and clientid<>'''+t_crm_client.fieldbyname('CLIENTID').AsString+''''); Open; if not IsEmpty then begin ShowMessage('系统中已存在此客户代码,代码:'+fieldbyname('代码').AsString+';简称:'+fieldbyname('客户简称').AsString+',不允许重复'); abort; end; end; finally FreeAndNil(aQuery); end; if pos(' ',t_crm_client.FieldByName('客户简称').AsString)>0 then begin showmessage('客户简称不能有空格,不能保存!'); abort; end; t_crm_client['客户简称']:=trim(t_crm_client['客户简称']); if (t_crm_client.fieldbyname('船公司').asboolean=false)and (t_crm_client.fieldbyname('场站').asboolean=false)and (t_crm_client.fieldbyname('车队').asboolean=false)and (t_crm_client.fieldbyname('报关行').asboolean=false)and (t_crm_client.fieldbyname('委托单位').asboolean=false)and (t_crm_client.fieldbyname('代理').asboolean=false)and (t_crm_client.fieldbyname('货代').asboolean=false)and (t_crm_client.fieldbyname('收货人').asboolean=false)and (t_crm_client.fieldbyname('发货人').asboolean=false)and (t_crm_client.fieldbyname('通知人').asboolean=false)and (t_crm_client.fieldbyname('航空公司').asboolean=false)and (t_crm_client.fieldbyname('其他客户').asboolean=false)and (t_crm_client.fieldbyname('船代').asboolean=false)and (t_crm_client.fieldbyname('快递公司').asboolean=false)then begin showmessage('船公司、场站、车队、报关行、委托单位、代理、货代、收货人、发货人、通知人、航空公司、其他客户、快递公司、船代必须选择其一!'); abort; end; if t_crm_client.State=dsedit then begin if t_crm_client.fieldbyname('客户简称').OldValue<>t_crm_client.fieldbyname('客户简称').AsString then begin frm_crm_client_num:=2; end else frm_crm_client_num:=0; end; end; procedure Tfrm_crm_client.DBEdit4KeyPress(Sender: TObject; var Key: Char); begin key_DBEdit(Key,DBEdit1); end; procedure Tfrm_crm_client.DBEdit5KeyPress(Sender: TObject; var Key: Char); begin key_DBEdit(Key,DBEdit2); end; procedure Tfrm_crm_client.DBEdit2KeyPress(Sender: TObject; var Key: Char); begin key_DBEdit(Key,DBEdit6); end; procedure Tfrm_crm_client.DBEdit6KeyPress(Sender: TObject; var Key: Char); begin key_DBEdit(Key,DBEdit7); end; procedure Tfrm_crm_client.DBEdit7KeyPress(Sender: TObject; var Key: Char); begin key_DBEdit(Key,DBEdit8); end; procedure Tfrm_crm_client.DBEdit8KeyPress(Sender: TObject; var Key: Char); begin key_DBEdit(Key,DBEdit10); end; procedure Tfrm_crm_client.DBEdit10KeyPress(Sender: TObject; var Key: Char); begin key_DBEdit(Key,DBEdit9); end; procedure Tfrm_crm_client.DBEdit9KeyPress(Sender: TObject; var Key: Char); begin key_RxDBLookupCombo(Key,RxDBLookupCombo14); end; procedure Tfrm_crm_client.RxDBLookupCombo14KeyPress(Sender: TObject; var Key: Char); begin key_RxDBLookupCombo(Key,RxDBLookupCombo1); end; procedure Tfrm_crm_client.bsSkinDBCheckRadioBox1KeyPress(Sender: TObject; var Key: Char); begin key_bsSkinDBCheckRadioBox(Key,bsSkinDBCheckRadioBox2); end; procedure Tfrm_crm_client.bsSkinDBCheckRadioBox2KeyPress(Sender: TObject; var Key: Char); begin key_bsSkinDBCheckRadioBox(Key,bsSkinDBCheckRadioBox3); end; procedure Tfrm_crm_client.bsSkinDBCheckRadioBox3KeyPress(Sender: TObject; var Key: Char); begin key_bsSkinDBCheckRadioBox(Key,bsSkinDBCheckRadioBox4); end; procedure Tfrm_crm_client.bsSkinDBCheckRadioBox4KeyPress(Sender: TObject; var Key: Char); begin key_bsSkinDBCheckRadioBox(Key,bsSkinDBCheckRadioBox11); end; procedure Tfrm_crm_client.bsSkinDBCheckRadioBox11KeyPress(Sender: TObject; var Key: Char); begin key_bsSkinDBCheckRadioBox(Key,bsSkinDBCheckRadioBox9); end; procedure Tfrm_crm_client.bsSkinDBCheckRadioBox9KeyPress(Sender: TObject; var Key: Char); begin key_bsSkinDBCheckRadioBox(Key,bsSkinDBCheckRadioBox8); end; procedure Tfrm_crm_client.bsSkinDBCheckRadioBox8KeyPress(Sender: TObject; var Key: Char); begin key_bsSkinDBCheckRadioBox(Key,bsSkinDBCheckRadioBox7); end; procedure Tfrm_crm_client.bsSkinDBCheckRadioBox7KeyPress(Sender: TObject; var Key: Char); begin key_bsSkinDBCheckRadioBox(Key,bsSkinDBCheckRadioBox6); end; procedure Tfrm_crm_client.bsSkinDBCheckRadioBox6KeyPress(Sender: TObject; var Key: Char); begin key_bsSkinDBCheckRadioBox(Key,bsSkinDBCheckRadioBox5); end; procedure Tfrm_crm_client.bsSkinDBCheckRadioBox5KeyPress(Sender: TObject; var Key: Char); begin key_bsSkinDBCheckRadioBox(Key,bsSkinDBCheckRadioBox12); end; procedure Tfrm_crm_client.bsSkinDBCheckRadioBox12KeyPress(Sender: TObject; var Key: Char); begin key_bsSkinDBCheckRadioBox(Key,bsSkinDBCheckRadioBox10); end; procedure Tfrm_crm_client.bsSkinDBCheckRadioBox10KeyPress(Sender: TObject; var Key: Char); begin key_bsSkinDBCheckRadioBox(Key,bsSkinDBCheckRadioBox13); end; procedure Tfrm_crm_client.t_crm_clientDeleteError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); begin showmessage('客户已经使用,不能删除!!'); end; procedure Tfrm_crm_client.t_crm_clientPostError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); var aQuery:TAdoQuery; begin { if (pos('代码',UpperCase(E.Message))<>0) then begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('select * from t_crm_client where 代码='''+t_crm_client['代码']+''' OR 客户简称='''+t_crm_client['客户简称']+''''); Open; if not IsEmpty then begin ShowMessage('系统中已存在此客户代码或简称,代码:'+fieldbyname('代码').AsString+';简称:'+fieldbyname('客户简称').AsString); end; end; finally FreeAndNil(aQuery); end; abort; end; if (pos('PRIMARY KEY',UpperCase(E.Message))<>0) then begin aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('select * from t_crm_client where 代码='''+t_crm_client['代码']+''' OR 客户简称='''+t_crm_client['客户简称']+''''); Open; if not IsEmpty then begin ShowMessage('系统中已存在此客户代码或简称,代码:'+fieldbyname('代码').AsString+';简称:'+fieldbyname('客户简称').AsString); end; end; finally FreeAndNil(aQuery); end; abort; end; } end; procedure Tfrm_crm_client.t_crm_clientAfterScroll(DataSet: TDataSet); begin if v_all_client.IsEmpty then begin DBEdit4.ReadOnly:=false; DBEdit5.ReadOnly:=false; end else begin DBEdit4.ReadOnly:=true; DBEdit5.ReadOnly:=true; end; end; procedure Tfrm_crm_client.dxDBGrid1ColumnSorting(Sender: TObject; Column: TdxDBTreeListColumn; var Allow: Boolean); begin Column_sort(Column,t_crm_client,'代码'); end; procedure Tfrm_crm_client.t_crm_clientBeforeDelete(DataSet: TDataSet); begin if not if_open('202') then begin showmessage('对不起你没有此模块的操作权限!'); abort; end; if not v_all_client.IsEmpty then begin showmessage('当前客户已经使用,不能删除!!'); abort; end; { if t_crm_client.State<>dsinsert then SendMsg_gonggao('54',''); } end; procedure Tfrm_crm_client.DBEdit1KeyPress(Sender: TObject; var Key: Char); begin key_DBEdit(Key,DBEdit5); end; procedure Tfrm_crm_client.RxDBLookupCombo1KeyPress(Sender: TObject; var Key: Char); begin key_bsSkinDBCheckRadioBox(Key,bsSkinDBCheckRadioBox1); end; procedure Tfrm_crm_client.bsSkinButton6Click(Sender: TObject); begin table_post(t_crm_client); IF t_crm_client.IsEmpty then exit; frm_data_share.t_sys_department.first; while not frm_data_share.t_sys_department.eof do begin if not t_crm_client_limited.Locate('部门名称',frm_data_share.t_sys_department.fieldbyname('部门名称').asstring,[])then begin t_crm_client_limited.insert; t_crm_client_limited['部门名称']:=frm_data_share.t_sys_department.fieldbyname('部门名称').asstring; t_crm_client_limited.post; end; frm_data_share.t_sys_department.next; end; end; procedure Tfrm_crm_client.bsSkinButton10Click(Sender: TObject); begin table_post(t_crm_client); IF t_crm_client.IsEmpty then exit; if not t_crm_client_limited.Locate('部门名称',frm_data_share.t_sys_department.fieldbyname('部门名称').asstring,[])then begin t_crm_client_limited.insert; t_crm_client_limited['部门名称']:=frm_data_share.t_sys_department.fieldbyname('部门名称').asstring; t_crm_client_limited.post; end; end; procedure Tfrm_crm_client.bsSkinButton11Click(Sender: TObject); begin if t_crm_client_limited.IsEmpty then exit; t_crm_client_limited.Delete; end; procedure Tfrm_crm_client.bsSkinPanel2Resize(Sender: TObject); var i:integer; begin i:=round(bsSkinPanel2.Width/11); bsSkinButton1.Width:=i; bsSkinButton2.Width:=i; bsSkinButton4.Width:=i; bsSkinButton3.Width:=i; bsSkinButton8.Width:=i; bsSkinButton9.Width:=i; bsSkinButton15.Width:=i; bsSkinButton17.Width:=i; bsSkinButton65.Width:=i; end; procedure Tfrm_crm_client.t_crm_client_limitedAfterInsert( DataSet: TDataSet); begin t_crm_client_limited['客户简称']:=t_crm_client['客户简称']; end; procedure Tfrm_crm_client.t_crm_client_limitedBeforeInsert( DataSet: TDataSet); begin table_post(t_crm_client); end; procedure Tfrm_crm_client.bsSkinDBCheckRadioBox13KeyPress(Sender: TObject; var Key: Char); begin key_DBMemo(Key,DBMemo1); end; procedure Tfrm_crm_client.bsSkinButton9Click(Sender: TObject); begin wwDBComboBox1.text:=''; Edit1.text:=''; Edit2.text:=''; Edit3.text:=''; RxDBLookupCombo2.ClearValue; end; procedure Tfrm_crm_client.bsSkinButton8Click(Sender: TObject); var str:widestring; begin str:='where 客户性质<>'+''''+'目标'+''''; if wwDBComboBox1.text<>'' then begin str:=str+' and '+wwDBComboBox1.text+'=1'; end; 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; if Edit4.text<>''then begin str:=str+' and 电话 like '+''''+'%'+Edit4.text+'%'+''''; end; if Edit5.text<>''then begin str:=str+' and 传真 like '+''''+'%'+Edit5.text+'%'+''''; end; if RxDBLookupCombo2.DisplayValue<>''then begin str:=str+' and EXISTS (select 1 from t_crm_client_sales WHERE t_crm_client.客户简称=t_crm_client_sales.客户简称 and t_crm_client_sales.揽货人='+''''+RxDBLookupCombo2.DisplayValue+''')'; end; t_crm_client.close; t_crm_client.sql.clear; t_crm_client.sql.add('select *,(select TOP 1 揽货人+''_''+结费类型 from t_crm_client_sales where 状态=''审核'' and 客户简称=t_crm_client.客户简称 order by 开始日期 desc) SALE from t_crm_client '+str+' order by 代码'); t_crm_client.open; end; procedure Tfrm_crm_client.wwDBComboBox1KeyPress(Sender: TObject; var Key: Char); begin IF key=#13 then begin key:=#0; frm_crm_client.bsSkinButton8Click(Sender); end; end; procedure Tfrm_crm_client.t_crm_clientAfterPost(DataSet: TDataSet); begin { if frm_crm_client_num=1 then SendMsg_gonggao('53','新客户:'+t_crm_client['代码']+','+t_crm_client['客户简称']); if frm_crm_client_num=2 then SendMsg_gonggao('54',''); } frm_crm_client_num:=0; end; procedure Tfrm_crm_client.t_crm_clientBeforeCancel(DataSet: TDataSet); begin frm_crm_client_num:=0; end; procedure Tfrm_crm_client.t_crm_clientBeforeEdit(DataSet: TDataSet); begin if not if_open('202') then begin showmessage('对不起你没有此模块的操作权限!'); abort; end; end; procedure Tfrm_crm_client.t_crm_clientBeforeInsert(DataSet: TDataSet); begin if not if_open('202') then begin showmessage('对不起你没有此模块的操作权限!'); abort; end; end; procedure Tfrm_crm_client.bsSkinButton7Click(Sender: TObject); begin t_crm_client_linkman.insert; end; procedure Tfrm_crm_client.bsSkinButton12Click(Sender: TObject); begin table_post(t_crm_client_linkman); end; procedure Tfrm_crm_client.bsSkinButton13Click(Sender: TObject); begin table_delete(t_crm_client_linkman); end; procedure Tfrm_crm_client.bsSkinButton14Click(Sender: TObject); begin table_cancel(t_crm_client_linkman); end; procedure Tfrm_crm_client.bsSkinButton15Click(Sender: TObject); begin try frm_crm_Import:=tfrm_crm_Import.Create (self); frm_crm_Import.ShowModal; finally frm_crm_Import.Free; end; end; procedure Tfrm_crm_client.N1Click(Sender: TObject); begin grid_save_xls(dxdbgrid1); end; procedure Tfrm_crm_client.bsSkinButton16Click(Sender: TObject); var Protocolrec:TProtocolrec; aAdoQuery,aAdoQueryUpdate:TAdoQuery; begin aAdoQuery:=CreateAdoQuery; aAdoQueryUpdate:=CreateAdoQuery; with aAdoQueryUpdate do begin close;sql.Clear; sql.Add('update t_op_seae '); sql.Add('set 结费类型=:结费类型 ,应结日期=:应结日期 '); sql.Add('where 编号=:编号'); end; with aAdoQuery do try close;sql.Clear; sql.Add('select * from t_op_seae'); sql.Add('where 开船日期>=''2015-5-1'' and 开船日期<=''2017-1-1'''); sql.Add('Order by 委托单位,开船日期'); Open;First; WriteLog(sql.Text); while not eof do begin Protocolrec:=getProtocol(fieldbyname('委托单位').asstring,fieldbyname('揽货人').asstring,fieldbyname('预抵日期').AsDateTime); if trim(Protocolrec.protocolType)<>'' then begin WriteLog(fieldbyname('委托单位').asstring+' '+fieldbyname('编号').asstring+'实际开船日期 '+FormatDateTime('YYYY-MM-DD',fieldbyname('预抵日期').AsDateTime)+ '结费类型 '+Protocolrec.protocolType+'应结日期 '+FormatDateTime('YYYY-MM-DD',Protocolrec.protocolDate)); if (Protocolrec.protocolDate<>null) and (Protocolrec.protocolDate<>0) then begin aAdoQueryUpdate.Close; aAdoQueryUpdate.Parameters.ParamByName('编号').Value:=fieldbyname('编号').asstring; aAdoQueryUpdate.Parameters.ParamByName('结费类型').Value:=Protocolrec.protocolType; aAdoQueryUpdate.Parameters.ParamByName('应结日期').Value:=Protocolrec.protocolDate; WriteLog(aAdoQueryUpdate.sql.Text+' '+ fieldbyname('编号').asstring+ ' '+Protocolrec.protocolType+' '+FormatDateTime('YYYY-MM-DD',Protocolrec.protocolDate)); aAdoQueryUpdate.ExecSQL; end; end; Next; end; finally Free; aAdoQueryUpdate.Free; end; end; procedure Tfrm_crm_client.bsSkinButton17Click(Sender: TObject); begin if not (t_crm_client.State in [dsedit,dsinsert]) then t_crm_client.Edit; t_crm_client.FieldByName('扣单状态').AsString:='扣单'; t_crm_client.Post; end; procedure Tfrm_crm_client.bsSkinButton65Click(Sender: TObject); begin if not (t_crm_client.State in [dsedit,dsinsert]) then t_crm_client.Edit; t_crm_client.FieldByName('扣单状态').AsString:='放单'; t_crm_client.Post; end; procedure Tfrm_crm_client.DBEdit21Change(Sender: TObject); begin if (DBEdit21.Text='扣单') then DBEdit21.Color:=clred else DBEdit21.Color:=clWhite; end; function Tfrm_crm_client.CreateNewDjyCustStr(): string; var str,str2,codetype,codestr,strsql,typestr,propstr:string; aAdoQuery:TAdoQuery; isfirst:Boolean; TempStr:TStringlist; begin if t_crm_client.FieldByName('委托单位').AsBoolean then propstr:=propstr+'[consignor]'; if t_crm_client.FieldByName('车队').AsBoolean then propstr:=propstr+'[fleet]'; if t_crm_client.FieldByName('报关行').AsBoolean then propstr:=propstr+'[customs_broker]'; if t_crm_client.FieldByName('订舱代理').AsBoolean then propstr:=propstr+'[booking_agent]'; if t_crm_client.FieldByName('代理').AsBoolean then propstr:=propstr+'[out_agent]'; if t_crm_client.FieldByName('船公司').AsBoolean then propstr:=propstr+'[carrier]'; if t_crm_client.FieldByName('货代').AsBoolean then propstr:=propstr+'[forwarder]'; if t_crm_client.FieldByName('场站').AsBoolean then propstr:=propstr+'[yard]'; if t_crm_client.FieldByName('收货人').AsBoolean then propstr:=propstr+'[shipper]'; if t_crm_client.FieldByName('发货人').AsBoolean then propstr:=propstr+'[consignee]'; if t_crm_client.FieldByName('通知人').AsBoolean then propstr:=propstr+'[notifyparty]'; if t_crm_client.FieldByName('船代').AsBoolean then propstr:=propstr+'[shipagency]'; if t_crm_client.FieldByName('快递公司').AsBoolean then propstr:=propstr+'[courier]'; if t_crm_client.FieldByName('其他客户').AsBoolean then propstr:=propstr+'[othercustomers]'; aAdoQuery:=CreateAdoQuery; str:=str+'{'; TempStr:=TStringList.Create; try str:=str+'"codeName":"'+ t_crm_client.FieldByName('代码').asstring+'"'; str:=str+',"shortName":"'+t_crm_client.FieldByName('客户简称').asstring+'"'; str:=str+',"fullName":"'+ t_crm_client.FieldByName('客户全称').asstring+'"'; str:=str+',"chief":"'+ t_crm_client.FieldByName('法人').asstring+'"'; str:=str+',"tel":"'+ t_crm_client.FieldByName('电话').asstring+'"'; str:=str+',"email":"'+ t_crm_client.FieldByName('邮箱').asstring+'"'; str:=str+',"qq":""'; str:=str+',"webUrl":"'+ t_crm_client.FieldByName('网站').asstring+'"'; str:=str+',"city":"'+ t_crm_client.FieldByName('城市').asstring+'"'; str:=str+',"addr":"'+ t_crm_client.FieldByName('通讯地址').asstring+'"'; str:=str+',"fullNameEN":"'+ t_crm_client.FieldByName('英文全称').asstring+'"'; str:=str+',"addrEN":""'; str:=str+',"propString":"'+propstr+'"'; str:=str+',"invTitle":"'+ t_crm_client.FieldByName('发票抬头').asstring+'"'; str:=str+',"taxNO":""'; str:=str+',"invAddrTel":""'; str:=str+',"rmbBank":"'+ t_crm_client.FieldByName('开户行RMB').asstring+'"'; str:=str+',"rmbAccount":"'+ t_crm_client.FieldByName('帐号RMB').asstring+'"'; str:=str+',"usdBank":"'+ t_crm_client.FieldByName('开户行USD').asstring+'"'; str:=str+',"usdAccount":"'+ t_crm_client.FieldByName('帐号USD').asstring+'"'; str:=str+',"CUSTSERVICE":"'+ t_crm_client.FieldByName('客服员').asstring+'"'; str:=str+',"remark":"'+ t_crm_client.FieldByName('备注').asstring+'"'; strsql:='select * from t_crm_client_sales where 状态=''审核'' and 开始日期<=cast(GETDATE()as date) and 结束日期>=cast(GETDATE()as date) and 客户简称=' +#39+t_crm_client.FieldByName('客户简称').asstring+#39; aAdoQuery.Close; aAdoQuery.SQL.Text:=strsql; aAdoQuery.Open; if (not aAdoQuery.IsEmpty) then str:=str+',"sale":"'+ aAdoQuery.FieldByName('揽货人').asstring+'"'; strsql:='select * from t_crm_client_class where 开始日期<=cast(GETDATE()as date) and 结束日期>=cast(GETDATE()as date) and 客户简称=' +#39+t_crm_client.FieldByName('客户简称').asstring+#39; aAdoQuery.Close; aAdoQuery.SQL.Text:=strsql; aAdoQuery.Open; if (not aAdoQuery.IsEmpty) then str:=str+',"level":"'+ aAdoQuery.FieldByName('客户等级').asstring+'"'; str:=str+',"contactList":['; strsql:='select * from t_crm_client_linkman where 客户简称=' +#39+t_crm_client.FieldByName('客户简称').asstring+#39; aAdoQuery.Close; aAdoQuery.SQL.Text:=strsql; aAdoQuery.Open; aAdoQuery.First; isfirst:=true; while not aAdoQuery.Eof do begin if (isfirst) then str:=str+'{' else str:=str+',{'; str:=str+'"name":"'+StringReplace(aAdoQuery.FieldByName('姓名').asstring,'''','',[])+'"'; str:=str+',"tel":'+aAdoQuery.FieldByName('办公电话').asstring; str:=str+',"email":"'+aAdoQuery.FieldByName('邮箱').asstring+'"'; // str:=str+',"qq":"'+aAdoQuery.FieldByName('QQ').asstring+'"'; str:=str+',"remark":"'+aAdoQuery.FieldByName('备注').asstring+'"'; str:=str+'}'; isfirst:=false; aAdoQuery.Next; end; str:=str+']'; str:=str+'}'; finally FreeAndNil(aAdoQuery); FreeAndNil(TempStr); end; Result:=str; end; procedure Tfrm_crm_client.bsSkinButton93Click(Sender: TObject); var i:Integer; str:string; dsstr,PostUrl,custstr,ScriptPath,filenamestr:string; sl:TStringList; begin if strtobool(get_parameters_value(3309,'false'))then exit; if t_crm_client.IsEmpty then exit; if dxDBGrid1.SelectedCount<1 then begin showmessage('请选择要上传数据的业务!!'); exit; end; sl:=TStringList.Create; str:=str+'['; for i:=0 to dxDBGrid1.SelectedCount-1 do begin t_crm_client.GotoBookmark(pointer(dxDBGrid1.selectedrows[i])); if (i<>0) then str:=str+','; dsstr:=CreateNewDjyCustStr; str:=str+dsstr; end; str:=str+']'; sl.Add(str); ScriptPath:=ExtractFilePath(ParamStr(0))+'JSON\'; if not DirectoryExists(ScriptPath) then CreateDir(ScriptPath); filenamestr:=ScriptPath +FormatDateTime('yyyy',now) +FormatDateTime('mm',now) +FormatDateTime('dd',now) +FormatDateTime('hh',now) +FormatDateTime('nn',now)+'.txt'; sl.SaveToFile(filenamestr); PostUrl:=get_parameters_value(3203,'http://60.209.125.238:25805/DataSync/SyncCustomerList'); // PostUrl:='http://60.209.125.238:25805/DataSync/SyncCustomerList'; TDsDjyThread.create(PostUrl,str,'','2b7957046d234d82a1b0a144324c466a','25d31b3b667fa77c875fd75153bf8debf93eb92433995136d7f3092ff10c51288962734153d8b63a'); ShowMessage('上传完成!'); end; procedure Tfrm_crm_client.bsSkinButton18Click(Sender: TObject); var afield : variant; i:Integer; begin afield := vararraycreate([0,t_crm_client.fieldcount-1],varvariant); for i := 0 to (t_crm_client.fieldcount-1) do begin afield[i] :=t_crm_client.fields[i].value ; end; t_crm_client.append; for i := 0 to (t_crm_client.fieldcount-1) do begin if (t_crm_client.fields[i].FieldName<>'客户简称') AND (t_crm_client.fields[i].FieldName<>'CLIENTID') then t_crm_client.fields[i].value := afield[i] ; end; end; end.