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, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator;

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_CodeName: TEdit;
    Label2: TLabel;
    CDS_Main: TClientDataSet;
    Tv1: TcxGridDBTableView;
    cxGrid2Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    v2Column1: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    Label5: TLabel;
    C_Code: TEdit;
    v1Column6: TcxGridDBColumn;
    MovePanel2: TMovePanel;
    v1Column7: TcxGridDBColumn;
    ToolButton1: TToolButton;
    Tv1Column1: TcxGridDBColumn;
    Label1: TLabel;
    conno: TEdit;
    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 Sum(KCKgQty) KCKgQty,count(*) JQty,');
//      SQL.Add('C.C_CodeName,C.C_Code  ');
//      SQL.Add(' from CK_PBCP_KC KC inner join WFB_MJJY_PB PB on KC.MJID=PB.MJID ');  //inner join  CK_PBCP_CR A on KC.CRID=A.CRID and A.CRFlag=''入库''
//      SQL.Add(' inner join Cloth_Sub C on pb.MainId=C.MainId    where  KC.KCKGQty>0 GROUP BY C.C_CodeName,C.C_Code   ');
      SQL.Add('SELECT * FROM V_FHSQ_KCSEL');
//      ShowMessage(SQL.Text);
      Open;

    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('发货申请专用sel', Tv1, '坯布仓库9');
  Close;
end;

procedure TfrmSQKCHZSelList.FormShow(Sender: TObject);
begin
  ReadCxGrid('发货申请专用sel', Tv1, '坯布仓库9');
  InitGrid();
  TBFind.Click();
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.

