unit U_DCTimeZhou;

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, cxDBLookupComboBox, cxContainer, cxDropDownEdit, cxPC, Menus,
  TeEngine, Series, TeeProcs, Chart, DbChart, GanttCh, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator;

type
  TfrmDCTimeZhou = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    cxGridPopupMenu2: TcxGridPopupMenu;
    Panel2: TPanel;
    Panel3: TPanel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v2Column12: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    SH1: TPanel;
    ClientDataSet1: TClientDataSet;
    DataSource1: TDataSource;
    v1Column1: TcxGridDBColumn;
    DataSource3: TDataSource;
    ClientDataSet3: TClientDataSet;
    Panel1: TPanel;
    Label5: TLabel;
    Label6: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Panel10: TPanel;
    ToolButton1: TToolButton;
    ComboBox1: TComboBox;
    v1Column4: TcxGridDBColumn;
    Panel4: TPanel;
    Panel5: TPanel;
    Panel6: TPanel;
    Panel7: TPanel;
    DataSource2: TDataSource;
    ClientDataSet2: TClientDataSet;
    cxGridPopupMenu1: TcxGridPopupMenu;
    cxGridPopupMenu3: TcxGridPopupMenu;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    Panel8: TPanel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    cxGrid5: TcxGrid;
    Tv5: TcxGridDBTableView;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridDBColumn18: TcxGridDBColumn;
    cxGridDBColumn19: TcxGridDBColumn;
    cxGridDBColumn20: TcxGridDBColumn;
    cxGridDBColumn21: TcxGridDBColumn;
    cxGridLevel4: TcxGridLevel;
    cxGridPopupMenu5: TcxGridPopupMenu;
    DataSource5: TDataSource;
    ClientDataSet5: TClientDataSet;
    Tv1Column4: TcxGridDBColumn;
    Tv3Column1: TcxGridDBColumn;
    Tv5Column1: TcxGridDBColumn;
    Tv2Column1: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv3Column2: TcxGridDBColumn;
    Tv3Column3: TcxGridDBColumn;
    Tv3Column4: TcxGridDBColumn;
    Tv3Column5: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure C_CodeNameChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure Tv3DblClick(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure Tv5DblClick(Sender: TObject);
    procedure Tv2DblClick(Sender: TObject);
    procedure Tv1Column3CustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    procedure cxGridDBColumn10CustomDrawCell(
      Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
      AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
  private

    { Private declarations }
    procedure InitGrid();
  public
  end;

var
  frmDCTimeZhou: TfrmDCTimeZhou;

implementation

uses
  U_DataLink, U_RTFun,U_DCCarMX,U_DCWorkerMX,U_DCJSDateMX,U_DCC_CodeNameMX, U_DJCPTopMX, U_ZJCPTopMX, U_DJGGZPMORDMX, U_DDDJJHMX;

{$R *.dfm}

procedure TfrmDCTimeZhou.InitGrid();
begin
  Panel10.Visible := True;
  Panel10.Refresh;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('exec P_BI_DC_CarNo :begdate,:enddate');
      Parameters.ParamByName('begdate').Value := Trim(FormatDateTime('yyyy-MM-dd', BegDate.Date));
      Parameters.ParamByName('enddate').Value := Trim(FormatDateTime('yyyy-MM-dd', enddate.Date + 1));
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet1);
    SInitCDSData20(ADOQueryMain, ClientDataSet1);

    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('exec P_BI_DC_Worker :begdate,:enddate');
      Parameters.ParamByName('begdate').Value := Trim(FormatDateTime('yyyy-MM-dd', BegDate.Date));
      Parameters.ParamByName('enddate').Value := Trim(FormatDateTime('yyyy-MM-dd', enddate.Date + 1));
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet3);
    SInitCDSData20(ADOQueryMain, ClientDataSet3);

    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('exec P_BI_DC_C_CodeName :begdate,:enddate');
      Parameters.ParamByName('begdate').Value := Trim(FormatDateTime('yyyy-MM-dd', BegDate.Date));
      Parameters.ParamByName('enddate').Value := Trim(FormatDateTime('yyyy-MM-dd', enddate.Date + 1));
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet2);
    SInitCDSData20(ADOQueryMain, ClientDataSet2);

    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('exec P_BI_DC_JSDate :begdate,:enddate');
      Parameters.ParamByName('begdate').Value := Trim(FormatDateTime('yyyy-MM-dd', BegDate.Date));
      Parameters.ParamByName('enddate').Value := Trim(FormatDateTime('yyyy-MM-dd', enddate.Date + 1));
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet5);
    SInitCDSData20(ADOQueryMain, ClientDataSet5);





  finally
    ADOQueryMain.EnableControls;
  end;
  Panel10.Visible := False;
end;

procedure TfrmDCTimeZhou.FormDestroy(Sender: TObject);
begin
  frmDCTimeZhou := nil;
end;

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

procedure TfrmDCTimeZhou.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('11', Tv1, 'P圆机产量查询');
  WriteCxGrid('21', Tv2, 'P圆机产量查询');
  WriteCxGrid('31', Tv3, 'P圆机产量查询');
  WriteCxGrid('51', Tv5, 'P圆机产量查询');
  Close;
end;

procedure TfrmDCTimeZhou.FormShow(Sender: TObject);
begin
  ReadCxGrid('11', Tv1, 'P圆机产量查询');
  ReadCxGrid('21', Tv2, 'P圆机产量查询');
  ReadCxGrid('31', Tv3, 'P圆机产量查询');
  ReadCxGrid('51', Tv5, 'P圆机产量查询');
end;

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

procedure TfrmDCTimeZhou.ToolButton2Click(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, ClientDataSet1);
    SInitCDSData20(ADOQueryMain, ClientDataSet1);
  end;
end;

procedure TfrmDCTimeZhou.C_CodeNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmDCTimeZhou.FormCreate(Sender: TObject);
var
  FYear: string;
  FMonth: string;
  FDate: TDate;
begin
 { FDate:=SGetServerDate10(ADOQueryTemp);
  FYear:=FormatDateTime('yyyy',FDate);
  FMonth:=FormatDateTime('MM',FDate);
  if StrToInt(FMonth)<2 then
  begin
    BegDate.Date:=StrToDate(IntToStr(strtoint(FYear)-1)+'-02-01');
    EndDate.Date:=StrToDate(FYear+'-01-31');
  end else
  begin
    BegDate.Date:=StrToDate(FYear+'-02-01');
    EndDate.Date:=StrToDate(IntToStr(strtoint(FYear)+1)+'-01-31');

  end;}
  BegDate.Date := SGetServerDateMBeg(ADOQueryTemp);
  EndDate.Date := SGetServerDate(ADOQueryTemp);
end;

procedure TfrmDCTimeZhou.ToolButton1Click(Sender: TObject);
begin
  if ComboBox1.Text = '' then
    Exit;
  if ComboBox1.ItemIndex = 0 then
  begin
    TcxGridToExcel(ComboBox1.Text, cxGrid1);
  end
  else if ComboBox1.ItemIndex = 1 then
  begin
    TcxGridToExcel(ComboBox1.Text, cxGrid3);
  end
  else if ComboBox1.ItemIndex = 2 then
  begin
    TcxGridToExcel(ComboBox1.Text, cxGrid2);
  end
  else if ComboBox1.ItemIndex = 3 then
  begin
    TcxGridToExcel(ComboBox1.Text, cxGrid5);
  end;
end;

procedure TfrmDCTimeZhou.Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  {Panel10.Visible := True;
  Panel10.Refresh;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('exec P_BI_DCMoneyAll_MX_PM :begdate,:enddate,:KHName');
      Parameters.ParamByName('begdate').Value := Trim(FormatDateTime('yyyy-MM-dd', BegDate.Date));
      Parameters.ParamByName('enddate').Value := Trim(FormatDateTime('yyyy-MM-dd', enddate.Date + 1));
      Parameters.ParamByName('KHName').Value := Trim(ClientDataSet1.fieldbyname('KHName').AsString);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet3);
    SInitCDSData20(ADOQueryMain, ClientDataSet3);

    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('exec P_BI_DCMoneyAll_MX_RQ :begdate,:enddate,:KHName');
      Parameters.ParamByName('begdate').Value := Trim(FormatDateTime('yyyy-MM-dd', BegDate.Date));
      Parameters.ParamByName('enddate').Value := Trim(FormatDateTime('yyyy-MM-dd', enddate.Date + 1));
      Parameters.ParamByName('KHName').Value := Trim(ClientDataSet1.fieldbyname('KHName').AsString);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet2);
    SInitCDSData20(ADOQueryMain, ClientDataSet2);

  finally
    ADOQueryMain.EnableControls;
  end;
  Panel10.Visible := False;}
end;

procedure TfrmDCTimeZhou.Tv3DblClick(Sender: TObject);
begin
  try
    frmDCWorkerMX := TfrmDCWorkerMX.Create(Application);
    with frmDCWorkerMX do
    begin
      FBegdate := Self.BegDate.Date;
      FEnddate := Self.enddate.Date + 1;
      FWorker := Trim(Self.ClientDataSet3.fieldbyname('Worker').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmDCWorkerMX.Free;
  end;
end;

procedure TfrmDCTimeZhou.Tv1DblClick(Sender: TObject);
begin
  try
    frmDCCarMX := TfrmDCCarMX.Create(Application);
    with frmDCCarMX do
    begin
      FBegdate := Self.BegDate.Date;
      FEnddate := Self.enddate.Date + 1;
      FCarNo := Trim(Self.ClientDataSet1.fieldbyname('CarNo').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmDCCarMX.Free;
  end;
end;

procedure TfrmDCTimeZhou.Tv5DblClick(Sender: TObject);
begin
  try
    frmDCJSDateMX := TfrmDCJSDateMX.Create(Application);
    with frmDCJSDateMX do
    begin
      FJSdate :=Self.ClientDataSet5.fieldbyname('JSDate').AsDateTime;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmDCJSDateMX.Free;
  end;
end;

procedure TfrmDCTimeZhou.Tv2DblClick(Sender: TObject);
begin
  try
    frmDCC_CodeNameMX := TfrmDCC_CodeNameMX.Create(Application);
    with frmDCC_CodeNameMX do
    begin
      FBegdate := Self.BegDate.Date;
      FEnddate := Self.enddate.Date + 1;
      FC_CodeName := Trim(Self.ClientDataSet2.fieldbyname('C_CodeName').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmDCC_CodeNameMX.Free;
  end;
end;

procedure TfrmDCTimeZhou.Tv1Column3CustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  Id0,Id1,Id11,Id21:Integer;
begin
  Id0:=TV1.GetColumnByFieldName('Qty0').Index;
  if AViewInfo.GridRecord.Values[Id0]>15000 then
  begin
    ACanvas.Brush.Color:=clRed;
  end;
  Id1:=TV1.GetColumnByFieldName('Qty1').Index;
  if AViewInfo.GridRecord.Values[Id0]>22500 then
  begin
    ACanvas.Brush.Color:=clRed;
  end;
  Id11:=TV1.GetColumnByFieldName('Qty11').Index;
  if AViewInfo.GridRecord.Values[Id11]>22500 then
  begin
    ACanvas.Brush.Color:=clRed;
  end;
  Id21:=TV1.GetColumnByFieldName('Qty21').Index;
  if AViewInfo.GridRecord.Values[Id21]>22500 then
  begin
    ACanvas.Brush.Color:=clRed;
  end;

end;

procedure TfrmDCTimeZhou.cxGridDBColumn10CustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  Id0,Id1,Id11,Id21:Integer;
begin
  Id0:=TV1.GetColumnByFieldName('Qty0').Index;
  if AViewInfo.GridRecord.Values[Id0]>15000 then
  begin
    ACanvas.Brush.Color:=clRed;
  end;
  Id1:=TV1.GetColumnByFieldName('Qty1').Index;
  if AViewInfo.GridRecord.Values[Id0]>22500 then
  begin
    ACanvas.Brush.Color:=clRed;
  end;
  Id11:=TV1.GetColumnByFieldName('Qty11').Index;
  if AViewInfo.GridRecord.Values[Id11]>22500 then
  begin
    ACanvas.Brush.Color:=clRed;
  end;
  Id21:=TV1.GetColumnByFieldName('Qty21').Index;
  if AViewInfo.GridRecord.Values[Id21]>22500 then
  begin
    ACanvas.Brush.Color:=clRed;
  end;

end;

end.

