⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 role.cs

📁 基于角色的用户验证. 这个程序重点写了四个pages以实现这些功能:增加用户
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace RolesBasedAthentication
{
	public class Role
	{
		private int roleID;
		private string roleName;
		private string connectionString;

		public Role()
		{
			connectionString = ConfigurationSettings.AppSettings["ConnectionString"];
		}

		public Role(int roleID)
		{
			connectionString = ConfigurationSettings.AppSettings["ConnectionString"];

			connectionString = ConfigurationSettings.AppSettings["ConnectionString"];
			SqlConnection connection = new SqlConnection(connectionString);
			DataSet dataSet = new DataSet();

			connection.Open();

			SqlDataAdapter adapter = new SqlDataAdapter();
			SqlCommand command = new SqlCommand("Get_RoleDetails", connection);
			command.Parameters.Add("@RoleID", roleID);
			command.CommandType = CommandType.StoredProcedure;

			adapter.SelectCommand = command;
			adapter.Fill(dataSet, "Roles");

			command.Dispose();
			adapter.Dispose();
			connection.Close();

			DataRow role = dataSet.Tables["Roles"].Rows[0];
			this.roleID = (int)role["RoleID"];
			this.roleName = (string)role["RoleName"];
			
			dataSet.Dispose();
		}

		public static DataSet GetRoles()
		{
			string connectionString = ConfigurationSettings.AppSettings["ConnectionString"];
			SqlConnection connection = new SqlConnection(connectionString);
			DataSet dataSet = new DataSet();

			connection.Open();

			SqlDataAdapter adapter = new SqlDataAdapter();
			SqlCommand command = new SqlCommand("Get_Roles", connection);
			
			adapter.SelectCommand = command;
			adapter.Fill(dataSet, "Roles");

			command.Dispose();
			adapter.Dispose();
			connection.Close();

			return dataSet;
		}

		public int Add()
		{
			int rowsAffected;
			SqlConnection connection = new SqlConnection(connectionString);
			SqlCommand command = new SqlCommand("Create_Role", connection);

			command.Parameters.Add("@RoleName", roleName);
			command.CommandType = CommandType.StoredProcedure;

			connection.Open();
			
			rowsAffected = command.ExecuteNonQuery();
			command.Dispose();
			connection.Close();

			return rowsAffected;
		}

		public bool Update()
		{
			int rowsAffected;
			SqlConnection connection = new SqlConnection(connectionString);
			SqlCommand command = new SqlCommand("Update_Role", connection);

			command.Parameters.Add("@RoleID", roleID);
			command.Parameters.Add("@RoleName", roleName);
			command.CommandType = CommandType.StoredProcedure;

			connection.Open();
			rowsAffected = command.ExecuteNonQuery();
			command.Dispose();
			connection.Close();

			return (rowsAffected == 1);
		}

		public bool Delete()
		{
			int rowsAffected;
			SqlConnection connection = new SqlConnection(connectionString);
			SqlCommand command = new SqlCommand("Delete_Role", connection);
			command.Parameters.Add("@RoleID", roleID);
			command.CommandType = CommandType.StoredProcedure;

			connection.Open();
			rowsAffected = command.ExecuteNonQuery();
			command.Dispose();
			connection.Close();

			return (rowsAffected == 1);
		}

		// Properties
		public int RoleID
		{
			get { return roleID; }
			set { roleID = value; }
		}

		public string RoleName
		{
			get { return roleName; }
			set { roleName = value; }
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -