Esempio n. 1
0
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  BasicMethod
        #region  ExtensionMethod

        #region 获取分页数据
        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="orderBy"></param>
        /// <param name="recordCount"></param>
        /// <param name="where"></param>
        /// <param name="fields"></param>
        /// <returns></returns>
        public List <oyxf.Model.Category> GetPage(int pageIndex, int pageSize, string orderBy, out int recordCount, string where = "", string fields = "*")
        {
            DataSet ds = dal.GetPage("Category", pageIndex, pageSize, orderBy, out recordCount, where, fields);

            if (ds == null || ds.Tables[0].Rows.Count <= 0)//非空判断
            {
                return(null);
            }
            List <oyxf.Model.Category> list = DataTableToList(ds.Tables[0]);                            //获取当前页数据
            List <int> listParentId         = list.Select(o => o.ParentId).ToList();                    //拿到当前页父级Id集合

            string ids = string.Join(",", listParentId.ToArray());                                      //拼接父级Id
            List <oyxf.Model.Category> listParentCategory = GetModelList("CategoryId in(" + ids + ")"); //获取父级Category数据

            for (int i = 0; i < list.Count; i++)                                                        //将当前页数据扩展的ParentCategoryName赋值为对应的Name
            {
                if (list[i].ParentId == 0)
                {
                    list[i].ParentCategoryName = "顶级分类";
                    continue;
                }
                oyxf.Model.Category parentCategory = listParentCategory.SingleOrDefault(o => o.CategoryId == list[i].ParentId);
                list[i].ParentCategoryName = parentCategory != null ? parentCategory.Name : "";
            }
            return(list);
        }
Esempio n. 2
0
        /// <summary>
        /// 新增分类
        /// </summary>
        private void AddCategory()
        {
            oyxf.Model.Category newCategory = GetControlData();//当前新增的分类
            newCategory.Content     = "";
            newCategory.HasChildren = 0;
            int categoryId = bll.Add(newCategory);

            newCategory.CategoryId = categoryId; //将自增长的id赋值到当前新增分类的实体对象
            if (newCategory.ParentId == 0)       //新增顶级分类
            {
                newCategory.IdPath = ',' + categoryId.ToString() + ',';
                newCategory.Depth  = 1;
            }
            else //新增非顶级分类
            {
                oyxf.Model.Category parentCategory = bll.GetModel(newCategory.ParentId);
                newCategory.IdPath = parentCategory.IdPath + categoryId + ',';
                newCategory.Depth  = parentCategory.Depth + 1;

                //修改父级分类的HasChildren
                parentCategory.HasChildren = 1;
                bll.Update(parentCategory);
            }
            bll.Update(newCategory);
            ScriptHelper.AlertRedirect("新增成功", "/Category/List.aspx");
        }
Esempio n. 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Context.Request.QueryString["id"];

            ViewState["id"] = id;
            oyxf.Model.Category model = bll.GetModel(Convert.ToInt32(id));
            lblCategoryName.Text = model.Name;
            Content = model.Content;
        }
Esempio n. 4
0
 /// <summary>
 /// 实体绑定到控件上
 /// </summary>
 /// <param name="categoryId"></param>
 private void BindModelToControl(int categoryId)
 {
     oyxf.Model.Category model = bll.GetModel(Convert.ToInt32(categoryId));
     txtCategoryName.Text      = model.Name;
     ddlType.SelectedValue     = model.Type.ToString();
     ddlParentId.SelectedValue = model.ParentId.ToString();
     rblStatus.SelectedValue   = model.Status.ToString();
     txtSortIndex.Text         = model.SortIndex.ToString();
     txtUrl.Text = model.Url;
 }
Esempio n. 5
0
        /// <summary>
        /// 修改分类
        /// </summary>
        private void modifyCategory()
        {
            string categoryId = ViewState["id"].ToString();

            oyxf.Model.Category oldCategory = bll.GetModel(Convert.ToInt32(categoryId));
            oyxf.Model.Category newCategory = GetControlData();
            //数据没有被修改
            if (oldCategory.Name == newCategory.Name && oldCategory.ParentId == newCategory.ParentId &&
                oldCategory.Type == newCategory.Type && oldCategory.Status == newCategory.Status &&
                oldCategory.SortIndex == newCategory.SortIndex && oldCategory.Url == newCategory.Url)
            {
                ScriptHelper.Alert("数据没有被修改");
                return;
            }
            //数据被修改了
            newCategory.CategoryId = oldCategory.CategoryId;
            newCategory.Content    = oldCategory.Content;
            oyxf.Model.Category oldParentCategory = bll.GetModel(oldCategory.ParentId);
            oyxf.Model.Category newParentCategory = bll.GetModel(newCategory.ParentId);
            bll.UpdateFatherCategory(oldParentCategory, newParentCategory, oldCategory, newCategory);
            ScriptHelper.AlertRedirect("修改成功", "/Category/List.aspx");
        }
Esempio n. 6
0
        /// <summary>
        /// 删除分类项
        /// </summary>
        /// <param name="CategoryId"></param>
        /// <returns></returns>
        public bool DeleteCategory(int CategoryId)
        {
            oyxf.Model.Category model = GetModel(CategoryId);//当前要删除的分类

            if (dal.DeleteCategory(CategoryId) > 0)
            {
                //删除之后,要判断原父节点是否还有子节点
                string where = "ParentId=" + model.ParentId;
                if (dal.GetRecordCount(where) <= 0)//原父节点没有子节点
                {
                    //修改原父节点的HasChildren
                    UpdateHasChildren(model.ParentId, false);
                }
                else
                {
                    UpdateHasChildren(model.ParentId, true);
                }

                return(true);
            }

            return(false);
        }
Esempio n. 7
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(oyxf.Model.Category model)
 {
     return(dal.Update(model));
 }
Esempio n. 8
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(oyxf.Model.Category model)
 {
     return(dal.Add(model));
 }