unit U_HZViewList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin, StdCtrls,
  cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP, ShellAPI, IniFiles, cxCheckBox, cxCalendar, cxButtonEdit,
  cxTextEdit, cxGridBandedTableView, cxGridDBBandedTableView, dxPSGlbl, dxPSUtl,
  dxPSEngn, dxPrnPg, dxBkgnd, dxWrap, dxPrnDev, dxPSCompsProvider,
  dxPSFillPatterns, dxPSEdgePatterns, dxPSCore, dxfQuickTyp, dxPScxCommon,
  dxPScxGridLnk, dxPSContainerLnk, dxCore, ActiveX, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxPSPDFExportCore, dxPSPDFExport,
  cxDrawTextUtils, dxPSPrVwStd, dxPSPrVwAdv, dxPSPrVwRibbon,
  dxPScxPageControlProducer, dxPScxGridLayoutViewLnk,
  dxPScxEditorProducers, dxPScxExtEditorProducers;

type
  TfrmHZViewList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBDel: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_NH: TDataSource;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    CDS_NH: TClientDataSet;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_JWL: TClientDataSet;
    DS_JWL: TDataSource;
    DS_RHL: TDataSource;
    CDS_RHL: TClientDataSet;
    cxGridPopupMenu3: TcxGridPopupMenu;
    DS_PB: TDataSource;
    CDS_PB: TClientDataSet;
    cxGridPopupMenu4: TcxGridPopupMenu;
    DS_CP: TDataSource;
    CDS_CP: TClientDataSet;
    cxGridPopupMenu5: TcxGridPopupMenu;
    ToolButton5: TToolButton;
    dxComponentPrinter1: TdxComponentPrinter;
    ScrollBox1: TScrollBox;
    Panel1: TPanel;
    Label1: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Chejian: TComboBox;
    Panel2: TPanel;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBBandedTableView;
    v1Column1: TcxGridDBBandedColumn;
    v1Column2: TcxGridDBBandedColumn;
    v1Column3: TcxGridDBBandedColumn;
    v1Column4: TcxGridDBBandedColumn;
    cxGridLevel1: TcxGridLevel;
    cxGrid1: TcxGrid;
    Tv2: TcxGridDBBandedTableView;
    cxGridDBBandedColumn1: TcxGridDBBandedColumn;
    cxGridDBBandedColumn2: TcxGridDBBandedColumn;
    cxGridDBBandedColumn3: TcxGridDBBandedColumn;
    v2Column1: TcxGridDBBandedColumn;
    v2Column2: TcxGridDBBandedColumn;
    cxGridLevel2: TcxGridLevel;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBBandedTableView;
    cxGridDBBandedColumn4: TcxGridDBBandedColumn;
    cxGridDBBandedColumn5: TcxGridDBBandedColumn;
    cxGridDBBandedColumn6: TcxGridDBBandedColumn;
    v3Column1: TcxGridDBBandedColumn;
    v3Column2: TcxGridDBBandedColumn;
    cxGridLevel3: TcxGridLevel;
    Panel3: TPanel;
    cxGrid4: TcxGrid;
    Tv4: TcxGridDBBandedTableView;
    cxGridDBBandedColumn8: TcxGridDBBandedColumn;
    cxGridDBBandedColumn9: TcxGridDBBandedColumn;
    v4Column1: TcxGridDBBandedColumn;
    v4Column2: TcxGridDBBandedColumn;
    cxGridLevel4: TcxGridLevel;
    cxGrid5: TcxGrid;
    Tv5: TcxGridDBBandedTableView;
    cxGridDBBandedColumn11: TcxGridDBBandedColumn;
    cxGridDBBandedColumn12: TcxGridDBBandedColumn;
    Tv5Column1: TcxGridDBBandedColumn;
    Tv5Column2: TcxGridDBBandedColumn;
    Tv5Column3: TcxGridDBBandedColumn;
    Tv5Column4: TcxGridDBBandedColumn;
    Tv5Column5: TcxGridDBBandedColumn;
    Tv5Column6: TcxGridDBBandedColumn;
    Tv5Column7: TcxGridDBBandedColumn;
    v5Column1: TcxGridDBBandedColumn;
    v5Column2: TcxGridDBBandedColumn;
    cxGridLevel5: TcxGridLevel;
    dxComponentPrinter1Link1: TdxCustomContainerReportLink;
    v4Column3: TcxGridDBBandedColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure NHBiaoNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ChejianChange(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();
  public
  end;

var
  frmHZViewList: TfrmHZViewList;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_NengHaoInput;

{$R *.dfm}

procedure TfrmHZViewList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select Sum(Qty) Qty,sum(Qty*Price) NHMoney,CheJian, NHType from NengHao ');
      sql.Add(' where NHDate>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)) + '''');
      sql.Add(' and NHDate<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.DateTime + 1)) + '''');
      sql.Add('Group by CheJian ,NHType');
      Open;
      SCreateCDS20(ADOQueryMain, CDS_NH);
      SInitCDSData20(ADOQueryMain, CDS_NH);
    end;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select Sum(CRQty) CRQty,sum(CRQty*YCLPrice) JWLMoney,ZdyStr1 chejian,YCLName,CRUnit from CK_YCL_CR ');
      sql.Add(' where CRTime>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)) + '''');
      sql.Add(' and CRTime<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.DateTime + 1)) + '''');
      sql.Add(' and CKName=''机物料仓库'' ');
      sql.Add(' and CRType=''正常出库'' ');
      sql.Add('Group by ZdyStr1,YCLName,CRUnit');
      Open;
      SCreateCDS20(ADOQueryMain, CDS_JWL);
      SInitCDSData20(ADOQueryMain, CDS_JWL);
    end;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select Sum(CRQty) CRQty,sum(CRQty*YCLPrice) RHLMoney,ZdyStr1 chejian,YCLName,CRUnit from CK_YCL_CR ');
      sql.Add(' where CRTime>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)) + '''');
      sql.Add(' and CRTime<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.DateTime + 1)) + '''');
      sql.Add(' and CKName=''染化料仓库'' ');
      sql.Add(' and CRType=''正常出库'' ');
      sql.Add('Group by ZdyStr1,YCLName,CRUnit');
      Open;
      SCreateCDS20(ADOQueryMain, CDS_RHL);
      SInitCDSData20(ADOQueryMain, CDS_RHL);
    end;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select Sum(CRQty) CRQty,sum(PS) PS,YCLName,CRUnit,GYSName from CK_PB_CR ');
      sql.Add(' where CRTime>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)) + '''');
      sql.Add(' and CRTime<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.DateTime + 1)) + '''');
      //sql.Add(' and CKName=''染化料仓库'' ');
      sql.Add(' and CRType=''正常出库'' ');
      sql.Add('Group by GYSName,YCLName,CRUnit');
      Open;
      SCreateCDS20(ADOQueryMain, CDS_PB);
      SInitCDSData20(ADOQueryMain, CDS_PB);
    end;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select sum(AA.Qty) Qty ,sum(AA.KgQty) KgQty,sum(AA.KgQtyP) KgQtyP,Count(*) JSL,LenUnit,PCode,ColorNo,MJDate,KHName,CKNO,OrderNo ');
      sql.Add(',PSpec,PCF,PHuaNo,PColorNo ,MJFK,MJSJKZ,MJType,CPMoney=Sum(CPMoney)');
      SQL.Add(' from(select  A.Qty ,A.KgQty ,A.KgQtyP,A.CKNO,D.LenUnit,D.PCode,D.ColorNo,D.OrderNo,CPMoney=Qty*A.Price,');
      sql.Add('MJDate=convert(varchar(10),A.CRTime,120),A.KHName');
      sql.Add(',D.PSpec,D.PCF,D.PHuaNo,D.PColorNo,D.MJFK,D.MJSJKZ,D.MJType,D.BatchNo');
      sql.add('from CK_BanCP_CR A ');
      Sql.add(' inner join XH_MJJY D on A.MJId=D.MJId');
      sql.add('where A.CRTime>=:begdate and A.CRTime<:enddate');
      SQL.Add(' and CRType=''正常出库'' ) AA');
      sql.Add(' Group by LenUnit,PCode,ColorNo,MJDate,KHName,CKNO,OrderNo,PSpec,PCF,PHuaNo,PColorNo ,MJFK,MJSJKZ,MJType,BatchNo');
      Parameters.ParamByName('begdate').Value := Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime));
      Parameters.ParamByName('enddate').Value := Trim(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1));
      Open;
      //ShowMessage(SQL.Text);
    end;
    SCreateCDS20(ADOQueryMain, CDS_CP);
    SInitCDSData20(ADOQueryMain, CDS_CP);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmHZViewList.FormDestroy(Sender: TObject);
begin
  frmHZViewList := nil;
end;

procedure TfrmHZViewList.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TfrmHZViewList.TBCloseClick(Sender: TObject);
begin
  WriteCxBandedGrid('HZ查询1', Tv1, '客户自定义');
  WriteCxBandedGrid('HZ查询2', Tv2, '客户自定义');
  WriteCxBandedGrid('HZ查询3', Tv3, '客户自定义');
  WriteCxBandedGrid('HZ查询4', Tv4, '客户自定义');
  WriteCxBandedGrid('HZ查询5', Tv5, '客户自定义');
  Close;
end;

procedure TfrmHZViewList.FormShow(Sender: TObject);
begin
  //ReadCxGrid('能耗查询',Tv2,'客户自定义');
  ReadCxBandedGrid('HZ查询1', Tv1, '客户自定义');
  ReadCxBandedGrid('HZ查询2', Tv2, '客户自定义');
  ReadCxBandedGrid('HZ查询3', Tv3, '客户自定义');
  ReadCxBandedGrid('HZ查询4', Tv4, '客户自定义');
  ReadCxBandedGrid('HZ查询5', Tv5, '客户自定义');
  //InitGrid();
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select Code=ZdyNo,Name=ZdyName from KH_Zdy where Type=''chejian'' ');
    Open;
  end;
  Chejian.Items.Clear;
  with ADOQueryTemp do
  begin
    First;
    while not Eof do
    begin
      Chejian.Items.Add(Trim(ADOQueryTemp.fieldbyname('Name').AsString));
      Next;
    end;
  end;
  Chejian.Items.Add('');
  BegDate.Date := SGetServerDate(ADOQueryTemp);
  EndDate.Date := BegDate.Date;
end;

procedure TfrmHZViewList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmHZViewList.NHBiaoNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmHZViewList.ToolButton1Click(Sender: TObject);
begin
  //if ADOQueryMain.IsEmpty then Exit;
 // SelExportData(Tv2,ADOQueryMain,'能耗列表');
end;

procedure TfrmHZViewList.ChejianChange(Sender: TObject);
begin
  if CDS_NH.Active = True then
    SDofilter10(CDS_NH, SGetFilters(Panel1, 1, 2));
  if CDS_JWL.Active = True then
    SDofilter10(CDS_JWL, SGetFilters(Panel1, 1, 2));
  if CDS_RHL.Active = True then
    SDofilter10(CDS_RHL, SGetFilters(Panel1, 1, 2));
end;

procedure TfrmHZViewList.ToolButton2Click(Sender: TObject);
begin
  if CDS_NH.Active = True then
    SDofilter10(CDS_NH, SGetFilters(Panel1, 1, 2));
  if CDS_JWL.Active = True then
    SDofilter10(CDS_JWL, SGetFilters(Panel1, 1, 2));
  if CDS_RHL.Active = True then
    SDofilter10(CDS_RHL, SGetFilters(Panel1, 1, 2));
end;

procedure TfrmHZViewList.ToolButton5Click(Sender: TObject);
begin
  dxComponentPrinter1.Preview(False, nil);
  dxComponentPrinter1.ReportLink[0].Preview;
end;

end.

