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, cxCheckBox;

type
  TfrmSQKCHZSelList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label2: TLabel;
    CDS_Main: TClientDataSet;
    Label5: TLabel;
    ConNo: TEdit;
    MovePanel2: TMovePanel;
    ToolButton1: TToolButton;
    Label1: TLabel;
    MPRTCodeName: TEdit;
    Label3: TLabel;
    C_Code: TEdit;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column2: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column10: 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 MPRTCodeNameChange(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, FZZType: 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 SUM(A.KGQty) KGQty,SUM(A.Qty) Qty,SUM(A.NetKGQty) NetKGQty,count(A.MJID) JQty,A.QtyUnit,A.CPType,A.ganghao ');
      sql.Add(' ,B.ConNo,B.MainId,C.SubId,B.CustomerNoName,B.OrderNo,B.MPRTCode,B.MPRTCodeName,B.MPRTMF,B.MPRTKZ ,C.PRTColor,C.PRTEColor,C.PRTHX,C.PrtKuanNo');
      sql.Add('from  CK_BanCP_CR A   inner join CK_BanCP_KC D on A.MJID=D.MJID inner join JYOrder_Main B on A.MainId=B.MainId  ');
      sql.Add('inner join JYOrder_Sub C on A.SubId=C.SubId   where A.CRFlag=''入库'' and D.KCValid=''Y'' ');
      sql.Add(' group by  A.QtyUnit,A.CPType,A.ganghao,B.ConNo,B.MainId,C.SubId,B.CustomerNoName,B.OrderNo,B.MPRTCode,B.MPRTCodeName,B.MPRTMF,B.MPRTKZ ,C.PRTColor,C.PRTEColor,C.PRTHX,C.PrtKuanNo');
      Open;
//      ShowMessage(SQL.Text);
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmSQKCHZSelList.TBRafreshClick(Sender: TObject);
begin
  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.MPRTCodeNameChange(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.

