Exemplo n.º 1
0
        //分类列表
        public virtual ActionResult List()
        {
            if (parId == 0)
            {
                parId = RequestInt("parId");
            }
            int id = RequestInt("id");

            classHtml = bll.ShowClass(0, 0, true);
            var list = bll.GetChildrenList(parId, true).ToList();

            GetActStr(list);

            Sys_Class model = null;

            if (id > 0)
            {
                model = bll.GetModel(id);
            }

            ViewBag.title      = Title;
            ViewBag.breadcrumb = bll.ShowClassPath(parId, "<li><a href='" + this.Path + "/list?parId={0}'>{1}</a></li>");
            ViewBag.list       = list;
            ViewBag.id         = id;
            ViewBag.parId      = parId;
            ViewBag.model      = model;
            ViewBag.classHtml  = classHtml;
            ViewBag.path       = this.Path;

            //此方法不重写,则公用一个View
            return(View("ClassList"));
        }
Exemplo n.º 2
0
 /// <summary>
 /// 增加分类
 /// </summary>
 /// <param name="sys_ManageClass"></param>
 /// <returns></returns>
 public virtual int Add(T model)
 {
     if (string.IsNullOrEmpty(tableName))
     {
         return(0);
     }
     else
     {
         Sys_Class sysModel = Mapping(model);
         string    flag     = "Flag";
         var       proc     = Db.Context.FromProc(sysModel.DepartId > 0 ? "Sys_ClassAddByDepart" : "Sys_ClassAdd")
                              .AddInParameter("TableName", System.Data.DbType.String, tableName)
                              .AddInParameter("ClassName", System.Data.DbType.String, sysModel.ClassName)
                              .AddInParameter("ParId", System.Data.DbType.Int32, sysModel.ParId)
                              .AddInputOutputParameter(flag, System.Data.DbType.Int32, 0);
         if (sysModel.DepartId > 0)
         {
             proc.AddInParameter("DepartId", System.Data.DbType.Int32, sysModel.DepartId);
         }
         proc.ExecuteNonQuery();
         var dic = proc.GetReturnValues();
         if (dic.ContainsKey(flag))
         {
             return(dic[flag].ToString().ToInt32());
         }
         return(0);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 模型映射
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        protected Sys_Class Mapping(T t)
        {
            if (t == null)
            {
                return(null);
            }
            Sys_Class sysClass = null;

            PropertyInfo[] propertyInfo = t.GetType().GetProperties();
            if (propertyInfo != null && propertyInfo.Count() > 0)
            {
                sysClass = new Sys_Class();
                Hashtable dic = new Hashtable();
                foreach (PropertyInfo tp in propertyInfo)
                {
                    dic.Add(tp.Name.ToLower(), tp.GetValue(t, null));
                }
                sysClass.Id        = (int)dic["id"];
                sysClass.ParId     = (int?)dic["parid"];
                sysClass.ClassName = (string)dic["classname"];
                sysClass.ParPath   = (string)dic["parpath"];
                sysClass.ChildNum  = (int?)dic["childnum"];
                sysClass.Depth     = (int?)dic["depth"];
                sysClass.Sequence  = (int?)dic["sequence"];
                sysClass.BeLock    = (bool?)dic["belock"];
                sysClass.DepartId  = (int?)dic["departid"];
            }
            return(sysClass);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 设置是否菜单项 ,如果本来是,则设置否,如果本来否,则设置是
        /// </summary>
        /// <param name="infoId">需要设置的信息ID</param>
        /// <returns></returns>
        public virtual bool SetBeLock(int infoId)
        {
            Sys_Class model = GetModel(infoId);

            if (model.BeLock.HasValue && model.BeLock.Value)
            {
                return(UpdateBitField("belock", false, infoId));
            }
            else
            {
                return(UpdateBitField("belock", true, infoId));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 根据Id取得一条记录
        /// </summary>
        /// <param name="id">id</param>
        /// <returns>无记录或出错返回 null,有记录返回一个Model</returns>
        public virtual Sys_Class GetModel(System.Int32 id)
        {
            string sql = string.Format("select * from {0} where Id={1}", tableName, id);

            using (SqlDataReader reader = (SqlDataReader)Db.Context.FromSql(sql).ToDataReader())
            {
                Sys_Class model = null;
                try
                {
                    if (reader.Read())
                    {
                        model = new Sys_Class();

                        if (reader["Id"] != System.DBNull.Value)
                        {
                            model.Id = System.Int32.Parse(reader["Id"].ToString());
                        }
                        if (reader["ParId"] != System.DBNull.Value)
                        {
                            model.ParId = System.Int32.Parse(reader["ParId"].ToString());
                        }
                        model.ClassName = reader["ClassName"].ToString();
                        if (reader["Sequence"] != System.DBNull.Value)
                        {
                            model.Sequence = System.Int32.Parse(reader["Sequence"].ToString());
                        }
                        if (reader["Depth"] != System.DBNull.Value)
                        {
                            model.Depth = System.Int32.Parse(reader["Depth"].ToString());
                        }
                        if (reader["ChildNum"] != System.DBNull.Value)
                        {
                            model.ChildNum = System.Int32.Parse(reader["ChildNum"].ToString());
                        }
                        model.ParPath = reader["ParPath"].ToString();
                        if (reader["BeLock"] != System.DBNull.Value)
                        {
                            model.BeLock = System.Boolean.Parse(reader["BeLock"].ToString());
                        }
                    }
                }
                catch (Exception ex)
                {
                    Tools.Tool.LogHelper.WriteLog(this.GetType(), ex, 0, "");
                    return(null);
                }
                return(model);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// 根据ID获取所有子类包括其本身的分类
 /// </summary>
 /// <param name="parentId">父类ID</param>
 /// <param name="includeLock">是否包含锁定项s</param>
 /// <returns>下属分类列表</returns>
 public virtual IEnumerable <T> GetListByParentId(int parentId, bool includeLock)
 {
     string where = "1=1";
     if (!includeLock)
     {
         where += " and belock = cast(0 as bit)";
     }
     if (parentId > 0)
     {
         //先获取父类信息;
         Sys_Class modParentClassInfo = GetModel(parentId);
         if (modParentClassInfo == null)
         {
             return(null);
         }
         where += string.Format(" and  parpath like '{0}%'", modParentClassInfo.ParPath);
     }
     return(GetSelectList(0, "*", where, "sequence"));
 }
Exemplo n.º 7
0
        /// <summary>
        /// 根据底层的ClassID 获取Class路径
        /// </summary>
        /// <param name="childClassId"></param>
        /// <param name="urlFormat"></param>
        /// <returns></returns>
        public virtual string ShowClassPath2(int childClassId)
        {
            string    path          = "";
            Sys_Class mod_Sys_Class = GetModelByCache(childClassId);

            if (mod_Sys_Class == null)
            {
                return("");
            }
            else
            {
                path = mod_Sys_Class.ClassName;
                if (mod_Sys_Class.ParId > 0)
                {
                    path += "###" + ShowClassPath((int)mod_Sys_Class.ParId);
                }
            }
            return(path);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 根据底层的ClassID 获取Class路径(路由模版)
        /// </summary>
        /// <param name="childClassId"></param>
        /// <param name="urlFormat"></param>
        /// <returns></returns>
        public virtual string ShowClassPath(int childClassId, string urlFormat)
        {
            string    path  = "";
            Sys_Class model = GetModelByCache(childClassId);

            if (model == null)
            {
                return("");
            }
            else
            {
                path = string.Format(urlFormat, model.Id.ToString(), model.ClassName);
                if (model.ParId > 0)
                {
                    path = ShowClassPath((int)model.ParId, urlFormat) + path;
                }
            }
            return(path);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 根据底层的ClassID 获取Class路径
        /// </summary>
        /// <param name="childClassId"></param>
        /// <param name="urlFormat"></param>
        /// <returns></returns>
        public virtual string ShowClassPath(int childClassId)
        {
            string    path          = "";
            Sys_Class mod_Sys_Class = GetModelByCache(childClassId);

            if (mod_Sys_Class == null)
            {
                return("");
            }
            else
            {
                path = string.Format("{0}", mod_Sys_Class.ClassName);
                if (mod_Sys_Class.ParId > 0)
                {
                    path = ShowClassPath((int)mod_Sys_Class.ParId) + " > " + path;
                }
                else if (mod_Sys_Class.ParId == 0)
                {
                    path = "<span>" + path + "</span>";
                }
            }
            return(path);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 根据Id取得一条记录
        /// </summary>
        /// <param name="id">id</param>
        /// <returns>无记录或出错返回 null,有记录返回一个Model</returns>
        public virtual Sys_Class GetModel(System.Int32 id, string cols)
        {
            cols = cols.ToLower();
            string sql = string.Format("select {2} from {0} where Id={1}", tableName, id, cols);

            cols = "," + cols + ",";
            using (SqlDataReader reader = (SqlDataReader)Db.Context.FromSql(sql).ToDataReader())
            {
                Sys_Class model = null;
                try
                {
                    if (reader.Read())
                    {
                        model = new Sys_Class();
                        if (cols.IndexOf(",id,".ToLower()) >= 0)
                        {
                            if (reader["Id"] != System.DBNull.Value)
                            {
                                model.Id = System.Int32.Parse(reader["Id"].ToString());
                            }
                        }
                        if (cols.IndexOf(",parid,".ToLower()) >= 0)
                        {
                            if (reader["ParId"] != System.DBNull.Value)
                            {
                                model.ParId = System.Int32.Parse(reader["ParId"].ToString());
                            }
                        }
                        if (cols.IndexOf(",classname,".ToLower()) >= 0)
                        {
                            model.ClassName = reader["ClassName"].ToString();
                        }
                        if (cols.IndexOf(",sequence,".ToLower()) >= 0)
                        {
                            if (reader["Sequence"] != System.DBNull.Value)
                            {
                                model.Sequence = System.Int32.Parse(reader["Sequence"].ToString());
                            }
                        }
                        if (cols.IndexOf(",depth,".ToLower()) >= 0)
                        {
                            if (reader["Depth"] != System.DBNull.Value)
                            {
                                model.Depth = System.Int32.Parse(reader["Depth"].ToString());
                            }
                        }
                        if (cols.IndexOf(",childnum,".ToLower()) >= 0)
                        {
                            if (reader["ChildNum"] != System.DBNull.Value)
                            {
                                model.ChildNum = System.Int32.Parse(reader["ChildNum"].ToString());
                            }
                        }
                        if (cols.IndexOf(",parpath,".ToLower()) >= 0)
                        {
                            model.ParPath = reader["ParPath"].ToString();
                        }
                        if (cols.IndexOf(",belock,".ToLower()) >= 0)
                        {
                            if (reader["BeLock"] != System.DBNull.Value)
                            {
                                model.BeLock = System.Boolean.Parse(reader["BeLock"].ToString());
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Tools.Tool.LogHelper.WriteLog(this.GetType(), ex, 0, "");
                    return(null);
                }
                return(model);
            }
        }