unit U_ClothHCList;

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, cxDropDownEdit, cxCheckBox;

type
  TfrmClothHCList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label1: TLabel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    OrderNoM: TEdit;
    Label5: TLabel;
    GangNo: TEdit;
    Order_Main: TClientDataSet;
    Label4: TLabel;
    AOrddefstr1: TEdit;
    Label6: TLabel;
    PRTColor: TEdit;
    Label7: TLabel;
    AOrddefstr4: TEdit;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    V2Column2: TcxGridDBColumn;
    V2Column8: TcxGridDBColumn;
    cxGridDBColumn1: TcxGridDBColumn;
    V2Column3: TcxGridDBColumn;
    V2Column4: TcxGridDBColumn;
    V2Column7: TcxGridDBColumn;
    V2Column1: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    V2Column10: TcxGridDBColumn;
    V2Column13: TcxGridDBColumn;
    V2APID: TcxGridDBColumn;
    V2Column9: TcxGridDBColumn;
    V2Column14: TcxGridDBColumn;
    KHconNo: TEdit;
    Label8: TLabel;
    conNo: TEdit;
    Label9: TLabel;
    V2Column15: TcxGridDBColumn;
    V2Column16: TcxGridDBColumn;
    mprtCodeName: TEdit;
    Label2: TLabel;
    Mprtspec: TEdit;
    Label10: TLabel;
    V2Column5: TcxGridDBColumn;
    V2Column6: TcxGridDBColumn;
    V2Column11: TcxGridDBColumn;
    V2Column12: TcxGridDBColumn;
    V2Column17: TcxGridDBColumn;
    V2Column18: TcxGridDBColumn;
    Label11: TLabel;
    prtkuanNo: TEdit;
    V2Column19: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure OrderNoMChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure OrderNoMKeyPress(Sender: TObject; var Key: Char);
    procedure TV2DblClick(Sender: TObject);
  private
    FInt,PFInt:Integer;
    procedure InitGrid();
    procedure InitForm();
    procedure InitGridWSQL(FWSQL:String);
    { Private declarations }
  public
    fType:string;
    { Public declarations }
  end;

var
  frmClothHCList: TfrmClothHCList;

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

{$R *.dfm}

procedure TfrmClothHCList.FormDestroy(Sender: TObject);
begin
  frmClothHCList:=nil;
end;

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

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

procedure TfrmClothHCList.InitGrid();
begin
  try
    //ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('exec P_View_HC :begdate,:enddate,:WSQL');
      Parameters.ParamByName('begdate').Value:=FormatDateTime('yyyy-MM-dd',BegDate.Date);
      Parameters.ParamByName('enddate').Value:=FormatDateTime('yyyy-MM-dd',EndDate.Date+1);
      Parameters.ParamByName('WSQL').Value:='';
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    //ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmClothHCList.InitGridWSQL(FWSQL:String);
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('exec P_View_HC :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 TfrmClothHCList.InitForm();
begin
  ReadCxGrid(self.Caption+tv2.Name,Tv2,'指示单管理');
  EndDate.DateTime:=SGetServerDateTime(ADOQueryTemp);
  BegDate.DateTime:=EndDate.DateTime-7;
  //InitGrid();
end;

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

procedure TfrmClothHCList.OrderNoMChange(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 TfrmClothHCList.FormShow(Sender: TObject);
begin
  InitForm();
  TBRafresh.Click;
end;

procedure TfrmClothHCList.OrderNoMKeyPress(Sender: TObject;
  var Key: Char);
var
  fsj:String;
begin
  if Key=#13 then
  begin
    if Length(Trim(OrderNoM.Text))<4 then Exit;
    fsj:=' and B.OrderNo like '''+'%'+Trim(OrderNoM.Text)+'%'+'''';
    InitGridWSQL(fsj);
  end;
end;

procedure TfrmClothHCList.TV2DblClick(Sender: TObject);
begin
  if fType='10' then frmClothHCList.ModalResult:=1;
end;

end.
