unit U_CKProductBSCRCList;

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, cxButtonEdit,
  cxTextEdit, cxTimeEdit, cxCalendar;

type
  TfrmCKProductBSCRCList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label3: TLabel;
    MPRTCodeName: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    Label5: TLabel;
    orderNo: TEdit;
    Label6: TLabel;
    MJID: TEdit;
    Label8: TLabel;
    MPRTKZ: TEdit;
    Label9: TLabel;
    MPRTMF: TEdit;
    MovePanel2: TMovePanel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    CustomerNoName: TEdit;
    MPRTCode: TEdit;
    cxGrid2: TcxGrid;
    TV1: TcxGridDBBandedTableView;
    V1Column1: TcxGridDBBandedColumn;
    V1Column2: TcxGridDBBandedColumn;
    V1Column3: TcxGridDBBandedColumn;
    V1Column5: TcxGridDBBandedColumn;
    V1Column7: TcxGridDBBandedColumn;
    V1Column8: TcxGridDBBandedColumn;
    V1Column9: TcxGridDBBandedColumn;
    cxGridLevel1: TcxGridLevel;
    V1Column27: TcxGridDBBandedColumn;
    V1Column30: TcxGridDBBandedColumn;
    V1Column31: TcxGridDBBandedColumn;
    V1Column34: TcxGridDBBandedColumn;
    V1Column35: TcxGridDBBandedColumn;
    V1Column36: TcxGridDBBandedColumn;
    V1Column37: TcxGridDBBandedColumn;
    V1Column19: TcxGridDBBandedColumn;
    V1Column41: TcxGridDBBandedColumn;
    V1Column43: TcxGridDBBandedColumn;
    V1Column44: TcxGridDBBandedColumn;
    V1Column45: TcxGridDBBandedColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure MPRTCodeNameChange(Sender: TObject);
    procedure PRTColorChange(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmCKProductBSCRCList: TfrmCKProductBSCRCList;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp;

{$R *.dfm}

procedure TfrmCKProductBSCRCList.FormDestroy(Sender: TObject);
begin
  frmCKProductBSCRCList:=nil;
end;

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

procedure TfrmCKProductBSCRCList.FormCreate(Sender: TObject);
begin
  BegDate.DateTime:=SGetServerDateTime(ADOQueryTemp)-30;
  EndDate.DateTime:=SGetServerDateTime(ADOQueryTemp)
end;

procedure TfrmCKProductBSCRCList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('exec P_CPCRC_List '+quotedstr(Trim(FormatDateTime('yyyy-MM-dd',begdate.DateTime)))
                +','+quotedstr(Trim(FormatDateTime('yyyy-MM-dd',EndDate.DateTime))));
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmCKProductBSCRCList.TBRafreshClick(Sender: TObject);
begin
  MovePanel2.Visible:=True;
  MovePanel2.Refresh;
  InitGrid();
  MovePanel2.Visible:=False;
end;

procedure TfrmCKProductBSCRCList.ConNoMChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  end;
end;

procedure TfrmCKProductBSCRCList.TBCloseClick(Sender: TObject);
begin
  WriteCxBandedGrid(self.Caption+tv1.Name,Tv1,'成品仓库');
  Close;
end;

procedure TfrmCKProductBSCRCList.FormShow(Sender: TObject);
begin
ReadCxBandedGrid(self.Caption+tv1.Name,Tv1,'成品仓库');
end;

procedure TfrmCKProductBSCRCList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then exit;
  TcxGridToExcel('库存汇总列表',cxGrid2);
end;

procedure TfrmCKProductBSCRCList.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 TfrmCKProductBSCRCList.MPRTCodeNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmCKProductBSCRCList.PRTColorChange(Sender: TObject);
begin
  TBFind.Click;
end;

end.
