您的位置:首页 > 其它

Ext.Net 1.x_Ext.Net.TreeGrid-无限制树形GUCD

2013-05-29 10:03 399 查看
HTML:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Source.aspx.cs" Inherits="DzPlatForm.CRM.Property.Source" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>来源配置</title>
<link rel="stylesheet" type="text/css" href="resources/css/main.css" />
<ext:ResourcePlaceHolder ID="ResourcePlaceHolder1" runat="server" Mode="Script" />
<ext:ResourcePlaceHolder ID="ResourcePlaceHolder2" Mode="Style" runat="server">
<script src="../../Scripts/am.js" type="text/javascript"></script>
</ext:ResourcePlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:TreeGrid ID="TreeGrid1" runat="server" UseArrows="true" Animate="true" AutoHeight="true"
AutoScroll="true" ForceLayout="true" Collapsed="false">
<Columns>
<ext:TreeGridColumn Header="来源名称" Width="300" DataIndex="Name">
</ext:TreeGridColumn>
<ext:TreeGridColumn Header="父节点" DataIndex="ParentId" Hidden="true" >
</ext:TreeGridColumn>
</Columns>
<TopBar>
<ext:Toolbar ID="Toolbar1" runat="server">
<Items>
<ext:SplitButton ID="SplitButton1" runat="server" Text="新建来源" Icon="Add">
<Menu>
<ext:Menu ID="Menu1" runat="server">
<Items>
<ext:MenuItem ID="menuAdd" runat="server" Text="新建顶层来源" Icon="Add">
<DirectEvents>
<Click OnEvent="Menu_Click">
<EventMask ShowMask="true" />
<ExtraParams>
<ext:Parameter Name="Item" Value="menuAdd" Mode="Value" />
</ExtraParams>
</Click>
</DirectEvents>
</ext:MenuItem>
<ext:MenuItem ID="menuAddSubitem" runat="server" Text="新建当前选中子来源" Icon="DatabaseAdd">
<DirectEvents>
<Click OnEvent="Menu_Click">
<EventMask ShowMask="true" />
<ExtraParams>
<ext:Parameter Name="Item" Value="menuAddSubitem" Mode="Value" />
</ExtraParams>
</Click>
</DirectEvents>
</ext:MenuItem>
</Items>
</ext:Menu>
</Menu>
</ext:SplitButton>
<ext:Button ID="Button1" runat="server" Text="修改" Icon="DatabaseEdit">
<DirectEvents>
<Click OnEvent="Menu_Click">
<EventMask ShowMask="true" Msg="修改..." MinDelay="500" />
<ExtraParams>
<ext:Parameter Name="Item" Value="menuEdit" Mode="Value" />
</ExtraParams>
</Click>
</DirectEvents>
</ext:Button>
<ext:Button ID="Button3" runat="server" Text="删除" Icon="DatabaseDelete">
<Listeners>
<Click Handler="DeleteNodeForTree2(#{TreeGrid1},#{txtValue});" />
</Listeners>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Listeners>
<Click Handler="Ext.net.DirectMethods.ClickCurrentNode(node.attributes.Id+'|'+node.attributes.Name+'|'+node.attributes.ParentId)" />
</Listeners>
</ext:TreeGrid>
<ext:Window ID="winMenuAdd" runat="server" Icon="Table" Closable="true" Title=""
AutoHeight="true" Width="450" Resizable="false" BodyStyle="background-color:#fff;"
Padding="15" Layout="FormLayout" ForceLayout="true" Hidden="true" Modal="true">
<Items>
<ext:TextField ID="txt_Menu_Name_varchar2" runat="server" Width="220" FieldLabel="来源名称"
LabelStyle="margin:5px 0 5 0;" StyleSpec="margin:5px 0 5 0;" />
<ext:TextField ID="txt_Menu_ParentID_number" runat="server" Enabled="false" Width="220"
FieldLabel="父节点编号" LabelStyle="margin:5px 0 5 0;" StyleSpec="margin:5px 0 5 0;"
Text="-1" Hidden="true" />
<ext:Hidden ID="txtValue" runat="server" Text="" />
<ext:Hidden ID="txtType" runat="server" Text="add" />
</Items>
<Buttons>
<ext:Button ID="btn_save" runat="server" Text="保存" Icon="Disk">
<Listeners>
<Click Handler="AddNodeForTree(#{TreeGrid1});" />
</Listeners>
</ext:Button>
</Buttons>
</ext:Window>
</form>
</body>
</html>
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);

}
}
/// <summary>
/// 初始化树形列表
/// </summary>
/// <param name="nodes"></param>
/// <returns></returns>
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;
}

}
/// <summary>
/// 刷新树形列表
/// </summary>
/// <returns></returns>
[DirectMethod]
public string RefreshMenu()
{
TreeGrid1.Root.Clear();
Ext.Net.TreeNodeCollection nodes = this.BuildTree(TreeGrid1.Root);
return nodes.ToJson();
}
/// <summary>
/// 操作集合
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
}
/// <summary>
/// 保存
/// </summary>
/// <returns></returns>
[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 = "";
}
/// <summary>
/// 删除
/// </summary>
/// <returns></returns>
[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();
}
}
}


效果:



感谢心是走动的词语的鼎力帮助和指导。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: