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;
            }
        }
    }
}
posted @ 2013-11-08 00:09  TOGGLE  阅读(1004)  评论(3)    收藏  举报