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, 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;
    Label4: TLabel;
    C_Code: TEdit;
    Label2: TLabel;
    CDS_Main: TClientDataSet;
    Tv1: TcxGridDBTableView;
    cxGrid2Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    v2Column1: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    Label5: TLabel;
    ConNo: TEdit;
    v1Column6: TcxGridDBColumn;
    MovePanel2: TMovePanel;
    v1Column7: TcxGridDBColumn;
    ToolButton1: TToolButton;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Label1: TLabel;
    C_CodeName: TEdit;
    Label3: TLabel;
    KHName: TEdit;
    Tv1Column3: TcxGridDBColumn;
    Label6: TLabel;
    C_Spec: 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 A.* ,C.C_CodeName,C.C_Code,C.MFQty,C.KZQty,C.C_Spec,C.PiKgQty,D.KHName,C.C_Spec');
      sql.Add(' ,D.ConNo,D.ConMainId,D.ConSubId,C.BatchNoHZ,D.GCCode');
      sql.Add(' from(');
      sql.Add(' select Sum(KCKgQty) KCKgQty,count(*) JQty,PB.MainId,PB.SubId ');
      sql.Add(' from CK_PBCP_KC KC ');
      sql.Add(' inner join WFB_MJJY_PB PB on KC.MJID=PB.MJID ');
      sql.Add('inner join  CK_PBCP_CR A on KC.CRID=A.CRID and A.CRFlag=''入库''  ');
      sql.Add(' where  KC.KCKGQty>0 ');
      sql.Add(' group by PB.MainId,PB.SubId');
      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');
//      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('发货申请专用sel1', Tv1, '坯布仓库');
  Close;
end;

procedure TfrmSQKCHZSelList.FormShow(Sender: TObject);
begin
  ReadCxGrid('发货申请专用sel1', 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.

