Пример #1
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            string name     = userName.Text;
            string password = userPd.Password;

            string    strSql    = "select password from userinfo where name = " + "'" + name + "'";
            DataTable dataTable = new DataTable();

            dbTool.selectSql(strSql, out dataTable);
            if (dataTable.Rows.Count > 0)
            {
                string pdDatabase = dataTable.Rows[0].ItemArray[0].ToString();
                if (pdDatabase.Equals(password))
                {
                    allMenu.IsEnabled  = true;
                    rootTree.IsEnabled = true;
                    Connect.IsEnabled  = true;
                    login.Visibility   = Visibility.Hidden;
                    welcome.Visibility = Visibility.Visible;
                    weluser.Text       = "欢迎您 " + name;
                    MessageBox.Show("登录成功");
                }
                else
                {
                    MessageBox.Show("密码错误");
                }
            }
            else
            {
                MessageBox.Show("该用户名不存在");
            }
        }