You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

420 lines
13 KiB
Plaintext

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

unit u_rp_cd_monthtotal;
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,
bsSkinTabs, ExtCtrls, StdCtrls, wwdbdatetimepicker, kbmMemTable,inifiles,
kbmMemBinaryStreamFormat,dateutils;
type
Tfrm_rp_cd_monthtotal = class(TForm)
Panel1: TPanel;
p_seae: TADOStoredProc;
p_seae1: TDataSource;
t_sum1: TDataSource;
p_seai: TADOStoredProc;
p_seai1: TDataSource;
p_airi1: TDataSource;
p_airi: TADOStoredProc;
p_aire: TADOStoredProc;
p_aire1: TDataSource;
p_sum: TADOStoredProc;
PopupMenu2: TPopupMenu;
N10: TMenuItem;
N11: TMenuItem;
N14: TMenuItem;
N13: TMenuItem;
N12: TMenuItem;
N15: TMenuItem;
N16: TMenuItem;
XPMenu2: TXPMenu;
bsSkinPanel1: TbsSkinPanel;
bsSkinPanel2: TbsSkinPanel;
bsSkinButton10: TbsSkinButton;
bsSkinButton9: TbsSkinButton;
bsSkinButton5: TbsSkinButton;
bsSkinCheckRadioBox1: TbsSkinCheckRadioBox;
bsSkinCheckRadioBox2: TbsSkinCheckRadioBox;
Label1: TLabel;
wwDBDateTimePicker1: TwwDBDateTimePicker;
Label2: TLabel;
wwDBDateTimePicker2: TwwDBDateTimePicker;
kbmThreadDataSet1: TkbmThreadDataSet;
kbmBinaryStreamFormat1: TkbmBinaryStreamFormat;
memtblDetail1: TDataSource;
memtblDetail: TkbmMemTable;
p_airtruck: TADOStoredProc;
p_airtruck1: TDataSource;
PopupMenu1: TPopupMenu;
MenuItem7: TMenuItem;
N1: TMenuItem;
N2: TMenuItem;
p_railway: TADOStoredProc;
p_railway1: TDataSource;
ADOStoredProc1: TADOStoredProc;
dxDBGrid5: TdxDBGrid;
Button1: TButton;
procedure bsSkinButton5Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure bsSkinButton9Click(Sender: TObject);
procedure MenuItem7Click(Sender: TObject);
procedure bsSkinButton10Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
procedure Creatememtbl(Obj:String);
procedure CreatememtblWeek(Obj:String);
procedure setFeeItems(bstypeid: Integer; StrObj, AirStr, sDate: string;
amemtblDetail: TKbmMemTable; ap_seae: TADOStoredProc);
{ Private declarations }
public
{ Public declarations }
procedure GetMonthData;
procedure GetweekData;
end;
var
frm_rp_cd_monthtotal: Tfrm_rp_cd_monthtotal;
rp_rp_total_open:boolean;
implementation
uses u_main, my_sys_function, u_rp_query, u_sys_progress,
u_data_share;
{$R *.dfm}
procedure Tfrm_rp_cd_monthtotal.Creatememtbl(Obj:String);
var
aDate:TDate;
sDate,aYear,aMonth:String;
aColumn:TdxDBTreeListColumn;
aBand:TdxTreeListBand;
i:integer;
begin
// dxDBGrid5.Bands.Clear;
// dxDBGrid1.DestroyColumns;
while dxDBGrid5.columncount>0 do
begin
dxDBGrid5.Columns[0].Destroy;
end;
dxDBGrid5.KeyField:=Obj;
memtblDetail.Close;
memtblDetail.EmptyTable;
memtblDetail.Fields.Clear;
memtblDetail.FieldDefs.Clear;
memtblDetail.FieldDefs.Add(Obj, ftString, 60, false);
memtblDetail.FieldDefs.Add('sort', ftInteger, 0, false);
aColumn:=dxDBGrid5.CreateColumn(TdxDBGridColumn);
aColumn.Caption:=Obj;
aColumn.BandIndex:=0;
aColumn.FieldName:=Obj;
i:=1;
aDate:=wwDBDateTimePicker2.Date;
while (not (aDate<wwDBDateTimePicker1.Date)) or (FormatDateTime('YYYYMM',aDate)=FormatDateTime('YYYYMM',wwDBDateTimePicker1.Date)) do begin
sDate:=FormatDateTime('YYYYMM',aDate);
aYear:=FormatDateTime('YYYY',aDate);
aMonth:=FormatDateTime('MM',aDate);
aColumn:=dxDBGrid5.CreateColumn(TdxDBGridColumn);
aColumn.Caption:=aYear+'<27><>'+aMonth+'<27><>';
aColumn.FieldName:=sDate+'BL';
// aColumn.SummaryFooterType:=cstSum;
aColumn.BandIndex:=0;
memtblDetail.FieldDefs.Add(sDate+'BL',ftinteger, 0, false);
aDate:=IncMonth(aDate,-1);
Inc(i);
end;
memtblDetail.CreateTable;
memtblDetail.Open;
end;
procedure Tfrm_rp_cd_monthtotal.bsSkinButton5Click(Sender: TObject);
begin
close;
end;
procedure Tfrm_rp_cd_monthtotal.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
frm_rp_cd_monthtotal.Hide;
frm_rp_cd_monthtotal.ManualFloat(frm_rp_cd_monthtotal.BoundsRect );
frm_main.freeTabs('frm_rp_cd_monthtotal');
action:=cafree;
frm_rp_cd_monthtotal:=nil;
end;
procedure Tfrm_rp_cd_monthtotal.setFeeItems(bstypeid:Integer;StrObj,AirStr,sDate:string;amemtblDetail:TKbmMemTable;ap_seae:TADOStoredProc);
begin
end;
procedure Tfrm_rp_cd_monthtotal.bsSkinButton9Click(Sender: TObject);
begin
sys_print('<27>յ<EFBFBD><D5B5>ۺ<EFBFBD>ͳ<EFBFBD><CDB3>',2,nil,nil,nil,nil,memtblDetail1,nil,nil,nil,nil,nil,nil);
end;
procedure Tfrm_rp_cd_monthtotal.MenuItem7Click(Sender: TObject);
begin
grid_save_xls(dxdbgrid5);
exit;
end;
procedure Tfrm_rp_cd_monthtotal.CreatememtblWeek(Obj: String);
var
aDate:TDate;
sDate,aYear,aweek,bfieldname:String;
aColumn:TdxDBTreeListColumn;
aBand:TdxTreeListBand;
i:integer;
begin
// dxDBGrid5.Bands.Clear;
// dxDBGrid1.DestroyColumns;
while dxDBGrid5.columncount>0 do
begin
dxDBGrid5.Columns[0].Destroy;
end;
dxDBGrid5.KeyField:=Obj;
memtblDetail.Close;
memtblDetail.EmptyTable;
memtblDetail.Fields.Clear;
memtblDetail.FieldDefs.Clear;
memtblDetail.FieldDefs.Add(Obj, ftString, 60, false);
memtblDetail.FieldDefs.Add('sort', ftInteger, 0, false);
aColumn:=dxDBGrid5.CreateColumn(TdxDBGridColumn);
aColumn.Caption:=Obj;
aColumn.BandIndex:=0;
aColumn.FieldName:=Obj;
i:=1;
aQuery:=CreateAdoQuery;
try
With aQuery do begin
Close;SQL.Clear;
SQL.Add('select distinct YEAR(¼<><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) CDYEAR,datepart(WEEK,¼<><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) CDWEEK from t_op_seae_edi where 1=1 AND (¼<><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> between :dt1 and :dt2) ');
SQL.Add('order by YEAR(¼<><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) desc,datepart(WEEK,¼<><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) desc ');
Parameters[0].Value:=wwDBDateTimePicker1.date;
Parameters[1].Value:=StrToDateTime(DateTimeToStr(wwDBDateTimePicker2.date)+' 23:59:59');
Open;
First;
while not Eof do begin
aYear:=Fieldbyname('CDYEAR').asstring;
aweek:=Fieldbyname('CDWEEK').asstring;
sDate:=aYear+aweek;
aColumn:=dxDBGrid5.CreateColumn(TdxDBGridColumn);
aColumn.Caption:=aYear+'<27><>'+aweek+'<27><>';
aColumn.FieldName:=sDate+'BL';
// aColumn.SummaryFooterType:=cstSum;
aColumn.BandIndex:=0;
memtblDetail.FieldDefs.Add(sDate+'BL',ftinteger, 0, false);
Next;
end;
END;
finally
FreeAndNil(aQuery);
end;
{
aDate:=wwDBDateTimePicker2.Date;
while (aDate>=wwDBDateTimePicker1.Date) do begin
aYear:=FormatDateTime('YYYY',aDate);
aweek:=inttostr(weekoftheyear(aDate));
if (MonthOf(aDate)=1) and (weekoftheyear(aDate)>50) then aYear:=IntToStr(StrToInt(aYear)-1);
sDate:=aYear+aweek;
if ((sDate+'BL')<>bfieldname) then begin
aColumn:=dxDBGrid5.CreateColumn(TdxDBGridColumn);
aColumn.Caption:=aYear+'<27><>'+aweek+'<27><>';
aColumn.FieldName:=sDate+'BL';
// aColumn.SummaryFooterType:=cstSum;
aColumn.BandIndex:=0;
memtblDetail.FieldDefs.Add(sDate+'BL',ftinteger, 0, false);
bfieldname:=sDate+'BL';
end;
aDate:=aDate-7;
if (aDate<wwDBDateTimePicker1.Date) and (i=1) then begin
aDate:=wwDBDateTimePicker1.Date;
Inc(i);
end;
aYear:=FormatDateTime('YYYY',aDate);
aweek:=inttostr(weekoftheyear(aDate));
// ShowMessage(DateToStr(aDate)+aweek);
end;
}
memtblDetail.CreateTable;
memtblDetail.Open;
end;
procedure Tfrm_rp_cd_monthtotal.GetMonthData;
var
aQuery:TADOQuery;
begin
aQuery:=CreateAdoQuery;
try
With aQuery do begin
Close;SQL.Clear;
SQL.Add('select ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>,SUBSTRING(CONVERT(char(15),¼<><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,112),1,6) CDMONTH,COUNT(1) CDBL from t_op_seae_edi where 1=1 AND (¼<><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> between :dt1 and :dt2) ');
SQL.Add('GROUP BY ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>,SUBSTRING(CONVERT(char(15),¼<><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,112),1,6) ');
SQL.Add('ORDER BY ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>,SUBSTRING(CONVERT(char(15),¼<><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,112),1,6) ');
Parameters[0].Value:=wwDBDateTimePicker1.date;
Parameters[1].Value:=StrToDateTime(DateTimeToStr(wwDBDateTimePicker2.date)+' 23:59:59');
Open;
if not IsEmpty then begin
First;
while not eof do begin
if memtblDetail.Locate('ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>',FieldByName('ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>').AsString,[]) THEN
begin
memtblDetail.edit;
memtblDetail.FieldByName(FieldByName('CDMONTH').AsString+'BL').AsInteger:=memtblDetail.FieldByName(FieldByName('CDMONTH').AsString+'BL').AsInteger+FieldByName('CDBL').AsInteger;
memtblDetail.Post;
end else begin
memtblDetail.Insert;
memtblDetail.FieldByName('ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>').AsString:=FieldByName('ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>').AsString;
memtblDetail.FieldByName(FieldByName('CDMONTH').AsString+'BL').AsInteger:=FieldByName('CDBL').AsInteger;
memtblDetail.FieldByName('sort').AsInteger:=1;
memtblDetail.Post;
end;
if memtblDetail.Locate('ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>','<27>ϼ<EFBFBD>',[]) THEN
begin
memtblDetail.edit;
memtblDetail.FieldByName(FieldByName('CDMONTH').AsString+'BL').AsInteger:=memtblDetail.FieldByName(FieldByName('CDMONTH').AsString+'BL').AsInteger+FieldByName('CDBL').AsInteger;
memtblDetail.Post;
end else begin
memtblDetail.Insert;
memtblDetail.FieldByName('ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>').AsString:='<27>ϼ<EFBFBD>';
memtblDetail.FieldByName(FieldByName('CDMONTH').AsString+'BL').AsInteger:=FieldByName('CDBL').AsInteger;
memtblDetail.FieldByName('sort').AsInteger:=1000;
memtblDetail.Post;
end;
Next;
end;
memtblDetail.SortOn('sort;ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>',[]);
end;
end;
finally
FreeAndNil(aQuery);
end;
end;
procedure Tfrm_rp_cd_monthtotal.bsSkinButton10Click(Sender: TObject);
begin
if wwDBDateTimePicker1.Text='' then begin
MessageDlg('<27><>ʼ<EFBFBD><CABC><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD><EFBFBD>ֵ',mtWarning,[mbYes],0);
exit;
end;
if wwDBDateTimePicker2.Text='' then begin
MessageDlg('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD><EFBFBD>ֵ',mtWarning,[mbYes],0);
exit;
end;
if (bsSkinCheckRadioBox2.Checked) then begin
Creatememtbl('ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>');
GetMonthData;
end else begin
CreatememtblWeek('ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>');
GetweekData;
end;
end;
procedure Tfrm_rp_cd_monthtotal.GetweekData;
var
aQuery:TADOQuery;
aYear,aweek,sDate:string;
begin
aQuery:=CreateAdoQuery;
try
With aQuery do begin
Close;SQL.Clear;
SQL.Add('select ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>,YEAR(¼<><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) CDYEAR,datepart(WEEK,¼<><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) CDWEEK,COUNT(1) CDBL from t_op_seae_edi where 1=1 AND (¼<><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> between :dt1 and :dt2) ');
SQL.Add('GROUP BY ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>,YEAR(¼<><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>),datepart(WEEK,¼<><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) ');
SQL.Add('ORDER BY ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>,YEAR(¼<><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>),datepart(WEEK,¼<><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) ');
Parameters[0].Value:=wwDBDateTimePicker1.date;
Parameters[1].Value:=StrToDateTime(DateTimeToStr(wwDBDateTimePicker2.date)+' 23:59:59');
Open;
if not IsEmpty then begin
if not ASSIGNED(frm_sys_progress) then
frm_sys_progress:=tfrm_sys_progress.Create(application);
frm_sys_progress.Show;
frm_sys_progress.bsSkinGauge1.MaxValue:=RecordCount;
frm_sys_progress.bsSkinGauge1.MinValue:=0;
frm_sys_progress.bsSkinGauge1.Value:=0;
frm_sys_progress.Update;
First;
while not eof do begin
aYear:=FieldByName('CDYEAR').AsString;
aweek:=inttostr(FieldByName('CDWEEK').AsInteger);
// if (MonthOf(FieldByName('CDMONTH').AsDateTime)=1) and (weekoftheyear(FieldByName('CDMONTH').AsDateTime)>50) then aYear:=IntToStr(StrToInt(aYear)-1);
frm_sys_progress.bsSkinGauge1.Value:=frm_sys_progress.bsSkinGauge1.Value+1;
sDate:=aYear+aweek;
if memtblDetail.Locate('ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>',FieldByName('ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>').AsString,[]) THEN
begin
memtblDetail.edit;
memtblDetail.FieldByName(sDate+'BL').AsInteger:=memtblDetail.FieldByName(sDate+'BL').AsInteger+FieldByName('CDBL').AsInteger;
memtblDetail.Post;
end else begin
memtblDetail.Insert;
memtblDetail.FieldByName('ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>').AsString:=FieldByName('ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>').AsString;
memtblDetail.FieldByName(sDate+'BL').AsInteger:=FieldByName('CDBL').AsInteger;
memtblDetail.FieldByName('sort').AsInteger:=1;
memtblDetail.Post;
end;
if memtblDetail.Locate('ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>','<27>ϼ<EFBFBD>',[]) THEN
begin
memtblDetail.edit;
memtblDetail.FieldByName(sDate+'BL').AsInteger:=memtblDetail.FieldByName(sDate+'BL').AsInteger+FieldByName('CDBL').AsInteger;
memtblDetail.Post;
end else begin
memtblDetail.Insert;
memtblDetail.FieldByName('ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>').AsString:='<27>ϼ<EFBFBD>';
memtblDetail.FieldByName(sDate+'BL').AsInteger:=FieldByName('CDBL').AsInteger;
memtblDetail.FieldByName('sort').AsInteger:=1000;
memtblDetail.Post;
end;
Next;
end;
memtblDetail.SortOn('sort;ί<>з<EFBFBD><D0B7>ͷ<EFBFBD>',[]);
end;
end;
finally
freeAndNil(frm_sys_progress);
FreeAndNil(aQuery);
end;
end;
procedure Tfrm_rp_cd_monthtotal.Button1Click(Sender: TObject);
begin
ShowMessage(IntToStr(WeekofYear(StrToDate(wwDBDateTimePicker2.Text))));
end;
end.