📄 userdb.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
namespace Park.Common
{
/// <summary>
/// User 的摘要说明。
/// </summary>
public class UserDB
{
//获取用户的角色
public static string GetRole(string userid)
{
SqlConnection myConnection=Utils.GetConnection();
SqlCommand myCommand = new SqlCommand("Login_Get_Role", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;
// Add Parameters to SPROC
SqlParameter UserId = new SqlParameter("@userid", SqlDbType.NVarChar, 20);
UserId.Value = userid;
myCommand.Parameters.Add(UserId);
// Add Parameters to SPROC
SqlParameter Role = new SqlParameter("@role", SqlDbType.Char, 20);
Role.Direction = ParameterDirection.Output;
myCommand.Parameters.Add( Role );
// Execute the command
myConnection.Open();
myCommand.ExecuteNonQuery();
string role = Role.Value.ToString();
myCommand.Dispose();
myConnection.Dispose();
return role;
}
//验证用户输入用户名、密码是否正确
public static bool VerifyUser(string userid,string password)
{
SqlConnection myConnection=Utils.GetConnection();
SqlCommand myCommand = new SqlCommand("Login_Verify_Password", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;
// Add Parameters to SPROC
SqlParameter UserId = new SqlParameter("@userid", SqlDbType.NVarChar, 20);
UserId.Value = userid;
myCommand.Parameters.Add(UserId);
// Add Parameters to SPROC
SqlParameter Password = new SqlParameter("@password", SqlDbType.VarChar, 50);
Password.Value = password;
myCommand.Parameters.Add(Password);
// Execute the command
myConnection.Open();
SqlDataReader result = myCommand.ExecuteReader();
bool retval = result.Read();
result.Close();
myCommand.Dispose();
myConnection.Dispose();
return retval;
}
//验证用户密码是否为空
public static bool VerifyPasswordNull(string userid)
{
SqlConnection myConnection=Utils.GetConnection();
SqlCommand myCommand = new SqlCommand("Login_Verify_PasswordNull", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;
// Add Parameters to SPROC
SqlParameter UserId = new SqlParameter("@userid", SqlDbType.NVarChar, 20);
UserId.Value = userid;
myCommand.Parameters.Add(UserId);
// Execute the command
myConnection.Open();
SqlDataReader result = myCommand.ExecuteReader();
bool retval = result.Read();
result.Close();
myCommand.Dispose();
myConnection.Dispose();
return retval;
}
//验证该用户角色是否具有当前操作的权限,同时用nextcontent返回下一个控件名称。函数自身返回是否具有权限。
public static bool CheckContentRight(string role,string content,out string nextcontent)
{
nextcontent = @"Module/error.ascx";
SqlConnection myConnection=Utils.GetConnection();
SqlCommand myCommand = new SqlCommand("Check_Content_Right", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;
// Add Parameters to SPROC
SqlParameter Role = new SqlParameter("@role", SqlDbType.NVarChar, 20);
Role.Value = role;
myCommand.Parameters.Add(Role);
// Add Parameters to SPROC
SqlParameter Content = new SqlParameter("@content", SqlDbType.VarChar, 50);
Content.Value = content;
myCommand.Parameters.Add(Content);
// Execute the command
myConnection.Open();
SqlDataReader result = myCommand.ExecuteReader();
bool retval = result.Read();
if(retval)
{
nextcontent = result["NextContent"].ToString();
}
result.Close();
myCommand.Dispose();
myConnection.Dispose();
return retval;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -