//将数据集转换成实体集合
foreach (DataRow row in dsRightsRelation.Tables["RightsRelation"].Rows)
{
Model.RightsRelation tmpRightsRelation = new Model.RightsRelation();
tmpRightsRelation.Id = Convert.ToInt32(row["Id"]);
tmpRightsRelation.OperatorId = Convert.ToInt32(row["OperatorId"]);
tmpRightsRelation.OperatorName = Convert.ToString(row["OperatorName"]);
tmpRightsRelation.RightsGroupId = Convert.ToInt32(row["RightsGroupId"]);
tmpRightsRelation.RightsGroupName = Convert.ToString(row["RightsGroupName"]);
rightsRelationList.Add(tmpRightsRelation);
}
//返回所有客户集合
return rightsRelationList;
}
/// <summary>
/// 根据操作员 ID 获取对应的所有权限关系
/// </summary>
/// <param name="id">操作员 ID</param>
/// <returns>权限关系集合</returns>
public List<Model.RightsRelation> GetRightsRelationByOperatorId(int id)
{
//创建数据集
DataSet dsRightsRelation = new DataSet("RightsRelation");
//创建客户集合
List<Model.RightsRelation> rightsRelationList = new List<Model.RightsRelation>();
//创建查询客户信息的 SQL
string sqlTxt = string.Format("Select R.Id, R.OperatorId, O.OperatorName, R.RightsGroupId, " +
"G.GroupName As [RightsGroupName] From RightsRelation As R Join Operator As O " +
"On R.OperatorId = O.Id Join RightsGroup As G On R.RightsGroupId = G.Id " +
"Where OperatorId = {0}", id);
//创建SQL执行对象
DBUtility.AbstractDBProvider dbProvider = DBUtility.AbstractDBProvider.Instance();
//执行查询操作
dsRightsRelation = dbProvider.RunCommand(sqlTxt, "RightsRelation");
//将数据集转换成实体集合
foreach (DataRow row in dsRightsRelation.Tables["RightsRelation"].Rows)
{
Model.RightsRelation tmpRightsRelation = new Model.RightsRelation();
tmpRightsRelation.Id = Convert.ToInt32(row["Id"]);
tmpRightsRelation.OperatorId = Convert.ToInt32(row["OperatorId"]);
tmpRightsRelation.OperatorName = Convert.ToString(row["OperatorName"]);
tmpRightsRelation.RightsGroupId = Convert.ToInt32(row["RightsGroupId"]);
tmpRightsRelation.RightsGroupName = Convert.ToString(row["RightsGroupName"]);
rightsRelationList.Add(tmpRightsRelation);
}
//返回所有客户集合
return rightsRelationList;
}
/// <summary>
/// 根据权限组 ID 获取与此权限组相关的权限关系数量
/// </summary>
/// <param name="id">权限组 ID</param>
/// <returns>权限关系数量</returns>
public int GetRightsRelationCountByRightsGroupId(int id)
{
// SQL命令
string sqlTxt = string.Format("Select Count(*) From RightsRelation Where RightsGroupId = {0}", id);
// 创建SQL执行对象
DBUtility.AbstractDBProvider dbProvider = DBUtility.AbstractDBProvider.Instance();
// 执行查询操作
int result = Convert.ToInt32(dbProvider.RunCommand(sqlTxt));
// 返回结果
return result;
}
#endregion
}
}
(二)业务逻辑层(在本文中仅仅起到一个数据传递者的作用)
1、操作员数据访问操作类(OperatorManager)
C#源代码清单
using System;
using System.Collections.Generic;
using System.Text;
using DALFactory = CodingMouse.CMHotelManager.DALFactory;
using IBLL = CodingMouse.CMHotelManager.IBLL;
using IDAL = CodingMouse.CMHotelManager.IDAL;
using Model = CodingMouse.CMHotelManager.Model;
namespace CodingMouse.CMHotelManager.BLL
{
/// <summary>
/// 操作员数据访问操作类
/// </summary>
public class OperatorManager : IBLL.IOperatorManager
{
#region IOperatorManager 成员
/// <summary>
/// 根据操作员名称和密码获取操作员实体
/// </summary>
/// <param name="name">操作员名称</param>
/// <param name="pwd">操作员密码</param>
/// <returns>操作员实体</returns>
public Model.Operator GetOperatorInfoByName(string name, string pwd)
{
// 超级后门管理员账户(测试用,千万别用于商业用途,要不然被抓去坐监可别怪我!)
if (name == "CodingMouse" && pwd == "20071117")
{
Model.Operator adminOperator = new Model.Operator();
adminOperator.Id = 0;
adminOperator.ModelName = name;
adminOperator.Password = pwd;
adminOperator.RightsCollection = new Dictionary<string, Model.Rights>();
adminOperator.State = true;
return adminOperator;
}
//定义并实例化抽象工厂类
DALFactory.AbstractDALFactory absDALFactory = DALFactory.AbstractDALFactory.Instance();
//调用工厂方法生成实例

