unit U_CKProductBCPOutHZ_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, RM_Common, RM_Class,
  RM_e_Xls, RM_Dataset, RM_System, RM_GridReport, cxCheckBox, Menus,
  MovePanel;

type
  TfrmCKProductBCPOutHZ_List = 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;
    Label4: TLabel;
    C_CodeName: TEdit;
    C_Color: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    Tv1: TcxGridDBTableView;
    cxGrid2Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    Label5: TLabel;
    orderNo: TEdit;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    Label8: TLabel;
    MPRTKZ: TEdit;
    Label9: TLabel;
    MPRTMF: TEdit;
    CDS_PRT: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    RMDB_Sub: TRMDBDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    MovePanel2: TMovePanel;
    CDS_CX: TClientDataSet;
    v1CRTYPE: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1customerNoname: TcxGridDBColumn;
    ADOPrint: TADOQuery;
    RMDB_MD: TRMDBDataSet;
    RMGridReport1: TRMGridReport;
    customerNoname: TEdit;
    Label11: TLabel;
    Label13: TLabel;
    CheckBox1: TCheckBox;
    ADOPrint1: TADOQuery;
    RMXLSExport2: TRMXLSExport;
    v1Column18: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    SYRName: TEdit;
    Label6: TLabel;
    CRTYPE: TComboBox;
    Label12: TLabel;
    v1Column4: TcxGridDBColumn;
    defstr1: TEdit;
    Label7: TLabel;
    ToolButton1: TToolButton;
    BCKZ1: TEdit;
    Label10: 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 PRTCodeNameChange(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);

  private
    TblCprk :string;
    procedure InitGrid();
    { Private declarations }
  public
    fckname:string;
    { Public declarations }
  end;

var
  frmCKProductBCPOutHZ_List: TfrmCKProductBCPOutHZ_List;

implementation
uses
  U_DataLink,U_Fun,U_CKProductBCPOutList;

{$R *.dfm}


procedure TfrmCKProductBCPOutHZ_List.FormDestroy(Sender: TObject);
begin
  frmCKProductBCPOutHZ_List:=nil;
end;

procedure TfrmCKProductBCPOutHZ_List.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin

  Action:=caFree;
end;

procedure TfrmCKProductBCPOutHZ_List.FormCreate(Sender: TObject);
begin
  cxGrid2.Align:=alClient;

  BegDate.DateTime:=SGetServerDateTime(ADOQueryTemp);
  EndDate.DateTime:=SGetServerDateTime(ADOQueryTemp)
  
end;

procedure TfrmCKProductBCPOutHZ_List.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      Filtered:=False;
      SQL.Add('select A.SYRName,A.CRTime,A.CRType,A.C_CodeName,A.C_Color,A.BCFK,A.BCKZ,A.QtyUnit,A.defstr1,B.customerNOName,B.OrderNo,');
      sql.Add('sum(RollNum) as RollNum,sum(Qty) as Qty,cast(A.bckz as varchar) as bckz1, ');
      sql.Add('C_CodeNameZw=(select MAX(defnote3) from KH_Zdy_Attachment X where X.ZdyName=A.C_CodeName) ');
      sql.add('from CK_BanCP_CR A ');
      Sql.add('LEFT join JYOrder_Main B on A.MainId=B.MainId');
      sql.add('where A.CRTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+''' ');
      sql.add('and  A.CRTime<'''+Trim(FormatDateTime('yyyy-MM-dd',enddate.DateTime+1))+''' ');
      SQL.Add('and CRflag  =''出库'' ');
      IF trim(fCKName)<>'' then
      sql.Add('and A.CKName='''+trim(fckName)+''' ');
      sql.Add('group by A.SYRName,A.CRTime,A.CRType,A.C_CodeName,A.C_Color,A.BCFK,A.BCKZ,A.QtyUnit,A.defstr1,B.customerNOName,B.OrderNo' );
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);

  finally
    ADOQueryMain.EnableControls;
  end;
  tbfind.Click;
end;

procedure TfrmCKProductBCPOutHZ_List.TBRafreshClick(Sender: TObject);
begin
  BegDate.SetFocus;
  InitGrid();
end;

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

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

procedure TfrmCKProductBCPOutHZ_List.FormShow(Sender: TObject);
begin
  ReadCxGrid(self.Caption,Tv1,'成品仓库');
  InitGrid();
end;

procedure TfrmCKProductBCPOutHZ_List.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then exit;
  SelExportData(Tv1,ADOQueryMain,'');
end;

procedure TfrmCKProductBCPOutHZ_List.TBFindClick(Sender: TObject);
var
  strwhere:string;
begin
  if ADOQueryMain.Active then
  begin
    strwhere:=SGetFilters(Panel1,1,2);
    SDofilter(ADOQueryMain,strwhere);
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmCKProductBCPOutHZ_List.PRTCodeNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmCKProductBCPOutHZ_List.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main,True);
end;

procedure TfrmCKProductBCPOutHZ_List.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main,False);
end;

procedure TfrmCKProductBCPOutHZ_List.CheckBox1Click(Sender: TObject);
begin
  IF  CDS_Main.IsEmpty then exit;
  with CDS_Main do
  begin
    DisableControls;
    first;
    while not eof do
    begin
      edit;
      fieldbyname('ssel').Value:=checkbox1.Checked;
      post;
      next;
    end;
    First;
    EnableControls;
  end;

end;

procedure TfrmCKProductBCPOutHZ_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('customerNoname').asstring;
    CRType.ItemIndex:=CRType.Items.IndexOf(trim(self.cds_main.fieldbyname('customerNoname').asstring));
    TBOtCk.Visible:=false;
//    TBPrint.Visible:=false;
//    TBPrint1.Visible:=false;
    tbpackNo.Visible:=false;
    ToolButton1.Visible:=false;
    TbNote.Visible:=false;
    show;
  end;
end;

end.
