⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tree_operate.aspx.cs

📁 4个源代码 比较经典 适合CSharp初学者
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace tree
{
	/// <summary>
	/// tree_Operate 的摘要说明。
	/// </summary>
	public class tree_Operate : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label lbl_Error;
		protected System.Web.UI.WebControls.ImageButton imgbtn_AddChildNode;
		protected System.Web.UI.WebControls.ImageButton imgbtn_AddBrotherNode;
		protected System.Web.UI.WebControls.ImageButton imgbtn_AddRootNode;
		protected System.Web.UI.WebControls.ImageButton imgbtn_DelNode;
		protected System.Web.UI.WebControls.Label lbl_Curnodeid;
		protected System.Web.UI.WebControls.TextBox txt_Mytext;
		protected System.Web.UI.WebControls.Repeater rpt_Graduate;
		protected config conn=new config();
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if (!Page.IsPostBack)
			{
				if (Request["location"]!=null)
				{
					string str_Location=Request["location"].ToString().Substring(0,Request["location"].ToString().Length-1);
					
					lbl_Curnodeid.Text=conn.GetTwoMiddleLastStr(str_Location,"_","_");
				}
				//conn.Logon('B',Session["limit_code"],Page); // 判断是否有权限登陆该页面
				// 下面四行是客户段验证,包括判断是否输入文字等
				imgbtn_AddChildNode.Attributes.Add("onclick","return vdf('txt_Mytext','请输入节点的内容','r');");
				imgbtn_AddBrotherNode.Attributes.Add("onclick","return vdf('txt_Mytext','请输入节点的内容','r');"); 
				imgbtn_AddRootNode.Attributes.Add("onclick","return vdf('txt_Mytext','请输入节点的内容','r');"); 
				imgbtn_DelNode.Attributes.Add("onclick","return confirm('您真的要删除吗?')");
				string str_Sql="select * from t_tree"; 
				if (conn.GetRowCount(str_Sql)>0) // 树表存在记录,做遍历操作
				{
					imgbtn_AddRootNode.Visible=false;
					
				}
				else // 数表不存在记录,不做遍历操作
				{
					imgbtn_DelNode.Visible=false;
					imgbtn_AddBrotherNode.Visible=false;
					imgbtn_AddChildNode.Visible=false;
				}
				if (conn.GetRowCount(str_Sql)==0) // 如果数据库表没有存在记录
				{
					str_Sql="select * from t_tree  order by order_id";
				}
				else
				{
					str_Sql="select * from t_tree where parentid='"+Request["location"].ToString()+"' order by order_id";
				}
				conn.BindRepeater(str_Sql,rpt_Graduate); // 显示选中节子的子节点
				if (Request["nodeid"]!=null) // 做修改时,左边树才作刷新
				{
					Page.RegisterClientScriptBlock("js","<script>parent.frames(\"leftFrame\").document.location.reload();</script>");
				}
				
			}
		
			
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.imgbtn_AddChildNode.Click += new System.Web.UI.ImageClickEventHandler(this.imgbtn_AddChildNode_Click);
			this.imgbtn_AddBrotherNode.Click += new System.Web.UI.ImageClickEventHandler(this.imgbtn_AddBrotherNode_Click);
			this.imgbtn_DelNode.Click += new System.Web.UI.ImageClickEventHandler(this.imgbtn_DelNode_Click);
			this.imgbtn_AddRootNode.Click += new System.Web.UI.ImageClickEventHandler(this.imgbtn_AddRootNode_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion


		private void imgbtn_AddChildNode_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			if (Request["location"]==null) // 判断是否选择右边树导航
			{
				conn.JsIsNull("请选择左边导航树节点,再做添加操作!",lbl_Error);
				return;
			}
			// 下面是增加子节点
			conn.AddChildNode("nodeid","order_id","parentid","location","mytext","t_tree",lbl_Curnodeid,txt_Mytext,lbl_Error);
			string str_Sql="select * from t_tree where parentid='"+Request["location"].ToString()+"' order by order_id";
		    conn.BindRepeater(str_Sql,rpt_Graduate); // 显示选中节子的子节点
			// 刷新左边树导航
			lbl_Error.Text="<script language=\"javascript\">parent.frames(\"leftFrame\").document.location.reload();</"+"script>";
		}

		private void imgbtn_AddBrotherNode_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			if (Request["location"]==null) // 判断是否选择右边树导航
			{
				conn.JsIsNull("请选择左边导航树节点,再做添加操作!",lbl_Error);
				return;
			}
			string str_Sql="select * from t_tree where nodeid="+lbl_Curnodeid.Text;
			conn.GetRowRecord(str_Sql);
			if (conn.dr["parentid"].ToString()=="0_")
			{
				conn.JsIsNull("不能给根节点增加兄弟节点,请增加子节点!",lbl_Error); // 判断不能给跟节点增加兄弟节点
				return;
			}
			// 下面是增加兄弟节点
			conn.AddBrotherNode("nodeid","order_id","parentid","location","mytext","t_tree",lbl_Curnodeid,txt_Mytext,lbl_Error); // 增加兄弟节点
			str_Sql="select * from t_tree where parentid='"+Request["location"].ToString()+"' order by order_id";
			conn.BindRepeater(str_Sql,rpt_Graduate); // 显示选中节子的子节点
			// 刷新左边树导航
			lbl_Error.Text="<script language=\"javascript\">parent.frames(\"leftFrame\").document.location.reload();</"+"script>";
		}

		private void imgbtn_DelNode_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			if (Request["location"]==null) // 判断是否选择右边树导航
			{
				conn.JsIsNull("请选择右边岗位名称!",lbl_Error);
				return;
			}
			conn.DelTreeViewNode("nodeid","parentid","t_tree",lbl_Curnodeid); // 递归删除节点
			string str_Sql="select * from t_tree";
			if (conn.GetRowCount(str_Sql)>0) // 如果树表中存在记录,就做遍历树等操作
			{
				imgbtn_DelNode.Visible=true;
				imgbtn_AddBrotherNode.Visible=true;
				imgbtn_AddChildNode.Visible=true;
				imgbtn_AddRootNode.Visible=false;
			}
			else // 如果数表中不存在记录,就清空数
			{
				imgbtn_DelNode.Visible=false;
				imgbtn_AddBrotherNode.Visible=false;
				imgbtn_AddChildNode.Visible=false;
				imgbtn_AddRootNode.Visible=true;
			}
			str_Sql="select * from t_tree where parentid='"+Request["location"].ToString()+"' order by order_id";
			conn.BindRepeater(str_Sql,rpt_Graduate); // 显示选中节子的子节点
			lbl_Error.Text="<script language=\"javascript\">parent.frames(\"leftFrame\").document.location.reload();</"+"script>";
		}

		private void imgbtn_AddRootNode_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			if (txt_Mytext.Text!="")
			{
				// 下面增加根节点
				string str_Sql="select * from t_tree";
				conn.Builder(str_Sql); // 开始增加
				conn.dr["nodeid"]=1;  // key值
				conn.dr["order_id"]=1; // 排序
				conn.dr["parentid"]="0_"; // 父接点key值
				conn.dr["location"]="0_1_"; // 父接点key值+自己key值
				conn.dr["mytext"]=txt_Mytext.Text; // 接点显示文字
				conn.ds.Tables[0].Rows.Add(conn.dr);
				conn.myAdapter.Update(conn.ds); // 添加成功
				imgbtn_DelNode.Visible=true;
				imgbtn_AddBrotherNode.Visible=true;
				imgbtn_AddChildNode.Visible=true;
				imgbtn_AddRootNode.Visible=false;
			}
			// 刷新左边树导航
			lbl_Error.Text="<script language=\"javascript\">parent.frames(\"leftFrame\").document.location.reload();</"+"script>";
		}
		private void Page_Unload(object sender, System.EventArgs e)
		{
			conn.Close();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -