private void LoadData() { CheckSet(); LoadSysData(); try { Label2.Text = "登录到" + SysSec.sysName; Label3.Text = SysSec.companyName + "版权所有" + Environment.NewLine + "COPYRIGHT@(2020 - 2023)"; int r1 = CreateRoundRectRgn(0, 0, Panel3.Width, Panel3.Height, 10, 10); SetWindowRgn(Panel3.Handle.ToInt32(), r1, true); int r2 = CreateRoundRectRgn(0, 0, Panel4.Width, Panel4.Height, 10, 10); SetWindowRgn(Panel4.Handle.ToInt32(), r2, true); //SetWindowRgn(TextBox2.Handle, r, True) //在注册表中获取是否记住用户名 string yhmt = null; yhmt = PublicVar.GetUserName(); if (!string.IsNullOrEmpty(yhmt)) { CheckBox1.Checked = true; TextBox1.Text = yhmt; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Button1_Click(object sender, EventArgs e) { //检查登录 string yhm = TextBox1.Text; string mima = TextBox4.Text; if (string.IsNullOrEmpty(yhm) | string.IsNullOrEmpty(mima)) { MessageBox.Show(this, "用户名或者密码为空,请检查。系统不允许用户使用空密码。", "用户名或密码不能为空", MessageBoxButtons.OK); return; } //检查用户名 myEFContext db = new myEFContext(); User user = db.Users.FirstOrDefault(t => t.UserLoginName.ToUpper() == yhm.ToUpper()); if (user == null) { MessageBox.Show(this, "未找到用户名,请检查。用户名一般为姓名全拼,请联系管理员添加。", "用户名不存在", MessageBoxButtons.OK); return; } //检查用户密码 if (user.UserPassword != sys.SysSec.StringSec(mima)) { MessageBox.Show(this, "用户密码不配对。", "密码错误", MessageBoxButtons.OK); return; } if (user.Enable == false) { MessageBox.Show(this, "用户已经被禁止登录,请联系管理员", "警告", MessageBoxButtons.OK); return; } //更新登录信息 user.LastLoginTime = DateTime.Now; db.SaveChanges(); PublicVar.UserLoginName = user.UserLoginName; PublicVar.UserName = user.UserName; //记住用户 if (CheckBox1.Checked == true) { PublicVar.SetUserName(yhm); } else { PublicVar.SetUserName(""); } this.Visible = false; if (user.Level == 0) { Form SysSet = new sys.SysSet(); SysSet.ShowDialog(); this.Close(); } else { Thread th = new Thread(new ThreadStart(StartMainForm)); th.Start(); this.Close(); } }