public static bool NewUser(string login_name, string login_password, string name, string department) { string pw = GetMD5(login_password); User u = new User(0, login_name, pw, name, department); return(DBUserAdapter.Insert(u)); }
public static bool ChangePassword(string name, string oldpassword, string newpassword) { if (ValidateUser(name, oldpassword)) { User u = DBUserAdapter.LoadWithName(name); u.Login_password = GetMD5(newpassword); return(DBUserAdapter.Update(u)); } else { return(false); } }
public static bool Exist(string name) { int res = DBUserAdapter.Exist(name); if (res != 1) { return(false); } else { return(true); } }
public static User LoginOn(string name, string password) { if (ValidateUser(name, password)) { User u = DBUserAdapter.LoadWithName(name); DBUserAdapter.SetLastLoginTimeNow(u.Id); DBUserAdapter.IncLoginCount(u.Id); return(u); } else { return(null); } }
private void mi_delete_Click(object sender, EventArgs e) { DataGridViewSelectedRowCollection rows = dgv.SelectedRows; foreach (DataGridViewRow r in rows) { string id = r.Cells[0].Value.ToString(); if (id != "") { int i = int.Parse(id); DBUserAdapter.Delete(i); } } RefreshDate(); }
private bool RefreshDate() { dt = DBUserAdapter.LoadAll(); if (dt == null) { MessageBox.Show("查询数据库错误"); return(false); } dgv.DataSource = dt; dgv.Columns[0].ReadOnly = true; dgv.Columns[2].ReadOnly = true; dgv.Columns.RemoveAt(5); dgv.Columns.RemoveAt(5); dgv.Columns.RemoveAt(5); return(true); }
private void mi_ok_Click(object sender, EventArgs e) { foreach (DataGridViewRow r in dgv.Rows) { if (!RowDataVerificate(r)) { MessageBox.Show("请您填写完整的信息"); r.Selected = true; return; } } foreach (DataGridViewRow r in dgv.Rows) { if (r.IsNewRow) { continue; } int id = 0; if (r.Cells[0].Value is Int32) { id = (int)(r.Cells[0].Value); } string lid = (string)(r.Cells[1].Value); string lpass = (string)(r.Cells[2].Value); string name = (string)(r.Cells[3].Value); string department = (string)(r.Cells[4].Value); User u = new User(id, lid, lpass, name, department); if (id == 0) { if (UserManager.Exist(name)) { MessageBox.Show("用户" + "\"" + name + "\"已经存在"); continue; } DBUserAdapter.Insert(u); } else { User ou = DBUserAdapter.LoadWithId(id); u.Level = ou.Level; DBUserAdapter.Update(u); } } }
public static bool ValidateUser(string name, string password) { string md5pass = GetMD5(password); if (!Exist(name)) { return(false); } User u = DBUserAdapter.LoadWithName(name); if (u == null) { return(false); } if (u.Login_password == md5pass) { return(true); } else { return(false); } }