コード例 #1
0
ファイル: Login.xaml.cs プロジェクト: mql620/MyProject
 private void LoginButton_Click(object sender, RoutedEventArgs e)
 {
     if (login_UserId.Text.Length == 0 || login_UserPwd.Password.Length == 0)
     {
         System.Windows.MessageBox.Show("用户名或密码不可以为空!");
     }
     else
     {
         userInfo = DB_Account.SearchUserInfo(login_UserId.Text);
         if (userInfo != null)
         {
             if (userInfo.AccountID.Equals(login_UserId.Text.Trim()) && userInfo.Password.Equals(login_UserPwd.Password.Trim()))
             {
                 MainWindow mainWindow = new MainWindow();
                 if (userInfo.UserLevel == "1")
                 {
                     mainWindow.UserInFoModule.Visibility = Visibility;
                 }
                 mainWindow.Show();
                 Close();
             }
             else
             {
                 System.Windows.MessageBox.Show("密码错误!");
             }
         }
     }
 }
コード例 #2
0
        public static UserInformation_Kp SearchUserInfo(string accountID)
        {
            UserInformation_Kp userInformation_Kp = null;
            string             sql          = DB_SQL.Sel_LoginInfo(accountID);
            SqlConnection      conn         = null;
            SqlCommand         cmd          = null;
            SqlDataReader      objSqlReader = null;

            try
            {
                using (conn = new SqlConnection(DB_SQL.conStr))
                {
                    using (cmd = new SqlCommand(sql, conn))
                    {
                        conn.Open();
                        objSqlReader = cmd.ExecuteReader();
                        int n = 0;
                        while (objSqlReader.Read())
                        {
                            n += 1;
                            userInformation_Kp = new UserInformation_Kp()
                            {
                                AccountID      = objSqlReader[0].ToString().Trim(),
                                UserName       = objSqlReader[1].ToString().Trim(),
                                Password       = objSqlReader[2].ToString().Trim(),
                                Status         = objSqlReader[3].ToString().Trim(),
                                UserLevel      = objSqlReader[4].ToString().Trim(),
                                CreateUserID   = objSqlReader[5].ToString().Trim(),
                                CreateTime     = objSqlReader[6].ToString().Trim(),
                                UpdateUserID   = objSqlReader[7].ToString().Trim(),
                                UpdateUserName = objSqlReader[8].ToString().Trim(),
                                UpdateTime     = objSqlReader[9].ToString().Trim()
                            };
                        }
                        if (n == 0)
                        {
                            MessageBox.Show("用户名不存在!");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString() + "打开数据库失败!");
            }
            finally
            {
                if (objSqlReader != null)
                {
                    objSqlReader.Close();
                }
                if (cmd != null)
                {
                    cmd.Dispose();
                }
                if (conn != null)
                {
                    conn.Close();
                    conn.Dispose();
                }
            }
            return(userInformation_Kp);
        }