Beispiel #1
0
 /// <summary>
 /// 更新IIS缓存中指定Id记录
 /// </summary>
 /// <param name="model">记录实体</param>
 public void SetModelForCache(Branch model)
 {
     SetModelForCache(Transform(model));
 }
Beispiel #2
0
        /// <summary>
        /// 添加与编辑Branch记录
        /// </summary>
        /// <param name="page">当前页面指针</param>
        /// <param name="model">Branch表实体</param>
        /// <param name="content">更新说明</param>
        /// <param name="isCache">是否更新缓存</param>
        /// <param name="isAddUseLog">是否添加用户操作日志</param>
        public void Save(Page page, Branch 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 ? "添加" : "编辑") + "Branch记录成功,ID为【" + model.Id + "】";
                    }

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

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

            return new DataAccess.Model.Branch
            {
                Id = model.Id,
                Code = model.Code,
                Name = model.Name,
                Notes = model.Notes,
                ParentId = model.ParentId,
                Sort = model.Sort,
                Depth = model.Depth,
                Manager_Id = model.Manager_Id,
                Manager_CName = model.Manager_CName,
                UpdateDate = model.UpdateDate,
            };
        }
        /// <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 (BranchBll.GetInstence().Exist(x => x.Name == sName && x.Id != id))
                {
                    return txtName.Label + "已存在!请重新输入!";
                }

                #endregion

                #region 赋值
                //定义是否更新其他关联表变量
                bool isUpdate = false;

                //获取实体
                var model = new Branch(x => x.Id == id);

                //判断是否有改变名称
                if (id > 0 && sName != model.Name)
                {
                    isUpdate = true;
                }

                //修改时间与管理员
                model.UpdateDate = DateTime.Now;
                model.Manager_Id = OnlineUsersBll.GetInstence().GetManagerId();
                model.Manager_CName = OnlineUsersBll.GetInstence().GetManagerCName();

                //设置名称
                model.Name = sName;
                //对应的父类id
                model.ParentId = ConvertHelper.Cint0(txtParent.Text);
                //设置备注
                model.Notes = StringHelper.Left(txtNotes.Text, 100);

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

                //设置排序
                if (txtSort.Text == "0")
                {
                    model.Sort = BranchBll.GetInstence().GetSortMax(model.ParentId) + 1;
                }
                else
                {
                    model.Sort = ConvertHelper.Cint0(txtSort.Text);
                }

                //新创建部门时,生成对应的部门编码
                if (id == 0)
                {
                    model.Code = SPs.P_Branch_GetMaxBranchCode(model.Depth + 1, model.ParentId).ExecuteScalar().ToString();
                }

                #endregion

                //----------------------------------------------------------
                //存储到数据库
                BranchBll.GetInstence().Save(this, model);

                //如果本次修改改变了相关名称,则同步更新其他关联表的对应名称
                if (isUpdate)
                {
                    PositionBll.GetInstence().UpdateValue_For_Branch_Id(this, model.Id, PositionTable.Branch_Name, model.Name);
                    ManagerBll.GetInstence().UpdateValue_For_Branch_Id(this, model.Id, ManagerTable.Branch_Name, model.Name);
                }
            }
            catch (Exception e)
            {
                result = "保存失败!";

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

            return result;
        }
Beispiel #5
0
 public static void Setup(int testItems)
 {
     SetTestRepo();
     for(int i=0;i<testItems;i++){
         Branch item=new Branch();
         _testRepo._items.Add(item);
     }
 }
Beispiel #6
0
 public static void Setup(Branch item)
 {
     SetTestRepo();
     _testRepo._items.Add(item);
 }