private void Button1_Click(Object obj, RoutedEventArgs e) { string name1 = TextBox1.Text.ToString(); string password = TextBox2.Text.ToString(); Connection = new MySqlConnection(connectionstring); while (Connection == null) { MessageBox.Show("登录失败", "出错", MessageBoxButton.OK); if (MessageBox.Show("是否重新连接", "出错", MessageBoxButton.YesNo) == MessageBoxResult.No) { //退出程序。 Close(); } else { Connection = new MySqlConnection(connectionstring); } } MessageBox.Show("连接成功", "连接数据库成功", MessageBoxButton.OK); Connection.Open(); MySqlCommand cmd = new MySqlCommand("select password from normaluser where id='" + name1 + "';", Connection); MySqlDataReader rdr = cmd.ExecuteReader(); rdr.Read(); if (rdr.HasRows) { if (rdr[0].ToString() == password) { rdr.Close(); MessageBox.Show("登录成功", "登录成功", MessageBoxButton.OK); w2 = new 功能(Connection, name1, password); w2.Show(); this.Owner = w2; } else { MessageBox.Show("用户或密码错误", "用户或密码错误", MessageBoxButton.OK); } } else { MessageBox.Show("用户或密码错误", "用户或密码错误", MessageBoxButton.OK); } } //button
public void Getpowver(MySqlConnection connection, string hightid, string hightpassword, 功能 w1) { string str1 = "select a.password from hightpowver_data a where a.id=@hightid"; MySqlCommand cmd = new MySqlCommand(str1, connection); cmd.Parameters.AddWithValue("@hightid", hightid); MySqlDataReader rdr0 = cmd.ExecuteReader(); rdr0.Read(); string password = rdr0[0].ToString(); rdr0.Close(); if (password == hightpassword) { w1.Settrue(); } else { MessageBox.Show("错误", "用户名或密码错误", MessageBoxButton.OK); } }
public 高级权限验证(MySqlConnection connection, 功能 w1) { Connection = connection; InitializeComponent(); }