unit U_DJBRKList_JYCX;

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_JYCX = 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;
    Filler: TEdit;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1FillTime: TcxGridDBColumn;
    v1Filler: TcxGridDBColumn;
    v1JYQty: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    v1JYPS: 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_JYCX: TfrmDJBRKList_JYCX;

implementation
uses
  U_DataLink,U_RTFun,U_DJBCKInPut,U_DJBCKInPut_JTZS;

{$R *.dfm}

procedure TfrmDJBRKList_JYCX.FormDestroy(Sender: TObject);
begin
  frmDJBRKList_JYCX:=nil;
end;

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

procedure TfrmDJBRKList_JYCX.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_JYCX.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select AP.Filler,convert(varchar(10),AP.Filltime,120) Filltime');
      sql.add(',C_CodeName=(select Top 1 C_CodeName from Cloth_Sub B where B.Subid=AP.Subid)');
      sql.add(',count(AP.MJID) JYPS,Sum(AP.MJMaoZ) JYQty ');
      sql.add('from WFB_MJJY_PB AP ');
      sql.add('where AP.filltime>='''+trim(Datetostr(begdate.Date)+' '+timetostr(cxTimeEdit1.Time))+''' ');
      sql.Add('and AP.filltime<'''+trim(Datetostr(Enddate.Date)+' '+timetostr(cxTimeEdit2.Time))+''' ');
      sql.Add('group by AP.Filler,convert(varchar(10),AP.Filltime,120),AP.Subid ');
      sql.add('order by convert(varchar(10),AP.Filltime,120),AP.Filler');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

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

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

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

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

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

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

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

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

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

end.
