easyflow

EasyFlow塞流程

#取得USER ID

<SPAN ID="strUserID"><%= Session["strUserID"].ToString() %></SPAN>
<asp:TextBox ID="strUserID" runat="server" OnPreRender="strUserID_PreRender"></asp:TextBox>
<script runat="server" language="C#">
    protected void strUserID_PreRender(object sender, EventArgs e)
    {
	strUserID.Text = Session["strUserID"].ToString();
    }
</script>

#審核時更新TT資料

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TOPPROD.TSC %>" ProviderName="<%$ ConnectionStrings:TOPPROD.TSC.ProviderName %>" SelectCommand="SELECT * FROM TSC_TEST07.&quot;AFA_FILE&quot;" UpdateCommand="UPDATE &quot;TSC_TEST07&quot;.&quot;FAF_FILE&quot; SET &quot;FAF02&quot; = :FAF02 WHERE &quot;FAF01&quot; = :FAF01">
    <UpdateParameters>
        <asp:Parameter Name="FAF01" Type="String" />
        <asp:Parameter Name="FAF02" Type="String" />
    </UpdateParameters>
</asp:SqlDataSource>

<script runat="server" language="C#">
    protected override void BeforeApprove(PublicUTIL.DBProcessor processor)
    {
        SqlDataSource1.UpdateParameters["FAF01"].DefaultValue = "140000";
        SqlDataSource1.UpdateParameters["FAF02"].DefaultValue = "消防機房789";
        SqlDataSource1.Update();
    }
</script>

#發單改下一關人員

<script runat="server" language="C#">

	protected override void BeforeApprove(PublicUTIL.DBProcessor processor)
	{
		base.BeforeApprove(processor);


		if (AryFlowProperty.SerialSignResult == "2" && this.FlowNo == "0010")
		{
			string l_where = " resdb001 = '{0}' AND resdb002 = '{1}' AND resdb003 = '{2}' AND resdb004 = '{3}' ";	
			l_where = String.Format(l_where, this.formID, this.SheetNo, this.FlowNo, this.BranchNo);
			foreach ( System.Data.DataRow my_resdb_row in RstTRFlow.Tables[0].Select(l_where) )
			{
				my_resdb_row["resdb010"] = "DS-管1;§1§§";
				my_resdb_row["resdb027"] = "josh168"; //流程提示訊息
			}
		}


	}

</script>
<script runat="server" language="C#">

	protected override void BeforeSendNewFormAddFlow(TRFlowRESDB[] xFlowData, ref bool xBlnFlowChanged)
	{
		//TT發單無反應
		xBlnFlowChanged = false; //不要重新解析流程


		using (System.IO.StreamWriter sw = new System.IO.StreamWriter(Server.MapPath("loginNote.txt"),true)) 
		{
			sw.Write(DateTime.Now);

			sw.Write("	");
			sw.Write("BeforeSendNewFormAddFlow:");

			sw.Write("	formID:");
			sw.Write(this.formID);

			sw.Write("	SheetNo:");
			sw.Write(this.SheetNo);

			sw.Write("	FlowNo:");
			sw.Write(this.FlowNo);

			sw.Write("	branchNo:");
			//sw.Write(this.branchNo);

			sw.Write("	Result:");
			sw.Write(AryFlowProperty.SerialSignResult);

			sw.WriteLine("");
		}
	}



	protected override void BeforeApprove(PublicUTIL.DBProcessor processor)
	{
		base.BeforeApprove(processor);



		foreach (System.Data.DataRow my_resdb_row in RstTRFlow.Tables[0].Select("resdb003 like '0020%'"))
		{
			//my_resdb_row["resdb027"] = "josh168"; //流程提示訊息
			//my_resdb_row.Delete();
			//my_resdb_row["resdb010"] = "P00282-許;DS-管;§1§§"; //流程角色參數4
			my_resdb_row["resdb010"] = "§1§§"; //流程角色參數4
		}



		using (System.IO.StreamWriter sw = new System.IO.StreamWriter(Server.MapPath("loginNote.txt"),true)) 
		{

			sw.Write(TextBox1_JJ.Text);


			sw.Write(DateTime.Now);

			sw.Write("	");
			sw.Write("BeforeSendNewFormAddFlow:");

			sw.Write("	formID:");
			sw.Write(this.formID); //表單代號

			sw.Write("	SheetNo:");
			sw.Write(this.SheetNo); //表單單號

			sw.Write("	FlowNo:");
			sw.Write(this.FlowNo); //關號

			sw.Write("	branchNo:");
			sw.Write(this.BranchNo); //支號

			sw.Write("	SerialNo:");
			sw.Write(this.SerialNo); //流水號


			sw.Write("	Result:");
			sw.Write(AryFlowProperty.SerialSignResult);

			sw.WriteLine("");

		}

	}



	//
	protected override void AfterApprove()
	{

		base.AfterApprove();
		using (System.IO.StreamWriter sw = new System.IO.StreamWriter(Server.MapPath("loginNote.txt"),true)) 
		{
			sw.Write(DateTime.Now);

			sw.Write("	");
			sw.Write("AfterApprove:");

			sw.Write("	");
			sw.Write(this.formID);

			sw.Write("	");
			sw.Write(this.SheetNo);

			sw.Write("	");
			sw.Write(AryFlowProperty.SerialSignResult);

			sw.Write("	");
			sw.Write(this.FlowNo);

			sw.WriteLine("");
		}

	}


</script>

主要參考https://jerry2yang.wordpress.com/tag/beforeapprove/

這次要在表單簽核流程中由程式判斷手動塞入新的流程關卡。所用的變數和先前開單塞流程中使用的是不一樣,至於為什麼不能用開單中所使用的變數我也不知道為何。相同的這次還是由雙檔表單的子單身中紀錄的人員作為塞入的流程關卡來作為操作範例。

一、取得紀錄 Grid 單身中人員的員工編號是使用 Easyflow 物件中內建的方法processor.getDataAdapter(sql_command) 直接由資料庫中抓取資料並填入 DataTable 物件的變數之中。在取得人員資料後就可以利用迴圈,將流程塞入表單流程異動子檔資料表中。

二、插入流程 於流程中使用表單流程資料表物件的方法「RstTRFlow.Tables[0].Add(my_datarow)」加入新的流程關卡。在這之前先必須藉由 「RstTRFlow.Tables[0].NewRow()」物件方法新增一個「DataRow」資料列件件(流程關卡資料列),再將這資料列物件的「key-value」資料補齊(設定方法如陣列元素給值那樣)。

   #region 簽核前處理
   protected override void BeforeApprove(PublicUTIL.DBProcessor processor)
   {
       base.BeforeApprove(processor);
       //取得單身欄位資料
       string sql_command = @"select empl1 from [EFNETDB].[dbo].[test2_2] where test2_2001='{0}' and test2_2002='{1}' ";
       sql_command = String.Format(sql_command, this.formID, this.SheetNo);
       SqlDataAdapter my_adapter = processor.getDataAdapter(sql_command);
       DataTable my_table= new DataTable();
       my_adapter.Fill(my_table);
 
       if (AryFlowProperty.SerialSignResult == "2") //同意
       {
           //如果關號是0010,則手動塞流程
           if (this.FlowNo == "0010")
           {
               int resdb003=9901;
               foreach( DataRow my_row in my_table.Rows )
               {
                       DataRow my_datarow = RstTRFlow.Tables[0].NewRow();//流程資料表建立一新的資料列
                       //開始設定資料列相關資資料
                       my_datarow["resdb001"] = formID;
                       my_datarow["resdb002"] = SheetNo;
                       my_datarow["resdb003"] = resdb003;
                       my_datarow["resdb004"] = "0010"; //支號
                       my_datarow["resdb005"] = 1; //流程角色
                       my_datarow["resdb006"] = 4; //簽核種類
                       my_datarow["resdb007"] = my_row["empl1"].ToString(); //流程角色參數1 (Grid物件中取得的員工編號值,中括號中填入"欄位名稱")
                       my_datarow["resdb008"] = ""; //流程角色參數2
                       my_datarow["resdb009"] = ""; //流程角色參數3
                       my_datarow["resdb010"] = ""; //流程角色參數4
                       my_datarow["resdb011"] = 0;  //容許簽核時間
                       my_datarow["resdb012"] = "N"; //自動ByPass?
                       my_datarow["resdb013"] = "0"; //ByPass方式
                       my_datarow["resdb014"] = "Y"; //是否強制簽核?
                       my_datarow["resdb015"] = "Y"; //是否單一簽核
                       my_datarow["resdb016"] = "N"; //可否列印?
                       my_datarow["resdb017"] = "Y"; //可否撤簽?
                       my_datarow["resdb018"] = "Y"; //可否加簽?
                       my_datarow["resdb019"] = "N"; //可否轉會?
                       my_datarow["resdb020"] = "N"; //可否轉寄?
                       my_datarow["resdb021"] = "N"; //可否新增附加檔?
                       my_datarow["resdb022"] = "N"; //可否修改附加檔?
                       my_datarow["resdb023"] = "N"; //可否刪除附加檔?
                       my_datarow["resdb024"] = "Y"; //可否閱讀附加檔?
                       my_datarow["resdb025"] = "N"; //簽核時密碼驗證?
                       my_datarow["resdb026"] = "N"; //流程是否已經解析?
                       my_datarow["resdb027"] = ""; //流程提示訊息
                       my_datarow["resdb028"] = ""; //
                       my_datarow["resdb029"] = ""; //
                       RstTRFlow.Tables[0].Rows.Add(my_datarow);//將資料列插入流程資料表中
                       resdb003++;
               }
           }
       }
   }
#endregion
#region 簽核前處理
        protected override void BeforeApprove(PublicUTIL.DBProcessor processor)
        {
            base.BeforeApprove(processor);
            //取得單身欄位資料
            string sql_command = @"select empl1 from [EFNETDB].[dbo].[test2_2] where test2_2001='{0}' and test2_2002='{1}' ";
            sql_command = String.Format(sql_command, this.formID, this.SheetNo);
            SqlDataAdapter my_adapter = processor.getDataAdapter(sql_command);
            DataTable my_table= new DataTable();
            my_adapter.Fill(my_table);
 
            if (AryFlowProperty.SerialSignResult == "2") //同意
            {
                //如果關號是0010,則手動塞流程
                if (this.FlowNo == "0010")
                {
                    foreach (DataRow my_resdd_row in RstTRFlowApprove.Tables[0].Select("resdd003 like '2%'"))
                    {
                        my_resdd_row.Delete();
                    }
                    foreach (DataRow my_resdc_row in RstTRFlowDetail.Tables[0].Select("resdc003 like '2%'"))
                    {
                        my_resdc_row.Delete();
                    }
                    foreach (DataRow my_resdb_row in RstTRFlow.Tables[0].Select("resdb003 like '2%'"))
                    {
                        my_resdb_row.Delete();
                    }
 
                    int resdb003=20;
                    foreach( DataRow my_row in my_table.Rows )
                    {
                        DataRow my_datarow = RstTRFlow.Tables[0].NewRow();//流程資料表建立一新的資料列
                        //開始設定資料列相關資資料
                        my_datarow["resdb001"] = formID;
                        my_datarow["resdb002"] = SheetNo;
                        my_datarow["resdb003"] = resdb003.ToString()+DateTime.Now.Second.ToString("00");
                        my_datarow["resdb004"] = "0010"; //支號
                        my_datarow["resdb005"] = 1; //流程角色
                        my_datarow["resdb006"] = 4; //簽核種類
                        my_datarow["resdb007"] = my_row["empl1"].ToString(); //流程角色參數1 (Grid物件中取得的員工編號值,中括號中填入"欄位名稱")
                        my_datarow["resdb008"] = ""; //流程角色參數2
                        my_datarow["resdb009"] = ""; //流程角色參數3
                        my_datarow["resdb010"] = ""; //流程角色參數4
                        my_datarow["resdb011"] = 0;  //容許簽核時間
                        my_datarow["resdb012"] = "N"; //自動ByPass?
                        my_datarow["resdb013"] = "0"; //ByPass方式
                        my_datarow["resdb014"] = "Y"; //是否強制簽核?
                        my_datarow["resdb015"] = "Y"; //是否單一簽核
                        my_datarow["resdb016"] = "N"; //可否列印?
                        my_datarow["resdb017"] = "Y"; //可否撤簽?
                        my_datarow["resdb018"] = "Y"; //可否加簽?
                        my_datarow["resdb019"] = "N"; //可否轉會?
                        my_datarow["resdb020"] = "N"; //可否轉寄?
                        my_datarow["resdb021"] = "N"; //可否新增附加檔?
                        my_datarow["resdb022"] = "N"; //可否修改附加檔?
                        my_datarow["resdb023"] = "N"; //可否刪除附加檔?
                        my_datarow["resdb024"] = "Y"; //可否閱讀附加檔?
                        my_datarow["resdb025"] = "N"; //簽核時密碼驗證?
                        my_datarow["resdb026"] = "N"; //流程是否已經解析?
                        my_datarow["resdb027"] = ""; //流程提示訊息
                        my_datarow["resdb028"] = ""; //
                        my_datarow["resdb029"] = ""; //
                        RstTRFlow.Tables[0].Rows.Add(my_datarow);//將資料列插入流程資料表中
                        resdb003++;
                    }
                }
            }
        }
#endregion
 
        protected override void AfterApprove()
        {
            base.AfterApprove();
        }

#JOSH:由TT發單無觸發此段
在開單時可利用覆寫「BeforeSendNewFormAddFlow」函式,在送出來表單時手動加入新的流程關卡。※「TRFlowRESDB」類別所建立的物件,可以在開單時新增流程資訊。

protected override void BeforeSendNewFormAddFlow(TRFlowRESDB[] xFlowData, ref bool xBlnFlowChanged)
{
    xBlnFlowChanged = false; //不要重新解析流程
    int rows_count = MasterObj.DetailObjs[0].NewRows.Count;//取得grid有幾列資料
    xFlowData = new TRFlowRESDB[rows_count];//宣告流程物件陣列及其大小
    int resdb003=9901,index=0;//迴圈用的變數,流程關號、流程物件索引
    //送出表單時插入自訂流程使用 MasterObj.DetailObjs[0].NewRows 物件
    //DetailObjs[0]代表第一個Grid物件
    //NewRows代表尚未存入資料庫的資料
    foreach (DscRow dscRow in MasterObj.DetailObjs[0].NewRows)
    {
        if (!dscRow.IsDeleted)
        {
            xFlowData[index].resdb001 = formID; //表單代號
            xFlowData[index].resdb002 = SheetNo; //表單單號
            xFlowData[index].resdb003 = resdb003.ToString(); //關號
            xFlowData[index].resdb004 = "0010"; //支號
            xFlowData[index].resdb005 = 1; //流程角色
            xFlowData[index].resdb006 = 4; //簽核種類
            xFlowData[index].resdb007 = dscRow["empl1"].Value.ToString(); //流程角色參數1 (Grid物件中取得的員工編號值,中括號中填入"欄位名稱")
            xFlowData[index].resdb008 = ""; //流程角色參數2
            xFlowData[index].resdb009 = ""; //流程角色參數3
            xFlowData[index].resdb010 = ""; //流程角色參數4
            xFlowData[index].resdb011 = 0;  //容許簽核時間
            xFlowData[index].resdb012 = "N"; //自動ByPass?
            xFlowData[index].resdb013 = "0"; //ByPass方式
            xFlowData[index].resdb014 = "Y"; //是否強制簽核?
            xFlowData[index].resdb015 = "Y"; //是否單一簽核
            xFlowData[index].resdb016 = "N"; //可否列印?
            xFlowData[index].resdb017 = "Y"; //可否撤簽?
            xFlowData[index].resdb018 = "Y"; //可否加簽?
            xFlowData[index].resdb019 = "N"; //可否轉會?
            xFlowData[index].resdb020 = "N"; //可否轉寄?
            xFlowData[index].resdb021 = "N"; //可否新增附加檔?
            xFlowData[index].resdb022 = "N"; //可否修改附加檔?
            xFlowData[index].resdb023 = "N"; //可否刪除附加檔?
            xFlowData[index].resdb024 = "Y"; //可否閱讀附加檔?
            xFlowData[index].resdb025 = "N"; //簽核時密碼驗證?
            xFlowData[index].resdb026 = "N"; //流程是否已經解析?
            xFlowData[index].resdb027 = ""; //流程提示訊息
            xFlowData[index].resdb028 = ""; //
            xFlowData[index].resdb029 = ""; //
            resdb003++;
            index++;
        }
    }
    base.BeforeSendNewFormAddFlow(xFlowData, ref xBlnFlowChanged);
}

可取單身的範例

由雙檔架構表單的單身(Grid)所儲存的員工編號欄位值,來當作程式手動塞流程的員工編號值(流程參數1的值)。此次的重點在於知道Grid的物件是什麼及如何從Grid物件中取得指定欄位的值。

protected override void BeforeSendNewFormAddFlow(TRFlowRESDB[] xFlowData, ref bool xBlnFlowChanged)
{
    xBlnFlowChanged = false; //不要重新解析流程
    int rows_count = MasterObj.DetailObjs[0].NewRows.Count;//取得grid有幾列資料
    xFlowData = new TRFlowRESDB[rows_count];//宣告流程物件陣列及其大小
    int resdb003=9901,index=0;//迴圈用的變數,流程關號、流程物件索引
    //送出表單時插入自訂流程使用 MasterObj.DetailObjs[0].NewRows 物件
    //DetailObjs[0]代表第一個Grid物件(第一個子單身)
    //NewRows代表尚未存入資料庫的資料
    foreach (DscRow dscRow in MasterObj.DetailObjs[0].NewRows)
    {
        if (!dscRow.IsDeleted)
        {
            xFlowData[index].resdb001 = formID; //表單代號
            xFlowData[index].resdb002 = SheetNo; //表單單號
            xFlowData[index].resdb003 = resdb003.ToString(); //關號
            xFlowData[index].resdb004 = "0010"; //支號
            xFlowData[index].resdb005 = 1; //流程角色
            xFlowData[index].resdb006 = 4; //簽核種類
            xFlowData[index].resdb007 = dscRow["empl1"].Value.ToString(); //流程角色參數1 (Grid物件中取得的員工編號值,中括號中填入"欄位名稱")
            xFlowData[index].resdb008 = ""; //流程角色參數2
            xFlowData[index].resdb009 = ""; //流程角色參數3
            xFlowData[index].resdb010 = ""; //流程角色參數4
            xFlowData[index].resdb011 = 0;  //容許簽核時間
            xFlowData[index].resdb012 = "N"; //自動ByPass?
            xFlowData[index].resdb013 = "0"; //ByPass方式
            xFlowData[index].resdb014 = "Y"; //是否強制簽核?
            xFlowData[index].resdb015 = "Y"; //是否單一簽核
            xFlowData[index].resdb016 = "N"; //可否列印?
            xFlowData[index].resdb017 = "Y"; //可否撤簽?
            xFlowData[index].resdb018 = "Y"; //可否加簽?
            xFlowData[index].resdb019 = "N"; //可否轉會?
            xFlowData[index].resdb020 = "N"; //可否轉寄?
            xFlowData[index].resdb021 = "N"; //可否新增附加檔?
            xFlowData[index].resdb022 = "N"; //可否修改附加檔?
            xFlowData[index].resdb023 = "N"; //可否刪除附加檔?
            xFlowData[index].resdb024 = "Y"; //可否閱讀附加檔?
            xFlowData[index].resdb025 = "N"; //簽核時密碼驗證?
            xFlowData[index].resdb026 = "N"; //流程是否已經解析?
            xFlowData[index].resdb027 = ""; //流程提示訊息
            xFlowData[index].resdb028 = ""; //
            xFlowData[index].resdb029 = ""; //
            resdb003++;
            index++;
        }
    }
    base.BeforeSendNewFormAddFlow(xFlowData, ref xBlnFlowChanged);
}

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。