unit U_ClothSCListSel;

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

type
  TfrmClothSCListSel = 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;
    RM1: TRMGridReport;
    RMXLSExport1: TRMXLSExport;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1OrderNo: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1PRTMF: TcxGridDBColumn;
    v1PRTKZ: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Column6: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    Label10: TLabel;
    C_Code: TEdit;
    v1Column20: TcxGridDBColumn;
    Label6: TLabel;
    BatchNoHZ: TEdit;
    v1Column32: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    ToolButton1: TToolButton;
    v1Column1: TcxGridDBColumn;
    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);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
  private
    FInt, PFInt: Integer;
    canshu1: string;
    procedure InitGrid();
    procedure InitForm();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmClothSCListSel: TfrmClothSCListSel;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp;

{$R *.dfm}

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

procedure TfrmClothSCListSel.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid(trim(self.Caption), Tv1, '坯布生产管理');
end;

procedure TfrmClothSCListSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select A.*,B.* ');
      sql.Add(' from Cloth_Main A inner join CLoth_Sub B on A.Mainid=B.MainId');
      sql.Add(' where A.FillTIme>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)) + '''');
      sql.Add(' and A.FillTIme<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.DateTime + 1)) + '''');
      sql.Add(' and A.OrderType=''染整计划单''');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmClothSCListSel.InitForm();
begin
  ReadCxGrid(trim(self.Caption), Tv1, '坯布生产管理');

  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime - 7;
  InitGrid();
end;

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

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

procedure TfrmClothSCListSel.FormCreate(Sender: TObject);
begin
  canshu1 := Trim(DParameters1);
end;

procedure TfrmClothSCListSel.ToolButton1Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  ModalResult := 1;
end;

end.

