码迷,mamicode.com
首页 > Windows程序 > 详细

C#条形码生成(五)----Web下的测试

时间:2015-01-22 06:55:30      阅读:317      评论:0      收藏:0      [点我收藏+]

标签:

Html部分

  1. <html xmlns="http://www.w3.org/1999/xhtml" >  
  2. <head runat="server">  
  3.     <title>无标题页</title>  
  4.     <script type="text/javascript" language="javascript" src="JS/1.5/jquery-1.5.js"></script>  
  5.     <script type="text/javascript" language="javascript">  
  6.         $(document).ready(function() {  
  7.             $("#barButton").click(function() {  
  8.                 var raw = $.trim($("#rawData").val());  
  9.                 $("#imgCode").attr("src", "Code128Handler.ashx?raw=" + raw + "&type=" + $("#se").val() + "&cw=" + $("#sw").val()  
  10.                     + "&hm=" + $("#hm").val() + "&vm=" + $("#vm").val() + "&sb=" + $("#cbblank").attr("checked") + "&fc=" + $("#cbfont").attr("checked")  
  11.                     + "&fs=" + $("#fs").val() + "&sf=" + $("#sf").get(0).selectedIndex  
  12.                     );  
  13.             });  
  14.         });  
  15.     </script>  
  16. </head>  
  17. <body>  
  18.     <form id="form1" runat="server">  
  19.     <div>  
  20.     原始码:  
  21.     <input type="text" id="rawData" maxlength="48" value="135703209730" />  
  22.     <br />  
  23.     编码选择:<select id="se"><option>Auto</option><option>A</option><option>B</option><option>C</option><option>GS1-128</option></select></div>  
  24.     模块宽度(Pix):<select id="sw"><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option></select>  
  25.     <br />  
  26.     水平空白倍率:<input type="text" id="hm" value="10" />垂直空白倍率<input type="text" id="vm" value="8" />  
  27.     <input type="checkbox" id="cbblank" checked="checked" />空白显示  
  28.     <br />  
  29.     字体大小:<input type="text" id="fs" value="16" />字体布局:<select id="sf"><option>Near</option><option selected="selected">Center</option><option>Far</option></select><input checked="checked" type="checkbox" id="cbfont" />字体显示  
  30.     <div>  
  31.     <input type="button" id="barButton" value="生成条形码" /></div>  
  32.     <div style="text-align:center; ">  
  33.     <img id="imgCode" alt="条形码" />  
  34.     </div>  
  35.     </form>  
  36. </body>  
  37. </html>  
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
    <script type="text/javascript" language="javascript" src="JS/1.5/jquery-1.5.js"></script>
    <script type="text/javascript" language="javascript">
        $(document).ready(function() {
            $("#barButton").click(function() {
                var raw = $.trim($("#rawData").val());
                $("#imgCode").attr("src", "Code128Handler.ashx?raw=" + raw + "&type=" + $("#se").val() + "&cw=" + $("#sw").val()
                    + "&hm=" + $("#hm").val() + "&vm=" + $("#vm").val() + "&sb=" + $("#cbblank").attr("checked") + "&fc=" + $("#cbfont").attr("checked")
                    + "&fs=" + $("#fs").val() + "&sf=" + $("#sf").get(0).selectedIndex
                    );
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    原始码:
    <input type="text" id="rawData" maxlength="48" value="135703209730" />
    <br />
    编码选择:<select id="se"><option>Auto</option><option>A</option><option>B</option><option>C</option><option>GS1-128</option></select></div>
    模块宽度(Pix):<select id="sw"><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option></select>
    <br />
    水平空白倍率:<input type="text" id="hm" value="10" />垂直空白倍率<input type="text" id="vm" value="8" />
    <input type="checkbox" id="cbblank" checked="checked" />空白显示
    <br />
    字体大小:<input type="text" id="fs" value="16" />字体布局:<select id="sf"><option>Near</option><option selected="selected">Center</option><option>Far</option></select><input checked="checked" type="checkbox" id="cbfont" />字体显示
    <div>
    <input type="button" id="barButton" value="生成条形码" /></div>
    <div style="text-align:center; ">
    <img id="imgCode" alt="条形码" />
    </div>
    </form>
</body>
</html>

 Code128Handler部分

  1. public void ProcessRequest(HttpContext context)  
  2.         {  
  3.             HttpRequest Request = context.Request;  
  4.             HttpResponse Response = context.Response;  
  5.             Response.ClearContent();  
  6.             Response.ContentType = "image/jpeg";  
  7.   
  8.             string barType = Request.QueryString["type"];  
  9.             string rawData = string.IsNullOrEmpty(Request.QueryString["raw"]) ? ((char)20).ToString() + @"123a" + ((char)18).ToString() + "ab" : Request.QueryString["raw"];  
  10.             if(string.IsNullOrEmpty(barType))  
  11.             {  
  12.                 barType="C";  
  13.             }  
  14.             int cw = string.IsNullOrEmpty(Request.QueryString["cw"]) ? 1 : byte.Parse(Request.QueryString["cw"]);  
  15.             int hm = string.IsNullOrEmpty(Request.QueryString["hm"]) ? 1 : byte.Parse(Request.QueryString["hm"]);  
  16.             int vm = string.IsNullOrEmpty(Request.QueryString["vm"]) ? 1 : byte.Parse(Request.QueryString["vm"]);  
  17.             bool showblank = string.IsNullOrEmpty(Request.QueryString["sb"]) ? true : bool.Parse(Request.QueryString["sb"]);  
  18.             bool showfont = string.IsNullOrEmpty(Request.QueryString["fc"]) ? true : bool.Parse(Request.QueryString["fc"]);  
  19.             int emSize = string.IsNullOrEmpty(Request.QueryString["fs"]) ? 16 : int.Parse(Request.QueryString["fs"]);  
  20.             int textA = string.IsNullOrEmpty(Request.QueryString["sf"]) ? 1 : int.Parse(Request.QueryString["sf"]);  
  21.             absCode128 code128;  
  22.             switch(barType)  
  23.             {  
  24.                 case "Auto":  
  25.                     code128 = new Code128Auto(rawData);  
  26.                     break;  
  27.                 case "A":  
  28.                     code128 = new Code128A(rawData);  
  29.                     break;  
  30.                 case "B":  
  31.                     code128=new Code128B(rawData);  
  32.                     break;  
  33.                 case "C":  
  34.                     code128 = new Code128C(rawData);  
  35.                     break;  
  36.                 default:  
  37.                     code128 = new GS1_128(rawData);  
  38.                     break;  
  39.             }  
  40.   
  41.             code128.BarCellWidth = (byte)cw;  
  42.             code128.HorizontalMulriple = (byte)hm;  
  43.             code128.VerticalMulriple = (byte)vm;  
  44.             code128.ShowBlank = showblank;  
  45.             code128.DataDisplay = showfont;  
  46.             code128.FontSize = emSize;  
  47.             code128.TextAlignment = (System.Drawing.StringAlignment)textA;  
  48.   
  49.             System.Drawing.Image img = code128.GetBarCodeImage();  
  50.             img.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);  
  51.   
  52.             img.Dispose();  
  53.         }  

C#条形码生成(五)----Web下的测试

标签:

原文地址:http://www.cnblogs.com/qqhfeng/p/4240598.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!