private bool checkHasLeaf(int id)
 {
     List<Model.products.productsClassify> lists = new List<Model.products.productsClassify>();
     Model.products.productsClassify model = new Model.products.productsClassify();
     skywolfORM.ORM.ORM orm = new skywolfORM.ORM.ORM();
     lists = orm.List(model, "pcParentID=" + id).OfType<Model.products.productsClassify>().ToList();
     if (lists.Count > 0)
         return false;
     else
         return true;
 }
Beispiel #2
0
 public void ProcessRequest(HttpContext context)
 {
     context.Response.ContentType = "text/plain";
     int pcID = Commons.WebPage.PageRequest.GetQueryInt("pcID");
     skywolfORM.ORM.ORM orm = new skywolfORM.ORM.ORM();
     List<Model.products.productsClassify> lists = new List<Model.products.productsClassify>();
     Model.products.productsClassify model = new Model.products.productsClassify();
     lists = orm.List(model, "pcParentID=" + pcID).OfType<Model.products.productsClassify>().ToList();
     string str = "[]";
     str = Newtonsoft.Json.JsonConvert.SerializeObject(lists);
     context.Response.Write(str);
 }
 private bool checkLevel(int parentID)
 {
     if (parentID < 1)
         return true;
     skywolfORM.ORM.ORM orm=new skywolfORM.ORM.ORM();
     Model.products.productsClassify model = new Model.products.productsClassify();
     model =(Model.products.productsClassify) orm.Load(model, parentID);
     if (model.pcParentID == 0)
         return true;
     else
         return false;
 }
 public void ProcessRequest(HttpContext context)
 {
     context.Response.ContentType = "text/plain";
     List<Model.products.productsClassify> lists = new List<Model.products.productsClassify>();
     List<Model.products.productsClassify> listChild = loadData(0);
     Model.products.productsClassify model = new Model.products.productsClassify();
     model.pcID = 0;
     model.pcName = "分类树";
     model.children = listChild;
     lists.Add(model);
     string str = Newtonsoft.Json.JsonConvert.SerializeObject(lists);
     context.Response.Write(str);
 }
 public void ProcessRequest(HttpContext context)
 {
     context.Response.ContentType = "text/plain";
     int id = 0;
     string strID = context.Request.Params["pcID"];
     if (strID.Trim() != "")
     {
         id = int.Parse(strID);
     }
     Model.products.productsClassify model = new Model.products.productsClassify();
     if (model != null)
     {
         skywolfORM.ORM.ORM orm = new skywolfORM.ORM.ORM();
         model = (Model.products.productsClassify)orm.Load(model, id);
     }
     string str = Newtonsoft.Json.JsonConvert.SerializeObject(model);
     context.Response.Write(str);
 }
 private string delType(int id)
 {
     skywolfORM.ORM.ORM orm = new skywolfORM.ORM.ORM();
     Model.products.productsClassify model = new Model.products.productsClassify();
     model = (Model.products.productsClassify)orm.Load(model, id);
     if (model == null)
     {
         return "{\"success\":false,\"msg\":\"该分类不存在或已被删除!\"}";
     }
     int parentID = model.pcParentID;
     if (!checkHasLeaf(parentID))
     {
         return "{\"success\":false,\"msg\":\"该分类存在子分类请先删除子分类!\"}";
     }
     if (orm.Delete(model))
     {
         return "{\"success\":true,\"msg\":\"删除分类成功!\"}";
     }
     return "{\"success\":false,\"msg\":\"删除分类失败!\"}";
 }
        private List<Model.products.productsClassify> loadData(int parentID)
        {
            Model.products.productsClassify pt = new Model.products.productsClassify();
            skywolfORM.ORM.ORM orm = new skywolfORM.ORM.ORM();
            List<Model.products.productsClassify> lists = orm.List(pt, "pcParentID=" + parentID).OfType<Model.products.productsClassify>().ToList();
            if (lists.Count > 0)
            {
                List<Model.products.productsClassify> ptChild = null;
                foreach (Model.products.productsClassify model in lists)
                {
                    ptChild = loadData(model.pcID);
                    if (ptChild.Count > 0)
                    {
                        model.children = ptChild;
                    }

                }
            }

            return lists;
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.ContentType = "text/plain";
            string strReq = Commons.WebPage.PageRequest.getJsonString();

            JavaScriptSerializer serializer = new JavaScriptSerializer();
            Model.products.productsClassify model = new Model.products.productsClassify();
            model = serializer.Deserialize<Model.products.productsClassify>(strReq);
            string str = "{\"success\":false,\"msg\":\"保存失败!\"}";
            if (model != null)
            {
                if (model.pcID > 0)
                {
                    if (updateClassify(model))
                    {
                        str = "{\"success\":true,\"msg\":\"修改分类成功!\"}";
                    }
                }
                else
                {
                    if (!checkLevel(model.pcParentID))
                    {
                        str = "{\"success\":false,\"msg\":\"对不起!分类只能到第二级!\"}";
                    }
                    else
                    {
                        if (addClassify(model))
                        {
                            str = "{\"success\":true,\"msg\":\"新增分类成功!\"}";
                        }
                    }
                }
            }

            context.Response.Write(str);
        }
 private bool updateClassify(Model.products.productsClassify model)
 {
     bool isSave = false;
     skywolfORM.ORM.ORM orm = new skywolfORM.ORM.ORM();
     if (model != null)
     {
         Model.products.productsClassify pt = new Model.products.productsClassify();
         pt = (Model.products.productsClassify)orm.Load(pt, model.pcID);
         if (pt != null)
         {
             pt.pcName = model.pcName;
             isSave = orm.Update(model);
         }
     }
     return isSave;
 }