unit U_DeptStuffHelp;

interface

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

type
  TfrmDeptStuffHelp = class(TForm)
    ToolBar1: TToolBar;
    BtnOk: TToolButton;
    BtnClose: TToolButton;
    ImageList24: TImageList;
    DataSource1: TDataSource;
    ADOQueryHelp: TADOQuery;
    ADOQueryHelpCode: TStringField;
    ADOQueryHelpName: TStringField;
    ADOConnection1: TADOConnection;
    cxGrid2: TcxGrid;
    tv2: TcxGridDBTableView;
    tv2code: TcxGridDBColumn;
    tv2Name: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    EditName: TEdit;
    Edit1: TEdit;
    frameLeftHelpTree1: TframeLeftHelpTree;
    procedure BtnCloseClick(Sender: TObject);
    procedure BtnOkClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure frameLeftHelpTree1tt1FocusedRecordChanged(
      Sender: TcxCustomGridTableView; APrevFocusedRecord,
      AFocusedRecord: TcxCustomGridRecord;
      ANewItemRecordFocusingChanged: Boolean);
    procedure tv2DblClick(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    procedure InitGrid();
    procedure DoFilter();
  public
    fFrameNo:string;
  end;

var
  frmDeptStuffHelp: TfrmDeptStuffHelp;

implementation
uses
  U_global;
{$R *.dfm}

procedure TfrmDeptStuffHelp.BtnCloseClick(Sender: TObject);
begin
  close;
end;

procedure TfrmDeptStuffHelp.BtnOkClick(Sender: TObject);
begin
  if ADOQueryHelp.IsEmpty  then
    ModalResult:=-1
  else
    ModalResult:=1;
end;

procedure TfrmDeptStuffHelp.FormCreate(Sender: TObject);
begin
  with ADOConnection1 do
  begin
    Connected:=false;
    ConnectionString:=gConString;
    Connected:=true;
  end;
  //业务员树
  frameLeftHelpTree1.InitLTree(ADOQueryHelp,'','USER','印花部','',true);

end;
///////////////////////////////////////////////////
  //
///////////////////////////////////////////////////
procedure TfrmDeptStuffHelp.InitGrid();
begin
  try
    ADOQueryHelp.DisableControls ;
    with ADOQueryHelp do
    begin
      close;
      sql.clear;
      filtered:=false;
      sql.Add('select * from yc_stuff');
      sql.Add('where 1=1');
      if trim(frameLeftHelpTree1.fLeftSelValue)<>'' then
        sql.Add('and dept='+quotedStr(trim(frameLeftHelpTree1.fLeftSelValue)));
      sql.Add('and valid=''Y''');
      sql.Add('order by dept,Name'); 
      Open;
    end;
  finally
    ADOQueryHelp.EnableControls;
  end;
end;

procedure TfrmDeptStuffHelp.frameLeftHelpTree1tt1FocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord;
  ANewItemRecordFocusingChanged: Boolean);
begin
  frameLeftHelpTree1.tt1FocusedRecordChanged(Sender,
  APrevFocusedRecord, AFocusedRecord, ANewItemRecordFocusingChanged);
  InitGrid();
end;

procedure TfrmDeptStuffHelp.tv2DblClick(Sender: TObject);
begin
  btnOk.Click ;
end;
//////////////////////////////////////////
  //函数：过滤
//////////////////////////////////////////
procedure TfrmDeptStuffHelp.DoFilter();
var
  mfilter:string;
begin
  if trim(edit1.text)<>'' then
    mfilter:='code like '+quotedStr('%'+trim(edit1.text)+'%');
  if trim(editName.text)<>'' then
    mfilter:='name like '+quotedStr('%'+trim(editName.text)+'%');
  try
    ADOQueryHelp.DisableControls ;
    with ADOQueryHelp do
    begin
      filtered:=false;
      filter:=mfilter;
      filtered:=true;
    end;
  finally
    ADOQueryHelp.EnableControls ;
  end;

end;
procedure TfrmDeptStuffHelp.Edit1Change(Sender: TObject);
begin
  DoFilter();
end;

procedure TfrmDeptStuffHelp.FormShow(Sender: TObject);
begin
  if trim(fFrameNo)<>'' then
    frameLeftHelpTree1.ADOQueryLTree.Locate('code',fFrameNo,[]);
end;

end.
