using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
/// <summary>
/// AppPubString 的摘要说明:公共变量及一些通用过程
/// </summary>
public class AppPubString
{
/// <summary>
/// Session["UserId"],Session["UserName"]:
/// Session["isBtnQuery"]:是否按钮查询
/// Session["AppCurModuleName"]:登录用户当前所在模块名
/// Session["AppUserRoleList"] :登录用户所属的角色组
/// Session["AppRoleModFunStr"]:登录用户所属的角色组所有的模块功能权限字串
///
/// </summary>
///
///GridView每页记录数
public static int AppPageSize = 2;
/// <summary>
/// 模块权限设置是否使用Session变量0,1
/// </summary>
public static int AppGrantSessionFlag = 1;
public AppPubString()
{
}
#region 菜单树选项框初始化
/// <summary>
/// 菜单树选项框初始化
/// </summary>
public static void TreeChkBoxInit(TreeView TreeView0,bool ChkFlag)
{
//菜单树的复选项
for (int j = 0; j < TreeView0.Nodes.Count; j++)
{
TreeView0.Nodes[j].Checked = ChkFlag;
if (TreeView0.Nodes[j].ChildNodes.Count > 0)
{
TreeChildBoxInit(TreeView0.Nodes[j],ChkFlag);
}
}
}
/// <summary>
/// 子结点树选项框初始化
/// </summary>
/// <param name="parentNode"></param>
public static void TreeChildBoxInit(TreeNode CurTreeNode,bool ChkFlag)
{
//子菜单树的复选项
for (int k = 0; k < CurTreeNode.ChildNodes.Count; k++)
{
CurTreeNode.ChildNodes[k].Checked = ChkFlag;
if (CurTreeNode.ChildNodes[k].ChildNodes.Count > 0)
{
TreeChildBoxInit(CurTreeNode.ChildNodes[k], ChkFlag);
}
}
}
#endregion
///
#region 按权限显示菜单树ShowGrantTree
/// <summary>
/// 按设置的权限选中树结点
/// </summary>
/// <param name="parentNode"></param>
public static void ShowGrantTree(DataSet ds,TreeView TreeView0)
{
string CurrentModuleId;
string TreeValue;
int TreeChkBoxCnt = -1;
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
CurrentModuleId = ds.Tables[0].Rows[i].ItemArray[0].ToString();
for (int j = 0; j < TreeView0.Nodes.Count; j++)
{
if (TreeView0.Nodes[j].ChildNodes.Count > 0)
{
TreeChkBoxCnt = 0;
ShowGrantTreeChild(TreeView0.Nodes[j], CurrentModuleId);
for (int m = 0; m < TreeView0.Nodes[j].ChildNodes.Count; m++)
{
if (TreeView0.Nodes[j].ChildNodes[m].Checked == true)
{
TreeChkBoxCnt++;
}
}
}
TreeValue = TreeView0.Nodes[j].Value.Trim();
if (CurrentModuleId == TreeValue || TreeView0.Nodes[j].ChildNodes.Count == TreeChkBoxCnt)
{
TreeView0.Nodes[j].Checked = true;
}
}
}
}
//递归遍历子菜单树
/// <summary>
/// 按设置的权限选中子树结点
/// </summary>
/// <param name="parentNode"></param>
public static void ShowGrantTreeChild(TreeNode CurTreeNode, string ModuleId)
{
string TreeValue;
int TreeChkBoxCnt = -1;
//按权限设置复选框
for (int i = 0; i < CurTreeNode.ChildNodes.Count; i++)
{
if (CurTreeNode.ChildNodes[i].ChildNodes.Count > 0)
{
ShowGrantTreeChild(CurTreeNode.ChildNodes[i], ModuleId);
}
//子结点选中个数
TreeChkBoxCnt = 0;
for (int m = 0; m < CurTreeNode.ChildNodes[i].ChildNodes.Count; m++)
{
if (CurTreeNode.ChildNodes[i].ChildNodes[m].Checked == true)
{
TreeChkBoxCnt++;
}
}
//
TreeValue = CurTreeNode.ChildNodes[i].Value.Trim();
if (ModuleId == TreeValue || CurTreeNode.ChildNodes.Count == TreeChkBoxCnt)
{
CurTreeNode.ChildNodes[i].Checked = true;
}
}
}
#endregion
#region 遍历页面所有的控件并清空(对于母版页无效)getAllControlValue(this)
public static Hashtable getAllControlValue(object PageOrUserControl)
{
Hashtable rtn = new Hashtable();
foreach (Control ctr in (PageOrUserControl as Page).Controls)
{
getControlValue(ctr, rtn);
}
return rtn;
}
//
private static void getControlValue(Control ctrIn, Hashtable ht)
{
foreach (Control ctr in ctrIn.Controls)
{
Type controlType = ctr.GetType();
switch (controlType.ToString())
{
case "System.Web.UI.WebControls.TextBox":
//TextBox controlTextBoxObj = (TextBox)ctr;
//string controlTextBoxName = controlTextBoxObj.ID;
//string controlTextBoxValue = controlTextBoxObj.Text;
//ht.Add(controlTextBoxName, controlTextBoxValue);
((TextBox)ctr).Text = "";
break;
case "System.Web.UI.WebControls.DropDownList":
((DropDownList)ctr).Text = "";
break;
default:
break;
}
}
}
#endregion
#region 遍历带有母版页的所有控件
/// <summary>
/// 遍历带有母版页的所有控件
/// </summary>
/// <param name="c"></param>
public static void GetMasterControls(ControlCollection c)
{
Control control;
if (c.Count > 0)
{
for (int i = 0; i < c.Count; i++)
{
control = c[i];
Type controlType = control.GetType();
switch (controlType.ToString())
{
case "System.Web.UI.WebControls.TextBox":
((TextBox)control).Text = "";
break;
case "System.Web.UI.WebControls.DropDownList":
//((DropDownList)control).Text = "";
//((DropDownList)control).SelectedValue = "0";
((DropDownList)control).SelectedIndex = 0;
break;
//case "其他类型":
// 其它类型 controlTextBoxObj = (其它类型)ctr;
// string controlTextBoxName = controlTextBoxObj.ID;
// string controlTextBoxValue = controlTextBoxObj.Text;
// ht.Add(controlTextBoxName, controlTextBoxValue);
// break;
default:
break;
}
if (control.HasControls())
{
GetMasterControls(control.Controls);
}
}
}
}
#endregion
#region //判断输入的数据类型是否正确
/// <summary>
/// //判断输入的数据类型是否正确(0:数字0-9,1:A-Za-z0-9,2:A-Za-z)
/// </summary>
/// <param name="c"></param>
public static bool IsDataTypeRight(int dataFlag,string str)
{
if (System.Text.RegularExpressions.Regex.IsMatch(str, @"^[0-9]+$") && dataFlag == 0)
{
return true;
}
else if (System.Text.RegularExpressions.Regex.IsMatch(str, @"^[A-Za-z0-9]+$") && dataFlag == 1)
{
return true;
}
else if (System.Text.RegularExpressions.Regex.IsMatch(str, @"^[A-Za-z]+$") && dataFlag == 2)
{
return true;
}
else
{
return false;
}
}
#endregion
#region GridView数据绑定,列已设置
// 参数:所要绑定的GridView 所要绑定的数据集
/// <summary>
/// GridView数据绑定,列已设置,无数据时显示GridView表头
/// </summary>
/// <param name="gridView"></param>
/// <param name="dt"></param>
public static void GridViewBindData(GridView gridView, DataTable dt)
{
gridView.AllowPaging = true;
gridView.PageSize = AppPubString.AppPageSize;
if (dt.Rows.Count == 0)
{
dt.Rows.Add(dt.NewRow());
gridView.DataSource = dt;
gridView.DataBind();
int columnCount = gridView.Rows[0].Cells.Count;
gridView.Rows[0].Cells.Clear();
gridView.Rows[0].Cells.Add(new TableCell());
gridView.Rows[0].Cells[0].ColumnSpan = columnCount;
gridView.Rows[0].Cells[0].Text = "没有任何记录!";
gridView.RowStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
}
else
{
gridView.DataSource = dt;
gridView.DataBind();
gridView.RowStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Left;
}
}
#endregion
#region GridView动态生成数据绑定列(普通列,数据链接列)
/// <summary>
/// 动态绑定生成GridView列--普通列,数据链接列
/// </summary>
/// <param name="gridView">要绑定的GridView</param>
/// <param name="dtblDataSource">GridView的数据源</param>
/// <param name="strDataKey">GridView的DataKeyNames</param>
/// <param name="HyLinkColumn">使用HyLinkField绑定的列</param>
/// <param name="HyLinkField">HyLinkField链接参数</param>
/// <param name="HyLinkDataUrl">HyLinkField的Url地址</param>
/// <param name="LinkUrlField">HyperLink的链接参数</param>
/// <param name="LinkUrl">HyLinkField的Url地址</param>
/// <param name="LinkUrlText">HyLinkField的显示文本</param>
public static void GridViewBind(GridView gridView, DataTable dtblDataSource, string strDataKey,GridLines gridLine,
int HyLinkColumn,String HyLinkField,string HyLinkDataUrl,
string LinkUrlField,string LinkUrl,string LinkUrlText,string SortField)
{
string DataField,HeaderText;
string[] UrlDataFields = null;
string[] tmpLinkField = HyLinkField.Split(',');
string[] SortDataFields = null;
string[] tmpSortField = SortField.Split(',');
//HyLinkField参数
UrlDataFields = new string[tmpLinkField.Length];
for (int i = 0; i< tmpLinkField.Length; i++)
{
UrlDataFields[i] = tmpLinkField[i].ToString();
}
//排序字段
SortDataFields = new string[tmpSortField.Length];
for (int j = 0; j < tmpSortField.Length; j++)
{
SortDataFields[j] = tmpSortField[j].ToString();
}
gridView.Columns.Clear();
gridView.AutoGenerateColumns = false;
gridView.GridLines = gridLine;
if (strDataKey != "")
{
gridView.DataKeyNames = new string[] { strDataKey };
}
for (int i = 0; i < dtblDataSource.Columns.Count; i++) //绑定普通数据列,链接列
{
DataField = dtblDataSource.Columns[i].ColumnName;
HeaderText = dtblDataSource.Columns[i].Caption;
if (HyLinkColumn == i)
{
HyperLinkField HyLnkColumn = new HyperLinkField();
HyLnkColumn.DataTextField = DataField;
HyLnkColumn.HeaderText = HeaderText;
for (int k = 0; k < SortDataFields.Length; k++)
{
if (DataField == SortDataFields[k].ToString())
{
HyLnkColumn.SortExpression = DataField;
}
}
HyLnkColumn.DataNavigateUrlFields = UrlDataFields;
HyLnkColumn.DataNavigateUrlFormatString = HyLinkDataUrl;
gridView.Columns.Add(HyLnkColumn);
}
else
{
BoundField bfColumn = new BoundField();
bfColumn.DataField = DataField;
bfColumn.HeaderText = HeaderText;
for (int k = 0; k < SortDataFields.Length; k++)
{
if (DataField == SortDataFields[k].ToString())
{
bfColumn.SortExpression = DataField;
}
}
gridView.Columns.Add(bfColumn);
}
}
//CommandField cfModify = new CommandField(); //绑定命令列
//cfModify.ButtonType = ButtonType.Button;
//cfModify.SelectText = "修改";
//cfModify.ShowSelectButton = true;
//gridView.Columns.Add(cfModify);
//生成HyLink链接
if (LinkUrl != "")
{
TemplateField tfColumn = new TemplateField();
tfColumn.ItemTemplate = new AppPubTemplate("", DataControlRowType.DataRow, "HyperLink", //行标题,行类型,控件类型
LinkUrlText, LinkUrl, LinkUrlField);//Url链接显示文本,Url地址,Url参数
gridView.Columns.Add(tfColumn);
}
//
GridViewBindData(gridView, dtblDataSource);
}
#endregion
#region GridView数据绑定后,手动设定排序
/// <summary>
/// GridView数据绑定后,手动设定排序
/// </summary>
/// <param name="gridView"></param>
/// <param name="dt"></param>
public static void GridViewColumnSort(GridView gridView, DataTable dt, string SortColumn, string SortType)
{
DataView dv = dt.DefaultView;
dv.Sort = SortColumn + " " + SortType;
gridView.DataSource = dv;
gridView.DataBind();
}
#endregion
/// <summary>
/// MD5加密
/// </summary>
/// <param name="SQLString">需要加密字符串</param>
/// <returns>加密后的字符串</returns>
public static string getMd5Hash(string input)
{
// Create a new instance of the MD5CryptoServiceProvider object.
MD5 md5Hasher = MD5.Create();
// Convert the input string to a byte array and compute the hash.
byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
// Return the hexadecimal string.
return sBuilder.ToString();
}
}
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;
/// <summary>
/// AppPubTemplate 的摘要说明:动态添加模版列
/// </summary>
public class AppPubTemplate:ITemplate
{
public AppPubTemplate()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
private string strColumnName;
private DataControlRowType dcrtColumnType;
private string ControlType;
private string ControlText;
private string ControlUrl; //控件Url地址
private string LinkUrlField; //Url地址的参数
private string strDataType ="date";
/** <summary>
/// 动态添加模版列
/// </summary>
/// <param name="strColumnName">列名</param>
/// <param name="dcrtColumnType">列的类型</param>
/// <param name="ControlType"></param>
///
public AppPubTemplate(string strColumnName, DataControlRowType dcrtColumnType, string ControlType)
{
this.strColumnName = strColumnName;
this.dcrtColumnType = dcrtColumnType;
this.ControlType = ControlType;
}
/// <summary>
/// 动态添加模版列
/// </summary>
/// <param name="strColumnName">列名</param>
/// <param name="dcrtColumnType"></param>
/// <param name="ControlType">控件类型</param>
/// <param name="ControlText">显示文本</param>
/// <param name="ControlUrl">Url地址</param>
/// <param name="LinkUrlField">Url参数</param>
public AppPubTemplate(string strColumnName, DataControlRowType dcrtColumnType, string ControlType,
string ControlText, string ControlUrl, string LinkUrlField)
{
this.strColumnName = strColumnName;
this.dcrtColumnType = dcrtColumnType;
this.ControlType = ControlType;
this.ControlText = ControlText;
this.ControlUrl = ControlUrl;
this.LinkUrlField = LinkUrlField;
}
/// <summary>
/// 后台生成模板列中的控件。
/// </summary>
/// <param name="ctlContainer"></param>
public void InstantiateIn(Control ctlContainer)
{
switch (dcrtColumnType)
{
case DataControlRowType.Header: //列标题
Literal ltr = new Literal();
ltr.Text = strColumnName;
ctlContainer.Controls.Add(ltr);
break;
case DataControlRowType.DataRow: //模版列内容——加载
{
if (ControlType == "ChkBox")
{
CheckBox cb = new CheckBox();
cb.ID = "CheckBox1";
cb.Checked = false;
ctlContainer.Controls.Add(cb);
Label lb = new Label();
ctlContainer.Controls.Add(lb);
}
//else if (ControlType == "HyperLink1")
//{
// HyperLink hf = new HyperLink();
// hf.ID = "HyperLink1";
// hf.Text = ControlText;
// hf.NavigateUrl = ControlUrl;
// ctlContainer.Controls.Add(hf);
//}
else if (ControlType == "HyperLink")
{
HyperLink hf = new HyperLink();
hf.DataBinding += new System.EventHandler(OnDataBinding);
ctlContainer.Controls.Add(hf);
}
}
break;
}
}
#region 绑定后台生成模板列中的控件。
private void OnDataBinding(object sender,EventArgs e)
{
DataGridItem container;
switch (ControlType.ToLower())
{
case "label":
Label label;
label=(Label)sender;
//控件发送绑定请求
container=(DataGridItem) label.NamingContainer;
switch(this.strDataType)
{
case "date":
label.Text=(DataBinder.Eval(container.DataItem, strColumnName)).ToString()==""?"":((DateTime)DataBinder.Eval(container.DataItem, strColumnName)).ToShortDateString();
break;
default:
label.Text=DataBinder.Eval(container.DataItem, strColumnName).ToString();
break;
}
break;
case "textbox":
TextBox textbox;
textbox=(TextBox)sender;
//控件发送绑定请求
container=(DataGridItem)textbox.NamingContainer;
textbox.Text=DataBinder.Eval(container.DataItem, strColumnName).ToString();
break;
case "hyperlink":
HyperLink hyperlink = null;
hyperlink =(HyperLink)sender;
//控件发送绑定请求
GridViewRow container1 = hyperlink.NamingContainer as GridViewRow;
//hyperlink.Text = DataBinder.Eval(container1.DataItem, strColumnName).ToString();
hyperlink.Text = ControlText;
hyperlink.NavigateUrl = DataBinder.Eval(container1.DataItem, LinkUrlField, ControlUrl);
hyperlink.Style.Add("cursor","hand");
break;
case "checkbox":
CheckBox checkbox;
checkbox=(CheckBox)sender;
//控件发送绑定请求
container=(DataGridItem) checkbox.NamingContainer;
checkbox.Checked=(bool)((DataRowView)(container.DataItem))[strColumnName];
break;
case "linkbutton":
LinkButton linkbutton = new LinkButton();
linkbutton=(LinkButton)sender;
container=(DataGridItem) linkbutton.NamingContainer;
linkbutton.Text=DataBinder.Eval(container.DataItem, strColumnName).ToString();
break;
default:
break;
}
#endregion
}
}
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.Collections.Generic;
/// <summary>
/// AppRoleModGrant的摘要说明:角色模块权限
/// </summary>
public class AppRoleModGrant
{
/// <summary>
/// Session["UserId"],Session["UserName"]:
/// Session["isBtnQuery"]:是否按钮查询
/// Session["AppCurModuleName"]:登录用户当前所在模块名
/// Session["AppUserRoleList"] :登录用户所属的角色组
/// Session["AppRoleModFunStr"]:登录用户所属的角色组所有的模块功能权限字串
///
/// </summary>
public AppRoleModGrant()
{
}
/// <summary>
/// 基本模块功能设置串名称(新增,删除等)
/// </summary>
public static ArrayList ModFuncString()
{
//浏览:只读查看,不能新增、编辑、删除,打印,数据导出、单据审核等权限。默认浏览
//编辑:可以修改已经存在的数据。
//新增:可以新增记录。
//删除:可以删除已存在的记录或者单据。
//打印:控制用户是否可以打印指定的报表或者单据。
//数据导出:是否可以将数据从系统中导出。
//审核:单据的审核权限。
ArrayList ArrayList0 = new ArrayList();
ArrayList0.Add("新增"); //2^0=1
ArrayList0.Add("修改"); //2^1=2
ArrayList0.Add("删除"); //2^2=4
ArrayList0.Add("打印"); //2^3=8
ArrayList0.Add("数据导出"); //2^4=16
ArrayList0.Add("审核"); //2^5=32
return ArrayList0;
}
#region //模块权限功能权值处理
/// <summary>
/// 提取各模块所具体有功能权限(如某模块有新增,审核,打印的功能),定位值写入动态表ArrayList
/// </summary>
/// <returns></returns>
public static ArrayList GetModFunGrand(string ModuleId)
{
string strSQL;
string ModFunString = "";
DataSet ds;
ArrayList ArrayListTB = new ArrayList();
strSQL = "Select ModFunction From ModuleList Where ModuleId = '" + ModuleId + "' and isClose=0";
ds = Common.QueryDataSet(strSQL);
if (ds.Tables[0].Rows.Count > 0)
{
ModFunString = ds.Tables[0].Rows[0]["ModFunction"].ToString();
GetRightValue(ModFunString,ref ArrayListTB);
}
return ArrayListTB;
}
/// <summary>
/// 从日志中提取各模块所具体有功能权限(如某模块有新增,审核,打印的功能),定位值写入动态表ArrayList
/// </summary>
/// <returns></returns>
public static ArrayList GetModFunGrandLog(string ModuleId)
{
string strSQL;
string ModFunString = "";
DataSet ds;
ArrayList ArrayListTB = new ArrayList();
strSQL = "Select ModFunction From ModuleListLog Where ModuleId = '" + ModuleId + "' and isClose=0";
ds = Common.QueryDataSet(strSQL);
if (ds.Tables[0].Rows.Count > 0)
{
ModFunString = ds.Tables[0].Rows[0]["ModFunction"].ToString();
GetRightValue(ModFunString, ref ArrayListTB);
}
return ArrayListTB;
}
#region 提取分配给各角色下各模块的功能权限字串
/// <summary>
/// 提取分配给各角色下各模块的功能权限字串(通过Session记录来设置)写ArrayList,参数:角色组,模块号
/// </summary>
/// <param name="ArrayRoleList"></param>
/// <param name="ModuleId"></param>
/// <returns></returns>
public static ArrayList GetRoleModFunGrand(ArrayList ArrayRoleList, string ModuleId)
{
string strSQL;
string ModFunString = "";
string RoleId;
DataSet ds = null;
ArrayList ArrayListTB = new ArrayList(); //直接在此创建实例,省去调用时判断是否Null
if (ArrayRoleList != null)
{
for (int k = 0; k < ArrayRoleList.Count; k++)
{
RoleId = ArrayRoleList[k].ToString().Trim();
strSQL = "Select ModuleGrant From RoleModule Where RoleId='" + RoleId + "' and ModuleId = '" + ModuleId + "'";
ds = Common.QueryDataSet(strSQL);
if (ds.Tables[0].Rows.Count > 0)
{
ModFunString = ds.Tables[0].Rows[0]["ModuleGrant"].ToString();
GetRightValue(ModFunString, ref ArrayListTB);
}
if (ds != null) ds = null;
}
}
return ArrayListTB;
}
#endregion
#region 提取分配给各角色下各模块的功能权限字串(根据登录用户ID直接从数据库中提取数据)
/// <summary>
/// 提取分配给各角色下各模块的功能权限字串(根据登录用户ID直接从数据库中提取数据)写ArrayList,参数:用户,模块号
/// </summary>
/// <returns></returns>
public static ArrayList GetRoleModFunGrand(String UserId, string ModuleId)
{
string strSQL;
string ModFunString = "";
string RoleId;
DataSet ds = null;
UserLogin CurUserLogin = null;
ArrayList UserRoleList = null;
ArrayList AppRoleModFunStr = null;
ArrayList ArrayListTB = new ArrayList(); //直接在此创建实例,省去调用时判断是否Null
if (UserId != null)
{
//根据登录用户提取角色组
CurUserLogin = new UserLogin();
CurUserLogin.LogUserId = UserId;
UserRoleList = CurUserLogin.GetUserRole();
if (UserRoleList != null)
{
for (int k = 0; k < UserRoleList.Count; k++)
{
RoleId = UserRoleList[k].ToString().Trim();
strSQL = "Select ModuleGrant From RoleModule Where RoleId='" + RoleId + "' and ModuleId = '" + ModuleId + "'";
ds = Common.QueryDataSet(strSQL);
if (ds.Tables[0].Rows.Count > 0)
{
ModFunString = ds.Tables[0].Rows[0]["ModuleGrant"].ToString();
GetRightValue(ModFunString, ref ArrayListTB);
}
if (ds != null) ds = null;
}
}
if (CurUserLogin != null) CurUserLogin = null;
if (UserRoleList != null) UserRoleList = null;
if (AppRoleModFunStr != null) AppRoleModFunStr = null;
}
return ArrayListTB;
}
#endregion
/// <summary>
/// 提取分配给各角色下各模块的功能权限字串写入Hashtable表(通过Session记录来设置)参数:角色组
/// </summary>
/// <param name="ArrayRoleList"></param>
/// <returns></returns>
public static Hashtable GetRoleModFunGrand(ArrayList ArrayRoleList)
{
string strSQL, RoleId, ModuleId;
string ModFunString = ""; //RoleModule表中的权限值
string ModGrantStr = null;//转换后权限值字串
DataSet ds = null;
Hashtable Hashtable0 = new Hashtable(); //直接在此创建实例,省去外部调用时判断是否Null
ArrayList ArrayListTB = null;
if (ArrayRoleList != null)
{
for (int k = 0; k < ArrayRoleList.Count; k++) //角色组
{
RoleId = ArrayRoleList[k].ToString().Trim();
strSQL = "Select ModuleId,ModuleGrant From RoleModule Where RoleId='" + RoleId + "' ";
ds = Common.QueryDataSet(strSQL);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
ModuleId = ds.Tables[0].Rows[i]["ModuleId"].ToString();
ModFunString = ds.Tables[0].Rows[i]["ModuleGrant"].ToString();
//权值转换
ModGrantStr = null;
ArrayListTB = new ArrayList();
GetRightValue(ModFunString, ref ArrayListTB);
for (int j = 0; j < ArrayListTB.Count; j++)
{
if (ModGrantStr != null)
{
ModGrantStr += ",";
}
ModGrantStr += ArrayListTB[j].ToString().Trim();
}
if (ModGrantStr != null)
{
if (!Hashtable0.ContainsKey(ModuleId) && !Hashtable0.ContainsValue(ModGrantStr))
{
Hashtable0.Add(ModuleId, ModGrantStr);
}
}
}
if (ds != null) ds = null;
}
}
return Hashtable0;
}
#endregion
/// <summary>
/// 从日志中提取各角色各模块所具有功能权限(如某模块有新增,审核,打印的功能),定位值写入动态表ArrayList
/// </summary>
/// <returns></returns>
public static ArrayList GetModGrandLog(string ModuleId, string RoleId, string CurSerialID)
{
string strSQL;
string ModFunString = "";
DataSet ds;
ArrayList ArrayListTB = new ArrayList();
strSQL = "Select moduleGrant From RoleModuleLog Where ModuleId = '" + ModuleId + "' and RoleId = '" + RoleId + "' and SerialID = '" + CurSerialID + "'";
ds = Common.QueryDataSet(strSQL);
if (ds.Tables[0].Rows.Count > 0)
{
ModFunString = ds.Tables[0].Rows[0]["moduleGrant"].ToString();
GetRightValue(ModFunString, ref ArrayListTB);
}
return ArrayListTB;
}
#region 位与提取权限值写入动态数组表ArrayList表
private static void GetRightValue(string RightString, ref ArrayList ArrayListTB)
{
int RightValue;
int purviewValue; //2^N,2的N次方值
if (RightString.Length > 0)
{
RightValue = Convert.ToInt32(RightString);
ArrayList ArrayList0 = AppRoleModGrant.ModFuncString(); //基本权限组表
for (int i = 0; i < ArrayList0.Count; i++)
{
purviewValue = (int)Math.Pow(2, i);
if ((RightValue & purviewValue) == purviewValue)
{
ArrayListTB.Add(i);
}
}
if (ArrayList0 != null) ArrayList0 = null;
}
}
#endregion
#region 模块权限设置页面展示(通过Session记录来设置)
/// <summary>
/// 根据角色分配的模块功能权限设置页面功能(如:是新增,修改还是删除)通过Session记录来设置
/// </summary>
/// <param name="TitleText"></param>
/// <param name="ReqId"></param>
/// <param name="AppRoleModFunStr"></param>
/// <param name="BtnEnter"></param>
/// <param name="BtnDel"></param>
/// <returns></returns>
public static string SetRoleModFun(String Flag, String TitleText, String ReqId, ArrayList AppRoleModFunStr, Button BtnEnter, Button BtnDel)
{
string FlagMemo = "";
String GrantFlag = "";
if (AppRoleModFunStr != null)
{
for (int i = 0; i < AppRoleModFunStr.Count; i++)
{
GrantFlag = AppRoleModFunStr[i].ToString();
AppRoleModGrant.SetShowInfo(ref FlagMemo, Flag, ReqId, GrantFlag, BtnEnter, BtnDel);
}
}
if (FlagMemo != "")
{
FlagMemo = " ==>操作状态:" + FlagMemo;
}
TitleText = TitleText + FlagMemo;
return TitleText;
}
#endregion
#region 模块权限设置页面展示(根据登录用户ID直接从数据库中提取数据)
/// <summary>
///根据角色分配的模块功能权限设置页面功能(如:是新增,修改还是删除)根据登录用户ID直接从数据库中提取数据
/// </summary>
/// <param name="TitleText"></param>
/// <param name="ReqId"></param>
/// <param name="UserId"></param>
/// <param name="ModuleId"></param>
/// <param name="BtnEnter"></param>
/// <param name="BtnDel"></param>
/// <returns></returns>
public static string SetRoleModFun(String Flag, String TitleText, String ReqId, String UserId, String ModuleId, Button BtnEnter, Button BtnDel)
{
string FlagMemo = "";
String GrantFlag = "";
UserLogin CurUserLogin = null;
ArrayList UserRoleList = null;
ArrayList AppRoleModFunStr = null;
if (UserId != null)
{
//根据登录用户提取角色组
CurUserLogin = new UserLogin();
CurUserLogin.LogUserId = UserId;
UserRoleList = CurUserLogin.GetUserRole();
//根据角色组提取分配的模块功能权限
AppRoleModFunStr = AppRoleModGrant.GetRoleModFunGrand(UserRoleList, ModuleId);
if (AppRoleModFunStr != null)
{
for (int i = 0; i < AppRoleModFunStr.Count; i++)
{
GrantFlag = AppRoleModFunStr[i].ToString();
AppRoleModGrant.SetShowInfo(ref FlagMemo,Flag, ReqId, GrantFlag, BtnEnter, BtnDel);
}
}
if (CurUserLogin != null) CurUserLogin = null;
if (UserRoleList != null) UserRoleList = null;
if (AppRoleModFunStr != null) AppRoleModFunStr = null;
}
if (FlagMemo != "")
{
FlagMemo = " ==>操作状态:" + FlagMemo;
}
TitleText = TitleText + FlagMemo;
return TitleText;
}
#endregion
//按钮及信息显示
private static string SetShowInfo(ref string FlagMemo, string Flag, String ReqId, string GrantFlag, Button BtnEnter, Button BtnDel)
{
//string FlagMemo = "";
if (Flag == "0")
{
if (GrantFlag == "0" && BtnEnter != null)
{
BtnEnter.Visible = true; //新增
}
if (GrantFlag == "2" && BtnDel != null)
{
BtnDel.Visible = true; //删除
}
}
else if (Flag == "1")
{
if (ReqId == null && GrantFlag == "0")
{
if (BtnEnter != null)
{
BtnEnter.Visible = true; //新增
}
FlagMemo = "新增";
}
else if (ReqId != null)
{
if (GrantFlag == "1" && BtnEnter != null)
{
BtnEnter.Visible = true; //修改
FlagMemo = "修改";
}
if (GrantFlag == "2" && BtnDel != null)
{
BtnDel.Visible = true; //删除
FlagMemo += "删除";
}
};
}
return FlagMemo;
}
}
<script language="javascript" type="text/javascript">
//全选
function selectAll(obj)
{
var theTable = obj.parentElement.parentElement.parentElement;
var i;
var j = obj.parentElement.cellIndex;
for(i=0;i<theTable.rows.length;i++)
{
var objCheckBox = theTable.rows[i].cells[j].firstChild;
if(objCheckBox.checked!=null)objCheckBox.checked = obj.checked;
}
}
function ChkBoxNotChecked(obj)
{
var theTable = obj.parentElement.parentElement.parentElement;
var i;
var j = obj.parentElement.cellIndex;
for(i=0;i<theTable.rows.length;i++)
{
var objCheckBox = theTable.rows[i].cells[j].firstChild;
if ( !objCheckBox.checked !=null)
{
var objCheckList = theTable.rows[i].cells[j].firstChild;
for (var k = 0 ; k < objCheckList.itmes.count; k ++ )
{
objCheckList.items[k].select = false;
}
}
}
}
function CheckSelected()
{
var inputsCheckPassenger = document.getElementsByName("form1");
var inputsCheck = document.getElementsByName("Checkbox1");
var isHasChecked = false;
for(var j = 0 ; j < inputsCheck.length; j++)
{
if (inputsCheck[j].checked)
{
isHasChecked = true;
break;
}
}
if (isHasChecked == false)
{
//所有的checkbox都没有选中
alert("所有的checkbox都没有选中 ");
event.returnValue = false;
return;
}
var inputsRadio = document.getElementsByName("CheckBoxList0");
var isHasCheckRadio = false;
for (var k = 0; k < inputsRadio.length; k++)
{
if (inputsRadio[k].selected)
{
isHasCheckRadio = true;
break;
}
}
if (isHasCheckRadio == false)
{
//所有的radio都没有选中
alert("所有的checkboxList都没有选中 ");
event.returnValue = false;
return;
}
}
</script>