コード例 #1
0
ファイル: admin_ajax.ashx.cs プロジェクト: eryueren/OScms
        private void edit_category(HttpContext context)
        {
            //取得管理员登录信息
            Model.managers.manager adminInfo = new Web.UI.ManagePage().GetAdminInfo();
            if (adminInfo == null)
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"未登录或已超时,请重新登录!\"}");
                return;
            }

            int category1 = OSRequest.GetFormInt("Category1");
            int category2 = OSRequest.GetFormInt("Category2");

            if (category1 == category2)
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"移动目录跟目的目录不能相同!\"}");
                return;
            }

            BLL.contents.article_category   bll   = new BLL.contents.article_category();
            Model.contents.article_category model = bll.GetModel(category2);

            if (model.class_list.IndexOf("," + category1 + ",") > 0)
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"父级本不能向其子级转移!\"}");
                return;
            }

            if (bll.GetModel(category1).parent_id == category2)
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"移动目录已经在目的目录里!\"}");
                return;
            }

            DataTable dt = bll.GetList(0, "class_list like '%," + category1 + ",%'", "class_layer asc").Tables[0];

            if (dt.Rows != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    int    id              = Convert.ToInt32(dt.Rows[i]["id"]);
                    string class_list      = dt.Rows[i]["class_list"].ToString();
                    int    new_channel_id  = model.channel_id;
                    string new_class_list  = model.class_list + class_list.Substring(class_list.IndexOf("," + category1 + ",")).TrimStart(',');
                    string new_class_layer = new_class_list.Trim(',').Split(',').Length.ToString();
                    if (i == 0)
                    {
                        bll.UpdateField(id, "channel_id=" + new_channel_id + ", parent_id=" + category2 + ", class_list='" + new_class_list + "',class_layer=" + new_class_layer);
                    }
                    else
                    {
                        bll.UpdateField(id, "channel_id=" + new_channel_id + ", class_list='" + new_class_list + "',class_layer=" + new_class_layer);
                    }
                }
            }

            new BLL.managers.manager_log().Add(adminInfo.id, adminInfo.user_name, OSEnums.ActionEnum.Edit.ToString(), "移动栏目:" + bll.GetModel(category1).title); //记录日志
            context.Response.Write("{\"status\": 1, \"msg\": \"栏目转移成功!\"}");
        }