zoukankan      html  css  js  c++  java
  • JQuery仿淘宝商家后台管理 之 管理添加分类

    先看一下效果图:

    JQuery 仿淘宝后台管理分类

    实现功能:

    1、打开时加载分类信息,折叠所有分类

    2、动态添加子类和父类

    3、顺序的调整

    4、无刷新删除,添加

    5、保存到数据库

    下面是HTML代码 :


    后台数据一般处理程序代码:

    添加

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace FM.Web.AdminView.ashx
    {
        /// <summary>
        /// UpdateClasses 的摘要说明
        /// </summary>
        public class UpdateClasses : IHttpHandler
        {
            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "text/plain";
                string strClass = context.Request["strClass"].TrimEnd(',');
                string strChilds = context.Request["strChilds"].TrimEnd(',');
    
                BLL.ClassInfo bll = new BLL.ClassInfo();
                BLL.ClassChild bllChild = new BLL.ClassChild();
    
                if (strClass.Length > 0 || strChilds.Length > 0)
                {
                    try
                    {
                        string[] classes = strClass.Split(',');
                        string[] childs = strChilds.Split(',');
                        //读取父类数据 保存到数据库中
                        foreach (string item in classes)
                        {
                            string[] classInfo = item.Split('&');
                            string classID = classInfo[0];
                            string className = classInfo[1];
                            bll.CheckAndAddClass(classID, className);
                        }
    
                        //读取子类数据 保存到数据库中
                        foreach (string item in childs)
                        {
                            string[] childrenInfo = item.Split('&');
                            string classID = childrenInfo[0];
                            string childClassName = childrenInfo[1];
    
                            bllChild.CheckAndAddClassChild(classID, childClassName);
                        }
                        context.Response.Write("OK");
                    }
                    catch
                    {
                        context.Response.Write("error");
                    }
                }
                else
                {
                    context.Response.Write("error");
                }
            }
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }

    删除

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace FM.Web.AdminView.ashx
    {
        /// <summary>
        /// DeletClass 的摘要说明
        /// </summary>
        public class DeletClass : IHttpHandler
        {
            BLL.ClassInfo bllClass = new BLL.ClassInfo();
            BLL.ClassChild bllChild = new BLL.ClassChild();
    
            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "text/plain";
                if (!string.IsNullOrEmpty(context.Request["Action"]))
                {
                    if (context.Request["Action"] == "Delete")
                    {
                        string ID = context.Request["ClassID"] == null ? "-1" : context.Request["ClassID"];
                        string DelObj = context.Request["DelObj"];
                        int delID = int.Parse(ID);
                        if (DelObj == "F")//父类
                        {
                            //根据ID查询父类的排序ID,再删除子类和父类
                            Model.ClassInfo modelClass = bllClass.GetModel(delID);
                            string classID = modelClass.ClassID;
                            if (bllChild.DeleteList("ClassID like '" + classID + "-%" + "'"))
                            {
                                if (bllClass.Delete(delID))
                                { 
                                    context.Response.Write("OK");
                                    return;
                                }
                            }
                            context.Response.Write("error");
                        }
                        else if (DelObj == "C")//子类
                        {
                            if (bllChild.Delete(delID))
                            {
                                context.Response.Write("OK");
                                return;
                            }
                            context.Response.Write("error");
                        }
                        else
                        {
                            context.Response.Write("error");
                        }
                    }
                    else
                    {
                        context.Response.Write("error");
                    }
                }
                else
                {
                    context.Response.Write("error");
                }
            }
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }
  • 相关阅读:
    谈一谈循环的性能提升
    Web前端性能优化的9大问题
    随机获取一种颜色值的三种方法
    ES6还是ES2015?
    history.back(-1)和history.go(-1)的区别
    关于overflow-y:scroll ios设备不流畅的问题
    前端如何压缩图片
    【转】理解JavaScript之闭包
    关于如何给数字排序
    本地缓存localstorage使用
  • 原文地址:https://www.cnblogs.com/lt-style/p/3413501.html
Copyright © 2011-2022 走看看