unit U_DJBRKList_DCGCL;

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_DCGCL = 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;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    Label12: TLabel;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1APDate: TcxGridDBColumn;
    v1SCPerson: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    v1MJMaoZ: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    SCPerson: TEdit;
    v1PS: TcxGridDBColumn;
    Begdate: TDateTimePicker;
    cxTimeEdit1: TcxTimeEdit;
    cxTimeEdit2: TcxTimeEdit;
    v1C_CodeName: TcxGridDBColumn;
    Label3: 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_DCGCL: TfrmDJBRKList_DCGCL;

implementation
uses
  U_DataLink,U_RTFun,U_DJBCKInPut,U_DJBCKInPut_JTZS;

{$R *.dfm}

procedure TfrmDJBRKList_DCGCL.FormDestroy(Sender: TObject);
begin
  frmDJBRKList_DCGCL:=nil;
end;

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

procedure TfrmDJBRKList_DCGCL.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_DCGCL.InitGrid();
begin
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select SUM(PP.MJMaoZ) MJMaoZ,SUM(PP.PS) ps,AP.APDate,AP.SCPerson,C_CodeName ');
      sql.add(',ZQty=(select Sum(Z.Qty) from Cloth_JiTaiZShu Z where Z.SCPerson=AP.SCPerson and Z.ZSDate=AP.APDate and Z.Subid=PP.Subid) ');
      sql.add('from (select SUM(P.MJMaoZ) MJMaoZ,count(P.MJID) PS,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 ');
      sql.add('where P.filltime>='''+trim(Datetostr(begdate.Date)+' '+timetostr(cxTimeEdit1.Time))+''' ');
      sql.Add('and P.filltime<'''+trim(Datetostr(Enddate.Date)+' '+timetostr(cxTimeEdit2.Time))+''' ');
      sql.add(' group by P.APID,P.Filltime,P.Subid) PP ');
      sql.add('inner join JYCon_Sub_AnPai AP on AP.APID=PP.APID ');
      sql.add('group by AP.APDate,AP.SCPerson,C_CodeName,PP.Subid');
      sql.add(' having Sum(PP.PS)<>0 ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
end;

procedure TfrmDJBRKList_DCGCL.TBRafreshClick(Sender: TObject);
begin
  Toolbar1.SetFocus;
  InitGrid();
end;

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

procedure TfrmDJBRKList_DCGCL.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('挡车工转数列表1',Tv1,'待检布仓库');
  Close;
end;

procedure TfrmDJBRKList_DCGCL.FormShow(Sender: TObject);
begin
  ReadCxGrid('挡车工转数列表1',Tv1,'待检布仓库');
  initgrid();
end;

procedure TfrmDJBRKList_DCGCL.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then exit;
  TcxGridToExcel('挡车工转数列表',cxGrid2);
end;

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

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

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

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

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

end.
