unit U_TradeClothWaitPack;

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, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator, dxDateRanges, dxBarBuiltInMenu, Vcl.ToolWin,
  dxScrollbarAnnotations, cxContainer, cxTextEdit, U_BaseList, cxProgressBar,
  dxSkinsCore, dxSkinWXI;

type
  TfrmTradeClothWaitPack = class(TfrmBaseList)
    Panel1: TPanel;
    Label2: TLabel;
    OrderNo: TcxTextEdit;
    Label3: TLabel;
    C_Color: TcxTextEdit;
    CDS_OrderSel: TClientDataSet;
    DataSource1: TDataSource;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label8: TLabel;
    CustName: TcxTextEdit;
    cxGrid1: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2SSel: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    v1PRTMF: TcxGridDBColumn;
    v1PRTKZ: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v2C_ColorNo: TcxGridDBColumn;
    ToolBar3: TToolBar;
    ToolButton5: TToolButton;
    ToolButton1: TToolButton;
    ToolButton8: TToolButton;
    ToolButton7: TToolButton;
    Tv2Column1: TcxGridDBColumn;
    Tv2Column2: TcxGridDBColumn;
    Tv2Column3: TcxGridDBColumn;
    Tv2Column4: TcxGridDBColumn;
    Tv2Column5: TcxGridDBColumn;
    Tv2C_pattern: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure OrderNoChange(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }

    procedure InitGrid();
  public
    { Public declarations }
  end;

var
  frmTradeClothWaitPack: TfrmTradeClothWaitPack;

implementation

uses
  U_DataLink, U_globalVar, U_RTFun;

{$R *.dfm}

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

procedure TfrmTradeClothWaitPack.FormCreate(Sender: TObject);
begin
  cxGrid1.Align := alClient;
end;

procedure TfrmTradeClothWaitPack.FormDestroy(Sender: TObject);
begin
  frmTradeClothWaitPack := nil;
end;

procedure TfrmTradeClothWaitPack.FormShow(Sender: TObject);
begin
  ReadCxGrid('打包订单选择1', Tv2, gDllFileCaption);
  InitGrid();
end;

procedure TfrmTradeClothWaitPack.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select A.*,B.*');
      sql.Add(',ZPPS=(select Count(KC.StkID) from Trade_Cloth_Stock KC  where KC.StkCycles=0 AND KC.SubID=B.SubID and KC.StkExists=0  ) ');
      sql.Add(',ZPKGQty=(select sum(StkGrossWeight) from Trade_Cloth_Stock KC where KC.StkCycles=0 AND KC.SubID=B.SubID and KC.StkExists=0 ) ');
      sql.Add(',ZPQty=(select sum(StkMeter) from Trade_Cloth_Stock KC where KC.StkCycles=0 AND KC.SubID=B.SubID and KC.StkExists=0 ) ');
      sql.Add(' from Trade_Plan_Main A inner join Trade_Plan_Sub B on A.MainId=B.MainID ');
      sql.Add('where ordtype=''包装单''  and status=''9''');
//      sql.Add(' where exists(select KC.SubID from Trade_Cloth_Stock KC  where KC.StkCycles=0 AND KC.SubID=B.SubID and KC.StkExists=0)');
//      ShowMessage(sql.Text);
      Open;
    end;
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_OrderSel);
    SInitCDSData(ADOQueryMain, CDS_OrderSel);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmTradeClothWaitPack.OrderNoChange(Sender: TObject);
begin
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, CDS_OrderSel);
  SInitCDSData(ADOQueryMain, CDS_OrderSel);
end;

procedure TfrmTradeClothWaitPack.ToolButton1Click(Sender: TObject);
var
  KHName: string;
begin
//  if CDS_OrderSel.Locate('SSel', True, []) = False then
//  begin
//    Application.MessageBox('没有选择数据！', '提示', 0);
//    Exit;
//  end;
//  CDS_OrderSel.DisableControls;
//  KHName := '';
//  with CDS_OrderSel do
//  begin
//    First;
//    while not Eof do
//    begin
//      if FieldByName('SSel').AsBoolean = True then
//      begin
//        if Trim(KHName) = '' then
//        begin
//          KHName := Trim(fieldbyname('CustNo').AsString);
//        end
//        else
//        begin
//          if Trim(fieldbyname('CustNo').AsString) <> KHName then
//          begin
//            Application.MessageBox('不能选择不同客户！', '提示', 0);
//            Exit;
//          end;
//        end;
//      end;
//      Next;
//    end;
//  end;
//  CDS_OrderSel.EnableControls;
  ModalResult := 1;
end;

procedure TfrmTradeClothWaitPack.ToolButton5Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmTradeClothWaitPack.ToolButton7Click(Sender: TObject);
begin

  Close;
end;

procedure TfrmTradeClothWaitPack.ToolButton8Click(Sender: TObject);
begin
  WriteCxGrid('打包订单选择1', Tv2, gDllFileCaption);
end;

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

end.

