📄 rightoprate.pas
字号:
unit rightoprate;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, CheckLst, ComCtrls, Buttons, DB, ADODB;
type
TFrmrightoprate = class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
RightListBox: TCheckListBox;
GroupList: TListView;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
ComQuery: TADOQuery;
procedure FormShow(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure GroupListSelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
procedure SpeedButton1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Frmrightoprate: TFrmrightoprate;
implementation
uses dbmodule,fun;
{$R *.dfm}
procedure TFrmrightoprate.FormShow(Sender: TObject);
var
mylist:TlistItem;
begin
GroupList.Items.Clear;
if comquery.Active then
comquery.Close;
comquery.SQL.Clear;
comquery.SQL.Add('select * from Q_group');
comquery.Open ;
while not comquery.Eof do
begin
mylist:=grouplist.Items.Add;
mylist.Caption:=inttostr(comquery.FieldValues['Groupid']);
mylist.SubItems.Add(comquery.FieldValues['Groupname']);
comquery.Next;
end;
comquery.Close;
if comquery.Active then
comquery.Close;
comquery.SQL.Clear;
comquery.SQL.Add('select * from Q_menu');
comquery.Open ;
rightlistbox.Items.Clear;
while not comquery.Eof do
begin
rightlistbox.Items.Add(comquery.FieldValues['menuname']);
//用hint属性来储存menutag的值
rightlistbox.Hint:=rightlistbox.Hint+inttostr(comquery.FieldValues['menutag'])+',';
comquery.Next;
end;
comquery.Close;
end;
procedure TFrmrightoprate.SpeedButton2Click(Sender: TObject);
begin
self.Close;
end;
procedure TFrmrightoprate.GroupListSelectItem(Sender: TObject;
Item: TListItem; Selected: Boolean);
var
i:integer;
begin
if Selected then
begin
if comquery.Active then
comquery.Close;
comquery.SQL.Clear;
comquery.SQL.Add('select menuname,isflag from Q_right where groupid='+item.Caption);
comquery.Open ;
if not comquery.Eof then
begin
RightListBox.Items.Clear;
i:=0;
while not comquery.Eof do
begin
RightListBox.Items.Add(comquery.FieldValues['menuname']);
RightListBox.Checked[i]:=comquery.FieldValues['isflag'];
inc(i);
comquery.Next;
end;
end
else
begin
if comquery.Active then
comquery.Close;
comquery.SQL.Clear;
comquery.SQL.Add('select * from Q_menu');
comquery.Open ;
rightlistbox.Items.Clear;
while not comquery.Eof do
begin
rightlistbox.Items.Add(comquery.FieldValues['menuname']);
comquery.Next;
end;
comquery.Close;
end;
end;
end;
procedure TFrmrightoprate.SpeedButton1Click(Sender: TObject);
var
msg:string;
menutag:Tstrings;
i:integer;
begin
if grouplist.Selected<> nil then
begin
msg:='你确定保存关于('+grouplist.Selected.SubItems[0]+')的权限表吗?';
if application.MessageBox(pchar(msg),'提示',mb_okcancel)=id_ok then
begin
if comquery.Active then
comquery.Close;
comquery.SQL.Clear;
comquery.SQL.Add('delete from Q_right where groupid='+grouplist.Selected.Caption);
comquery.ExecSQL;
comquery.Close;
if comquery.Active then
comquery.Close;
comquery.SQL.Clear;
menutag:=Tstringlist.Create;
menutag:=split(rightlistbox.Hint,',');
if comquery.Active then
comquery.Close;
comquery.SQL.Clear;
comquery.SQL.Add('select * from Q_right where groupid='+grouplist.Selected.Caption);
comquery.Open;
if comquery.Eof then
begin
for i:=0 to rightlistbox.Items.Count -1 do
begin
comquery.Append;
comquery.FieldByName('menuname').AsString:=rightlistbox.Items[i];
comquery.FieldByName('rightid').AsInteger:=strtoint(menutag.Strings[i]);
comquery.FieldByName('groupid').AsInteger:=strtoint(grouplist.Selected.Caption);
comquery.FieldByName('isflag').AsBoolean:=rightlistbox.Checked[i];
end;
if comquery.State in [dsEdit,dsInsert] then
try
comquery.Post;
application.MessageBox('数据保存成功!','提示',mb_ok)
except
application.MessageBox('数据保存失败!','提示',mb_ok)
end;
end;
comquery.Close;
menutag.Free;
end;
end
else
begin
application.MessageBox('没有选择组!','提示',mb_ok);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -