//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_dbAdd_jurisdictionCoud
//修改节点视图
@{ Layout = null;}@model jurisdiction_Yzw.module_dbUPD_jurisdictionCoud