unit U_THRK_CP_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
  TfrmTHRK_CP_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;
    BCKZ1: 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;
    v1Column5: TcxGridDBColumn;
    v1Column6: 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;
    C_CodeName: TEdit;
    Label11: TLabel;
    ToolButton1: TToolButton;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    SYRName: TEdit;
    Label12: TLabel;
    THcust: TEdit;
    Label13: TLabel;
    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 BCKZ1Change(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Tv1DblClick(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
  frmTHRK_CP_list: TfrmTHRK_CP_list;

implementation
uses
  U_DataLink,U_Fun,U_CKProductBCPInList;

{$R *.dfm}

procedure TfrmTHRK_CP_list.FormDestroy(Sender: TObject);
begin
  frmTHRK_CP_list:=nil;
end;

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

procedure TfrmTHRK_CP_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 TfrmTHRK_CP_list.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.SYRName,A.THcust,A.C_CodeName,A.C_Color,A.BCKZ,cast(A.BCKZ as varchar) as BCKZ1,count(MJID) as  T_RollNum,sum(Qty) as T_Qty');
      sql.Add(' from CK_BanCP_CR A');
      sql.Add(' where A.CRTime>='''+formatdatetime('yyyy-MM-dd',begdate.DateTime)+''' ');
      sql.Add(' and A.CRTime<'''+formatdatetime('yyyy-MM-dd',enddate.DateTime+1)+''' ');
      sql.Add(' and A.CRType=''退货入库'' ');
      sql.Add(' group by A.SYRName,A.THcust,A.C_CodeName,A.C_Color,A.BCKZ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
    TBFind.Click;
  end;
end;

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

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

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

procedure TfrmTHRK_CP_list.FormShow(Sender: TObject);
begin

  ReadCxGrid(self.Caption+tv1.Name,Tv1,'成品仓库');
  
  InitGrid();
end;

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

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

procedure TfrmTHRK_CP_list.ToolButton1Click(Sender: TObject);
begin
  IF CDS_Main.IsEmpty then exit;
  frmCKProductBCPInList:=TfrmCKProductBCPInList.create(self);
  with frmCKProductBCPInList do
  begin
    begdate.Date:=self.BegDate.Date;
    enddate.Date:=self.EndDate.date;
    CRType.ItemIndex:=CRType.Items.IndexOf('退货入库');
    C_CodeName.Text:=self.cds_main.fieldbyname('C_CodeName').asstring;
    BCKZ1.text:=self.cds_main.fieldbyname('BCKZ1').asstring;
    ToolButton1.Visible:=false;
    TBAdd.Visible:=false;
    TBedit.Visible:=false;
    TBprint.Visible:=false;
    TBprint1.Visible:=false;
  //  TBprint2.Visible:=false;
    ToolButton3.Visible:=false;
    ToolButton4.Visible:=false;
    ToolButton5.Visible:=false;
    show;
  end;
end;

procedure TfrmTHRK_CP_list.Tv1DblClick(Sender: TObject);
begin
  ToolButton1.Click;
end;

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

end.
