public static void Setup(int testItems)
 {
     SetTestRepo();
     for (int i = 0; i < testItems; i++)
     {
         InformationClass item = new InformationClass();
         _testRepo._items.Add(item);
     }
 }
 public override bool Equals(object obj)
 {
     if (obj.GetType() == typeof(InformationClass))
     {
         InformationClass compare = (InformationClass)obj;
         return(compare.KeyValue() == this.KeyValue());
     }
     else
     {
         return(base.Equals(obj));
     }
 }
        public static InformationClass SingleOrDefault(Expression <Func <InformationClass, bool> > expression, string connectionString, string providerName)
        {
            var repo                = GetRepo(connectionString, providerName);
            var results             = repo.Find(expression);
            InformationClass single = null;

            if (results.Count() > 0)
            {
                single = results.ToList()[0];
            }

            return(single);
        }
        public static InformationClass SingleOrDefault(Expression <Func <InformationClass, bool> > expression)
        {
            var repo                = GetRepo();
            var results             = repo.Find(expression);
            InformationClass single = null;

            if (results.Count() > 0)
            {
                single = results.ToList()[0];
                single.OnLoaded();
                single.SetIsLoaded(true);
                single.SetIsNew(false);
            }

            return(single);
        }
 void Init()
 {
     TestMode      = this._db.DataProvider.ConnectionString.Equals("test", StringComparison.InvariantCultureIgnoreCase);
     _dirtyColumns = new List <IColumn>();
     if (TestMode)
     {
         InformationClass.SetTestRepo();
         _repo = _testRepo;
     }
     else
     {
         _repo = new SubSonicRepository <InformationClass>(_db);
     }
     tbl = _repo.GetTable();
     SetIsNew(true);
     OnCreated();
 }
        internal static IRepository <InformationClass> GetRepo(string connectionString, string providerName)
        {
            Solution.DataAccess.DataModel.SolutionDataBaseDB db;
            if (String.IsNullOrEmpty(connectionString))
            {
                db = new Solution.DataAccess.DataModel.SolutionDataBaseDB();
            }
            else
            {
                db = new Solution.DataAccess.DataModel.SolutionDataBaseDB(connectionString, providerName);
            }
            IRepository <InformationClass> _repo;

            if (db.TestMode)
            {
                InformationClass.SetTestRepo();
                _repo = _testRepo;
            }
            else
            {
                _repo = new SubSonicRepository <InformationClass>(db);
            }
            return(_repo);
        }
 public static void Setup(InformationClass item)
 {
     SetTestRepo();
     _testRepo._items.Add(item);
 }
        /// <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, 20);
                if (InformationClassBll.GetInstence().Exist(x => x.Name == sName && x.Id != id))
                {
                    return txtName.Label + "已存在!请重新输入!";
                }

                #endregion

                #region 赋值
                //定义是否更新其他关联表变量
                bool isUpdate = false;
                var oldParentId = ConvertHelper.Cint0(txtParent.Text);

                //获取实体
                var model = new InformationClass(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 = oldParentId;
                //设置备注
                model.Notes = StringHelper.Left(txtNotes.Text, 100);

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

                    //限制分类层数只能为3层
                    if (model.Depth > 3)
                    {
                        return "信息分类只能创建3层分类!";
                    }
                }

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

                //设定当前项是否显示
                model.IsShow = ConvertHelper.StringToByte(rblIsShow.SelectedValue);
                //设定当前项是否单页
                model.IsPage = ConvertHelper.StringToByte(rblIsPage.SelectedValue);

                //SEO
                model.SeoTitle = StringHelper.Left(txtSeoTitle.Text, 100);
                model.SeoKey = StringHelper.Left(txtSeoKey.Text, 100);
                model.SeoDesc = StringHelper.Left(txtSeoDesc.Text, 200);
                #endregion

                #region 上传图片
                //上传分类大图
                if (this.fuClassImg.HasFile && this.fuClassImg.FileName.Length > 3)
                {
                    int vid = 2; //2	信息(新闻)分类图
                    //---------------------------------------------------
                    var upload = new UploadFile();
                    result = new UploadFileBll().Upload_AspNet(this.fuClassImg.PostedFile, vid, RndKey, OnlineUsersBll.GetInstence().GetManagerId(), OnlineUsersBll.GetInstence().GetManagerCName(), upload);
                    this.fuClassImg.Dispose();
                    //---------------------------------------------------
                    if (result.Length == 0)//上传成功
                    {
                        model.ClassImg = upload.Path;
                    }
                    else
                    {
                        CommonBll.WriteLog("上传出错:" + result, null);//收集异常信息
                        return "上传出错!" + result;
                    }
                }
                //如果是修改,检查用户是否重新上传过新图片,如果是删除旧的图片
                if (model.Id > 0)
                {
                    UploadFileBll.GetInstence().Upload_DiffFile(InformationClassTable.Id, InformationClassTable.ClassImg, InformationClassTable.TableName, model.Id, model.ClassImg);

                    //同步UploadFile上传表
                    UploadFileBll.GetInstence().Upload_UpdateRs(RndKey, InformationClassTable.TableName, model.Id);
                }

                #endregion

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

                #region 同步更新上传图片表绑定Id
                if (id == 0)
                {
                    //同步UploadFile上传表记录,绑定刚刚上传成功的文件Id为当前记录Id
                    UploadFileBll.GetInstence().Upload_UpdateRs(RndKey, InformationClassTable.TableName, model.Id);
                }

                #endregion

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

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

            return result;
        }
        /// <summary>
        /// 将InformationClass记录实体(SubSonic实体)转换为普通的实体(DataAccess.Model.InformationClass)
        /// </summary>
        /// <param name="model">SubSonic插件生成的实体</param>
        /// <returns>DataAccess.Model.InformationClass</returns>
        public DataAccess.Model.InformationClass Transform(InformationClass model)
        {
            if (model == null)
                return null;

            return new DataAccess.Model.InformationClass
            {
                Id = model.Id,
                Name = model.Name,
                Notes = model.Notes,
                IsSys = model.IsSys,
                ClassImg = model.ClassImg,
                IsShow = model.IsShow,
                IsPage = model.IsPage,
                RootId = model.RootId,
                ParentId = model.ParentId,
                Depth = model.Depth,
                Sort = model.Sort,
                SeoTitle = model.SeoTitle,
                SeoKey = model.SeoKey,
                SeoDesc = model.SeoDesc,
                Manager_Id = model.Manager_Id,
                Manager_CName = model.Manager_CName,
                UpdateDate = model.UpdateDate,
            };
        }
 /// <summary>
 /// 更新IIS缓存中指定Id记录
 /// </summary>
 /// <param name="model">记录实体</param>
 public void SetModelForCache(InformationClass model)
 {
     SetModelForCache(Transform(model));
 }
        /// <summary>
        /// 添加与编辑InformationClass记录
        /// </summary>
        /// <param name="page">当前页面指针</param>
        /// <param name="model">InformationClass表实体</param>
        /// <param name="content">更新说明</param>
        /// <param name="isCache">是否更新缓存</param>
        /// <param name="isAddUseLog">是否添加用户操作日志</param>
        public void Save(Page page, InformationClass 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 ? "添加" : "编辑") + "InformationClass记录成功,ID为【" + model.Id + "】";
                    }

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

                //出现异常,保存出错日志信息
                CommonBll.WriteLog(result, e);
            }
        }
 public static void Setup(int testItems)
 {
     SetTestRepo();
     for(int i=0;i<testItems;i++){
         InformationClass item=new InformationClass();
         _testRepo._items.Add(item);
     }
 }
 public static void Setup(InformationClass item)
 {
     SetTestRepo();
     _testRepo._items.Add(item);
 }