unit U_PBSXJGHZList;

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;

type
  TfrmPBSXJGHZList = 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;
    cxGrid2: TcxGrid;
    cxGrid2Level1: TcxGridLevel;
    Tv1: TcxGridDBBandedTableView;
    v1Column1: TcxGridDBBandedColumn;
    v1Column2: TcxGridDBBandedColumn;
    v1Column3: TcxGridDBBandedColumn;
    v1Column4: TcxGridDBBandedColumn;
    v1Column5: TcxGridDBBandedColumn;
    v1Column6: TcxGridDBBandedColumn;
    v1Column17: TcxGridDBBandedColumn;
    v1Column18: TcxGridDBBandedColumn;
    v1Column19: TcxGridDBBandedColumn;
    v1Column20: TcxGridDBBandedColumn;
    Label5: TLabel;
    SCOrderNo: TEdit;
    v1Column28: TcxGridDBBandedColumn;
    v1Column8: TcxGridDBBandedColumn;
    v1Column10: TcxGridDBBandedColumn;
    v1Column11: TcxGridDBBandedColumn;
    v1Column12: TcxGridDBBandedColumn;
    v1Column14: TcxGridDBBandedColumn;
    v1Column7: TcxGridDBBandedColumn;
    v1Column9: TcxGridDBBandedColumn;
    v1Column13: TcxGridDBBandedColumn;
    v1Column15: TcxGridDBBandedColumn;
    v1Column16: TcxGridDBBandedColumn;
    v1Column21: TcxGridDBBandedColumn;
    Label3: TLabel;
    C_Code: TEdit;
    Label4: TLabel;
    C_CodeName: TEdit;
    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 SPNameChange(Sender: TObject);
    procedure SPSpecChange(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
  private
    canshu1,canshu2:string;
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmPBSXJGHZList: TfrmPBSXJGHZList;

implementation
uses
  U_DataLink,U_RTFun;

{$R *.dfm}

procedure TfrmPBSXJGHZList.FormDestroy(Sender: TObject);
begin
  frmPBSXJGHZList:=nil;
end;

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

procedure TfrmPBSXJGHZList.FormCreate(Sender: TObject);
begin
  EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime:=EndDate.DateTime-30;
end;

procedure TfrmPBSXJGHZList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' P_View_PBSXSH :begdate,:enddate ');
      Parameters.ParamByName('begdate').Value:=Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime));
      Parameters.ParamByName('enddate').Value:=Trim(FormatDateTime('yyyy-MM-dd',enddate.DateTime+1));
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

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

procedure TfrmPBSXJGHZList.TBCloseClick(Sender: TObject);
begin
  WriteCxBandedGrid('纱线加工汇总查询',Tv1,'纱线仓库');
  Close;
end;

procedure TfrmPBSXJGHZList.FormShow(Sender: TObject);
begin
  ReadCxBandedGrid('纱线加工汇总查询',Tv1,'纱线仓库');
end;

procedure TfrmPBSXJGHZList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then exit;
  TcxGridToExcel('纱线加工汇总查询',cxGrid2);
end;

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

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

procedure TfrmPBSXJGHZList.CheckBox1Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

end.
