Feb 10, 2010, 3:08 PM
Treepanel Node
I am working on a org chart like tool for a piece of an application.
I am using a treepanel with drag and drop enabled. Ideally everything is working well, however potentially anyone could be responsible for someone.
I can not figure out how to allow a Is there a way to enable a node to allow a drop onto it even though initially its set that the leaf is true.
Page
Code behind
I am using a treepanel with drag and drop enabled. Ideally everything is working well, however potentially anyone could be responsible for someone.
I can not figure out how to allow a Is there a way to enable a node to allow a drop onto it even though initially its set that the leaf is true.
Page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="POC_Administration.aspx.cs" Inherits="EMR_Clean.POC_Administration" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" 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 id="Head2" runat="server">
<title></title>
<script type="text/javascript">
function beforeDrop(dropEvent) {
//if with ctrl key then copy else move
if (dropEvent.rawEvent.ctrlKey) {
dropEvent.dropNode = new Ext.tree.TreeNode(dropEvent.dropNode.attributes);
}
return true;
}
function dragOver(dragOverEvent) {
// we don't want 'above' or 'below' operations which mean insert
//also you can perform additional checks with dragOverEvent.target and dragOverEvent.dropNode
return dragOverEvent.point == 'append';
}
</script>
</head>
<body>
<form id="form1" runat="server">
<ext:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Debug" />
<ext:TextField ID="TextField1" runat="server" Text="Node" />
<ext:TreePanel ID="TreePanel1" runat="server" RootVisible="true" EnableDD="true">
<TopBar>
<ext:Toolbar ID="ToolBar1" runat="server">
<Items>
<ext:Button ID="Button1" runat="server" Text="Expand All">
<Listeners>
<Click Handler="#{TreePanel1}.expandAll();" />
</Listeners>
</ext:Button>
<ext:Button ID="Button2" runat="server" Text="Collapse All">
<Listeners>
<Click Handler="#{TreePanel1}.collapseAll();" />
</Listeners>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Loader>
<ext:PageTreeLoader OnNodeLoad="NodeLoad">
<BaseParams>
<ext:Parameter Name="prefix" Value="117" Mode="Raw" />
</BaseParams>
</ext:PageTreeLoader>
</Loader>
<Root>
<ext:AsyncTreeNode NodeID="117" Text="Bill Ramey" />
</Root>
<Listeners>
<BeforeNodeDrop Fn="beforeDrop" />
<NodeDragOver Fn="dragOver" />
</Listeners>
<AjaxEvents>
<NodeDrop OnEvent="NodeDrop">
<ExtraParams>
<ext:Parameter Name="TargetID" Value="dropEvent.target.id" Mode="Raw" />
<ext:Parameter Name="DropedID" Value="dropEvent.dropNode.id" Mode="Raw" />
<ext:Parameter Name="isCopy" Value="dropEvent.rawEvent.ctrlKey" Mode="Raw" />
</ExtraParams>
</NodeDrop>
</AjaxEvents>
</ext:TreePanel>
</form>
</body>
</html>
Code behind
public partial class POC_Administration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void NodeDrop(object sender, AjaxEventArgs e)
{
string targetID = e.ExtraParams["TargetID"];
string dropedID = e.ExtraParams["DropedID"];
bool isCopy = Convert.ToBoolean(e.ExtraParams["isCopy"]);
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["EMRConnectionString"].ConnectionString))
{
using (SqlCommand cm = new SqlCommand("Update_POC", cn))
{
cm.CommandType = CommandType.StoredProcedure;
cm.Parameters.Add(new SqlParameter("@intUserID", SqlDbType.Int));
cm.Parameters["@intUserID"].Value = targetID;
cm.Parameters.Add(new SqlParameter("@intUserID_POC", SqlDbType.Int));
cm.Parameters["@intUserID_POC"].Value = dropedID;
cn.Open();
cm.ExecuteNonQuery();
}
}
}
protected void NodeLoad(object sender, NodeLoadEventArgs e)
{
int _n = int.Parse(e.NodeID);
if (_n == 0)
{
_n = 117;
}
else
{
_n = int.Parse(e.NodeID);
}
{
String Query =
"SELECT emp.intUserID AS EmployeeID, emp.txtFirstName + ' ' + emp.txtLastName AS EmployeeName, " +
" CAST(CASE WHEN a.Subordinates > 0 THEN 0 ELSE 1 END AS BIT) AS IsSupervisor " +
"FROM tblUsers AS emp WITH (NOLOCK) LEFT OUTER JOIN " +
" (SELECT intUserID_POC, COUNT(*) AS Subordinates " +
" FROM tblUsers AS sup WITH (NOLOCK) " +
" GROUP BY intUserID_POC) AS a ON a.intUserID_POC = emp.intUserID " +
"WHERE (emp.intUserID_POC IS NOT NULL) AND IsNull(emp.intUserID_POC, 0) =" + _n;
DataSet myDataSet = new DataSet();
string connectionString = ConfigurationManager.ConnectionStrings["EMRConnectionString"].ConnectionString;
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter(Query, connection);
mySqlDataAdapter.Fill(myDataSet);
}
DataTable employees = myDataSet.Tables[0];
string isLeaf = string.Empty;
bool isSupervisor = false;
for (int i = 0; i < employees.Rows.Count; i++)
{
DataRow dr = employees.Rows[i];
isSupervisor = Convert.ToBoolean(dr["IsSupervisor"].ToString());
AsyncTreeNode asyncNode = new AsyncTreeNode();
asyncNode.Text = dr["EmployeeName"].ToString();
asyncNode.NodeID = dr["EmployeeID"].ToString();
asyncNode.Leaf = isSupervisor;
e.Nodes.Add(asyncNode);
}
}
}
}