unit U_OrderSelRK;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, StdCtrls, ADODB, DBClient, ComCtrls,
  ExtCtrls, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxCheckBox;

type
  TfrmOrderSelRK = class(TForm)
    Panel1: TPanel;
    Label2: TLabel;
    ConNo: TEdit;
    Label3: TLabel;
    C_Color: TEdit;
    CDS_OrderSel: TClientDataSet;
    DataSource1: TDataSource;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    cxGrid1: TcxGrid;
    Tv2: TcxGridDBTableView;
    v1OrderNo: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    v1PRTMF: TcxGridDBColumn;
    v1PRTKZ: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyleRepository2: TcxStyleRepository;
    cxStyle2: TcxStyle;
    cxStyleRepository3: TcxStyleRepository;
    cxStyle3: TcxStyle;
    v2Column2: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    Label1: TLabel;
    C_Code: TEdit;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button2Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure ConNoChange(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
  private
    { Private declarations }
    procedure InitGrid();
  public
    { Public declarations }
  end;

var
  frmOrderSelRK: TfrmOrderSelRK;

implementation
uses
  U_DataLink,U_Fun ;

{$R *.dfm}

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

procedure TfrmOrderSelRK.Button2Click(Sender: TObject);
var
  KHName:String;
begin
  {if CDS_OrderSel.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据！','提示',0);
    Exit;
  end; }
  ModalResult:=1;
end;

procedure TfrmOrderSelRK.FormDestroy(Sender: TObject);
begin
  frmOrderSelRK:=nil;
end;

procedure TfrmOrderSelRK.Button3Click(Sender: TObject);
begin
  ModalResult:=-1;
  WriteCxGrid('坯布入库订单选择',Tv2,'坯布仓库');
  Close;
end;

procedure TfrmOrderSelRK.FormShow(Sender: TObject);
begin
  ReadCxGrid('坯布入库订单选择',Tv2,'坯布仓库');
  InitGrid();
end;

procedure TfrmOrderSelRK.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select A.ConNo,B.C_CodeName,B.C_Code,A.MainId,B.SubId,B.C_Color,WY.ClothType');
      sql.Add(',JYPS=Count(WY.MJID),JYQty=sum(WY.MJJingZ)');
      sql.Add(' from Cloth_Main A inner join Cloth_Sub B on A.MainId=B.Mainid');
      sql.Add(' inner join WFB_MJJY_PB WY on B.SubId=WY.SubId');
      sql.Add(' where isnull(WY.MJStr2,'''')=''未入库'' ');
      sql.Add(' Group by A.ConNo,B.C_CodeName,B.C_Code,A.MainId,B.SubId,B.C_Color,WY.ClothType');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_OrderSel);
    SInitCDSData20(ADOQueryMain,CDS_OrderSel);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmOrderSelRK.Button1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmOrderSelRK.ConNoChange(Sender: TObject);
begin
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,CDS_OrderSel);
  SInitCDSData20(ADOQueryMain,CDS_OrderSel);
end;

procedure TfrmOrderSelRK.Tv2CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  ModalResult:=1;
end;

end.
