unit U_SQKCHZSelList;

interface

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

type
  TfrmSQKCHZSelList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label4: TLabel;
    C_Spec: TEdit;
    Label2: TLabel;
    CDS_Main: TClientDataSet;
    Tv1: TcxGridDBTableView;
    cxGrid2Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    Label5: TLabel;
    ConNo: TEdit;
    v1Column6: TcxGridDBColumn;
    Label7: TLabel;
    v1Column3: TcxGridDBColumn;
    MovePanel2: TMovePanel;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    Label6: TLabel;
    MJStr3: TComboBox;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    ToolButton1: TToolButton;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    Label1: TLabel;
    BatchNoHZ: TEdit;
    Label3: TLabel;
    GCCode: TEdit;
    ClothType: TComboBox;
    v1Column12: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure C_CodeNameChange(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton1Click(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
    FCode,FClothType,FSeBie:String;
  end;

var
  frmSQKCHZSelList: TfrmSQKCHZSelList;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp,U_JYMXInfo;

{$R *.dfm}

procedure TfrmSQKCHZSelList.FormDestroy(Sender: TObject);
begin
  frmSQKCHZSelList:=nil;
end;

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

procedure TfrmSQKCHZSelList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select A.* ,C.C_CodeName,C.C_Code,C.MFQty,C.KZQty,C.C_Spec,C.PiKgQty');
      sql.Add(' ,D.ConNo,XSConNo=E.ConNo,KHName=E.CustomerNoName,D.ConMainId,D.ConSubId,C.BatchNoHZ,D.GCCode');
      sql.Add(' from(');
      sql.Add(' select Sum(KCKgQty) KCKgQty,count(*) JQty,PB.MainId,PB.SubId,PB.ClothType ');       //,MJStr3=isnull(PB.MJStr3,'''')
      sql.Add(' from CK_PBCP_KC KC ');
      sql.Add(' inner join WFB_MJJY_PB PB on KC.MJID=PB.MJID ');
      sql.Add(' inner join Cloth_Sub CS on PB.SubId=CS.SubId');
      sql.Add(' where  KC.KCKGQty>0 and CS.C_Code='''+Trim(FCode)+'''');
      if Trim(FClothType)<>'' then
      begin
        sql.Add(' and isnull(PB.Cloth_Type,'''')='''+Trim(FClothType)+'''');
      end;
      if Trim(FSeBie)<>'' then
      begin
        sql.Add(' and isnull(PB.MJStr3,'''')='''+Trim(FSeBie)+'''');
      end;
      sql.Add(' group by PB.MainId,PB.SubId,PB.ClothType');       //,isnull(PB.MJStr3,'''')
      sql.Add(' )A');
      Sql.add(' inner join Cloth_Sub C on A.MainId=C.MainId');
      sql.Add(' inner join Cloth_Main D on A.Mainid=D.Mainid');
      sql.Add(' inner join JYOrderCon_Main_PB E on D.ConMainId=E.MainId');
      Open;
//      ShowMessage(SQL.Text);
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmSQKCHZSelList.TBRafreshClick(Sender: TObject);
begin
  //BegDate.SetFocus;
  MovePanel2.Visible:=True;
  MovePanel2.Refresh;
  InitGrid();
  MovePanel2.Visible:=False;
end;

procedure TfrmSQKCHZSelList.ConNoMChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  end;
end;

procedure TfrmSQKCHZSelList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('发货申请专用',Tv1,'坯布仓库');
  Close;
end;

procedure TfrmSQKCHZSelList.FormShow(Sender: TObject);
begin
  ReadCxGrid('发货申请专用',Tv1,'坯布仓库');
  InitGrid();
end;

procedure TfrmSQKCHZSelList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmSQKCHZSelList.C_CodeNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmSQKCHZSelList.Tv1CellDblClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
//  try
//    frmJYMXInfo:=TfrmJYMXInfo.Create(Application);
//    with frmJYMXInfo do
//    begin
//      FFMainId:=Trim(self.CDS_Main.fieldbyname('MainId').AsString);
//      FFClothType:=Trim(self.CDS_Main.fieldbyname('ClothType').AsString);
//      if ShowModal=1 then
//      begin
//
//      end;
//    end;
//  finally
//    frmJYMXInfo.Free;
//  end;
end;

procedure TfrmSQKCHZSelList.ToolButton1Click(Sender: TObject);
begin
  ModalResult:=1;
end;

end.
