using System;
using System.Collections.Generic;
using System.Text;
using Fm.DataAccess;
using System.Data;
using System.Data.Common;
using System.Collections;

namespace Fm.Bussiness
{
    public class sys_user_role
    {
        public sys_user_role()
        { }
        /// <summary>
        /// 添加新权限
        /// </summary>
        /// <param name="m_id">菜单栏ID</param>
        /// <param name="r_id">用户组ID</param>
        /// <returns></returns>
        public bool power_add(Fm.EntityClass.Power power)
        {
            DbCommand db = DataAccess.DataAccess.db.GetStoredProcCommand("Query_Fm_power_ADD");
            DataAccess.DataAccess.db.AddOutParameter(db, "@p_id",DbType.Int32,power.p_id);
            DataAccess.DataAccess.db.AddInParameter(db, "@m_id",DbType.Int32,power.m_id);
            DataAccess.DataAccess.db.AddInParameter(db, "@r_id",DbType.Int32,power.r_id);
            return DataAccess.DataAccess.GetData.Query<DbCommand>(db);
        }
        /// <summary>
        /// 修改新权限前删除原有权限            
        /// </summary>
        /// <param name="r_id"></param>
        /// <returns></returns>
        public bool power_del(Fm.EntityClass.Power power)
        {
            DbCommand db = DataAccess.DataAccess.db.GetStoredProcCommand("Query_Fm_power_Delete");
            DataAccess.DataAccess.db.AddInParameter(db, "@p_id", DbType.Int32, power.p_id);
            return DataAccess.DataAccess.GetData.Query<DbCommand>(db);
        }
        /// <summary>
        /// 根据角色ID来删除权限
        /// </summary>
        /// <param name="power"></param>
        /// <returns></returns>
        public bool power_del_role(Fm.EntityClass.Power power)
        {
            DbCommand db = DataAccess.DataAccess.db.GetStoredProcCommand("Query_Fm_power_Delete_1");
            DataAccess.DataAccess.db.AddInParameter(db, "@r_id", DbType.Int32, power.r_id);
            return DataAccess.DataAccess.GetData.Query<DbCommand>(db);
        }
        /// <summary>
        /// 获取用户组所拥有的权限
        /// </summary>
        /// <param name="r_id"></param>
        /// <returns></returns>
        public IList get_role(int r_id)
        {
            DbCommand db = DataAccess.DataAccess.db.GetStoredProcCommand("Fm_get_power");
            DataAccess.DataAccess.db.AddInParameter(db,"@r_id",DbType.Int16,r_id);
            return DataAccess.DataAccess.GetData.Select<DbCommand>(db);
        }
        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="m_id"></param>
        /// <returns></returns>
        public IList get_menu(int m_id)
        {
            DbCommand db = DataAccess.DataAccess.db.GetStoredProcCommand("Fm_get_menu");
            DataAccess.DataAccess.db.AddInParameter(db, "@m_id", DbType.Int16, m_id);
            return DataAccess.DataAccess.GetData.Select<DbCommand>(db);
        }
        /// <summary>
        /// 用户组信息删除
        /// </summary>
        /// <param name="r_id"></param>
        /// <returns></returns>
        public bool role_del(Fm.EntityClass.Role role)
        {
            DbCommand db = DataAccess.DataAccess.db.GetStoredProcCommand("Query_Fm_role_Delete");
            DataAccess.DataAccess.db.AddInParameter(db,"@r_id",DbType.Int32,role.r_id);
            return DataAccess.DataAccess.GetData.Query<DbCommand>(db);

        }
        /// <summary>
        /// 用户组信息添加
        /// </summary>
        /// <param name="r_name">用户组名称</param>
        /// <param name="g_id">所属级别</param>
        /// <returns></returns>
        public bool role_add(Fm.EntityClass.Role role)
        {
            DbCommand db = DataAccess.DataAccess.db.GetStoredProcCommand("Query_Fm_role_ADD");
            DataAccess.DataAccess.db.AddOutParameter(db,"@r_id",DbType.Int32,role.r_id);
            DataAccess.DataAccess.db.AddInParameter(db, "@r_name",DbType.String,role.r_name);
            DataAccess.DataAccess.db.AddInParameter(db, "@g_id",DbType.Int32,role.g_id);
            return DataAccess.DataAccess.GetData.Query<DbCommand>(db);
        }
        /// <summary>
        /// 用户组信息修改
        /// </summary>
        /// <param name="r_id">用户组ID</param>
        /// <param name="r_name">用户组名称</param>
        /// <param name="g_id">所属级别</param>
        /// <returns></returns>
        public bool role_update(Fm.EntityClass.Role role)
        {
            DbCommand db = DataAccess.DataAccess.db.GetStoredProcCommand("Query_Fm_role_Update");
            DataAccess.DataAccess.db.AddInParameter(db, "@r_id", DbType.Int32, role.r_id);
            DataAccess.DataAccess.db.AddInParameter(db, "@r_name", DbType.String, role.r_name);
            DataAccess.DataAccess.db.AddInParameter(db, "@g_id", DbType.Int32, role.g_id);
            return DataAccess.DataAccess.GetData.Query<DbCommand>(db);
        }
    }
}
