unit U_ShaKCHZList;

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, cxCheckBox, RM_Common, RM_Class, RM_e_Xls, RM_Dataset,
  RM_System, RM_GridReport, Menus, cxCalendar, cxButtonEdit, cxTextEdit;

type
  TfrmShaKCHZList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v2Column1: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    Label3: TLabel;
    Label8: TLabel;
    SPName: TEdit;
    SPSpec: TEdit;
    ToolButton2: TToolButton;
    v1Column17: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    Label2: TLabel;
    BatchNo: TEdit;
    v1Column19: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    v1Column22: TcxGridDBColumn;
    v1FactoryName: TcxGridDBColumn;
    Label9: TLabel;
    FactoryName: 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 MPRTCodeNameChange(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure SXBatchNOChange(Sender: TObject);
    procedure FactoryNameChange(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton2Click(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmShaKCHZList: TfrmShaKCHZList;

implementation

uses
  U_DataLink, U_RTFun, U_ShaOutList, U_ShaKCList;

{$R *.dfm}

procedure TfrmShaKCHZList.FormDestroy(Sender: TObject);
begin
  frmShaKCHZList := nil;
end;

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

procedure TfrmShaKCHZList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' select SPName,SPSpec,BatchNo,FactoryName');
      sql.Add(' ,RKPiQty=Sum(isnull(PiQty,0)),RKQty=Sum(isnull(Qty,0))');
      sql.Add(' ,KCPiQty=Sum(isnull(MXKCPiQty,0)),KCQty=Sum(isnull(MXKCQty,0))');
      sql.Add(' ,CKPiQty=Sum(isnull(PiQty,0))-Sum(isnull(MXKCPiQty,0)),CKQty=Sum(isnull(Qty,0))-Sum(isnull(MXKCQty,0))');
      sql.Add(' from CK_SXPB_CR A where isnull(CKName,'''')=''纱线'' ');
      SQL.Add(' and A.CRFlag=''入库'' and MXKCQty>0 and ZFFlag=0 ');
      SQL.Add(' Group by SPName,SPSpec,BatchNo,FactoryName');
      Open;
      //ShowMessage(SQL.Text);
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmShaKCHZList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

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

procedure TfrmShaKCHZList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('纱线库存汇总列表111', Tv1, '纱线仓库');
  Close;
end;

procedure TfrmShaKCHZList.FormShow(Sender: TObject);
begin
  ReadCxGrid('纱线库存汇总列表111', Tv1, '纱线仓库');
  //InitGrid();
end;

procedure TfrmShaKCHZList.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 TfrmShaKCHZList.MPRTCodeNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmShaKCHZList.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, True);
end;

procedure TfrmShaKCHZList.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, False);
end;

procedure TfrmShaKCHZList.SXBatchNOChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmShaKCHZList.FactoryNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmShaKCHZList.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  try
    frmShaKCList := TfrmShaKCList.Create(Application);
    with frmShaKCList do
    begin
      frmShaKCList.Align := alClient;
      FDYFlag := '99';
      frmShaKCList.Y_CodeName.Text := Trim(Self.CDS_Main.fieldbyname('Y_CodeName').AsString);
      frmShaKCList.Y_Spec.Text := Trim(Self.CDS_Main.fieldbyname('Y_Spec').AsString);
      frmShaKCList.BatchNo.Text := Trim(Self.CDS_Main.fieldbyname('BatchNo').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmShaKCList.Free;
  end;
end;

procedure TfrmShaKCHZList.ToolButton2Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  TcxGridToExcel('纱线库存汇总列表111', cxGrid2);
end;

end.

