读取数据库中数据,在页面上直接显示图片(点击该图片变大)

来源:互联网 发布:打谱软件哪个好索呢 编辑:程序博客网 时间:2024/04/30 09:23

1.js根据ID查找该图片表

function bindControlColumn(value) {
    var s = value.split(",");


    if (s[0] == s[1]) {


        var imghtml = "<div style='margin: 2px; border:1px solid #cccccc; padding: 2px; width: 30px; height:40px; float: left;'>";
        //        var fjsm = selData[i].fjsm;


        imghtml = imghtml + "<img onclick='ViewUserInfo(" + s[0] + ")' title='点击可以查看大图' alt='点击可以查看大图' src='../../Page/Dialog/MQC_GetImage.aspx?id=" + s[0] + "&operType=fj' style='max-width:30px;max-height: 40px; _margin-top: expression_r(40 - this.height);' />";
        imghtml = imghtml + "</div><div style='word-break: break-all; width: 30px;'>";
        imghtml = imghtml + "</div>";


    } else {
        var imghtml = "<div>"
        for (var i = 0; i < s.length; i++) {
            imghtml = imghtml + "<div style='margin: 2px; border:1px solid #cccccc; padding: 2px; width: 30px; height:40px; float: left;'>";
            imghtml = imghtml + "<img onclick='ViewUserInfo(" + s[i] + ")' title='点击可以查看大图' alt='点击可以查看大图' src='../../Page/Dialog/MQC_GetImage.aspx?id=" + s[i] + "&operType=fj' style='max-width:30px;max-height: 40px; _margin-top: expression_r(40 - this.height);' />";
            imghtml = imghtml + "</div><div style='word-break: break-all; width: 30px;'>";
            imghtml = imghtml + "</div>";
        }
        imghtml = imghtml + "</div>";


    }
    return imghtml.toString();
}

2.ViewUserInfo方法

//查看 
function ViewUserInfo(id) {
    var url = "Page/Dialog/ImageView.aspx?id=" + id + "&operType=fj&ran=" + Math.random();
    topWindow.LayerAPI.OpenPopupPage("查看图片附件(下载图片,请在图片上右键 - 图片另存为)", url, "1024", "700", function () { }, 1);
}


3.ImageView.aspx页面

 <form id="form1" runat="server">
    <div style="overflow:auto; width:990px; text-align:center;" >
    <center>
    <% 
        
        string id = Request["id"];
        string url = "MQC_GetImage.aspx?id=" + id + "&operType=fj";
         %>
    <img src='<%=url %>' style="width:980px; " alt="" /></center></div>
    </form>

4.MQC_GetImage.aspx页面

MQC_Experts mqc_experts = new MQC_Experts();
        MQC_ProjectAnswer pro = new MQC_ProjectAnswer();
        protected void Page_Load(object sender, EventArgs e)
        {
            object dataTable_zp = null;
            string DefaultImage = string.Empty;
            if (!string.IsNullOrEmpty(Request["operType"]))
            {
                if (Request["operType"] == "fj")
                {
                    string id = Request.Params["id"];


                    ResultMessage rsg = pro.GetMQC_AnswerAttachment(id);// BasicDataInfo.GetReviewLevelInfo(code);//rmcAddConsult.GetSlaveInfo(code, CurrenLangType);
                    DataTable dt = rsg.MessageDataTable;
                    string zkzxname = dt.Rows[0]["zkzxname"].ToString();
                    string dxmname = dt.Rows[0]["dxmname"].ToString();
                    string wjm = dt.Rows[0]["wjm"].ToString();
                    string kzm = dt.Rows[0]["kzm"].ToString();
                    DefaultImage = @"..\..\Images\nothing.jpg";
                    if (dt.Rows.Count > 0)
                    {
                        DefaultImage = "../../MQC_UPLOAD/" + zkzxname + "/" + dxmname + "/" + wjm + kzm;
                    }
                    dataTable_zp = null;// dt.Rows[0]["fj"];
                }
            }
            else
            {
                string SerialNO = Request.Params["ID"] == null ? "" : Request.Params["ID"].ToString();
                string operType = Request.Params["operType"] == null ? "" : Request.Params["operType"].ToString();
                ResultMessage rsg = mqc_experts.GetExpertsByID(SerialNO);// BasicDataInfo.GetReviewLevelInfo(code);//rmcAddConsult.GetSlaveInfo(code, CurrenLangType);
                DataTable dt = rsg.MessageDataTable;
                dataTable_zp = dt.Rows[0]["zp"];
                DefaultImage = @"..\..\Images\nothing.jpg";
            }


            if (dataTable_zp != DBNull.Value && dataTable_zp != null)
            {
                byte[] zp = (Byte[])dataTable_zp;
                Response.BinaryWrite(zp);
                Response.End();
            }
            else
            {
                if (File.Exists(Server.MapPath(DefaultImage)))
                {
                    string path = Server.MapPath(DefaultImage);
                    System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                    byte[] bArr = new byte[fs.Length];
                    fs.Read(bArr, 0, bArr.Length);
                    fs.Close();
                    Response.BinaryWrite(bArr);
                    Response.End();
                }
            }
        }




0 0
原创粉丝点击