Ejemplo n.º 1
0
        //string corpadminid = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            CorpAdminBLL.CheckSession(Session, Request, Response);
            corpid = Functions.ParseStr(Session["corp.id"]);

            using (SqlConnection conn = new SqlConnection(Globals.ConnectionString))
            {
                string templetid = Functions.ParseStr(Request["templetid"]);
                string type = Functions.ParseStr(Request["type"],"pdf").ToLower();//pdf/img

                string filename = "";
                if (!templetid.Equals(""))
                {
                    //TempletDAL templetDAL = new TempletDAL(conn);
                    //DataRow t = templetDAL.GetATemplet(templetid);
                    //string docpath = Functions.CleanDBString(t["docpath"]);
                    //string docbase = Functions.GetAppConfigString("TempletFileRootPath", "");
                    //filename = docbase + "\\" + corpid + "\\" + docpath;

                    TempletBLL tb = new TempletBLL(conn);
                    filename = tb.GetTempletFilePathByID(templetid);
                }

                if (type.Equals("img"))//转换为图片输出                {
                {
                    int page = Functions.ParseInt(Request["page"],1);//页码

                    string outputimgfile = PDF2ImageConvertor.ConvertPDF2Png(filename, page);

                    CommonBLL.GetStreamFromFile(outputimgfile, Response);
                    File.Delete(outputimgfile);
                }
                else
                {
                    CommonBLL.GetStreamFromFile(filename, Response);
                }

            }
        }
Ejemplo n.º 2
0
        public void BindData() {
            try
            {
                //do
                //根据id和type返回模板或者实例(临时或永久)的文件路径;
                //PDFType:t 模板; hrc 合同实例
                string pdffile = "";
                bool needdelete = false;
                if (PDFType.Equals("t"))
                {
                    TempletBLL tb = new TempletBLL(_conn);
                    pdffile = tb.GetTempletFilePathByID(PDFID);
                    needdelete = false;

                }
                if (PDFType.Equals("hrc"))
                {
                    HRContractBLL hrcb = new HRContractBLL(_conn);
                    int res = hrcb.GetContractFilePathByID(PDFID, out pdffile);
                    if (1 == res)
                        needdelete = false;
                    else
                        needdelete = true;
                }
                //读取pdf的页数
                if (pdffile.Equals("") || !File.Exists(pdffile))
                {
                    Response.Write("合同[" + PDFType + "]文件不存在.");
                    this.imgPreviewer.ImageUrl = "../images/logo.png";
                    return;
                }
                PDFFile pdfFile = PDFFile.Open(pdffile);
                int cnt = pdfFile.PageCount;
                ViewState["pagecount"] = cnt;
                pdfFile.Dispose();
                if (PageNo > cnt) PageNo = cnt;


                if (needdelete) File.Delete(pdffile);


                //绑定图片
                this.imgPreviewer.ImageUrl = "/control/GetPDFPageImage.aspx?id=" + PDFID + "&type=" + PDFType + "&from=" + From + "&page=" + PageNo;

                //生成翻页器
                this.phLinks.Controls.Clear();

                for (int i = 1; i <= cnt; i++)
                {
                    Button lb = new Button();
                    lb.Text = " [ " + i.ToString() + " ] ";
                    //lb.Click += new EventHandler(this.OnButton);
                    lb.CssClass = "txt";
                    lb.Command += new CommandEventHandler(this.OnButton);
                    lb.CommandArgument = i.ToString();

                    this.phLinks.Controls.Add(lb);
                }
            }
            catch (Exception e) {
                Response.Write(e.ToString());
                GetErrMsg(e.Message);
                
            }
        
        }