unit u_op_seae_teshushen; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, dxExEdtr, XPMenu, Menus, dxDBTLCl, dxGrClms, dxDBCtrl, dxDBGrid, dxTL, dxCntner, DB, ADODB, Mask, wwdbedit, Wwdotdot, Wwdbcomb, wwdblook, RxLookup, wwdbdatetimepicker, StdCtrls, bsSkinCtrls, ExtCtrls, ComCtrls, bsSkinTabs, DBCtrls,DateUtils, DBCtrlsEh, DBLookupEh; type Tfrm_op_seae_teshushenhe = class(TForm) t_op_seae: TADOQuery; t_op_seae1: TDataSource; bsSkinButton13: TbsSkinButton; bsSkinButton1: TbsSkinButton; PopupMenu2: TPopupMenu; N16: TMenuItem; XPMenu1: TXPMenu; t_op_seaesel: TADOQuery; ds_op_seaesel1: TDataSource; pm1: TPopupMenu; N1: TMenuItem; N2: TMenuItem; N3: TMenuItem; bsSkinPanel2: TbsSkinPanel; bsSkinPanel3: TbsSkinPanel; bsSkinButton3: TbsSkinButton; bsSkinButton7: TbsSkinButton; bsSkinButton8: TbsSkinButton; t_op_bill: TADOQuery; ds_op_bill1: TDataSource; bsSkinPageControl1: TbsSkinPageControl; bskntbsht1: TbsSkinTabSheet; bskntbsht2: TbsSkinTabSheet; dxDBGrid2: TdxDBGrid; dxDBGrid2Column2: TdxDBGridColumn; dxDBGrid2Column3: TdxDBGridColumn; dxDBGrid2Column4: TdxDBGridColumn; dxDBGrid2Column5: TdxDBGridColumn; dxDBGrid2Column6: TdxDBGridColumn; bsSkinPanel4: TbsSkinPanel; dxDBGrid3: TdxDBGrid; dxDBGridMaskColumn4: TdxDBGridMaskColumn; dxDBGridMaskColumn7: TdxDBGridMaskColumn; dxDBGridMaskColumn13: TdxDBGridMaskColumn; dxDBGridMaskColumn14: TdxDBGridMaskColumn; dxDBGridMaskColumn15: TdxDBGridMaskColumn; dxDBGridDateColumn1: TdxDBGridDateColumn; dxDBGridMaskColumn17: TdxDBGridMaskColumn; dxDBGridMaskColumn24: TdxDBGridMaskColumn; dxDBGridMaskColumn57: TdxDBGridMaskColumn; dxDBGridMaskColumn58: TdxDBGridMaskColumn; dxDBGridMaskColumn61: TdxDBGridMaskColumn; PopupMenu1: TPopupMenu; MenuItem1: TMenuItem; bsSkinButton5: TbsSkinButton; bsSkinButton9: TbsSkinButton; PopupMenu3: TPopupMenu; MenuItem2: TMenuItem; dxDBGrid2Column7: TdxDBGridColumn; bsSkinPanel5: TbsSkinPanel; Panel1: TPanel; bsSkinButton11: TbsSkinButton; Label17: TLabel; wwDBDateTimePicker6: TwwDBDateTimePicker; Label18: TLabel; wwDBDateTimePicker7: TwwDBDateTimePicker; Label19: TLabel; dxDBGrid2Column8: TdxDBGridColumn; dxDBGrid2Column9: TdxDBGridColumn; dxDBGrid3Column12: TdxDBGridColumn; dxDBGrid3Column13: TdxDBGridColumn; dxDBGrid3Column14: TdxDBGridColumn; dxDBGrid3Column15: TdxDBGridColumn; Label4: TLabel; Label7: TLabel; Label12: TLabel; Label13: TLabel; Label14: TLabel; Label21: TLabel; Label22: TLabel; Label23: TLabel; Label24: TLabel; Label15: TLabel; Label25: TLabel; Label26: TLabel; RxDBLookupCombo4: TRxDBLookupCombo; DBEdit9: TDBEdit; DBEdit10: TDBEdit; wwDBDateTimePicker5: TwwDBDateTimePicker; DBEdit1: TDBEdit; RxDBLookupCombo5: TRxDBLookupCombo; wwDBDateTimePicker8: TwwDBDateTimePicker; RxDBLookupCombo7: TRxDBLookupCombo; wwDBDateTimePicker9: TwwDBDateTimePicker; DBEdit2: TDBEdit; DBEdit3: TDBEdit; RxDBLookupCombo8: TRxDBLookupCombo; dxDBGrid2Column10: TdxDBGridColumn; dxDBGrid2Column11: TdxDBGridColumn; bsSkinButton38: TbsSkinButton; dxDBGrid2Column12: TdxDBGridColumn; dxDBGrid2Column13: TdxDBGridColumn; dxDBGrid2Column14: TdxDBGridColumn; DBMemo1: TDBMemo; Label1: TLabel; Label29: TLabel; DBMemo2: TDBMemo; Label2: TLabel; Label3: TLabel; ComboBox1: TComboBox; dxDBGrid2Column15: TdxDBGridColumn; DataSource1: TDataSource; ADOQuery1: TADOQuery; RxDBLookupCombo31: TRxDBLookupCombo; dxDBGrid3Column16: TdxDBGridColumn; RxDBLookupCombo3: TRxDBLookupCombo; Label35: TLabel; dxDBGrid2Column16: TdxDBGridColumn; Label36: TLabel; DBMemo3: TDBMemo; dxDBGrid2Column17: TdxDBGridColumn; dxDBGrid2Column18: TdxDBGridColumn; Label37: TLabel; DBEdit4: TDBEdit; Label38: TLabel; DBEdit5: TDBEdit; Label39: TLabel; DBEdit6: TDBEdit; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormShow(Sender: TObject); procedure bsSkinButton3Click(Sender: TObject); procedure bsSkinButton7Click(Sender: TObject); procedure bsSkinButton8Click(Sender: TObject); procedure bsSkinButton5Click(Sender: TObject); procedure bsSkinButton9Click(Sender: TObject); procedure bsSkinButton38Click(Sender: TObject); procedure dxDBGrid2Click(Sender: TObject); procedure N16Click(Sender: TObject); procedure bsSkinButton11Click(Sender: TObject); procedure t_op_billBeforeEdit(DataSet: TDataSet); procedure dxDBGrid3Column16CustomDraw(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 RxDBLookupCombo3Enter(Sender: TObject); procedure RxDBLookupCombo3Exit(Sender: TObject); procedure dxDBGrid2CustomDraw(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 } public { Public declarations } function UpdateBillStatus(bsStStatus:string):Boolean; end; var frm_op_seae_teshushenhe: Tfrm_op_seae_teshushenhe; implementation uses my_sys_function, u_main; {$R *.dfm} function Tfrm_op_seae_teshushenhe.UpdateBillStatus(bsStStatus:string):Boolean; var aAdoQuery,aAdoQuerySelect:TAdoQuery; begin {var aAdoQuery:TAdoQuery; begin result:=False; aAdoQuery:=CreateAdoQuery; with aAdoQuery do try Close;Sql.Clear; SQL.Add('select count(编号) c from t_op_fangdan'); SQL.Add('where 编号=:编号'); Parameters.ParamByName('编号').Value:=BsNo; Open; if aAdoQuery.FieldByName('c').AsInteger=0 then begin Close;Sql.Clear; SQL.Add('Insert into t_op_fangdan (编号, 放单状态,申请人,申请日期)'); SQL.Add('values (:编号,:放单状态,:申请人,:申请日期)'); Parameters.ParamByName('编号').Value:=BsNo; Parameters.ParamByName('放单状态').Value:='申请放单'; Parameters.ParamByName('申请人').Value:=employee; Parameters.ParamByName('申请日期').Value:=date; ExecSQL; end; finally aAdoQuery.Free; end; } result:=False; aAdoQuery:=CreateAdoQuery; aAdoQuerySelect:=CreateAdoQuery; with t_op_seaesel do try Open;First; while not eof do begin aAdoQuerySelect.Close;aAdoQuerySelect.Sql.Clear; aAdoQuerySelect.SQL.Add('select count(编号) c from t_op_fangdan'); aAdoQuerySelect.SQL.Add('where 编号=:编号'); aAdoQuerySelect.Parameters.ParamByName('编号').Value:=fieldByName('编号').AsString; aAdoQuerySelect.Open; if aAdoQuerySelect.FieldByName('c').AsInteger=0 then begin aAdoQuery.Close;aAdoQuery.Sql.Clear; aAdoQuery.SQL.Add('Insert into t_op_fangdan (编号, 放单状态)'); aAdoQuery.SQL.Add('values (:编号,:放单状态)'); aAdoQuery.Parameters.ParamByName('编号').Value:=fieldByName('编号').AsString; aAdoQuery.Parameters.ParamByName('放单状态').Value:=bsStStatus; aAdoQuery.ExecSQL; end else begin aAdoQuery.Close;aAdoQuery.Sql.Clear; aAdoQuery.SQL.Add('Update t_op_fangdan set 放单状态=:放单状态'); aAdoQuery.SQL.Add('where 编号=:编号'); aAdoQuery.Parameters.ParamByName('编号').Value:=fieldByName('编号').AsString; aAdoQuery.Parameters.ParamByName('放单状态').Value:=bsStStatus; aAdoQuery.ExecSQL; end; Next; end; finally aAdoQuery.Free; aAdoQuerySelect.Free; end; end; procedure Tfrm_op_seae_teshushenhe.FormClose(Sender: TObject; var Action: TCloseAction); begin frm_op_seae_teshushenhe.Hide; frm_op_seae_teshushenhe.ManualFloat(frm_op_seae_teshushenhe.BoundsRect ); frm_main.freeTabs('frm_op_seae_teshushenhe'); action:=cafree; frm_op_seae_teshushenhe:=nil; end; procedure Tfrm_op_seae_teshushenhe.FormShow(Sender: TObject); begin with t_op_bill do begin Parameters.ParamByName('Employee').Value:=Employee; Open; end; t_op_seaesel.Open; ADOQuery1.Open; if t_op_bill.FieldByName('特批标志').AsInteger=1 then begin Label35.Visible:=True; Label35.Caption:='此特放需要特批!'; end else begin label35.Visible:=false; Label35.Caption:=''; end; end; procedure Tfrm_op_seae_teshushenhe.bsSkinButton3Click(Sender: TObject); begin if t_op_bill.State in [dsedit,dsinsert] then t_op_bill.Post; end; procedure Tfrm_op_seae_teshushenhe.bsSkinButton7Click(Sender: TObject); begin if t_op_bill.IsEmpty then exit; t_op_bill.Cancel; end; procedure Tfrm_op_seae_teshushenhe.bsSkinButton8Click(Sender: TObject); begin Close; end; procedure Tfrm_op_seae_teshushenhe.bsSkinButton5Click(Sender: TObject); var aQuery:TADOQuery; begin if t_op_bill.IsEmpty then exit; aQuery:=CreateAdoQuery; try with aQuery do begin close;SQL.Clear; sql.add('select 特殊放单提醒,特殊放单条件 from t_crm_client where 客户简称='''+t_op_bill.FieldByName('委托单位').AsString+''''); open; if not IsEmpty then begin if FieldByName('特殊放单提醒').AsString='是' then begin if MessageDlg(t_op_bill.FieldByName('委托单位').AsString+'有特殊放单条件,特殊放单条件为:'+fieldbyname('特殊放单条件').AsString+#13#10+'确实要放单吗?',mtWarning,[mbyes,mbno],0)<>mryes then begin exit; end; end; end; end; finally FreeAndNil(aQuery); end; if t_op_bill.FieldByName('业务审核日期').IsNull then begin showmessage('销售没有审核,不能审核!'); Exit; end else begin t_op_bill.edit; t_op_bill['状态']:='主管审核'; t_op_bill['签单日期']:=date; t_op_bill['签单人']:=employee; t_op_bill.post; UpdateBillStatus('主管审核'); with t_op_seaesel do begin First; while not eof do begin InsertSeaeStatus(FieldByName('编号').AsString,'主管审核',employee,FormatDateTime('YYYY-MM-DD',Now)); Next; end; end; t_op_bill.Refresh; end; end; procedure Tfrm_op_seae_teshushenhe.bsSkinButton9Click(Sender: TObject); var str:string; begin if t_op_bill.IsEmpty then exit; if t_op_bill.FieldByName('签单日期').IsNull then begin showmessage('没有审核,不用取消审核!!'); Exit; end else if (not t_op_bill.FieldByName('签单日期').IsNull) and t_op_bill.FieldByName('副总审核日期').IsNull then begin t_op_bill.edit; t_op_bill['状态']:='销售审核'; t_op_bill['签单日期']:=null; t_op_bill.post; UpdateBillStatus('销售审核'); with t_op_seaesel do begin First; while not eof do begin DelteSeaeStatus(fieldbyname('编号').AsString,'主管审核'); Next; end; end; t_op_bill.Refresh; end else showmessage('副总已经审核不能取消审核,副总取消审核后才可以审核!'); end; procedure Tfrm_op_seae_teshushenhe.bsSkinButton38Click(Sender: TObject); begin t_op_bill.Refresh; end; procedure Tfrm_op_seae_teshushenhe.dxDBGrid2Click(Sender: TObject); begin if t_op_bill.FieldByName('特批标志').AsInteger=1 then begin Label35.Visible:=True; Label35.Caption:='此特放需要特批!'; end else begin label35.Visible:=false; Label35.Caption:=''; end; bsSkinPageControl1.ActivePageIndex:=1; end; procedure Tfrm_op_seae_teshushenhe.N16Click(Sender: TObject); begin grid_save_xls(dxdbgrid2); end; procedure Tfrm_op_seae_teshushenhe.bsSkinButton11Click(Sender: TObject); begin if (wwDBDateTimePicker6.Date<>null) and (wwDBDateTimePicker7.Date<>null) then begin with t_op_bill do begin Close; sql.Clear; sql.Add('select * from t_op_bill_fangdan'); sql.Add('where 操作日期 between :date1 and :date2'); if trim(ComboBox1.Text)<>'' then begin sql.Add('and 特放分析=:特放分析'); Parameters.ParamByName('特放分析').Value:=ComboBox1.Text; end; sql.Add('order by BILL_ID DESC'); Parameters.ParamByName('date1').Value:=wwDBDateTimePicker6.Date; Parameters.ParamByName('date2').Value:=wwDBDateTimePicker7.Date; Open; end; end; end; procedure Tfrm_op_seae_teshushenhe.t_op_billBeforeEdit(DataSet: TDataSet); begin if (t_op_bill.FieldByName('状态').AsString='副总审核') then begin ShowMessage('当前状态'+t_op_bill.FieldByName('状态').AsString+'不能修改'); abort; end; end; procedure Tfrm_op_seae_teshushenhe.dxDBGrid3Column16CustomDraw( 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(Trim(ANode.Strings[dxDBGrid3Column16.Index]))='TRUE' then AColor:=clred; AFont.Color:=clblack; end; procedure Tfrm_op_seae_teshushenhe.RxDBLookupCombo3Enter(Sender: TObject); begin TRxDBLookupCombo(Sender).LookupDisplay:='代码;姓名'; end; procedure Tfrm_op_seae_teshushenhe.RxDBLookupCombo3Exit(Sender: TObject); begin TRxDBLookupCombo(Sender).LookupDisplay:='姓名'; end; procedure Tfrm_op_seae_teshushenhe.dxDBGrid2CustomDraw(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 sValues : string; begin if not VarIsNull(ANode.Values[dxDBGrid2Column18.Index]) then begin sValues :=ANode.Values[dxDBGrid2Column18.Index]; if StrToIntDef(sValues,0) = 1 then afont.Color:=$00C080FF; end; if not VarIsNull(ANode.Values[dxDBGrid2Column17.Index]) then begin sValues :=ANode.Values[dxDBGrid2Column17.Index]; if StrToIntDef(sValues,0) = 1 then afont.Color:=clred; end; end; end.