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;

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;
    ConNo: TEdit;
    Label5: TLabel;
    C_CodeNameM: TEdit;
    Order_Main: TClientDataSet;
    Label10: TLabel;
    CSCode: TEdit;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1OrderNo: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1PRTMF: TcxGridDBColumn;
    v1PRTKZ: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Column16: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    v1Column22: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    ToolButton1: TToolButton;
    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 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:=caFree;
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.ConNo,A.QDTime,A.DeliveryDate,A.MainId,B.C_CodeName,B.C_Code,B.C_Color ');
//      sql.Add(' ,CSCode=B.C_Code+isnull(B.XDCS,'''')');
      sql.Add(',B.MFQty,B.KZQty,B.PiKgQty,B.PiQty,B.C_Qty,B.SubId,B.PiKgQtyFD,B.C_Spec,B.BatchNoHZ,C.JGID');
      sql.Add(',C.JHJiaoQi,C.WFGYSName,C.WFGYSNameJC,C.WFJHPS,C.WFJHQty,C.WFWCPS,C.WFWCQty,C.WFWCPSZP,C.WFWCQtyZP,C.WFWCPSCP,C.WFWCQtyCP');
      sql.Add(' from Cloth_Main A inner join CLoth_Sub B on A.Mainid=B.MainId');
      sql.Add(' inner join Cloth_WJG  C on C.MainId=A.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))+'''');
      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)-7;
  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.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 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.
