unit U_EquipmentkCList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, StdCtrls, ExtCtrls, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData,
  cxButtonEdit, cxDropDownEdit, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView,
  cxGrid, DBClient, ADODB, cxGridCustomPopupMenu, cxGridPopupMenu, cxCheckBox,
  RM_Common, RM_Class, RM_GridReport, RM_System, RM_Dataset, MMSystem, Menus,
  BtnEdit;

type
  TfrmEquipmentkCList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Qty: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    DataSource1: TDataSource;
    CDS_Main: TClientDataSet;
    cxGridPopupMenu1: TcxGridPopupMenu;
    TOk: TToolButton;
    Label7: TLabel;
    ADOQueryPrint: TADOQuery;
    RMDB_Main: TRMDBDataSet;
    RM1: TRMGridReport;
    ADOQueryMain: TADOQuery;
    v1Column16: TcxGridDBColumn;
    Label31: TLabel;
    FactoryName: TEdit;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ToolButton2: TToolButton;
    v1Ssel: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    Label1: TLabel;
    P_CodeName: TEdit;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure P_CodeNameChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TOkClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
  private
    procedure InitGrid();
    procedure SetStatus();
    { Private declarations }
  public
    fCKName, canshu1: string;
    
    { Public declarations }
  end;

var
  frmEquipmentkCList: TfrmEquipmentkCList;

implementation

uses
  U_DataLink, U_Fun10, U_ZDYHelp;
{$R *.dfm}

procedure TfrmEquipmentkCList.SetStatus();
begin
  TOk.Visible := false;
  TOk.Visible := false;
  if Trim(canshu1) = '选择' then
  begin
    TOk.Visible := true;
    v1Ssel.Visible := true;
  end;
  if Trim(canshu1) = '管理' then
  begin
    TOk.Visible := true;
    v1Ssel.Visible := true;
  end;
end;

procedure TfrmEquipmentkCList.InitGrid();
begin
  try
    with adoqueryMain do
    begin
      close;
      sql.Clear;
      sql.Add(' select FactoryName,P_CodeName,KCPS=ISNULL(SUM(X.CRQtyFlag*X.RollNum),0) from CK_Equipment_CR	X ');
      sql.Add(' where Valid=''Y'' and  CKName=''设备''  ');
      sql.ADD(' group by FactoryName,P_CodeName');
      sql.ADD(' having ISNULL(SUM(X.CRQtyFlag*X.RollNum),0)>0 ');

      open;
    end;
    SCreateCDS20(adoqueryMain, CDS_Main);
    SInitCDSData20(adoqueryMain, CDS_Main);
  finally
  end;
end;

procedure TfrmEquipmentkCList.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  writeCxGrid(self.Caption, Tv1, '仓储管理');
  if Trim(canshu1) = '选择' then
    Action := cahide
  else
    Action := cafree;
end;

procedure TfrmEquipmentkCList.FormDestroy(Sender: TObject);
begin
  frmEquipmentkCList := nil;
end;

procedure TfrmEquipmentkCList.P_CodeNameChange(Sender: TObject);
begin
  if adoqueryMain.Active = False then
    Exit;
  SDofilter(adoqueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(adoqueryMain, CDS_Main);
  SInitCDSData20(adoqueryMain, CDS_Main);
end;

procedure TfrmEquipmentkCList.FormShow(Sender: TObject);
begin
  readCxGrid(self.Caption, Tv1, '仓储管理');
  SetStatus();
  InitGrid();
end;

procedure TfrmEquipmentkCList.TBCloseClick(Sender: TObject);
begin
  close;
end;

procedure TfrmEquipmentkCList.TBRafreshClick(Sender: TObject);
begin
  initGrid();
end;

procedure TfrmEquipmentkCList.TBExportClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;
  TcxGridToExcel(self.Caption, cxgrid1);
end;

procedure TfrmEquipmentkCList.TOkClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;
  ModalResult := 1;
end;

procedure TfrmEquipmentkCList.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, true);
end;

procedure TfrmEquipmentkCList.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, false);
end;

procedure TfrmEquipmentkCList.ToolButton2Click(Sender: TObject);
begin
  if adoqueryMain.Active = False then
    Exit;
  SDofilter(adoqueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(adoqueryMain, CDS_Main);
  SInitCDSData20(adoqueryMain, CDS_Main);
end;

end.

