Ejemplo n.º 1
0
 /// <summary>
 /// 取得欄位值後轉型成string
 /// </summary>
 /// <param name="fieldName">欄位名稱</param>
 /// <returns></returns>
 public string ValueAsString(string fieldName)
 {
     if (this.HasField(fieldName))
     {
         return(BaseFunc.CStr(this[fieldName]));
     }
     return("");
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 取得篩選值。
 /// </summary>
 /// <param name="dbType">欄位資料型別。</param>
 /// <param name="value">輸入值。</param>
 private string GetFilterValue(EFieldDbType dbType, object value)
 {
     if (dbType == EFieldDbType.DateTime)
     {
         if (BaseFunc.IsNullOrDBNull(value))
         {
             return(string.Empty);
         }
         else
         {
             return(BaseFunc.CDateTime(value).ToString("yyyy/MM/dd"));
         }
     }
     else
     {
         return(BaseFunc.CStr(value));
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 解析過濾條件中的欄位變數。
        /// </summary>
        /// <param name="dataSet">資料集。</param>
        /// <param name="tableName">作用資料表名稱。</param>
        /// <param name="rowIndex">作用資料列索引。</param>
        public GFilterItemCollection ParseField(DataSet dataSet, string tableName, int rowIndex)
        {
            var oFilterItems = new GFilterItemCollection();

            foreach (GFilterItem item in this.FilterItems)
            {
                // 產生過濾條件複本
                var oFilterItem = item.Clone();
                // 解析變數值
                this.VariableParser.Parse(item.FilterValue);
                // 變數類型
                var oVariableType = this.VariableParser.VariableType;
                // 取得欄位變數的值
                if (oVariableType == EVariableType.Field || oVariableType == EVariableType.TableField)
                {
                    // 拆解字串的資料表名稱及欄位名稱
                    StrFunc.StrSplitFieldName(this.VariableParser.Value, out string sTableName, out string sFieldName);
                    if (StrFunc.StrIsEmpty(sTableName))
                    {
                        sTableName = tableName;
                    }
                    // 取得作用資料列
                    var oRow = GetDataRow(dataSet, sTableName, sFieldName, rowIndex);
                    if (BaseFunc.IsNotNull(oRow))
                    {
                        oFilterItem.FilterValue = BaseFunc.CStr(oRow[sFieldName]);
                    }
                    else
                    {
                        oFilterItem.FilterValue = string.Empty;
                    }
                }
                oFilterItems.Add(oFilterItem);
            }

            // 移除無查詢值的條件
            oFilterItems.RemoveEmpty();
            return(oFilterItems);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 取得群組過濾條件集合。
        /// </summary>
        /// <param name="filterItems">過濾條件項目集合。</param>
        private GDictionary <GFilterItemCollection> GetGroupFilterItems(GFilterItemCollection filterItems)
        {
            GDictionary <GFilterItemCollection> oList;
            GFilterItemCollection oFilterItems;
            string sGroupNumber;

            oList = new GDictionary <GFilterItemCollection>();
            foreach (GFilterItem filterItem in filterItems)
            {
                sGroupNumber = BaseFunc.CStr(filterItem.GroupNumber);
                if (!oList.ContainsKey(sGroupNumber))
                {
                    oFilterItems = new GFilterItemCollection();
                    oFilterItems.Add(filterItem);
                    oList.Add(sGroupNumber, oFilterItems);
                }
                else
                {
                    oList[sGroupNumber].Add(filterItem);
                }
            }
            return(oList);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 取得 Db Parameter 的回傳的參數。
        /// </summary>
        /// <param name="fieldDefine">欄位定義。</param>
        /// <param name="comparison">比較運算子。</param>
        /// <param name="value">過濾條件值。</param>
        private string GetDbParameter(GFieldDefine fieldDefine, EComparisonOperator comparison, object value)
        {
            var oDbParameter = this.DbCommandHelper.AddFilterParameter(fieldDefine);

            if (comparison == EComparisonOperator.Like &&
                (fieldDefine.DbType == EFieldDbType.String || fieldDefine.DbType == EFieldDbType.Text))
            {
                // Like 加入 % 符號
                if (BaseFunc.CStr(value).Contains("%"))
                {
                    oDbParameter.Value = value;
                }
                else
                {
                    oDbParameter.Value = StrFunc.StrFormat("%{0}%", value);
                }
            }
            else
            {
                oDbParameter.Value = value;
            }

            return(oDbParameter.ParameterName);
        }