/// <summary> /// 處理區間條件。 /// </summary> /// <param name="fieldDefine">欄位定義。</param> /// <param name="filterItem">資料過濾條件項目。</param> /// <param name="isDetail">是否為明細欄位。</param> private string ProcessBetween(GFieldDefine fieldDefine, GFilterItem filterItem, bool isDetail) { StringBuilder oBuilder; string sFieldName; string[] oFilterValues; object oMinValue; object oMaxValue; DateTime oStartDate; DateTime oEndDate; string sMinParameterName; string sMaxParameterName; sFieldName = GetFieldName(fieldDefine, isDetail); if (StrFunc.StrIsEmpty(sFieldName)) { return(string.Empty); } oBuilder = new StringBuilder(); oFilterValues = StrFunc.StrSplit(filterItem.FilterValue, ","); if (oFilterValues.Length != 2) { return(string.Empty); } if (fieldDefine.DbType == EFieldDbType.DateTime) { // 起始日 oStartDate = BaseFunc.CDateTime(oFilterValues[0]); sMinParameterName = GetDbParameter(fieldDefine, filterItem.ComparisonOperator, oStartDate); // 終止日+1 oEndDate = BaseFunc.CDateTime(oFilterValues[1]); sMaxParameterName = GetDbParameter(fieldDefine, filterItem.ComparisonOperator, DateFunc.AddDays(oEndDate, 1)); // 傳回過濾條件,日期區間需大於等於 [起始日] And 小於 [終止日+1] return(StrFunc.StrFormat("({0} >= {1} And {0} < {2})", sFieldName, sMinParameterName, sMaxParameterName)); } else { // 起始值 oMinValue = BaseFunc.CFieldValue(fieldDefine.DbType, oFilterValues[0]); sMinParameterName = GetDbParameter(fieldDefine, filterItem.ComparisonOperator, oMinValue); // 終止值 oMaxValue = BaseFunc.CFieldValue(fieldDefine.DbType, oFilterValues[1]); sMaxParameterName = GetDbParameter(fieldDefine, filterItem.ComparisonOperator, oMaxValue); // 傳回過濾條件 return(StrFunc.StrFormat("({0} >= {1} And {0} <= {2})", sFieldName, sMinParameterName, sMaxParameterName)); } }
/// <summary> /// 處理一般條件。 /// </summary> /// <param name="fieldDefine">欄位定義。</param> /// <param name="filterItem">資料過濾條件項目。</param> /// <param name="isDetail">是否為明細欄位。</param> private string ProcessItem(GFieldDefine fieldDefine, GFilterItem filterItem, bool isDetail) { string sFieldName; string sParameterName; string sComparisonOperator; object oValue; sFieldName = GetFieldName(fieldDefine, isDetail); if (StrFunc.StrIsEmpty(sFieldName)) { return(string.Empty); } if (StrFunc.SameText(filterItem.FilterValue, "DB.NULL")) { return(StrFunc.StrFormat("{0} Is Null", sFieldName)); } else if (StrFunc.SameText(filterItem.FilterValue, "DB.NOTNULL")) { return(StrFunc.StrFormat("{0} Is Not Null", sFieldName)); } else { if (fieldDefine.DbType == EFieldDbType.DateTime && (filterItem.ComparisonOperator == EComparisonOperator.Equal || filterItem.ComparisonOperator == EComparisonOperator.Like)) { // DateTime 型別設 Equal 或 Like 皆視為等於,要以區間條件處理 return(ProcessDateTime(fieldDefine, filterItem, isDetail)); } else { sComparisonOperator = filterItem.GetComparisonText(); oValue = BaseFunc.CFieldValue(fieldDefine.DbType, filterItem.FilterValue, DBNull.Value); if (BaseFunc.IsDBNull(oValue)) { return(string.Empty); } sParameterName = GetDbParameter(fieldDefine, filterItem.ComparisonOperator, oValue); return(StrFunc.StrFormat("{0} {1} {2}", sFieldName, sComparisonOperator, sParameterName)); } } }