TreeControl.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;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using System.IO;
using System.Text;
using System.Xml;
using Microsoft.Web.UI.WebControls;
namespace YljWeb.Classes
{
/// <summary>
/// TreeControl 的摘要说明。
/// </summary>
public class TreeControl
{
public DataTable dt;
public TreeControl()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public void BindTreeView1(string f_key,string f_parentkey,string location,string f_text,string str_Sql,string Frame,string Url,Label lbl_Curnodeid,TreeView TreeView1)
{
DataSet ds = YljWeb.Classes.SqlConn.ExecuteSqlForDataSet(str_Sql);
dt = ds.Tables[0];
TreeView1.Nodes.Clear(); // 清空树
TreeNode rootnode=new TreeNode();
rootnode.Text=dt.Rows[0][f_text].ToString(); // 给节点绑定显示值
rootnode.NodeData=dt.Rows[0][f_key].ToString(); // 给节点绑定key值
lbl_Curnodeid.Text=dt.Rows[0][f_key].ToString(); // 保存选中key值
rootnode.Expanded=true; // 默认根结点为展开
rootnode.Target = Frame;
rootnode.NavigateUrl = Url+"?"+location+"=" + dt.Rows[0][location].ToString();
TreeView1.Nodes.Add(rootnode);
string parentid=dt.Rows[0][f_parentkey].ToString()+dt.Rows[0][f_key].ToString()+"_"; // 他子节点的parentid字段值
CreateNode1(f_key,f_parentkey,location,f_text,Frame,Url,parentid,rootnode);// 加入所有根结点以下的结点
}
public void BindTreeView2(string f_key,string f_parentkey,string location,string f_text,string str_Sql,string Frame,string Url,Label lbl_Curnodeid,TreeView TreeView1)
{
DataSet ds = YljWeb.Classes.SqlConn.ExecuteSqlForDataSet(str_Sql);
dt = ds.Tables[0];
TreeView1.Nodes.Clear(); // 清空树
TreeNode rootnode=new TreeNode();
rootnode.Text=dt.Rows[0][f_text].ToString(); // 给节点绑定显示值
rootnode.NodeData=dt.Rows[0][f_key].ToString(); // 给节点绑定key值
lbl_Curnodeid.Text=dt.Rows[0][f_key].ToString(); // 保存选中key值
rootnode.Expanded=true; // 默认根结点为展开
rootnode.Target = Frame;
rootnode.NavigateUrl = Url+"?location2=" + dt.Rows[0][location].ToString();
TreeView1.Nodes.Add(rootnode);
string parentid=dt.Rows[0][f_parentkey].ToString()+dt.Rows[0][f_key].ToString()+"_"; // 他子节点的parentid字段值
CreateNode2(f_key,f_parentkey,location,f_text,Frame,Url,parentid,rootnode);// 加入所有根结点以下的结点
}
public void CreateNode1(string f_key,string f_parentkey,string location,string f_text,string Frame,string Url,string parentid,TreeNode parentnode)
{
DataRow [] drs = dt.Select(f_parentkey +"= '" + parentid + "'");// 选出所有子节点
//遍历所有子节点
foreach( DataRow r in drs )
{
TreeNode tempnode = new TreeNode();
tempnode.Text = r[f_text].ToString();
tempnode.NodeData = r[f_key].ToString();
parentnode.Nodes.Add(tempnode);
tempnode.Expanded=true;
tempnode.Target = Frame;
tempnode.NavigateUrl = Url+"?"+location+"=" + r[location].ToString();
parentid=r[f_parentkey].ToString()+r[f_key].ToString()+"_";
CreateNode1(f_key,f_parentkey,location,f_text,Frame,Url,parentid,tempnode);
}
}
public void CreateNode2(string f_key,string f_parentkey,string location,string f_text,string Frame,string Url,string parentid,TreeNode parentnode)
{
DataRow [] drs = dt.Select(f_parentkey +"= '" + parentid + "'");// 选出所有子节点
//遍历所有子节点
foreach( DataRow r in drs )
{
TreeNode tempnode = new TreeNode();
tempnode.Text = r[f_text].ToString();
tempnode.NodeData = r[f_key].ToString();
parentnode.Nodes.Add(tempnode);
tempnode.Expanded=true;
tempnode.Target = Frame;
tempnode.NavigateUrl = Url+"?location2=" + r[location].ToString();
parentid=r[f_parentkey].ToString()+r[f_key].ToString()+"_";
CreateNode2(f_key,f_parentkey,location,f_text,Frame,Url,parentid,tempnode);
}
}
public void BindTreeViewShow(string f_key,string f_parentkey,string location,string f_text,string str_Sql,Label lbl_Curnodeid,TreeView TreeView1)
{
DataSet ds = YljWeb.Classes.SqlConn.ExecuteSqlForDataSet(str_Sql);
dt = ds.Tables[0];
TreeView1.Nodes.Clear(); // 清空树
TreeNode rootnode = new TreeNode();
rootnode.Text = dt.Rows[0][f_text].ToString(); // 给节点绑定显示值
rootnode.NodeData = dt.Rows[0][f_key].ToString(); // 给节点绑定key值
// lbl_Curnodeid.Text = dt.Rows[0][f_key].ToString(); // 保存选中key值
rootnode.Expanded = true; // 默认根结点为展开
rootnode.NavigateUrl = "?"+location+"=" + dt.Rows[0][f_text].ToString();
TreeView1.Nodes.Add(rootnode);
string parentid=dt.Rows[0][f_parentkey].ToString()+dt.Rows[0][f_key].ToString()+"_"; // 他子节点的parentid字段值
CreateNodeShow(f_key,f_parentkey,location,f_text,parentid,rootnode);// 加入所有根结点以下的结点
}
public void CreateNodeShow(string f_key,string f_parentkey,string location,string f_text,string parentid,TreeNode parentnode)
{
DataRow [] drs = dt.Select(f_parentkey +"= '" + parentid + "'");// 选出所有子节点
//遍历所有子节点
foreach( DataRow r in drs )
{
TreeNode tempnode = new TreeNode();
tempnode.Text = r[f_text].ToString();
tempnode.NodeData = r[f_key].ToString();
parentnode.Nodes.Add(tempnode);
tempnode.Expanded=true;
tempnode.NavigateUrl = "?"+location+"=" + r[f_text].ToString();
parentid=r[f_parentkey].ToString()+r[f_key].ToString()+"_";
CreateNodeShow(f_key,f_parentkey,location,f_text,parentid,tempnode);
}
}
public string GetFirstStr(string strOriginal,string strSymbol)
{
int strPlace=strOriginal.IndexOf(strSymbol);
if (strPlace!=-1)
strOriginal=strOriginal.Substring(0,strPlace);
return strOriginal;
}
/// <summary>
/// 获得某个字符串在另个字符串最后一次出现时后面所有字符
/// </summary>
/// <param name="strOriginal">要处理的字符</param>
/// <param name="strSymbol">符号</param>
/// <returns>返回值</returns>
public string GetLastStr(string strOriginal,string strSymbol)
{
int strPlace=strOriginal.LastIndexOf(strSymbol)+strSymbol.Length;
strOriginal=strOriginal.Substring(strPlace);
return strOriginal;
}
/// <summary>
/// 获得两个字符之间最后一次出现时的所有字符
/// </summary>
/// <param name="strOriginal">要处理的字符</param>
/// <param name="strFirst">最前哪个字符</param>
/// <param name="strLast">最后哪个字符</param>
/// <returns>返回值</returns>
public string GetTwoMiddleLastStr(string strOriginal,string strFirst,string strLast)
{
strOriginal=GetLastStr(strOriginal,strFirst);
strOriginal=GetFirstStr(strOriginal,strLast);
return strOriginal;
}
public void AddRootNode(string nodeid,string order_id,string parentid,string location,string text,string tablename,string MyText)
{
if( MyText !="" )
{
string str_Sql = "INSERT INTO "+ tablename +"("+ nodeid +","+ parentid +","+ location +","+ text +","+ order_id +") VALUES ('1','0_','0_1_','"+ MyText +"','0')";
YljWeb.Classes.SqlConn.ExecuteSql(str_Sql);
}
}
public void AddChildNode(string nodeid,string order_id,string parentid,string location,string text,string tablename,int Curnodeid,string MyText)
{
if( MyText !="" )
{
string str_MaxId =(int.Parse(YljWeb.Classes.SqlConn.GetMaxId("nodeid",tablename).ToString())+1).ToString();
int NewNodeId = int.Parse(str_MaxId);
string str_Sql="select * from "+tablename+" where "+ nodeid +"="+ Curnodeid;
DataSet ds = YljWeb.Classes.SqlConn.ExecuteSqlForDataSet(str_Sql);
DataRow dr = ds.Tables[0].Rows[0];
string str_ = dr[parentid]+ Curnodeid.ToString() +"_";
string str_Location = str_+str_MaxId+"_";
string str_Sql1 = "INSERT INTO "+ tablename +"("+ nodeid +","+ parentid +","+ location +","+ text +","+ order_id +") VALUES ("+ NewNodeId +",'"+ str_ +"','"+ str_Location +"','"+ MyText +"',"+ NewNodeId +")";
YljWeb.Classes.SqlConn.ExecuteSql(str_Sql1);
}
}
public void AddChildNode2(string nodeid,string order_id,string parentid,string location,string text,string text2,string tablename,int Curnodeid,string MyText,string MyText2)
{
if( MyText !="" )
{
string str_MaxId =(int.Parse(YljWeb.Classes.SqlConn.GetMaxId("nodeid",tablename).ToString())+1).ToString();
int NewNodeId = int.Parse(str_MaxId);
string str_Sql="select * from "+tablename+" where "+ nodeid +"="+ Curnodeid;
DataSet ds = YljWeb.Classes.SqlConn.ExecuteSqlForDataSet(str_Sql);
DataRow dr = ds.Tables[0].Rows[0];
string str_ = dr[parentid]+ Curnodeid.ToString() +"_";
string str_Location = str_+str_MaxId+"_";
string str_Sql1 = "INSERT INTO "+ tablename +"("+ nodeid +","+ parentid +","+ location +","+ text +","+ text2 +","+ order_id +") VALUES ("+ NewNodeId +",'"+ str_ +"','"+ str_Location +"','"+ MyText +"','"+ MyText2 +"',"+ NewNodeId +")";
YljWeb.Classes.SqlConn.ExecuteSql(str_Sql1);
}
}
public void AddBrotherNode(string nodeid,string order_id,string parentid,string location,string text,string tablename,int Curnodeid,string MyText)
{
if( MyText !="" )
{
string str_MaxId =(int.Parse(YljWeb.Classes.SqlConn.GetMaxId("nodeid",tablename).ToString())+1).ToString();
int NewNodeId = int.Parse(str_MaxId);
string str_Sql="select * from "+ tablename +" where "+ nodeid +"="+ Curnodeid;
DataSet ds = YljWeb.Classes.SqlConn.ExecuteSqlForDataSet(str_Sql);
DataRow dr = ds.Tables[0].Rows[0];
string str_ = dr[parentid].ToString();
string str_Location = str_+str_MaxId+"_";
str_Sql = "INSERT INTO "+tablename+"("+ nodeid +","+ parentid +","+ location +","+ text +","+ order_id +") VALUES ("+ NewNodeId +",'"+ str_ +"','"+ str_Location +"','"+ MyText +"',"+ NewNodeId +")";
YljWeb.Classes.SqlConn.ExecuteSql(str_Sql);
}
}
public void AddBrotherNode2(string nodeid,string order_id,string parentid,string location,string text,string text2,string tablename,int Curnodeid,string MyText,string MyText2)
{
if( MyText !="" )
{
string str_MaxId =(int.Parse(YljWeb.Classes.SqlConn.GetMaxId("nodeid",tablename).ToString())+1).ToString();
int NewNodeId = int.Parse(str_MaxId);
string str_Sql="select * from "+ tablename +" where "+ nodeid +"="+ Curnodeid;
DataSet ds = YljWeb.Classes.SqlConn.ExecuteSqlForDataSet(str_Sql);
DataRow dr = ds.Tables[0].Rows[0];
string str_ = dr[parentid].ToString();
string str_Location = str_+str_MaxId+"_";
str_Sql = "INSERT INTO "+tablename+"("+ nodeid +","+ parentid +","+ location +","+ text +","+ text2 +","+ order_id +") VALUES ("+ NewNodeId +",'"+ str_ +"','"+ str_Location +"','"+ MyText +"','"+ MyText2 +"',"+ NewNodeId +")";
YljWeb.Classes.SqlConn.ExecuteSql(str_Sql);
}
}
public void DelTreeViewNode(string nodeid,string parentid,string tablename,int Curnodeid)
{
string str_Sql="delete from "+tablename+" where "+nodeid+"="+ Curnodeid +" or "+ parentid +" like '%"+ Curnodeid +"%'";
YljWeb.Classes.SqlConn.ExecuteSql(str_Sql);
}
}
}
Purview_All_Left.aspx.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;
using Microsoft.Web.UI.WebControls;
namespace YljWeb._Admin.Purview_Manage
{
/// <summary>
/// Tree_Left 的摘要说明。
/// </summary>
public class Purview_All_Left : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lbl_Curnodeid;
protected Microsoft.Web.UI.WebControls.TreeView TreeView1;
protected Microsoft.Web.UI.WebControls.TreeView Treeview1;
protected YljWeb.Classes.TreeControl tree=new YljWeb.Classes.TreeControl();
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string str_Sql="select * from Purview_All order by order_id";
if (YljWeb.Classes.SqlConn.IsExist(str_Sql)) // 遍历树
{
tree.BindTreeView1("nodeid","parentid","location","mytext",str_Sql,"mainFrame","Purview_All_Operate.aspx",lbl_Curnodeid,TreeView1);
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void TreeView_Selected(object sender, Microsoft.Web.UI.WebControls.TreeViewSelectEventArgs e)
{
lbl_Curnodeid.Text = ((TreeNode)TreeView1.GetNodeFromIndex(e.NewNode)).NodeData;
}
}
}
Purview_All_Operate.aspx.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;
using Microsoft.Web.UI.WebControls;
namespace YljWeb._Admin.Purview_Manage
{
/// <summary>
/// Tree_Operate 的摘要说明。
/// </summary>
public class Purview_All_Operate : System.Web.UI.Page
{
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.Button btn_AddChildNode;
protected System.Web.UI.WebControls.Button btn_AddBrotherNode;
protected System.Web.UI.WebControls.Button btn_DelNode;
protected System.Web.UI.WebControls.Button btn_AddRootNode;
protected System.Web.UI.WebControls.TextBox txt_Mytext;
protected System.Web.UI.WebControls.Label lbl_Error;
protected YljWeb.Classes.TreeControl tree=new YljWeb.Classes.TreeControl();
public static DataView dv1;//数据视图
public string str_Sql;
public string str_Location;
public string cru_location;
public int Curnodeid;
protected System.Web.UI.WebControls.TextBox Txt_Command;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator2;
public string MyText;
protected System.Web.UI.WebControls.Label lbl_name;
protected System.Web.UI.WebControls.Label lbl_command;
protected System.Web.UI.WebControls.Button btn_CruNode_Modify;
public string MyText2;
public string cru_user;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
btn_DelNode.Attributes.Add("onClick","javascript:return confirm('你确定要删除此结点及其子结点吗?')");
if (Request["location"]!=null)
{
str_Location=Request["location"].ToString().Substring(0,Request["location"].ToString().Length-1);
Curnodeid = int.Parse(tree.GetTwoMiddleLastStr(str_Location,"_","_"));
MyText = this.txt_Mytext.Text.Replace(" ","");
MyText2 = this.Txt_Command.Text.Replace(" ","");
//////////////// 通过用户的权限来控制按扭的属性 ////////////////////////////////////////////////
if ( Session["AdminName"] != null )
{
cru_user = Session["AdminName"].ToString();
}
else
{
cru_user = "------";/////// 只要该值在用户数据库中不存在就可以
}
if ( YljWeb.Classes.Purview.Purview_Verify(cru_user,"Purview_All_node_Del") )
{
this.btn_DelNode.Visible = true;
}
// else
// {
// this.ShowErrMsg("您没有权限删除!");
// }
/////////////////////////////////////////////////////////////////////////////////////////////////
this.btn_CruNode_Modify.Visible = true;
Get_CruNode_Info();
// BindGrid();
}
str_Sql="select * from Purview_All";
if (YljWeb.Classes.SqlConn.GetRowCount(str_Sql)>0) // 树表存在记录,做遍历操作
{
btn_AddRootNode.Visible=false;
}
else // 数表不存在记录,不做遍历操作
{
btn_DelNode.Visible=false;
btn_AddBrotherNode.Visible=false;
btn_AddChildNode.Visible=false;
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btn_AddRootNode.Click += new System.EventHandler(this.btn_AddRootNode_Click);
this.btn_AddChildNode.Click += new System.EventHandler(this.btn_AddChildNode_Click);
this.btn_AddBrotherNode.Click += new System.EventHandler(this.btn_AddBrotherNode_Click);
this.btn_DelNode.Click += new System.EventHandler(this.btn_DelNode_Click);
this.btn_CruNode_Modify.Click += new System.EventHandler(this.btn_CruNode_Modify_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Get_CruNode_Info()
{
cru_location = Request["location"].ToString();
string str_Sql = "Select * from Purview_All where location = '"+ cru_location +"' ";
DataSet ds1= new DataSet();
ds1 = YljWeb.Classes.SqlConn.ExecuteSqlForDataSet(str_Sql);
this.lbl_name.Text = ds1.Tables[0].Rows[0]["mytext"].ToString();
this.lbl_command.Text = ds1.Tables[0].Rows[0]["command_name"].ToString();
ds1.Dispose();
}
/// <summary>
/// /////////
/// </summary>
// public void BindGrid()
// {
// str_Location = Request["location"].ToString();
// str_Sql="select * from Purview_All where parentid='"+ str_Location +"' order by order_id";
// ViewState["Sort"]="";
// DataSet myds1 = new DataSet();
// myds1 = YljWeb.Classes.SqlConn.ExecuteSqlForDataSet(str_Sql);//调用YljWeb.Classes.SqlConn.ExecuteSqlForDataSet
// dv1=myds1.Tables[0].DefaultView;
// dv1.Table.AcceptChanges();
// ////////////// dv1.Sort /////////////////////////////////////////////////////////////////////////
// if(!object.Equals(ViewState["Sort"],null))
// {
// dv1.Sort =ViewState["Sort"].ToString() ;
// }
//
// ViewState["PageDataCount"]=dv1.Count;//记录每页的数据条数
// if(dv1.Count==0)//判断所查询出来的数据中是否有记录
// {
// dv1.Dispose();
// }
// show_all.DataSource = dv1;//指定数据源
// show_all.DataBind();//控件绑定
// }
/// <summary>
/// //////////
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_AddChildNode_Click(object sender, System.EventArgs e)
{
if (Request["location"]==null) // 判断是否选择左边导航树导航
{
// this.ShowErrMsg("请选择左边导航树节点,再做添加操作!");
// string Str_Show = YljWeb.Classes.MyMethod.ShowErrMsg("请选择左边导航树节点,再做添加操作!");
this.Response.Write( YljWeb.Classes.MyMethod.ShowErrMsg("请选择左边导航树节点,再做添加操作!") );
return;
}
str_Sql="select * from Purview_All where command_name='"+ MyText2 +"'";
if ( YljWeb.Classes.SqlConn.IsExist(str_Sql) )
{
this.ShowErrMsg("对不起,已经存在此命令,请重新输入!");
return;
}
// 下面是增加子节点
tree.AddChildNode2("nodeid","order_id","parentid","location","mytext","command_name","Purview_All",Curnodeid,MyText,MyText2);
// 将最新加入的权限填加到Purview_User_Have预定义
Add_To_Purview_User_Have();
// 刷新左边树导航
lbl_Error.Text="<script language=\"javascript\">parent.frames(\"leftFrame\").document.location.reload();</"+"script>";
}
/// <summary>
/// /////////
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_AddBrotherNode_Click(object sender, System.EventArgs e)
{
if (Request["location"]==null) // 判断是否选择左边导航树导航
{
this.ShowErrMsg("请选择左边导航树节点,再做添加操作!");
return;
}
string str_Sql="select * from Purview_All where nodeid="+ Curnodeid +"and parentid='0_' ";
int count=int.Parse(YljWeb.Classes.SqlConn.GetRowCount(str_Sql).ToString());
if ( count != 0 )
{
this.ShowErrMsg("不能给根节点增加兄弟节点,请增加子节点!"); // 判断不能给跟节点增加兄弟节点
return;
}
str_Sql="select * from Purview_All where command_name='"+ MyText2 +"'";
if ( YljWeb.Classes.SqlConn.IsExist(str_Sql) )
{
this.ShowErrMsg("对不起,已经存在此命令,请重新输入!");
return;
}
// 下面是增加兄弟节点
tree.AddBrotherNode2("nodeid","order_id","parentid","location","mytext","command_name","Purview_All",Curnodeid,MyText,MyText2); // 增加兄弟节点
// 将最新加入的权限填加到Purview_User_Have预定义
Add_To_Purview_User_Have();
// 刷新左边树导航
lbl_Error.Text="<script language=\"javascript\">parent.frames(\"leftFrame\").document.location.reload();</"+"script>";
}
public void Add_To_Purview_User_Have()
{
////// 查出所有用户
string strSql_User = "Select * from AdminUser ";
DataSet ds_user= new DataSet();
ds_user = YljWeb.Classes.SqlConn.ExecuteSqlForDataSet(strSql_User);
if ( ds_user.Tables[0].Rows.Count > 0 )
{
for ( int i = 0 ; i < ds_user.Tables[0].Rows.Count ; i ++ )
{
string strSql_Purview = "Select top 1 * from Purview_All order by nodeid desc";
DataSet ds_purview= new DataSet();
ds_purview = YljWeb.Classes.SqlConn.ExecuteSqlForDataSet(strSql_Purview);
/////// 组合用户权限列表的项 /////////////////////
if ( ds_purview.Tables[0].Rows.Count > 0 )
{
for ( int j = 0 ; j < ds_purview.Tables[0].Rows.Count ; j ++ )
{
string username = ds_user.Tables[0].Rows[i]["username"].ToString().Trim();
string nodeid = ds_purview.Tables[0].Rows[j]["nodeid"].ToString().Trim();
string parentid = ds_purview.Tables[0].Rows[j]["parentid"].ToString().Trim();
string mytext = ds_purview.Tables[0].Rows[j]["mytext"].ToString().Trim();
string location = ds_purview.Tables[0].Rows[j]["location"].ToString().Trim();
string command_name = ds_purview.Tables[0].Rows[j]["command_name"].ToString().Trim();
string order_id = ds_purview.Tables[0].Rows[j]["order_id"].ToString().Trim();
try
{
//////// 写入用户权限数据库 ///////////////////////////
string strSql_Insert = "Insert into Purview_User_Have (username,nodeid,parentid,mytext,location,command_name,order_id,state) values('"+ username +"','"+ nodeid +"','"+ parentid +"','"+ mytext +"','"+ location +"','"+ command_name +"','"+ order_id +"',0)";
YljWeb.Classes.SqlConn.ExecuteSql(strSql_Insert);
}
catch(Exception er)
{
this.ShowErrMsg(" Sorry! 用户权限初始化失败!原因是:"+ er.Message);
}
}
}
else
{
this.ShowErrMsg("对不起,系统功能列表为空,请先设置功能列表!2秒自动转到功能设置页面");
}
}
////// 在这里是调用这个方法,所以最好不要出现以下提示
// this.ShowErrMsg(" 提示:用户权限初始化成功!");
}
else
{
this.ShowErrMsg("对不起,暂时没有用户,请先填加用户!2秒自动转到填加用户页面");
}
}
/// <summary>
/// /
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_DelNode_Click(object sender, System.EventArgs e)
{
if (Request["location"]==null) // 判断是否选择左边导航树节点
{
this.ShowErrMsg("请选择左边导航树节点,再做添加操作!");
return;
}
tree.DelTreeViewNode("nodeid","parentid","Purview_All",Curnodeid); // 递归删除节点
////// 删除Purview_User_Have中的相应记录
Delete_Purview_User_Have();
string str_Sql="select * from Purview_All";
if (YljWeb.Classes.SqlConn.GetRowCount(str_Sql)>0) // 如果树表中存在记录,就做遍历树等操作
{
btn_DelNode.Visible=true;
btn_AddBrotherNode.Visible=true;
btn_AddChildNode.Visible=true;
btn_AddRootNode.Visible=false;
}
else // 如果数表中不存在记录,就清空数
{
btn_DelNode.Visible=false;
btn_AddBrotherNode.Visible=false;
btn_AddChildNode.Visible=false;
btn_AddRootNode.Visible=true;
}
// 刷新左边树导航
lbl_Error.Text="<script language=\"javascript\">parent.frames(\"leftFrame\").document.location.reload();</"+"script>";
}
public void Delete_Purview_User_Have()
{
str_Sql = "Delete from Purview_User_Have where location like '"+ str_Location +"%'";
YljWeb.Classes.SqlConn.ExecuteSql(str_Sql);
}
/// <summary>
/// /
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_AddRootNode_Click(object sender, System.EventArgs e)
{
// 下面增加根节点
string str_Sql="select * from Purview_All where parentid='0_'";
int count=int.Parse(YljWeb.Classes.SqlConn.GetRowCount(str_Sql).ToString());
if ( count != 0 )
{
this.ShowErrMsg("已经存在根结点,只能有一个根结点,填加失败!"); // 判断不能给跟节点增加兄弟节点
return;
}
string MyText = this.txt_Mytext.Text.ToString();
tree.AddRootNode("nodeid","order_id","parentid","location","mytext","Purview_All",MyText);
// 将最新加入的权限填加到Purview_User_Have预定义
Add_To_Purview_User_Have();
btn_DelNode.Visible=true;
btn_AddBrotherNode.Visible=true;
btn_AddChildNode.Visible=true;
btn_AddRootNode.Visible=false;
// 刷新左边树导航
lbl_Error.Text="<script language=\"javascript\">parent.frames(\"leftFrame\").document.location.reload();</"+"script>";
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
// public void node_Delete(Object sender, DataGridCommandEventArgs e)
// {
// string nodeid=e.Item.Cells[0].Text.ToString();
// this.ShowErrMsg("对不起,删除失败!原因:"+ nodeid);
// try
// {
// string deleteCmd = "Delete from Purview_All where nodeid ='"+ nodeid +"'";
// YljWeb.Classes.SqlConn.ExecuteSql(deleteCmd);
// BindGrid();
// }
// catch(Exception er)
// {
// this.ShowErrMsg("对不起,删除失败!原因:"+ er.Message);
// }
// /////////////// 在 1秒后自动刷新 //////////////////////////////////////////
// Response.Write("<meta http-equiv=refresh content=0>");
// }
/// <summary>
///
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
// private void show_all_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
// {
// if(e.SortExpression==ViewState["Sort"].ToString() )
// {
// ViewState["Sort"]=ViewState["Sort"]+" desc";
// }
// else
// {
// ViewState["Sort"]=e.SortExpression;
// }
// BindGrid();
// }
/// <summary>
/// /
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
// private void show_all_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
// {
// System.Web.UI.WebControls.Button TempBtn;
// TempBtn=(System.Web.UI.WebControls.Button)e.Item.FindControl("node_delete") ;
// if(object.Equals(TempBtn,null)==false)
// {
// TempBtn.Attributes.Add("onClick","javascript:return confirm('你确定要删除此结点及其子结点吗?')");
// }
// }
/// <summary>
/// ////////////////////////////// 弹出消息框 ////////////////////////////////////////
/// </summary>
/// <param name="MsgStr"></param>
private void ShowErrMsg(string MsgStr)
{
this.Response.Write("<script language='javascript'>");
this.Response.Write("alert('" +MsgStr + "');");
this.Response.Write("</script>");
}
private void btn_CruNode_Modify_Click(object sender, System.EventArgs e)
{
string str_Sql = "Update Purview_All set mytext ='"+ MyText +"',command_name = '"+ MyText2 +"' where location = '"+ cru_location +"' ";
try
{
YljWeb.Classes.SqlConn.ExecuteSql(str_Sql);
/////// 修改Purview_User_Have,使之同步
Update_Purview_User_Have();
this.ShowErrMsg("修改成功");
Response.Write("<meta http-equiv=refresh content=0>");
lbl_Error.Text="<script language=\"javascript\">parent.frames(\"leftFrame\").document.location.reload();</"+"script>";
}
catch(Exception er)
{
this.ShowErrMsg("对不起,修改失败!原因:"+ er.Message);
}
}
public void Update_Purview_User_Have()
{
str_Sql = "Update Purview_User_Have set mytext ='"+ MyText +"',command_name = '"+ MyText2 +"' where location = '"+ cru_location +"' ";
YljWeb.Classes.SqlConn.ExecuteSql(str_Sql);
}
}
}
本文地址:http://com.8s8s.com/it/it41239.htm