unit U_KH_XS_list;

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;

type
  TfrmKH_XS_list = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label3: TLabel;
    Label4: TLabel;
    factoryName: TEdit;
    C_Color: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    Tv1: TcxGridDBTableView;
    cxGrid2Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    Label5: TLabel;
    conNO: TEdit;
    Label6: TLabel;
    MJID: TEdit;
    Label8: TLabel;
    KZ: TEdit;
    Label9: TLabel;
    MF: TEdit;
    Label7: TLabel;
    CPType: TComboBox;
    MovePanel2: TMovePanel;
    Label10: TLabel;
    Edit1: TEdit;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    cxStyle_gridRow: TcxStyle;
    cxStyle_gridFoot: TcxStyle;
    cxStyle_gridHead: TcxStyle;
    cxStyle_gridGroupBox: TcxStyle;
    cxStyle_yellow: TcxStyle;
    cxStyle_Red: TcxStyle;
    cxStyle_fontBlack: TcxStyle;
    cxStyle_fontclFuchsia: TcxStyle;
    cxStyle_fontclPurple: TcxStyle;
    cxStyle_fontclGreen: TcxStyle;
    cxStyle_fontclBlue: TcxStyle;
    cxStyle_fontclTeal: TcxStyle;
    cxStyle_fontclOlive: TcxStyle;
    v1Column11: TcxGridDBColumn;
    SYRName: TEdit;
    Label11: TLabel;
    ToolButton1: TToolButton;
    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 factoryNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
  private
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmKH_XS_list: TfrmKH_XS_list;

implementation
uses
  U_DataLink,U_Fun,U_CKProductBCPOutList;

{$R *.dfm}

procedure TfrmKH_XS_list.FormDestroy(Sender: TObject);
begin
  frmKH_XS_list:=nil;
end;

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

procedure TfrmKH_XS_list.FormCreate(Sender: TObject);
begin
  //cxGrid1.Align:=alClient;
  BegDate.DateTime:=SGetServerDateTime(ADOQueryTemp);
  EndDate.DateTime:=SGetServerDateTime(ADOQueryTemp);
//  begdate.DateTime:=strtodateTime(formatdateTime('yyyy-MM',EndDate.DateTime)+'-01');
end;

procedure TfrmKH_XS_list.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' exec P_Get_KH_XS ');
      sql.Add(' @begdate='''+formatdatetime('yyyy-MM-dd',begdate.DateTime)+''' ');
      sql.Add(',@enddate='''+formatdatetime('yyyy-MM-dd',enddate.DateTime+1)+''' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
    TBFind.Click;
  end;
end;

procedure TfrmKH_XS_list.TBRafreshClick(Sender: TObject);
begin
  //BegDate.SetFocus;
  MovePanel2.Visible:=True;
  MovePanel2.Refresh;
  InitGrid();
  MovePanel2.Visible:=False;
end;

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

procedure TfrmKH_XS_list.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(self.Caption+tv1.Name,Tv1,'³ÉÆ·²Ö¿â');
  Close;
end;

procedure TfrmKH_XS_list.FormShow(Sender: TObject);
begin

  ReadCxGrid(self.Caption+tv1.Name,Tv1,'³ÉÆ·²Ö¿â');
  
  InitGrid();
end;

procedure TfrmKH_XS_list.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then exit;
  TcxGridToExcel(self.Caption,cxGrid2);
end;

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

procedure TfrmKH_XS_list.ToolButton1Click(Sender: TObject);
begin
  frmCKProductBCPOutList:=TfrmCKProductBCPOutList.create(self);
  with frmCKProductBCPOutList do
  begin
    begdate.Date:=self.BegDate.Date;
    enddate.Date:=self.EndDate.date;
    SYRName.Text:=self.cds_main.fieldbyname('SYRName').asstring;
    customerNoName.text:=self.cds_main.fieldbyname('factoryName').asstring;
    TBOtCk.Visible:=false;
  //  TBPrint.Visible:=false;
 //   TBPrint1.Visible:=false;
    tbpackNo.Visible:=false;
    ToolButton1.Visible:=false;
    TbNote.Visible:=false;
    show;
  end;
end;

procedure TfrmKH_XS_list.Tv1CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  ToolButton1.Click;
end;

end.
