/*-----------------------------------------
 *开 发 者:  awp
 *创建日期:   2009-6-25 星期4
 *功能描述:   防止页面重复提交
 *
 * 用法服务器控件的
 *  <form id="form1" runat="server">
    <input type="text" id="tbxName" runat="server" />
    <input type="text" id="tbxPass" value="" runat="server" />
    <asp:Button ID="btnSubmit" runat="server" OnClick="Button1_Click" Text="Button" />
    <asp:Label ID="lblMessage" runat="server" Text=""></asp:Label>
    <input id="hiddenTest" type="hidden" value="<%=AvoidRefurbish.GetToken() %>" name="hiddenTestN" />
    </form>
 * 后台代码
 * 
 *  protected void Page_Load(object sender, EventArgs e)
    {
        AvoidRefurbish.FirstRefurbish();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (AvoidRefurbish.IfOnRefurbish())
        {
            Response.Write("true");
        }
        else
        {
            Response.Write("false");
        }
    }
 * 
 * 
 * 
 * html控件
 * 
 *   <form id="form1" action="?cmd=add" method="post">
    <input type="text" id="tbxName" runat="server" />
    <input type="text" id="tbxPass" value="" runat="server" />
    <input id="Submit1" type="submit" value="submit" />
    <input id="hiddenTest" type="hidden" value="<%=AvoidRefurbish.GetToken() %>" name="hiddenTestN" />
    </form>
 * 
 *  protected void Page_Load(object sender, EventArgs e)
    {
     AvoidRefurbish.FirstRefurbish();

        if (Request.QueryString["cmd"] != null)
        {
            if (Request.QueryString["cmd"].ToString() == "add")
            {

                if (AvoidRefurbish.IfOnRefurbish())
                {
                    Response.Write("true");
                }
                else
                {
                    Response.Write("false");
                }
            }
        }
    }
 * 
 * 
 * 
 *-----------------------------------------
*/
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Security.Cryptography;
using System.Text;

/// <summary>
///AvoidRefurbish 的摘要说明
/// </summary>
public class AvoidRefurbish
{
    
/// <summary>
    
/// 判断是否正常提交
    
/// </summary>
    
/// <returns></returns>
    public static bool IfOnRefurbish()
    {
        
if (HttpContext.Current.Request.Form.Get("hiddenTestN").Equals(GetToken()))
        {
            SetToken();
            
return true;
        }
        
return false;
    }

    
/// <summary>
    
/// 第一次进入页面
    
/// </summary>
    public static void FirstRefurbish()
    {
        
//第一次载入的时候,生成一个初始的标志 
        if (null == HttpContext.Current.Session["Token"])
        {
            SetToken();
        }
    }

    
/// <summary>
    
/// 获得当前Session里保存的标志 
    
/// </summary>
    
/// <returns></returns>
    public static string GetToken()
    {
        
if (null != HttpContext.Current.Session["Token"])
        {
            
return HttpContext.Current.Session["Token"].ToString();
        }
        
else
        {
            
return string.Empty;
        }
    }


    
//生成标志,并保存到Session 
    private static void SetToken()
    {
        HttpContext.Current.Session.Add(
"Token", UserMd5(HttpContext.Current.Session.SessionID + DateTime.Now.Ticks.ToString()));
    }


    
//这个函数纯粹是为了让标志稍微短点儿,一堆乱码还特有神秘感,另外,这个UserMd5函数是网上找来的现成儿的 
    private static string UserMd5(string str1)
    {
        
string cl1 = str1;
        
string pwd = "";
        MD5 md5 
= MD5.Create();
        
// 加密后是一个字节类型的数组 
        byte[] s = md5.ComputeHash(Encoding.Unicode.GetBytes(cl1));
        
// 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得 
        for (int i = 0; i < s.Length; i++)
        {
            
// 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符 
            pwd = pwd + s[i].ToString("X");
        }
        
return pwd;
    }
}
posted @ 2009-07-09 14:03 awp110 阅读(79) 评论(0) 编辑
    /// <summary>
        
///  编辑关联分类 的属性 添加新值删除去掉的值
        
/// </summary>
        
/// <param name="IListNew">最新的分类信息</param>
        
/// <returns>是否更新成功</returns>
        public bool Update(IList<CategoryAttributeInfo> IListNew, int categoryID)
        {
            IList
<CategoryAttributeInfo> IListOld = new List<CategoryAttributeInfo>();//取出数据库里的分类
            IList<CategoryAttributeInfo> IListDel = new List<CategoryAttributeInfo>();//待删除的
            IList<CategoryAttributeInfo> IListAdd = new List<CategoryAttributeInfo>();//待添加的

            IListOld 
= GetCategoryAttributeInfoList("CategoryID=" + categoryID, "");


            
//对比取出 那些该删除 那些该添加
            foreach (CategoryAttributeInfo iListOld in IListOld)
            {
                
if (IListNew.Contains(iListOld))
                {
                    IListNew.Remove(iListOld);
                }
                
else
                {
                    IListDel.Add(iListOld);
                }

            }
            IListAdd 
= IListNew;

            
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction())
            {
                
try
                {
                    
foreach (CategoryAttributeInfo CategoryAttributeInfo in IListDel)
                    {
                        SqlHelper.ExecuteNonQuery(sqlTran, 
"delete  from t_CategoryAttribute where ID=" + CategoryAttributeInfo.ID, null);
                    }

                    
//添加新增的 分类属性
                    foreach (CategoryAttributeInfo CategoryAttributeInfo in IListAdd)
                    {
                        Add(CategoryAttributeInfo);
                    }

                    sqlTran.Commit();
                    
return true;

                }
                
catch
                {
                    sqlTran.Rollback();
                    
return false;
                }
            }

        }
posted @ 2009-07-09 14:02 awp110 阅读(19) 评论(0) 编辑

首先将需要权限控制的菜单添加打菜单管理中!

 

在角色管理中将 该角色拥有的菜单打上钩

 

在页面中读取即可

 

可以将权限位防止一张表里如这种型式(一对多)

主建  角色id  权限位

       1         1    

       1          2

还可以(1对1)将角色全部防止同一个字段中 如果该位为1 表明他拥有该位的权限 0表明没

第几位是根据添加的菜单主键id来确认的(自增)

主建  角色id  权限位

       1         101010101    

 

   /// <summary>
        
/// 增加权限串
        
/// 比如:原始权限串为101011101,现在需要将 110110110 增加进去
        
/// </summary>
        
/// <returns>返回更新后的权限串</returns>
        public static string AddPowerStr(string powerids, string powerids2)
        {
            
if (string.IsNullOrEmpty(powerids2))
                
return powerids;

            
const int splitLen = 63;                  //Int64.MaxValue 转成二进制字符串的长度            
            int len1 = powerids.Length;
            
int len2 = powerids2.Length;

            
//确保两个权限长度一样
            if (len1 < len2)
            {
                powerids 
= powerids.PadRight(len2, '0');
            }
            
else if (len1 > len2)
            {
                powerids2 
= powerids2.PadRight(len1, '0');
            }

            
//将权限串按splitLen位长度分隔
            IDictionary<intstring> p1 = new Dictionary<intstring>();
            IDictionary
<intstring> p2 = new Dictionary<intstring>();
            
int i = 0;
            
while (powerids.Length > splitLen)
            {              
//将权限串按63位长度分隔
                p1.Add(i, powerids.Substring(0, splitLen));
                p2.Add(i, powerids2.Substring(
0, splitLen));
                powerids 
= powerids.Substring(splitLen);
                powerids2 
= powerids2.Substring(splitLen);
                i
++;
            }
            p1.Add(i, powerids);
            p2.Add(i, powerids2);

            
//位运算进行对比,添加权限
            string newpowerstr = string.Empty;
            
int count = p1.Count;
            
for (i = 0; i < count; i++)
            {
                newpowerstr 
+= Convert.ToString(Convert.ToInt64(p1[i], 2| Convert.ToInt64(p2[i], 2), 2);      //转换成2进制 进行或运算
            }

            
return newpowerstr;
        }

 

 

        /// <summary>
        /// 检查是否拥有某项权限
        /// </summary>
        /// <param name="powerids">用户权限串</param>
        /// <param name="powerid">检测权限位</param>
        /// <returns>是否有权限:true-有权限,false-没权限</returns>
        public static bool CheckPower(string powerids, int powerid)
        {
            //如果检查权限位大于权限串长度,则说明没有权限
            if (powerids.Length < powerid || powerid < 1)
                return false;
            return powerids[powerid - 1].Equals('1');
        }

 

在页面中通过 CheckPower判断该权限位是否存在 存在则显示不存在则该菜单不显示

<%if(!page.CheckPower(1)){ %>
<p class="menu_t" onclick="menu0(1)">
    <strong class="menu_ts"><a href="news_admin.html">资讯管理</a></strong><span class="arrow"><img
        id="img_01" src="images/arrow_02.gif" title="收起" alt="收起" /></span></p>
<div id="info001">
    <ul class="menu_c">
        <li><a href="#"><em>&middot;</em>站内信列表</a></li>
        <li><a href="#"><em>&middot;</em>系统提醒邮件</a></li>
        <li><a href="#"><em>&middot;</em>群发邮件</a></li>
    </ul>
</div>
<%} %>

 

posted @ 2009-07-09 13:28 awp110 阅读(169) 评论(0) 编辑
最近写一些东西需要提供网页打印功能,所以归纳总结了一下,本节主要讲述使用IE6支持打印功能,不同浏览器安全设置与支持有差异,如果不支持,请使用您的浏览器自带打印功能(或手动设置启用ActiveX控件)。书写有不足或描述不清的地方请大家指正。^-^

利用CSS样式打印是经常使用的一种打印方法,利用它可以非常方便的实现打印页面中的指定内容和分页打印,下面将通过具体实例介绍如何利用CSS样式打印。

[分析]:
1.打印样式区分:打印网页带页面样式,需指明一个media='print'的样式,建议分开,如下创建军一个bankprint.css打印样式文件。
<link rel="stylesheet" media="screen" type="text/css" href="/public/default/css/bank.css" />
<!-- 打印样式 -->
<link rel="stylesheet" media="print" type="text/css" href="/public/default/css/bankprint.css" />
例:
<style media=‘print’>

.Noprint {display:none;}

.PageBreak {page-break-after: always;}

</style>
说明:
media类型是CSS属性媒体类型,用于直接引入媒体的属性。其语法格式如下:
@media screen | print | projection | braille | aural | tv | handheld | all
参数说明
  screen:指计算机屏幕。
  print:指用于打印机的不透明介质。
  projection:指用于显示的项目。
  braille:盲文系统,指有触觉效果的印刷品。
  aural:指语音电子合成器。
  tv:电视类型的媒体。
  handheld:指手持式显示设备。
  all:用于所有媒体。
2.WebBrowser控件
同其他控件一样,首先我们需要在页面中嵌入WebBrowser控件,不过由于该控件是IE浏览器自带的,支持浏览器默认安全设置,因此避免了安全性设置的麻烦。对于IE7及以上安全性要求更高的浏览器,您或许还是需要自定义IE的安全性级别。
<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" id="wb" width="0" height="0"></OBJECT>
下面就是该控件涉及打印的功能调用,用户可以在JavaScrip中调用:
wb.execwb(6,1); //打印,打印当前页面
wb.execwb(7,1); //打印预览
wb.execwb(8,1); //打印设置,调出系统打印设置对话框

3.页眉、页脚设置:打印时,有的需要去掉页眉页脚,或替换成自已想要的。
<script language="JavaScript">
    var hkey_root,hkey_path,hkey_key;
    hkey_root="HKEY_CURRENT_USER";
    hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
    //配置网页打印的页眉页脚为空
    function pagesetup_null(){   
        try{
            var RegWsh = new ActiveXObject("WScript.Shell");           
            hkey_key="header";           
            RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"");
            hkey_key="footer";
            RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"");
            //&b 第&p页/共&P页 &b
        }catch(e){}
    }
    //配置网页打印的页眉页脚为默认值
    function pagesetup_default(){
        try{
            var RegWsh = new ActiveXObject("WScript.Shell");
            hkey_key="header";
            RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&w&b页码,&p/&P")
            hkey_key="footer";
            RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&u&b&d");
        }catch(e){}
    }
...
</script>

[源码例子]:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>打印设置</title>
<link rel="stylesheet" media="screen" type="text/css" href="http://www.chinasvf.com/Webs/public/default/css/bank.css" />
<!-- 打印样式 -->
<link rel="stylesheet" media="print" type="text/css" href="http://www.chinasvf.com/Webs/public/default/css/bankprint.css" />
<script language="JavaScript">
    var hkey_root,hkey_path,hkey_key;
    hkey_root="HKEY_CURRENT_USER";
    hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
    //配置网页打印的页眉页脚为空
    function pagesetup_null(){   
        try{
            var RegWsh = new ActiveXObject("WScript.Shell");           
            hkey_key="header";           
            RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"");
            hkey_key="footer";
            RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"");
            //&b 第&p页/共&P页 &b
        }catch(e){}
    }
    //配置网页打印的页眉页脚为默认值
    function pagesetup_default(){
        try{
            var RegWsh = new ActiveXObject("WScript.Shell");
            hkey_key="header";
            RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&w&b页码,&p/&P")
            hkey_key="footer";
            RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&u&b&d");
        }catch(e){}
     
     //打印选区内容
    function doPrint() {
        pagesetup_null();
        bdhtml=window.document.body.innerHTML; 
        sprnstr="<!--startprint-->"; 
        eprnstr="<!--endprint-->"; 
        prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17); 
        prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr)); 
        window.document.body.innerHTML=prnhtml; 
        window.print(); 
    }
    //打印页面预览
    function printpreview(){
        pagesetup_null();
        //wb.printing.header = "居左显示&b居中显示&b居右显示页码,第&p页/共&P页";
        //wb.printing.footer = "居左显示&b居中显示&b居右显示页码,第&p页/共&P页";
        try{
            wb.execwb(7,1);
        }catch(e){
            alert("您的浏览器不支持此功能,请选择'文件'->'打印预览'");
        }
    }
    //打印
    function prints(){
        pagesetup_null();
        //wb.printing.header = "居左显示&b居中显示&b居右显示页码,第&p页/共&P页";
        //wb.printing.footer = "居左显示&b居中显示&b居右显示页码,第&p页/共&P页";
        try{
            wb.execwb(6,1);
        }catch(e){
            alert("您的浏览器不支持此功能");
        }
    }
</script>
</head>
<body>
<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" id="wb" width="0" height="0"></OBJECT>
<div id="bankwrap">
  <div class="Noprint"><a href="http://www.chinasvf.com" style="cursor:pointer; color:#0000FF">返回首页</a></div>
  <div style="text-align:right">
    <p class="Noprint">
        <span style="cursor:pointer; color:#0000FF" onclick="javascript:window.open('http://www.chinasvf.com/Webs/Share/printhelp')" class="Noprint">打印帮助</span>
        <span style="cursor:pointer; color:#0000FF" onclick="printpreview();">打印预览</span>
        <span style="cursor:pointer; color:#0000FF" onclick="prints();" class="Noprint">打印</span>
    </p>
  </div>
  <div class="banktitle">内容</div>
</div>
</body>
</html>
posted @ 2009-07-09 10:33 awp110 阅读(986) 评论(0) 编辑