unit u_rp_sales_dayprofit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, dxExEdtr, RxMemDS, DB, ADODB, Menus, XPMenu, bsSkinCtrls, dxDBGrid, dxDBTLCl, dxGrClms, dxTL, dxDBCtrl, dxCntner, ComCtrls,DateUtils, bsSkinTabs, ExtCtrls, StdCtrls, Mask, wwdbedit, Wwdotdot, Wwdbcomb, kbmMemTable, kbmMemBinaryStreamFormat, wwdbdatetimepicker, RxLookup, Grids, DBGrids; type Tfrm_rp_sales_dayprofit2 = class(TForm) Panel1: TPanel; bsSkinPageControl1: TbsSkinPageControl; bsSkinTabSheet1: TbsSkinTabSheet; bsSkinTabSheet4: TbsSkinTabSheet; bsSkinTabSheet6: TbsSkinTabSheet; bsSkinPageControl2: TbsSkinPageControl; bsSkinTabSheet13: TbsSkinTabSheet; dxDBGrid7: TdxDBGrid; dxDBGridMaskColumn93: TdxDBGridMaskColumn; PopupMenu2: TPopupMenu; N10: TMenuItem; N11: TMenuItem; N14: TMenuItem; N13: TMenuItem; N12: TMenuItem; N15: TMenuItem; N16: TMenuItem; XPMenu2: TXPMenu; bsSkinPanel1: TbsSkinPanel; bsSkinPanel3: TbsSkinPanel; dxDBGrid3: TdxDBGrid; dxDBGridMaskColumn39: TdxDBGridMaskColumn; dxDBGridMaskColumn42: TdxDBGridMaskColumn; dxDBGridMaskColumn47: TdxDBGridMaskColumn; dxDBGridDateColumn7: TdxDBGridDateColumn; dxDBGridMaskColumn75: TdxDBGridMaskColumn; t_salepriftset: TADOQuery; t_salepriftset1: TDataSource; kbmThreadDataSet1: TkbmThreadDataSet; kbmBinaryStreamFormat1: TkbmBinaryStreamFormat; memtblrpt_total: TkbmMemTable; RxDBLookupCombo3: TRxDBLookupCombo; Label14: TLabel; kbmMemTable2: TkbmMemTable; P_SUM: TkbmMemTable; DataSource1: TDataSource; DataSource3: TDataSource; DataSource4: TDataSource; dxDBGrid3Column57: TdxDBGridColumn; dxDBGrid7Column20: TdxDBGridColumn; dxDBGrid9: TdxDBGrid; dxDBGridMaskColumn77: TdxDBGridMaskColumn; dxDBGridColumn27: TdxDBGridColumn; dxDBGridColumn28: TdxDBGridColumn; dxDBGridColumn29: TdxDBGridColumn; dxDBGridColumn30: TdxDBGridColumn; dxDBGridColumn31: TdxDBGridColumn; dxDBGridColumn32: TdxDBGridColumn; dxDBGridColumn33: TdxDBGridColumn; dxDBGridColumn34: TdxDBGridColumn; dxDBGridColumn35: TdxDBGridColumn; dxDBGridColumn36: TdxDBGridColumn; dxDBGridColumn37: TdxDBGridColumn; dxDBGridColumn38: TdxDBGridColumn; dxDBGridColumn39: TdxDBGridColumn; dxDBGridColumn40: TdxDBGridColumn; dxDBGridColumn41: TdxDBGridColumn; dxDBGridColumn42: TdxDBGridColumn; dxDBGridColumn43: TdxDBGridColumn; dxDBGridColumn44: TdxDBGridColumn; dxDBGridColumn45: TdxDBGridColumn; dxDBGridColumn56: TdxDBGridColumn; dxDBGrid7Column23: TdxDBGridColumn; P_SUMField: TStringField; P_SUMField2: TFloatField; P_SUMField3: TFloatField; P_SUMField4: TFloatField; P_SUMField5: TFloatField; P_SUMField6: TFloatField; P_SUMField7: TFloatField; P_SUMField8: TFloatField; P_SUMField9: TFloatField; P_SUMField10: TFloatField; P_SUMField11: TFloatField; P_SUMField12: TFloatField; P_SUMField13: TFloatField; P_SUMField14: TFloatField; P_SUMField15: TFloatField; P_SUMField16: TFloatField; pnl1: TPanel; bsSkinButton10: TbsSkinButton; bsSkinButton9: TbsSkinButton; bsSkinButton5: TbsSkinButton; RxDBLookupCombo2: TRxDBLookupCombo; Label9: TLabel; Label22: TLabel; RxDBLookupCombo10: TRxDBLookupCombo; bskntbsht2: TbsSkinTabSheet; bsSkinPageControl3: TbsSkinPageControl; bskntbshtpg1: TbsSkinTabSheet; dxDBGrid2: TdxDBGrid; dxDBGridMaskColumn32: TdxDBGridMaskColumn; dxDBGridMaskColumn33: TdxDBGridMaskColumn; dxDBGridMaskColumn36: TdxDBGridMaskColumn; dxDBGridColumn10: TdxDBGridColumn; memtblDetail: TkbmMemTable; StringField1: TStringField; FloatField1: TFloatField; FloatField2: TFloatField; FloatField3: TFloatField; FloatField4: TFloatField; FloatField5: TFloatField; FloatField7: TFloatField; FloatField8: TFloatField; FloatField15: TFloatField; memtblDetailField: TStringField; memtblDetailField2: TDateTimeField; memtblDetailField3: TStringField; memtblDetailField4: TStringField; memtblDetailField5: TDateTimeField; memtblDetailField6: TStringField; memtblDetailField7: TFloatField; memtblDetailField8: TStringField; memtblDetailField9: TStringField; DataSource6: TDataSource; DataSource7: TDataSource; dxDBGrid2Column11: TdxDBGridColumn; dxDBGrid2Column12: TdxDBGridColumn; dxDBGrid2Column14: TdxDBGridColumn; dxDBGrid2Column15: TdxDBGridColumn; memtblDetailField10: TStringField; memtblDetailField11: TStringField; memtblDetailField12: TDateTimeField; memtblDetailField13: TDateTimeField; P_SUMField17: TFloatField; dxDBGrid2Column18: TdxDBGridColumn; P_SUMField18: TFloatField; dxDBGrid7Column21: TdxDBGridColumn; dxDBGrid3Column7: TdxDBGridColumn; dxDBGrid3Column8: TdxDBGridColumn; dxDBGrid3Column9: TdxDBGridColumn; dxDBGrid3Column10: TdxDBGridColumn; dxDBGrid3Column11: TdxDBGridColumn; dxDBGrid3Column12: TdxDBGridColumn; dxDBGrid3Column13: TdxDBGridColumn; dxDBGrid3Column14: TdxDBGridColumn; dxDBGrid3Column15: TdxDBGridColumn; kbmMemTable2Field: TStringField; kbmMemTable2Field2: TStringField; kbmMemTable2Field3: TStringField; kbmMemTable2Field4: TDateField; kbmMemTable2Field5: TStringField; kbmMemTable2USD: TFloatField; kbmMemTable2RMB: TFloatField; kbmMemTable2Field6: TFloatField; kbmMemTable2USD2: TFloatField; kbmMemTable2RMB2: TFloatField; kbmMemTable2Field7: TFloatField; kbmMemTable2USD3: TFloatField; kbmMemTable2RMB3: TFloatField; kbmMemTable2Field8: TFloatField; kbmMemTable2Field9: TFloatField; kbmMemTable2Field10: TStringField; kbmMemTable2USD4: TFloatField; kbmMemTable2RMB4: TFloatField; kbmMemTable2Field11: TFloatField; dxDBGrid3Column16: TdxDBGridColumn; dxDBGrid3Column17: TdxDBGridColumn; dxDBGrid3Column18: TdxDBGridColumn; Label2: TLabel; wwDBComboBox20: TwwDBComboBox; Label3: TLabel; wwDBComboBox1: TwwDBComboBox; RxDBLookupCombo1: TRxDBLookupCombo; Label1: TLabel; bsSkinButton12: TbsSkinButton; dxDBGrid7Column5: TdxDBGridColumn; memtblDetailField14: TStringField; memtblDetailField15: TFloatField; memtblDetailField16: TFloatField; procedure bsSkinButton5Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormShow(Sender: TObject); procedure bsSkinButton9Click(Sender: TObject); procedure N10Click(Sender: TObject); procedure N14Click(Sender: TObject); procedure N16Click(Sender: TObject); procedure bsSkinButton10Click(Sender: TObject); procedure kbmMemTable4AfterOpen(DataSet: TDataSet); procedure kbmMemTable2AfterOpen(DataSet: TDataSet); procedure P_SUMAfterOpen(DataSet: TDataSet); procedure memtblrpt_totalAfterOpen(DataSet: TDataSet); procedure kbmMemTable1AfterOpen(DataSet: TDataSet); procedure memtblDetailAfterOpen(DataSet: TDataSet); procedure memtblLXAfterOpen(DataSet: TDataSet); procedure bsSkinButton12Click(Sender: TObject); private procedure GetProfit; procedure Getcq; procedure GetProfitSum; function GetSALEprofit(SALE:string;aMonth:Integer;profit:Double):Double; function GetBetwMonth(aBe,aEe:TDate):Integer; function gettotalprofit(sale:string):double; { Private declarations } public { Public declarations } end; var frm_rp_sales_dayprofit2: Tfrm_rp_sales_dayprofit2; rp_rp_total_open:boolean; implementation uses u_main, my_sys_function, u_rp_query, u_sys_progress, u_data_share, u_sys_sale_dayprofitset; {$R *.dfm} procedure Tfrm_rp_sales_dayprofit2.bsSkinButton5Click(Sender: TObject); begin close; end; function Tfrm_rp_sales_dayprofit2.GetSALEprofit(SALE:string;aMonth:Integer;profit:Double):Double; var aQuery:TADOQuery; BL:Double; begin BL:=0.00; if profit=0 then begin result:=0.0; exit; end; aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select * from t_crm_salesdayproftSet where 开始天数<='+inttostr(aMonth)+' and 结束天数>='+inttostr(amonth)+' and 方案名称='''+RxDBLookupCombo1.DisplayValues[0]+''' Order by 利润起 ASC'); Open; first; while not eof do begin if (Profit>FieldByName('利润起').AsFloat) and (Profit<=FieldByName('利润止').AsFloat) then begin Result:=FieldByName('本月结提成比例').AsFloat; exit; end; Next; end; end; finally FreeAndNil(aQuery); end; end; procedure Tfrm_rp_sales_dayprofit2.FormClose(Sender: TObject; var Action: TCloseAction); begin savereggrid(dxdbgrid2,caption+'2'); savereggrid(dxdbgrid3,caption+'3'); savereggrid(dxdbgrid9,caption+'9'); frm_rp_sales_dayprofit2.Hide; frm_rp_sales_dayprofit2.ManualFloat(frm_rp_sales_dayprofit2.BoundsRect ); frm_main.freeTabs('frm_rp_sales_dayprofit2'); action:=cafree; frm_rp_sales_dayprofit2:=nil; end; procedure Tfrm_rp_sales_dayprofit2.FormShow(Sender: TObject); var bYear,bMonth,bDate:Word; begin DecodeDate(incmonth(Now,-5),bYear,bMonth,bDate); wwDBComboBox20.Text:=IntToStr(bYear); wwDBComboBox1.Text:=IntToStr(bMonth); loadreggrid(dxdbgrid2,true,caption+'2'); loadreggrid(dxdbgrid3,false,caption+'3'); loadreggrid(dxdbgrid9,false,caption+'9'); t_salepriftset.Open; end; procedure Tfrm_rp_sales_dayprofit2.bsSkinButton9Click(Sender: TObject); begin sys_print('业务综合统计',2,nil,nil,nil,DataSource4,DataSource6,DataSource7,DataSource3,nil,nil,nil,nil); end; procedure Tfrm_rp_sales_dayprofit2.N10Click(Sender: TObject); begin if bsSkinTabSheet1.Showing then begin if bskntbsht2.Showing then begin if bskntbshtpg1.Showing then begin update_grid_view_no(dxdbgrid2); exit; end; end; if bsSkinTabSheet13.Showing then begin update_grid_view_no(dxdbgrid3); exit; end; end else begin if bsSkinTabSheet4.Showing then begin update_grid_view_no(dxdbgrid7); exit; end; end; end; procedure Tfrm_rp_sales_dayprofit2.N14Click(Sender: TObject); begin if bsSkinTabSheet1.Showing then begin if bskntbsht2.Showing then begin if bskntbshtpg1.Showing then begin update_grid_view_all(dxdbgrid2); exit; end; end; if bsSkinTabSheet13.Showing then begin update_grid_view_all(dxdbgrid3); exit; end; end else begin if bsSkinTabSheet4.Showing then begin update_grid_view_all(dxdbgrid7); exit; end; end; end; procedure Tfrm_rp_sales_dayprofit2.N16Click(Sender: TObject); begin if bsSkinTabSheet1.Showing then begin if bskntbsht2.Showing then begin if bskntbshtpg1.Showing then begin grid_save_xls(dxdbgrid2); exit; end; end; if bsSkinTabSheet13.Showing then begin grid_save_xls(dxdbgrid3); exit; end; end else begin if bsSkinTabSheet4.Showing then begin grid_save_xls(dxdbgrid7); exit; end; end; end; procedure Tfrm_rp_sales_dayprofit2.bsSkinButton10Click(Sender: TObject); var betd,eetd:TDate; aquery:TADOQuery; str:String; begin if RxDBLookupCombo1.DisplayValue='' then begin showmessage('请选择提成模板!'); exit; end; memtblrpt_total.EmptyTable; kbmMemTable2.EmptyTable; memtblDetail.EmptyTable; P_SUM.EmptyTable; betd:=EncodeDate(StrToInt(wwDBComboBox20.Text), StrToInt(wwDBComboBox1.Text), 1); eetd:=EncodeDate(StrToInt(wwDBComboBox20.Text), StrToInt(wwDBComboBox1.Text), MonthDays[isLeapYear(StrToInt(wwDBComboBox20.Text)),StrToInt(wwDBComboBox1.Text)]); aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; str:='select * from v_op_seae where (装运方式=''整箱'' or 装运方式=''拼箱单票'' or 装运方式=''拼箱分票'' or 装运方式=''其他'') and 合计应收=合计已收 and '; str:=Str+'开船日期>='+''''+DateToStr(betd)+''''; str:=Str+' and 开船日期<='+''''+DateToStr(eetd)+''''; if RxDBLookupCombo3.DisplayValue<>'' then str:=Str+' and 揽货人='+''''+RxDBLookupCombo3.DisplayValue+''''; if RxDBLookupCombo2.DisplayValue<>'' then str:=Str+' and 委托单位='+''''+RxDBLookupCombo2.DisplayValues[1]+''''; if RxDBLookupCombo10.DisplayValue<>'' then str:=Str+' and 销售部门='+''''+RxDBLookupCombo10.DisplayValue+''''; str:=str+' and '+open_data('0039','揽货人','no','no','no','no'); { str:=str+' union select * from v_op_bscard where (装运方式=''拼箱单票'' or 装运方式=''拼箱分票'') and '; str:=Str+'开船日期>='+''''+DateToStr(betd)+''''; str:=Str+' and 开船日期<='+''''+DateToStr(eetd)+''''; if RxDBLookupCombo3.DisplayValue<>'' then str:=Str+' and 揽货人='+''''+RxDBLookupCombo3.DisplayValue+''''; if RxDBLookupCombo2.DisplayValue<>'' then str:=Str+' and 委托单位='+''''+RxDBLookupCombo2.DisplayValues[1]+''''; if RxDBLookupCombo10.DisplayValue<>'' then str:=Str+' and 销售部门='+''''+RxDBLookupCombo10.DisplayValue+''''; str:=str+' and '+open_data('0039','揽货人','no','no','no','no'); } SQL.Add(str); Open; memtblrpt_total.LoadFromDataSet(aQuery,[mtcpostructure,mtcpoProperties,mtcpoFieldIndex]); Close;SQL.Clear; str:='select * from v_op_seae where 合计应收<>合计已收 and '; str:=Str+'预抵日期>=''2011-03-01'' '; str:=Str+' and 预抵日期>='+''''+DateToStr(betd-90)+''''; str:=Str+' and 预抵日期<='+''''+DateToStr(eetd-90)+''''; if RxDBLookupCombo3.DisplayValue<>'' then str:=Str+' and 揽货人='+''''+RxDBLookupCombo3.DisplayValue+''''; if RxDBLookupCombo2.DisplayValue<>'' then str:=Str+' and 委托单位='+''''+RxDBLookupCombo2.DisplayValues[1]+''''; if RxDBLookupCombo10.DisplayValue<>'' then str:=Str+' and 销售部门='+''''+RxDBLookupCombo10.DisplayValue+''''; str:=str+' and '+open_data('0039','揽货人','no','no','no','no'); SQL.Add(str); Open; kbmMemTable2.LoadFromDataSet(aQuery,[]); end; if (memtblrpt_total.RecordCount=0) and (kbmMemTable2.RecordCount=0) then exit; GetProfit; Getcq; GetProfitSum; finally FreeAndNil(aquery); end; end; procedure Tfrm_rp_sales_dayprofit2.GetProfit; var aQuery,aQuery3:TADOQuery; aStlDate:TDate; bYear,bMonth,bDate,eYear,eMonth,eDate:Word; btMonth,l,d:Integer; LXBL:Double; ED:Boolean; begin if memtblrpt_total.RecordCount=0 then exit; if not P_SUM.Active then P_SUM.Open; if not t_salepriftset.Active then t_salepriftset.Open; if NOT memtblDetail.Active then memtblDetail.Open; l:=memtblrpt_total.RecordCount; if l=0 then l:=100; aQuery:=CreateAdoQuery; aQuery3:=CreateAdoQuery; try if not ASSIGNED(frm_sys_progress) then frm_sys_progress:=tfrm_sys_progress.Create(application); frm_sys_progress.Show; frm_sys_progress.bsSkinGauge1.MaxValue:=l; frm_sys_progress.bsSkinGauge1.MinValue:=0; frm_sys_progress.bsSkinGauge1.Value:=0; frm_sys_progress.Update; memtblrpt_total.First; while not memtblrpt_total.eof do begin if not P_SUM.Locate('揽货人',memtblrpt_total.fieldbyname('揽货人').asstring,[])then begin P_SUM.insert; P_SUM['揽货人']:=memtblrpt_total.fieldbyname('揽货人').asstring; P_SUM['当月结算']:=0; P_SUM['次月结算']:=0; P_SUM['拖至次月']:=0.0; P_SUM['三月结算']:=0.0; P_SUM['拖至三月']:=0; P_SUM['四月结算']:=0; P_SUM['拖至四月']:=0; P_SUM['扣利息']:=0.00; P_SUM['扣利润']:=0.00; P_SUM['特殊客户']:=0.00; P_SUM['已扣利润']:=0.00; P_SUM['毛利润']:=0.00; P_SUM['应提成']:=0.00; P_SUM['合计提成']:=0.00; end else begin P_SUM.edit; end; memtblDetail.Insert; memtblDetail.FieldByName('编号').AsString:=memtblrpt_total.FieldByName('编号').AsString; memtblDetail.FieldByName('业务编号').AsString:=memtblrpt_total.FieldByName('业务编号').AsString; memtblDetail.FieldByName('主提单号').AsString:=memtblrpt_total.FieldByName('主提单号').AsString; memtblDetail.FieldByName('揽货人').AsString:=memtblrpt_total.FieldByName('揽货人').AsString; aQuery.Close; aQuery.SQL.Clear; aQuery.SQL.Add('select top 1 * from v_fee_do where 业务编号='''+memtblDetail.FieldByName('编号').AsString+''' order by 核销日期 DESC '); aQuery.Open; if not aQuery.IsEmpty then begin memtblDetail.FieldByName('工作编号').AsString:=aQuery.fieldByName('工作编号').AsString; memtblDetail.FieldByName('收款金额').AsString:=aQuery.fieldByName('币别').AsString+Floattostr(aQuery.fieldByName('结算金额').AsFloat); memtblDetail.FieldByName('结算日期').Value:=aQuery.FieldByName('核销日期').Value; end else begin memtblDetail.FieldByName('工作编号').AsString:=''; memtblDetail.FieldByName('收款金额').AsString:=''; end; memtblDetail.FieldByName('客户名称').AsString:=memtblrpt_total.FieldByName('委托单位').AsString; memtblDetail.FieldByName('开船日期').Value:=memtblrpt_total.FieldByName('预抵日期').Value; memtblDetail.FieldByName('毛利润').Value:=memtblrpt_total.FieldByName('毛利润').Value; P_SUM['毛利润']:=P_SUM['毛利润']+memtblrpt_total.FieldByName('毛利润').AsFloat; memtblDetail.FieldByName('实际提成金额').AsFloat:=0; memtblDetail.Post; P_SUM.post; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; memtblrpt_total.Next; end; finally frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.MaxValue; frm_sys_progress.free; frm_sys_progress:=nil; FreeAndNil(aQuery); FreeAndNil(aQuery3); end; end; procedure Tfrm_rp_sales_dayprofit2.GetProfitSum; var aK,YB,SB:Double; aSBDATE:TDate; aQuery3:TAdoQuery; d:integer; ED:Boolean; begin if (memtblrpt_total.RecordCount=0) and (kbmMemTable2.RecordCount=0) then exit; aQuery3:=CreateAdoQuery; try if not ASSIGNED(frm_sys_progress) then frm_sys_progress:=tfrm_sys_progress.Create(application); frm_sys_progress.Show; frm_sys_progress.bsSkinGauge1.MaxValue:=memtblDetail.RecordCount*2; frm_sys_progress.bsSkinGauge1.MinValue:=0; frm_sys_progress.bsSkinGauge1.Value:=0; frm_sys_progress.Update; P_SUM.Open; if kbmMemTable2.Active then if not kbmMemTable2.IsEmpty then begin kbmMemTable2.First; while not kbmMemTable2.Eof do begin if not P_SUM.Locate('揽货人',kbmMemTable2.fieldbyname('揽货人').asstring,[])then begin P_SUM.insert; P_SUM['揽货人']:=kbmMemTable2.fieldbyname('揽货人').asstring; P_SUM['扣利润']:=kbmMemTable2.fieldbyname('扣除利润').asfloat; P_SUM['已扣利润']:=0; P_SUM['扣利息']:=0.00; P_SUM['当月结算']:=0.00; P_SUM['次月结算']:=0.00; P_SUM['拖至次月']:=0.00; P_SUM['三月结算']:=0.00; P_SUM['拖至三月']:=0.00; P_SUM['四月结算']:=0.00; P_SUM['拖至四月']:=0.00; P_SUM['应提成']:=0.00; P_SUM['合计提成']:=0; P_SUM.post; end else begin P_SUM.Edit; P_SUM['揽货人']:=kbmMemTable2.fieldbyname('揽货人').asstring; P_SUM['扣利润']:=P_SUM['扣利润']+kbmMemTable2.fieldbyname('扣除利润').asfloat; P_SUM.post; end; frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1; kbmMemTable2.Next; end; end; P_SUM.First; while not P_SUM.Eof do begin P_SUM.Edit; P_SUM.FieldByName('毛利润').AsFloat:=gettotalprofit(P_SUM.FieldByName('揽货人').AsString); P_SUM.post; P_sum.Next; end; if not memtblDetail.IsEmpty then begin memtblDetail.SortOn('结算日期',[]); memtblDetail.Last; while not memtblDetail.Bof do begin if P_SUM.Locate('揽货人',memtblDetail.FieldByName('揽货人').AsString,[]) then begin memtblDetail.Edit; P_SUM.Edit; if (memtblDetail.FieldByName('结算日期').AsDateTimeeYear then begin Result:=bMonth+(12-eMonth); end else begin Result:=eMonth+(12-bMonth); end; end; end; procedure Tfrm_rp_sales_dayprofit2.Getcq; begin end; procedure Tfrm_rp_sales_dayprofit2.kbmMemTable4AfterOpen(DataSet: TDataSet); begin AdoFormatdxDBGrid(DataSet); end; procedure Tfrm_rp_sales_dayprofit2.kbmMemTable2AfterOpen(DataSet: TDataSet); begin AdoFormatdxDBGrid(DataSet); end; procedure Tfrm_rp_sales_dayprofit2.P_SUMAfterOpen(DataSet: TDataSet); begin AdoFormatdxDBGrid(DataSet); end; procedure Tfrm_rp_sales_dayprofit2.memtblrpt_totalAfterOpen(DataSet: TDataSet); begin AdoFormatdxDBGrid(DataSet); end; procedure Tfrm_rp_sales_dayprofit2.kbmMemTable1AfterOpen(DataSet: TDataSet); begin AdoFormatdxDBGrid(DataSet); end; procedure Tfrm_rp_sales_dayprofit2.memtblDetailAfterOpen(DataSet: TDataSet); begin AdoFormatdxDBGrid(DataSet); end; procedure Tfrm_rp_sales_dayprofit2.memtblLXAfterOpen(DataSet: TDataSet); begin AdoFormatdxDBGrid(DataSet); end; function Tfrm_rp_sales_dayprofit2.gettotalprofit(sale: string): double; var betd,eetd:TDate; aquery:TADOQuery; str:String; begin betd:=EncodeDate(StrToInt(wwDBComboBox20.Text), StrToInt(wwDBComboBox1.Text), 1); eetd:=EncodeDate(StrToInt(wwDBComboBox20.Text), StrToInt(wwDBComboBox1.Text), MonthDays[isLeapYear(StrToInt(wwDBComboBox20.Text)),StrToInt(wwDBComboBox1.Text)]); aQuery:=CreateAdoQuery; try with aQuery do begin Close;SQL.Clear; str:='select sum(毛利润) as 毛利润 from v_op_seae where 1=1 and '; str:=Str+'预抵日期>='+''''+DateToStr(betd)+''''; str:=Str+' and 预抵日期<='+''''+DateToStr(eetd)+''''; str:=Str+' and 揽货人='+''''+sale+''''; SQL.Add(str); Open; if IsEmpty then begin result:=0.00; end else result:=fieldbyname('毛利润').asfloat; end; finally FreeAndNil(aquery); end; end; procedure Tfrm_rp_sales_dayprofit2.bsSkinButton12Click(Sender: TObject); begin if not if_open('252') then begin showmessage('对不起你没有此模块的操作权限!'); exit; end; try frm_sys_sale_dayprofitset:=tfrm_sys_sale_dayprofitset.Create (self); frm_sys_sale_dayprofitset.ShowModal; finally FreeAndNil(frm_sys_sale_dayprofitset); end; end; end.