Esempio n. 1
0
        internal static IRepository <MenuInfo> GetRepo(string connectionString, string providerName)
        {
            Solution.DataAccess.DataModel.SolutionDataBase_standardDB db;
            if (String.IsNullOrEmpty(connectionString))
            {
                db = new Solution.DataAccess.DataModel.SolutionDataBase_standardDB();
            }
            else
            {
                db = new Solution.DataAccess.DataModel.SolutionDataBase_standardDB(connectionString, providerName);
            }
            IRepository <MenuInfo> _repo;

            if (db.TestMode)
            {
                MenuInfo.SetTestRepo();
                _repo = _testRepo;
            }
            else
            {
                _repo = new SubSonicRepository <MenuInfo>(db);
            }
            return(_repo);
        }
Esempio n. 2
0
        /// <summary>
        /// 取得MenuInfo全表内容——使用菜单地址做为KEY
        /// </summary>
        /// <returns>返回Hashtable</returns>
        public Hashtable GetHashtable()
        {
            //读取记录
            object obj = CacheHelper.GetCache(const_CacheKey_Model);
            //如果记录不存在,则重新加载
            if (obj == null)
            {
                //初始化全局菜单内容缓存
                var ht = new Hashtable();
                //获取菜单表全部内容
                var all = MenuInfo.All();
                //遍历读取
                foreach (var model in all)
                {
                    //创建菜单实体
                    var menuinfo = new MenuInfo();
                    menuinfo.Id = model.Id;
                    menuinfo.Name = model.Name;
                    menuinfo.Url = model.Url;
                    menuinfo.ParentId = model.ParentId;
                    menuinfo.Depth = model.Depth;

                    try
                    {
                        //将菜单实体存入容器中
                        //使用页面地址做为KEY
                        ht.Add(Encrypt.Md5(menuinfo.Url), menuinfo);
                    }
                    catch (Exception)
                    {
                    }
                }

                if (ht.Count > 0)
                {
                    CacheHelper.SetCache(const_CacheKey_Model, ht);
                }

                return ht;
            }
            else
            {
                return (Hashtable)obj;
            }
        }
Esempio n. 3
0
 /// <summary>
 /// 更新IIS缓存中指定Id记录
 /// </summary>
 /// <param name="model">记录实体</param>
 public void SetModelForCache(MenuInfo model)
 {
     SetModelForCache(Transform(model));
 }
Esempio n. 4
0
        /// <summary>
        /// 添加与编辑MenuInfo记录
        /// </summary>
        /// <param name="page">当前页面指针</param>
        /// <param name="model">MenuInfo表实体</param>
        /// <param name="content">更新说明</param>
        /// <param name="isCache">是否更新缓存</param>
        /// <param name="isAddUseLog">是否添加用户操作日志</param>
        public void Save(Page page, MenuInfo model, string content = null, bool isCache = true, bool isAddUseLog = true)
        {
            try {
                //保存
                model.Save();

                //判断是否启用缓存
                if (CommonBll.IsUseCache() && isCache)
                {
                    SetModelForCache(model);
                }

                if (isAddUseLog)
                {
                    if (string.IsNullOrEmpty(content))
                    {
                        content = "{0}" + (model.Id == 0 ? "添加" : "编辑") + "MenuInfo记录成功,ID为【" + model.Id + "】";
                    }

                    //添加用户访问记录
                    UseLogBll.GetInstence().Save(page, content);
                }
            }
            catch (Exception e) {
                var result = "执行MenuInfoBll.Save()函数出错!";

                //出现异常,保存出错日志信息
                CommonBll.WriteLog(result, e);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 将MenuInfo记录实体(SubSonic实体)转换为普通的实体(DataAccess.Model.MenuInfo)
        /// </summary>
        /// <param name="model">SubSonic插件生成的实体</param>
        /// <returns>DataAccess.Model.MenuInfo</returns>
        public DataAccess.Model.MenuInfo Transform(MenuInfo model)
        {
            if (model == null)
                return null;

            return new DataAccess.Model.MenuInfo
            {
                Id = model.Id,
                Name = model.Name,
                Url = model.Url,
                ParentId = model.ParentId,
                Sort = model.Sort,
                Depth = model.Depth,
                IsDisplay = model.IsDisplay,
                IsMenu = model.IsMenu,
            };
        }
Esempio n. 6
0
 public static void Setup(int testItems)
 {
     SetTestRepo();
     for(int i=0;i<testItems;i++){
         MenuInfo item=new MenuInfo();
         _testRepo._items.Add(item);
     }
 }
Esempio n. 7
0
 public static void Setup(MenuInfo item)
 {
     SetTestRepo();
     _testRepo._items.Add(item);
 }
Esempio n. 8
0
 public static void Setup(MenuInfo item)
 {
     SetTestRepo();
     _testRepo._items.Add(item);
 }
Esempio n. 9
0
        /// <summary>
        /// 数据保存
        /// </summary>
        /// <returns></returns>
        public override string Save()
        {
            string result = string.Empty;
            int id = ConvertHelper.Cint0(hidId.Text);

            try
            {
                #region 数据验证

                if (string.IsNullOrEmpty(txtName.Text.Trim()))
                {
                    return txtName.Label + "不能为空!";
                }
                var sName = StringHelper.Left(txtName.Text, 50);
                if (MenuInfoBll.GetInstence().Exist(x => x.Name == sName && x.Id != id))
                {
                    return txtName.Label + "已存在!请重新输入!";
                }
                if (string.IsNullOrEmpty(txtUrl.Text.Trim()))
                {
                    return txtUrl.Label + "不能为空!";
                }
                var sUrl = StringHelper.Left(txtUrl.Text, 250, true, false);
                if (MenuInfoBll.GetInstence().Exist(x => x.Url == sUrl && x.Id != id))
                {
                    return txtUrl.Label + "已存在!请重新输入!";
                }

                #endregion

                #region 赋值
                //获取实体
                var model = new MenuInfo(x => x.Id == id);

                //设置名称
                model.Name = sName;
                //连接地址
                model.Url = sUrl;
                //对应的父类id
                model.ParentId = ConvertHelper.Cint0(txtParent.Text);

                //由于限制了编辑时不能修改父节点,所以这里只对新建记录时处理
                if (id == 0)
                {
                    //设定当前的深度与设定当前的层数级
                    if (model.ParentId == 0)
                    {
                        //设定当前的层数级
                        model.Depth = 0;
                    }
                    else
                    {
                        //设定当前的层数
                        model.Depth = ConvertHelper.Cint0(MenuInfoBll.GetInstence().GetFieldValue(ConvertHelper.Cint0(ddlParentId.SelectedValue), MenuInfoTable.Depth)) + 1;
                    }
                }

                //设置排序
                if (txtSort.Text == "0")
                {
                    model.Sort = MenuInfoBll.GetInstence().GetSortMax(model.ParentId) + 1;
                }
                else
                {
                    model.Sort = ConvertHelper.Cint0(txtSort.Text);
                }
                //设定当前项属于菜单还是页面
                model.IsMenu = ConvertHelper.StringToByte(rblIsMenu.SelectedValue);
                //设定当前项是否显示
                model.IsDisplay = ConvertHelper.StringToByte(rblIsDisplay.SelectedValue);
                #endregion

                //----------------------------------------------------------
                //存储到数据库
                MenuInfoBll.GetInstence().Save(this, model);
            }
            catch (Exception e)
            {
                result = "保存失败!";

                //出现异常,保存出错日志信息
                CommonBll.WriteLog(result, e);
            }

            return result;
        }