using System;using System.Text;using System.Drawing;using ThoughtWorks.QRCode.Codec;using ThoughtWorks.QRCode.Codec.Data;using Winsteps.Validator;public partial class Build : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //客户端弹出验证消息框 WinVal WinValInstance = new WinVal(); WinValInstance.ValStyle = "toppoptip"; WinValInstance.SetValidator(); } } /// <summary> /// 生成二维码 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnBuild_Click(object sender, EventArgs e) { string con = PageOperate.GetNullToString(txtCon.Text.Trim()); if (con == "") { PageOperate.AlertAndRedirect("请填写内容", "Build.aspx"); return; } ImgCode.ImageUrl = "Handler.ashx?data=" Server.HtmlEncode(con) "&len=4"; } /// <summary> /// 上传二维码图 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUpload_Click(object sender, EventArgs e) { try { string fileName = PageOperate.GetNullToString(fileUp.FileName.Trim()); if (fileName == "") { PageOperate.AlertAndRedirect("请选择二维码图", "Build.aspx"); return; } string ext = fileName.Substring(fileName.LastIndexOf(".")).ToLower(); ViewState["name"] = DateTime.Now.ToString("yyyyMMddHHmmss") ext; if (ext.Contains("jpg") || ext.Contains("gif") || ext.Contains("png") || ext.Contains("bmp")) { string dirName = Server.MapPath("~/FileUpload/") ViewState["name"].ToString(); fileUp.SaveAs(dirName); this.ImgUpCode.ImageUrl = "~/FileUpload/" ViewState["name"].ToString(); } else PageOperate.AlertAndRedirect("二维码图片格式不正确", "Build.aspx"); } catch { PageOperate.AlertAndRedirect("上传出现异常!", "Build.aspx"); return; } } /// <summary> /// 解析二维码图 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAnalyse_Click(object sender, EventArgs e) { if (PageOperate.GetNullToString(ViewState["name"]) != "") { try { QRCodeDecoder qrc = new QRCodeDecoder(); string fileName = Server.MapPath("~/FileUpload/") PageOperate.GetNullToString(ViewState["name"]); string qrcStr = qrc.decode(new QRCodeBitmapImage(new Bitmap(fileName)), Encoding.UTF8); this.lblCon.Text = qrcStr; } catch { PageOperate.AlertAndRedirect("解析出现异常!", "Build.aspx"); return; } } else { PageOperate.AlertAndRedirect("请上传二维码图!", "Build.aspx"); return; } }}
评论