博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Ztree简单实现
阅读量:5824 次
发布时间:2019-06-18

本文共 14653 字,大约阅读时间需要 48 分钟。

//ztree的前台视图

@{    Layout = null;   }     
Index @*//jquery文件*@ @*//ztree的js文件*@
@*//ztree的风格样式文件*@ @*//遮罩层layer的js文件*@

//后台控制器

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using System.Data;using System.Data.SqlClient;using Newtonsoft.Json;namespace jurisdiction_Yzw.Controllers{    public class jurisdiction_Magaer_Controller : Controller    {        // GET: jurisdiction_Magaer_        public ActionResult Index()        {            return View();        }        [HttpGet]        public ActionResult Add_jurisdictionCoud(string id)        {            ViewBag.id = id.Remove(id.LastIndexOf("_"));            Session["Codeid"]= id.Remove(id.LastIndexOf("_"));            Session["PrnCodeid"]= id.Remove(0, id.LastIndexOf("_") + 1);            string name = id.Remove(0,id.LastIndexOf("_")+1);            ViewBag.name = name;            return View();        }        [HttpPost]        public ActionResult Add_jurisdictionCoud(module_db model)        {            if (model.creator_name == "")            {                model.creator_name = "YZW";            }            if (model.creator_full_name == "")            {                model.creator_full_name = "YZW";            }            model.creator_time =Convert.ToDateTime(DateTime.Now.ToString());                        using (SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=system_center_db;Integrated Security=True"))            {                string Codeid = Session["Codeid"].ToString();                              string sqls = "select  *  from  module_db  where module_code = '"+ Codeid + "'";                SqlDataAdapter cmds = new SqlDataAdapter(sqls, conn);                DataTable tb = new DataTable();                cmds.Fill(tb);                module_db pmodel = new module_db();                foreach (DataRow item in tb.Rows)                {                       pmodel.module_code       = item["module_code"].ToString();                       pmodel.module_name       =item["module_name"].ToString();                       pmodel.parent_code = Codeid;                       pmodel.module_level      =Convert.ToInt32(item["module_level"]);                       pmodel.is_menu           = Convert.ToInt32(item["is_menu"]);                       pmodel.is_action         = Convert.ToInt32(item["is_action"]);                       pmodel.action_url        =item["action_url"].ToString();                                          pmodel.module_status     = Convert.ToInt32(item["module_status"]);                       pmodel.creator_name      =item["creator_name"].ToString();                       pmodel.creator_full_name =item["creator_full_name"].ToString();                       pmodel.creator_time      = Convert.ToDateTime(item["creator_time"]);                       pmodel.modifi_name       =item["modifi_name"].ToString();                       pmodel.modifi_full_name  =item["modifi_full_name"].ToString();                                     }                model.module_level = pmodel.module_level + 1;                model.parent_code = pmodel.parent_code;                string sql =string.Format(                @"insert   module_db(                 module_code,                module_name,                parent_code,                module_level,                is_menu,                is_action,                action_url,                order_by,                module_status,                creator_name,                creator_full_name,                creator_time,                modifi_name,                modifi_full_name,                modifi_time)                    values ('{0}','{1}','{2}',{3},{4},{5},'{6}','{7}',{8},'{9}','{10}','{11}','{12}','{13}',NULL)",                 model.module_code,                model.module_name,                model.parent_code,                model.module_level,                model.is_menu,                model.is_action,                model.action_url,                model.order_by,                model.module_status,                model.creator_name,                model.creator_full_name,                 model.creator_time,                model.modifi_name,                model.modifi_full_name                );                conn.Close();                conn.Open();                //values ('config_manager','配置管理','yixin_public',2,1,0,'','2',1,'lzh','lzh','2017-07-05 15:57:06',NULL,NULL,),");                SqlCommand cmd = new SqlCommand(sql,conn);                cmd.ExecuteNonQuery();                conn.Close();            }            return View();        }        public string Get_jurisdiction()        {            using (SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=system_center_db;Integrated Security=True"))            {                SqlDataAdapter adp = new SqlDataAdapter("select * FROM module_db", conn);                DataTable tb = new DataTable();                adp.Fill(tb);                string result = "[";                foreach (DataRow item in tb.Rows)                {                    bool open = Convert.ToInt32(item["module_status"]) == 1 ? true : false;                    bool checkeds = Convert.ToInt32(item["is_menu"]) == 1 ? true : false;                    //  bool isParent = Convert.ToInt32(item["module_status"]) == 1 ? true : false;                                                                                                  //"+item["action_url"] + "                                               result += "{\"id\":\"" + item["module_code"] + "\",\"pId\":\"" + item["parent_code"] + "\",\"name\":\"" + item["module_name"] + "\",\"open\":\"" + open + "\",\"checked\":\"" + checkeds + "\",\"url\":\"\",\"isParent\":\"true\"},";                }                result = result.Substring(0, result.LastIndexOf(","));                result += "]";                return result;            }        }        [HttpGet]        public ActionResult UPD_jurisdictionCoud(string id)        {            ViewBag.id = id.Remove(id.LastIndexOf("_"));            Session["edaCodeid"] = id.Remove(id.LastIndexOf("_"));            string name = id.Remove(0, id.LastIndexOf("_") + 1);            module_db pmodel = new module_db();            #region            using (SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=system_center_db;Integrated Security=True"))            {                string sqls = "select  *  from  module_db  where module_code = '" + id.Remove(id.LastIndexOf("_")) + "'";                SqlDataAdapter cmds = new SqlDataAdapter(sqls, conn);                DataTable tb = new DataTable();                cmds.Fill(tb);                foreach (DataRow item in tb.Rows)                {                    pmodel.module_code = item["module_code"].ToString();                    pmodel.module_name = item["module_name"].ToString();                    Session["pedaCodeid"]= item["parent_code"].ToString();                    pmodel.module_level = Convert.ToInt32(item["module_level"]);                    pmodel.modifi_name = item["modifi_name"].ToString();                    pmodel.modifi_full_name = item["modifi_full_name"].ToString();                    pmodel.is_menu = Convert.ToInt32(item["is_menu"]);                    pmodel.is_action = Convert.ToInt32(item["is_action"]);                    pmodel.action_url = item["action_url"].ToString();                    pmodel.module_status = Convert.ToInt32(item["module_status"]);                    pmodel.creator_name = item["creator_name"].ToString();                    pmodel.creator_full_name = item["creator_full_name"].ToString();                    pmodel.creator_time = Convert.ToDateTime(item["creator_time"]);                                        Session["creator_time"] = (item["creator_time"]).ToString();                    Session["creator_name"] = (item["creator_name"]).ToString();                    Session["creator_full_name"] = (item["creator_full_name"]).ToString();                }            }            #endregion            ViewBag.name = name;            return View(pmodel);        }        [HttpPost]        public ActionResult UPD_jurisdictionCoud(module_db model)        {            if (model.modifi_name == "")            {                model.modifi_name = "YZW";            }            if (model.modifi_full_name == "")            {                model.modifi_full_name = "YZW";            }            model.modifi_time = Convert.ToDateTime(DateTime.Now.ToString());            using (SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=system_center_db;Integrated Security=True"))            {                string sql = string.Format(@"update   module_db   set modifi_time='{0}', module_name='{1}',  parent_code='{2}',                                                                      module_level={3},   is_menu={4},    is_action={5},                                                                      action_url='{6}',   order_by='{7}', module_status={8},                                                                      creator_name='{9}', creator_full_name='{10}',creator_time='{11}',                                                                      modifi_name='{12}',   modifi_full_name='{13}'    where  module_code='{14}'",                                                                      model.modifi_time,                                                                      model.module_name,                                                                      Session["pedaCodeid"].ToString(),                                                                      model.module_level,                                                                      model.is_menu,                                                                      model.is_action,                                                                      model.action_url,                                                                      model.order_by,                                                                      model.module_status,                                                                      Session["creator_time"],                                                                      Session["creator_full_name"],                                                                      Session["creator_time"],                                                                      model.modifi_name,                                                                      model.modifi_full_name,                                                                      Session["edaCodeid"].ToString());                conn.Close();                conn.Open();                //values ('config_manager','配置管理','yixin_public',2,1,0,'','2',1,'lzh','lzh','2017-07-05 15:57:06',NULL,NULL,),");                SqlCommand cmd = new SqlCommand(sql, conn);                cmd.ExecuteNonQuery();                conn.Close();            }            return View();        }        public string Del_urisdictionCoud(string  id)        {            using (SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=system_center_db;Integrated Security=True"))            {                conn.Open();                SqlCommand cmd = new SqlCommand("DELETE    from  module_db  where module_code='"+ id + "'", conn);                 int  i= cmd.ExecuteNonQuery();                conn.Close();                if (i==1)                {                    return "删除模块成功";                }                else                {                    return "删除模块失败";                }            }        }    }}

//添加节点页面

@{    Layout = null;}@model jurisdiction_Yzw.module_db    
Add_jurisdictionCoud
父模块: @ViewBag.name 父模块Code: @ViewBag.id
模块Code: @Html.TextBoxFor(T => T.module_code) 模块名称 @Html.TextBoxFor(T => T.module_name)
级别: @Html.TextBoxFor(T => T.module_level) 是否菜单:
是否请求: 是否有效:
显示顺序: @Html.TextBoxFor(T =>T.order_by) 请求url: @Html.TextBoxFor(T => T.action_url)

//修改节点视图

@{    Layout = null;}@model jurisdiction_Yzw.module_db    
UPD_jurisdictionCoud
父模块: @ViewBag.name 父模块Code:
模块Code: @Html.TextBoxFor(T=>T.module_code ,new { disabled = "disabled" }) 模块名称 @Html.TextBoxFor(T => T.module_name)
级别: @Html.TextBoxFor(T => T.module_level) 是否菜单:
是否请求: 是否有效:
显示顺序: @Html.TextBoxFor(T => T.order_by) 请求url: @Html.TextBoxFor(T => T.action_url)

 

转载于:https://www.cnblogs.com/-bai/p/8017732.html

你可能感兴趣的文章
环境变量(总结)
查看>>
ios之UILabel
查看>>
Java基础之String,StringBuilder,StringBuffer
查看>>
1月9日学习内容整理:爬虫基本原理
查看>>
安卓中数据库的搭建与使用
查看>>
AT3908 Two Integers
查看>>
渐变色文字
查看>>
C++ 0X 新特性实例(比较常用的) (转)
查看>>
node生成自定义命令(yargs/commander)
查看>>
各种非算法模板
查看>>
node-express项目的搭建并通过mongoose操作MongoDB实现增删改查分页排序(四)
查看>>
如何创建Servlet
查看>>
.NET 设计规范--.NET约定、惯用法与模式-2.框架设计基础
查看>>
win7 64位+Oracle 11g 64位下使用 PL/SQL Developer 的解决办法
查看>>
BZOJ1997:[HNOI2010]PLANAR——题解
查看>>
BZOJ1014:[JSOI2008]火星人prefix——题解
查看>>
使用Unity3D引擎开发赛车游戏
查看>>
HTML5新手入门指南
查看>>
opennebula 开发记录
查看>>
ubuntu 修改hostname
查看>>