You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CaiQie/RfidWeb/Frm/FormPersionCent.cs

94 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NewLife.Caching;
using Tool.Model;
using Tool;
using DB.Dto;
using DB.Service;
using NewLife;
using System.Security.Cryptography;
namespace RfidWeb.Frm
{
public partial class FromEn : Form
{
private readonly string Kes = CacheKeyManager.AesPwd;
private RoleService roleService = new RoleService();
private UserService userService = new UserService();
private long id = 0;
private UserDto OlduserDto;
public FromEn()
{
InitializeComponent();
OlduserDto = UserManager.GetUser();
id=OlduserDto.Id;
FillCbo();
var info = userService.Query(id);
this.ucTextBoxUser.InputText = info.UserName;
this.ucTextBoxPwd.InputText = Aes.Create().Decrypt(info.Pwd.ToBase64(), Kes.GetBytes()).ToStr();
ucCombox1.SelectedValue = info.RoleId.ToString();
ucCombox1.Enabled = false;
ucTextBoxUser.Enabled = false;
}
public void FillCbo()
{
var list = roleService.GetList();
var level = OlduserDto.RoleLevel;
if (level == 1)
{
list = list.Where(x => x.RoleLevel == 1).ToList();
}
if (level == 2)
{
list = list.Where(x => x.RoleLevel == 1 || x.RoleLevel == 2).ToList();
}
List<KeyValuePair<string, string>> key = new List<KeyValuePair<string, string>>();
foreach (var role in list)
{
key.Add(new KeyValuePair<string, string>(role.ID.ToString(), role.RoleName));
}
ucCombox1.Source = key;
ucCombox1.SelectedIndex = 0;
}
private void ucBtnExt1_BtnClick(object sender, EventArgs e)
{
this.Close();
}
private void ucBtnExit_BtnClick(object sender, EventArgs e)
{
Cache.Default.Remove(CacheKeyManager.HmiUser);
PlcConnect.Instance.Write(HmiPointInfo.Safety_level, int.Parse("0"));
this.Close();
}
private void btnOK_BtnClick(object sender, EventArgs e)
{
var info = userService.Query(id);
info.LastModifyDate=DateTime.Now;
info.Pwd = Aes.Create().Encrypt(ucTextBoxPwd.InputText.GetBytes(), Kes.GetBytes()).ToBase64();
userService.Update(info);
this.Close();
}
}
}