【Wonder原创】系统菜单设计【C#、ASP.NET、Oracle】二:自定义操作类
二、自定义操作类及需要引用的JavaScript代码
1、TreeViewOp.cs
TreeViewOp.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OracleClient;
using Daxon.Mes.Common;
/// <summary>
/// TreeViewOp 的摘要说明
/// </summary>
public class TreeViewOp
{
public TreeViewOp()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
private string strAllow = "";
private string strDeny = "";
//属性
public string AllowString //设置或者获取数据库的连接字符串的属性
{
get
{
return strAllow;
}
}
//属性
public string DenyString //设置或者获取数据库的连接字符串的属性
{
get
{
return strDeny;
}
}
//绑定结构到TreeView
public void BindToTreeView(TreeView tree, DataTable dt, string fieldCMID, string fieldCMName, string fieldValuePath, bool ISShowCheckBox)
{
#region Methods Remark
/********************************************************************
函数名称: BindToTreeView(TreeView tree, DataTable dt, string fieldCMID,string fieldCMName,string fieldValuePath, bool ISShowCheckBox)
功能描述: 将 DataTable 绑定至 TreeView
参数: tree : 要绑定的 TreeView
dt : 严格序列化的数据表
fieldCMID : 作为Node.Value的字段名
fieldCMName : 作为Node.Text的字段名
fieldValuePath: 作为父结点的valuepath的字段名
ISShowCheckBox: 是否显示结点的 checkbox
原作者: Wonder Wang
原作日期: 2007/11/27
修改者:
修改日期:
备注:
*********************************************************************/
#endregion
tree.Nodes.Clear();
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
TreeNode node = new TreeNode();
node.Value = dr[fieldCMID].ToString();
node.Text = dr[fieldCMName].ToString();
if (ISShowCheckBox)
node.ShowCheckBox = true;
node.SelectAction = TreeNodeSelectAction.Expand;
node.ToolTip = "0";
if (i == 0)
tree.Nodes.Add(node);
else
{
TreeNode fNode = new TreeNode();
fNode = tree.FindNode(dr[fieldValuePath].ToString());
if (fNode != null)
fNode.ChildNodes.Add(node);
}
}
tree.Nodes[0].Expand();
}
}
//绑定结构到TreeView
public void BindToSystemMenu(TreeView tree, DataTable dt, string fieldCMID, string fieldCMName, string fieldValuePath, string fieldURL, string fieldTarget)
{
#region Methods Remark
/********************************************************************
函数名称: BindToSystemMenu(TreeView tree, DataTable dt, string fieldCMID,string fieldCMName,string fieldValuePath, bool ISShowCheckBox)
功能描述: 将 DataTable 绑定至 TreeView
参数: tree : 要绑定的 TreeView
dt : 严格序列化的数据表
fieldCMID : 作为Node.Value的字段名
fieldCMName : 作为Node.Text的字段名
fieldValuePath: 作为父结点的valuepath的字段名
ISShowCheckBox: 是否显示结点的 checkbox
原作者: Wonder Wang
原作日期: 2007/11/27
修改者:
修改日期:
备注:
*********************************************************************/
#endregion
tree.Nodes.Clear();
if (dt!=null && dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
TreeNode node = new TreeNode();
node.Value = dr[fieldCMID].ToString();
node.Text = dr[fieldCMName].ToString();
node.NavigateUrl = dr[fieldURL].ToString();
node.Target = dr[fieldTarget].ToString();
node.SelectAction = TreeNodeSelectAction.Expand;
if (i == 0)
tree.Nodes.Add(node);
else
{
TreeNode fNode = new TreeNode();
fNode = tree.FindNode(dr[fieldValuePath].ToString());
if (fNode != null)
fNode.ChildNodes.Add(node);
}
}
tree.Nodes[0].Expand();
}
}
//获取TreeView所有的选中的MenuID
public void GetSelected(TreeNode fnode, bool ISAll)
{
#region Method Remark
/********************************************************************
函数名称: GetSelected(TreeNode fnode, bool ISAll)
功能描述: 获取子节点树的所有checked的结点(value值)
参数: fnode:当前节点
ISAll:是否只获取有改变的
原作者: Wonder Wang
原作日期: 2007/11/27
修改者:
修改日期:
备注:
*********************************************************************/
#endregion
foreach (TreeNode node in fnode.ChildNodes)
{
if (ISAll)
{
if (node.ToolTip.ToString() == "1")
{
if (node.Checked)
strAllow += node.Value + ",";
else
strDeny += node.Value + ",";
}
if (node.ChildNodes.Count > 0)
GetSelected(node, ISAll);
}
else
{
if (node.Checked)
strAllow += "," + node.Value;
else
strDeny += "," + node.Value;
if (node.ChildNodes.Count > 0)
GetSelected(node, ISAll);
}
}
}
//设置父结点CheckBox状态
public void SetParentChecked(TreeNode node)
{
#region Method Remark
/********************************************************************
函数名称: SetParentChecked(TreeNode node)
功能描述: 根据当前节点 checkbox 状态设置所有父结点的 checkbox,
若 checked = true ,则 所有父结点 checked = true,否则不改变父结点
参数: fnode:当前节点
原作者: Wonder Wang
原作日期: 2007/11/27
修改者:
修改日期:
备注:
*********************************************************************/
#endregion
if (node.Parent != null)
{
string modifyFlag = node.Parent.ToolTip.ToString();
if (node.Checked && !node.Parent.Checked)
{
node.Parent.Checked = true;
if (modifyFlag == "0")
node.Parent.ToolTip = "1";
else
node.Parent.ToolTip = "0";
}
SetParentChecked(node.Parent);
}
}
//设置子树结点CheckBox状态
public void SetChildChecked(TreeNode parentNode)
{
#region Method Remark
/********************************************************************
函数名称: SetChildChecked(TreeNode parentNode)
功能描述: 根据当前节点 checkbox 状态设置所有子结点的 checkbox
参数: parentNode:当前节点
原作者: Wonder Wang
原作日期: 2007/11/27
修改者:
修改日期:
备注:
*********************************************************************/
#endregion
foreach (TreeNode node in parentNode.ChildNodes)
{
string modifyFlag = node.ToolTip.ToString();
if (node.Checked != parentNode.Checked)
{
node.Checked = parentNode.Checked;
node.ToolTip = Convert.ToString(Math.Abs(Convert.ToInt16(node.ToolTip)-1));//更新ToolTip
}
if (node.ChildNodes.Count > 0)
{
SetChildChecked(node);
}
}
}
//清空TreeView所有的CheckBox
public void ClearTreeViewCheckStatus(TreeNode fnode)
{
#region Method Remark
/********************************************************************
函数名称: ClearTreeViewCheckStatus(TreeNode fnode)
功能描述: 将所有子结点的 checkbox 设置为 false
参数: fnode:当前节点
原作者: Wonder Wang
原作日期: 2007/11/27
修改者:
修改日期:
备注:
*********************************************************************/
#endregion
foreach (TreeNode node in fnode.ChildNodes)
{
if (node.Checked)
{
node.Checked = false;
node.ToolTip = "0";
}
if (node.ChildNodes.Count > 0)
ClearTreeViewCheckStatus(node);
}
}
//清空TreeView所有的CheckBox
public void ResetTreeViewChangeStatus(TreeNode fnode)
{
#region Method Remark
/********************************************************************
函数名称: ResetTreeViewChangeStatus(TreeNode fnode)
功能描述: 将所有子结点的 ToolTip 还原为 "0",表示未修改状态
参数: fnode:当前节点
原作者: Wonder Wang
原作日期: 2007/11/27
修改者:
修改日期:
备注:
*********************************************************************/
#endregion
fnode.ToolTip = "0";
foreach (TreeNode node in fnode.ChildNodes)
{
node.ToolTip = "0";
if (node.ChildNodes.Count > 0)
ResetTreeViewChangeStatus(node);
}
}
//设置TreeView结点的CheckBox状态
public void SetTreeViewCheckBox(TreeView tree, DataTable dt, string fieldCMID, string fieldValuePath)
{
#region Methods Remark
/********************************************************************
函数名称: SetTreeViewLeaf(TreeView tree,DataTable dt,string fieldCMID,string fieldValuePath)
功能描述: 根据DataTable序列在TreeView中搜索对应结点,并设置 checkbox 选中状态
参数: tree : 已经绑定的 TreeView
dt : 序列化的数据集
fieldCMID : 作为结点value的字段名
fieldValuePath : 作为父结点valuepath的字段名
原作者: Wonder Wang
原作日期: 2007/11/27
修改者:
修改日期:
备注:
*********************************************************************/
#endregion
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
string vp;
if (i == 0)
vp = dr[fieldValuePath].ToString();
else
vp = dr[fieldValuePath].ToString() + "/" + dr[fieldCMID].ToString();
TreeNode node = tree.FindNode(vp);
if (node != null)
if (node.ShowCheckBox == true)
node.Checked = true;
}
}
public static void BindDataToDrpList(System.Web.UI.WebControls.DropDownList drp, string strSql, string valueColumn, string textColumn)
{
#region Methods Remark
/********************************************************************
函数名称: BindDataToDrpList(System.Web.UI.WebControls.DropDownList drp, string strSql, string valueColumn, string textColumn)
功能描述: 将Sql语句的查询结果绑定至DropDownList控件
参数:
drp:DropDownList控件
strSql:查询语句
valueColumn:绑定到drp控件的Value属性的字段名
textColumn:绑定到drp控件的Text属性的字段名
原作者: Wonder Wang
原作日期: 2007/11/27
修改者:
修改日期:
备注:
*********************************************************************/
#endregion
drp.Items.Clear();
OracleAccess dbAccess = new OracleAccess(BaseCommon.GetConntectStr());
System.Data.DataTable dt = dbAccess.GetDataTable(strSql);
for (int i = 0; i < dt.Rows.Count; i++)
{
System.Data.DataRow dr = dt.Rows[i];
System.Web.UI.WebControls.ListItem li = new System.Web.UI.WebControls.ListItem(dr[textColumn].ToString(), dr[valueColumn].ToString());
drp.Items.Add(li);
}
dt = null;
dbAccess = null;
}
public static bool IsDateTime(string str)
{
#region Methods Remark
/********************************************************************
函数名称: IsDateTime(string str)
功能描述: 判断字符串是否是日期格式
参数:
str:源字串
返回值:Bool值,true:是日期格式,false:不是日期格式
原作者: Wonder Wang
原作日期: 2007/12/7
修改者:
修改日期:
备注:
*********************************************************************/
#endregion
try
{
DateTime date = Convert.ToDateTime(str);
return true;
}
catch
{
return false;
}
}
public static string ToLongStringfromDateTime(DateTime date)
{
#region Methods Remark
/********************************************************************
函数名称: ToLongStringfromDateTime(DateTime date)
功能描述: 判断字符串是否是日期格式
参数:
date:日期
返回值:字符串
原作者: Wonder Wang
原作日期: 2007/12/7
修改者:
修改日期:
备注:
*********************************************************************/
#endregion
System.Text.StringBuilder str = new System.Text.StringBuilder();
str.Append(date.Year.ToString());
str.Append(date.Month.ToString());
str.Append(date.Day.ToString());
str.Append(date.Hour.ToString());
str.Append(date.Minute.ToString());
str.Append(date.Second.ToString());
return str.ToString();
}
}
2、UserMenuData.cs
UserMenuData.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Daxon.Mes.Common;
using System.Data.OracleClient;
/// <summary>
/// UserMenuData 的摘要说明
/// </summary>
public class UserMenuData
{
public UserMenuData()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static DataTable GetSystemMenu(string root_cmid)
{
OracleAccess dbAccess = new OracleAccess(BaseCommon.GetConntectStr());
DataSet ds = new DataSet();
try
{
#region Parameter
System.Data.IDataParameter[] oPara = new System.Data.OracleClient.OracleParameter[2];
oPara[0] = new OracleParameter("p_cmptid", OracleType.Number);
oPara[0].Value = Convert.ToInt32( root_cmid);
oPara[0].Direction = ParameterDirection.Input;
oPara[1] = new OracleParameter("p_cursor", OracleType.Cursor);
oPara[1].Direction = ParameterDirection.Output;
#endregion
ds = dbAccess.GetDataSet("SysMenu.proc_Get_SysMenu", oPara);
return ds.Tables[0];
}
catch
{
return null;
}
finally
{ dbAccess = null; }
}
/// <summary>
/// 获取用户菜单
/// </summary>
/// <param name="username"></param>
/// <param name="cmptid"></param>
/// <returns></returns>
public static DataTable GetUserMenu(string username, string cmptid)
{
OracleAccess dbAccess = new OracleAccess(BaseCommon.GetConntectStr());
DataSet ds = new DataSet();
try
{
#region Parameter
System.Data.IDataParameter[] oPara = new System.Data.OracleClient.OracleParameter[3];
oPara[0] = new OracleParameter("p_username", OracleType.VarChar,20);
oPara[0].Value = username.ToUpper();
oPara[0].Direction = ParameterDirection.Input;
oPara[1] = new OracleParameter("p_cmptid", OracleType.Number);
oPara[1].Value = Convert.ToInt32( cmptid);
oPara[1].Direction = ParameterDirection.Input;
oPara[2] = new OracleParameter("p_cursor", OracleType.Cursor);
oPara[2].Direction = ParameterDirection.Output;
#endregion
ds = dbAccess.GetDataSet("SysMenu.proc_Get_UserMenu", oPara);
return ds.Tables[0];
}
catch
{
return null;
}
finally
{ dbAccess = null; }
}
/// <summary>
/// 登录验证
/// </summary>
/// <param name="dbName">Web.Config连接字符串名称</param>
/// <param name="userid"></param>
/// <param name="userPwd"></param>
/// <returns>xml字符串</returns>
public static string UserLogin(string dbName, string userid, string userPwd)
{
OracleAccess oAccess = new OracleAccess(BaseCommon.GetConntectStr(dbName));
OracleParameter[] param = new OracleParameter[5];
string result;
string msg = "";
string username = "";
try
{
#region param
param[0] = new OracleParameter("p_userid", OracleType.VarChar, 50);
param[0].Value = userid.ToUpper();
param[0].Direction = ParameterDirection.Input;
param[1] = new OracleParameter("p_passwd", OracleType.VarChar, 50);
param[1].Value = userPwd;
param[1].Direction = ParameterDirection.Input;
param[2] = new OracleParameter("p_result", OracleType.Int16);
param[2].Direction = ParameterDirection.Output;
param[3] = new OracleParameter("p_username", OracleType.VarChar, 50);
param[3].Direction = ParameterDirection.Output;
param[4] = new OracleParameter("p_msg", OracleType.VarChar, 50);
param[4].Direction = ParameterDirection.Output;
#endregion
oAccess.ExecSPCommand("SysMenu.proc_UserLogin", param);
result = param[2].Value.ToString();
msg = param[4].Value.ToString();
username = param[3].Value.ToString().ToUpper();
}
catch(Exception ex)
{
result = "-99";
msg = ex.Message.Replace("\r\n","");
}
finally
{
param = null;
oAccess = null;
}
string str = @"<?xml version='1.0' encoding='utf-8'?>" +
"<root>" +
"<result>" + result + "</result>" + //0:成功; 其他值:失败
"<username>" + username + "</username>" + //登录用户
"<Description>" + msg + "</Description>" + //如果失败为失败原因描述,如果成功则为"Successed"
"</root>";
return str;
}
/// <summary>
/// 修改密码
/// </summary>
/// <param name="username"></param>
/// <param name="oldPwd"></param>
/// <param name="newPwd"></param>
/// <returns></returns>
public static string UserPWD_Chg(string username,string oldPwd, string newPwd)
{
OracleAccess oAccess = new OracleAccess(BaseCommon.GetConntectStr());
OracleParameter[] param = new OracleParameter[5];
string result;
string msg = "";
try
{
#region param
param[0] = new OracleParameter("p_username", OracleType.VarChar, 50);
param[0].Value = username.ToUpper();
param[0].Direction = ParameterDirection.Input;
param[1] = new OracleParameter("p_oldPwd", OracleType.VarChar, 50);
param[1].Value = oldPwd.ToUpper();
param[1].Direction = ParameterDirection.Input;
param[2] = new OracleParameter("p_newPwd", OracleType.VarChar, 50);
param[2].Value = newPwd.ToUpper();
param[2].Direction = ParameterDirection.Input;
param[3] = new OracleParameter("p_result", OracleType.Int16);
param[3].Direction = ParameterDirection.Output;
param[4] = new OracleParameter("p_msg", OracleType.VarChar, 50);
param[4].Direction = ParameterDirection.Output;
#endregion
oAccess.ExecSPCommand("SysMenu.proc_UserPWD_Chg", param);
result = param[3].Value.ToString();
msg = param[4].Value.ToString();
username = param[3].Value.ToString().ToUpper();
}
catch (Exception ex)
{
result = "-99";
msg = "数据转换异常.";
}
finally
{
param = null;
oAccess = null;
}
string str = @"<?xml version='1.0' encoding='utf-8'?>" +
"<root>" +
"<result>" + result + "</result>" + //0:成功; 其他值:失败
"<username>" + username + "</username>" + //登录用户
"<Description>" + msg + "</Description>" + //如果失败为失败原因描述,如果成功则为"Successed"
"</root>";
return str;
}
/// <summary>
/// 新增用户
/// </summary>
/// <param name="userid"></param>
/// <param name="username"></param>
/// <param name="pwd"></param>
/// <param name="authtype"></param>
/// <param name="dept"></param>
/// <param name="editor"></param>
/// <returns></returns>
public static string AddUser(string userid, string username, string pwd, string authtype, string dept, string editor,string cname)
{
OracleAccess dbAccess = new OracleAccess(BaseCommon.GetConntectStr());
string result;
string msg;
try
{
#region param
OracleParameter[] param = new OracleParameter[9];
param[0] = new OracleParameter("p_userid", OracleType.VarChar, 20);
param[0].Value = userid.ToUpper();
param[0].Direction = ParameterDirection.Input;
param[1] = new OracleParameter("p_ename", OracleType.VarChar, 20);
param[1].Value = username.ToUpper();
param[1].Direction = ParameterDirection.Input;
param[2] = new OracleParameter("p_dept", OracleType.VarChar, 10);
param[2].Value = dept.ToUpper();
param[2].Direction = ParameterDirection.Input;
param[3] = new OracleParameter("p_pwd", OracleType.VarChar, 50);
param[3].Value = pwd;
param[3].Direction = ParameterDirection.Input;
param[4] = new OracleParameter("p_authtype", OracleType.VarChar, 10);
param[4].Value = authtype.ToUpper();
param[4].Direction = ParameterDirection.Input;
param[5] = new OracleParameter("p_editor", OracleType.VarChar, 20);
param[5].Value = editor.ToUpper();
param[5].Direction = ParameterDirection.Input;
param[6] = new OracleParameter("p_result", OracleType.Int16);
param[6].Direction = ParameterDirection.Output;
param[7] = new OracleParameter("p_msg", OracleType.VarChar, 250);
param[7].Direction = ParameterDirection.Output;
param[8] = new OracleParameter("p_cname", OracleType.VarChar, 50);
param[8].Value = cname;
param[8].Direction = ParameterDirection.Input;
#endregion
dbAccess.ExecSPCommand("SysMenu.proc_ADD_User", param);
result = param[6].Value.ToString().Trim();
msg = param[7].Value.ToString().Trim();
}
catch (OracleException ex)
{
result = "-99";
msg = "数据操作失败,错误代码:" + ex.Code.ToString();
}
catch (Exception ex)
{
result = "-100";
msg = ex.Message.Replace("\r\n", "");
}
finally
{
dbAccess = null;
}
string str = @"<?xml version='1.0' encoding='utf-8'?>" +
"<root>" +
"<result>" + result + "</result>" + //0:成功; 其他值:失败
"<Description>" + msg + "</Description>" + //如果失败为失败原因描述,如果成功则为"Successed"
"</root>";
return str;
}
/// <summary>
/// 获取用户列表
/// </summary>
/// <param name="strQueryCondition"></param>
/// <param name="strQueryText"></param>
/// <returns></returns>
public static DataTable GetUserList(string strQueryCondition, string strQueryText)
{
OracleAccess dbAccess = new OracleAccess(BaseCommon.GetConntectStr());
DataTable dt = new DataTable();
try
{
#region param
OracleParameter[] param = new OracleParameter[3];
param[0] = new OracleParameter("p_condition", OracleType.VarChar, 50);
param[0].Value = strQueryCondition.ToUpper();
param[0].Direction = ParameterDirection.Input;
param[1] = new OracleParameter("p_textvalue", OracleType.VarChar,50);
param[1].Value = strQueryText.ToUpper();
param[1].Direction = ParameterDirection.Input;
param[2] = new OracleParameter("p_cursor", OracleType.Cursor);
param[2].Direction = ParameterDirection.Output;
#endregion
dt = dbAccess.GetDataTable("SysMenu.proc_Get_UserList", param);
}
catch (OracleException ex)
{
dt = null;
}
catch (Exception ex)
{
dt = null;
}
finally
{
dbAccess = null;
}
return dt;
}
/// <summary>
/// 更新用户信息
/// </summary>
/// <param name="userid"></param>
/// <param name="authtype"></param>
/// <param name="dept"></param>
/// <param name="status"></param>
/// <param name="editor"></param>
/// <returns></returns>
public static string UpdateUserInfo(string userid, string authtype, string dept,int status, string editor,string cname)
{
OracleAccess dbAccess = new OracleAccess(BaseCommon.GetConntectStr());
string result;
string msg;
try
{
#region param
OracleParameter[] param = new OracleParameter[8];
param[0] = new OracleParameter("p_userid", OracleType.VarChar, 20);
param[0].Value = userid.ToUpper();
param[0].Direction = ParameterDirection.Input;
param[1] = new OracleParameter("p_status", OracleType.Number);
param[1].Value = status;
param[1].Direction = ParameterDirection.Input;
param[2] = new OracleParameter("p_dept", OracleType.VarChar, 10);
param[2].Value = dept.ToUpper();
param[2].Direction = ParameterDirection.Input;
param[3] = new OracleParameter("p_authtype", OracleType.VarChar, 10);
param[3].Value = authtype.ToUpper();
param[3].Direction = ParameterDirection.Input;
param[4] = new OracleParameter("p_editor", OracleType.VarChar, 20);
param[4].Value = editor.ToUpper();
param[4].Direction = ParameterDirection.Input;
param[5] = new OracleParameter("p_result", OracleType.Int16);
param[5].Direction = ParameterDirection.Output;
param[6] = new OracleParameter("p_msg", OracleType.VarChar, 250);
param[6].Direction = ParameterDirection.Output;
param[7] = new OracleParameter("p_cname", OracleType.VarChar, 50);
param[7].Value = cname;
param[7].Direction = ParameterDirection.Input;
#endregion
dbAccess.ExecSPCommand("SysMenu.proc_Update_UserInfo", param);
result = param[5].Value.ToString().Trim();
msg = param[6].Value.ToString().Trim();
}
catch (OracleException ex)
{
result = "-99";
msg = "数据操作失败,错误代码:" + ex.Code.ToString();
}
catch (Exception ex)
{
result = "-100";
msg = ex.Message.Replace("\r\n", "");
}
finally
{
dbAccess = null;
}
string str = @"<?xml version='1.0' encoding='utf-8'?>" +
"<root>" +
"<result>" + result + "</result>" + //0:成功; 其他值:失败
"<Description>" + msg + "</Description>" + //如果失败为失败原因描述,如果成功则为"Successed"
"</root>";
return str;
}
/// <summary>
/// 更新用户信息
/// </summary>
/// <param name="userid"></param>
/// <param name="authtype"></param>
/// <param name="dept"></param>
/// <param name="status"></param>
/// <param name="editor"></param>
/// <returns></returns>
public static string DeleteUserInfo(string userid)
{
OracleAccess dbAccess = new OracleAccess(BaseCommon.GetConntectStr());
string result;
string msg;
try
{
#region param
OracleParameter[] param = new OracleParameter[3];
param[0] = new OracleParameter("p_userid", OracleType.VarChar, 20);
param[0].Value = userid.ToUpper();
param[0].Direction = ParameterDirection.Input;
param[1] = new OracleParameter("p_result", OracleType.Int16);
param[1].Direction = ParameterDirection.Output;
param[2] = new OracleParameter("p_msg", OracleType.VarChar, 250);
param[2].Direction = ParameterDirection.Output;
#endregion
dbAccess.ExecSPCommand("SysMenu.proc_Delete_User", param);
result = param[1].Value.ToString().Trim();
msg = param[2].Value.ToString().Trim();
}
catch (OracleException ex)
{
result = "-99";
msg = "数据操作失败,错误代码:" + ex.Code.ToString();
}
catch (Exception ex)
{
result = "-100";
msg = ex.Message.Replace("\r\n", "");
}
finally
{
dbAccess = null;
}
string str = @"<?xml version='1.0' encoding='utf-8'?>" +
"<root>" +
"<result>" + result + "</result>" + //0:成功; 其他值:失败
"<Description>" + msg + "</Description>" + //如果失败为失败原因描述,如果成功则为"Successed"
"</root>";
return str;
}
/// <summary>
/// 更新用户菜单权限
/// </summary>
/// <param name="username"></param>
/// <param name="strAllow"></param>
/// <param name="strDeny"></param>
/// <param name="editor"></param>
/// <returns></returns>
public static string UpdateUserRight(string username, string strAllow, string strDeny, string editor)
{
OracleAccess dbAccess = new OracleAccess(BaseCommon.GetConntectStr());
string result;
string msg;
try
{
#region param
OracleParameter[] param = new OracleParameter[6];
param[0] = new OracleParameter("p_username", OracleType.VarChar, 20);
param[0].Value = username.ToUpper();
param[0].Direction = ParameterDirection.Input;
param[1] = new OracleParameter("p_allow", OracleType.VarChar, 2000);
param[1].Value = strAllow.ToUpper();
param[1].Direction = ParameterDirection.Input;
param[2] = new OracleParameter("p_deny", OracleType.VarChar, 2000);
param[2].Value = strDeny.ToUpper();
param[2].Direction = ParameterDirection.Input;
param[3] = new OracleParameter("p_editor", OracleType.VarChar, 20);
param[3].Value = editor.ToUpper();
param[3].Direction = ParameterDirection.Input;
param[4] = new OracleParameter("p_result", OracleType.Int16);
param[4].Direction = ParameterDirection.Output;
param[5] = new OracleParameter("p_msg", OracleType.VarChar, 250);
param[5].Direction = ParameterDirection.Output;
#endregion
dbAccess.ExecSPCommand("SysMenu.proc_Update_UserRight", param);
result = param[4].Value.ToString().Trim();
msg = param[5].Value.ToString().Trim();
}
catch (OracleException ex)
{
result = "-99";
msg = "数据操作失败,错误代码:" + ex.Code.ToString();
}
catch (Exception ex)
{
result = "-100";
msg = ex.Message.Replace("\r\n", "");
}
finally
{
dbAccess = null;
}
string str = @"<?xml version='1.0' encoding='utf-8'?>" +
"<root>" +
"<result>" + result + "</result>" + //0:成功; 其他值:失败
"<Description>" + msg + "</Description>" + //如果失败为失败原因描述,如果成功则为"Successed"
"</root>";
return str;
}
}
3、TreeView2.js
作用:使权限设置页面,勾选 TreeView 结点的 CheckBox 时页面不刷新
TreeView2.js
/***************************************************************************************
Name: Client Javascript for ASP.NET 2.0 TreeView
Description: ASP.NET 2.0 TreeView lack for client operation. This set of functions provide
some supports. Includes:
* get node
* change checkbox status of parent and child nodes
***************************************************************************************/
//TreeView1.Attributes.Add("onclick", "OnTreeNodeChecked('TreeView1')");
function OnTreeNodeChecked(treeview)
{
//debugger
var element = window.event.srcElement;
if (!IsCheckBox(element))
return;
//Set ToolTip begin (wonder 080710)
if( element.parentElement.children(1).title == "0")
element.parentElement.children(1).title = "1";
else
element.parentElement.children(1).title = "0";
//Set ToolTip end (wonder 080710)
var isChecked = element.checked;
var tree = TV2_GetTreeById(treeview);
var node = TV2_GetNode(tree,element);
TV2_SetChildNodesCheckStatus(node,isChecked);
var parent = TV2_GetParentNode(tree,node);
TV2_NodeOnChildNodeCheckedChanged(tree,parent,isChecked);
}
//set child nodes checkbox status
function TV2_SetChildNodesCheckStatus(node,isChecked)
{
var childNodes = TV2i_GetChildNodesDiv(node);
if(childNodes == null)
return;
var inputs = WebForm_GetElementsByTagName(childNodes,"INPUT");
if(inputs == null || inputs.length == 0)
return;
for(var i = 0; i < inputs.length; i++)
{
if(IsCheckBox(inputs[i]))
{
if( inputs[i].checked != isChecked)
{
inputs[i].checked = isChecked;
//Set ToolTip begin (wonder 080710)
if( inputs[i].parentElement.children(1).title == "0")
inputs[i].parentElement.children(1).title = "1";
else
inputs[i].parentElement.children(1).title = "0";
//Set ToolTip end (wonder 080710)
}
}
}
}
//change parent node checkbox status after child node changed
function TV2_NodeOnChildNodeCheckedChanged(tree,node,isChecked)
{
if(node == null)
return;
var childNodes = TV2_GetChildNodes(tree,node);
if(childNodes == null || childNodes.length == 0)
return;
var isAllSame = true;
for(var i = 0; i < childNodes.length; i++)
{
var item = childNodes[i];
var value = TV2_NodeGetChecked(item);
if(isChecked != value)
{
isAllSame = false;
break;
}
}
var parent = TV2_GetParentNode(tree,node);
if(isAllSame)
{
TV2_NodeSetChecked(node,true);
TV2_NodeOnChildNodeCheckedChanged(tree,parent,isChecked);
if( isAllSame && !isChecked)//
TV2_NodeSetChecked(node,isChecked);//当所有字节点都取消选择时,取消父结点的选择状态 080710 wonder
}
else
{
TV2_NodeSetChecked(node,true);
TV2_NodeOnChildNodeCheckedChanged(tree,parent,false);
}
}
//get node relative element(etc. checkbox)
function TV2_GetNode(tree,element)
{
var id = element.id.replace(tree.id,"");
id = id.toLowerCase().replace(element.type,"");
id = tree.id + id;
var node = document.getElementById(id);
if(node == null) //leaf node, no "A" node
return element;
return node;
}
//get parent node
function TV2_GetParentNode(tree,node)
{
var div = WebForm_GetParentByTagName(node,"DIV");
//The structure of node: <table>information of node</table><div>child nodes</div>
var table = div.previousSibling;
if(table == null)
return null;
return TV2i_GetNodeInElement(tree,table);
}
//get child nodes array
function TV2_GetChildNodes(tree,node)
{
if(TV2_NodeIsLeaf(node))
return null;
var children = new Array();
var div = TV2i_GetChildNodesDiv(node);
var index = 0;
for(var i = 0; i < div.childNodes.length; i++)
{
var element = div.childNodes[i];
if(element.tagName != "TABLE")
continue;
var child = TV2i_GetNodeInElement(tree,element);
if(child != null)
children[index++] = child;
}
return children;
}
function TV2_NodeIsLeaf(node)
{
return !(node.tagName == "A"); //Todo
}
function TV2_NodeGetChecked(node)
{
var checkbox = TV2i_NodeGetCheckBox(node);
return checkbox.checked;
}
function TV2_NodeSetChecked(node,isChecked)
{
var checkbox = TV2i_NodeGetCheckBox(node);
if(checkbox != null)
//
{
if( checkbox.checked != isChecked)
{ //debugger
checkbox.checked = isChecked;
if( checkbox.parentElement.children(1).title == "0")
checkbox.parentElement.children(1).title = "1";
else
checkbox.parentElement.children(1).title = "0";
}
}
//
}
function IsCheckBox(element)
{
if(element == null)
return false;
return (element.tagName == "INPUT" && element.type.toLowerCase() == "checkbox");
}
//get tree
function TV2_GetTreeById(id)
{
return document.getElementById(id);
}
//////////////////////////////////////////////////////////////////////////////////////////////
//private mothods, with TV2i_ prefix
//////////////////////////////////////////////////////////////////////////////////////////////
//get div contains child nodes
function TV2i_GetChildNodesDiv(node)
{
if(TV2_NodeIsLeaf(node))
return null;
var childNodsDivId = node.id + "Nodes";
return document.getElementById( childNodsDivId );
}
//find node in element
function TV2i_GetNodeInElement(tree,element)
{
var node = TV2i_GetNodeInElementA(tree,element);
if(node == null)
{
node = TV2i_GetNodeInElementInput(tree,element);
}
return node;
}
//find "A" node
function TV2i_GetNodeInElementA(tree,element)
{
var as = WebForm_GetElementsByTagName(element,"A");
if(as== null || as.length == 0)
return null;
var regexp = new RegExp("^" + tree.id + "n\\d+$");
for(var i = 0; i < as.length; i++)
{
if(as[i].id.match(regexp))
{
return as[i];
}
}
return null;
}
//find "INPUT" node
function TV2i_GetNodeInElementInput(tree,element)
{
var as = WebForm_GetElementsByTagName(element,"INPUT");
if(as== null || as.length == 0)
return null;
var regexp = new RegExp("^" + tree.id + "n\\d+");
for(var i = 0; i < as.length; i++)
{
if(as[i].id.match(regexp))
{
return as[i];
}
}
return null;
}
//get checkbox of node
function TV2i_NodeGetCheckBox(node)
{
if(IsCheckBox(node))
return node;
var id = node.id + "CheckBox";
return document.getElementById(id);
}