unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, RzLstBox, RzChkLst, DB, MemDS, DBAccess, Uni, ComCtrls,
RzTreeVw, SQLServerUniProvider;
type
TForm1 = class(TForm)
UniConnection1: TUniConnection;
UniQuery1: TUniQuery;
Button1: TButton;
RzCheckTree1: TRzCheckTree;
UniQuery2: TUniQuery;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
const
DivNum = 2;
var
nLevel: Integer;
operid :string;
pNodes: array[0..4095] of TTreeNode; //4K字节
tClassID, tmpClassID, tClassName: string;
i,j:integer;
begin
operid := 'system';
//所有权限
with UniQuery1 do
begin
sql.Text := 'Select a.CLASSID, a.CLASSName, a.ParentClassID, b.ClassID TClassID from CLASSDA001 a ';
sql.Text := sql.Text + 'LEFT OUTER JOIN ';
sql.Text := sql.Text + '(SELECT * FROM classpower001 WHERE OPERATID = ''system'') b ON a.CLASSID = b.ClassID ORDER BY a.CLASSID ';
try
open;
//showmessage(sql.Text);
RzCheckTree1.Items.Clear;
RzCheckTree1.Items.BeginUpdate;
pNodes[0] := RzCheckTree1.Items.Add(nil, '商品类别');
//pNodes[0].ImageIndex := 0; pNodes[0].SelectedIndex := 0;
i := 0;
if Not UniQuery1.IsEmpty then begin j := UniQuery1.RecordCount;
while not UniQuery1.Eof do
//for i := 1 to j do
begin
tClassID := UniQuery1.fieldbyName('CLASSID').AsString;
tClassName := UniQuery1.fieldbyName('CLASSNAME').AsString;
tmpClassID := UniQuery1.fieldbyName('TCLASSID').AsString;
nLevel := Length(tClassID) div DivNum ;
pNodes[nLevel] := RzCheckTree1.Items.AddChild(pNodes[nLevel - 1], tClassID + ' - ' + tClassName);
//打钩
i := i+1;
if tClassID = tmpClassID then
RzCheckTree1.ItemState[i] := csChecked
else
RzCheckTree1.ItemState[i] := csUnchecked;
//打钩结束
UniQuery1.Next;
end;
RzCheckTree1.Items.EndUpdate;
RzCheckTree1.Items[0].Expanded := True;
UniQuery1.Close;
end;
except
end;
end;
end;
end.
问题补充:另外一种存储权限的时候使用字符串的方法也能够实现,如'1111111111111111111110011111111101'我将这个用作菜单的权限,如果用作类别权限的话,添加类别后会出现其他人员的类别有问题的情况,所以没有使用。如果朋友们可以解决这个问题当然也可以用,这个方法比较快。