📄 unituser.~pas
字号:
cbxSex.Text := '';
//edtBorn.Text := '';
//edtPost.Text := '';
edtTel.Text := '';
edtEmail.Text := '';
edtAddress.Text := '';
memUser.Text := '';
edtUserName.ReadOnly := false;
edtTel.ReadOnly := false;
edtEmail.ReadOnly := false;
edtAddress.ReadOnly := false;
memUser.ReadOnly := false;
adotmp.Connection := adoconn;
adotmp.SQL.Text := 'select max(UNo) from Tuser';
adotmp.Open;
if adotmp.RecordCount<>0 then
begin
strNo := inttostr(strtoint(adotmp.Fields[0].text)+1);
if length(strNo)=1 then
strNo :='00'+strNo
else if length(strNo)=2 then
strNo :='0'+strNo;
edtUserNo.Text := strNo;
edtUserNo.ReadOnly := true;
edtUserName.SetFocus;
end;
adotmp.Close;
end;
procedure TfrmUser.bbtnModifyClick(Sender: TObject);
begin
iflag := DOMODIFY;
buttonstate(DOMODIFY);
edtUserNo.ReadOnly := true;
edtUserName.SetFocus;
edtUserName.ReadOnly := false;
edtTel.ReadOnly := false;
edtEmail.ReadOnly := false;
edtAddress.ReadOnly := false;
memUser.ReadOnly := false;
end;
procedure TfrmUser.bbtnDelClick(Sender: TObject);
var
iDel : integer;
begin
buttonstate(DODEL);
iDel := application.MessageBox('真的要删除吗?','删除提示',MB_YESNO+MB_Iconquestion);
if iDel=6 then
begin
try
adotmp.Connection := adoconn;
adotmp.SQL.Text := 'delete from TUserRole where Uno='''+edtUserNo.Text+'''';
adotmp.ExecSQL;
adotmp.SQL.Text := 'delete from TUser where Uno='''+edtUserNo.Text+'''';
adotmp.ExecSQL;
adotmp.Close;
showmessage('成功删除');
except
on e:exception do
showmessage('删除失败');
end;
showlist;
end
else
begin
bbtnAdd.Enabled := true;
bbtnModify.Enabled := true;
bbtnSave.Enabled := true;
exit;
end;
end;
{
*************************************************************************************
函数名称: 保存数据
功能描述: 保存用户添加或修改的内容
输入参数: 无
输出参数: 无
返回 值: 无
说 明:
*************************************************************************************
}
procedure TfrmUser.bbtnSaveClick(Sender: TObject);
var
irole : integer;
strNewNo : string; //新添加用户的编号
begin
try
case iflag of
1:
begin
strMsg := '添加';
{if (edtUserName.Text ='') or (cbxSex.Text='') or (cbxPost.text='') then
begin
showmessage('带*号的项不能为空');
exit;
end;}
strNewNo := edtUserNo.text;
strSexNo := copy(cbxsex.Text,1,pos('[',cbxsex.Text)-1);
strPostNo := copy(cbxpost.Text,1,pos('[',cbxpost.Text)-1);
strsql :='insert into TUser (UNo,UName,USex,UPassWord,UBirth,UPost,UPhone,UEmail,UAddress,UMemo)'; //注意:性别跟职位加入数据库的是数据字典中对应的编号
strsql := strsql + ' values ('''+edtUserNo.text+''','''+edtUserName.Text+''','''+strSexNo+''',';
strsql := strsql + '''123456'','''+datetostr(DTPBorn.Date)+''','''+strPostNo+''','''+edtTel.text+''',''';
strsql := strsql + edtEmail.text+''','''+edtAddress.text+''','''+memUser.text+''''+')'; //注意:由于SQL语句是字符串,DTPBorn得转化为字符串类型,
//但前后不能加单引号(由于出生年月字段是日期类型,
//不加单引号保存到数据库后该字段能自动把他转化为日期类型)
adotmp.Connection := adoconn;
adotmp.SQL.Text :=strsql;
adotmp.ExecSQL;
adotmp.Close;
showmessage('添加成功');
showlist;
irole := application.MessageBox('是否现在给该用户分配角色?','提示',MB_YESNO+MB_Iconquestion);
strUno := strNewNo;
if irole=6 then
begin
pclUser.TabIndex := 1;
end
else
exit;
end;
2:
begin
strMsg := '修改';
//strUno := edtUserNo.Text;
{if (edtUserName.Text ='') or (cbxSex.Text='') or (cbxPost.text='') then
begin
showmessage('带*号的项不能为空');
exit;
end;}
adotmp.Connection := adoconn;
adotmp.Close;
strSexNo := copy(cbxsex.Text,1,pos('[',cbxsex.Text)-1);
strPostNo := copy(cbxpost.Text,1,pos('[',cbxpost.Text)-1);
strsql := 'update TUser set Uname='''+edtUserName.Text+''',Usex='''+strSexNo+ ''',Ubirth=''';
strsql := strsql + datetostr(DTPBorn.Date)+''',UPost='''+strPostNo+''',UPhone='''+edtTel.Text;
strsql := strsql + ''',UEmail='''+edtEmail.Text+''',UAddress='''+edtAddress.Text+''',UMemo=''';
strsql := strsql + memUser.Text+''' where Uno='''+edtUserNo.text+'''';
//adotmp.Parameters.ParamByName('strUname').Value := edtUserNo.Text;
adotmp.SQL.Text := strsql;
adotmp.ExecSQL;
adotmp.Close;
showmessage('修改成功');
showlist;
end;
end;
except
showmessage('执行'+strMsg+'操作不成功!');
end;
end;
{procedure TfrmUser.bbtnCancelClick(Sender: TObject);
begin
buttonstate(DOCANCEL);
if iflag = 1 then //如果是删除操作,按取消后,用户编辑区显示当前数据集的内容
begin
edtUserNo.Text := adolist.Fields[0].Text;
strUno := edtUserNo.Text;
edtUserName.Text := adolist.Fields[1].Text;
cbxSex.Text := adolist.Fields[2].Text;
DTPBorn.Date := strtodate(adolist.Fields[3].Text);
cbxPost.Text := adolist.Fields[4].Text;
edtTel.Text := adolist.Fields[5].Text;
edtEmail.Text := adolist.Fields[6].Text;
edtAddress.Text := adolist.Fields[7].Text;
memUser.Text := adolist.Fields[8].Text;
edtUserNo.ReadOnly := true;
edtUserName.ReadOnly := true;
edtTel.ReadOnly := true;
edtEmail.ReadOnly := true;
edtAddress.ReadOnly := true;
memUser.ReadOnly := true;
iflag :=0;
end; //如果是修改操作,按取消后,用户编辑区显示会修改前的内容
if iflag = 2 then
begin
adotmp.Connection := adoconn;
adotmp.Close;
adotmp.SQL.Text := 'select UNo,UName,USex,UBirth,UPost,UPhone,UEmail,UAddress,Umemo from TUser where Uno='''+edtUserNo.Text+'''';
adotmp.Open;
edtUserNo.Text := adotmp.Fields[0].Text;
strUno := edtUserNo.Text;
edtUserName.Text := adotmp.Fields[1].Text;
cbxSex.Text := adotmp.Fields[2].Text;
DTPBorn.Date := strtodate(adotmp.Fields[3].Text);
cbxPost.Text := adotmp.Fields[4].Text;
edtTel.Text := adotmp.Fields[5].Text;
edtEmail.Text := adotmp.Fields[6].Text;
edtAddress.Text := adotmp.Fields[7].Text;
memUser.Text := adotmp.Fields[8].Text;
adotmp.Close;
edtUserNo.ReadOnly := true;
edtUserName.ReadOnly := true;
edtTel.ReadOnly := true;
edtEmail.ReadOnly := true;
edtAddress.ReadOnly := true;
memUser.ReadOnly := true;
iflag := 0;
end;
end; }
procedure TfrmUser.bbtnExitClick(Sender: TObject);
begin
close;
end;
{
*************************************************************************************
函数名称: 初始化数据
功能描述: 将数据字典中的数据初始化到combox下拉列表中
输入参数: 无
输出参数: 无
返回 值: 无
说 明:
*************************************************************************************
}
procedure TfrmUser.iniData;
begin
try
adotmp.Connection := adoconn;
adotmp.SQL.Text := 'select a.DId,a.DName from TDataParam a,TDataType b where a.DTypeId=b.DTypeId and b.DTypeName=''性别''';
adotmp.Open;
while not adotmp.Eof do
begin
cbxSex.Items.Add(adotmp.fieldbyname('DId').asstring+'['+adotmp.fieldbyname('DName').asstring+']');
adotmp.Next;
end;
adotmp.Close;
adotmp.SQL.Text := 'select a.DId,a.DName from TDataParam a,TDataType b where a.DTypeId=b.DTypeId and b.DTypeName=''职务''';;
adotmp.Open;
while not adotmp.Eof do
begin
cbxPost.Items.Add(adotmp.fieldbyname('DId').asstring+'['+adotmp.fieldbyname('DName').asstring+']');
adotmp.Next;
end;
adotmp.Close;
except
on e:exception do
showmessage('初始化数据失败');
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -