unit U_QryBSPrtDyeStkList;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  Vcl.ComCtrls, Vcl.ToolWin, cxGraphics, cxControls, cxLookAndFeels, cxContainer,
  cxEdit, dxLayoutcxEditAdapters, dxBarBuiltInMenu, cxPC, dxLayoutContainer,
  cxClasses, cxTextEdit, dxLayoutControl, cxStyles, cxCustomData, cxFilter,
  cxData, cxDataStorage, cxNavigator, dxDateRanges, dxScrollbarAnnotations,
  Data.DB, cxDBData, cxCalendar, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGridCustomView, cxGrid, U_BaseList,
  Data.Win.ADODB, cxGridCustomPopupMenu, cxGridPopupMenu, Datasnap.DBClient,
  cxCheckBox, cxButtonEdit, cxSplitter, dxCore, cxDateUtils, cxMaskEdit,
  cxDropDownEdit, cxProgressBar, Vcl.Menus, RM_Common, RM_Class, RM_GridReport,
  RM_Dataset, cxLookAndFeelPainters, Vcl.ExtCtrls, dxSkinsCore,
  dxSkinsDefaultPainters, dxLayoutControlAdapters, FrameDateSel10, Vcl.StdCtrls,
  MovePanel, cxCurrencyEdit, U_WindowFormdesign, BtnEdit, dxSkinWXI;

type
  TfrmQryBSPrtDyeStkList = class(TfrmBaseList)
    ToolBar3: TToolBar;
    Trefresh: TToolButton;
    TsaveGrid: TToolButton;
    Tclose: TToolButton;
    DataSource1: TDataSource;
    ADOQueryList: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    dxLayoutControl_query: TdxLayoutControl;
    dxLayoutControl_queryGroup_Root: TdxLayoutGroup;
    CDS_List: TClientDataSet;
    cxProgressBar1: TMovePanel;
    ADOQueryCmd: TADOQuery;
    ToolButton1: TToolButton;
    TBexcpet: TToolButton;
    TgridSet: TToolButton;
    P_Name: TcxTextEdit;
    dxLayoutItem2: TdxLayoutItem;
    P_Spec: TcxTextEdit;
    dxLayoutItem3: TdxLayoutItem;
    ADOQueryTemp: TADOQuery;
    BatchNo: TcxTextEdit;
    dxLayoutItem1: TdxLayoutItem;
    P_Code: TcxTextEdit;
    dxLayoutItem4: TdxLayoutItem;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column14: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    Tv1Column3: TcxGridDBColumn;
    procedure TrefreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TcloseClick(Sender: TObject);
    procedure TsaveGridClick(Sender: TObject);
    procedure dxLayoutControl_queryDblClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure TBexcpetClick(Sender: TObject);
    procedure TgridSetClick(Sender: TObject);
    procedure P_CodeKeyPress(Sender: TObject; var Key: Char);

  private
    fWindowDesign: TWindowFormdesign;
    fDesignCode: string;
    procedure initGrid();
    procedure initForm();
  protected
  public
    canshu1, FSTKName, canshu3: string;
  end;

var
  frmQryBSPrtDyeStkList: TfrmQryBSPrtDyeStkList;

implementation

uses
  U_RTFun, U_globalVar, U_dataLink, U_FormLayOutDesign, U_LabelPrint,
  U_cxGridCustomSet, U_PrtDyeInfoInPut, U_ZDYHelp;
{$R *.dfm}

procedure TfrmQryBSPrtDyeStkList.TsaveGridClick(Sender: TObject);
begin
  WriteCxGrid(trim(self.Caption) + 'Tv1', Tv1, gDllFileCaption);
  if gIsCanDesign then
  begin
    saveLayOut(application, dxLayoutControl_query, ADOQueryCmd, PWideChar(fDllFileName + '|' + Self.Name + '|' + dxLayoutControl_query.Name + '.ini'));
  end;
end;

procedure TfrmQryBSPrtDyeStkList.ToolButton1Click(Sender: TObject);
begin
  if CDS_List.IsEmpty then
    Exit;
  if CDS_List.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  ModalResult := 1;
end;

procedure TfrmQryBSPrtDyeStkList.TBexcpetClick(Sender: TObject);
begin
  if CDS_List.IsEmpty then
    exit;
  TcxGridToExcel(self.Caption, cxGrid2);
end;

procedure TfrmQryBSPrtDyeStkList.TcloseClick(Sender: TObject);
begin
  close;
end;

procedure TfrmQryBSPrtDyeStkList.TgridSetClick(Sender: TObject);
begin
  fWindowDesign.OpenGridDesignWin10(fDesignCode, 'cxgrid2', tv1);
end;

procedure TfrmQryBSPrtDyeStkList.TrefreshClick(Sender: TObject);
begin
  inherited;
  initGrid();
end;

procedure TfrmQryBSPrtDyeStkList.cxTabControl1Change(Sender: TObject);
begin
  inherited;
  initGrid();
end;

procedure TfrmQryBSPrtDyeStkList.dxLayoutControl_queryDblClick(Sender: TObject);
begin
  layoutDesign(TdxLayoutControl(Sender), ADOQueryCmd, PWideChar(dcode));
end;

procedure TfrmQryBSPrtDyeStkList.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  Action := cafree;
end;

procedure TfrmQryBSPrtDyeStkList.FormCreate(Sender: TObject);
begin
  inherited;
  cxgrid2.Align := alClient;
  canshu1 := Trim(Self.fParameters1);
  FSTKName := Trim(Self.fParameters2);
  canshu3 := Trim(Self.fParameters3);
end;

procedure TfrmQryBSPrtDyeStkList.FormDestroy(Sender: TObject);
begin
  inherited;
  frmQryBSPrtDyeStkList := nil;
end;

procedure TfrmQryBSPrtDyeStkList.FormShow(Sender: TObject);
begin
  inherited;
  InitForm();
end;

procedure TfrmQryBSPrtDyeStkList.InitForm();
begin
  addQryContionByLay(ADOQueryBaseTemp, fformId, 'cxgrid2', dxLayoutControl_query, 7);
  ReadCxGrid(trim(self.Caption) + 'Tv1', Tv1, gDllFileCaption);
  InitGrid();
end;

procedure TfrmQryBSPrtDyeStkList.InitGrid();
var
  mSqlWhere: string;
begin
  mSqlWhere := SLGetFilters(dxLayoutControl_query, 1, 2);
  if trim(mSqlWhere) <> '' then
  begin
    mSqlWhere := ' and ' + trim(mSqlWhere);
  end;
  try
    ADOQueryList.DisableControls;
    with ADOQueryList do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' select   XH,price,P_Code,P_Name,P_Spec,BatchNo,SUM(StkQty)StkQty,QtyUnit,money=sum(price*StkQty) ');
      SQL.Add(' ,p_type=(select p_type from Bs_Product_Info e where e.p_code=a.p_code)');
      sql.Add(' from BS_Product_IO A    ');
      SQL.Add(' where A.IOFlag=''入库'' and  isnull(StkQty,0)>0   ');
      SQL.Add(Trim(mSqlWhere));
      sql.Add(' and isnull(stkName,'''')=''' + Trim(FstkName) + '''');
      SQL.Add('GROUP BY  XH,price,P_Code,P_Name,P_Spec,BatchNo, QtyUnit');
//      showmessage(Sql.text);
      Open;
    end;
    SCreateCDS(ADOQueryList, CDS_List);
    SInitCDSData(ADOQueryList, CDS_List);
  finally
    ADOQueryList.EnableControls;
  end;
end;

procedure TfrmQryBSPrtDyeStkList.P_CodeKeyPress(Sender: TObject; var Key: Char);
begin
  inherited;
  if Key = #13 then
  begin
    initGrid();
  end;
end;

end.

