国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

以一個(gè)權(quán)限系統(tǒng)來(lái)告別WebForm —(一)項(xiàng)目整休架構(gòu)設(shè)計(jì)與數(shù)據(jù)庫(kù)設(shè)計(jì)

2019-11-17 02:09:15
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

以一個(gè)權(quán)限系統(tǒng)來(lái)告別WebForm —(一)項(xiàng)目整休架構(gòu)設(shè)計(jì)與數(shù)據(jù)庫(kù)設(shè)計(jì)

在本節(jié)我想與大家與分享一下,我所將要做的權(quán)限系統(tǒng)的架構(gòu)和數(shù)據(jù)庫(kù)的表的設(shè)計(jì)。請(qǐng)各位大神們對(duì)我項(xiàng)目中設(shè)計(jì)的不足之處進(jìn)行指導(dǎo),讓我得以更好的寫(xiě)完它,留給需要它的人。

我的項(xiàng)目架構(gòu)如下圖所示:

如上圖所示,在數(shù)據(jù)訪問(wèn)層,我采用了抽象工廠的方式,來(lái)對(duì)數(shù)據(jù)訪問(wèn)層和業(yè)務(wù)邏輯層解耦,當(dāng)然如果你想更高大上一些,可以用第三方的框架,比如SPRing.Net ,Autofac來(lái)實(shí)現(xiàn)。解耦的好處在于可以方便的切換數(shù)據(jù)庫(kù),當(dāng)數(shù)據(jù)庫(kù)變更時(shí),只需換一下對(duì)應(yīng)的數(shù)據(jù)訪問(wèn)DAL就行,本系列中,我所采用的是SQLServer。寫(xiě)到這我想在如下這個(gè)大數(shù)據(jù)時(shí)代,MongoDB其實(shí)也是不錯(cuò)的。后面有機(jī)會(huì),可以開(kāi)一個(gè)MongoDB的專題和大家一起來(lái)使用一下MongoDB學(xué)習(xí)一下它。對(duì)于抽象工廠來(lái)實(shí)現(xiàn)業(yè)務(wù)邏輯層與數(shù)據(jù)訪問(wèn)層的解耦實(shí)現(xiàn)代碼如下,主要用到了反射,面向接口編程。

配置:

<appSettings>  <add key="DAL" value="MCFramework.SQLDAL"/>    <!--頁(yè)容量-->  <add key="PageSize" value="20"/></appSettings>
View Code

抽象工廠:

namespace MCFramework.RepositoryFactory{    public class RepositoryFactory    {        public RepositoryFactory()        { }        private static readonly string AssemblyPath =ConfigurationSettings.AppSettings["DAL"];        #region CreateObject        //不使用緩存        private static object CreateObjectNoCache(string AssemblyPath, string classNamespace)        {            try            {                object objType = Assembly.Load(AssemblyPath).CreateInstance(classNamespace);                return objType;            }            catch(System.Exception ex)            {                string str=ex.StackTrace;// 記錄錯(cuò)誤日志                return null;            }        }        //使用緩存        //private static object CreateObject(string AssemblyPath, string classNamespace)        //{        //    object objType = DataCache.GetCache(classNamespace);        //    if (objType == null)        //    {        //        try        //        {        //            objType = Assembly.Load(AssemblyPath).CreateInstance(classNamespace);        //            DataCache.SetCache(classNamespace, objType);// 寫(xiě)入緩存        //        }        //        catch//(System.Exception ex)        //        {        //            //string str=ex.Message;// 記錄錯(cuò)誤日志        //        }        //    }        //    return objType;        //}        #endregion        /// <summary>        /// 用戶倉(cāng)儲(chǔ)        /// </summary>        public static ISystem_EmployeeRepository System_EmployeeRepository { get { return (ISystem_EmployeeRepository)CreateObjectNoCache(AssemblyPath, AssemblyPath + ".System_EmployeeRepository"); } }        /// <summary>        ///菜單倉(cāng)儲(chǔ)        /// </summary>        public static ISystem_MenuRepository  System_MenuRepository { get { return (ISystem_MenuRepository)CreateObjectNoCache(AssemblyPath, AssemblyPath + ".System_MenuRepository"); } }        /// <summary>        ///角色倉(cāng)儲(chǔ)        /// </summary>        public static ISystem_RoleRepository System_RoleRepository { get { return (ISystem_RoleRepository)CreateObjectNoCache(AssemblyPath, AssemblyPath + ".System_RoleRepository"); } }        /// <summary>        ///按鈕倉(cāng)儲(chǔ)        /// </summary>        public static ISystem_ButtonRepository System_ButtonRepository { get { return (ISystem_ButtonRepository)CreateObjectNoCache(AssemblyPath, AssemblyPath + ".System_ButtonRepository"); } }    }}
View Code

所有的訪問(wèn)數(shù)據(jù)庫(kù)的操作都用接口來(lái)約束:

namespace MCFramework.IDAL{    public interface IBaseRepository<T> where T:class    {        int Add(T model);        int UpdateDel(string ids, bool isDel);        int Del(string ids);        int Update(T model);        DataSet GetListByProc(string procName, System.Data.SqlClient.SqlParameter[] paras);        DataSet GetModel(string Id);        DataSet GetList(string strWhere);    }}
View Code
namespace MCFramework.IDAL{   public interface ISystem_ButtonRepository:IBaseRepository<System_ButtonModel>    {        bool IsExit(string ButtonCode);    }}
View Code

接口的實(shí)現(xiàn):

namespace MCFramework.SQLDAL{    /// <summary>    /// Author: MaChun    /// Description: DALTier -- the DAL class of System_Button.    /// Datetime:2015/6/8 13:00:35    /// </summary>    public class  BaseSystem_ButtonRepository: IBaseRepository<System_ButtonModel>    {            //創(chuàng)建企業(yè)庫(kù)連接     public  SqlDataaccess db = SqlDataAccess.CreateDataAccess();            #region 新增一條記錄 Add(System_ButtonModel model)        /// <summary>        /// 新增一條記錄        /// </summary>        public int Add(System_ButtonModel  model)        {            int result = 0;            try            {                StringBuilder strSql = new StringBuilder();                strSql.Append("insert into System_Button(");                strSql.Append("SBT_Guid,SBT_ButtonCode,SBT_ButtonName,SBT_IconUrl,SBT_IconCSS,SBT_CreateBy,SBT_CreatedDate)");                strSql.Append(" values (");                strSql.Append("@SBT_Guid,@SBT_ButtonCode,@SBT_ButtonName,@SBT_IconUrl,@SBT_IconCss,@SBT_CreateBy,@SBT_CreatedDate)");                strSql.Append(";select @@IDENTITY");                SqlParameter[] parameters = {                    new SqlParameter("@SBT_Guid", SqlDbType.VarChar,36),                    new SqlParameter("@SBT_ButtonCode", SqlDbType.VarChar,200),                    new SqlParameter("@SBT_ButtonName", SqlDbType.VarChar,100),                    new SqlParameter("@SBT_IconUrl", SqlDbType.VarChar,100),                    new SqlParameter("@SBT_IconCss", SqlDbType.VarChar,100),                    new SqlParameter("@SBT_CreateBy", SqlDbType.VarChar,100),                    new SqlParameter("@SBT_CreatedDate", SqlDbType.DateTime,8)};                                parameters[0].Value = model.SBTGuid;                parameters[1].Value = model.SBTButtonCode;                parameters[2].Value = model.SBTButtonName;                parameters[3].Value = model.SBTIconUrl;                parameters[4].Value = model.SBTIconCss;                parameters[5].Value = model.SBTCreateBy;                parameters[6].Value = model.SBTCreatedDate;                                result =   db.ExecuteNonQuery(strSql.ToString(), parameters);            }            catch (Exception ex)            {                throw ex;            }            return result;        }        #endregion         #region 邏輯刪除 UpdateDel(
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 莱西市| 静海县| 农安县| 丰县| 二连浩特市| 方城县| 宁河县| 绥芬河市| 双柏县| 东莞市| 盈江县| 贺兰县| 深州市| 台中县| 留坝县| 会东县| 石城县| 枣强县| 麻城市| 和龙市| 丹凤县| 任丘市| 海丰县| 梁山县| 黑龙江省| 宝丰县| 从化市| 和政县| 诏安县| 伊川县| 资中县| 松潘县| 永昌县| 南溪县| 保山市| 怀宁县| 和静县| 尤溪县| 裕民县| 泗洪县| 微山县|