Beispiel #1
0
        public ActionResult New(int?id, int pid)
        {
            int CategoryID = id == null ? 0 : (int)id;

            Model.SysCategory model = new Model.SysCategory();
            model.ParentID = pid;
            if (CategoryID > 0)
            {
                model         = Opr.GetEntity(CategoryID);
                ViewBag.Title = "品类管理-正在编辑品类名称: " + model.Name;
            }
            else
            {
                if (pid == 0)
                {
                    model.Layer = 1;
                }
                else
                {
                    model.Layer = Opr.GetLayer(pid) + 1;
                }
                model.CategoryID = 0;
                model.State      = true;
                ViewBag.Title    = "新增品类";
            }
            return(View(model));
        }
Beispiel #2
0
        /// <summary>
        /// 修改模块
        /// </summary>
        /// <returns>返回影响行数</returns>
        /// <param name="Model">模块实体</param>
        public int ModifyModel(Model.SysCategory Model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("Update SysCategory ");
            strSql.Append("Set Name=@Name,Style=@Style ");
            strSql.Append("Where CategoryID=@CategoryID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CategoryID", SqlDbType.Int,       4),
                new SqlParameter("@Name",       SqlDbType.NVarChar, 50),
                new SqlParameter("@Style",      SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = Model.CategoryID;
            parameters[1].Value = Model.Name;
            parameters[2].Value = Model.Style;
            return(DbHelperSQL.ExecuteSql(strSql.ToString(), parameters));
        }
Beispiel #3
0
        /// <summary>
        /// 设置实体
        /// </summary>
        /// <returns>返回对象实体</returns>
        /// <param name="dr">行</param>
        private Model.SysCategory SetEntity(DataRow dr)
        {
            Model.SysCategory model = new Model.SysCategory();
            if (dr != null)
            {
                if (dr["CategoryID"].ToString() != "")
                {
                    model.CategoryID = int.Parse(dr["CategoryID"].ToString());
                }
                if (dr["ParentID"].ToString() != "")
                {
                    model.ParentID = int.Parse(dr["ParentID"].ToString());
                }
                model.Name = dr["Name"].ToString();
                if (dr["Layer"].ToString() != "")
                {
                    model.Layer = int.Parse(dr["Layer"].ToString());
                }
                model.Style     = dr["Style"].ToString();
                model.OrderCode = dr["OrderCode"].ToString();
                if (dr["State"].ToString() != "")
                {
                    if ((dr["State"].ToString() == "1") || (dr["State"].ToString().ToLower() == "true"))
                    {
                        model.State = true;
                    }
                    else
                    {
                        model.State = false;
                    }
                }

                return(model);
            }
            else
            {
                return(null);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 插入品类
        /// </summary>
        /// <returns>The insert.</returns>
        /// <param name="Model">Model.</param>
        public int Insert(Model.SysCategory Model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(" if not exists(select Name from SysCategory where Name =@Name ) begin ");
            strSql.Append(" insert into SysCategory(");
            strSql.Append(" ParentID,Name,Layer,State,Style,OrderCode)");
            strSql.Append(" values (");
            strSql.Append(" @ParentID,@Name,@Layer,@State,@Style,@OrderCode)");
            strSql.Append(" ; select @@IDENTITY; ");
            strSql.Append(" end ELSE begin SELECT -1 END");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ParentID",  SqlDbType.Int,       4),
                new SqlParameter("@Name",      SqlDbType.NVarChar, 50),
                new SqlParameter("@Layer",     SqlDbType.Int,       4),
                new SqlParameter("@State",     SqlDbType.Bit,       1),
                new SqlParameter("@Style",     SqlDbType.NVarChar, 50),
                new SqlParameter("@OrderCode", SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = Model.ParentID;
            parameters[1].Value = Model.Name;
            parameters[2].Value = Model.Layer;
            parameters[3].Value = Model.State;
            parameters[4].Value = Model.Style;
            parameters[5].Value = Model.OrderCode;
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Beispiel #5
0
 /// <summary>
 /// 新增模块
 /// </summary>
 /// <returns>返回新增模块ID</returns>
 /// <param name="Model">品类实体</param>
 public int Insert(Model.SysCategory Model)
 {
     return(dal.Insert(Model));
 }
Beispiel #6
0
 /// <summary>
 /// 修改模块
 /// </summary>
 /// <returns>返回影响行数</returns>
 /// <param name="Model">模块实体</param>
 public int ModifyModel(Model.SysCategory Model)
 {
     return(dal.ModifyModel(Model));
 }
Beispiel #7
0
 public ActionResult New(Model.SysCategory model)
 {
     Helper.ResultInfo <int> rs = new Helper.ResultInfo <int>();
     if (ModelState.IsValid)
     {
         if (model.CategoryID > 0)
         {
             rs.Data = Opr.ModifyModel(model);
             if (rs.Data > 0)
             {
                 rs.Msg    = "修改成功.";
                 rs.Result = true;
             }
             else
             {
                 rs.Msg    = "修改失败.";
                 rs.Result = false;
             }
             JsonResult jr = new JsonResult();
             jr.Data = rs;
             return(jr);
         }
         else
         {
             model.OrderCode = Opr.GetNewOrderCode(model.ParentID, model.Layer);
             rs.Data         = Opr.Insert(model);
             if (rs.Data > 0)
             {
                 rs.Msg    = "新增成功.";
                 rs.Result = true;
             }
             else
             {
                 rs.Msg    = "新增失败.";
                 rs.Result = false;
             }
             JsonResult jr = new JsonResult();
             jr.Data = rs;
             return(jr);
         }
     }
     else
     {
         System.Text.StringBuilder sbErrors = new System.Text.StringBuilder();
         foreach (var item in ModelState.Values)
         {
             if (item.Errors.Count > 0)
             {
                 for (int i = item.Errors.Count - 1; i >= 0; i--)
                 {
                     sbErrors.Append(item.Errors[i].ErrorMessage);
                     sbErrors.Append("<br/>");
                 }
             }
         }
         rs.Data   = 0;
         rs.Msg    = sbErrors.ToString();
         rs.Result = false;
         rs.Url    = "";
         JsonResult jr = new JsonResult();
         jr.Data = rs;
         return(jr);
     }
 }