HTML:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Source.aspx.cs" Inherits="DzPlatForm.CRM.Property.Source" %> <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %> 来源配置CS:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Ext.Net; using DzPlatForm.Control; using System.Data; using DzPlatForm.DBUtility; namespace DzPlatForm.CRM.Property { public partial class Source : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!X.IsAjaxRequest) { Session["utype"] = 1; this.BuildTree(TreeGrid1.Root); } } ////// 初始化树形列表 /////////private Ext.Net.TreeNodeCollection BuildTree(Ext.Net.TreeNodeCollection nodes) { if (Session["utype"] == null) { Response.Redirect("Login.aspx"); return null; } else { string sql = "SELECT [Id],[ParentId],[Name] FROM [OA].[dbo].[CustomerSource] "; TreeTableControl treeTable = new TreeTableControl(); DataTable dt = DbHelperSQL.ExecuteDT(sql, null); Ext.Net.TreeNode tvn = treeTable.BindTableTree(dt); nodes.Add(tvn); return nodes; } } ////// 刷新树形列表 //////[DirectMethod] public string RefreshMenu() { TreeGrid1.Root.Clear(); Ext.Net.TreeNodeCollection nodes = this.BuildTree(TreeGrid1.Root); return nodes.ToJson(); } ////// 操作集合 /////////protected void Menu_Click(object sender, DirectEventArgs e) { string item = e.ExtraParams.GetParameter("Item").Value; string[] strValue = txtValue.Text.Split('|'); switch (item) { case "menuAddSubitem": if (strValue.Length <= 1) Notification.Show(new NotificationConfig { Title = "客户来源管理", Icon = Icon.Information, Html = "未选择记录" }); else { txt_Menu_Name_varchar2.Text = ""; this.txt_Menu_ParentID_number.Text = strValue[0]; txtType.Text = "add"; this.winMenuAdd.Title = "新建子客户来源"; this.winMenuAdd.Show(); } break; case "menuAdd": txt_Menu_Name_varchar2.Text = ""; this.txt_Menu_ParentID_number.Text = "-1"; this.winMenuAdd.Title = "新建客户来源"; txtType.Text = "add"; this.winMenuAdd.Show(); break; case "menuEdit": if (strValue.Length <= 1) Notification.Show(new NotificationConfig { Title = "客户来源管理", Icon = Icon.Information, Html = "未选择记录" }); else { txt_Menu_Name_varchar2.Text = strValue[1]; this.txt_Menu_ParentID_number.Text = strValue[2]; txtType.Text = "edit"; this.winMenuAdd.Title = "菜单修改"; this.winMenuAdd.Show(); } break; case "menuDelete": if (strValue.Length <= 1) { Notification.Show(new NotificationConfig { Title = "客户来源管理", Icon = Icon.Information, Html = "未选择记录" }); } else { this.Delete(); } break; } } [DirectMethod] public void ClickCurrentNode(string name) { txtValue.Text = name; } ////// 保存 //////[DirectMethod] public string Save() { string name = this.txt_Menu_Name_varchar2.Text; string pid = this.txt_Menu_ParentID_number.Text; MenuInfo menu = new MenuInfo(); menu.Name = name; menu.Pid = pid; bool bl = false; string sql = ""; if (txtType.Text == "add") { sql = "insert into [CustomerSource] (Name,ParentId) values ('" + menu.Name + "'," + menu.Pid + ")"; int res = DbHelperSQL.ExecuteSql(sql, null); if (res > 0) bl = true; } else { string[] strValue = txtValue.Text.Split('|'); menu.Id = strValue[0]; sql = "update CustomerSource set Name='" + menu.Name + "' " + " where Id=" + menu.Id + " "; int res = DbHelperSQL.ExecuteSql(sql, null); if (res > 0) bl = true; } if (bl) { txt_Menu_Name_varchar2.Text = ""; Notification.Show(new NotificationConfig { Title = "客户来源管理", Icon = Icon.Information, Html = "保存成功" }); winMenuAdd.Hide(); string rtn = RefreshMenu(); return rtn; } else { Notification.Show(new NotificationConfig { Title = "客户来源管理", Icon = Icon.Information, Html = "保存失败" }); return this.TreeGrid1.Root.ToJson(); } this.txtValue.Text = ""; } ////// 删除 //////[DirectMethod] public string Delete() { string[] strValue = txtValue.Text.Split('|'); string id = strValue[0]; string ssql = "select Id from [CustomerSource] where ParentId=" + id + ""; DataTable dt = DbHelperSQL.ExecuteDT(ssql, null); if (dt.Rows.Count > 0) { Notification.Show(new NotificationConfig { Title = "客户来源管理", Icon = Icon.Information, Html = "存在根节点,请先删除下级!" }); } else { string sql = "delete from CustomerSource where Id=" + id + ""; int res = DbHelperSQL.ExecuteSql(sql, null); bool success = false; if (res > 0) success = true; if (success) { Notification.Show(new NotificationConfig { Title = "客户来源管理", Icon = Icon.Information, Html = "删除成功" }); } else { Notification.Show(new NotificationConfig { Title = "客户来源管理", Icon = Icon.Information, Html = "删除失败" }); } this.txtValue.Text = ""; } return RefreshMenu(); } } }
效果:
感谢心是走动的词语的鼎力帮助和指导。