unit U_ClothGMListSel;

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,ShellAPI, cxCheckBox, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator;

type
  TfrmClothGMListSel = 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;
    OrderNo: TEdit;
    Label5: TLabel;
    MPRTCodeName: TEdit;
    Order_Main: TClientDataSet;
    Label10: TLabel;
    MPRTCode: TEdit;
    ToolButton1: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1OrderNo: TcxGridDBColumn;
    v1ConNo: TcxGridDBColumn;
    v1CustomerNoName: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1OrdDate: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1DeliveryDate: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1MPRTCodeName: TcxGridDBColumn;
    v1MPRTSpec: TcxGridDBColumn;
    v1MPRTMF: TcxGridDBColumn;
    v1MPRTKZ: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    Label4: TLabel;
    ConNo: TEdit;
    Label6: TLabel;
    CustomerNoName: TEdit;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure OrderNoChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure conPress(Sender: TObject; var Key: Char);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
  private
    FInt,PFInt:Integer;
    canshu1:string;
    procedure InitGrid();
    procedure InitForm();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmClothGMListSel: TfrmClothGMListSel;

implementation
uses
  U_DataLink,U_Fun;

{$R *.dfm}

procedure TfrmClothGMListSel.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action:=caHide;
end;

procedure TfrmClothGMListSel.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('坯布生产计划单',Tv1,'坯布生产管理');
end;

procedure TfrmClothGMListSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.add('select A.*,B.* from JYOrder_Main A') ;
       sql.add(' inner join JYOrder_Sub B on A.MainId=B.MainId') ;
      sql.add(' where Filltime>='+quotedstr(trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime)))) ;
      sql.add(' and Filltime<'+quotedstr(trim(FormatDateTime('yyyy-MM-dd',enddate.DateTime+1)))) ;

//      sql.add(' and isnull(status,''0'')='+quotedstr(trim(inttostr(cxTabControl1.TabIndex)))) ;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmClothGMListSel.InitForm();
begin

  ReadCxGrid('坯布生产计划单',Tv1,'坯布生产管理');
  BegDate.DateTime:=SGetServerDate10(ADOQueryTemp)-30;
  EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
  InitGrid();
end;

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

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

procedure TfrmClothGMListSel.conPress(Sender: TObject;
  var Key: Char);
begin
  if Key=#13 then
  begin
    if Length(Trim(ConNo.Text))<4 then Exit;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        sql.Clear;
        //sql.Add('exec Cloth_QryList :MainId,:WSql');
       // Parameters.ParamByName('WSql').Value:=' and OM.conNo like '''+'%'+Trim(ConNoM.Text)+'%'+''''
                                             // +' and ConType=''生产'' ';
       sql.Add('select * from Cloth_Main A inner join CLoth_Sub B on A.Mainid=B.MainId');
       sql.Add(' where A.ConNo like '''+'%'+Trim(ConNo.Text)+'%'+'''');

        Open;
      end;
      SCreateCDS20(ADOQueryMain,Order_Main);
      SInitCDSData20(ADOQueryMain,Order_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

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

procedure TfrmClothGMListSel.FormDestroy(Sender: TObject);
begin
  frmClothGMListSel:=nil;
end;

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

procedure TfrmClothGMListSel.Tv1DblClick(Sender: TObject);
begin
  if order_Main.IsEmpty then Exit;
  ModalResult:=1;
end;

end.
