unit U_CaiGouSQChkListSel;

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
  TfrmCaiGouSQChkListSel = 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;
    TBFind: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column7: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label4: TLabel;
    Label5: TLabel;
    Label3: TLabel;
    Label6: TLabel;
    SPName: TEdit;
    SQPerson: TEdit;
    PinPai: TEdit;
    FactoryName: TEdit;
    Label7: TLabel;
    ConNo: TEdit;
    v1Column19: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    Label8: TLabel;
    SPType: TComboBox;
    v1Column17: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    v1Column22: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    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 cxTabControl1Change(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure SPTypeChange(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
  private
    canshu1,canshu2:string;
    procedure InitGrid();
    procedure InitForm();
    { Private declarations }
  public
    { Public declarations }
  end;
var
  frmCaiGouSQChkListSel:TfrmCaiGouSQChkListSel;


implementation
uses
  U_DataLink,U_RTFun,U_CaiGouSQInPut,U_ModuleNote;

{$R *.dfm}

procedure TfrmCaiGouSQChkListSel.FormDestroy(Sender: TObject);
begin
  frmCaiGouSQChkListSel:=nil;
end;

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

procedure TfrmCaiGouSQChkListSel.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('采购申请审批列表Sel',Tv1,'采购申请管理');
end;

procedure TfrmCaiGouSQChkListSel.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 SQType=''纱线'' ');
      sql.Add(' and isnull(ChkStatus,'''')=''已审核'' ');
      sql.Add(' and (isnull(SQQty,0)*(isnull(SQQtyUp,0)*0.01+1)>isnull(DHQty,0)');
      sql.Add(' or isnull(QtySXStr,'''')<>'''')');
      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(' order by SQDate');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmCaiGouSQChkListSel.InitForm();
begin
  EndDate.Date:=SGetServerDate(ADOQueryTemp);
  BegDate.Date:=EndDate.Date-60;
  ReadCxGrid('采购申请审批列表Sel',Tv1,'采购申请管理');
  InitGrid();
end;

procedure TfrmCaiGouSQChkListSel.TBExportClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  TcxGridToExcel('纱线采购加工列表',cxGrid1);
end;

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

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

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

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

procedure TfrmCaiGouSQChkListSel.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;

procedure TfrmCaiGouSQChkListSel.SPTypeChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmCaiGouSQChkListSel.Tv1DblClick(Sender: TObject);
begin
  ModalResult:=1;
end;

end.
