unit u_rp_edi; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DB, ADODB,ComObj,IniFiles, DBClient, bsSkinCtrls, DateUtils, Mask, bsSkinBoxCtrls, ExtCtrls, TeeProcs, TeEngine, Chart, DbChart,math,my_sys_function, Series, bsdbctrls, wwdblook; type Tfrm_rp_edi = class(TForm) OpenDialog1: TOpenDialog; QryExcel: TADOQuery; ADOQuery1: TADOQuery; QryData: TADOQuery; bsSkinGauge1: TbsSkinGauge; bsSkinPanel2: TbsSkinPanel; bsSkinPanel1: TbsSkinPanel; Label1: TLabel; ComboBox1: TComboBox; bsSkinPanel3: TbsSkinPanel; bsSkinButton1: TbsSkinButton; Button2: TbsSkinButton; Button1: TbsSkinButton; Button3: TbsSkinButton; Label2: TLabel; ComboBox2: TComboBox; t_num: TADOQuery; t_ys: TADOQuery; Chart1: TChart; Chart2: TChart; Chart3: TChart; t_yf: TADOQuery; t_lr: TADOQuery; Label3: TLabel; dt1: TbsSkinDateEdit; Label4: TLabel; dt2: TbsSkinDateEdit; bsSkinRadioGroup1: TbsSkinRadioGroup; t_ctn: TADOQuery; bsSkinRadioGroup2: TbsSkinRadioGroup; bsSkinRadioGroup3: TbsSkinRadioGroup; wwDBLookupCombo25: TwwDBLookupCombo; t_code_CUST: TADOQuery; t_code_cust1: TDataSource; procedure Button2Click(Sender: TObject); procedure FormShow(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure bsSkinButton1Click(Sender: TObject); procedure GetBeginEndDate; procedure bsSkinRadioGroup1Click(Sender: TObject); procedure dt1Change(Sender: TObject); procedure dt2Change(Sender: TObject); procedure ComboBox2KeyPress(Sender: TObject; var Key: Char); procedure bsSkinRadioGroup2Click(Sender: TObject); private { Private declarations } XlsFileNameStr,ztdh,yfje,ysje,sbrq,begindate,enddate:string; public { Public declarations } end; var frm_rp_edi: Tfrm_rp_edi; var clientjp,clientname:array of string; const myarr:array[0..11] of string= ('一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'); implementation uses u_data_share, u_op_seae, u_main; {$R *.dfm} var ReadXlsThread,UpdateDataThread: THandle; {线程句柄} function GetHzPy(const AHzStr: string): string; const ChinaCode: array[0..25, 0..1] of Integer = ((1601, 1636), (1637, 1832), (1833, 2077), (2078, 2273), (2274, 2301), (2302, 2432), (2433, 2593), (2594, 2786), (9999, 0000), (2787, 3105), (3106, 3211), (3212, 3471), (3472, 3634), (3635, 3722), (3723, 3729), (3730, 3857), (3858, 4026), (4027, 4085), (4086, 4389), (4390, 4557), (9999, 0000), (9999, 0000), (4558, 4683), (4684, 4924), (4925, 5248), (5249, 5589)); var i, j, HzOrd: integer; begin i:= 1; while i <= Length(AHzStr) do begin if (AHzStr[i] >= #160) and (AHzStr[i + 1] >= #160) then begin HzOrd := (Ord(AHzStr[i]) - 160) * 100 + Ord(AHzStr[i + 1]) - 160; for j := 0 to 25 do begin if (HzOrd >= ChinaCode[j][0]) and (HzOrd <= ChinaCode[j][1]) then begin Result := Result + char(byte( 'a') + j); break; end; end; Inc(i); end else Result := Result + AHzStr[i]; Inc(i); end; end; procedure openaq(aq:TADOQuery;sqlstr:string); begin aq.Close; aq.SQL.Clear; aq.SQL.Add(sqlstr); aq.Open; end; procedure execaq(aq:TADOQuery;sqlstr:string); begin aq.Close; aq.SQL.Clear; aq.SQL.Add(sqlstr); aq.ExecSQL; end; procedure Tfrm_rp_edi.Button2Click(Sender: TObject); var Excel: OleVariant; i : integer; begin OpenDialog1.Title := '请选择正确的excel文件'; OpenDialog1.Filter := 'Excel(*.xls)|*.xlsx'; if OpenDialog1.Execute then XlsFileNameStr := OpenDialog1.FileName; if (trim(XlsFileNameStr ) = '') then begin GetActiveWindow(); showmessage( '请选择正确的excel路径'); exit; end; try Excel := CreateOLEObject('Excel.Application'); except showmessage('excel没有安装'); Exit; end; Excel.DisplayAlerts:=false; Excel.Visible := False; Excel.WorkBooks.Open(XlsFileNameStr); ComboBox1.Items.Clear; for i:=1 to Excel.Worksheets.COUNT do ComboBox1.Items.Add(Excel.WorkSheets[i].Name); Excel.Quit; execaq(QryExcel,'create table #EDI (序号 integer null,单号 varchar(50) null,应收 numeric(18,4) null,应付 numeric(18,4) null)'); end; procedure UpdateData; var i:Integer; bh,dh,ys,yf,s:string; begin openaq(frm_rp_edi.QryData,'select * from #EDI order by 序号'); frm_rp_edi.QryData.First; frm_rp_edi.bsSkinGauge1.ProgressText:='正在更新请稍后。。。'; frm_rp_edi.bsSkinGauge1.MaxValue:=frm_rp_edi.QryData.RecordCount; frm_rp_edi.bsSkinGauge1.MinValue:=0; frm_rp_edi.bsSkinGauge1.Value:=0; while not frm_rp_edi.QryData.Eof do begin dh:= frm_rp_edi.QryData.fieldbyname('单号').AsString; ys:= frm_rp_edi.QryData.fieldbyname('应收').AsString; yf:= frm_rp_edi.QryData.fieldbyname('应付').AsString; s:='select * from t_op_seae_edi where (主提单号= '+QuotedStr(dh)+' or 分提单号= '+QuotedStr(dh)+') and (录入日期 between ' +QuotedStr(frm_rp_edi.begindate)+' and '+QuotedStr(frm_rp_edi.enddate)+') and 标志 is null '; openaq(frm_rp_edi.ADOQuery1,s); { if Form1.ADOQuery1.RecordCount=0 then begin s:= 'select * from t_op_seae_edi where (主提单号= '+QuotedStr(dh)+' or 分提单号= '+QuotedStr(dh)+') and (录入日期 between ' +QuotedStr(form1.begindate)+' and '+QuotedStr(Form1.enddate)+') '; openaq(Form1.QryExcel,s); Form1.Memo1.Lines.Add('序号'+Form1.QryData.fieldbyname('序号').AsString+'提单号:'+dh+'存在 应收='+Form1.QryExcel.fieldbyname('应收').AsString+' 应付='+Form1.QryExcel.fieldbyname('应付').AsString); end; } if frm_rp_edi.ADOQuery1.RecordCount>0 then begin frm_rp_edi.ADOQuery1.First; bh:= frm_rp_edi.ADOQuery1.fieldbyname('编号').AsString; s:= 'update t_op_seae_edi set 应付='+QuotedStr(yf)+',应收='+QuotedStr(ys)+',标志=1 where 编号='+QuotedStr(bh); execaq(frm_rp_edi.QryExcel,s); end; frm_rp_edi.bsSkinGauge1.Value:=frm_rp_edi.bsSkinGauge1.Value+1; frm_rp_edi.QryData.Next; end; frm_rp_edi.bsSkinGauge1.ProgressText:='更新完成'; frm_rp_edi.bsSkinGauge1.Value:=0; TerminateThread(ReadXlsThread,0); end; function ReadXls(p: Pointer): Integer; stdcall; const BeginRow = 2; BeginCol = 1; var Excel: OleVariant; iRow,iCol,i,isheet,iztdh,idj,icb,irq : integer; xlsFilename,s: string; ExcelRowCount : integer; begin frm_rp_edi.GetBeginEndDate; if (frm_rp_edi.begindate='') or (frm_rp_edi.enddate='') then begin Exit; end; try Excel := CreateOLEObject('Excel.Application'); except showmessage('excel没有安装'); Exit; end; Excel.DisplayAlerts:=false; Excel.Visible := False; Excel.WorkBooks.Open(frm_rp_edi.XlsFileNameStr); for i:=1 to Excel.Worksheets.COUNT do begin if Excel.WorkSheets[i].Name=frm_rp_edi.ComboBox1.Text then begin ExcelRowCount := Excel.WorkSheets[i].UsedRange.Rows.Count; isheet:=i; Break; end; end; frm_rp_edi.bsSkinGauge1.ProgressText:='正在提取Excel表格数据请稍后。。。'; frm_rp_edi.bsSkinGauge1.MaxValue:=ExcelRowCount; frm_rp_edi.bsSkinGauge1.MinValue:=0; frm_rp_edi.bsSkinGauge1.Value:=0; try iRow := BeginRow; for i:=1 to Excel.WorkSheets[isheet].UsedRange.columns.count do begin if Excel.WorkSheets[isheet].UsedRange.Cells[1,i].value='提单号' then iztdh:=i; if Excel.WorkSheets[isheet].UsedRange.Cells[1,i].value='应付' then idj:=i; // column[i].Name if Excel.WorkSheets[isheet].UsedRange.Cells[1,i].value='应收' then icb:=i; if Excel.WorkSheets[isheet].UsedRange.Cells[1,i].value='申报日期' then irq:=i; end; while trim(Excel.WorkSheets[isheet].Cells[iRow,iztdh].value) <> '' do begin frm_rp_edi.ztdh:= trim(Excel.WorkSheets[isheet].Cells[iRow,iztdh].value); frm_rp_edi.yfje:= trim(Excel.WorkSheets[isheet].Cells[iRow,idj].value); frm_rp_edi.ysje:= trim(Excel.WorkSheets[isheet].Cells[iRow,icb].value); frm_rp_edi.sbrq:= trim(Excel.WorkSheets[isheet].Cells[iRow,irq].value); if frm_rp_edi.yfje='' then frm_rp_edi.yfje:='0'; if frm_rp_edi.ysje='' then frm_rp_edi.ysje:='0'; s:='insert into #EDI (序号,单号,应收,应付) values ('+inttostr(iRow-1)+','+QuotedStr(frm_rp_edi.ztdh) +','+QuotedStr(frm_rp_edi.ysje)+','+QuotedStr(frm_rp_edi.yfje)+')'; execaq(frm_rp_edi.QryExcel,s); frm_rp_edi.bsSkinGauge1.Value:=frm_rp_edi.bsSkinGauge1.Value+1; iRow := iRow + 1; end; Excel.Quit; frm_rp_edi.bsSkinGauge1.ProgressText:=''; frm_rp_edi.bsSkinGauge1.Value:=0; UpdateData; execaq(frm_rp_edi.QryExcel,'drop table #EDI'); except Excel.Quit; end; end; procedure Tfrm_rp_edi.FormShow(Sender: TObject); var aQuery:TADOQuery; i:Integer; begin aQuery:=CreateAdoQuery; openaq(aQuery,'select distinct 委托发送方 from t_op_seae_edi where ltrim(rtrim(委托发送方))<>'''' order by 委托发送方 '); SetLength(clientname,aQuery.RecordCount); SetLength(clientjp,aQuery.RecordCount); t_code_CUST.Open; dt2.Date:=Now; ComboBox2.Items.Clear; for i:=0 to aQuery.RecordCount-1 do begin ComboBox2.Items.Add(aQuery.fieldbyname('委托发送方').AsString); clientname[i]:=aQuery.fieldbyname('委托发送方').AsString; clientjp[i]:=GetHzPy(aQuery.fieldbyname('委托发送方').AsString); aQuery.Next; end; FreeAndNil(aQuery); bsSkinGauge1.Value:=0; end; procedure Tfrm_rp_edi.Button1Click(Sender: TObject); var ID: DWORD; begin if (trim(XlsFileNameStr ) = '') then begin ShowMessage('您没有选择要导入的Excel文件!'); Exit; end; if ComboBox1.ItemIndex=-1 then begin ShowMessage('您没有选择要导入的工作簿!'); Exit; end; if MessageBox(Handle,PChar('确认要导入的工作簿为'+trim(ComboBox1.Text)+'?'),'确认信息',MB_OKCANCEL)=idok then begin execaq(QryExcel,'delete #EDI '); ReadXlsThread := CreateThread(nil, 0, @ReadXls, nil, CREATE_SUSPENDED, ID); begindate:=''; enddate:=''; ResumeThread(ReadXlsThread); end; end; procedure Tfrm_rp_edi.Button3Click(Sender: TObject); begin if ReadXlsThread>0 then TerminateThread(ReadXlsThread,0); end; procedure Tfrm_rp_edi.bsSkinButton1Click(Sender: TObject); var i,k,j:Integer; MySeries: TChartSeries; str:string; begin if (bsSkinRadioGroup3.ItemIndex=0) then begin if bsSkinRadioGroup1.ItemIndex=0 then begin if Trim(wwDBLookupCombo25.Text)='' then str:='' else str:=' and 委托发送方='+QuotedStr(Trim(wwDBLookupCombo25.Text)); t_ys.Close; t_ys.SQL.Clear; t_ys.SQL.Add('SELECT YEAR(录入日期) 年度, ' +'SUM(CASE WHEN MONTH(录入日期) =1 THEN 应收金额 ELSE 0 END) 一月, ' +'SUM(CASE WHEN MONTH(录入日期) =2 THEN 应收金额 ELSE 0 END) 二月, ' +'SUM(CASE WHEN MONTH(录入日期) =3 THEN 应收金额 ELSE 0 END) 三月, ' +'SUM(CASE WHEN MONTH(录入日期) =4 THEN 应收金额 ELSE 0 END) 四月, ' +'SUM(CASE WHEN MONTH(录入日期) =5 THEN 应收金额 ELSE 0 END) 五月, ' +'SUM(CASE WHEN MONTH(录入日期) =6 THEN 应收金额 ELSE 0 END) 六月, ' +'SUM(CASE WHEN MONTH(录入日期) =7 THEN 应收金额 ELSE 0 END) 七月, ' +'SUM(CASE WHEN MONTH(录入日期) =8 THEN 应收金额 ELSE 0 END) 八月, ' +'SUM(CASE WHEN MONTH(录入日期) =9 THEN 应收金额 ELSE 0 END) 九月, ' +'SUM(CASE WHEN MONTH(录入日期) =10 THEN 应收金额 ELSE 0 END) 十月, ' +'SUM(CASE WHEN MONTH(录入日期) =11 THEN 应收金额 ELSE 0 END) 十一月, ' +'SUM(CASE WHEN MONTH(录入日期) =12 THEN 应收金额 ELSE 0 END) 十二月 ' +' FROM ' +' (select ' +' case when 应收 IS null then 0 else 应收 end as 应收金额, ' +' case when 应付 IS null then 0 else 应付 end as 应付金额,* ' +' from t_op_seae_edi where (录入日期 between :dt1 and :dt2) '+str+' ) t ' +' GROUP BY YEAR(录入日期) ' ) ; t_ys.Parameters[0].Value:=dt1.date; t_ys.Parameters[1].Value:=StrToDateTime(DateTimeToStr(dt2.date)+' 23:59:59'); t_ys.Open; chart1.RemoveAllSeries; if t_ys.RecordCount>0 then begin t_ys.First; while not t_ys.Eof do begin if t_ys.RecordCount=1 then begin Chart1.Legend.Visible := False; Chart1.Title.Text.Text:='财务数据对比----'+t_ys.fieldbyname('年度').AsString+'年度'; end else begin Chart1.Legend.Visible := True; Chart1.Title.Text.Text:='财务数据对比'; end; if bsSkinRadioGroup2.ItemIndex=0 then MySeries := TBarSeries.Create(Application) else MySeries := TLineSeries.Create(Application); MySeries.Title:= t_ys.fieldbyname('年度').AsString; MySeries.Marks.Style:=smsValue; for i:=0 to 11 do MySeries.AddXY(i,t_ys.fieldbyname(myarr[i]).AsFloat,myarr[i]); Chart1.AddSeries(MySeries); t_ys.Next; end; end; end; if bsSkinRadioGroup1.ItemIndex=1 then begin if Trim(wwDBLookupCombo25.Text)='' then str:='' else str:=' and 委托发送方='+QuotedStr(Trim(wwDBLookupCombo25.Text)); t_yf.Close; t_yf.SQL.Clear; t_yf.SQL.Add('SELECT YEAR(录入日期) 年度, ' +'SUM(CASE WHEN MONTH(录入日期) =1 THEN 应付金额 ELSE 0 END) 一月, ' +'SUM(CASE WHEN MONTH(录入日期) =2 THEN 应付金额 ELSE 0 END) 二月, ' +'SUM(CASE WHEN MONTH(录入日期) =3 THEN 应付金额 ELSE 0 END) 三月, ' +'SUM(CASE WHEN MONTH(录入日期) =4 THEN 应付金额 ELSE 0 END) 四月, ' +'SUM(CASE WHEN MONTH(录入日期) =5 THEN 应付金额 ELSE 0 END) 五月, ' +'SUM(CASE WHEN MONTH(录入日期) =6 THEN 应付金额 ELSE 0 END) 六月, ' +'SUM(CASE WHEN MONTH(录入日期) =7 THEN 应付金额 ELSE 0 END) 七月, ' +'SUM(CASE WHEN MONTH(录入日期) =8 THEN 应付金额 ELSE 0 END) 八月, ' +'SUM(CASE WHEN MONTH(录入日期) =9 THEN 应付金额 ELSE 0 END) 九月, ' +'SUM(CASE WHEN MONTH(录入日期) =10 THEN 应付金额 ELSE 0 END) 十月, ' +'SUM(CASE WHEN MONTH(录入日期) =11 THEN 应付金额 ELSE 0 END) 十一月, ' +'SUM(CASE WHEN MONTH(录入日期) =12 THEN 应付金额 ELSE 0 END) 十二月 ' +' FROM ' +' (select ' +' case when 应收 IS null then 0 else 应收 end as 应收金额, ' +' case when 应付 IS null then 0 else 应付 end as 应付金额,* ' +' from t_op_seae_edi where (录入日期 between :dt1 and :dt2) '+str+' ) t ' +' GROUP BY YEAR(录入日期) ' ) ; t_yf.Parameters[0].Value:=dt1.date; t_yf.Parameters[1].Value:=StrToDateTime(DateTimeToStr(dt2.date)+' 23:59:59'); t_yf.Open; chart1.RemoveAllSeries; if t_yf.RecordCount>0 then begin t_yf.First; while not t_yf.Eof do begin if t_yf.RecordCount=1 then begin Chart1.Legend.Visible := False; Chart1.Title.Text.Text:='财务数据对比----'+t_yf.fieldbyname('年度').AsString+'年度'; end else begin Chart1.Legend.Visible := True; Chart1.Title.Text.Text:='财务数据对比'; end; if bsSkinRadioGroup2.ItemIndex=0 then MySeries := TBarSeries.Create(Application) else MySeries := TLineSeries.Create(Application); MySeries.Title:= t_yf.fieldbyname('年度').AsString; MySeries.Marks.Style:=smsValue; for i:=0 to 11 do MySeries.AddXY(i,t_yf.fieldbyname(myarr[i]).AsFloat,myarr[i]); Chart1.AddSeries(MySeries); t_yf.Next; end; end; end; if bsSkinRadioGroup1.ItemIndex=2 then begin if Trim(wwDBLookupCombo25.Text)='' then str:='' else str:=' and 委托发送方='+QuotedStr(Trim(wwDBLookupCombo25.Text)); t_lr.Close; t_lr.SQL.Clear; t_lr.SQL.Add('SELECT YEAR(录入日期) 年度, ' +'SUM(CASE WHEN MONTH(录入日期) =1 THEN 应收金额 ELSE 0 END)-SUM(CASE WHEN MONTH(录入日期) =1 THEN 应付金额 ELSE 0 END) 一月, ' +'SUM(CASE WHEN MONTH(录入日期) =2 THEN 应收金额 ELSE 0 END)-SUM(CASE WHEN MONTH(录入日期) =2 THEN 应付金额 ELSE 0 END) 二月, ' +'SUM(CASE WHEN MONTH(录入日期) =3 THEN 应收金额 ELSE 0 END)-SUM(CASE WHEN MONTH(录入日期) =3 THEN 应付金额 ELSE 0 END) 三月, ' +'SUM(CASE WHEN MONTH(录入日期) =4 THEN 应收金额 ELSE 0 END)-SUM(CASE WHEN MONTH(录入日期) =4 THEN 应付金额 ELSE 0 END) 四月, ' +'SUM(CASE WHEN MONTH(录入日期) =5 THEN 应收金额 ELSE 0 END)-SUM(CASE WHEN MONTH(录入日期) =5 THEN 应付金额 ELSE 0 END) 五月, ' +'SUM(CASE WHEN MONTH(录入日期) =6 THEN 应收金额 ELSE 0 END)-SUM(CASE WHEN MONTH(录入日期) =6 THEN 应付金额 ELSE 0 END) 六月, ' +'SUM(CASE WHEN MONTH(录入日期) =7 THEN 应收金额 ELSE 0 END)-SUM(CASE WHEN MONTH(录入日期) =7 THEN 应付金额 ELSE 0 END) 七月, ' +'SUM(CASE WHEN MONTH(录入日期) =8 THEN 应收金额 ELSE 0 END)-SUM(CASE WHEN MONTH(录入日期) =8 THEN 应付金额 ELSE 0 END) 八月, ' +'SUM(CASE WHEN MONTH(录入日期) =9 THEN 应收金额 ELSE 0 END)-SUM(CASE WHEN MONTH(录入日期) =9 THEN 应付金额 ELSE 0 END) 九月, ' +'SUM(CASE WHEN MONTH(录入日期) =10 THEN 应收金额 ELSE 0 END)-SUM(CASE WHEN MONTH(录入日期) =10 THEN 应付金额 ELSE 0 END) 十月, ' +'SUM(CASE WHEN MONTH(录入日期) =11 THEN 应收金额 ELSE 0 END)-SUM(CASE WHEN MONTH(录入日期) =11 THEN 应付金额 ELSE 0 END) 十一月, ' +'SUM(CASE WHEN MONTH(录入日期) =12 THEN 应收金额 ELSE 0 END)-SUM(CASE WHEN MONTH(录入日期) =12 THEN 应付金额 ELSE 0 END) 十二月 ' +' FROM ' +' (select ' +' case when 应收 IS null then 0 else 应收 end as 应收金额, ' +' case when 应付 IS null then 0 else 应付 end as 应付金额,* ' +' from t_op_seae_edi where (录入日期 between :dt1 and :dt2) '+str+' ) t ' +' GROUP BY YEAR(录入日期) ' ) ; t_lr.Parameters[0].Value:=dt1.date; t_lr.Parameters[1].Value:=StrToDateTime(DateTimeToStr(dt2.date)+' 23:59:59'); t_lr.Open; chart1.RemoveAllSeries; if t_lr.RecordCount>0 then begin t_lr.First; while not t_lr.Eof do begin if t_lr.RecordCount=1 then begin Chart1.Legend.Visible := False; Chart1.Title.Text.Text:='财务数据对比----'+t_lr.fieldbyname('年度').AsString+'年度'; end else begin Chart1.Legend.Visible := True; Chart1.Title.Text.Text:='财务数据对比'; end; if bsSkinRadioGroup2.ItemIndex=0 then MySeries := TBarSeries.Create(Application) else MySeries := TLineSeries.Create(Application); MySeries.Title:= t_lr.fieldbyname('年度').AsString; MySeries.Marks.Style:=smsValue; for i:=0 to 11 do MySeries.AddXY(i,t_lr.fieldbyname(myarr[i]).AsFloat,myarr[i]); Chart1.AddSeries(MySeries); t_lr.Next; end; end; end; if Trim(wwDBLookupCombo25.Text)='' then str:='' else str:=' and 委托发送方='+QuotedStr(Trim(wwDBLookupCombo25.Text)); t_num.Close; t_num.SQL.Clear; t_num.SQL.Add('select datepart(year,录入日期) as 年度, ' +'sum(case when datepart(month,录入日期)=1 then 1 else 0 end) as 一月, ' +'sum(case when datepart(month,录入日期)=2 then 1 else 0 end) as 二月, ' +'sum(case when datepart(month,录入日期)=3 then 1 else 0 end) as 三月, ' +'sum(case when datepart(month,录入日期)=4 then 1 else 0 end) as 四月, ' +'sum(case when datepart(month,录入日期)=5 then 1 else 0 end) as 五月, ' +'sum(case when datepart(month,录入日期)=6 then 1 else 0 end) as 六月, ' +'sum(case when datepart(month,录入日期)=7 then 1 else 0 end) as 七月, ' +'sum(case when datepart(month,录入日期)=8 then 1 else 0 end) as 八月, ' +'sum(case when datepart(month,录入日期)=9 then 1 else 0 end) as 九月, ' +'sum(case when datepart(month,录入日期)=10 then 1 else 0 end) as 十月, ' +'sum(case when datepart(month,录入日期)=11 then 1 else 0 end) as 十一月, ' +'sum(case when datepart(month,录入日期)=12 then 1 else 0 end) as 十二月 ' +' from t_op_seae_edi where 录入日期 between :dt1 and :dt2 '+str +' group by datepart(year,录入日期) '); t_num.Parameters[0].Value:=dt1.date; t_num.Parameters[1].Value:=StrToDateTime(DateTimeToStr(dt2.date)+' 23:59:59'); t_num.Open; chart3.RemoveAllSeries; if t_num.RecordCount>0 then begin t_num.First; while not t_num.Eof do begin if t_num.RecordCount=1 then begin Chart3.Legend.Visible := False; Chart3.Title.Text.Text:='票数对比----'+t_num.fieldbyname('年度').AsString+'年度'; end else begin Chart3.Legend.Visible := True; Chart3.Title.Text.Text:='票数对比'; end; if bsSkinRadioGroup2.ItemIndex=0 then MySeries := TBarSeries.Create(Application) else MySeries := TLineSeries.Create(Application); MySeries.Title:= t_num.fieldbyname('年度').AsString; MySeries.Marks.Style:=smsValue; for i:=0 to 11 do MySeries.AddXY(i,t_num.fieldbyname(myarr[i]).AsFloat,myarr[i]); Chart3.AddSeries(MySeries); t_num.Next; end; end; if Trim(wwDBLookupCombo25.Text)='' then str:='' else str:=' and 委托发送方='+QuotedStr(Trim(wwDBLookupCombo25.Text)); t_ctn.Close; t_ctn.SQL.Clear; t_ctn.SQL.Add('select datepart(year,录入日期) as 年度, ' +' sum(case when datepart(month,录入日期)=1 then 实际箱数 else 0 end) as 一月, ' +' sum(case when datepart(month,录入日期)=2 then 实际箱数 else 0 end) as 二月, ' +' sum(case when datepart(month,录入日期)=3 then 实际箱数 else 0 end) as 三月, ' +' sum(case when datepart(month,录入日期)=4 then 实际箱数 else 0 end) as 四月, ' +' sum(case when datepart(month,录入日期)=5 then 实际箱数 else 0 end) as 五月, ' +' sum(case when datepart(month,录入日期)=6 then 实际箱数 else 0 end) as 六月, ' +' sum(case when datepart(month,录入日期)=7 then 实际箱数 else 0 end) as 七月, ' +' sum(case when datepart(month,录入日期)=8 then 实际箱数 else 0 end) as 八月, ' +' sum(case when datepart(month,录入日期)=9 then 实际箱数 else 0 end) as 九月, ' +' sum(case when datepart(month,录入日期)=10 then 实际箱数 else 0 end) as 十月, ' +' sum(case when datepart(month,录入日期)=11 then 实际箱数 else 0 end) as 十一月, ' +' sum(case when datepart(month,录入日期)=12 then 实际箱数 else 0 end) as 十二月 ' +' from ' +' (select case when 箱数 is null then 0 when 箱数='''' then 0 else 箱数 end as 实际箱数,* from t_op_seae_edi ' // +' where (录入日期 between '+QuotedStr(FormatDateTime('yyyy-mm-dd',dt1.Date))+' and '+QuotedStr(FormatDateTime('yyyy-mm-dd',dt2.Date))+') '+str+' ) t ' +' where (录入日期 between :dt1 and :dt2) '+str+' ) t ' +' group by datepart(year,t.录入日期) '); t_ctn.Parameters[0].Value:=dt1.date; t_ctn.Parameters[1].Value:=StrToDateTime(DateTimeToStr(dt2.date)+' 23:59:59'); t_ctn.Open; chart2.RemoveAllSeries; if t_ctn.RecordCount>0 then begin t_ctn.First; while not t_ctn.Eof do begin if t_ctn.RecordCount=1 then begin Chart2.Legend.Visible := False; Chart2.Title.Text.Text:='箱数对比----'+t_ctn.fieldbyname('年度').AsString+'年度'; end else begin Chart2.Legend.Visible := True; Chart2.Title.Text.Text:='箱数对比'; end; if bsSkinRadioGroup2.ItemIndex=0 then MySeries := TBarSeries.Create(Application) else MySeries := TLineSeries.Create(Application); MySeries.Title:= t_ctn.fieldbyname('年度').AsString; MySeries.Marks.Style:=smsValue; for i:=0 to 11 do MySeries.AddXY(i,t_ctn.fieldbyname(myarr[i]).AsFloat,myarr[i]); Chart2.AddSeries(MySeries); t_ctn.Next; end; end; end else begin if bsSkinRadioGroup1.ItemIndex=0 then begin if Trim(wwDBLookupCombo25.Text)='' then str:='' else str:=' and 委托发送方='+QuotedStr(Trim(wwDBLookupCombo25.Text)); t_ys.Close; t_ys.SQL.Clear; t_ys.SQL.Add('SELECT YEAR(录入日期) 年度, '); for j:=1 to 53 do begin t_ys.SQL.Add('SUM(CASE WHEN datename(week,录入日期) ='+inttostr(j)+' THEN 应收金额 ELSE 0 END) 第'+inttostr(j)+'周, '); end; t_ys.SQL.Add('0 十二月 '); t_ys.SQL.Add(' FROM '); t_ys.SQL.Add(' (select '); t_ys.SQL.Add(' case when 应收 IS null then 0 else 应收 end as 应收金额, '); t_ys.SQL.Add(' case when 应付 IS null then 0 else 应付 end as 应付金额,* '); t_ys.SQL.Add(' from t_op_seae_edi where (录入日期 between :dt1 and :dt2) '+str+' ) t '); t_ys.SQL.Add(' GROUP BY YEAR(录入日期) ' ) ; t_ys.Parameters[0].Value:=dt1.date; t_ys.Parameters[1].Value:=StrToDateTime(DateTimeToStr(dt2.date)+' 23:59:59'); t_ys.Open; chart1.RemoveAllSeries; if t_ys.RecordCount>0 then begin t_ys.First; while not t_ys.Eof do begin if t_ys.RecordCount=1 then begin Chart1.Legend.Visible := False; Chart1.Title.Text.Text:='财务数据对比----'+t_ys.fieldbyname('年度').AsString+'年度'; end else begin Chart1.Legend.Visible := True; Chart1.Title.Text.Text:='财务数据对比'; end; if bsSkinRadioGroup2.ItemIndex=0 then MySeries := TBarSeries.Create(Application) else MySeries := TLineSeries.Create(Application); MySeries.Title:= t_ys.fieldbyname('年度').AsString; MySeries.Marks.Style:=smsValue; for j:=1 to 53 do begin MySeries.AddXY(j,t_ys.fieldbyname('第'+inttostr(j)+'周').AsFloat,'第'+inttostr(j)+'周'); end; Chart1.AddSeries(MySeries); t_ys.Next; end; end; end; if bsSkinRadioGroup1.ItemIndex=1 then begin if Trim(wwDBLookupCombo25.Text)='' then str:='' else str:=' and 委托发送方='+QuotedStr(Trim(wwDBLookupCombo25.Text)); t_yf.Close; t_yf.SQL.Clear; t_yf.SQL.Add('SELECT YEAR(录入日期) 年度, '); for j:=1 to 53 do begin t_yf.SQL.Add('SUM(CASE WHEN datename(week,录入日期) ='+inttostr(j)+' THEN 应付金额 ELSE 0 END) 第'+inttostr(j)+'周, '); end; t_yf.SQL.Add('0 十二月 '); t_yf.SQL.Add(' FROM '); t_yf.SQL.Add(' (select '); t_yf.SQL.Add(' case when 应收 IS null then 0 else 应收 end as 应收金额, '); t_yf.SQL.Add(' case when 应付 IS null then 0 else 应付 end as 应付金额,* '); t_yf.SQL.Add(' from t_op_seae_edi where (录入日期 between :dt1 and :dt2) '+str+' ) t '); t_yf.SQL.Add(' GROUP BY YEAR(录入日期) ' ) ; t_yf.Parameters[0].Value:=dt1.date; t_yf.Parameters[1].Value:=StrToDateTime(DateTimeToStr(dt2.date)+' 23:59:59'); t_yf.Open; chart1.RemoveAllSeries; if t_yf.RecordCount>0 then begin t_yf.First; while not t_yf.Eof do begin if t_yf.RecordCount=1 then begin Chart1.Legend.Visible := False; Chart1.Title.Text.Text:='财务数据对比----'+t_yf.fieldbyname('年度').AsString+'年度'; end else begin Chart1.Legend.Visible := True; Chart1.Title.Text.Text:='财务数据对比'; end; if bsSkinRadioGroup2.ItemIndex=0 then MySeries := TBarSeries.Create(Application) else MySeries := TLineSeries.Create(Application); MySeries.Title:= t_yf.fieldbyname('年度').AsString; MySeries.Marks.Style:=smsValue; for j:=1 to 53 do begin MySeries.AddXY(j,t_yf.fieldbyname('第'+inttostr(j)+'周').AsFloat,'第'+inttostr(j)+'周'); end; Chart1.AddSeries(MySeries); t_yf.Next; end; end; end; if bsSkinRadioGroup1.ItemIndex=2 then begin if Trim(wwDBLookupCombo25.Text)='' then str:='' else str:=' and 委托发送方='+QuotedStr(Trim(wwDBLookupCombo25.Text)); t_lr.Close; t_lr.SQL.Clear; t_lr.SQL.Add('SELECT YEAR(录入日期) 年度, '); for j:=1 to 53 do begin t_lr.SQL.Add('SUM(CASE WHEN datename(week,录入日期) ='+inttostr(j)+' THEN 应收金额 ELSE 0 END)-SUM(CASE WHEN datename(week,录入日期) ='+inttostr(j)+' THEN 应付金额 ELSE 0 END) 第'+inttostr(j)+'周, '); end; t_lr.SQL.Add('0 十二月 '); t_lr.SQL.Add(' FROM '); t_lr.SQL.Add(' (select '); t_lr.SQL.Add(' case when 应收 IS null then 0 else 应收 end as 应收金额, '); t_lr.SQL.Add(' case when 应付 IS null then 0 else 应付 end as 应付金额,* '); t_lr.SQL.Add(' from t_op_seae_edi where (录入日期 between :dt1 and :dt2) '+str+' ) t '); t_lr.SQL.Add(' GROUP BY YEAR(录入日期) ' ) ; t_lr.Parameters[0].Value:=dt1.date; t_lr.Parameters[1].Value:=StrToDateTime(DateTimeToStr(dt2.date)+' 23:59:59'); t_lr.Open; chart1.RemoveAllSeries; if t_lr.RecordCount>0 then begin t_lr.First; while not t_lr.Eof do begin if t_lr.RecordCount=1 then begin Chart1.Legend.Visible := False; Chart1.Title.Text.Text:='财务数据对比----'+t_lr.fieldbyname('年度').AsString+'年度'; end else begin Chart1.Legend.Visible := True; Chart1.Title.Text.Text:='财务数据对比'; end; if bsSkinRadioGroup2.ItemIndex=0 then MySeries := TBarSeries.Create(Application) else MySeries := TLineSeries.Create(Application); MySeries.Title:= t_lr.fieldbyname('年度').AsString; MySeries.Marks.Style:=smsValue; for j:=1 to 53 do begin MySeries.AddXY(j,t_lr.fieldbyname('第'+inttostr(j)+'周').AsFloat,'第'+inttostr(j)+'周'); end; Chart1.AddSeries(MySeries); t_lr.Next; end; end; end; if Trim(wwDBLookupCombo25.Text)='' then str:='' else str:=' and 委托发送方='+QuotedStr(Trim(wwDBLookupCombo25.Text)); t_num.Close; t_num.SQL.Clear; t_num.SQL.Add('select datepart(year,录入日期) as 年度, '); for j:=1 to 53 do begin t_num.SQL.Add('SUM(CASE WHEN datename(week,录入日期) ='+inttostr(j)+' THEN 1 ELSE 0 END) 第'+inttostr(j)+'周, '); end; t_num.SQL.Add('0 十二月 '); t_num.SQL.Add(' from t_op_seae_edi where 录入日期 between :dt1 and :dt2 '+str); t_num.SQL.Add(' group by datepart(year,录入日期) '); t_num.Parameters[0].Value:=dt1.date; t_num.Parameters[1].Value:=StrToDateTime(DateTimeToStr(dt2.date)+' 23:59:59'); t_num.Open; chart3.RemoveAllSeries; if t_num.RecordCount>0 then begin t_num.First; while not t_num.Eof do begin if t_num.RecordCount=1 then begin Chart3.Legend.Visible := False; Chart3.Title.Text.Text:='票数对比----'+t_num.fieldbyname('年度').AsString+'年度'; end else begin Chart3.Legend.Visible := True; Chart3.Title.Text.Text:='票数对比'; end; if bsSkinRadioGroup2.ItemIndex=0 then MySeries := TBarSeries.Create(Application) else MySeries := TLineSeries.Create(Application); MySeries.Title:= t_num.fieldbyname('年度').AsString; MySeries.Marks.Style:=smsValue; for j:=1 to 53 do begin MySeries.AddXY(j,t_num.fieldbyname('第'+inttostr(j)+'周').AsFloat,'第'+inttostr(j)+'周'); end; Chart3.AddSeries(MySeries); t_num.Next; end; end; if Trim(wwDBLookupCombo25.Text)='' then str:='' else str:=' and 委托发送方='+QuotedStr(Trim(wwDBLookupCombo25.Text)); t_ctn.Close; t_ctn.SQL.Clear; t_ctn.SQL.Add('select datepart(year,录入日期) as 年度, '); for j:=1 to 53 do begin t_num.SQL.Add('SUM(CASE WHEN datename(week,录入日期) ='+inttostr(j)+' THEN 实际箱数 ELSE 0 END) 第'+inttostr(j)+'周, '); end; t_num.SQL.Add('0 十二月 '); t_num.SQL.Add(' from '); t_num.SQL.Add(' (select case when 箱数 is null then 0 when 箱数='''' then 0 else 箱数 end as 实际箱数,* from t_op_seae_edi '); t_num.SQL.Add(' where (录入日期 between :dt1 and :dt2) '+str+' ) t '); t_num.SQL.Add(' group by datepart(year,t.录入日期) '); t_ctn.Parameters[0].Value:=dt1.date; t_ctn.Parameters[1].Value:=StrToDateTime(DateTimeToStr(dt2.date)+' 23:59:59'); t_ctn.Open; chart2.RemoveAllSeries; if t_ctn.RecordCount>0 then begin t_ctn.First; while not t_ctn.Eof do begin if t_ctn.RecordCount=1 then begin Chart2.Legend.Visible := False; Chart2.Title.Text.Text:='箱数对比----'+t_ctn.fieldbyname('年度').AsString+'年度'; end else begin Chart2.Legend.Visible := True; Chart2.Title.Text.Text:='箱数对比'; end; if bsSkinRadioGroup2.ItemIndex=0 then MySeries := TBarSeries.Create(Application) else MySeries := TLineSeries.Create(Application); MySeries.Title:= t_ctn.fieldbyname('年度').AsString; MySeries.Marks.Style:=smsValue; for j:=1 to 53 do begin MySeries.AddXY(j,t_ctn.fieldbyname('第'+inttostr(j)+'周').AsFloat,'第'+inttostr(j)+'周'); end; Chart2.AddSeries(MySeries); t_ctn.Next; end; end; end; end; procedure Tfrm_rp_edi.GetBeginEndDate; var str,s,s1,s2:string; begin str:=Trim(ComboBox1.Text); if str='' then begin ShowMessage('工作簿选择不正确!请选择格式为yyyy.mm的工作簿'); Exit; end; dateseparator := '-'; s1:=Copy(str,0,Pos('.',str)-1); s2:=Copy(str,Pos('.',str)+1,Length(str)); begindate:=s1+dateseparator+s2+dateseparator+'01'; if s2='12' then begin s1:=IntToStr(1+strtoint(s1)); s2:=IntToStr(strtoint(s2)-1); end; enddate:=s1+dateseparator+IntToStr(strtoint(s2)+1)+dateseparator+'01'; end; procedure Tfrm_rp_edi.bsSkinRadioGroup1Click(Sender: TObject); begin // bsSkinButton1Click(nil); end; procedure Tfrm_rp_edi.dt1Change(Sender: TObject); begin // bsSkinButton1Click(nil); end; procedure Tfrm_rp_edi.dt2Change(Sender: TObject); begin // bsSkinButton1Click(nil); end; procedure Tfrm_rp_edi.ComboBox2KeyPress(Sender: TObject; var Key: Char); begin { if Key=#13 then begin ShowMessage(GetHzPy(ComboBox2.Text)); //bsSkinButton1Click(nil); end else begin end; } end; procedure Tfrm_rp_edi.bsSkinRadioGroup2Click(Sender: TObject); begin // bsSkinButton1Click(nil); end; end.