08
2013
07

把某个层固定在网页顶部

 <!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 runat="server">
        <title>
        </title>
        <script src="js/jquery-1.7.1.min.js" type="text/javascript">
        </script>
        <script type="text/javascript">
            $(function() {
                //获取要定位元素距离浏览器顶部的距离
                var navH = $(".hb").offset().top;
                //滚动条事件
                $(window).scroll(function() {
                    //获取滚动条的滑动距离
                    var scroH = $(this).scrollTop();
                    //滚动条的滑动距离大于等于定位元素距离浏览器顶部的距离,就固定,反之就不固定
                    if (scroH >= navH) {
                        $(".hb").css({
                            "position": "fixed",
                            "top": 0
                        });
                    } else if (scroH < navH) {
                        $(".hb").css({
                            "position": "static"
                        });
                    }
                })
            })
        </script>
    </head>
    
    <body>
        <div style=" height: 300px;">
            空div
        </div>
        <div class="hb" style="height: 100px; width: 100%; background: #999">
            移动到顶部固定不变
        </div>
        <div style="background: #ccc; height: 1500px;">
            空div
        </div>
    </body>

08
2013
07

jQuery 常见操作实现方式

一个优秀的 JavaScript 框架,一篇 jQuery 常用方法及函数的文章留存备忘。

jQuery 常见操作实现方式

27
2013
06

使用百度地图Api,在地图上取两个点,并测算他们的距离

<html>    
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <style type="text/css">
            body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;}
            #l-map{height:100%;width:78%;float:left;border-right:2px solid #bcbcbc;}
            #r-result{height:100%;width:20%;float:left;}
        </style>
        <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&ak=E2e5a8af567e7bb2e3a9892e1006c505">
        </script>
        <title>
            测算两点的距离
        </title>
    </head>
    
    <body>
        <div id="allmap">
        </div>
    </body>

26
2013
06

使用百度地图Api,在地图上画圆形区域

 <html>    
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <style type="text/css">
            body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;}
            #l-map{height:100%;width:78%;float:left;border-right:2px solid #bcbcbc;}
            #r-result{height:100%;width:20%;float:left;}
        </style>
        <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&ak=E2e5a8af567e7bb2e3a9892e1006c505">
        </script>
        <title>
            圆形区域搜索
        </title>
    </head>    
    <body>
        <div id="allmap">
        </div>
    </body>

05
2013
06

asp.net 使用处理程序生成带有logo的二维码

首先建一个asp.net页面,里面包含生成所需的logo上传file控件:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="QrLogCode.aspx.cs" Inherits="AdminTest_QrLogCode" %>

<!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 id="Head1" runat="server">
    <title>二维码生成工具(带log)</title>
    <script type="text/javascript" src="../Jscript/admin/jquery-1.4.2.js"></script>
    <script src="../Jscript/admin/jquery.form.js" type="text/javascript"></script>
    <style type="text/css">
        .style1
        {
            width: 100%;
            min-width: 800px;
            text-align: left;
        }
        .txt
        {
            width: 40%;
        }
    </style>
</head>
<body>
    <form id="form1" enctype="multipart/form-data">
    <div>
        <table class="style1">
            <tr>
                <td style="text-align: right; width: 20%;">
                    输入要生成二维码的内容:
                </td>
                <td>
                    <input type="text" id="txt_qr" name="txt_qr" value="https://www.zhengdecai.com/" class="txt" />&nbsp;&nbsp;&nbsp;&nbsp;<span>请使用生成“<a
                        href="BarCode.aspx">条形码</a>”</span>
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">
                    二维码图片:
                </td>
                <td>
                    <img id="qrimg" alt="二维码图片" src="../images/20130424105224.jpg" />
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">
                    log图片:
                </td>
                <td>
                    <input type="file" id="fileLog" name="fileLog" /> 
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">
                    尺寸大小:
                </td>
                <td>
                    <input id="txt_size" name="txt_size" type="text" value="4" class="txt" />
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <div style="text-align: left; padding-left: 200px; margin-top: 50px;">
                        <input id="btnSubmit" type="button" value="生成二维码" /></div>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
<script type="text/javascript">
    $(function () {
        $("#btnSubmit").click(function () {
            /*if ($("[id$='fileLog']").val() == "") {
            alert("请选择log图片的文件!");
            return false;
            }*/
            var txt_qr = $("#txt_qr").val();
            var txt_size = $("#txt_size").val();
            $("[id$='form1']").ajaxSubmit({
                url: "../AjaxUrl/Admin/QrLogCode.ashx",
                type: "post",
                dataType: 'text',
                resetForm: "true",
                success: function (data) {
                    var dataObj = data;
                    if ($(dataObj).text() != "") {
                        $("#qrimg").attr("src", "../File/" + $(dataObj).text());
                    }
                    else {
                        $("#qrimg").attr("src", "../File/" + dataObj);
                    }
                    $("#txt_qr").val(txt_qr);
                    $("#txt_size").val(txt_size);
                },
                error: function (request, message, ex) {
                    alert("错误:" + message);
                }
            });
        });
    });
</script>

04
2013
06

Asp.Net 获取中文字符串的首字母

    string nameZM = GetFirstSpell("云南省昆明市"); //返回YNSKMS

    /// <summary>  
    /// 获取中文字符串的首字母  
    /// </summary>  
    /// <param name="strText">需要装换的中文字符串</param>  
    /// <returns>返回字母的字符串</returns>  
    public static string GetFirstSpell(string strText)
    {
        int len = strText.Length;
        string myStr = "";
        for (int i = 0; i < len; i++)
        {
            myStr += GetSpell(strText.Substring(i, 1));
        }
        return myStr;
    }
    /// <summary>  
    /// 获取单个中文的首字母  
    /// </summary>  
    /// <param name="cnChar"></param>  
    /// <returns></returns>  
    private static string GetSpell(string cnChar)
    {
        byte[] arrCN = Encoding.Default.GetBytes(cnChar);
        if (arrCN.Length > 1)
        {
            int area = (short)arrCN[0];
            int pos = (short)arrCN[1];
            int code = (area << 8) + pos;
            int[] areacode = { 45217, 45253, 45761, 46318, 46826, 47010, 47297, 47614, 48119, 48119, 49062, 49324, 49896, 50371, 50614, 50622, 50906, 51387, 51446, 52218, 52698, 52698, 52698, 52980, 53689, 54481 };
            for (int i = 0; i < 26; i++)
            {
                int max = 55290;
                if (i != 25)
                {
                    max = areacode[i + 1];
                }
                if (areacode[i] <= code && code < max)
                {
                    return Encoding.Default.GetString(new byte[] { (byte)(65 + i) });
                }
            }
            return "*";
        }
        else return cnChar;
    }  

30
2013
05

使用jquery和txt文件对Asp页面进行统计,增长数量自定义

建立asp页面,在此之前要有一个txt文件,里面存放的是统计的数值,这个当然可以随意更改,统计的值也就随之改,里面的代码如下:

<%    
response.write counter()
function counter()
whichfile=server.mappath("n.txt")
'打开文件并将其值读取,最后关闭连接释放资源
set fso=createobject("Scripting.FileSystemObject")
set openfile=fso.opentextfile(whichfile,1)
visitors=openfile.readline
openfile.close
'页面显示记数内容并做加1运算
visitors=visitors+RndNumber(1,1)
'将新的数值添加写入到文本,最后关闭所有连接释放资源
set creatfile=fso.createtextfile(whichfile)
creatfile.writeLine(visitors)
creatfile.close
set fso=nothing
counter=visitors
end function 
'自定义函数
'1-3之间的随机数
Function RndNumber(MaxNum,MinNum)
 Randomize 
 RndNumber=int((MaxNum-MinNum+1)*rnd+MinNum)
 RndNumber=RndNumber
End Function

24
2013
05

Asp.Net使用一般处理程序读写txt文档实现页面统计

一般处理程序文件代码内容:

/// <summary>

/// $codebehindclassname$ 的摘要说明

/// </summary>

public class number : IHttpHandler

{


   public void ProcessRequest(HttpContext context)

   {

23
2013
05

Asp.Net 图片流按照最大宽度等比缩放

上传图片时需要将图片进行按照宽度缩放,直接调用方法就可以上传图片

   /// <summary>
   /// 图片按宽带等比缩放
   /// </summary>
   /// <param name="fromFile">原图Stream对象</param>
   /// <param name="savePath">缩略图存放地址</param>
   /// <param name="targetWidth">指定的最大宽度</param>
   public static void ZoomAuto(System.IO.Stream fromFile, string savePath, System.Double targetWidth)
   {
       //创建目录
       string dir = Path.GetDirectoryName(savePath);
       if (!Directory.Exists(dir))
           Directory.CreateDirectory(dir);

08
2013
05

广告式弹出div层显示图片或广告内容

 代码如下:

<html xmlns="http://www.w3.org/1999/xhtml">    
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>
            郑德才弹出层测试
        </title>
    </head>    
    <body style="padding: 0px; background-color: #3399cc;">
        <div id="ads_14" style="font-family: verdana,sans-serif; width:230px; height:200px; height:0px; padding:0px; margin:0px; right:2; bottom:2; 

03
2013
05

简单使用Jquery和ashx一般处理程序实现无刷新上传文件

 使用html或aspx建立一个上传页面,再实用jquery进行图片或文件上传

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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 id="Head1" runat="server">
    <title>Porschev--Asp.Net 使用Jquery和一般处理程序实现无刷新上传大文件</title>
    <link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server" enctype="multipart/form-data">
    <div class="carea">
        <div class="ui-tabs-panel">
            <div class="search_head">
                <h3 class="sh_title">
                    Porschev--Asp.Net 使用Jquery和一般处理程序实现无刷新上传大文件</h3>
            </div>
            <ul class="info_input">
                <li><b>选择文件:</b>
                    <div class="ii_conarea">
                        <input id="fulFile" name="fulFile" type="file" class="ful" />
                        <img id="imgUploading" src="images/uploading.gif" alt="正在上传..." class="loading_img none" />
                    </div>
                </li>
            </ul>
            <input id="btnSubmit" type="button" value="上传" class="btn_sub" />
        </div>
    </div>
    </form>
</body>
</html>

03
2013
05

简单html控件与ashx处理程序进行上传文件操作

网上很多种上传图片的实例,再不使用aspx控件的时候可以使用html的input的file控件:<input id="imgfile" name="imgfile" type="file" />

使用aspx或html建立需要上传文件的页面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

28
2013
04

Server.UrlEncode与HttpUtility.UrlDecode使用

 

在对URL进行编码时,该用哪一个?这两都使用上有什么区别吗?
测试:
string file="文件上(传)篇.doc";
string Server_UrlEncode=Server.UrlEncode(file);
string Server_UrlDecode=Server.UrlDecode(Server_UrlEncode);
string HttpUtility_UrlEncode=System.Web.HttpUtility.UrlEncode(file);
string HttpUtility_UrlDecode=System.Web.HttpUtility.UrlDecode(HttpUtility_UrlEncode);
Response.Write("原数据:"+file);
SFun.WriteLine("Server.UrlEncode:"+Server_UrlEncode);
SFun.WriteLine("Server.UrlDecode:"+Server_UrlDecode);
SFun.WriteLine("HttpUtility.UrlEncode:"+HttpUtility_UrlEncode);
SFun.WriteLine("HttpUtility.UrlDecode:"+HttpUtility_UrlDecode);

输出:
原数据:文件上(传)篇.doc 
Server.UrlEncode:%ce%c4%bc%fe%c9%cf%a3%a8%b4%ab%a3%a9%c6%aa.doc
Server.UrlDecode:文件上(传)篇.doc
HttpUtility.UrlEncode:%e6%96%87%e4%bb%b6%e4%b8%8a%ef%bc%88%e4%bc%a0%ef%bc%89%e7%af%87.doc
HttpUtility.UrlDecode:文件上(传)篇.doc

区别在于:HttpUtility.UrlEncode()默认是以UTF8对URL进行编码,而Server.UrlEncode()则以默认的编码对URL进行编码。

在用 ASP.Net 开发页面的时候, 我们常常通过 System.Web.HttpUtility.UrlEncode 和 UrlDecode 在页面间通过 URL 传递参数. 成对的使用 Encode 和 Decode 是没有问题的.

但是, 我们在编写文件下载的页面的时候, 常常用如下方法来指定下载的文件的名称:
Response.AddHeader("Content-Disposition","attachment; filename="
+ HttpUtility.UrlEncode(fileName, Encoding.UTF8));
之所以转换成 UTF8 是为了支持中文文件名.

这 时候问题就来了, 因为 HttpUtility.UrlEncode 在 Encode 的时候, 将空格转换成加号('+'), 在 Decode 的时候将加号转为空格, 但是浏览器是不能理解加号为空格的, 所以如果文件名包含了空格, 在浏览器下载得到的文件, 空格就变成了加号.

一个解决办法是, 在 HttpUtility 的 UrlEncode 之后, 将 "+" 替换成 "%20"( 如果原来是 "+" 则被转换成 "%2b" ) , 如: 
fileName = HttpUtility.UrlEncode(fileName, Encoding.UTF8); 
fileName = fileName.Replace("+", "%20"); 
不明白微软为什么要把空格转换成加号而不是"%20". 记得 JDK 的 UrlEncoder 是将空格转换成 "%20"的.
经检查, 在 .Net 2.0 也是这样.
  默认aspx是以utf-8为编码的,程序中必须用gb2312为默认编码(<globalization requestEncoding="gb2312" responseEncoding="gb2312"/>),问题出现了,以前没有问题的HttpUtility.UrlDecode在Page.Request回的值是乱码这就是上面说的HttpUtility.UrlDecode默认以UTF8对URL进行编码,这种情况下面只需将HttpUtility.UrlDecode改成Server.UrlEncode即可。

25
2013
04

asp.net 使用处理程序生成二维码

效果图:image

首先下载ThoughtWorks.QRCode.dll 

22
2013
04

Asp.Net生成条形码实例,通过测试

 已经有网友制作出来,没有实际的调用,调试已经通过

    Code128 code128 = new Code128();
    context.Response.Clear();

    MemoryStream ms = new MemoryStream();
    Bitmap bmp = code128.GetCodeImage("https://www.zhengdecai.com/", Code128.Encode.Code128B); //生成字符串的“123456”的条形码图片
    bmp.Save(ms, ImageFormat.Png);
    context.Response.BinaryWrite(ms.ToArray());

11
2013
04

C# 读取网页所有源代码,存成字符串

        //第一个为读取网页或某个网页文件

        public static string WriteFile(string FilePath)
        {
            Encoding code = Encoding.GetEncoding("gb2312");
            //读取html和其他文件
            string temp = HttpContext.Current.Server.MapPath(FilePath);
            StreamReader sr = null;
            StreamWriter sw = null;
            string str = "";
            try
            {
                sr = new StreamReader(temp, code);
                str = sr.ReadToEnd(); // 读取文件   
            }
            catch (Exception exp)
            {
                sr.Close();
            }
            return str;
        }

09
2013
04

百度地图给定两个经纬度坐标测算出他们之间的直线距离

 <html>    
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <style type="text/css">
            body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;}
            #l-map{height:100%;width:78%;float:left;border-right:2px solid #bcbcbc;}
            #r-result{height:100%;width:20%;float:left;}
        </style>
        <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.2"> //百度地图引用工具
        </script>
        <script type="text/javascript" src="http://api.map.baidu.com/library/DistanceTool/1.2/src/DistanceTool_min.js"> //地图测算工具引用
        </script>
        <script type="text/javascript" src="js/jquery-1.5.1.min.js"> //引用js的jquery文件
        </script>
        <title>
            鼠标测距
        </title>
    </head>
    
    <body>
        <div id="allmap" style="width:800px;"> //显示地图的div层
        </div>
    </body>

30
2013
03

C# 判断远程图片和文件是否存在

 /// <summary>
/// 判断远程图片是否存在
/// </summary>
/// <param name="curl">远程图片地址</param>
/// <returns></returns>
private int GetUrlError(string curl)
{
    int num = 200;
    if (this.method == 1)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(curl));
        ServicePointManager.Expect100Continue = false;
        try
        {
            ((HttpWebResponse)request.GetResponse()).Close();
        }

25
2013
03

Asp.Net中常用的数据验证类

   /// <summary>

   /// 数据验证类

   /// </summary>

   public class PageValidate

20
2013
03

C#中年月填充到ComboBox中的方法

/// <summary>

/// 年月填充到ComboBox中的方法

/// </summary>

private void FillYearMonth()

{

   int minYear = 2012;  //最小年份

   int maxYear = DateTime.Now.Year;  //当前年份