unit U_CKCPHZList;

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;

type
  TfrmCKCPHZList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    Label4: TLabel;
    MPRTCodeName: TEdit;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    Tv1: TcxGridDBTableView;
    cxGrid2Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    Label5: TLabel;
    orderNo: TEdit;
    Label6: TLabel;
    MJID: TEdit;
    v1Column7: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    Label8: TLabel;
    MPRTKZ: TEdit;
    Label9: TLabel;
    MPRTMF: TEdit;
    Label7: TLabel;
    v1Column3: TcxGridDBColumn;
    RMXLSExport1: TRMXLSExport;
    v1Column4: TcxGridDBColumn;
    Label10: TLabel;
    CkOrdNo: TEdit;
    v1Column5: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    MovePanel2: TMovePanel;
    v1Column12: TcxGridDBColumn;
    DS_JuanPRT: TDataSource;
    cxGridPopupMenu2: TcxGridPopupMenu;
    Label11: TLabel;
    v1Column15: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    conNo: TEdit;
    Label15: TLabel;
    Label16: TLabel;
    KHConNo: TEdit;
    Label17: TLabel;
    apid: TEdit;
    v1Column21: TcxGridDBColumn;
    v1Column22: TcxGridDBColumn;
    begtime: TDateTimePicker;
    endTime: TDateTimePicker;
    ADOQueryPrint: TADOQuery;
    RMDB_Main: TRMDBDataSet;
    v1rkplace: TcxGridDBColumn;
    RKplace: TEdit;
    Label19: TLabel;
    RMDBHZ: TRMDBDataSet;
    CDS_HZ: TClientDataSet;
    RM3: TRMGridReport;
    v1Column24: TcxGridDBColumn;
    RMDBPRT: TRMDBDataSet;
    CDS_PRT: TClientDataSet;
    Label22: TLabel;
    KHName: TEdit;
    v1Column25: TcxGridDBColumn;
    Label24: TLabel;
    CRType: TComboBox;
    CPType: TComboBox;
    IsJYTime: TCheckBox;
    PRTColor: TEdit;
    ganghao: TEdit;
    v1Column13: TcxGridDBColumn;
    ToolButton2: TToolButton;
    ToolButton1: TToolButton;
    ComboBox1: TComboBox;
    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 Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    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 ToolButton2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    FLeft, FTop: Integer;
    CurrentPage, RecordsNumber: Integer;
    procedure InitGrid();
    { Private declarations }
  public
    canshu1: string;
    { Public declarations }
  end;

var
  frmCKCPHZList: TfrmCKCPHZList;

implementation

uses
  U_DataLink, U_Fun, U_SysLogHelp;

{$R *.dfm}

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

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

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

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select AA.*, B.orderNo,B.MPRTCodeName,B.MPRTMF,B.MPRTKZ,B.conNo,B.KHconNo');
      sql.Add(' ,C.PRTColor,C.PRTEColor,D.KHNmae,D.CKDate,D.CKType');
      sql.Add(' from ( select ckordno,APID,MainId,SubId,sum(KGQty) KGQty,COUNT(MJID) ps from CK_BanCP_CR A ');
      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)));
      sql.Add(' group by ckordno,APID,MainId,SubId )   AA  ');
      sql.Add(' inner join JYOrder_Main B on AA.MainId=B.MainId inner join JYOrder_Sub C on AA.SubId=C.SubId ');
      sql.Add(' inner join CK_BanCP_CKList D on AA.CKOrdNo=D.CKOrdNo  ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
    MovePanel2.Visible := false;
  finally
    ADOQueryMain.EnableControls;
    MovePanel2.Visible := false;
  end;

end;

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

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

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

procedure TfrmCKCPHZList.FormShow(Sender: TObject);
begin
  ReadCxGrid(trim(self.Caption), Tv1, '成品仓库');
  CurrentPage := 1;
  RecordsNumber := 500;

end;

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

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

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

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

procedure TfrmCKCPHZList.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  Clipboard.SetTextBuf(PChar(Trim(CDS_Main.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

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

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

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

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

  end;
end;

procedure TfrmCKCPHZList.ToolButton2Click(Sender: TObject);
begin
  frmSysLogHelp := TfrmSysLogHelp.create(self);
  with frmSysLogHelp do
  begin
    fModel := self.caption;
  //  facction:='生产指示单删除';
    showmodal;
    free;
  end;
end;

procedure TfrmCKCPHZList.ToolButton1Click(Sender: TObject);
var
  fPrintFile, fPrintFile10, FMainID, FKHName, FFPNo: string;
begin
  ExportFtErpFile(trim(ComboBox1.Text) + '.rmf', ADOQueryTemp);
  if trim(ComboBox1.Text) = '成品出库单' then
  begin
    with ADOQueryTemp do
    begin

      Close;
      sql.Clear;
      sql.add('exec P_Print_CKMDWSQ1 ');
      sql.add('@CKOrdNo=' + quotedstr(Trim(Trim(CDS_Main.fieldbyname('CKOrdNo').AsString))));
      Open;
    end;
    SCreateCDS20(ADOQueryTemp, CDS_PRT);
    SInitCDSData20(ADOQueryTemp, CDS_PRT);
  end;

  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(ComboBox1.Text) + '.rmf';
  if FileExists(fPrintFile) then
  begin
    RM3.LoadFromFile(fPrintFile);
    RMVariables['Filler'] := trim(DName);
    RM3.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找到' + fPrintFile), '提示', 0);
  end;
end;

procedure TfrmCKCPHZList.FormDestroy(Sender: TObject);
begin
  frmCKCPHZList := nil;
end;

end.

