using System; using System.Data; using static iMESCore.DataBase.iMESSql; using iMESCore.Settings; using iMESException; using Microsoft.VisualBasic; using Microsoft.VisualBasic.CompilerServices; namespace udSYS_Customer { public class clsSerialNoFunction : IDisposable { private AppSettings objSetting = new AppSettings(); private IDbConnection cnnTemp; private IDbCommand cmmTemp; private string strConnectionString; // Connection string private string strDataBaseType; // DataBase Type:oracle, mysql, access private string strMQType; // MessageQueue Type:TIBCO, MQSeries, MSMQ private string strSQLAddField; private string strSQLAddValue; private string strSQL; #region IDisposable Support private bool disposedValue; // 偵測多餘的呼叫 // //Initial Object---------------------------------- public clsSerialNoFunction() { // //Get database type strDataBaseType = objSetting.GetDataBaseType(); // //Get connection string strConnectionString = objSetting.GetConnectionString(strDataBaseType); // //Get Message Queue Type strMQType = objSetting.GetMQType(); } // IDisposable protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // TODO: 處置 Managed 狀態 (Managed 物件)。 } // 釋放 Unmanaged 資源 (Unmanaged 物件) 並覆寫下方的 Finalize()。 if (objSetting != null) objSetting = null; // 將大型欄位設為 null。 } disposedValue = true; } // 只有當上方的 Dispose(disposing As Boolean) 具有要釋放 Unmanaged 資源的程式碼時,才覆寫 Finalize()。 ~clsSerialNoFunction() { // 請勿變更這個程式碼。請將清除程式碼放在上方的 Dispose(disposing As Boolean) 中。 Dispose(false); } // Visual Basic 加入這個程式碼的目的,在於能正確地實作可處置的模式。 public void Dispose() { // 請勿變更這個程式碼。請將清除程式碼放在上方的 Dispose(disposing As Boolean) 中。 Dispose(true); // 覆寫上列 Finalize() 時,取消下行的註解狀態。 GC.SuppressFinalize(this); } #endregion #region --- Property --- public string ConnectionString { get { return strConnectionString; } } public string DataBaseType { get { return strDataBaseType; } } public string MQType { get { return strMQType; } } #endregion // 2018/04/10 OwenLiu, Mantis:0045761, 增加客製 SerialNoFunction 支援機制 // colParameters 變更為下述格式(FunctionName 及 . 可省略) // [FunctionName][.] // FunctionName 必須以 funC_ 作為名稱的前綴字串,才可以正常運作 // 前端(WinForm)呼叫範例(新開發的功能,儘量以 <.> 方式加入,以避免同樣的Key 對不同的ScriptFunction // 有不同的值,造成執行階段引發的錯誤編碼結果 // ----------------------------------------------------------------------------------------------------------- // Dim strAddition As String = "" // Dim aryAdditionKey() As String = {"FabCode", "funC_GetSample.FabCode"} // Dim aryAdditionVal() As String = {"F1_", "F2_"} // If Not aryAdditionKey Is Nothing AndAlso Not aryAdditionKey.Length.Equals(0) Then // For i As Integer = LBound(aryAdditionKey) To UBound(aryAdditionKey) // strAddition += CombineAddXML_Add(aryAdditionKey(i), "String", CInput(aryAdditionVal(i))) // Next i // strParameter += CombineXMLAdditional(strAddition) // End If // ----------------------------------------------------------------------------------------------------------- public string funC_GetSample(Collection colParameters) { IDbConnection cnnTemp = null; string strResult = string.Empty; string strFunctionName = System.Reflection.MethodBase.GetCurrentMethod().Name; string strParameterKey = string.Empty; string FabCode = string.Empty; try { // 建立連線 cnnTemp = CreateConnection_None(strConnectionString, strDataBaseType); // 取出參數 strParameterKey = "FabCode"; if (colParameters.Contains(strFunctionName + "." + strParameterKey)) { // 有只針對此Function傳入的Parameter FabCode = Conversions.ToString(colParameters[strFunctionName + "." + strParameterKey]); } else if (colParameters.Contains(strParameterKey)) { // 泛用的Parameter FabCode = Conversions.ToString(colParameters[strParameterKey]); } else { // 找不到傳入的Parameter throw new MESException("0000-200002", "[%Parameter%] [%not found%]: [%" + strParameterKey + "%]"); } strResult = FabCode; } catch (Exception ex) { throw; } finally { // 關閉連線 CloseConnection(cnnTemp); } return strResult; } } }