unit U_YarnStkSummary;

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
  TfrmYarnStkSummary = 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;
    Y_Name: TcxTextEdit;
    Y_Code: TcxTextEdit;
    ToolButton1: TToolButton;
    BegDate: TcxDateEdit;
    EndDate: TcxDateEdit;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    tv1: TcxGridDBBandedTableView;
    tv1Y_Name: TcxGridDBBandedColumn;
    tv1QtyUnit: TcxGridDBBandedColumn;
    tv1SQJYQty: TcxGridDBBandedColumn;
    tv1BQRKQty: TcxGridDBBandedColumn;
    tv1BQCKQty: TcxGridDBBandedColumn;
    tv1BQJYQty: TcxGridDBBandedColumn;
    tv1Y_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 Y_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_LabelPrint;

{$R *.dfm}

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

procedure TfrmYarnStkSummary.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 TfrmYarnStkSummary.InitGrid();
var
  strBeg, strEnd: string;
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;

      if BegDate.Text <> '' then
        strBeg := FormatDateTime('yyyy-mm-dd', BegDate.Date)
      else
        strBeg := '1900-01-01';
      if EndDate.Text <> '' then
        strEnd := FormatDateTime('yyyy-mm-dd', EndDate.Date)
      else
        strEnd := FormatDateTime('yyyy-mm-dd', Date + 3650);

      SQL.Add('exec P_BS_YarnStkSummary ');
      SQL.Add(' @stkname=' + QuotedStr(Trim(FStkName)));
      SQL.Add(', @begdate=' + QuotedStr(strBeg));
      SQL.Add(', @enddate=' + QuotedStr(strEnd));
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_Main);
    SInitCDSData(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

procedure TfrmYarnStkSummary.ToolButton1Click(Sender: TObject);
begin
  ReadCxBandedGrid(trim(Self.Caption) + tv1.Name, Tv1, '纱线仓库');

end;

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

procedure TfrmYarnStkSummary.TBCloseClick(Sender: TObject);
begin

  Close;
end;

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

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

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

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

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

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

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

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

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

end.

