//--------------------------日期:2013-8-28
//--------------------------版本:2.0.1.0
//--------------------------作者:itrycn
using System;
using System.Collections.Generic;
using System.Text;
//权限控制
namespace ryCommon
{
    /// <summary>
    /// 基于XML实现的权限类
    /// </summary>
    public class Authority
    {
        private Storage mStor = new Storage();
        private string m_username ="";
        /// <summary>
        /// 用户名
        /// </summary>
        public string UserName
        {
            get { return m_username; }
            set { m_username = value; }
        }
        private string m_userid = "";
        /// <summary>
        /// 用户id
        /// </summary>
        public string UserId
        {
            get { return m_userid; }
            set { m_userid = value; }
        }
        private string m_password = "";
        /// <summary>
        /// 密码
        /// </summary>
        public string PassWord
        {
            get { return m_password; }
            set { m_password = value; }
        }
        private string m_AuthId = "";
        /// <summary>
        /// 权限控制Id
        /// </summary>
        public string AuthId
        {
            get { return m_AuthId; }
            set { m_AuthId = value; }
        }
        private string m_UserDes = "";
        /// <summary>
        /// 用户备注
        /// </summary>
        public string UserDes
        {
            get { return m_UserDes; }
            set { m_UserDes = value; }
        }
        private int m_AdminAuth = 0;
        /// <summary>
        /// 是否是管理员权限
        /// </summary>
        public int AdminAuth
        {
            get { return m_AdminAuth; }
            set { m_AdminAuth = value; }
        }
        private int m_SuperAdmin = 0;
        /// <summary>
        /// 是否是超级管理员权限
        /// </summary>
        public int SuperAdmin
        {
            get { return m_SuperAdmin; }
            set { m_SuperAdmin = value; }
        }
        /// <summary>
        /// 设置权限
        /// </summary>
        /// <param name="name">权限名称</param>
        /// <param name="value">权限值</param>
        /// <returns>返回是否设置成功</returns>
        public int SetAuthority(string name, string value)
        {
            mStor.SelectNode2("name", name);
            return mStor.SetAttrValue("value", value);
        }
        /// <summary>
        /// 获取权限
        /// </summary>
        /// <param name="name">权限名称</param>
        /// <param name="defValue">默认权限值</param>
        /// <returns>返回权限值</returns>
        public string GetAuthority(string name,string defValue)
        {
            mStor.SelectNode("name", name);
            return mStor.GetAttrValue("value", defValue);
        }
        /// <summary>
        /// 获取权限
        /// </summary>
        /// <param name="name">权限名称</param>
        /// <returns>返回权限值</returns>
        public string GetAuthority(string name)
        {
            mStor.SelectNode("name", name);
            return mStor.GetAttrValue("value");
        }
        /// <summary>
        /// 批量导入权限
        /// </summary>
        /// <param name="XMLText">权限相关的内容</param>
        /// <returns>返回是否执行成功</returns>
        public int PutAuthorityText(string XMLText)
        {
           return mStor.LoadFromXMLText(XMLText);
        }
        /// <summary>
        /// 导出权限
        /// </summary>
        /// <returns>返回导出文本</returns>
        public string GetAuthorityText()
        {
            return mStor.GetXMLText();
        }
        /// <summary>
        /// 清除所有权限
        /// </summary>
        /// <returns>返回是否执行成功</returns>
        public int ClearAuthority()
        {
            return mStor.LoadEmptyXMLText();
        }
    }
}
