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文件一覽表增加表單列印

廣告

鼎新 Easyflow.Net Dump 出來的 Session 索引/值

鼎新 Easyflow.Net Dump 出來的 Session 索引/值

IsFromLoginPage: Y
EFDBLoginKey: 715678D3F25E9C822BBE281392C55F6E
EFLoginDDLUserCompany: [EFNETDB, EFNETDB]
EFDBLoginUserId: 080xxxx
tDomain:
strUserID: 080xxxx
UserID_resak004: 080xxxx
strProcID: Q57tKlZGj3kqBNCYcjNP
UserOnlineCount: 10
UserInfo: tw.com.dsc.dscDotNet.tool.UserInfoClass
EFUserInfoClass: tw.com.dsc.easyflowDotNet.kernelBasePage.easyflowfunction.EFUserInfoClass

MSSQL 使用 OPENROWSET 插入或更新檔案到資料型態是「varbinary(max)」的欄位

由於Easyflow的ISO文管人員在沒有注意文件內容是否正確的情況下就將新版文件發佈,隔天才發現發佈檔案有問題。但依照Easyflow ISO文管運作流程,當文件發佈後如果需要進行修正就要做一次文件版本更新。這樣的作法費時又費工,如果可以直接置換存放於資料庫中的檔案內容或許是一個比較簡的作法。

在MSSQL的資料庫中,可以利用內建函式「OPENROWSET」來將檔案塞入到欄位中。使用「OPENROWSET」可以當作是一個子查詢,而這個子查詢的來源資料表就是實體檔案的存放路徑(以SQLSERVER本機的路徑為基準、或是可以存取的網芳資料夾中的檔案路徑)。

注意!必須要給子查詢指定一個別名,否則在執行操作中會出現錯誤。

以下的範例是置換文件編號為「TQP-G001」發佈版本為「C」所對應到的發佈檔案,置換為網芳分享資料夾中的檔案。

update isoebb set isoebb010 =
(select * FROM OPENROWSET(bulk N'\\192.168.128.189\temp\廢棄物管理程序.pdf', SINGLE_BLOB ) as binary_file )
where isoebb005='TQP-G001' and isoebb006='C'

EasyFlow.net 上自已寫的 javascript

我們可以將自已 javascript 程式碼寫在「目標表單的JS檔」、或是「目標表單的ASPX」都可以。

EasyFlow.NET 3.X版也有使用 jquery 函式庫。

因此可以用 jQuery 中最常用的語法

$(document).ready(function(){
   var xyz="12345";
   ....
});

來註冊我們所要的函式或是物件的事件觸發所要執行的動作等!!

EasyFlow 修改電子表單的網頁元件屬性

有時候,我們可能因為設計上的不小心或是後來因為某些因素,要來更改原先表單精靈設計的表單。

但是我們可能沒有辦法直接由電子表單設計精靈的表單重新設計區,來規劃表單欄位在網頁上所顯示的屬性。例如:要將 textarea改成text,因為網頁上這兩個標籤看起來就不一樣。
繼續閱讀