unit u_op_seae_signqtdlist; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, dxExEdtr, dxCntner, dxTL, dxDBCtrl, dxDBGrid, bsSkinCtrls, DB, ADODB, ExtCtrls, RxLookup, StdCtrls, wwdbdatetimepicker, wwdblook, Menus, Mask, bsSkinBoxCtrls, bsdbctrls,DateUtils, kbmMemTable, DBCtrlsEh,ShellAPI, ComCtrls, bsSkinTabs, dxDBTLCl, dxGrClms, cxDBLabel, cxControls, cxContainer, cxEdit, cxLabel; type Tfrm_op_seae_signqdtlist = class(TForm) t_op_seae: TADOQuery; t_op_seae1: TDataSource; kbmMemTable1: TkbmMemTable; kbmMemTable1Field: TStringField; kbmMemTable1Field3: TStringField; kbmMemTable1Field4: TStringField; kbmMemTable1Field5: TStringField; kbmMemTable1Field6: TStringField; kbmMemTable1Field7: TStringField; kbmMemTable1Field2: TStringField; kbmMemTable1Field9: TStringField; kbmMemTable1Field10: TStringField; kbmMemTable1Field8: TStringField; PopupMenu1: TPopupMenu; N1: TMenuItem; kbmMemTable1Field11: TStringField; kbmMemTable1Field12: TStringField; kbmMemTable1Field13: TStringField; kbmMemTable1Field14: TStringField; kbmMemTable1Field15: TStringField; kbmMemTable1Field16: TStringField; bsSkinPanel3: TbsSkinPanel; btn3_notify: TbsSkinButton; btn6_exit: TbsSkinButton; btn1_search: TbsSkinButton; btn2_clear: TbsSkinButton; bsSkinPanel4: TbsSkinPanel; Label13: TLabel; Label14: TLabel; wwDBDateTimePicker5: TwwDBDateTimePicker; wwDBDateTimePicker6: TwwDBDateTimePicker; dxDBGrid1: TdxDBGrid; dxDBGridColumn2: TdxDBGridColumn; dxDBGridColumn4: TdxDBGridColumn; dxDBGridColumn7: TdxDBGridColumn; dxDBGridColumn8: TdxDBGridColumn; dxDBGrid1Column6: TdxDBGridColumn; dxDBGrid1Column7: TdxDBGridColumn; dxDBGrid1Column8: TdxDBGridColumn; Edit6_searchkhmch: TEdit; Label8: TLabel; kbmMemTable1Field17: TStringField; kbmMemTable1Field18: TStringField; kbmMemTable1Field19: TStringField; kbmMemTable1Field20: TStringField; kbmMemTable1Field21: TStringField; kbmMemTable1Field22: TBooleanField; kbmMemTable1Field23: TStringField; dxdbgrdclmnDBGrid1Column10: TdxDBGridColumn; kbmMemTable1Field24_xuanxiang: TBooleanField; dxdbgrdclmnDBGrid1Column11: TdxDBGridColumn; dxdbgrdclmnDBGrid1Column12: TdxDBGridColumn; dxdbgrdclmnDBGrid1Column13: TdxDBGridColumn; Edit1_qdtbh: TEdit; lbl14: TLabel; lbl15_searchqdthm: TLabel; Edit15_searchqdthm: TEdit; bsknpnl1_m: TbsSkinPanel; qry1_qdtm: TADOQuery; ds1: TDataSource; lbl10: TLabel; cbb1: TDBComboBoxEh; dxdbgrdclmnDBGrid1Column14: TdxDBGridColumn; dxdbgrdchckclmnDBGrid1Column14_tf: TdxDBGridCheckColumn; dxdbgrdclmnDBGrid1Column15: TdxDBGridColumn; dxdbgrdchckclmnDBGrid1Column13b: TdxDBGridCheckColumn; mniN2: TMenuItem; mniN3: TMenuItem; dxdbgrdclmnDBGrid1Column16: TdxDBGridColumn; dxdbgrdclmnDBGrid1Column17: TdxDBGridColumn; procedure btn4_exitClick(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure N1Click(Sender: TObject); procedure Edit3_ztdhKeyPress(Sender: TObject; var Key: Char); procedure btn1_searchClick(Sender: TObject); procedure MenuItem1Click(Sender: TObject); procedure btn6_exitClick(Sender: TObject); procedure FormShow(Sender: TObject); procedure searchqdt(bh:string); procedure Edit1_qdtbhKeyPress(Sender: TObject; var Key: Char); procedure dxDBGrid1DblClick(Sender: TObject); procedure btn3_notifyClick(Sender: TObject); procedure Edit6_searchkhmchKeyPress(Sender: TObject; var Key: Char); procedure mniN2Click(Sender: TObject); procedure mniN3Click(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); private { Private declarations } employeePhone:string; function CheckBilldue():Boolean; public { Public declarations } op:integer; function GetmblState(bsno:string):Boolean; function GetmblzbState(bsno:string):Boolean; function GetmblStateOut(bsno:string):Boolean; procedure UpateSeaeState(bsno,billstate:string); function GetSeaeStateDate(bsno,billstate:string):string; function _GetmblStateout(bsno,bsstatus:string):string; procedure Initsql_ts(AdoQuery:TAdoQuery); procedure initialEmployeePhone(); procedure show_qdtxx(qdtbh:string;iway:Integer); end; var frm_op_seae_signqdtlist: Tfrm_op_seae_signqdtlist; implementation uses u_main,my_sys_function, u_op_seae_teshufandan,u_sys_progress,u_op_seae_sign_info, u_op_seae_sign; {$R *.dfm} const stateNewQD = '生成签单条'; // function Tfrm_op_seae_signqdtlist._GetmblStateout(bsno,bsstatus:string):string; var aAdoQuery:TAdoQuery; begin result:=''; aAdoQuery:=CreateAdoQuery; with aAdoQuery do try Close;SQL.Clear; SQL.Add('select 编号,业务状态,录入日期'); SQL.Add('from t_op_state where 编号=:bsNo1 and 业务状态=:bsstatus '); Parameters.ParamByName('bsNo1').value:=bsno; Parameters.ParamByName('bsstatus').value:=bsstatus; Open; if not IsEmpty then result:=FieldByName('业务状态').AsString; finally aAdoQuery.Free; end; end; function Tfrm_op_seae_signqdtlist.GetSeaeStateDate(bsno,billstate:string):string; var aAdoQuery:TAdoQuery; begin Result:=''; aAdoQuery:=CreateAdoQuery; with aAdoQuery do try Close;SQL.Clear; SQL.Add('select 编号,录入日期 处理日期 from t_op_state'); SQL.Add('where 编号=:bsNo and 业务状态=:billstate'); Parameters.ParamByName('bsNo').value:=bsno; Parameters.ParamByName('billstate').value:=billstate; open; if not IsEmpty then Result:=FormatDateTime('YYYY-MM-DD',FieldByName('处理日期').AsDateTime); finally aAdoQuery.Free; end; end; procedure Tfrm_op_seae_signqdtlist.UpateSeaeState(bsno,billstate:string); var aAdoQuery:TAdoQuery; begin aAdoQuery:=CreateAdoQuery; with aAdoQuery do try Close;SQL.Clear; SQL.Add('Update t_op_Seae'); SQL.Add('set 提单签发状态=:billstate where 编号=:bsNo'); Parameters.ParamByName('bsNo').value:=bsno; Parameters.ParamByName('billstate').value:=billstate; execsql; finally aAdoQuery.Free; end; end; function Tfrm_op_seae_signqdtlist.GetmblState(bsno:string):Boolean; var aAdoQuery:TAdoQuery; b1,b2,b3:Boolean; begin result:=false; aAdoQuery:=CreateAdoQuery; with aAdoQuery do try Close;SQL.Clear; SQL.Add('select 编号,业务状态'); SQL.Add('from t_op_state where 业务状态=''通知放单'' and 编号=:bsNo'); Parameters.ParamByName('bsNo').value:=bsno; Open; b1:=RecordCount>=1; Close;SQL.Clear; SQL.Add('select 编号,业务状态'); SQL.Add('from t_op_state where 业务状态=''提单签出'' and 编号=:bsNo'); Parameters.ParamByName('bsNo').value:=bsno; Open; b2:=RecordCount>=1; Close;SQL.Clear; SQL.Add('select 编号,业务状态'); SQL.Add('from t_op_state where 业务状态=''提单签发'' and 编号=:bsNo'); Parameters.ParamByName('bsNo').value:=bsno; Open; b3:= isempty or (RecordCount=0); result:=(b1 or b2) and b3; finally aAdoQuery.Free; end; end; function Tfrm_op_seae_signqdtlist.GetmblzbState(bsno:string):Boolean; // var aAdoQuery:TAdoQuery; b1,b2,b3,b4:Boolean; begin result:=false; aAdoQuery:=CreateAdoQuery; with aAdoQuery do try Close;SQL.Clear; SQL.Add('select 编号,业务状态'); SQL.Add('from t_op_state where 业务状态=''通知放单'' and 编号=:bsNo'); Parameters.ParamByName('bsNo').value:=bsno; Open; b1:=RecordCount>=1; Close;SQL.Clear; SQL.Add('select 编号,业务状态'); SQL.Add('from t_op_state where 业务状态=''提单签入'' and 编号=:bsNo'); Parameters.ParamByName('bsNo').value:=bsno; Open; b2:=RecordCount>=1; Close;SQL.Clear; SQL.Add('select 编号,业务状态'); SQL.Add('from t_op_state where 业务状态=''提单签出'' and 编号=:bsNo'); Parameters.ParamByName('bsNo').value:=bsno; Open; b3:=RecordCount>=1; Close;SQL.Clear; SQL.Add('select 编号,业务状态'); SQL.Add('from t_op_state where 业务状态=''提单签发'' and 编号=:bsNo'); Parameters.ParamByName('bsNo').value:=bsno; Open; b4:= isempty or (RecordCount=0); result:=(b1 or b2 or b3) and b4; finally aAdoQuery.Free; end; end; function Tfrm_op_seae_signqdtlist.GetmblStateOut(bsno:string):Boolean; var aAdoQuery:TAdoQuery; begin result:=false; aAdoQuery:=CreateAdoQuery; with aAdoQuery do try Close;SQL.Clear; SQL.Add('select 编号,业务状态'); SQL.Add('from t_op_state where 业务状态=''提单签出'' and 编号=:bsNo'); Parameters.ParamByName('bsNo').value:=bsno; Open; result:=RecordCount=1; finally aAdoQuery.Free; end; end; procedure Tfrm_op_seae_signqdtlist.btn4_exitClick(Sender: TObject); begin Close; end; procedure Tfrm_op_seae_signqdtlist.FormShow(Sender: TObject); var str,mblstatus:string; begin Width :=width-1; dxDBGrid1.Width :=dxDBGrid1.width-1; bsSkinPanel3.Height :=34; wwDBDateTimePicker5.Date:=Date-7;//StrToDateTime(Formatdatetime('YYYY-MM-DD',date-3)); wwDBDateTimePicker6.Date:=Date;//StrToDateTime(Formatdatetime('YYYY-MM-DD',date)); show_qdtxx('',1); Edit1_qdtbh.SetFocus(); loadreggrid(dxdbgrid1,false,caption ); end; procedure Tfrm_op_seae_signqdtlist.FormClose(Sender: TObject; var Action: TCloseAction); begin savereggrid(dxdbgrid1,caption); frm_op_seae_signqdtlist.Hide; frm_op_seae_signqdtlist.ManualFloat(frm_op_seae_signqdtlist.BoundsRect ); frm_main.freeTabs('frm_op_seae_signqdtlist'); action:=cafree; frm_op_seae_signqdtlist:=nil; end; procedure Tfrm_op_seae_signqdtlist.Initsql_ts(AdoQuery:TAdoQuery); begin with AdoQuery do begin Close;Sql.Clear; SQL.Add('Select 编号,放单状态 from t_op_fangdan'); sql.add('order by 编号'); Open;First; end; end; procedure Tfrm_op_seae_signqdtlist.N1Click(Sender: TObject); begin //grid_save_xls(dxdbgrd2); end; procedure Tfrm_op_seae_signqdtlist.Edit3_ztdhKeyPress(Sender: TObject; var Key: Char); begin if key=#13 then begin key:=#0; //bsSkinButton8Click(Sender); end; end; procedure Tfrm_op_seae_signqdtlist.btn1_searchClick(Sender: TObject); begin // show_qdtxx('',1); end; procedure Tfrm_op_seae_signqdtlist.MenuItem1Click(Sender: TObject); begin grid_save_xls(dxDBGrid1); end; procedure Tfrm_op_seae_signqdtlist.btn6_exitClick(Sender: TObject); begin Close(); end; procedure Tfrm_op_seae_signqdtlist.initialEmployeePhone(); var empQuery:TADOQuery; begin // empQuery:=CreateAdoQuery(); with empQuery do begin SQL.Add('select [固定电话],[移动电话] from [t_sys_employee] where [姓名]='''+ employee +''' '); Open;First; employeePhone :=FieldByName('固定电话').AsString; close(); end; end; procedure Tfrm_op_seae_signqdtlist.searchqdt(bh:string); begin // if bh<>'' then begin // show_qdtxx(bh,1); end; end; procedure Tfrm_op_seae_signqdtlist.Edit1_qdtbhKeyPress(Sender: TObject; var Key: Char); var str:string; begin // if key=#13 then begin str:= Edit1_qdtbh.Text; Edit1_qdtbh.Clear(); Edit15_searchqdthm.Text:=str; show_qdtxx(str,0); end; end; procedure Tfrm_op_seae_signqdtlist.dxDBGrid1DblClick(Sender: TObject); var str:string; begin // str:=qry1_qdtm.FieldByName('签单条编号').AsString; show_qdtxx(str,2); qry1_qdtm.Requery(); end; procedure Tfrm_op_seae_signqdtlist.show_qdtxx (qdtbh:string;iway:Integer); var str:string; begin //初始化窗体 if not assigned(frm_op_seae_sign_info) then frm_op_seae_sign_info:=Tfrm_op_seae_sign_info.Create (self); //双击进行显示明细 if iway=2 then begin frm_op_seae_sign_info.InitialUserinfo(qdtbh,3); frm_op_seae_sign_info.SigninfoShow(); Exit; end; if(qdtbh<>'') then str :=' where 签单条编号 =''' +qdtbh + '''' else begin // str:=' where 1=1'; if wwDBDateTimePicker5.text<>''then str:=str+' and t_op_seae_sign_main.录入日期>='+''''+wwDBDateTimePicker5.text+''''; if wwDBDateTimePicker6.text<>''then str:=str+' and t_op_seae_sign_main.录入日期<='+''''+wwDBDateTimePicker6.text+' 23:59:59'''; if Edit6_searchkhmch.text<>''then str:=str+' and t_op_seae_sign_main.客户名称 like'+'''%'+stringreplace(trim(Edit6_searchkhmch.text),'''','''''',[rfReplaceAll])+'%'''; end; str:='SELECT *,case 是否特放 when 1 then 录入日期+1 else null end as 截止日期 FROM [t_op_seae_sign_main] ' +str; qry1_qdtm.Close() ; qry1_qdtm.SQL.Clear; qry1_qdtm.SQL.Add(str); qry1_qdtm.open; qry1_qdtm.First; if qry1_qdtm.IsEmpty then begin showmessage('没有检索出要查找的记录!!'); exit; end; if (qry1_qdtm.Recordset.RecordCount=1) and (qdtbh<>'') and (iway=0) then begin // frm_op_seae_sign_info.InitialUserinfo(qdtbh,3); frm_op_seae_sign_info.SigninfoShow(); end; end; /// /// 检查客户是否欠费 /// function Tfrm_op_seae_signqdtlist.CheckBilldue():Boolean; var FeeItems:string; amt,usd:Double; wtdw,tdh:string; begin wtdw:=t_op_seae.FieldByName('委托单位').AsString; tdh:=t_op_seae.FieldByName('主提单号').AsString; if (Trim(t_op_seae.FieldByName('结费类型').AsString)='') or (Trim(t_op_seae.FieldByName('结费类型').AsString)='无帐期') or (Trim(t_op_seae.FieldByName('结费类型').AsString)='现结买单') or (t_op_seae.FieldByName('结费类型').IsNull) then begin if GetCrmsales(t_op_seae.FieldByName('编号').AsString ,t_op_seae.FieldByName('委托单位').AsString,t_op_seae.FieldByName('结费类型').AsString,amt,usd,FeeItems) then begin //客户结费类型为票结 MessageDlg('主提单号为"'+ tdh+'"的'+wtdw+'客户结费类型为票结人民币金额为:'+FormatFloat('0.00;0.00;0',amt) +'美元金额为:'+FormatFloat('0.00;0.00;0',USD) +'不能生成签单条',mtWarning,[mbok],0); Result:=False; end ; end else begin if GetCrmsales(t_op_seae.FieldByName('编号').AsString,t_op_seae.FieldByName('委托单位').AsString ,t_op_seae.FieldByName('结费类型').AsString,amt,usd,FeeItems) then begin MessageDlg( '主提单号为"'+ tdh+'"的'+wtdw+'客户结费类型为月结人民币金额为:'+FormatFloat('0.00;0.00;0',amt) +'美元金额为:'+FormatFloat('0.00;0.00;0',USD) +'不能生成签单条',mtWarning,[mbok],0); Result:=False; end; end; end; //end CheckBilldue procedure Tfrm_op_seae_signqdtlist.btn3_notifyClick(Sender: TObject); var qdtzht,strsql:string; i,noticecount:integer; aQuery:TADOQuery; DatabaseDateTime:TDatetime; qdtlx:string; begin // if dxDBGrid1.SelectedCount<1 then Exit; aQuery:=CreateAdoQuery; with aQuery do try Close;sql.Clear; sql.Add('select GetDate() as FDate'); open; DatabaseDateTime:=FieldValues['FDate']; finally FreeAndNil(aQuery); end; { 生成签单条 已打印签单条 已发送签单条 通知迁出签单条 签出签单条 财务签字签单条 客户签字签单条 } noticecount:=0; //检查状态 try frm_main.db.BeginTrans; for i:=0 to dxDBGrid1.SelectedCount-1 do begin qry1_qdtm.GoTobookmark(pointer(dxDBGrid1.SelectedRows[i])); qdtzht := qry1_qdtm.FieldByName('状态').AsString; qdtlx:= qry1_qdtm.FieldByName('签单条类型').AsString; if (qdtlx='票结') and (qdtzht='生成签单条') or (qdtzht='已打印签单条') or (qdtzht='已发送签单条') then begin // qry1_qdtm.Edit; qry1_qdtm.FieldByName('状态').AsString:='通知签出签单条'; qry1_qdtm.FieldByName('通知签出时间').AsDateTime:= GetDbDatetime; strsql:='INSERT INTO [dbo].[t_op_state]([编号],[业务状态],[录入人] ,[录入日期] ) ' +'select 编号 ,''通知签出'' as 业务状态,'''+ employee +''' as 录入人 ,GETDATE() 录入日期 from' +' (select 编号 from t_op_seae_sign_detail d where 签单条编号='''+ qry1_qdtm.FieldByName('签单条编号').AsString +'''' +' and not exists (select 编号 from [t_op_state] where 业务状态=''通知签出'' and 编号= d.编号 )) v;'; frm_main.db.Execute(strsql); noticecount:=noticecount+1; end; end; frm_main.db.CommitTrans; if noticecount>0 then application.MessageBox(PChar('签单条通知已发出,共发出'+IntToStr(noticecount)+'条信息'),'信息提示') ; qry1_qdtm.Requery(); except on ex: Exception do begin errorlog(ex.Message) ; ShowMessage(ex.Message); qry1_qdtm.Cancel; frm_main.db.rollbacktrans; end; end; end; procedure Tfrm_op_seae_signqdtlist.Edit6_searchkhmchKeyPress( Sender: TObject; var Key: Char); begin // 回车自动查询 if key=#13 then begin btn1_searchClick(btn1_search); end; end; procedure Tfrm_op_seae_signqdtlist.mniN2Click(Sender: TObject); var tmpfile:string; begin if qry1_qdtm.IsEmpty then exit; try tmpfile:=qry1_qdtm.fieldbyname('客户签字').asstring ; if(tmpfile='') or (not FileExists(tmpfile)) then Exit; ShellExecute(Handle, nil, pchar(tmpfile), nil, nil, SW_NORMAL); except showmessage('不能打开文件,请检查!'); end ; end; procedure Tfrm_op_seae_signqdtlist.mniN3Click(Sender: TObject); var tmpfile:string; begin if qry1_qdtm.IsEmpty then exit; try tmpfile:=qry1_qdtm.fieldbyname('财务签字').asstring ; if(tmpfile='') or (not FileExists(tmpfile)) then Exit; ShellExecute(Handle, nil, pchar(tmpfile), nil, nil, SW_NORMAL); except showmessage('不能打开文件,请检查!'); end ; end; procedure Tfrm_op_seae_signqdtlist.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); var value:string; begin value:=ANode.Strings[dxdbgrdchckclmnDBGrid1Column14_tf.Index]; if value ='True' then begin AFont.Color:=clgreen; end else AFont.Color:=clblack; end; end.