unit U_BMSel;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, ToolWin, ComCtrls, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGrid, DBClient, ADODB, ImgList, StdCtrls, ExtCtrls,
  cxTextEdit, cxGridCustomPopupMenu, cxGridPopupMenu, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator;

type
  TfrmBMSel = class(TForm)
    TV1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    V1Code: TcxGridDBColumn;
    V1Name: TcxGridDBColumn;
    ToolBar1: TToolBar;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DataSource1: TDataSource;
    ClientDataSet1: TClientDataSet;
    TBClose: TToolButton;
    ToolButton1: TToolButton;
    ADOConnection1: TADOConnection;
    Panel1: TPanel;
    ThreeImgList: TImageList;
    cxGridPopupMenu1: TcxGridPopupMenu;
    V1Column1: TcxGridDBColumn;
    Label2: TLabel;
    Udept: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure UserNameChange(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure TV1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
  private
    procedure InitGrid();
    { Private declarations }
  public
    sql_str: string;
    flag, flagname, snote, MainType: string;
    fnote, forderno, fZdyFlag, ViewFlag, fnote1: Boolean;
    PPSTE: integer;
    { Public declarations }
  end;

var
  frmBMSel: TfrmBMSel;

implementation

uses
  U_DataLink, U_Fun10, U_ZDYHelp;

{$R *.dfm}

procedure TfrmBMSel.FormCreate(Sender: TObject);
begin
  try
    cxGrid1.Align := alClient;
    with Self.ADOConnection1 do
    begin
      Connected := false;
      ConnectionString := DConString;
      //ConnectionString:='';
      Connected := true;
    end;
  except
    frmBMSel.Free;
  end;
end;

procedure TfrmBMSel.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Udept.SetFocus;
  Action := caHide;
end;

procedure TfrmBMSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select DISTINCT Udept from SY_User where ISNULL(Udept, '''') <> '''' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet1);
    SInitCDSData20(ADOQueryMain, ClientDataSet1);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

procedure TfrmBMSel.FormShow(Sender: TObject);
begin
  frmBMSel.Caption := Trim(flagname);
  InitGrid();
end;

procedure TfrmBMSel.ToolButton1Click(Sender: TObject);
begin
  ModalResult := 1;
end;

procedure TfrmBMSel.UserNameChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, ClientDataSet1);
    SInitCDSData20(ADOQueryMain, ClientDataSet1);
  end;
end;

procedure TfrmBMSel.FormDestroy(Sender: TObject);
begin
  frmBMSel := nil;
end;

procedure TfrmBMSel.TV1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  ToolButton1.Click;
end;

end.

