//修改用户 private void 修改用户() { if (!正则检验()) { return; } user.set姓名(name.Text.Trim()); user.set用户名(yhm.Text.Trim()); if (yh.Checked) { user.set身份用户(); } else { user.set身份管理员(); } String sql = "UPDATE user SET name = '{0}', uname = '{1}', password = '******', role = '{3}' WHERE _id = {4};"; sql = String.Format(sql, user.姓名(), user.用户名(), user.密码(), user.身份(), user.ID()); //打开链接 MySqlConnection cnn = 系统.链接(); cnn.Open(); //执行 MySqlCommand command = new MySqlCommand(sql, cnn); command.ExecuteNonQuery(); cnn.Close(); MessageBox.Show("保存成功"); this.Close(); }
//删除用户 private void 除用户() { 用户 user = new 用户(); user.setID(int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString())); string sql = "DELETE FROM user WHERE _id=" + user.ID(); //打开链接 MySqlConnection cnn = 系统.链接(); cnn.Open(); //执行 MySqlCommand command = new MySqlCommand(sql, cnn); command.ExecuteNonQuery(); cnn.Close(); MessageBox.Show("删除成功"); 显示数据(); }