unit U_QryBSPrtDyeEJStkList;

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
  TfrmQryBSPrtDyeEJStkList = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    CDS_HZ: TClientDataSet;
    PopupMenu1: TPopupMenu;
    ToolButton1: TToolButton;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v2Column1: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    dxLayoutControl_query: TdxLayoutControl;
    cxTextEdit1: TcxTextEdit;
    cxTextEdit2: TcxTextEdit;
    cxTextEdit3: TcxTextEdit;
    dxLayoutControl_queryGroup_Root: TdxLayoutGroup;
    dxLayoutItem2: TdxLayoutItem;
    dxLayoutItem3: TdxLayoutItem;
    dxLayoutItem1: TdxLayoutItem;
    ToolButton4: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure cxTextEdit1KeyPress(Sender: TObject; var Key: Char);
  private
    fWindowDesign: TWindowFormdesign;
    fDesignCode:string;
    procedure InitGrid();
    { Private declarations }
  public
    canshu1, FSTKName, canshu3: string;
    { Public declarations }
  end;

var
  frmQryBSPrtDyeEJStkList: TfrmQryBSPrtDyeEJStkList;

implementation

uses
   U_RTFun, U_globalVar, U_dataLink, U_FormLayOutDesign,
  U_LabelPrint,U_cxGridCustomSet, U_ZDYHelp;

{$R *.dfm}

procedure TfrmQryBSPrtDyeEJStkList.FormDestroy(Sender: TObject);
begin
  inherited;
  frmQryBSPrtDyeEJStkList := nil;
end;

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

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

procedure TfrmQryBSPrtDyeEJStkList.FormCreate(Sender: TObject);
begin
  inherited;
  canshu1 := Trim(self.fParameters1);
  FSTKName := Trim(self.fParameters2);
  canshu3 := Trim(self.fParameters3);
end;

procedure TfrmQryBSPrtDyeEJStkList.InitGrid();
var
  mSqlWhere: string;
begin
  mSqlWhere := SLGetFilters(dxLayoutControl_query, 1, 2);
  if trim(mSqlWhere) <> '' then
  begin
    mSqlWhere := ' and ' + trim(mSqlWhere);
  end;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' select    P_Code,P_Name,P_Spec,BatchNo,SUM(IOQtyFlag*Qty)StkQty,SUM(IOQtyFlag*Qty/1000)StkQtyKG,money=sum(IOQtyFlag*price*Qty) ');
      SQL.Add(' ,p_type=(select p_type from Bs_Product_Info e where e.C_SCcode=a.p_code)');

      sql.Add(' from BS_Product_IO A    ');
      sql.Add(' where isnull(stkName,'''')=''' + Trim(FstkName) + '''');
      SQL.Add(Trim(mSqlWhere));
      SQL.Add('GROUP BY   P_Code,P_Name,P_Spec,BatchNo');
      sql.add('having sum(IOQtyFlag*Qty)>0');

      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_Main);
    SInitCDSData(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

procedure TfrmQryBSPrtDyeEJStkList.TBCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmQryBSPrtDyeEJStkList.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(trim(Self.Caption), Tv1, '机物料仓库');
  InitGrid();
end;

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

procedure TfrmQryBSPrtDyeEJStkList.ToolButton2Click(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 TfrmQryBSPrtDyeEJStkList.ToolButton3Click(Sender: TObject);
begin
  inherited;
  if ADOQueryMain.IsEmpty then
    exit;
  TcxGridToExcel(trim(self.Caption), cxGrid2);
end;

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

procedure TfrmQryBSPrtDyeEJStkList.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  ModalResult := 1;
end;

end.

