C#技术百科
问问你的心你有没有信心 做事情要专一坚定,执着

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using System.Data.SqlClient;
using System.Text;
namespace BLL
{
    public enum ModelList
    {
        商业信息 = 0,
        产品信息 = 1,
        免费会员 = 2,
        浙商通会员 = 3,
        会员操作 = 4,
        留言管理 = 5,
        系统设置 = 6,
        权限设置 = 7,
    }
    public class AdminPage : System.Web.UI.Page
    {
        private int _PageSize;
       // private int _CurrentPage;
        private string _Columns;
        private string _TableName;
        private string _Where;
        private string _Order;
        private string _Pid;
        private DataTable _PageData;
        private string _checkbox;
        private string _U_Account;

        private SQLDB.DbAccess _db;
        public string[] MIDS = new string[]{"BE875758-3608-4B89-B3A2-1C30F0418E8A","C55FA608-29CC-4FB5-8A54-F0190BA3DEFC","A90D5DE5-530F-47F3-87D5-3D0D014019D5","FD024BF2-9690-46E1-A1B0-5A2046D9E4EA","3B8D9F44-1185-4BC2-A861-A116302A7024","4B124CD5-3064-4B8D-9977-BCC953018C56","414D177A-2DC6-4F2D-A788-E6C37C23DF79","01E6167F-BF36-4498-ABDB-0E8C2AEDD23F"};
        /// <summary>
        /// 页面大小
        /// </summary>
        public int PageSize
        {

            set
            {
                if (Regex.IsMatch(Convert.ToString(value), "^\\d+$"))
                {
                    this._PageSize = Convert.ToInt32(value);
                }
                else
                {
                    this._PageSize =1;
                }
            }
            get
            {
                return this._PageSize;
            }

        }
        /// <summary>
        /// 当前页
        /// </summary>
        public int CurrentPage
        {
            get
            {
                return (Convert.ToInt32(Convert.ToInt32(Request["page"] ?? "0")));
            }
        }
        /// <summary>
        /// 显示的字段
        /// </summary>
        public string Columns
        {
            set
            {
                _Columns = value;
            }
            get
            {
                return _Columns;
            }
        }
        /// <summary>
        /// 表明
        /// </summary>
        public string TableName
        {
            set
            {
                _TableName = value;
            }
            get
            {
                return _TableName;
            }
        }
        /// <summary>
        /// 条件
        /// </summary>
        public string Where
        {
            set
            {
                _Where = value;
            }
            get
            {
                return _Where;
            }
        }
        /// <summary>
        /// 排序
        /// </summary>
        public string Order
        {
            set
            {
                _Order = value;
            }
            get
            {
                return _Order;
            }
        }
    /// <summary>
    /// 逐渐字段
    /// </summary>
        public string Pid
        {
            set
            {
                _Pid = value;
            }
            get
            {
                return _Pid;
            }
        }
        /// <summary>
        /// 分页数据
        /// </summary>
        public DataTable PageData
        {

            get
            {
                _PageData = this.Db.GetProcAdminData(this.CurrentPage, PageSize, Columns, TableName, Pid, Where, Order, "","");
                return _PageData;

            }
        }
        /// <summary>
        /// 数据库链接类
        /// </summary>
        public SQLDB.DbAccess Db
        {
            get
            {
                if (_db ==null)
                {
                  this._db = new SQLDB.DbAccess();
                }
          
                return _db;
            }
        }
        /// <summary>
        /// 多选框的模板
        /// </summary>
        public string CheckBoxString
        {
            get
            {
                if (_checkbox == null|| _checkbox.Length < 1)
                {
                    return "<input type=\"checkbox\" name=\"action\" value=\"{0}\"/>";
                }
                else
                {
                    return _checkbox;
                }
            }
            set
           
            {
                this._checkbox = value;
            }
        }
        /// <summary>
        /// 用户名
        /// </summary>
        public string U_Account
        {
            get
            {
                try
                {
                    _U_Account= Convert.ToString(HttpContext.Current.Request.Cookies["adminusers"]["name"] ?? "");
                }
                catch
                {
                    _U_Account = "";
                   
                }
                return _U_Account;
             
            }
           
        }
        //****************************************************************************************************属性
        public AdminPage()
        {
            if (!IsAdminLogin())
            {
                HttpContext.Current.Response.Redirect(HttpContext.Current.Request.Url.ToString().Replace(HttpContext.Current.Request.RawUrl.ToString(), "") + "/manage/index.aspx");
            }
        }
        /// <summary>
        /// 查看是否管理员是否登陆
        /// </summary>
        /// <returns></returns>
        public bool IsAdminLogin()
        {
            bool state = false;
            string username = "";     
            string userpass ="";
            try
            {
                username = Convert.ToString(HttpContext.Current.Request.Cookies["adminusers"]["name"] ?? "");

                userpass = Convert.ToString(HttpContext.Current.Request.Cookies["adminusers"]["pass"] ?? "");
            }
            catch
            {

                state = false;
            }
            if (username.Length < 1 || userpass.Length < 1)
            {

            }
            else
            {
                state = true;
            }
            return state;
        }
        /// <summary>
        /// 条件设置字符串
        /// </summary>
        public string GetWhereString(string whereName,string whereValue)
        {
            return string.Format(" and [{0}] like '%{1}%'", whereName, whereValue);
        }
        //////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 获取参数值
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public string GetRequest(string key)
        {
            return Convert.ToString(Request[key]??"").Replace("'","''");
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        //////----------------------------------------方法的集合--------------------------------------------------------------
        ////////数据绑定方法
        /// <summary>
        /// 绑定列表框
        /// </summary>
        /// <param name="ddl"></param>
        /// <param name="dt"></param>
        /// <param name="text"></param>
        /// <param name="value"></param>
        public void BindDropDownList(ref DropDownList ddl,DataTable dt,string text,string value)
        {
            ddl.DataSource = dt;
            ddl.DataTextField = text;
            ddl.DataValueField = value;
            ddl.DataBind();
        }
        /// <summary>
        /// 绑定列表框
        /// </summary>
        /// <param name="ddl"></param>
        /// <param name="dt"></param>
        /// <param name="text"></param>
        /// <param name="value"></param>
        public void BindListBox(ref ListBox ddl, DataTable dt, string text, string value)
        {
            ddl.DataSource = dt;
            ddl.DataTextField = text;
            ddl.DataValueField = value;
            ddl.DataBind();
        }
        /////////////////////     ////////数据绑定方法------------------------------------------------------------------
        /// <summary>
        /// /获取选中的多选框
        /// </summary>
        /// <returns></returns>
        public string[] GetCheckValues()
        {
            string ids = Convert.ToString(Request["action"] ?? "");
            if (ids.Length > 0)
            {
                string[] id = ids.Trim(',').Split(',');
                return id;
            }
            else
            {
                return new string[] { "-100" };
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public ArrayList GetSqls(string sql)
        {
            string[] ids = this.GetCheckValues();
            ArrayList al = new ArrayList();
            for (int i = 0; i < ids.Length; i++)
            {
                al.Add(string.Format(sql, (ids[i].Replace("'", "''"))));
            }
            return al;
        }
        //////////////-----------------------------消息类-----------------------------------------------------------
        /// <summary>
        /// 弹出错误的信息
        /// </summary>
        /// <param name="err"></param>
        public void ShowError(string err)
        {
             System.Web.HttpContext.Current.Response.Write(Script(err, ""));
        }
        /// <summary>
        /// 显示信息
        /// </summary>
        /// <param name="err"></param>
        public void ShowMessage(string mes, string loc)
        {
             System.Web.HttpContext.Current.Response.Write(Script(mes, loc));
        }
        /// <summary>
        /// javascript脚本
        /// </summary>
        /// <param name="mess"></param>
        /// <param name="loc"></param>
        /// <returns></returns>
        public string Script(string mess, string loc)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<script language='javascript'>");
            sb.Append("alert('");
            sb.Append(mess);
            sb.Append("');");
            sb.Append(loc);
            sb.Append("</script>");
            return sb.ToString();

        }
        public virtual RightClass Power(string U_Account,string M_ID)
        {
            //select [right_Insert],[right_Delete],[right_Update],[right_Select],[right_Verify],[right_Other],[right_Other1] from User_right where U_Account=@U_Account and M_ID=@M_ID
            RightClass rc = new RightClass();
            if (U_Account == "administrator")
            {
                rc.right_Insert = true;
                rc.right_Delete = true;
                rc.right_Update = true;
                rc.right_Select = true;
                rc.right_Verify = true;
                rc.right_Other = true;
                rc.right_Other1 = true;
            }
            else
            {
                #region 权限设定
                SqlParameter[] pas = { new SqlParameter("@U_Account", U_Account), new SqlParameter("@M_ID", M_ID) };
                DataTable dt = this.Db.GetTable("select isnull([right_Insert],0) right_Insert,isnull([right_Delete],0) right_Delete,isnull([right_Update],0) right_Update,isnull([right_Select],0) right_Select,isnull([right_Verify],0) right_Verify,isnull([right_Other],0) right_Other,isnull([right_Other1],0) right_Other1 from User_right where U_Account=@U_Account and M_ID=@M_ID", pas);
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        DataRow dr = dt.Rows[0];
                        rc.right_Insert = Convert.ToBoolean(dr["right_Insert"] ?? false);
                        rc.right_Delete = Convert.ToBoolean(dr["right_Delete"] ?? false);
                        rc.right_Update = Convert.ToBoolean(dr["right_Update"] ?? false);
                        rc.right_Select = Convert.ToBoolean(dr["right_Select"] ?? false);
                        rc.right_Verify = Convert.ToBoolean(dr["right_Verify"] ?? false);
                        rc.right_Other = Convert.ToBoolean(dr["right_Other"] ?? false);
                        rc.right_Other1 = Convert.ToBoolean(dr["right_Other1"] ?? false);
                    }
                    else
                    {
                        rc.right_Insert = Convert.ToBoolean(false);
                        rc.right_Delete = Convert.ToBoolean(false);
                        rc.right_Update = Convert.ToBoolean(false);
                        rc.right_Select = Convert.ToBoolean(false);
                        rc.right_Verify = Convert.ToBoolean(false);
                        rc.right_Other = Convert.ToBoolean(false);
                        rc.right_Other1 = Convert.ToBoolean(false);
                    }
                }
                else
                {
                    rc.right_Insert = Convert.ToBoolean(false);
                    rc.right_Delete = Convert.ToBoolean(false);
                    rc.right_Update = Convert.ToBoolean(false);
                    rc.right_Select = Convert.ToBoolean(false);
                    rc.right_Verify = Convert.ToBoolean(false);
                    rc.right_Other = Convert.ToBoolean(false);
                    rc.right_Other1 = Convert.ToBoolean(false);
                }
                if (!rc.right_Select)
                {
                    Response.Write("<font color='red'>你对此栏目没有权限!!请联系管理员</font>");
                    Response.End();
                }
                #endregion
            }
          
           
            return rc;
           
        }

        //////////////-----------------------------消息类-----------------------------------------------------------
 
  }
    /// <summary>
    /// 权限类
    /// </summary>
     public class RightClass
     {
         private bool _right_Insert;
         private bool _right_Delete;
         private bool _right_Update;
         private bool _right_Select;
         private bool _right_Verify;
         private bool _right_Other;
         private bool _right_Other1;
         public bool right_Insert { set { this._right_Insert = value; } get { return this._right_Insert; } }
         public bool right_Delete { set { this._right_Delete = value; } get { return this._right_Delete; } }
         public bool right_Update { set { this._right_Update = value; } get { return this._right_Update; } }
         public bool right_Select { set { this._right_Select = value; } get { return this._right_Select; } }
         public bool right_Verify { set { this._right_Verify = value; } get { return this._right_Verify; } }
         public bool right_Other { set { this._right_Other = value; } get { return this._right_Other; } }
         public bool right_Other1 { set { this._right_Other1 = value; } get { return this._right_Other1; } }
     }
}

posted on 2008-06-17 10:04  王德田  阅读(322)  评论(0编辑  收藏  举报