unit U_DCCarMX;

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
  TfrmDCCarMX = class(TForm)
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ClientDataSet1: TClientDataSet;
    DataSource1: TDataSource;
    Panel2: TPanel;
    Panel4: TPanel;
    Panel5: TPanel;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridDBColumn18: TcxGridDBColumn;
    cxGridDBColumn19: TcxGridDBColumn;
    cxGridDBColumn20: TcxGridDBColumn;
    cxGridDBColumn21: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    Panel6: TPanel;
    Panel7: TPanel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Panel8: TPanel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DataSource2: TDataSource;
    ClientDataSet2: TClientDataSet;
    cxGridPopupMenu3: TcxGridPopupMenu;
    DataSource3: TDataSource;
    ClientDataSet3: TClientDataSet;
    Tv1Column1: TcxGridDBColumn;
    Tv2Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure cxGridDBColumn10CustomDrawCell(
      Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
      AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
  private

    { Private declarations }
    procedure InitGrid();
  public
    FBegdate,FEnddate:TDate;
    FCarNo:String;
   
  end;

var
  frmDCCarMX: TfrmDCCarMX;

implementation

uses
  U_DataLink, U_RTFun,U_DCCarMX_Worker;

{$R *.dfm}


procedure TfrmDCCarMX.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('exec P_BI_DC_CarNo_MX :begdate,:enddate,:CarNo,:Type');
      Parameters.ParamByName('begdate').Value:=Trim(FormatDateTime('yyyy-MM-dd',FBegdate));
      Parameters.ParamByName('enddate').Value:=Trim(FormatDateTime('yyyy-MM-dd',FEnddate));;
      Parameters.ParamByName('CarNo').Value:=FCarNo;
      Parameters.ParamByName('Type').Value:='Worker';
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet1);
    SInitCDSData20(ADOQueryMain, ClientDataSet1);
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('exec P_BI_DC_CarNo_MX :begdate,:enddate,:CarNo,:Type');
      Parameters.ParamByName('begdate').Value:=Trim(FormatDateTime('yyyy-MM-dd',FBegdate));
      Parameters.ParamByName('enddate').Value:=Trim(FormatDateTime('yyyy-MM-dd',FEnddate));;
      Parameters.ParamByName('CarNo').Value:=FCarNo;
      Parameters.ParamByName('Type').Value:='C_CodeName';
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet2);
    SInitCDSData20(ADOQueryMain, ClientDataSet2);
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('exec P_BI_DC_CarNo_MX :begdate,:enddate,:CarNo,:Type');
      Parameters.ParamByName('begdate').Value:=Trim(FormatDateTime('yyyy-MM-dd',FBegdate));
      Parameters.ParamByName('enddate').Value:=Trim(FormatDateTime('yyyy-MM-dd',FEnddate));;
      Parameters.ParamByName('CarNo').Value:=FCarNo;
      Parameters.ParamByName('Type').Value:='JSDate';
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet3);
    SInitCDSData20(ADOQueryMain, ClientDataSet3);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmDCCarMX.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caHide;;
end;

procedure TfrmDCCarMX.FormShow(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmDCCarMX.FormDestroy(Sender: TObject);
begin
   frmDCCarMX:=nil;
end;

procedure TfrmDCCarMX.Tv1DblClick(Sender: TObject);
begin
  try
    frmDCCarMX_Worker := TfrmDCCarMX_Worker.Create(Application);
    with frmDCCarMX_Worker do
    begin
      FBegdate := Self.FBegdate;
      FEnddate := Self.FEnddate;
      FCarNo := Trim(Self.FCarNo);
      FWorker := Trim(Self.ClientDataSet1.fieldbyname('Worker').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmDCCarMX_Worker.Free;
  end;
end;

procedure TfrmDCCarMX.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.

