unit U_CKProductBCPOutListHZSEL;

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, RM_E_llPDF, cxCalendar, Math,
  Clipbrd, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmCKProductBCPOutListHZSEL = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    MPRTCodeName: TEdit;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    Tv1: TcxGridDBTableView;
    cxGrid2Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    v2Column1: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    Label5: TLabel;
    orderNo: TEdit;
    v1Column8: TcxGridDBColumn;
    RMXLSExport1: TRMXLSExport;
    Label10: TLabel;
    CkOrdNo: TEdit;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    MovePanel2: TMovePanel;
    DS_JuanPRT: TDataSource;
    cxGridPopupMenu2: TcxGridPopupMenu;
    v1Column15: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    KHCONNO: TEdit;
    Label15: TLabel;
    begtime: TDateTimePicker;
    endTime: TDateTimePicker;
    ADOQueryPrint: TADOQuery;
    RMDB_Main: TRMDBDataSet;
    RM3: TRMGridReport;
    v1Column24: TcxGridDBColumn;
    Label22: TLabel;
    CustomerNoName: TEdit;
    Label24: TLabel;
    v1Column13: TcxGridDBColumn;
    Label1: TLabel;
    CRType: TComboBox;
    v1Column6: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    CDS_Label: TClientDataSet;
    v1Column14: TcxGridDBColumn;
    Label9: TLabel;
    MPRTCode: TEdit;
    ADOQuery1: TADOQuery;
    RMDBHZ: TRMDBDataSet;
    CDS_HZ: TClientDataSet;
    CDS_PRT: TClientDataSet;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    ToolButton1: TToolButton;
    Tv1Column4: TcxGridDBColumn;
    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 N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure orderNoKeyPress(Sender: TObject; var Key: Char);
    procedure Tv1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure CPTypeChange(Sender: TObject);
    procedure CRTypeChange(Sender: TObject);
    procedure edtSMNOKeyPress(Sender: TObject; var Key: Char);
    procedure FormDestroy(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
  private
    FLeft, FTop: Integer;
    CurrentPage, RecordsNumber: Integer;
    procedure InitGrid();
  
    { Private declarations }
  public
    canshu1: string;
    { Public declarations }
  end;

var
  frmCKProductBCPOutListHZSEL: TfrmCKProductBCPOutListHZSEL;

implementation

uses
  U_DataLink, U_Fun;

{$R *.dfm}

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

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

procedure TfrmCKProductBCPOutListHZSEL.InitGrid();
var
  fwhere, Pwhere: string;
begin
  MovePanel2.Left := (self.Width - MovePanel2.Width) div 2;
  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  Pwhere := SGetFilters(Panel1, 1, 2);

  if trim(Pwhere) <> '' then
    fwhere := fwhere + ' where ' + trim(Pwhere);

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from (');
      sql.Add(' select A.CKOrdNo,COUNT(A.MJID)PS ,SUM(KGQty)KGQty,SUM(NetKGQty)NetKGQty ,SUM(A.Qty) Qty   ');
      sql.Add(',SUM(A.MJYLen) MJYLen,A.SUBID,CustomerNoName');
      sql.Add(',convert(varchar(10),A.CRTime,120) CRTime,A.CRType,a.mainid,PRTCOLOR,MPRTCode,MPRTCodeName,PRTHX,KHConno,ORDERNO,PRTorderqty');
      sql.Add('from CK_BanCP_CR a inner join JYOrder_sub B ON A.SUBID=B.SUBID');
      sql.Add('inner join JYOrder_MAIN C ON A.MAINID=B.MAINID AND B.MAINID=C.MAINID');
      sql.Add('where  A.CRFlag=''出库'' ');
      sql.Add(' and   A.CRTime>=' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)));
      sql.Add(' and  A.CRTime<' + quotedstr(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1)));
      sql.Add('GROUP BY CKOrdNo,A.SUBID,convert(varchar(10),A.CRTime,120) ,');

      sql.Add('A.CRType,PRTCOLOR,MPRTCode,MPRTCodeName,PRTHX,KHConno,ORDERNO,a.mainid,PRTorderqty,CustomerNoName');

      sql.Add('  ) aa   ');
      sql.Add(fwhere);
      sql.Add('order by crtime desc ');
//      ShowMessage(sql.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);

    MovePanel2.Visible := false;
  finally
    ADOQueryMain.EnableControls;
    MovePanel2.Visible := false;
  end;

end;

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

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

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

procedure TfrmCKProductBCPOutListHZSEL.FormShow(Sender: TObject);
var
  fsj: string;
begin
  ReadCxGrid(trim(self.Caption), Tv1, '成品仓库');
//  fsj := 'select distinct(LMName) name from Lbael_Map where LMType=''出库码单汇总''  ';
//  SInitComBoxBySql(ADOQueryCmd, ComboBox1, true, fsj);

  with ADOQueryTemp do
  begin
    Filtered := False;
    Close;
    sql.Clear;
    Sql.Add('select * from Lbael_Map where LMType=''出库码单汇总''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_Label);
  SInitCDSData20(ADOQueryTemp, CDS_Label);
end;

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

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

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

procedure TfrmCKProductBCPOutListHZSEL.orderNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    CurrentPage := 1;
    InitGrid();
  end;
end;

procedure TfrmCKProductBCPOutListHZSEL.Tv1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FLeft := X;
  FTop := Y;
end;

procedure TfrmCKProductBCPOutListHZSEL.CPTypeChange(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmCKProductBCPOutListHZSEL.CRTypeChange(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmCKProductBCPOutListHZSEL.edtSMNOKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin

  end;
end;

procedure TfrmCKProductBCPOutListHZSEL.FormDestroy(Sender: TObject);
begin
  frmCKProductBCPOutListHZSEL := nil;
end;

procedure TfrmCKProductBCPOutListHZSEL.ToolButton1Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty = True then
    Exit;

  ModalResult := 1;
end;

end.

