unit U_GKManageSel;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin, StdCtrls,
  cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP, ShellAPI, IniFiles, cxCheckBox, cxCalendar, cxButtonEdit,
  cxTextEdit, cxPC, cxCheckComboBox, cxDropDownEdit, Menus, RM_e_Xls,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxDateRanges,
  dxBarBuiltInMenu, U_BaseList, RM_BarCode, dxScrollbarAnnotations, cxContainer,
  cxProgressBar, dxSkinsCore, dxSkinsDefaultPainters;

type
  TfrmGKManageSel = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    TbFilter: TToolButton;
    ADOQueryMain: TADOQuery;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    GPM_1: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Panel1: TPanel;
    Label1: TLabel;
    GKBH: TcxTextEdit;
    Tv2Column4: TcxGridDBColumn;
    Tv2Column10: TcxGridDBColumn;
    Tv2Column1: TcxGridDBColumn;
    Tv2Column3: TcxGridDBColumn;
    Tv2Column5: TcxGridDBColumn;
    Tv2Column6: TcxGridDBColumn;
    Tv2Column7: TcxGridDBColumn;
    Tv2SSel: TcxGridDBColumn;
    Select: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure CustomerChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure MCNOPropertiesChange(Sender: TObject);
    procedure SelectClick(Sender: TObject);

  private
    { Private declarations }
    procedure InitGrid();
  public
    fFlag: integer;
    { Public declarations }
    RKFlag, FCYID, fmanage: string;
  end;

var
  frmGKManageSel: TfrmGKManageSel;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_LabelPrint, U_EmployeeSel;

{$R *.dfm}

procedure TfrmGKManageSel.InitGrid();
begin
  GKBH.SetFocus;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select A.* ');
      sql.Add(' ,kcqty=( select sum(e.IOQtyFlag*e.qty) from Bs_Product_IO e JOIN BS_GK a on e.p_code=a.GKBH where e.stkname=''物料'')');
      SQL.Add(' from  BS_GK A');
//      showmessage(Sql.text);
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_HZ);
    SInitCDSData(ADOQueryMain, CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
    TbFilter.Click;
  end;
end;

procedure TfrmGKManageSel.MCNOPropertiesChange(Sender: TObject);
var
  sql: string;
begin
  if ADOQueryMain.Active then
  begin
    sql := SGetFilters(Panel1, 1, 2);
    SDofilter(ADOQueryMain, sql);
    SCreateCDS(ADOQueryMain, CDS_HZ);
    SInitCDSData(ADOQueryMain, CDS_HZ);
  end;
end;

procedure TfrmGKManageSel.FormDestroy(Sender: TObject);
begin
  inherited;
  frmGKManageSel := nil;
end;

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

procedure TfrmGKManageSel.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(Trim(Self.Caption), Tv2, '钢筘信息选择');
  Close;
end;

procedure TfrmGKManageSel.FormShow(Sender: TObject);
begin
  inherited;
//  ReadCxGrid(Trim(Self.Caption), Tv2, '钢筘信息选择');
  InitGrid();
end;

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

procedure TfrmGKManageSel.cxTabControl1Change(Sender: TObject);
begin
  InitGrid;
end;

procedure TfrmGKManageSel.N1Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  SelOKNo(CDS_HZ, True);
end;

procedure TfrmGKManageSel.N2Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  SelOKNo(CDS_HZ, False);
end;

procedure TfrmGKManageSel.SelectClick(Sender: TObject);
begin
  inherited;
  if CDS_HZ.Locate('ssel', True, []) = False then
  begin
    Application.MessageBox('请选择数据！', '提示信息', MB_OK);
    exit;
  end;
  ModalResult := 1;
end;

procedure TfrmGKManageSel.CustomerChange(Sender: TObject);
begin
  TbFilter.Click;
end;

procedure TfrmGKManageSel.FormCreate(Sender: TObject);
begin
  inherited;
  fmanage := Trim(DParameters1);
end;

end.

