Easyflow.NET 表單預設 AjaxPro function 運用

在Easyflow使用表單精靈建立的新表單,都能在C#的檔案中找到類似下面這樣的程式碼片段。這些是用 AjaxPro 函式庫所寫的程式碼片段。

#region AjaxMethod()
#region GetEmployeeId
		///
<summary>
		/// 取得員工 ID
		/// </summary>
		/// 回傳員工 ID(string)
		[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
			public string ajaxGetEmployeeId()
			{
				return this.UserInfo.EmployeeId.ToString().Trim();
			}
#endregion

#region GetLoginName
		///
<summary>
		/// 取得登入者員工姓名
		/// </summary>
		/// 回傳員工姓名(string)
		[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
			public string ajaxGetLoginName()
			{
				return this.UserInfo.LoginName.ToString().Trim();
			}
#endregion

#region GetAgentID
		///
<summary>
		/// 取得代理人員工 ID
		/// </summary>
		/// 回傳代理人員工 ID(string)
		[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
			public string ajaxGetAgentID()
			{
				return base.StrAgentID.ToString().Trim();
			}
#endregion

#region GetAgentName
		///
<summary>
		/// 取得代理人姓名
		/// </summary>
		/// 回傳代理人姓名(string)
		[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
			public string ajaxGetAgentName()
			{
				string tAgentName = "";
				UserInfoClass tClass = (UserInfoClass)Session["UserInfo"];
				string mCompany = tClass.Company;
				DBCommand dbCommand = DscDBData.GetDataDBCommand();
				DataTable tDt = new DataTable();
				StringBuilder tSql = new StringBuilder();
				tSql.AppendFormat("SELECT resak002 FROM {0}..resak AS resak ", mCompany);
				tSql.AppendFormat("WHERE resak001 = '{0}' ", base.StrAgentID.ToString().Trim());
				tDt = dbCommand.Query(tSql.ToString());
				if (tDt.Rows.Count > 0)
				{
					tAgentName = tDt.Rows[0]["resak002"].ToString().Trim();
				}
				return tAgentName;
			}
#endregion

#region GetDepartmentId
		///
<summary>
		/// 取得部門 ID
		/// </summary>
		/// 回傳部門 ID(string)
		[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
			public string ajaxGetDepartmentId()
			{
				string tDeptID = "";
				UserInfoClass tClass = (UserInfoClass)Session["UserInfo"];
				tDeptID = m_objRE.FindEmplDeptID(tClass.EmployeeId.ToString().Trim(), m_strProcID);
				return tDeptID;
			}
#endregion

#region GetDepartmentName
		///
<summary>
		/// 取得部門名稱
		/// </summary>
		/// 回傳部門名稱(string)
		[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
			public string ajaxGetDepartmentName()
			{
				string tDeptName = "";
				string tDeptID = "";
				UserInfoClass tClass = (UserInfoClass)Session["UserInfo"];
				tDeptID = m_objRE.FindEmplDeptID(tClass.EmployeeId.ToString().Trim(), m_strProcID);
				tDeptName = m_objRE.FindDeptName(tDeptID, m_strProcID);
				return tDeptName;
			}
#endregion

#region GetEFDBFieldValue
		[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
			public string ajaxGetEFDBFieldValue(string pSql, string pFieldName)
			{
				string tResult = "";
				UserInfoClass tClass = (UserInfoClass)Session["UserInfo"];
				string mCompany = tClass.Company;
				DBCommand dbCommand = DscDBData.GetDataDBCommand();
				DataTable tDt = new DataTable();
				string tSql = pSql;
				tDt = dbCommand.Query(tSql);
				if (tDt.Rows.Count > 0)
				{
					tResult = tDt.Rows[0]["\""+pFieldName+"\""].ToString().Trim();
				}
				return tResult;
			}
#endregion

#region GetOtherDBFieldValue
		[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
			public string ajaxGetOtherDBFieldValue(string pDBType,string pSql,string pConn,string pFieldName)
			{
				string tResult = "";
				DataSet tDs = new DataSet();
				if (pDBType == "SqlServer")
				{
					SqlConnection tDbConnection = new SqlConnection(pConn);
					tDbConnection.Open();
					SqlDataAdapter tAdpt = new SqlDataAdapter(pSql, pConn);
					tAdpt.Fill(tDs, "Result");
				}
				else if (pDBType == "Oracle")
				{
					OracleConnection tDbConnection = new OracleConnection (pConn);
					tDbConnection.Open();
					OracleDataAdapter tAdpt = new OracleDataAdapter (pSql, pConn);
					tAdpt.Fill(tDs, "Result");
				}
				else if (pDBType == "OleDb")
				{
					OleDbConnection tDbConnection = new OleDbConnection (pConn);
					tDbConnection.Open();
					OleDbDataAdapter tAdpt = new OleDbDataAdapter (pSql, pConn);
					tAdpt.Fill(tDs, "Result");
				}
				else if (pDBType == "Odbc")
				{
					OdbcConnection tDbConnection = new OdbcConnection (pConn);
					tDbConnection.Open();
					OdbcDataAdapter tAdpt = new OdbcDataAdapter (pSql, pConn);
					tAdpt.Fill(tDs, "Result");
				}

				DataTable tDt = tDs.Tables["Result"];
				if (tDt != null)
				{
					if (tDt.Rows.Count > 0)
					{
						tResult = tDt.Rows[0]["\""+pFieldName+"\""].ToString().Trim();
					}
				}
				return tResult;
			}
#endregion

既然已經有現成的Ajax可以取得關於表單相關的資訊,為何不拿來好好利用呢?那該如何使用由 AjaxPro 函式庫,所提供出來的Ajax呢?可以像下面這樣來取得值..

<script type="text/javascript">
            $(function () {                                alert(tw.com.dsc.easyflowDotNet.forms.TEST2.ajaxGetEmployeeId().value);                
            });

</script>

上面有些地方需要說明:

  • 1. tw.com.dsc.easyflowDotNet 是命名空間,需加在類別之前。
  • 2. TEST2 是表單的類別名稱,需要加在命名空間及Ajax後端函式的中間。
  • 綜合上述兩點在前端叫用Ajax函式時像是這樣 「命名空間.表單類別.Ajax後端函式([參數值…])」。

為什麼使用方法很簡單呢?因為Easyflow已經將Ajaxpro函式庫的DLL檔引用進入網頁應用程式,並也已經設定Web.config設定檔註冊HttpHandler,並在表單後端Page_Load時註冊包含Ajax函式的類別。如果想了解 AjaxPro 從安裝到使用的詳細說明,可以造訪 http://www.ajaxpro.info/ 網站。

發表迴響

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

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