Asp.Net

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>   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C语言是一种广泛使用的编程语言,它具有高效、灵活、可移植性强等特点,被广泛应用于操作系统、嵌入式系统、数据库、编译器等领域的开发。C语言的基本语法包括变量、数据类型、运算符、控制结构(如if语句、循环语句等)、函数、指针等。在编写C程序时,需要注意变量的声明和定义、指针的使用、内存的分配与释放等问题。C语言中常用的数据结构包括: 1. 数组:一种存储同类型数据的结构,可以进行索引访问和修改。 2. 链表:一种存储不同类型数据的结构,每个节点包含数据和指向下一个节点的指针。 3. 栈:一种后进先出(LIFO)的数据结构,可以通过压入(push)和弹出(pop)操作进行数据的存储和取出。 4. 队列:一种先进先出(FIFO)的数据结构,可以通过入队(enqueue)和出队(dequeue)操作进行数据的存储和取出。 5. 树:一种存储具有父子关系的数据结构,可以通过中序遍历、前序遍历和后序遍历等方式进行数据的访问和修改。 6. 图:一种存储具有节点和边关系的数据结构,可以通过广度优先搜索、深度优先搜索等方式进行数据的访问和修改。 这些数据结构在C语言中都有相应的实现方式,可以应用于各种不同的场景。C语言中的各种数据结构都有其优缺点,下面列举一些常见的数据结构的优缺点: 数组: 优点:访问和修改元素的速度非常快,适用于需要频繁读取和修改数据的场合。 缺点:数组的长度是固定的,不适合存储大小不固定的动态数据,另外数组在内存中是连续分配的,当数组较大时可能会导致内存碎片化。 链表: 优点:可以方便地插入和删除元素,适用于需要频繁插入和删除数据的场合。 缺点:访问和修改元素的速度相对较慢,因为需要遍历链表找到指定的节点。 栈: 优点:后进先出(LIFO)的特性使得栈在处理递归和括号匹配等问题时非常方便。 缺点:栈的空间有限,当数据量较大时可能会导致栈溢出。 队列: 优点:先进先出(FIFO)的特性使得
该资源内项目源码是个人的课程设计、毕业设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 该资源内项目源码是个人的课程设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。
该资源内项目源码是个人的课程设计、毕业设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 该资源内项目源码是个人的课程设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值