unit U_TatClothStkSummary;

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
  TfrmTatClothStkSummary = 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;
    tv1C_Name: TcxGridDBBandedColumn;
    tv1QtyUnit: TcxGridDBBandedColumn;
    tv1SQJYQty: TcxGridDBBandedColumn;
    tv1BQRKQty: TcxGridDBBandedColumn;
    tv1BQCKQty: TcxGridDBBandedColumn;
    tv1BQJYQty: TcxGridDBBandedColumn;
    tv1C_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);
  private
    procedure InitGrid();
    { Private declarations }
  public
    canshu1, FStkName, canshu3: string;
    FFSPID: string;
    { Public declarations }
  end;

implementation

uses
  U_DataLink, U_RTFun, U_LabelPrint;

{$R *.dfm}

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

procedure TfrmTatClothStkSummary.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 TfrmTatClothStkSummary.InitGrid();
var
  sBeg, sEnd: string;
begin
  try
    ADOQueryMain.DisableControls;
    // 将日期格式化为 yyyy-mm-dd 字符串，直接拼入 SQL
    sBeg := FormatDateTime('yyyy-mm-dd', BegDate.Date);
    sEnd := FormatDateTime('yyyy-mm-dd', EndDate.Date);
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      SQL.Add('exec P_Tat_ClothStkSummary ''' + sBeg + ''', ''' + sEnd + '''');
//      SQL.Add('exec P_Tat_ClothStkSummary ');
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_Main);
    SInitCDSData(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmTatClothStkSummary.TBRafreshClick(Sender: TObject);
begin
  ToolBar1.SetFocus;
  InitGrid();
end;

procedure TfrmTatClothStkSummary.ToolButton1Click(Sender: TObject);
begin
  ReadCxBandedGrid(trim(Self.Caption) + tv1.Name, Tv1, '坯布仓库');

end;

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

procedure TfrmTatClothStkSummary.TBCloseClick(Sender: TObject);
begin

  Close;
end;

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

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

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

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

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

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

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

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

end.

