299 lines
8.9 KiB
ObjectPascal
299 lines
8.9 KiB
ObjectPascal
unit U_QryPivotBaseList;
|
||
|
||
interface
|
||
|
||
uses
|
||
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
|
||
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.ToolWin,cxExportPivotGridLink,
|
||
FrameDateSel10, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
|
||
dxSkinsCore, dxSkinsDefaultPainters, dxSkinWXI, cxClasses, dxLayoutContainer, cxPivotDrillDownFormUnit,
|
||
dxLayoutControl, cxContainer, cxEdit, cxTextEdit, cxMaskEdit, cxDropDownEdit,
|
||
Vcl.StdCtrls, Vcl.ExtCtrls, cxCustomData, cxStyles, dxBarBuiltInMenu,U_WindowFormdesign,
|
||
cxCustomPivotGrid, cxPivotGrid, cxGridCustomPopupMenu, cxGridPopupMenu, math,
|
||
Data.DB, Datasnap.DBClient, Data.Win.ADODB, cxDBPivotGrid;
|
||
|
||
type
|
||
TfrmQryPivotBaseList = class(TForm)
|
||
ToolBar3: TToolBar;
|
||
Trefresh: TToolButton;
|
||
Tprint: TToolButton;
|
||
TprintGrid: TToolButton;
|
||
TsaveGrid: TToolButton;
|
||
TgridLiSet: TToolButton;
|
||
Tclose: TToolButton;
|
||
frmFrameDateSel1: TfrmFrameDateSel10;
|
||
dxLayoutControl_query: TdxLayoutControl;
|
||
dxLayoutControl_queryGroup_Root: TdxLayoutGroup;
|
||
Panel_page: TPanel;
|
||
LBCPAP: TLabel;
|
||
Label31: TLabel;
|
||
BTNP: TButton;
|
||
BTLP: TButton;
|
||
TCBNOR: TcxComboBox;
|
||
ADOQueryBaseCmd: TADOQuery;
|
||
ADOQueryBaseTemp: TADOQuery;
|
||
CDS_List: TClientDataSet;
|
||
ADOQueryList: TADOQuery;
|
||
DataSource1: TDataSource;
|
||
cxGridPopupMenu1: TcxGridPopupMenu;
|
||
cxDBPivotGrid1: TcxDBPivotGrid;
|
||
procedure TprintClick(Sender: TObject);
|
||
procedure TrefreshClick(Sender: TObject);
|
||
procedure TcloseClick(Sender: TObject);
|
||
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
||
procedure FormCreate(Sender: TObject);
|
||
procedure FormDestroy(Sender: TObject);
|
||
procedure FormShow(Sender: TObject);
|
||
procedure cxDBPivotGrid1DblClick(Sender: TObject);
|
||
private
|
||
fWindowDesign: TWindowFormdesign;
|
||
CurrentPage, RecordsNumber: Integer;
|
||
fDesignCode:string;
|
||
procedure doQuery();
|
||
procedure doQueryByCriteria();
|
||
procedure initGrid();
|
||
protected
|
||
fParameters1: string;
|
||
fParameters2: string;
|
||
fParameters3: string;
|
||
fParameters4: string;
|
||
fParameters5: string;
|
||
fParameters10: string;
|
||
function GetPivotGrid: TcxCustomPivotGrid; virtual;
|
||
public
|
||
fExportFileName:string;
|
||
fFormId: integer;
|
||
fProcedureName:string; //<2F>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
FLMType:string; //<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ͱ<EFBFBD>־
|
||
ftimeType:string; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
fQueryType:String; //<2F><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>
|
||
FFiltration1:string; //<2F><>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
fCriteria:string; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
property PivotGrid: TcxCustomPivotGrid read GetPivotGrid;
|
||
constructor Create(AOwner: TComponent; ACaption: string=''; Parameters1: string=''; Parameters2: string=''; Parameters3: string=''; Parameters4: string=''; Parameters5: string=''; Parameters10: string='';FormID:Integer=0);
|
||
|
||
end;
|
||
|
||
var
|
||
frmQryPivotBaseList: TfrmQryPivotBaseList;
|
||
|
||
implementation
|
||
uses
|
||
U_RTFun, U_globalVar, U_dataLink,U_FormLayOutDesign, U_LabelPrint;
|
||
{$R *.dfm}
|
||
|
||
constructor TfrmQryPivotBaseList.Create(AOwner: TComponent; ACaption: string=''; Parameters1: string=''; Parameters2: string=''; Parameters3: string=''; Parameters4: string=''; Parameters5: string=''; Parameters10: string='';FormID:Integer=0);
|
||
begin
|
||
inherited Create(AOwner);
|
||
if ACaption <> '' then
|
||
Caption := ACaption;
|
||
|
||
fParameters1 := Parameters1;
|
||
fParameters2 := Parameters2;
|
||
fParameters3 := Parameters3;
|
||
fParameters4 := Parameters4;
|
||
fParameters5 := Parameters5;
|
||
fParameters10 := Parameters10;
|
||
fFormId:= FormID ;
|
||
end;
|
||
|
||
procedure TfrmQryPivotBaseList.FormClose(Sender: TObject;
|
||
var Action: TCloseAction);
|
||
begin
|
||
Sendmessage(application.MainForm.Handle, WM_CloseForm, 4, 0);
|
||
|
||
Action:=cafree;
|
||
end;
|
||
|
||
procedure TfrmQryPivotBaseList.FormCreate(Sender: TObject);
|
||
begin
|
||
cxDBPivotGrid1.Align:=alClient;
|
||
CurrentPage := 1;
|
||
RecordsNumber := 500;
|
||
fWindowDesign := TWindowFormdesign.Create();
|
||
frmFrameDateSel1.begdate.Date:=SGetServerDate(ADOQueryBaseTemp);
|
||
frmFrameDateSel1.enddate.Date:=frmFrameDateSel1.begdate.Date;
|
||
end;
|
||
|
||
procedure TfrmQryPivotBaseList.FormDestroy(Sender: TObject);
|
||
begin
|
||
fWindowDesign.free;
|
||
end;
|
||
|
||
procedure TfrmQryPivotBaseList.FormShow(Sender: TObject);
|
||
begin
|
||
fDesignCode := fDllFileName +'|'+self.name+ '|' + intTostr(fformId) + '|' + 'cxgrid1';
|
||
if DParameters8<>'1' then
|
||
begin
|
||
fWindowDesign.FormStyleInit10(self, fFormId, ADOQueryBaseTemp, ADOQueryBaseCmd, '', fParameters10);
|
||
end;
|
||
if dxLayoutControl_query.Tag<>999 then
|
||
readLayOut(dxLayoutControl_query,ADOQueryBaseTemp,PWideChar( fDllFileName+'|'+self.name+'|'+dxLayoutControl_query.Name+'.ini'));
|
||
fWindowDesign.fProcedureName:=fProcedureName;
|
||
//<2F><><EFBFBD>Ӷ<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>
|
||
addQryContionByLay(ADOQueryBaseTemp,fformId,'cxgrid1',dxLayoutControl_query,7);
|
||
initGrid();
|
||
end;
|
||
|
||
procedure TfrmQryPivotBaseList.TcloseClick(Sender: TObject);
|
||
begin
|
||
close;
|
||
end;
|
||
|
||
procedure TfrmQryPivotBaseList.TprintClick(Sender: TObject);
|
||
begin
|
||
cxExportPivotGridToXLSX(fExportFileName, cxDBPivotGrid1, True, True, '', nil);
|
||
end;
|
||
|
||
procedure TfrmQryPivotBaseList.TrefreshClick(Sender: TObject);
|
||
begin
|
||
if frmFrameDateSel1.BegDate.Visible then
|
||
begin
|
||
frmFrameDateSel1.BegDate.SetFocus;
|
||
end;
|
||
CurrentPage := 1;
|
||
initGrid();
|
||
end;
|
||
|
||
///////////////////////////////
|
||
///
|
||
procedure TfrmQryPivotBaseList.initGrid();
|
||
begin
|
||
if fQueryType='criteria' then
|
||
begin
|
||
doQueryByCriteria() ;
|
||
end
|
||
else
|
||
begin
|
||
frmFrameDateSel1.jqModel.Checked:=true;
|
||
doQuery() ;
|
||
end;
|
||
end;
|
||
|
||
|
||
////////////////////////////////////
|
||
procedure TfrmQryPivotBaseList.cxDBPivotGrid1DblClick(Sender: TObject);
|
||
var
|
||
ACrossCell: TcxPivotGridCrossCell;
|
||
begin
|
||
// with PivotGrid.HitTest do
|
||
// begin
|
||
// if HitAtDataCell then
|
||
// begin
|
||
// ACrossCell := (HitObject as TcxPivotGridDataCellViewInfo).CrossCell;
|
||
// if ACrossCell <> nil then
|
||
// cxShowDrillDownDataSource(ACrossCell);
|
||
// end;
|
||
// end;
|
||
end;
|
||
|
||
procedure TfrmQryPivotBaseList.doQuery();
|
||
var
|
||
strwhere: string;
|
||
begin
|
||
if fProcedureName='' then
|
||
begin
|
||
application.MessageBox('<27>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʋ<EFBFBD><C6B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>!','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ',0);
|
||
exit;
|
||
end;
|
||
strwhere := GetProcedureParam(dxLayoutControl_query);
|
||
|
||
try
|
||
cxDBPivotGrid1.BeginUpdate();
|
||
CDS_List.DisableControls;
|
||
with ADOQueryList do
|
||
begin
|
||
close;
|
||
Filtered := false;
|
||
sql.Clear;
|
||
sql.Add('exec '+fProcedureName);
|
||
sql.Add('@timeType='+quotedstr(fTimeType));
|
||
sql.Add(',@begDate='+quotedstr(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.begdate.Date)));
|
||
sql.Add(',@endDate='+quotedstr(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.enddate.Date+1)));
|
||
if frmFrameDateSel1.jqModel.Checked then
|
||
sql.Add(',@jqModel=1')
|
||
else
|
||
sql.Add(',@jqModel=0');
|
||
if Panel_page.Visible then
|
||
begin
|
||
sql.Add(',@pageIndex=' + inttostr(CurrentPage));
|
||
sql.Add(',@pageSize=' + inttostr(RecordsNumber));
|
||
end;
|
||
sql.Add(',@criteria='+ quotedstr(fcriteria));
|
||
if strwhere<>'' then
|
||
sql.Add(','+strwhere);
|
||
// showMessage(sql.Text);
|
||
//cxMemo1.Text:= sql.Text ;
|
||
open;
|
||
end;
|
||
SCreateCDS(ADOQueryList, CDS_List);
|
||
SInitCDSData(ADOQueryList, CDS_List);
|
||
if Panel_page.Visible then
|
||
begin
|
||
LBCPAP.Caption := inttostr(CurrentPage) + '/' + inttostr(ceil(cds_list.FieldByName('TotalCount').AsInteger / RecordsNumber));
|
||
end;
|
||
finally
|
||
CDS_List.EnableControls;
|
||
cxDBPivotGrid1.EndUpdate;
|
||
end;
|
||
end;
|
||
|
||
|
||
////////////////////////////////////
|
||
procedure TfrmQryPivotBaseList.doQueryByCriteria();
|
||
var
|
||
mSqlWhere: string;
|
||
begin
|
||
if fProcedureName='' then
|
||
begin
|
||
application.MessageBox('<27>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʋ<EFBFBD><C6B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>!','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ',0);
|
||
exit;
|
||
end;
|
||
|
||
mSqlWhere := SLGetFilters(dxLayoutControl_query, 1, 2);
|
||
if trim(mSqlWhere) <> '' then
|
||
begin
|
||
mSqlWhere := ' and ' + trim(mSqlWhere);
|
||
end;
|
||
mSqlWhere:=fCriteria + ' ' + mSqlWhere ;
|
||
try
|
||
cxDBPivotGrid1.BeginUpdate();
|
||
CDS_List.DisableControls;
|
||
with ADOQueryList do
|
||
begin
|
||
close;
|
||
Filtered := false;
|
||
sql.Clear;
|
||
sql.Add('exec '+fProcedureName);
|
||
sql.Add('@timeType='+quotedstr(fTimeType));
|
||
sql.Add(',@begDate='+quotedstr(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.begdate.Date)));
|
||
sql.Add(',@endDate='+quotedstr(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.enddate.Date+1)));
|
||
if Panel_page.Visible then
|
||
begin
|
||
sql.Add(',@pageIndex=' + inttostr(CurrentPage));
|
||
sql.Add(',@pageSize=' + inttostr(RecordsNumber));
|
||
end;
|
||
sql.Add(',@criteria='+ quotedstr(mSqlWhere));
|
||
|
||
//cxMemo1.Text:= sql.Text ;
|
||
open;
|
||
end;
|
||
SCreateCDS(ADOQueryList, CDS_List);
|
||
SInitCDSData(ADOQueryList, CDS_List);
|
||
if Panel_page.Visible then
|
||
begin
|
||
LBCPAP.Caption := inttostr(CurrentPage) + '/' + inttostr(ceil(cds_list.FieldByName('TotalCount').AsInteger / RecordsNumber));
|
||
end;
|
||
finally
|
||
CDS_List.EnableControls;
|
||
cxDBPivotGrid1.EndUpdate;
|
||
end;
|
||
end;
|
||
|
||
function TfrmQryPivotBaseList.GetPivotGrid: TcxCustomPivotGrid;
|
||
begin
|
||
Result := nil;
|
||
end;
|
||
|
||
end.
|