unit U_ClothContractKCList;

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;

type
  TfrmClothContractKCList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label1: TLabel;
    Label2: TLabel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    ConNo: TEdit;
    Label5: TLabel;
    C_CodeName: TEdit;
    Order_Main: TClientDataSet;
    Label4: TLabel;
    C_Spec: TEdit;
    ClientDataSet3: TClientDataSet;
    DataSource2: TDataSource;
    DataSource3: TDataSource;
    ClientDataSet2: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1OrderNo: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1FactoryNo1Name: TcxGridDBColumn;
    v1PRTSpec: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    cxGridPopupMenu2: TcxGridPopupMenu;
    Label6: TLabel;
    FactoryNoName: TEdit;
    Label7: TLabel;
    FirstName: TEdit;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    ThreeColorBase: TcxStyleRepository;
    SHuangSe: TcxStyle;
    SkyBlue: TcxStyle;
    Default: TcxStyle;
    QHuangSe: TcxStyle;
    Red: TcxStyle;
    FontBlue: TcxStyle;
    TextSHuangSe: TcxStyle;
    FonePurple: TcxStyle;
    FoneClMaroon: TcxStyle;
    FoneRed: TcxStyle;
    RowColor: TcxStyle;
    handBlack: TcxStyle;
    cxBlue: TcxStyle;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    FInt,PFInt:Integer;
    procedure InitGrid();
    procedure InitForm();
    procedure InitGridWSQL(FWSQL:String);
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmClothContractKCList: TfrmClothContractKCList;

implementation
uses
  U_DataLink,U_ClothContractInPut,U_Fun,U_ProductOrderList,U_ZDYHelp;

{$R *.dfm}

procedure TfrmClothContractKCList.FormDestroy(Sender: TObject);
begin
  frmClothContractKCList:=nil;
end;

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

procedure TfrmClothContractKCList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid(self.Caption+tv1.Name,Tv1,'指示单管理');
end;

procedure TfrmClothContractKCList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('exec P_Get_PBKC :begdate,:enddate');
      Parameters.ParamByName('begdate').Value:=FormatDateTime('yyyy-MM-dd',BegDate.Date);
      Parameters.ParamByName('enddate').Value:=FormatDateTime('yyyy-MM-dd',EndDate.Date+1);
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;
procedure TfrmClothContractKCList.InitGridWSQL(FWSQL:String);
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('exec P_View_ClothHZ :begdate,:enddate,:WSQL');
      Parameters.ParamByName('begdate').Value:='1900-01-01';
      Parameters.ParamByName('enddate').Value:='2050-01-01';
      Parameters.ParamByName('WSQL').Value:=FWSQL;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmClothContractKCList.InitForm();
begin
  ReadCxGrid(self.Caption+tv1.Name,Tv1,'指示单管理');
  EndDate.DateTime:=SGetServerDateTime(ADOQueryTemp);
  BegDate.DateTime:=EndDate.DateTime-15;
  InitGrid();
end;

procedure TfrmClothContractKCList.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 TfrmClothContractKCList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmClothContractKCList.ConNoChange(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 TfrmClothContractKCList.FormShow(Sender: TObject);
begin
  InitForm();
end;

end.
