unit U_BSPrtStkSummary;

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, cxPC,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxDateRanges,
  dxBarBuiltInMenu, U_BaseList, cxContainer, dxCore, cxDateUtils, cxMaskEdit,
  dxSkinsCore, dxSkinsDefaultPainters, dxScrollbarAnnotations, cxProgressBar,
  dxSkinWXI;

type
  TfrmBSPrtStkSummary = class(TfrmBaseList)
    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;
    CDS_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    RMDBHZ: TRMDBDataSet;
    CDS_HZ: TClientDataSet;
    CDS_PRT: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Label3: TLabel;
    Label8: TLabel;
    P_Name: TcxTextEdit;
    P_Code: TcxTextEdit;
    ToolButton1: TToolButton;
    BegDate: TcxDateEdit;
    EndDate: TcxDateEdit;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    tv1: TcxGridDBBandedTableView;
    tv1P_Name: TcxGridDBBandedColumn;
    tv1QtyUnit: TcxGridDBBandedColumn;
    tv1SQJYQty: TcxGridDBBandedColumn;
    tv1BQRKQty: TcxGridDBBandedColumn;
    tv1BQCKQty: TcxGridDBBandedColumn;
    tv1BQJYQty: TcxGridDBBandedColumn;
    tv1P_Code: TcxGridDBBandedColumn;
    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 SPNameChange(Sender: TObject);
    procedure BPIOIDChange(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure P_specChange(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure P_CodeKeyPress(Sender: TObject; var Key: Char);
  private
    procedure InitGrid();
    { Private declarations }
  public
    canshu1, FStkName, canshu3: string;
    FFSPID: string;
    { Public declarations }
  end;

implementation

uses
  U_DataLink, U_RTFun, U_BSPrtOutEdit, U_LabelPrint;

{$R *.dfm}

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

procedure TfrmBSPrtStkSummary.FormCreate(Sender: TObject);
begin
  inherited;
  canshu1 := Trim(self.fParameters1);
  FStkName := Trim(self.fParameters2);
  canshu3 := Trim(self.fParameters3);
  EndDate.Date := SGetServerDate(ADOQueryTemp);
  BegDate.Date := EndDate.Date - 30;
end;

procedure TfrmBSPrtStkSummary.InitGrid();
var
  sBeg, sEnd: string;
begin
  if VarIsNull(BegDate.Date) or VarIsNull(EndDate.Date) then
  begin
    EndDate.Date := SGetServerDate(ADOQueryTemp);
    BegDate.Date := EndDate.Date - 30;
  end;

  sBeg := QuotedStr(FormatDateTime('yyyy-mm-dd', BegDate.Date));
  sEnd := QuotedStr(FormatDateTime('yyyy-mm-dd', EndDate.Date));

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      SQL.Add('exec P_BS_PrtStkSummary ');
      SQL.Add(' @stkname=' + QuotedStr(Trim(FStkName)));
      SQL.Add(', @begdate=' + sBeg);
      SQL.Add(', @enddate=' + sEnd);
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_Main);
    SInitCDSData(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmBSPrtStkSummary.TBRafreshClick(Sender: TObject);
begin
  toolbar1.SetFocus;
  InitGrid();
end;

procedure TfrmBSPrtStkSummary.ToolButton1Click(Sender: TObject);
begin
  ReadCxBandedGrid(trim(Self.Caption) + tv1.Name, Tv1, '物料仓库');

end;

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

procedure TfrmBSPrtStkSummary.TBCloseClick(Sender: TObject);
begin

  Close;
end;

procedure TfrmBSPrtStkSummary.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxBandedGrid(trim(Self.Caption) + tv1.Name, Tv1, '物料仓库');
  InitGrid();
end;

procedure TfrmBSPrtStkSummary.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    exit;
  TcxGridToExcel(FStkName + '库存汇总列表', cxGrid1);
end;

procedure TfrmBSPrtStkSummary.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_Main);
    SInitCDSData(ADOQueryMain, CDS_Main);
  end;
end;

procedure TfrmBSPrtStkSummary.SPNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmBSPrtStkSummary.BPIOIDChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmBSPrtStkSummary.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, True);
end;

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

procedure TfrmBSPrtStkSummary.P_CodeKeyPress(Sender: TObject; var Key: Char);
begin
  inherited;
  if Key = #13 then
  begin
    TBFind.Click;
  end;
end;

procedure TfrmBSPrtStkSummary.P_specChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmBSPrtStkSummary.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

end.

