unit U_SelectStuff;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, ADODB, cxSplitter, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses,
  cxControls, cxGridCustomView, cxGrid, cxContainer, cxTreeView, ToolWin,
  cxCheckBox, DBClient, cxGridCustomPopupMenu, cxGridPopupMenu, ImgList,
  ExtCtrls, cxTL, cxMaskEdit, cxInplaceContainer, cxDBTL, cxTLData,
  StdCtrls;

type
  TfrmSelectStuff = class(TForm)
    ToolBar1: TToolBar;
    Trefresh: TToolButton;
    Tclose: TToolButton;
    TreeView1: TcxTreeView;
    Grid1: TcxGrid;
    TV1: TcxGridDBTableView;
    V1name: TcxGridDBColumn;
    V1code: TcxGridDBColumn;
    V1Dept: TcxGridDBColumn;
    V1Duties: TcxGridDBColumn;
    V1Career: TcxGridDBColumn;
    V1InTime: TcxGridDBColumn;
    Grid1Level1: TcxGridLevel;
    cxSplitter1: TcxSplitter;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryMain: TADOQuery;
    DataSource1: TDataSource;
    CDS_Sub: TClientDataSet;
    V1selected: TcxGridDBColumn;
    ToolButton3: TToolButton;
    ADOQuerycmd: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ImageList24: TImageList;
    ADOConnection1: TADOConnection;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle_Active: TcxStyle;
    cxStyle_gridRow: TcxStyle;
    cxStyle_gridFoot: TcxStyle;
    cxStyle_gridHead: TcxStyle;
    cxStyle_gridGroupBox: TcxStyle;
    cxStyle_yellow: TcxStyle;
    cxStyle_Red: TcxStyle;
    cxStyle_group: TcxStyle;
    cxStyle_fontBlue: TcxStyle;
    cxStyle_fontOlive: TcxStyle;
    cxStyle_fontbalck: TcxStyle;
    V1gangwei1: TcxGridDBColumn;
    V1Sex1: TcxGridDBColumn;
    V1Pstatus: TcxGridDBColumn;
    ADOQueryTemp1: TADOQuery;
    ADOQueryTemp2: TADOQuery;
    Panel1: TPanel;
    cxDBTreeList1: TcxDBTreeList;
    cxDBTreeList1cxDBTreeListColumn2: TcxDBTreeListColumn;
    DataSource2: TDataSource;
    ADOQueryTree: TADOQuery;
    Panel2: TPanel;
    lbl1: TLabel;
    Code: TEdit;
    lbl2: TLabel;
    name: TEdit;
    procedure FormShow(Sender: TObject);
    procedure TcloseClick(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure TreeView1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TrefreshClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TV1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure V1nameStylesGetHeaderStyle(Sender: TcxGridTableView;
      AColumn: TcxGridColumn; out AStyle: TcxStyle);
    procedure cxDBTreeList1DblClick(Sender: TObject);
  private
    procedure InitGrid();
    function  TreeFiltered10(ADOQueryTemp:TADOQuery;TreeStr:string):string;
    function  AddData():boolean;
    function  AddData10():Boolean;
    procedure DelData10();
    procedure InitTree10();
    procedure InitTree20();
    procedure InitGrid20(ADOQueryMain:TADOQuery;ADOQueryTree:TADOQuery);
    {procedure InitTree();

    procedure TreeSelect();
    function  GetRoot(node:TTreeNode):TTreeNode;
    procedure TreeFiltered();
    procedure InitChildTree();
    procedure GetRootInt(node:TTreeNode); }
    { Private declarations }
  public
    PState:Integer;
    TreeStr:string;
    TreeFilter:string;
    { Public declarations }
  end;

var
  frmSelectStuff: TfrmSelectStuff;

implementation
uses
  U_FormPas,U_CxGridSet,U_global,U_RSFormPas,U_iniParam,U_SelfForm;

{$R *.dfm}

procedure TfrmSelectStuff.FormShow(Sender: TObject);
begin
  Grid1.Align:=alClient;
  ReadCxGrid(Self.Caption,TV1,'人事考核');
  //InitTree(ADOQueryTemp,TreeView1);
  {if Trim(FormFlag)='2' then
  begin
    cxDBTreeList1.Visible:=True;
    TreeView1.Visible:=False;
    InitTree20();
  end else
  begin
    TreeView1.Visible:=True;
    cxDBTreeList1.Visible:=False;
    InitTree10();
  end;}
  cxDBTreeList1.Visible:=True;
  TreeView1.Visible:=False;
  InitTree20();
end;

procedure TfrmSelectStuff.TcloseClick(Sender: TObject);
begin
  WriteCxGrid(Self.Caption,tv1,'人事考核');
  close;
end;

procedure TfrmSelectStuff.ToolButton3Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then Exit;
  {if AddData() then
  begin
    Application.MessageBox('添加成功~','提示',0);
  end;}
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from AssTemp ');
    Open;
    if RecordCount<1 then
    begin
      Application.MessageBox('没有选择数据！','提示',0);
      Exit;
    end;
  end;
  Application.MessageBox('添加成功~','提示',0);
  frmSelectStuff.Close;
end;
function TfrmSelectStuff.AddData10():Boolean;
begin
  try
    Result:=False;
    ADOQuerycmd.Connection.BeginTrans;
    with ADOQuerycmd do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from AssTemp where 1<>1');
      Open;
    end;
    with ADOQuerycmd do
    begin
      Append;
      FieldByName('code').Value:=Trim(CDS_Sub.fieldbyname('code').asstring);
      FieldByName('name').Value:=Trim(CDS_Sub.fieldbyname('name').asstring);
      FieldByName('Dept').Value:=Trim(CDS_Sub.fieldbyname('Dept').asstring);
      Post;
    end;
    ADOQuerycmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOQuerycmd.Connection.RollbackTrans;
    Application.MessageBox('Asstemp表繁忙，请稍后！','提示',0);
  end;
end;
function TfrmSelectStuff.AddData():Boolean;
begin
  try
    Result:=False;
    ADOQuerycmd.Connection.BeginTrans;
    with ADOQuerycmd do
    begin
      Close;
      SQL.Clear;
      SQL.Add('delete asstemp');
      ExecSQL;
    end;
    with ADOQuerycmd do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from AssTemp where 1<>1');
      Open;
    end;
    if (CDS_Sub.Active) and (CDS_Sub.RecordCount>0) then
    begin
      CDS_Sub.First;
      while not CDS_Sub.Eof do
      begin
        if CDS_Sub.FieldByName('sel').Value=True then
        begin
          with ADOQuerycmd do
          begin
            Append;
            FieldByName('code').Value:=Trim(CDS_Sub.fieldbyname('code').asstring);
            FieldByName('name').Value:=Trim(CDS_Sub.fieldbyname('name').asstring);
            FieldByName('Dept').Value:=Trim(CDS_Sub.fieldbyname('Dept').asstring);
            Post;
          end;
        end;
        CDS_Sub.Next;
      end;
    end;
    if ADOQuerycmd.RecordCount<1 then
    begin
      ADOQuerycmd.Connection.RollbackTrans;
      Exit;
    end;
    ADOQuerycmd.Connection.CommitTrans;
    Result:=True;
    close;
  except
    Result:=False;
    ADOQuerycmd.Connection.RollbackTrans;
    Application.MessageBox('Asstemp表繁忙，请稍后！','提示',0);
  end;
end;



procedure TfrmSelectStuff.ToolButton1Click(Sender: TObject);
begin
  try
    CDS_Sub.DisableControls;
    if (CDS_Sub.Active) and (CDS_Sub.RecordCount>0) then
    begin
      CDS_Sub.First;
      while not CDS_Sub.Eof do
      begin
        CDS_Sub.Edit ;
        CDS_Sub.FieldByName('sel').Value:=True;
        DelData10();
        AddData10();
        CDS_Sub.Next;
      end;
    end;
  finally
    CDS_Sub.EnableControls;
  end;
end;

procedure TfrmSelectStuff.ToolButton2Click(Sender: TObject);
begin
  Try
    if (CDS_Sub.Active) and (CDS_Sub.RecordCount>0) then
    begin
      CDS_Sub.First;
      while not CDS_Sub.Eof do
      begin
        CDS_Sub.Edit ;
        CDS_Sub.FieldByName('sel').Value:=False;
        DelData10();
        CDS_Sub.Next;
      end;
    end;
  finally
  end;
end;
procedure TfrmSelectStuff.InitGrid();
var
  fsj:string;
begin
  try
    fsj:='select YS.Code,YS.Name,YS.Duties,YS.Dept,YF.framename dept1,YSA.Career,'+
                   ' YS.Intime,YSA.PStatus,YSA.StuffType,XC.name gangwei1,XC1.name sex1 from YC_Stuff YS '+
                   ' left join YC_Stuff_Attachment YSA on  YS.code=YSA.code '+
                   ' left join YC_Frame YF on YS.dept=YF.frameno '+
                   ' Left join XC_CustCode XC on YS.gangwei=XC.code and XC.flag=''gangwei'' ' +
                   ' Left join XC_CustCode XC1 on YS.sex=XC1.code and XC1.flag=''sex'' '+
                   ' order by  YSA.PStatus,len(ltrim(rtrim(Ys.code))),ltrim(rtrim(Ys.code)) ';
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      //SQL.Add('Exec P_Select_Yc_Stuff_Main :begindate,:enddate,''0'',0');
      sql.Add(fsj);
      Open;
    end;
    if PState=1 then
    begin
      with ADOQueryTemp do
      begin
        Close;
        SQL.Clear;
        SQL.Add(' select * from XC_CustCOde where name=''在职'' ');
        SQL.Add(' and flag=''PStatus'' ');
        Open;
        TreeFilter:=' PStatus='''+Trim(adoquerytemp.fieldbyname('code').AsString)+'''';
      end;
      Dofilter(ADOQueryMain,TreeFilter);
    end;
    if PState=2 then
    begin
      with ADOQueryTemp do
      begin
        Close;
        SQL.Clear;
        SQL.Add(' select * from  YC_Stuff_Attachment');
        SQL.Add(' where StuffType<>''''');
        Open;
        if IsEmpty then
        begin
          Application.MessageBox('Yc_Stuff_Attachment 表中StuffType值为空,无数据显示','提示',0);
          Exit;
        end;
      end;
      with ADOQueryTemp do
      begin
        Close;
        SQL.Clear;
        SQL.Add(' select * from XC_CustCOde where name=''在职'' ');
        SQL.Add(' and flag=''PStatus'' ');
        Open;
        TreeFilter:=' PStatus='''+Trim(adoquerytemp.fieldbyname('code').AsString)+'''';
      end;
      with ADOQueryTemp do
      begin
        Close;
        SQL.Clear;
        SQL.Add('select * from XC_CustCode where name=''试用'' and flag=''StuffType''');
        Open;
      end;
      TreeFilter:=TreeFilter+' and  StuffType='''+Trim(ADOQueryTemp.fieldbyname('code').AsString)+'''';
      Dofilter(ADOQueryMain,TreeFilter);
      //PState:=0;
    end;
    if PState=3 then
    begin
      with ADOQueryTemp do
      begin
        Close;
        SQL.Clear;
        SQL.Add(' select * from XC_CustCOde where name=''离职'' ');
        SQL.Add(' and flag=''PStatus'' ');
        Open;
        TreeFilter:=' PStatus='''+Trim(adoquerytemp.fieldbyname('code').AsString)+'''';
      end;
      Dofilter(ADOQueryMain,TreeFilter);
    end;
    CreateCDS20(ADOQueryMain,CDS_sub);
    InitCDSData30(ADOQueryMain,CDS_sub);
  finally
    ADOQueryMain.EnableControls;
  end;
end;
procedure TfrmSelectStuff.TreeView1Click(Sender: TObject);
begin
  Panel1.Visible:=True;
  Panel1.Refresh;
  if Trim(ADOQueryMain.SQL.Text)='' then
  begin
    if ((PState=1) or (PState=2))then
    begin
      if TreeView1.Selected.Text<>'所有在职员工' then
      begin
        Exit;
      end;
    end;
    if PState=3 then
    begin
      if TreeView1.Selected.Text<>'所有离职员工' then
      begin
        Exit;
      end;
    end;
    InitGrid();
  end;
  //InitChildTree(ADOQueryTemp,TreeView1);
  //InitChildTree10(ADOQueryTemp,TreeView1);
  if TreeView1.Selected.Parent=nil then
  begin
    TreeStr:=trim(TreeView1.Selected.Text);
    TreeFilter:=TreeSelect(TreeStr,ADOQueryTemp);
  end else
  begin
    if Trim(FormFlag)='2' then
    begin
      InitData30(ADOQueryMain,TreeView1);
      CreateCDS20(ADOQueryMain,CDS_Sub);
      InitCDSData20(ADOQueryMain,CDS_Sub);
    end else
    begin
      TreeStr:=Trim(GetRoot(TreeView1.Selected).Text);
      TreeFilter:=TreeSelect(TreeStr,ADOQueryTemp);
      TreeStr:=Trim(TreeView1.Selected.Text);
      TreeFilter:=TreeFilter+TreeFiltered(ADOQueryTemp,TreeStr);
    end;
    {TreeStr:=Trim(GetRoot(TreeView1.Selected).Text);
    TreeFilter:=TreeSelect(TreeStr,ADOQueryTemp);
    TreeStr:=Trim(TreeView1.Selected.Text);
    TreeFilter:=TreeFilter+TreeFiltered10(ADOQueryTemp,TreeStr);}
  end;
  try
    with CDS_Sub do
    begin
      filtered:=false;
      filter:=TreeFilter;
      filtered:=true;
    end;
  finally
  end;
  Panel1.Visible:=False;
end;
procedure TfrmSelectStuff.InitTree20();
begin
  with ADOQueryTree do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Yc_Frame order by framelevel');
    Open;
  end;
end;
procedure TfrmSelectStuff.InitGrid20(ADOQueryMain:TADOQuery;ADOQueryTree:TADOQuery);
var
  fsj:String;
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      SQL.Clear;
      SQL.Add('exec P_Select_Yc_Stuff_Main20 :FCode,0 ,:Def1,:UserId,:DeptCode');
      if Length(Trim(gDef1))<2 then
      begin
        if Trim(gDef1)<>'' then
          Parameters.ParamByName('Def1').Value:=StrToInt(gDef1);
      end;
      Parameters.ParamByName('UserId').Value:=Trim(gUserID);
      Parameters.ParamByName('DeptCode').Value:=Trim(ADOQueryTree.fieldbyname('frameno').Asstring);
      Open;
    end;
  finally
    ADOQueryMain.EnableControls;
  end;
end;
procedure TfrmSelectStuff.InitTree10();
var
  aNode,FNode:TTreeNode;
  kind,LKind:string;
  i,ii,j,z,hh,kk:Integer;
begin
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from Xc_CustCode where Flag=''PStatus''');
    Open;
  end;
  with ADOQueryTemp do
  begin
    first;
    while not eof  do
    begin
      kind:='所有'+Trim(ADOQueryTemp.FieldByName('name').AsString)+'员工';
      aNode:=TreeView1.Items.AddChild(nil,kind) ;
      with ADOQueryTemp2 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('Select * from Yc_Frame where framelevel=0');
        Open;
      end;
      kind:=Trim(ADOQueryTemp2.FieldByName('framename').AsString);
      aNode:=TreeView1.Items.AddChild(aNode,kind);
      Next;
    end;
  end;
  with ADOQueryTemp1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('Select Max(Framelevel) MaxLevel from Yc_Frame ');
    Open;
    Z:=ADOQueryTemp1.fieldbyname('MaxLevel').AsInteger;
  end;
  for ii:=1 to Z do
  begin
    if ii=4 then TreeView1.TopItem.Expand(True);
    hh:=1;
    while hh=1 do
    begin
      kk:=TreeView1.Items.Count-1;
      for i:=0 to kk do
      begin
        //showmessage(TreeView1.Items.Item[i].Text+InttoStr(TreeView1.Items.Item[i].Level));
        if TreeView1.Items.Item[i].Level=ii then
        begin
          aNode:=TreeView1.Items.Item[i];
          if aNode.HasChildren then Continue;
          with ADOQueryTemp1 do
          begin
            Close;
            SQL.Clear;
            sql.Add('Select * from Yc_Frame where framename='''+Trim(aNode.Text)+'''');
            Open;
            LKind:=Trim(ADOQueryTemp1.fieldbyname('frameno').AsString);
          end;
          with ADOQueryTemp1 do
          begin
            Close;
            SQL.Clear;
            sql.Add('Select * from Yc_Frame where framelevel='+Inttostr(ii));
            sql.Add(' and frametop='''+LKind+'''');
            Open;

          end;
          with ADOQueryTemp1 do
          begin
            if IsEmpty then Continue;
            First;
            j:=0;
            kind:=Trim(ADOQueryTemp1.fieldbyname('framename').AsString);
            aNode:=TreeView1.Items.AddChild(aNode,kind);
            while not eof do
            begin
              if j>0 then
              begin
                kind:=Trim(ADOQueryTemp1.fieldbyname('framename').AsString);
                aNode:=TreeView1.Items.Add(aNode,kind);
              end;
              Next;
              j:=j+1;
            end;
            hh:=1;
            break;
          end;
        end;
        if i=kk then
        begin
          hh:=0;
          Break;
        end;
      end;
    end;
  end;
  //TreeView1.TopItem.Expand(True);
end;
function TfrmSelectStuff.TreeFiltered10(ADOQueryTemp:TADOQuery;TreeStr:string):string;
var
  TreeFilter:string;
begin
  result:='';
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from Yc_Frame where framename='''+TreeStr+'''');
    Open;
    TreeStr:=Trim(fieldbyname('frameNo').AsString);
  end;
  TreeFilter:=' and Dept like'''+'%'+TreeStr+'%'+'''';
  result:=TreeFilter;
end;
{
procedure TfrmSelectStuff.TreeSelect();
begin
   TreeStr:=Copy(TreeStr,5,4);
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from Xc_CustCode where name='''+TreeStr+''' and flag=''PStatus''');
    Open;
    TreeStr:=Trim(fieldbyname('code').AsString);
  end;
  TreeFilter:=' PStatus='''+TreeStr+'''';
end;
function TfrmSelectStuff.GetRoot(node:TTreeNode):TTreeNode;
begin 
  Result:=node;
  while((Result   <>   nil)   and   (Result.Parent   <>   nil))   do
    Result:=   Result.Parent;
end;
procedure TfrmSelectStuff.GetRootInt(node:TTreeNode);
begin
  i:=0;
  while((node<>nil)and(node.Parent<>nil)) do
  begin
    node:=node.Parent;
    i:=i+1;
  end;
end;
procedure TfrmSelectStuff.TreeFiltered();
begin
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from Yc_Frame where framename='''+TreeStr+'''');
    Open;
    TreeStr:=Trim(fieldbyname('frameNo').AsString);
  end;
  TreeFilter:=TreeFilter+' and Dept like '+''''+'%'+TreeStr+'%'+'''';
end; }

procedure TfrmSelectStuff.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  ModalResult:=1;
end;

procedure TfrmSelectStuff.TrefreshClick(Sender: TObject);
var
  fsj:String;
begin
  //InitGrid();
  //SDofilter(ADOQueryMain,SGetFilters(Panel2,1,2));
  if not(CDS_Sub.Active) then Exit;
  fsj:=' code<>''''';
  if Trim(Code.Text)<>'' then
  begin
    fsj:=fsj+' and code='+Quotedstr(Trim(Code.Text));
  end;
  if Trim(name.Text)<>'' then
  begin
    fsj:=fsj+' and name='+Quotedstr(Trim(name.Text));
  end;
  try
    with CDS_Sub do
    begin
      filtered:=false;
      if Trim(fsj)<>'' then
        TreeFilter:=fsj;
      filter:=TreeFilter;
      filtered:=true;
    end;
  finally
  end;
end;

procedure TfrmSelectStuff.FormCreate(Sender: TObject);
begin
  Grid1.Align :=alclient;
  with ADOConnection1 do
  begin
    Connected:=false;
    ConnectionString:=gConString;
    Connected:=true;
  end;
end;

procedure TfrmSelectStuff.TV1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  CDS_Sub.Edit;
  if CDS_Sub.FieldByName('Sel').Value<>True then
  begin
    CDS_Sub.FieldByName('Sel').Value:=True;
    DelData10();
    AddData10();
  end
  else
  begin
    CDS_Sub.FieldByName('Sel').Value:=False;
    DelData10();
  end;
end;
procedure TfrmSelectStuff.DelData10();
begin
  with ADOQuerycmd do
  begin
    Close;
    SQL.Clear;
    SQL.Add('delete AssTemp where code='''+Trim(CDS_Sub.fieldbyname('code').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmSelectStuff.V1nameStylesGetHeaderStyle(
  Sender: TcxGridTableView; AColumn: TcxGridColumn; out AStyle: TcxStyle);
begin
  v1Pstatus.SortOrder:=soAscending;
  v1Code.SortOrder:=TcxDataSortOrder(0);
end;

procedure TfrmSelectStuff.cxDBTreeList1DblClick(Sender: TObject);
var
  fsj:string;
begin
  Panel1.Visible:=True;
  Panel1.Refresh;
  if Trim(ADOQueryMain.SQL.Text)='' then
  begin
    if ((PState=1) or (PState=2))then
    begin
      with ADOQueryTemp do
      begin
        Close;
        sql.Clear;
        SQL.Add('select * from Xc_CustCode where name=''在职'' and flag=''PStatus'' ');
        Open;
        fsj:=Trim(fieldbyname('Code').AsString);
      end;
    end;
    if PState=3 then
    begin
      with ADOQueryTemp do
      begin
        Close;
        sql.Clear;
        SQL.Add('select * from Xc_CustCode where name=''离职'' and flag=''PStatus'' ');
        Open;
        fsj:=Trim(fieldbyname('Code').AsString);
      end;
    end;
  end;
  {if Trim(FormFlag)='2' then
  begin
    InitGrid20(ADOQueryMain,ADOQueryTree);
   // Dofilter(ADOQueryMain,' PStatus='''+fsj+'''');
    CreateCDS20(ADOQueryMain,CDS_Sub);
    InitCDSData20(ADOQueryMain,CDS_Sub);
  end; }
  InitGrid20(ADOQueryMain,ADOQueryTree);
   // Dofilter(ADOQueryMain,' PStatus='''+fsj+'''');
  CreateCDS20(ADOQueryMain,CDS_Sub);
  InitCDSData20(ADOQueryMain,CDS_Sub);

  try
    with CDS_Sub do
    begin
      filtered:=false;
      if Trim(fsj)<>'' then
        TreeFilter:=' PStatus='''+fsj+'''';
      filter:=TreeFilter;
      filtered:=true;
    end;
  finally
  end;
  Panel1.Visible:=False;
end;

end.
