unit U_PBRKHZList;

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, cxContainer, cxTextEdit, cxMaskEdit,
  cxCalendar, Clipbrd, cxLookAndFeels, cxLookAndFeelPainters, dxCore,
  cxDateUtils, cxNavigator;

type
  TfrmPBRKHZList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    C_CodeName: TEdit;
    CDS_Main: TClientDataSet;
    Label5: TLabel;
    ConNo: TEdit;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column1: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ADOQueryPrint: TADOQuery;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    cxGridPopupMenu1: TcxGridPopupMenu;
    cxgrdbclmnv1Column12: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    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 C_CodeNameChange(Sender: TObject);
    procedure ConNoChange(Sender: TObject);
    procedure CheJianChange(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmPBRKHZList: TfrmPBRKHZList;

implementation

uses
  U_DataLink, U_Fun;

{$R *.dfm}

procedure TfrmPBRKHZList.FormDestroy(Sender: TObject);
begin
  frmPBRKHZList:=nil;
end;

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

procedure TfrmPBRKHZList.FormCreate(Sender: TObject);
begin
  //cxGrid1.Align:=alClient;
  EndDate.Date:= SGetServerDate10(ADOQueryTemp);
  BegDate.Date:=EndDate.Date-7;
end;

procedure TfrmPBRKHZList.InitGrid();
begin

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select A.*');
      SQL.Add(',B.ConNo,C.C_CodeName,C.C_Code,C.C_Color,C.gongyi,G.PBJGPrice,C.JGTiaoJia ');
      sql.Add(',GYPrice=isnull(G.PBJGPrice,0)+isnull(C.JGTiaoJia,0)');
      sql.Add(',GYMoney=(isnull(G.PBJGPrice,0)+isnull(C.JGTiaoJia,0))*KGQty');
      SQL.Add('From(select CRTime=convert(varchar(10),CRTime,120), Mainid,SubId,KCCarNo,CheJian,PS=Count(*),KGQty=sum(KGQty) ');
      sql.add('from CK_PBCP_CR  ');
      sql.add('where CRTime>=''' + Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date)) +''' ');
      sql.add('and CRTime<''' + Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1)) +''' ');
      SQL.Add(' and CRFlag=''入库''  Group by Mainid,SubId,KCCarNo,CheJian,convert(varchar(10),CRTime,120))A');
      Sql.add(' inner join Cloth_Main B on A.MainId=B.MainId');
      Sql.add(' inner join Cloth_Sub C on A.MainId=C.MainId');
      sql.Add(' left join CP_Info G on C.C_CodeName=G.SPName');
      sql.Add(' order by A.CRTIme,B.ConNo');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

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

procedure TfrmPBRKHZList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(Self.Caption+'11', Tv1, '坯布仓库');
  Close;
end;

procedure TfrmPBRKHZList.FormShow(Sender: TObject);
begin
  ReadCxGrid(Self.Caption+'11', Tv1, '坯布仓库');
end;

procedure TfrmPBRKHZList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    exit;
  TcxGridToExcel('坯布入库列表', cxGrid2);
end;

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

procedure TfrmPBRKHZList.ConNoChange(Sender: TObject);
begin
  if Length(Trim(ConNo.Text)) < 4 then
    Exit;
  TBFind.Click;
end;

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

end.

