unit u_ch_zlsales; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, dxExEdtr, BusinessSkinForm, dxTL, dxDBCtrl, dxDBGrid, dxCntner, bsSkinCtrls, ExtCtrls, DB, ADODB, dxDBTLCl, dxGrClEx, Grids, Wwdbigrd, Wwdbgrid, StdCtrls, wwdblook, RxLookup, Mask, wwdbedit, Wwdotdot, Wwdbcomb, wwdbdatetimepicker; type Tfrm_ch_zlsales = class(TForm) bsBusinessSkinForm1: TbsBusinessSkinForm; Panel1: TPanel; bsSkinButton1: TbsSkinButton; bsSkinButton2: TbsSkinButton; bsSkinButton4: TbsSkinButton; bsSkinButton3: TbsSkinButton; bsSkinButton5: TbsSkinButton; t_ch_zlsales: TADOQuery; t_ch_zlsales1: TDataSource; wwDBGrid1: TwwDBGrid; bsSkinButton10: TbsSkinButton; wwDBLookupCombo2: TwwDBLookupCombo; SaveDialog: TSaveDialog; bsSkinPanel3: TbsSkinPanel; Label40: TLabel; RxDBLookupCombo3: TRxDBLookupCombo; RxDBLookupCombo5: TRxDBLookupCombo; Label13: TLabel; bsSkinButton6: TbsSkinButton; wwDBDateTimePicker1: TwwDBDateTimePicker; wwDBComboBox1: TwwDBComboBox; wwDBComboBox2: TwwDBComboBox; procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure FormShow(Sender: TObject); procedure bsSkinButton1Click(Sender: TObject); procedure bsSkinButton2Click(Sender: TObject); procedure bsSkinButton4Click(Sender: TObject); procedure bsSkinButton3Click(Sender: TObject); procedure bsSkinButton5Click(Sender: TObject); procedure bsSkinButton10Click(Sender: TObject); procedure wwDBLookupCombo2Exit(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure t_ch_zlsalesBeforeInsert(DataSet: TDataSet); procedure t_ch_zlsalesBeforeDelete(DataSet: TDataSet); procedure bsSkinButton6Click(Sender: TObject); procedure wwDBGrid1TitleButtonClick(Sender: TObject; AFieldName: String); procedure t_ch_zlsalesAfterOpen(DataSet: TDataSet); private sortfield:string; { Private declarations } public { Public declarations } end; var frm_ch_zlsales: Tfrm_ch_zlsales; implementation uses my_sys_function, u_data_share, u_main; {$R *.dfm} procedure Tfrm_ch_zlsales.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin CanClose:=frm_close_query(t_ch_zlsales); end; procedure Tfrm_ch_zlsales.FormShow(Sender: TObject); begin t_ch_zlsales.Open; if not if_open('525') then begin bsSkinButton1.Enabled:=false; bsSkinButton4.Enabled:=false; bsSkinButton10.Enabled:=false; wwDBGrid1.ColumnByName('客户简称').ReadOnly:=True; wwDBGrid1.ColumnByName('欠款责任人').ReadOnly:=True; wwDBGrid1.ColumnByName('超期RMB').ReadOnly:=True; wwDBGrid1.ColumnByName('超期USD').ReadOnly:=True; wwDBGrid1.ColumnByName('信用期').ReadOnly:=True; wwDBGrid1.ColumnByName('结算日').ReadOnly:=True; wwDBLookupCombo2.ReadOnly:=true; end; end; procedure Tfrm_ch_zlsales.bsSkinButton1Click(Sender: TObject); begin t_ch_zlsales.Insert; end; procedure Tfrm_ch_zlsales.bsSkinButton2Click(Sender: TObject); begin table_post(t_ch_zlsales); end; procedure Tfrm_ch_zlsales.bsSkinButton4Click(Sender: TObject); var i:integer; str:widestring; aQuery:TADOQuery; begin if t_ch_zlsales.IsEmpty then exit; if wwDBGrid1.SelectedList.Count>=1 then begin for i:=0 to wwDBGrid1.SelectedList.Count-1 do begin t_ch_zlsales.GotoBookmark(pointer(wwDBGrid1.SelectedList[i])); if i=0 then str:='('+t_ch_zlsales.fieldbyname('ID').asstring else str:=str+','+t_ch_zlsales.fieldbyname('ID').asstring; end; str:=str+')'; aQuery:=CreateAdoQuery; try with aQuery do begin aQuery.close; aQuery.sql.clear; aQuery.sql.add('delete from t_ch_zlsales ' +'where ID in '+str); aQuery.ExecSQL; end; finally FreeAndNil(aQuery); end; t_ch_zlsales.Requery(); end else begin table_delete(t_ch_zlsales); end; end; procedure Tfrm_ch_zlsales.bsSkinButton3Click(Sender: TObject); begin table_cancel(t_ch_zlsales); end; procedure Tfrm_ch_zlsales.bsSkinButton5Click(Sender: TObject); begin close; end; procedure Tfrm_ch_zlsales.bsSkinButton10Click(Sender: TObject); begin SaveDialog.Filter := '(*.xls)|*.xls'; // SaveDialog.FileName := frm_op_seae.t_op_seae2.DataSet.fieldbyname('主提单号').asstring+'.xls'; if SaveDialog.Execute then begin wwDBGrid1.ExportOptions.FileName:=SaveDialog.FileName; wwDBGrid1.ExportOptions.Save; end; end; procedure Tfrm_ch_zlsales.wwDBLookupCombo2Exit(Sender: TObject); begin if (t_ch_zlsales.state=dsinsert)or(t_ch_zlsales.state=dsedit) then begin if not frm_data_share.t_crm_client.IsEmpty then if frm_data_share.t_crm_client.locate('客户简称',t_ch_zlsales.fieldbyname('客户简称').AsString,[]) then begin t_ch_zlsales['客户代码']:=frm_data_share.t_crm_client.fieldbyname('代码').asstring; t_ch_zlsales['欠款责任人']:=frm_data_share.t_crm_client.fieldbyname('揽货人').asstring; end; end; end; procedure Tfrm_ch_zlsales.FormClose(Sender: TObject; var Action: TCloseAction); begin frm_ch_zlsales.Hide; frm_ch_zlsales.ManualFloat(frm_ch_zlsales.BoundsRect ); frm_main.freeTabs('frm_ch_zlsales'); action:=cafree; frm_ch_zlsales:=nil; end; procedure Tfrm_ch_zlsales.t_ch_zlsalesBeforeInsert(DataSet: TDataSet); begin if not if_open('525') then Abort; end; procedure Tfrm_ch_zlsales.t_ch_zlsalesBeforeDelete(DataSet: TDataSet); begin if not if_open('525') then Abort; end; procedure Tfrm_ch_zlsales.bsSkinButton6Click(Sender: TObject); begin t_ch_zlsales.Close; t_ch_zlsales.SQL.Clear; t_ch_zlsales.SQL.Add('select ROW_NUMBER() OVER(ORDER BY ID) ROWNUM,* from t_ch_zlsales where 1=1 '); if RxDBLookupCombo3.DisplayValues[1]<>'' then begin t_ch_zlsales.SQL.Add(' and 欠款责任人='''+RxDBLookupCombo3.DisplayValues[1]+''''); end; if RxDBLookupCombo5.DisplayValues[1]<>'' then begin t_ch_zlsales.SQL.Add(' and 客户简称='''+RxDBLookupCombo5.DisplayValues[1]+''''); end; t_ch_zlsales.Open; end; procedure Tfrm_ch_zlsales.wwDBGrid1TitleButtonClick(Sender: TObject; AFieldName: String); begin if (sortfield=AFieldName) then sortfield:=AFieldName+' DESC' ELSE sortfield:=AFieldName; t_ch_zlsales.Close; t_ch_zlsales.SQL.Clear; t_ch_zlsales.SQL.Add('select ROW_NUMBER() OVER(ORDER BY '+sortfield+') ROWNUM,* from t_ch_zlsales where 1=1 '); if RxDBLookupCombo3.DisplayValue<>'' then begin t_ch_zlsales.SQL.Add(' and 欠款责任人='''+RxDBLookupCombo3.DisplayValue+''''); end; if RxDBLookupCombo5.DisplayValue<>'' then begin t_ch_zlsales.SQL.Add(' and 客户简称='''+RxDBLookupCombo5.DisplayValue+''''); end; t_ch_zlsales.SQL.Add(' order by '+sortfield); t_ch_zlsales.Open; end; procedure Tfrm_ch_zlsales.t_ch_zlsalesAfterOpen(DataSet: TDataSet); begin TNumericField(DataSet.FieldByName('超期RMB')).DisplayFormat:='#,##0.00;-#,##0.00;#'; TNumericField(DataSet.FieldByName('超期USD')).DisplayFormat:='#,##0.00;-#,##0.00;#'; TNumericField(DataSet.FieldByName('超期合计')).DisplayFormat:='#,##0.00;-#,##0.00;#'; end; end.