private void logo_Click(object sender, EventArgs e) { user.set用户名(textBox1.Text); user.set密码(textBox2.Text); //打开链接 MySqlConnection cnn = 系统.链接(); cnn.Open(); string sql = "SELECT * FROM user WHERE uname='" + user.用户名() + "' AND password='******' AND role='" + user.身份() + "'"; //执行 MySqlCommand command = new MySqlCommand(sql, cnn); MySqlDataReader sdr = command.ExecuteReader(); if (sdr.Read()) { user.set姓名(sdr.GetString("name")); user.setID(sdr.GetInt32("_id")); MessageBox.Show("欢迎" + user.姓名()); 管理系统主界面 主界面 = new 管理系统主界面(); //写入数据 系统.startApp(this); 系统.setUser(user); //启动主界面 主界面.Show(); //隐藏线程 this.Hide(); } else { MessageBox.Show("用户名或密码错误或身份不正确"); } //关闭数据链接 cnn.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("删除成功"); 显示数据(); }
//编辑 private void button6_Click(object sender, EventArgs e) { 用户 user = new 用户(); user.setID(int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString())); user.set用户名((string)dataGridView1.CurrentRow.Cells[1].Value.ToString()); user.set密码((string)dataGridView1.CurrentRow.Cells[2].Value.ToString()); user.set姓名((string)dataGridView1.CurrentRow.Cells[3].Value.ToString()); if ("管理员".Equals((string)dataGridView1.CurrentRow.Cells[4].Value.ToString())) { user.set身份管理员(); } else { user.set身份用户(); } new 注册界面(user).Show(); }