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)); }
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); } } }