unit U_PBOuGLtListBHHZ;

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, BtnEdit, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmPBOuGLtListBHHZ = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    CDS_Print: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    MovePanel2: TMovePanel;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v2Column1: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    Label3: TLabel;
    PrtCode: TEdit;
    CDS_DH: TClientDataSet;
    ADOQueryDH: TADOQuery;
    ADOQueryPrint: TADOQuery;
    v1Column1: TcxGridDBColumn;
    Label4: TLabel;
    APBatchNo: TEdit;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    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 MPRTCodeNameChange(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure PrtCodeChange(Sender: TObject);
    procedure CheJianChange(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmPBOuGLtListBHHZ: TfrmPBOuGLtListBHHZ;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp;

{$R *.dfm}

procedure TfrmPBOuGLtListBHHZ.FormDestroy(Sender: TObject);
begin
  frmPBOuGLtListBHHZ:=nil;
end;

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

procedure TfrmPBOuGLtListBHHZ.FormCreate(Sender: TObject);
begin
  //cxGrid1.Align:=alClient;

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

procedure TfrmPBOuGLtListBHHZ.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;

      SQL.Add('select  B.Note,C.PrtCode,C.PrtCodeName,SUM(A.KGQty) KGQty,COUNT(MJID) PS ');
      sql.add(' ,D.APBatchNo from CK_PBCP_CR A inner join FHSQ_Main B on A.CKOrdNo=B.FSId ');
      Sql.add('  inner join JYOrderCon_Sub_PB C on B.ConSubId=C.SubId');
      Sql.add(' inner join JYCon_Sub_AnPai D on D.APID=A.MJID');
      Sql.add(' inner join Cloth_Sub E on A.MainId=E.MainId');
      Sql.add(' where A.CRFlag=''³ö¿â'' ');
      sql.add(' and A.CRTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+''' ');
      sql.Add(' and A.CRTime<'''+Trim(FormatDateTime('yyyy-MM-dd',enddate.DateTime+1))+'''');
      SQL.Add(' group by  B.Note,C.PrtCode,C.PrtCodeName,D.APBatchNo');
      SQL.Add(' order by C.PrtCode,C.PrtCodeName,D.APBatchNo ');
//      ShowMessage(SQL.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

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

procedure TfrmPBOuGLtListBHHZ.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(Self.Caption+'1',Tv1,'Å÷²¼²Ö¿â');
  Close;
end;

procedure TfrmPBOuGLtListBHHZ.FormShow(Sender: TObject);
begin
  ReadCxGrid(Self.Caption,Tv1,'Å÷²¼²Ö¿â');
  ReadCxGrid(Self.Caption+'1',Tv1,'Å÷²¼²Ö¿â');
end;

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

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

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

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

procedure TfrmPBOuGLtListBHHZ.PrtCodeChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmPBOuGLtListBHHZ.CheJianChange(Sender: TObject);
begin
  TBFind.Click;
end;

end.
