unit U_CaiGouSQCXList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxGrid, DBClient, cxCalendar, cxButtonEdit, cxSplitter,
  RM_Common, RM_Class, RM_e_Xls, RM_Dataset, RM_System, RM_GridReport,
  cxTextEdit, cxPC, cxDropDownEdit, cxCheckBox;

type
  TfrmCaiGouSQCXList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    ToolButton2: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column7: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    TBFind: TToolButton;
    YCLName: TEdit;
    Label4: TLabel;
    SQPerson: TEdit;
    Label5: TLabel;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cxPageControl1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
  private
    canshu1,canshu2:string;
    procedure InitGrid();
    procedure InitForm();
    { Private declarations }
  public
    { Public declarations }
  end;



implementation
uses
  U_DataLink,U_RTFun;

{$R *.dfm}

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

procedure TfrmCaiGouSQCXList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('采购申请查询列表',Tv1,'采购申请管理');
end;

procedure TfrmCaiGouSQCXList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      SQL.Add(' from CaiGou_SQ A where isnull(SChkStatus,'''')<>'''' and  isnull(ChkStatus,'''')<>'''' ');
      sql.Add(' and A.SQDate>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.Date))+'''');
      sql.Add(' and A.SQDate<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.Date+1))+'''');
      sql.Add(' and SQType='''+Trim(canshu2)+'''');
      sql.Add(' order by SQDate');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmCaiGouSQCXList.InitForm();
begin
  EndDate.Date:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=EndDate.Date-7;
  ReadCxGrid('采购申请查询列表',Tv1,'采购申请管理');
  InitGrid();
end;

procedure TfrmCaiGouSQCXList.TBExportClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  TcxGridToExcel('采购申请查询列表',cxGrid1);
end;

procedure TfrmCaiGouSQCXList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmCaiGouSQCXList.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmCaiGouSQCXList.cxPageControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmCaiGouSQCXList.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
  canshu2:=Trim(DParameters2);
end;

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

procedure TfrmCaiGouSQCXList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);  
end;

end.
