/// <summary> /// 解析變數。 /// </summary> /// <param name="value">解析值。</param> /// <remarks> /// 只對單一欄位解析,如:[@@Session]、[@FieldName]、[@Table.FieldName] 與常數。 /// </remarks> public void Parse(string value) { Regex oRegex; MatchCollection oMatches; GroupCollection oGroups; string sPattern; string sWord; string[] oArray; sPattern = @"\[(?<word>@+[\w]*.?[\w]*)\]"; oRegex = new Regex(sPattern, RegexOptions.IgnoreCase); oMatches = oRegex.Matches(value); foreach (Match m in oMatches) { oGroups = m.Groups; sWord = oGroups["word"].Value; if (sWord.Contains("@@")) { // 系統變數 _Value = StrFunc.StrSubstring(sWord, 2); _VariableType = EVariableType.Variable; } else if (sWord.Contains("@")) { // 欄位變數 _Value = StrFunc.StrSubstring(sWord, 1); if (sWord.Contains(".")) { // 資料欄位,格式為 [@Table.FieldName],但其中 [@DB.NULL] 或 [@DB.NOTNULL] 為常數 oArray = StrFunc.StrSplit(this.Value, "."); if (oArray.Length > 0) { if (StrFunc.SameText(StrFunc.StrUpper(oArray[0]), "DB")) { _VariableType = EVariableType.Constant; // DB.NULL 或 DB.NOTNULL 為常數 } else { _VariableType = EVariableType.TableField; } } } else { // 欄位變數,格式為 [@FieldName] _VariableType = EVariableType.Field; // 格式為 [@Table.FieldName] } } return; } _Value = value; _VariableType = EVariableType.Constant; }
/// <summary> /// 設定資料庫命令字串,並用命令參數集合做格式化字串。 /// </summary> /// <param name="commandText">命令字串。</param> public void SetCommandFormatText(string commandText) { StringBuilder oBuffer; if (StrFunc.StrContains(commandText, CommandTextVariable.Parameters)) { oBuffer = new StringBuilder(); for (int N1 = 0; N1 < this.DbCommand.Parameters.Count; N1++) { StrFunc.StrMerge(oBuffer, "{" + N1 + "}", ","); } commandText = StrFunc.StrReplace(commandText, CommandTextVariable.Parameters, oBuffer.ToString()); } commandText = StrFunc.StrUpper(commandText); this.DbCommand.CommandText = StrFunc.SQLFormat(commandText, this.DbCommand.Parameters); }
/// <summary> /// 設定資料庫命令字串。 /// </summary> /// <param name="commandText">命令字串。</param> public void SetCommandText(string commandText) { this.DbCommand.CommandText = StrFunc.StrUpper(commandText); }