Пример #1
0
        //登录
        private void LoginBut_Click(object sender, RoutedEventArgs e)
        {
            if (UserName.Text == "")
            {
                notlog.Content = "请输入用户名";
            }
            else if (UserPassword.Text == "")
            {
                notlog.Content = "请输入密码";
            }
            else
            {
                string          DbLink = "Host = localhost; Database = socket; Username = root; Password = 123456";
                DataBaseLink    DBA    = new DataBaseLink(DbLink);
                string          SQL    = "SELECT username,userpassword FROM user WHERE username={0} AND userpassword={1}";
                object[]        value  = { UserName.Text, UserPassword.Text };
                MySqlDataReader Read   = DBA.Select(value, SQL);

                if (Read.Read())
                {
                    //LoginUserName = UserName.Text;
                    MessageBox.Show("yes");
                    MainWindow Mw = new MainWindow(UserName.Text);
                    //MainWindow.LoginUserName = UserName.Text;
                    DBA.DataBaseClose();
                    this.Close();
                    Mw.ShowDialog();
                }
                else
                {
                    DBA.DataBaseClose();
                    notlog.Content = "用户名或者密码错误";
                }
            }
        }
Пример #2
0
 //失去焦点时查询用户名是否存在
 private void UserName_LostFocus(object sender, RoutedEventArgs e)
 {
     if (UserName.Text == "")
     {
     }
     else
     {
         string          DbLink = "Host = localhost; Database = socket; Username = root; Password = 123456";
         DataBaseLink    DBA    = new DataBaseLink(DbLink);
         string          SQL    = "SELECT username FROM user WHERE username ={0}";
         object[]        Value  = { UserName.Text };
         MySqlDataReader Read   = null;
         Read = DBA.Select(Value, SQL);
         //DBA.DataBaseClose();
         if (Read.Read())
         {
             UseNameSelect.Content = "√";
         }
         else
         {
             UseNameSelect.Content = "×";
         }
         DBA.DataBaseClose();
     }
 }