unit u_crm_client_special; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, BusinessSkinForm, bsSkinCtrls, DB, ADODB, StdCtrls, Mask, DBCtrls, Grids, DBGrids, dxExEdtr, dxCntner, dxTL, dxDBCtrl, dxDBGrid, RxLookup, ComCtrls, bsSkinTabs; type Tfrm_crm_client_special = class(TForm) bsBusinessSkinForm1: TbsBusinessSkinForm; bsSkinPanel1: TbsSkinPanel; t_crm_client: TADOQuery; t_crm_client1: TDataSource; v_all_client: TADOQuery; t_crm_client_yanzheng: TADOQuery; p_update_client: TADOStoredProc; t_crm_client_wrong: TADOQuery; t_crm_client_wrong1: TDataSource; t_crm_client_ti: TADOQuery; t_crm_client_ti1: TDataSource; bsSkinPageControl1: TbsSkinPageControl; bsSkinTabSheet1: TbsSkinTabSheet; bsSkinTabSheet2: TbsSkinTabSheet; bsSkinTabSheet3: TbsSkinTabSheet; bsSkinGroupBox1: TbsSkinGroupBox; Label15: TLabel; Label16: TLabel; Label17: TLabel; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; bsSkinButton8: TbsSkinButton; bsSkinGroupBox5: TbsSkinGroupBox; Label8: TLabel; Label14: TLabel; Label18: TLabel; Edit6: TEdit; Edit7: TEdit; bsSkinButton5: TbsSkinButton; bsSkinButton6: TbsSkinButton; RxDBLookupCombo1: TRxDBLookupCombo; bsSkinGroupBox4: TbsSkinGroupBox; Label9: TLabel; Label10: TLabel; Label11: TLabel; Label12: TLabel; Label13: TLabel; dxDBGrid1: TdxDBGrid; dxDBGrid1Column1: TdxDBGridMaskColumn; DBEdit1: TDBEdit; RxDBLookupCombo2: TRxDBLookupCombo; bsSkinButton3: TbsSkinButton; bsSkinButton4: TbsSkinButton; bsSkinPanel2: TbsSkinPanel; bsSkinGroupBox3: TbsSkinGroupBox; Label1: TLabel; Label3: TLabel; Edit4: TEdit; Edit5: TEdit; bsSkinButton1: TbsSkinButton; bsSkinButton2: TbsSkinButton; bsSkinGroupBox2: TbsSkinGroupBox; Label4: TLabel; Label5: TLabel; Label2: TLabel; Label6: TLabel; Label7: TLabel; DBEdit4: TDBEdit; DBEdit5: TDBEdit; DBEdit2: TDBEdit; DBEdit6: TDBEdit; DBEdit7: TDBEdit; dxDBGrid2: TdxDBGrid; dxDBGridMaskColumn1: TdxDBGridMaskColumn; dxDBGrid2Column2: TdxDBGridColumn; procedure bsSkinButton8Click(Sender: TObject); procedure bsSkinButton1Click(Sender: TObject); procedure bsSkinButton2Click(Sender: TObject); procedure bsSkinButton4Click(Sender: TObject); procedure bsSkinButton3Click(Sender: TObject); procedure bsSkinButton5Click(Sender: TObject); procedure bsSkinButton6Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var frm_crm_client_special: Tfrm_crm_client_special; implementation uses u_main, u_data_share, my_sys_chat; {$R *.dfm} procedure Tfrm_crm_client_special.bsSkinButton8Click(Sender: TObject); var str:widestring; begin 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; 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; if t_crm_client.RecordCount>1 then begin showmessage('检索出多个客户信息,请再精确查找!!'); t_crm_client.close; exit; end; if t_crm_client.IsEmpty then exit; bsSkinButton1.Enabled:=true; end; procedure Tfrm_crm_client_special.bsSkinButton1Click(Sender: TObject); begin if (trim(Edit4.text)='') or (trim(Edit5.text)='') then begin showmessage('请完整输入新的代码和简称!!'); exit; end; t_crm_client_yanzheng.close; t_crm_client_yanzheng.Parameters.ParamByName('代码').value:=DBEdit4.text; t_crm_client_yanzheng.Parameters.ParamByName('客户简称').value:=DBEdit5.text; t_crm_client_yanzheng.Parameters.ParamByName('new代码').value:=trim(Edit4.text); t_crm_client_yanzheng.Parameters.ParamByName('new客户简称').value:=trim(Edit5.text); t_crm_client_yanzheng.open; if t_crm_client_yanzheng.IsEmpty then begin bsSkinButton2.Enabled:=true; showmessage('验证通过!!'); end else begin showmessage('验证失败,有重复现象!!'); end; end; procedure Tfrm_crm_client_special.bsSkinButton2Click(Sender: TObject); VAR old_name,old_code:STRING; begin if application.MessageBox('您确定要更改客户吗?','警告:',MB_OKCANCEL)<>IDOK then exit; v_all_client.close; v_all_client.open; old_name:=DBEdit5.text; old_code:=DBEdit4.text; if v_all_client.IsEmpty then begin try t_crm_client.edit; t_crm_client['代码']:=trim(Edit4.text); t_crm_client['客户简称']:=trim(Edit5.text); t_crm_client.post; except t_crm_client.Cancel; t_crm_client.Refresh; bsSkinButton2.Enabled:=false; showmessage('客户更改失败!!'); end; end else begin try t_crm_client.edit; t_crm_client['代码']:=trim(Edit4.text); t_crm_client['客户简称']:=trim(Edit5.text); t_crm_client.post; p_update_client.Parameters.ParamByName('old_name').value:=old_name; p_update_client.Parameters.ParamByName('new_name').value:=trim(Edit5.text); p_update_client.ExecProc; except t_crm_client.Cancel; t_crm_client.Refresh; bsSkinButton2.Enabled:=false; end; end; frm_main.t_sys_message_no.insert; frm_main.t_sys_message_no['类型']:='客户更改'; frm_main.t_sys_message_no['发送方']:=employee; frm_main.t_sys_message_no['发送地址']:=LocalIP; frm_main.t_sys_message_no['是否知道']:=1; frm_main.t_sys_message_no['时间']:=now; frm_main.t_sys_message_no['事件描述']:='客户更改:更改前:'+old_code+','+old_name +';更改后:'+Edit4.text+','+Edit5.text; frm_main.t_sys_message_no.post; { SendMsg_gonggao('51','更改前:'+old_code+','+old_name +';更改后:'+Edit4.text+','+Edit5.text); } showmessage('客户更改成功!!'); bsSkinButton1.Enabled:=false; bsSkinButton2.Enabled:=false; Edit4.text:=''; Edit5.text:=''; v_all_client.close; end; procedure Tfrm_crm_client_special.bsSkinButton4Click(Sender: TObject); begin t_crm_client_wrong.close; t_crm_client_wrong.open; end; procedure Tfrm_crm_client_special.bsSkinButton3Click(Sender: TObject); var old_name:string; begin if t_crm_client_wrong.IsEmpty then exit; if RxDBLookupCombo2.DisplayValue=''then begin showmessage('请输入要替换成的客户!!'); exit; end; old_name:=t_crm_client_wrong.fieldbyname('客户简称').asstring; if application.MessageBox('您确定要纠正错误客户吗?','警告:',MB_OKCANCEL)<>IDOK then exit; try p_update_client.Parameters.ParamByName('old_name').value:=t_crm_client_wrong.fieldbyname('客户简称').asstring; p_update_client.Parameters.ParamByName('new_name').value:=RxDBLookupCombo2.DisplayValues[1]; p_update_client.ExecProc; except showmessage('纠正客户失败!!'); exit; end; showmessage('纠正客户成功!!'); t_crm_client_wrong.requery; frm_main.t_sys_message_no.insert; frm_main.t_sys_message_no['类型']:='客户纠错'; frm_main.t_sys_message_no['发送方']:=employee; frm_main.t_sys_message_no['发送地址']:=LocalIP; frm_main.t_sys_message_no['是否知道']:=1; frm_main.t_sys_message_no['时间']:=now; frm_main.t_sys_message_no['事件描述']:='客户纠错:将业务中使用的客户名称('+old_name +')更换为('+RxDBLookupCombo2.DisplayValues[1]+')'; frm_main.t_sys_message_no.post; end; procedure Tfrm_crm_client_special.bsSkinButton5Click(Sender: TObject); var str:widestring; begin str:='where 客户性质<>'+''''+'目标'+''''; if Edit6.text<>''then begin str:=str+' and 代码 like '+''''+'%'+Edit6.text+'%'+''''; end; if Edit7.text<>''then begin str:=str+' and 客户简称 like '+''''+'%'+Edit7.text+'%'+''''; end; t_crm_client_ti.close; t_crm_client_ti.sql.clear; t_crm_client_ti.sql.add('select * from t_crm_client '+str+' order by 代码'); t_crm_client_ti.open; end; procedure Tfrm_crm_client_special.bsSkinButton6Click(Sender: TObject); var old_name:string; str_tell:string; begin if t_crm_client_ti.IsEmpty then exit; if RxDBLookupCombo1.DisplayValue=''then begin showmessage('请输入要合并成的客户!!'); exit; end; old_name:=t_crm_client_ti.fieldbyname('客户简称').asstring; str_tell:='您确定要将‘'+old_name+'’合并成‘'+RxDBLookupCombo1.DisplayValues[1]+'’吗?'; if application.MessageBox(pchar(str_tell),'警告:',MB_OKCANCEL)<>IDOK then exit; try p_update_client.Parameters.ParamByName('old_name').value:=t_crm_client_ti.fieldbyname('客户简称').asstring; p_update_client.Parameters.ParamByName('new_name').value:=RxDBLookupCombo1.DisplayValues[1]; p_update_client.ExecProc; t_crm_client_ti.Delete; except showmessage('合并客户失败!!'); exit; end; showmessage('合并客户成功!!'); t_crm_client_ti.requery; frm_main.t_sys_message_no.insert; frm_main.t_sys_message_no['类型']:='客户合并'; frm_main.t_sys_message_no['发送方']:=employee; frm_main.t_sys_message_no['发送地址']:=LocalIP; frm_main.t_sys_message_no['是否知道']:=1; frm_main.t_sys_message_no['时间']:=now; frm_main.t_sys_message_no['事件描述']:='客户合并:将业务中使用的客户名称('+old_name +')合并为('+RxDBLookupCombo1.DisplayValues[1]+')'; frm_main.t_sys_message_no.post; { SendMsg_gonggao('51','合并前:'+old_name +';合并后:'+RxDBLookupCombo1.DisplayValues[1]); } end; end.