unit U_DJBRKList_JTCL;

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, cxCheckBox, RM_Common,
  RM_Class, RM_e_Xls, RM_Dataset, RM_System, RM_GridReport, Menus,
  cxCalendar, cxButtonEdit, cxTextEdit, cxContainer, cxMaskEdit,
  cxSpinEdit, cxTimeEdit;

type
  TfrmDJBRKList_JTCL = 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;
    Label3: TLabel;
    CarNo: TEdit;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1APDate: TcxGridDBColumn;
    v1CarNo: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    v1MJMaoZ: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    v1PS: TcxGridDBColumn;
    cxTimeEdit1: TcxTimeEdit;
    cxTimeEdit2: TcxTimeEdit;
    v1C_CodeName: TcxGridDBColumn;
    Label4: TLabel;
    C_CodeName: TEdit;
    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 N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ConNoChange(Sender: TObject);
    procedure SPSpecChange(Sender: TObject);
    procedure BTNoteChange(Sender: TObject);
  private
    canshu1,canshu2:string;
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmDJBRKList_JTCL: TfrmDJBRKList_JTCL;

implementation
uses
  U_DataLink,U_RTFun,U_DJBCKInPut,U_DJBCKInPut_JTZS;

{$R *.dfm}

procedure TfrmDJBRKList_JTCL.FormDestroy(Sender: TObject);
begin
  frmDJBRKList_JTCL:=nil;
end;

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

procedure TfrmDJBRKList_JTCL.FormCreate(Sender: TObject);
begin
  //cxGrid1.Align:=alClient;
  canshu1:=Trim(DParameters1);
  canshu2:=Trim(DParameters2);
  EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime:=EndDate.DateTime-1;
end;

procedure TfrmDJBRKList_JTCL.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.add('select Sum(PP.PS) PS,Sum(PP.MJMaoZ) MJMaoZ,AP.APDate,AP.CarNo,PP.C_CodeName ');
      sql.add(',ZQty=(select Sum(Z.Qty) from Cloth_JiTaiZShu Z where Z.CarNo=AP.CarNo and Z.ZSDate=AP.APDate and Z.Subid=PP.Subid) ');
      sql.add('from (select count(P.MJID) PS,Sum(P.MJMaoZ) MJMaoZ,P.APID,P.filltime,P.Subid');
      sql.add(',C_CodeName=(select Top 1 C_CodeName from Cloth_Sub B where B.Subid=P.Subid)');
      sql.add(' from WFB_MJJY_PB P group by P.APID,P.filltime,P.Subid) PP ');
      sql.Add('inner join JYCon_Sub_AnPai AP on AP.APID=PP.APID ');
      sql.add('where PP.filltime>='''+trim(Datetostr(begdate.Date)+' '+timetostr(cxTimeEdit1.Time))+''' ');
      sql.Add('and PP.filltime<'''+trim(Datetostr(Enddate.Date)+' '+timetostr(cxTimeEdit2.Time))+''' ');
      sql.add('group by AP.APDate,AP.CarNo,PP.C_CodeName,PP.Subid');
      sql.add('having Sum(PP.PS)<>0 ');
      sql.add('order by AP.APDate,CAST(CarNo as int)');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

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

procedure TfrmDJBRKList_JTCL.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('机台转数列表1',Tv1,'待检布仓库');
  Close;
end;

procedure TfrmDJBRKList_JTCL.FormShow(Sender: TObject);
begin
  ReadCxGrid('机台转数列表1',Tv1,'待检布仓库');
  initgrid();
end;

procedure TfrmDJBRKList_JTCL.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then exit;
  TcxGridToExcel('机台转数列表',cxGrid2);
end;

procedure TfrmDJBRKList_JTCL.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 TfrmDJBRKList_JTCL.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main,True);
end;

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

procedure TfrmDJBRKList_JTCL.ConNoChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmDJBRKList_JTCL.SPSpecChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmDJBRKList_JTCL.BTNoteChange(Sender: TObject);
begin
  TBFind.Click;
end;

end.
