unit U_GZHJList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridCustomTableView, cxGridTableView,
  cxGridBandedTableView, cxGridDBBandedTableView, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridDBTableView, cxGrid, StdCtrls, ComCtrls,
  ExtCtrls, ToolWin, cxGridCustomPopupMenu, cxGridPopupMenu, ADODB, DBClient,
  cxDropDownEdit, MovePanel, Menus, cxCheckBox, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, RM_e_Xls, cxPC, cxCalendar, cxButtonEdit, cxTextEdit;

type
  TfrmGZHJList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    Label1: TLabel;
    DCGName: TEdit;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    MovePanel2: TMovePanel;
    cxGridPopupMenu2: TcxGridPopupMenu;
    cxPageControl1: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBBandedTableView;
    v1Column1: TcxGridDBBandedColumn;
    v1Column3: TcxGridDBBandedColumn;
    v1Column7: TcxGridDBBandedColumn;
    v1Column11: TcxGridDBBandedColumn;
    v1Column15: TcxGridDBBandedColumn;
    v1Column19: TcxGridDBBandedColumn;
    v1Column23: TcxGridDBBandedColumn;
    v1Column24: TcxGridDBBandedColumn;
    v1Column27: TcxGridDBBandedColumn;
    v1Column30: TcxGridDBBandedColumn;
    v1Column31: TcxGridDBBandedColumn;
    v1Column32: TcxGridDBBandedColumn;
    v1Column33: TcxGridDBBandedColumn;
    v1Column34: TcxGridDBBandedColumn;
    v1Column35: TcxGridDBBandedColumn;
    v1Column36: TcxGridDBBandedColumn;
    v1Column37: TcxGridDBBandedColumn;
    v1Column38: TcxGridDBBandedColumn;
    v1Column39: TcxGridDBBandedColumn;
    v1Column40: TcxGridDBBandedColumn;
    v1Column41: TcxGridDBBandedColumn;
    v1Column42: TcxGridDBBandedColumn;
    v1Column43: TcxGridDBBandedColumn;
    v1Column44: TcxGridDBBandedColumn;
    v1Column45: TcxGridDBBandedColumn;
    v1Column46: TcxGridDBBandedColumn;
    v1Column47: TcxGridDBBandedColumn;
    v1Column48: TcxGridDBBandedColumn;
    v1Column49: TcxGridDBBandedColumn;
    v1Column50: TcxGridDBBandedColumn;
    v1Column51: TcxGridDBBandedColumn;
    v1Column52: TcxGridDBBandedColumn;
    v1Column53: TcxGridDBBandedColumn;
    v1Column2: TcxGridDBBandedColumn;
    v1Column4: TcxGridDBBandedColumn;
    v1Column5: TcxGridDBBandedColumn;
    v1Column6: TcxGridDBBandedColumn;
    v1Column8: TcxGridDBBandedColumn;
    v1Column9: TcxGridDBBandedColumn;
    v1Column10: TcxGridDBBandedColumn;
    v1Column12: TcxGridDBBandedColumn;
    v1Column13: TcxGridDBBandedColumn;
    v1Column14: TcxGridDBBandedColumn;
    v1Column16: TcxGridDBBandedColumn;
    v1Column17: TcxGridDBBandedColumn;
    v1Column18: TcxGridDBBandedColumn;
    v1Column20: TcxGridDBBandedColumn;
    v1Column21: TcxGridDBBandedColumn;
    v1Column22: TcxGridDBBandedColumn;
    v1Column25: TcxGridDBBandedColumn;
    v1Column26: TcxGridDBBandedColumn;
    v1Column28: TcxGridDBBandedColumn;
    v1Column29: TcxGridDBBandedColumn;
    v1Column54: TcxGridDBBandedColumn;
    v1Column55: TcxGridDBBandedColumn;
    v1Column56: TcxGridDBBandedColumn;
    v1Column57: TcxGridDBBandedColumn;
    v1Column58: TcxGridDBBandedColumn;
    v1Column59: TcxGridDBBandedColumn;
    v1Column60: TcxGridDBBandedColumn;
    v1Column61: TcxGridDBBandedColumn;
    v1Column62: TcxGridDBBandedColumn;
    v1Column63: TcxGridDBBandedColumn;
    v1Column64: TcxGridDBBandedColumn;
    v1Column65: TcxGridDBBandedColumn;
    cxGrid1Level1: TcxGridLevel;
    cxTabSheet2: TcxTabSheet;
    ToolButton1: TToolButton;
    RMDB_Main: TRMDBDataSet;
    RM1: TRMGridReport;
    RMXLSExport1: TRMXLSExport;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    ADOPrint: TADOQuery;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2Column3: TcxGridDBColumn;
    v2Column19: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    v2Column17: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure DCGNameChange(Sender: TObject);
    procedure cxPageControl1Change(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
  private
    FLeft, FTop: Integer;
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
    FMainid, FSubId, FConNo, FColor, FCodeName: string;
  end;

var
  frmGZHJList: TfrmGZHJList;

implementation

uses
  U_DataLink, U_Fun;

{$R *.dfm}

procedure TfrmGZHJList.FormDestroy(Sender: TObject);
begin
  frmGZHJList := nil;
end;

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

procedure TfrmGZHJList.InitGrid();
begin
  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;

      if cxPageControl1.ActivePageIndex = 0 then
      begin
        SQL.Add('exec P_View_DAY_GZCL' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', Begdate.DateTime))));
      end
      else
      begin
        SQL.Add('select GZDate,DName,sum(GZMoney) GZMoney,sum(ZhongZS) ZhongZS, CarNo ');
        SQL.Add('from DCGMoney where GZDate= ' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', Begdate.DateTime))));
        SQL.Add('group by GZDate,GZDate,DName,CarNo ');
        SQL.Add('order by DName  ,cast(CarNo as int)  ');

      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
  MovePanel2.Visible := False;
end;

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

procedure TfrmGZHJList.TBCloseClick(Sender: TObject);
begin
  WriteCxBandedGrid('Tv1', Tv1, '产品排行');
  WriteCxGrid('Tv2', Tv2, '产品排行');
  Close;
end;

procedure TfrmGZHJList.FormShow(Sender: TObject);
begin
  BegDate.Date := SGetServerDate(ADOQueryTemp);
  ReadCxBandedGrid('Tv1', Tv1, '产品排行');
  ReadCxGrid('Tv2', Tv2, '产品排行');
end;

procedure TfrmGZHJList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  end;
end;

procedure TfrmGZHJList.DCGNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmGZHJList.cxPageControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmGZHJList.ToolButton1Click(Sender: TObject);
var
  filepath: string;
begin
  if CDS_Main.IsEmpty then
    exit;
  with AdoPrint do
  begin
    close;
    sql.Clear;
    SQL.Add('select GZDate,DName,sum(GZMoney) GZMoney,sum(ZhongZS) ZhongZS, CarNo ');
    SQL.Add('from DCGMoney where GZDate= ' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', Begdate.DateTime))));
    SQL.Add('group by GZDate,GZDate,DName,CarNo ');
    SQL.Add('order by DName  ,cast(CarNo as int)  ');
    open;
  end;

  try
    filepath := ExtractFilePath(Application.ExeName) + 'report\每日机台产量表.rmf';
    if not FileExists(Pchar(filepath)) then
    begin
      application.MessageBox(pchar('文件[' + filepath + ']不存在！'), '提示信息', MB_IConError);
      exit;
    end;
    RM1.LoadFromFile(filepath);
    RM1.ShowReport;
  finally

  end;

end;

procedure TfrmGZHJList.ToolButton2Click(Sender: TObject);
var
  filepath: string;
begin
  if CDS_Main.IsEmpty then
    exit;
  with AdoPrint do
  begin
    close;
    sql.Clear;
    SQL.Add('exec P_View_DAY_GZCL' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', Begdate.DateTime))));
    open;
  end;

  try
    filepath := ExtractFilePath(Application.ExeName) + 'report\产量统计表.rmf';
    if not FileExists(Pchar(filepath)) then
    begin
      application.MessageBox(pchar('文件[' + filepath + ']不存在！'), '提示信息', MB_IConError);
      exit;
    end;
    RM1.LoadFromFile(filepath);
    RM1.ShowReport;
  finally

  end;

end;

procedure TfrmGZHJList.ToolButton3Click(Sender: TObject);
var
  filepath: string;
begin
  if CDS_Main.IsEmpty then
    exit;
  with AdoPrint do
  begin
    close;
    sql.Clear;
    SQL.Add('exec P_View_DAY_GZCL' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', Begdate.DateTime))));
    open;
  end;

  try

    filepath := ExtractFilePath(Application.ExeName) + 'report\机台统计表.rmf';

    if not FileExists(Pchar(filepath)) then
    begin
      application.MessageBox(pchar('文件[' + filepath + ']不存在！'), '提示信息', MB_IConError);
      exit;
    end;
    RM1.LoadFromFile(filepath);
    RM1.ShowReport;
  finally

  end;

end;

end.

