📄 urightgrpattr.pas
字号:
unit uRightGrpAttr;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, RzTabs, RzButton, StdCtrls, RzLabel, Grids, DBGridEh,
cxControls, cxContainer, cxEdit, cxTextEdit, cxMemo, ExtCtrls,
cxMaskEdit, cxDropDownEdit, RzPanel, fcTreeView, ImgList, DB, DBClient,
ActiveX;
type
TfrmRightGrpAttr = class(TForm)
RzButton1: TRzButton;
RzButton2: TRzButton;
RzPageControl1: TRzPageControl;
TabSheet1: TRzTabSheet;
TabSheet2: TRzTabSheet;
RzLabel1: TRzLabel;
Label1: TLabel;
RzLabel2: TRzLabel;
cxTextEdit1: TcxTextEdit;
RzLabel3: TRzLabel;
Label2: TLabel;
RzLabel4: TRzLabel;
cxMemo1: TcxMemo;
TV_Sub: TfcTreeView;
cds_SubSys: TClientDataSet;
cds_SubMod: TClientDataSet;
ImageList1: TImageList;
procedure RzButton2Click(Sender: TObject);
procedure RzButton1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
procedure InitData;
procedure InitTree;
function GetSysNode(TV: TfcTreeView; const SysId: string): TfcTreeNode;
function GetRightNode(const SysId, ModId: string): TfcTreeNode;
procedure SetRightTreeFromUserGrp(const GrpId: string);
procedure SetGrpRightFromTree(const GrpId: string);
public
{ Public declarations }
iMod: smallint; // 0浏览 1 属性 2 新建
end;
TInitThread = class(TThread)
protected
procedure Execute; override;
end;
var
frmRightGrpAttr: TfrmRightGrpAttr;
implementation
uses untDM, untPublic;
{$R *.dfm}
procedure TfrmRightGrpAttr.RzButton2Click(Sender: TObject);
begin
close;
end;
procedure TfrmRightGrpAttr.RzButton1Click(Sender: TObject);
var
cSqlStr: string;
iRet: smallint;
begin
if trim(cxTextEdit1.Text) = '' then
begin
TPublicFunc.ShowWarningMsg('名称不能为空!');
cxTextEdit1.SetFocus;
exit;
end;
if iMod = 1 then
begin
cSqlStr := 'update T_004 set V02=' +
Quotedstr(trim(cxTextEdit1.Text)) + ',V06=' +
Quotedstr(trim(cxMemo1.Text)) + ' where V01=' +
Quotedstr(trim(Label2.Caption));
iRet := DM.ExecuteSqlCmd(cSqlStr);
if iRet <> 0 then
begin
TPublicFunc.ShowErrorMsg('存盘出错!');
exit;
end
else
SetGrpRightFromTree(trim(Label2.Caption));
end
else if iMod = 2 then
begin
cSqlStr := 'insert T_004(V01,V02,V05,V06) values(' +
Quotedstr(trim(Label2.Caption)) + ',' +
Quotedstr(trim(cxTextEdit1.Text)) + ',0,' +
Quotedstr(trim(cxMemo1.Text)) + ')';
iRet := DM.ExecuteSqlCmd(cSqlStr);
if iRet <> 0 then
begin
TPublicFunc.ShowErrorMsg('存盘出错!');
exit;
end
else
SetGrpRightFromTree(trim(Label2.Caption));
end;
ModalResult := mrOk;
end;
procedure TfrmRightGrpAttr.FormCreate(Sender: TObject);
begin
Label1.Caption := '';
Label2.Caption := '';
end;
{ TInitThread }
procedure TInitThread.Execute;
begin
inherited;
FreeOnTerminate := true;
CoInitialize(nil);
frmRightGrpAttr.InitTree;
frmRightGrpAttr.InitData;
CoUninitialize;
end;
procedure TfrmRightGrpAttr.InitData;
begin
SetRightTreeFromUserGrp(trim(Label2.Caption));
end;
procedure TfrmRightGrpAttr.InitTree;
var
Node: TfcTreeNode;
begin
with cds_SubSys do
begin
if Active then
Active := false;
XMLData := DM.FreeQuery('select * from T_005 order by V01');
Active := true;
end;
with cds_SubMod do
begin
if Active then
Active := false;
XMLData := DM.FreeQuery('select * from T_005_L order by V01,V02');
Active := true;
end;
with cds_SubSys do
begin
first;
while not eof do
begin
Node := TV_Sub.Items.AddChild(nil, trim(fieldbyname('V02').AsString));
Node.StringData := trim(fieldbyname('V01').AsString);
Node.ImageIndex := 0;
next;
end;
end;
with cds_SubMod do
begin
first;
while not eof do
begin
Node := TV_Sub.Items.AddChild(
GetSysNode(TV_Sub, trim(fieldbyname('V01').AsString)),
trim(fieldbyname('V03').AsString));
Node.StringData := trim(fieldbyname('V02').AsString);
Node.StringData2 := trim(fieldbyname('V01').AsString);
Node.CheckboxType := tvctCheckbox;
Node.ImageIndex := -1;
next;
end;
end;
TV_Sub.FullExpand;
end;
function TfrmRightGrpAttr.GetSysNode(TV: TfcTreeView;
const SysId: string): TfcTreeNode;
var
i: integer;
begin
result := nil;
for i := 0 to TV.Items.Count - 1 do
begin
if TV.Items[i].Level = 0 then
if TV.Items[i].StringData = SysId then
begin
result := TV.Items[i];
break;
end;
end;
end;
procedure TfrmRightGrpAttr.SetRightTreeFromUserGrp(const GrpId: string);
var
Node: TfcTreeNode;
cSqlStr: string;
begin
if trim(GrpId) = '' then
exit;
cSqlStr := 'select * from T_004_L where V01=' + QuotedStr(GrpId) +
' order by V02,V03';
with cds_SubMod do
begin
if Active then
Active := false;
XMLData := DM.FreeQuery(cSqlStr);
Active := true;
end;
with cds_SubMod do
begin
first;
while not eof do
begin
Node := GetRightNode(trim(fieldbyname('V02').AsString),
trim(fieldbyname('V03').AsString));
if Node <> nil then
Node.Checked := true;
next;
end;
end;
end;
function TfrmRightGrpAttr.GetRightNode(const SysId,
ModId: string): TfcTreeNode;
var
i: integer;
begin
result := nil;
for i := 0 to TV_Sub.Items.Count - 1 do
begin
if TV_Sub.Items[i].Level = 1 then
if (TV_Sub.Items[i].StringData = ModId) and
(TV_Sub.Items[i].StringData2 = SysId) then
begin
result := TV_Sub.Items[i];
break;
end;
end;
end;
procedure TfrmRightGrpAttr.FormShow(Sender: TObject);
begin
TInitThread.Create(False);
end;
procedure TfrmRightGrpAttr.SetGrpRightFromTree(const GrpId: string);
var
i: integer;
begin
DM.GrpRightDel(GrpId);
for i := 0 to TV_Sub.Items.Count - 1 do
begin
if (TV_Sub.Items[i].Level = 1) and TV_Sub.Items[i].Checked then
DM.GrpRightAdd(GrpId, TV_Sub.Items[i].StringData2,
TV_Sub.Items[i].StringData);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -