Easyflow ISO 直接開啟文件PDF發佈檔(自訂網頁程式)

在 Easyflow ISO 模組上,把開放給使用者能列印(直接開啟PDF)的表單,文件權限等級為標記「9」。

建立後端程式碼處理pdf,由資料庫讀取PDF字串並輸出到前端。

using System;
using System.Collections.Generic;
//using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

public partial class functions_readStream : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Response.Write("功能尚未開放,請耐心等候。");
        //Response.End();
        try
        {
            string DocNO = Request.QueryString["DocNO"];
            string DocVer = Request.QueryString["DocVer"];

            using (SqlConnection myConnection = new SqlConnection("User ID=sa;Password = qwe19735;Data Source=192.168.128.219;DataBase=EFNETDB;"))
            {
                if (Session["IsFromLoginPage"] == null || Session["IsFromLoginPage"].ToString() != "Y")
                {
                    Response.Write("你尚未登入Easyflow或是Session已逾時。<br/>如有任何疑問請聯繫資訊課人員。");
                    Response.End();
                }

                const string SQL = @"select isoebb005,isoebb006,isoebb009,isoebb010,isoebf003,isoebf004
                from isoebb join isoebf on isoebb005=isoebf001 and isoebb006=isoebf002
                where isoebb005=@DocNO and isoebb006=@DocVer
                and (isoebf003='0' or (isoebf003='1' and isoebf004 in (select resan001 from resan where resan003=@UserId)))
                and isoebf005='9'
                and isoebb015='1'
                    ;";
                SqlCommand myCommand = new SqlCommand(SQL, myConnection);
                myCommand.Parameters.AddWithValue("@DocNO", DocNO);
                myCommand.Parameters.AddWithValue("@DocVer", DocVer);
                myCommand.Parameters.AddWithValue("@UserId", Session["strUserID"].ToString());

                myConnection.Open();
                SqlDataReader myReader = myCommand.ExecuteReader();

                if (myReader.Read())
                {
                    //Response.ContentType = myReader["MIME"].ToString();
                    Response.ContentType = "application/pdf";
                    Response.BinaryWrite((byte[])myReader["isoebb010"]);
                    Response.End();
                }
                else{
                    Response.Write("你沒有權限瀏覽與列印所選取的文件。<br/>如有任何疑問請聯繫資訊課人員。");
                }

                myReader.Close();
                myConnection.Close();
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }
}

修改一般第三階表單判斷文件權限等級是否為 “9″ ,來產生列印的文件的連結。

using System;
using System.Collections.Generic;
//using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

public partial class MIS_ISO_Doc_Index : System.Web.UI.Page
{
    SqlConnection myConEFnet;
    SqlDataAdapter myISOAdapter;
    public string tmpstring, isoType, SessionValues;
    string sqlstring1 = @"
select
a.isoebe003,a.isoebe004,a.isoead003,a.isoeba003, a.isoebe001,a.isoeba002,
b.isoeba003 as isoeba003x,b.isoeba001 as isoeba001x,b.isoeba002 as isoeba002x ,b.isoebd003,isoebf005,in_groups
from
(select isoebe002,isoebe003, isoebe004,isoead003,isoebe001,isoeba002,isoeba003,isoeba012 from
(isoebe join isoead on isoebe003=isoead001 and isoebe004=isoead002 ) join isoeba on isoebe001=isoeba001
and isoebe002=isoeba002 where isoebe001 not like '%-%-%'  and isoeba099='2'
) as a left join
(select substring(isoeba001,0,LEN(isoeba001)-CHARINDEX('-',reverse(isoeba001))+1) as isoeba000,
isoeba001,isoeba002,isoeba003,isoebd003,isoebf005,
in_groups=(case when (isoebf003='0' or (isoebf003='1' and isoebf004 in (select resan001 from resan where resan003=@UserId))) then '1' else '0' end)
from isoeba left join isoebd on isoeba001=isoebd001 and isoeba002=isoebd002 left join isoebf on isoeba001=isoebf001 and isoeba002=isoebf002
where isoeba001 like '%-%-%' and isoeba099='2'
) as b on a.isoebe001=b.isoeba000
where a.isoebe003=@isoType
order by isoebe003,isoebe004,isoebe001,isoeba001x
";
    string sqlstring2 = @"
select
a.isoebe003,a.isoebe004,a.isoead003,a.isoeba003, a.isoebe001,a.isoeba002,
b.isoeba003 as isoeba003x,b.isoeba001 as isoeba001x,b.isoeba002 as isoeba002x ,b.isoebd003,isoebf005,in_groups
from
(select isoebe002,isoebe003, isoebe004,isoead003,isoebe001,isoeba002,isoeba003,isoeba012 from
(isoebe join isoead on isoebe003=isoead001 and isoebe004=isoead002 ) join isoeba on isoebe001=isoeba001
and isoebe002=isoeba002 where isoebe001 not like '%-%-%'  and isoeba099='2'
) as a left join
(select substring(isoeba001,0,LEN(isoeba001)-CHARINDEX('-',reverse(isoeba001))+1) as isoeba000,
isoeba001,isoeba002,isoeba003,isoebd003,isoebf005,
in_groups=(case when (isoebf003='0' or (isoebf003='1' and isoebf004 in (select resan001 from resan where resan003=@UserId))) then '1' else '0' end)
from isoeba left join isoebd on isoeba001=isoebd001 and isoeba002=isoebd002 left join isoebf on isoeba001=isoebf001 and isoeba002=isoebf002
where isoeba001 like '%-%-%' and isoeba099='2'
) as b on a.isoebe001=b.isoeba000
where a.isoebe003='ISO'
order by isoebe003,isoebe004,isoebe001,isoeba001x
";

    DataTable myDataTable1,myDataTable2;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["IsFromLoginPage"] == null || Session["IsFromLoginPage"].ToString() != "Y")
        {
            Response.Write("你尚未登入Easyflow或是Session已逾時。<br/>如有任何疑問請聯繫資訊課人員。");
            Response.End();
        }

        isoType="14001";
        if (Request.QueryString["isoType"] != null)
        {
            isoType = Request.QueryString["isoType"];
        }

        myConEFnet = new SqlConnection("User ID=sa;Password = password;Data Source=192.168.128.219;DataBase=EFNETDB;");
        SqlCommand myCommand1 = new SqlCommand(sqlstring1, myConEFnet);
        myCommand1.Parameters.AddWithValue("@isoType",isoType);
        myCommand1.Parameters.AddWithValue("@UserId", Session["strUserID"].ToString());
        SqlCommand myCommand2 = new SqlCommand(sqlstring2, myConEFnet);
        myCommand2.Parameters.AddWithValue("@UserId", Session["strUserID"].ToString());

        myConEFnet.Open();
        myISOAdapter = new SqlDataAdapter(myCommand1);
        myDataTable1 = new DataTable();
        myISOAdapter.Fill(myDataTable1);
        myISOAdapter = new SqlDataAdapter(myCommand2);
        myDataTable2 = new DataTable();
        myISOAdapter.Fill(myDataTable2);
        string[] strs;
        DataView tmpView1 = myDataTable1.DefaultView;
        DataTable tmpTable1 = tmpView1.ToTable("tmpTable1",true,strs= new string[]{"isoebe004","isoead003"});
        DataTable tmpTable2 = tmpView1.ToTable("tmpTable2", true, strs = new string[] { "isoebe004","isoeba003","isoebe001","isoeba002" });
        DataTable tmpTable3 = tmpView1.ToTable("tmpTable3", true, strs = new string[] { "isoebe001", "isoeba003x", "isoeba001x", "isoeba002x", "isoebd003", "isoebf005","in_groups" });
        DataView tmpView2 = myDataTable2.DefaultView;
        DataTable tmpTable4 = tmpView2.ToTable("tmpTable4",true,strs= new string[]{"isoebe004","isoead003"});
        DataTable tmpTable5 = tmpView2.ToTable("tmpTable5", true, strs = new string[] { "isoebe004","isoeba003","isoebe001","isoeba002" });
        DataTable tmpTable6 = tmpView2.ToTable("tmpTable6", true, strs = new string[] { "isoebe001", "isoeba003x", "isoeba001x", "isoeba002x", "isoebd003", "isoebf005","in_groups" });

        foreach (DataRow row in tmpTable1.Rows) {
            tmpstring += "<tr><td class='td1'><div>" + row["isoebe004"] + " " + row["isoead003"] + "</div></td><td><table>";
            foreach (DataRow row1 in tmpTable2.Select("isoebe004 = '"+ row["isoebe004"]+"'")) {
                tmpstring += "<tr><td class='td2'><div><a style='color:blue;' target='_blank' href='/efnet/src/ISO/ISOEM008/DocDetail.aspx?DocNO=" + row1["isoebe001"] + "&DocVer=" + row1["isoeba002"] + "'>" + row1["isoeba003"] + "</div></td><td class='td3'><div>" + row1["isoebe001"] + "</div></td><td  class='td4'><div>" + row1["isoeba002"] + "</div></td><td><table>";
                foreach(DataRow row2 in tmpTable3.Select("isoebe001 = '"+ row1["isoebe001"]+"'")){
                    if (row2["isoeba003x"].ToString() == "")
                    {
                        tmpstring += "<tr><td  class='td5'><div>&nbsp;</div></td><td  class='td6'><div>&nbsp;</div></td><td  class='td7'><div>&nbsp;</div></td></tr>";
                    }
                    else
                    {
                        tmpstring += "<tr><td  class='td5'><div><a style='color:blue;' target='_blank' href='/efnet/src/ISO/ISOEM008/DocDetail.aspx?DocNO=" + row2["isoeba001x"] + "&DocVer=" + row2["isoeba002x"] + "'>" + row2["isoeba003x"] + "</a>"+
						((row2["isoebd003"].ToString()!="")?"<a style='color:red;font-weight:bold;' target='_blank' href='../../frm/"+row2["isoebd003"].ToString()+"/"+row2["isoebd003"].ToString()+".aspx'>&nbsp;&nbsp;[申請]</a>":"")
                        + (row2["isoebf005"].ToString() == "9" && row2["in_groups"].ToString() == "1" ? "<a style='color:blue;' target='_blank' href='../functions/readStream.aspx?DocNO=" + row2["isoeba001x"] + "&DocVer=" + row2["isoeba002x"] + "''>&nbsp;&nbsp;[列印]</a>" : "")
                        +"</div></td><td  class='td6'><div>" + row2["isoeba001x"] + "</div></td><td  class='td7'><div>" + row2["isoeba002x"] + "</div></td></tr>";
                    }
                }
                tmpstring += "</table></td><td><table title='" + row1[1] + "'>";

				foreach (DataRow row3 in tmpTable5.Select("isoebe004 = '"+ row1[2].ToString().Replace("-","")+"'")) {
					tmpstring += "<tr><td class='td2'><div><a style='color:blue;' target='_blank' href='/efnet/src/ISO/ISOEM008/DocDetail.aspx?DocNO=" + row3["isoebe001"] + "&DocVer=" + row3["isoeba002"] + "'>" + row3["isoeba003"] + "</div></td><td class='td3'><div>" + row3["isoebe001"] + "</div></td><td  class='td4'><div>" + row3["isoeba002"] + "</div></td><td><table>";
					foreach(DataRow row4 in tmpTable6.Select("isoebe001 = '"+ row3["isoebe001"]+"'")){
						if (row4["isoeba003x"].ToString() == "")
						{
							tmpstring += "<tr><td  class='td5'><div>&nbsp;</div></td><td  class='td6'><div>&nbsp;</div></td><td  class='td7'><div>&nbsp;</div></td></tr>";
						}
						else
						{
							tmpstring += "<tr><td  class='td5'><div><a style='color:blue;' target='_blank' href='/efnet/src/ISO/ISOEM008/DocDetail.aspx?DocNO=" + row4["isoeba001x"] + "&DocVer=" + row4["isoeba002x"] + "'>" + row4["isoeba003x"] + "</a>"+
							((row4["isoebd003"].ToString()!="")?"<a style='color:red;font-weight:bold;' target='_blank' href='../../frm/"+row4["isoebd003"].ToString()+"/"+row4["isoebd003"].ToString()+".aspx'>&nbsp;&nbsp;[申請]</a>":"")
                            + (row4["isoebf005"].ToString() == "9" && row4["in_groups"].ToString() == "1" ? "<a style='color:blue;' target='_blank' href='../functions/readStream.aspx?DocNO=" + row4["isoeba001x"] + "&DocVer=" + row4["isoeba002x"] + "''>&nbsp;&nbsp;[列印]</a>" : "")
							+"</div></td><td  class='td6'><div>" + row4["isoeba001x"] + "</div></td><td  class='td7'><div>" + row4["isoeba002x"] + "</div></td></tr>";
						}
					}
                    tmpstring += "</table></td></tr>";
				}
				tmpstring += "</table></td></tr>";
            }
            tmpstring+="</table></td></tr>";
        }
        tmpstring="<table class='table1' style='display:none;'>"+tmpstring+"</table>";
        foreach (string SessionVar in Session.Keys)
        {
            SessionValues += "<br />" + SessionVar + ":" + Session[SessionVar].ToString();
        }
        SessionValues = "<div>" + SessionValues + "</div>";
    }
}

接著在機密等級代號維護作業中,新增一條文件權限等級「9」自訂公開、可列印。 新增一條機密等級代號9允許列印

指定允許被開啟列印的ISO文件,將文件的機密等級設定為「9」。指定允許列印的表單文件權限為「9 」

最後就完成了,ISO文件一覽表中加載了列印連結。ISO文件一覽表增加表單列印

One thought on “Easyflow ISO 直接開啟文件PDF發佈檔(自訂網頁程式)

  1. 請問上面您寫的兩段語法要加在哪裡?還有您最後一張呈現 ISO 文件的方式,怎麼跟我的不一樣?需要在哪裡設定?https://drive.google.com/file/d/0B9PNRO2A1CnlaFR4ZjZNSklhcUE/edit?usp=sharing

    此外,有個問題想請教您;可否在表單每一關卡簽核時,都能修改欄位資料嗎?而不用再流程精靈一關一關設定

    不好意思,問題多了點,才請您指導一下~

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s