unit U_LeftHelptree;

interface

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

type
  TframeLeftHelpTree = class(TFrame)
    cxGridt1: TcxGrid;
    tt1: TcxGridDBTableView;
    tt1codeName: TcxGridDBColumn;
    cleveltt1: TcxGridLevel;
    DS_LTree: TDataSource;
    ADOQueryLTree: TADOQuery;
    Panel1: TPanel;
    tt1ParentCodeName: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    cxStyle_gridRow: TcxStyle;
    cxStyle_gridFoot: TcxStyle;
    cxStyle_gridHead: TcxStyle;
    cxStyle_gridGroupBox: TcxStyle;
    cxStyle_yellow: TcxStyle;
    cxStyle_Red: TcxStyle;
    cxStyle_fontred: TcxStyle;
    cxStyle_fontBlue: TcxStyle;
    ComboBox1: TComboBox;
    Edit1: TEdit;
    procedure tt1FocusedRecordChanged(Sender: TcxCustomGridTableView;
      APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord;
      ANewItemRecordFocusingChanged: Boolean);
    procedure Edit1Change(Sender: TObject);
  private
    { Private declarations }
  public
    fLeftSelValue:string;
    fLeftSelCaption:string;
    procedure DoLeftFilter();
    procedure InitLTree(fromADOQ:TADOQuery;mTreeCaption:string;
                        mTreeKind,mTreeFlag,mOtherWhere:string;autoExpand:boolean);
  end;

implementation

{$R *.dfm}
/////////////////////////////////////////
   //�������ܣ���ʼ������
   //��ʾ��ʽ��
   //mTreeCaption:������
   //mTreeKind �ͻ���Ա������̨����
   //mTreeFlag; ���ֿͻ����ľ�����ű�־
   //mOtherWhere:������������
   //autoExpand�����Ƿ��Զ�չ��
/////////////////////////////////////////
procedure TframeLeftHelpTree.InitLTree(fromADOQ:TADOQuery;mTreeCaption:string;
                                         mTreeKind,mTreeFlag,mOtherWhere:string;autoExpand:boolean);
begin
 {
  if mTreeCaption<>'' then
  begin
    Panel1.caption:=trim(mTreeCaption);
    Panel1.Visible :=true;
  end;
  }
 //if autoExpand  then
   TT1.DataController.Options:=[dcoGroupsAlwaysExpanded];
 //else
  // TT1.DataController.Options:=[];
  try
    ADOQueryLTree.Connection:=fromADOQ.Connection;
    ADOQueryLTree.DisableControls ;
    with ADOQueryLTree do
    begin
      close;
      sql.clear;
      sql.Add('exec P_Get_WinLeftTree');
      sql.Add(quotedStr(mTreeKind));
      sql.Add(','+quotedStr(mTreeflag));
      sql.Add(','+quotedStr(mOtherWhere));
      Open;
    end;
    ADOQueryLTree.EnableControls;
  except
    application.MessageBox(pchar('��ʼ����'+mTreeCaption+'����ʧ��!'),'������Ϣ',0);
  end;
end;
procedure TframeLeftHelpTree.tt1FocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord;
  ANewItemRecordFocusingChanged: Boolean);
begin
  if (tt1.Controller.FocusedRow is TcxGridGroupRow) then
  begin
    fLeftSelValue:='';
    fLeftSelCaption:='';
  end
  else
  begin
    fLeftSelValue:=trim(ADOQueryLTree.fieldByName('code').AsString) ;
    fLeftSelCaption:=trim(ADOQueryLTree.fieldByName('codeName').AsString) ;
  end;
end;
///////////////////////////////////////////////////////////////
procedure TframeLeftHelpTree.DoLeftFilter();
var
  mfilterStr:string;
begin
  //����
  if (ComboBox1.ItemIndex=0) and (trim(edit1.Text) <>'') then
  begin
    mfilterStr:='codeName like '+quotedStr('%'+trim(edit1.Text)+'%');
  end;
  //���
  if (ComboBox1.ItemIndex=1) and (trim(edit1.Text) <>'') then
  begin
    mfilterStr:='code like '+quotedStr('%'+trim(edit1.Text)+'%');
  end;
  try
    ADOQueryLTree.DisableControls ;
    with ADOQueryLTree do
    begin
      filtered:=false;
      if trim(mfilterStr)<>'' then
      begin
        filter:=mfilterStr;
        filtered:=true;
      end;
    end;
  finally
    ADOQueryLTree.EnableControls;
  end;
end;

procedure TframeLeftHelpTree.Edit1Change(Sender: TObject);
begin
  DoLeftFilter();
end;

end.