unit U_ShaWDHMXList;

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, cxCheckBox, RM_Common, RM_Class, RM_e_Xls, RM_Dataset,
  RM_System, RM_GridReport, Menus, cxCalendar, cxButtonEdit, cxTextEdit,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmShaWDHMXList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column14: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    v1Column10: TcxGridDBColumn;
    Panel1: TPanel;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    v1Column9: TcxGridDBColumn;
    ToolButton1: TToolButton;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    FactoryName1,Y_CodeName1,Y_Spec1,BatchNo1:string;
    { Public declarations }
  end;

var
  frmShaWDHMXList: TfrmShaWDHMXList;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmShaWDHMXList.FormDestroy(Sender: TObject);
begin
  //frmShaWDHMXList := nil;
end;

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

procedure TfrmShaWDHMXList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('exec P_View_SXYLDH_MX :begdate,:enddate,:FactoryName1,:Y_CodeName1,:Y_Spec1,:BatchNo1   ');
      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('FactoryName1').Value:=FactoryName1;
      Parameters.ParamByName('Y_CodeName1').Value:=Y_CodeName1;
      Parameters.ParamByName('Y_Spec1').Value:=Y_Spec1;
      Parameters.ParamByName('BatchNo1').Value:=BatchNo1;
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;

end;

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

procedure TfrmShaWDHMXList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('原料流水', Tv1, '原料仓库');
  Close;
end;

procedure TfrmShaWDHMXList.FormShow(Sender: TObject);
begin
  ReadCxGrid('原料流水', Tv1, '原料仓库');
  InitGrid();
end;

procedure TfrmShaWDHMXList.ToolButton1Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  TcxGridToExcel('原料计划到货明细',cxGrid2);
end;

end.

