unit U_DJBRKList_PBNo;

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_PBNo = 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;
    ConNO: TEdit;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1FillTime: TcxGridDBColumn;
    v1ConNO: TcxGridDBColumn;
    v1JYQty: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    v1JYPS: TcxGridDBColumn;
    v1JGPrice: TcxGridDBColumn;
    v1JGMoney: TcxGridDBColumn;
    cxTimeEdit1: TcxTimeEdit;
    cxTimeEdit2: TcxTimeEdit;
    Label4: TLabel;
    C_CodeName: TEdit;
    v1C_CodeName: 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 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_PBNo: TfrmDJBRKList_PBNo;

implementation
uses
  U_DataLink,U_RTFun,U_DJBCKInPut,U_DJBCKInPut_JTZS;

{$R *.dfm}

procedure TfrmDJBRKList_PBNo.FormDestroy(Sender: TObject);
begin
  frmDJBRKList_PBNo:=nil;
end;

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

procedure TfrmDJBRKList_PBNo.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_PBNo.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select M.ConNO,M.JGPrice,JGMoney=Sum(AP.MJMaoZ*M.JGPrice),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('inner join Cloth_Main M on AP.Mainid=M.Mainid ');
      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 M.ConNO,M.JGPrice,convert(varchar(10),AP.Filltime,120),AP.Subid ');
      sql.add('order by convert(varchar(10),AP.Filltime,120),M.ConNO');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

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

procedure TfrmDJBRKList_PBNo.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('白坯单号列表1',Tv1,'待检布仓库');
  Close;
end;

procedure TfrmDJBRKList_PBNo.FormShow(Sender: TObject);
begin
  ReadCxGrid('白坯单号列表1',Tv1,'待检布仓库');
  initgrid();
end;

procedure TfrmDJBRKList_PBNo.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then exit;
  TcxGridToExcel('白坯单号产量列表',cxGrid2);
end;

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

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

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

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

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

end.
