/// <summary>
 /// 获取系统所有角色数据
 /// </summary>
 /// <returns>角色数据集</returns>
 public EntityBase GetRoles(string loginId, ref List<RoleEntity> list)
 {
     TradeUser reftradeuser = new TradeUser();
     if (ComFunction.ExistUserLoginID(loginId, ref reftradeuser) == false)
     {
         return entityBase;
     }
     try
     {
         string sqlCommand = @"select * from Base_Role where roleid not in(select roleid from base_userrole
             where userid in(select userid from base_user where account in('root','admin')))";
         if ("ROOT" == reftradeuser.Account.ToUpper())
         {
             sqlCommand = @"select * from Base_Role where roleid not in(select roleid from base_userrole
                         where userid in(select userid from base_user where account='admin'))";
         }
         else if ("ADMIN" == reftradeuser.Account.ToUpper())
         {
             sqlCommand = @"select * from Base_Role";
         }
         DataTable dt = ComFunction.GetRoles(sqlCommand);
         RoleEntity roleEntity = null;
         foreach (DataRow dr in dt.Rows)
         {
             roleEntity = new RoleEntity();
             roleEntity.RoleID = dr["RoleID"].ToString();
             roleEntity.RoleName = dr["RoleName"].ToString();
             roleEntity.Remark = dr["Remark"].ToString();
             list.Add(roleEntity);
         }
         entityBase.Desc = "获取系统所有角色成功!";
         entityBase.Result = true;
     }
     catch (Exception ex)
     {
         SetException("获取角色记录数出错,原因:", ex);
     }
     return entityBase;
 }
 /// <summary>
 /// 向数据库插入角色
 /// </summary>
 /// <param name="loginId"></param>
 /// <param name="roleEntity"></param>
 /// <returns></returns>
 public EntityBase AddRole(string loginId, RoleEntity roleEntity)
 {
     if (ComFunction.ExistUserLoginID(loginId) == false)
     {
         return entityBase;
     }
     try
     {
         if (ComFunction.AddRole(roleEntity) > 0)
         {
             entityBase.Result = true;
             entityBase.Desc = "角色新增成功";
         }
         else
         {
             entityBase.Result = false;
             entityBase.Desc = "角色新增失败";
         }
     }
     catch (Exception ex)
     {
         SetException("角色新增失败,原因:", ex);
     }
     return entityBase;
 }
 /// <summary>
 /// 新增角色
 /// </summary>
 /// <param name="roleEntity"></param>
 /// <returns></returns>
 public static int AddRole(RoleEntity roleEntity)
 {
     string sqlCommand = string.Format(@"INSERT INTO Base_Role (RoleID,RoleName,Remark)   VALUES ('{0}' ,'{1}' ,'{2}')", roleEntity.RoleID, roleEntity.RoleName, roleEntity.Remark);
     return DbHelper.ExecuteNonQuery(sqlCommand);
 }
 /// <summary>
 /// 读取角色
 /// </summary>
 /// <param name="loginId"></param>
 /// <param name="roleID"></param>
 /// <returns></returns>
 public RoleEntity ReadRole(string loginId, string roleID)
 {
     RoleEntity roleEntity = new RoleEntity();
     if (ComFunction.ExistUserLoginID(loginId) == false)
     {
         return roleEntity;
     }
     try
     {
         DataTable dt = ComFunction.ReadRole(roleID);
         foreach (DataRow dr in dt.Rows)
         {
             roleEntity = new RoleEntity();
             roleEntity.RoleID = dr["RoleID"].ToString();
             roleEntity.RoleName = dr["RoleName"].ToString();
             roleEntity.Remark = dr["Remark"].ToString();
         }
         roleEntity.Desc = "获取系统角色成功!";
         roleEntity.Result = true;
     }
     catch (Exception ex)
     {
         SetException("获取角色记录数出错,原因:", ex);
     }
     return roleEntity;
 }
 /// <summary>
 /// 修改角色
 /// </summary>
 /// <param name="roleEntity"></param>
 /// <returns></returns>
 public static int UpdateRole(RoleEntity roleEntity)
 {
     string sqlCommand = string.Format(@"UPDATE  Base_Role SET RoleName = '{0}',Remark = '{1}' WHERE   RoleID = '{2}'", roleEntity.RoleName, roleEntity.Remark, roleEntity.RoleID);
     return DbHelper.ExecuteNonQuery(sqlCommand);
 }