📄 utuser.pas
字号:
{
***************************************************************
说明:操作员信息类
***************************************************************
}
unit UTUser;
interface
uses windows, forms, SysUtils, Controls,Classes, ActnList,Dialogs;
type
TUser = class
public
RetVal: integer; //返回码
RetMsg: string; //返回信息
UsrName: string; //用户姓名
AllName: string; //全称
Cxbmtj:string;//
Ms: string; //描述
PassWord: string; //密码
GroupName: string; //所属组
RpassWord: integer; //是否可修改密码 0:下次登录时要改密码 1:不可修改密码
Stop: integer; //是否停用 0:可用 1:停用
GroupList:TStringList;
constructor create;
public
function GetUserInfo(sUsrName: string): boolean;
function AddUser(): boolean;
function UpdateUserInfo(): boolean;
function AddUserToGroup(): boolean;
function DelUserToGroup(): boolean;
function DeleteUser(): boolean;
function SetOperatePopedom(var ActionList:TActionList):boolean;
procedure MenuSaveToTable(ActionList: TActionList);
private
procedure IniData; //初始化变量数据
end;
implementation
uses DM_DataModal, UGeneralFunc;
{ TUser }
function TUser.AddUser: boolean;
begin
Result := False;
try
with winddata.pUsr_101_UsrInfo do
begin
parameters.ParamByName('@czfs').Value := 1;
parameters.ParamByName('@UsrName').Value := UsrName;
parameters.ParamByName('@AllName').Value := AllName;
parameters.ParamByName('@cxbm').Value := cxbmtj;
parameters.ParamByName('@Ms').Value := Ms;
parameters.ParamByName('@Password').Value := Encode(PassWord, 13);
parameters.ParamByName('@GroupName').Value := GroupName;
parameters.ParamByName('@RpassWord').Value := Rpassword;
parameters.ParamByName('@Stop').Value := Stop;
execproc;
retval := parameters.ParamByName('@return_value').Value;
retmsg := parameters.ParamByName('@retmsg').Value;
end;
except
retval := -1;
retmsg := '执行存储异常'
end;
end;
function TUser.AddUserToGroup: boolean;
begin
Result := False;
try
with winddata.pUsr_101_UsrInfo do
begin
parameters.ParamByName('@czfs').Value := 4;
parameters.ParamByName('@UsrName').Value := UsrName;
parameters.ParamByName('@GroupName').Value := GroupName;
execproc;
retval := parameters.ParamByName('@return_value').Value;
retmsg := parameters.ParamByName('@retmsg').Value;
end;
except
retval := -1;
retmsg := '执行存储异常'
end;
end;
constructor TUser.create;
begin
inherited Create;
RetVal := -1; //返回码
RetMsg := ''; //返回信息
GroupList:=TStringList.Create;
IniData;
end;
function TUser.DeleteUser: boolean;
begin
Result := False;
try
with winddata.pUsr_101_UsrInfo do
begin
parameters.ParamByName('@czfs').Value := 2;
parameters.ParamByName('@UsrName').Value := UsrName;
parameters.ParamByName('@AllName').Value := AllName;
parameters.ParamByName('@cxbm').Value := cxbmtj;
parameters.ParamByName('@Ms').Value := Ms;
parameters.ParamByName('@Password').Value := PassWord;
parameters.ParamByName('@GroupName').Value := GroupName;
parameters.ParamByName('@RpassWord').Value := Rpassword;
parameters.ParamByName('@Stop').Value := Stop;
execproc;
retval := parameters.ParamByName('@return_value').Value;
retmsg := parameters.ParamByName('@retmsg').Value;
end;
except
retval := -1;
retmsg := '执行存储异常'
end;
end;
function TUser.DelUserToGroup: boolean;
begin
Result := False;
try
with winddata.pUsr_101_UsrInfo do
begin
parameters.ParamByName('@czfs').Value := 5;
parameters.ParamByName('@UsrName').Value := UsrName;
parameters.ParamByName('@GroupName').Value := GroupName;
execproc;
retval := parameters.ParamByName('@return_value').Value;
retmsg := parameters.ParamByName('@retmsg').Value;
end;
except
retval := -1;
retmsg := '执行存储异常'
end;
end;
function TUser.GetUserInfo(sUsrName: string): boolean;
begin
Result := False;
with winddata.PublicQuery do
begin
sql.Clear;
sql.add('select * from usr_info where usrname=''' + sUsrName + '''');
open;
if not eof then
begin
UsrName := sUsrName;
AllName := fieldbyname('AllName').asstring;
Ms := fieldbyname('ms').asstring;
Cxbmtj:=fieldbyname('cxbm').asstring;
Password := Decode(fieldbyname('usrpassword').asstring,13);
GroupName := fieldbyname('GroupName').asstring;
RPassword := fieldbyname('rpassword').asinteger;
Stop := fieldbyname('stop').asinteger;
close;
sql.Clear;
sql.Add('select * from usr_UsrRight where usrname='''+UsrName+'''');
open;
GroupList.Clear;
while not eof do
begin
GroupList.Add(fieldbyname('groupname').asstring);
next;
end;
Retval := 0;
RetMsg := '操作成功';
Result := True;
end
else
begin
RetVal := 1;
RetMsg := '无此操作员记录'
end;
end;
end;
procedure TUser.IniData;
begin
UsrName := ''; //用户姓名
AllName := ''; //全称
cxbmtj:='';
Ms := ''; //描述
PassWord := ''; //密码
GroupName := '';
RpassWord := -1; //是否可修改密码 0:下次登录时要改密码 1:不可修改密码
Stop := -1; //是否停用 0:可用 1:停用
end;
function TUser.SetOperatePopedom(var ActionList: TActionList): boolean;
var
i:integer;
tmp:string;
begin
if UsrName='admin' then
begin
for i := 0 to ActionList.ActionCount-1 do
begin
(ActionList.Actions[i] as taction).Enabled:= True;
end;
exit;
end;
for i := 0 to ActionList.ActionCount-1 do
begin
(ActionList.Actions[i] as taction).Enabled:= False;
(ActionList.Actions[i] as taction).Visible:=False;
end;
with winddata.PublicQuery do
begin
sql.Clear;
sql.Add('select a.UsrName,b.RightNum from usr_info a left join Usr_right b on a.GroupName=b.GroupName where UsrName='''+UsrName+''' order by rightnum');
open;
while not eof do
begin
for i := 0 to ActionList.ActionCount-1 do
begin
tmp:=fieldbyname('RightNum').asstring ;
if trim(copy(ActionList.Actions[i].Name, 7, 20))=fieldbyname('RightNum').asstring then
begin
(ActionList.Actions[i] as taction).Enabled:=True;
(ActionList.Actions[i] as taction).Visible:=True;
end;
end;
next;
end;
end;
end;
function TUser.UpdateUserInfo: boolean;
begin
Result := False;
try
with winddata.pUsr_101_UsrInfo do
begin
parameters.ParamByName('@czfs').Value := 3;
parameters.ParamByName('@UsrName').Value := UsrName;
parameters.ParamByName('@AllName').Value := AllName;
parameters.ParamByName('@cxbm').Value := cxbmtj;
parameters.ParamByName('@Ms').Value := Ms;
parameters.ParamByName('@Password').Value := Encode(PassWord, 13);
parameters.ParamByName('@GroupName').Value := GroupName;
parameters.ParamByName('@RpassWord').Value := Rpassword;
parameters.ParamByName('@Stop').Value := Stop;
execproc;
retval := parameters.ParamByName('@return_value').Value;
retmsg := parameters.ParamByName('@retmsg').Value;
end;
except
retval := -1;
retmsg := '执行存储异常'
end;
end;
procedure TUser.MenuSaveToTable(ActionList: TActionList);
var
mi: integer;
MenuModule, strsql: string;
Msg: string;
begin
Msg := '请确认要把系统菜单项目添加到数据库中!';
if not showmsg(msg, 0, 0) then exit;
MenuModule := inputbox('重新加载系统菜单输入框', '请输入菜单模块序号:范围在(01~99)', '');
if MenuModule = '' then exit;
strsql := 'delete from Usr_rightinfo where RightNum like ''' + MenuModule + '%''';
with winddata.PublicQuery do
begin
sql.Clear;
sql.Add(strsql);
ExecSql;
strsql := 'delete from Usr_right where RightNum like ''' + MenuModule + '%''';
sql.Clear;
sql.Add(strsql);
ExecSql;
for mi := 1 to ActionList.ActionCount do
begin
strsql := 'insert into Usr_rightinfo(RightNum,RightMemo) values ('''
+ copy(ActionList.Actions[Mi - 1].Name, 7, 30) + ''','''
+ (ActionList.Actions[Mi - 1] as taction).caption + ''')';
sql.Clear;
sql.Add(strsql);
ExecSql;
end;
msg := '菜单保存操作成功完成!';
showmsg(msg, 1, 0);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -