/// <summary> /// 取得關連明細資料表使用欄位集合。 /// </summary> /// <param name="useFields">取得使用的欄位集合。</param> /// <param name="detailTableName">傳回明細資料表名稱。</param> private GStringHashSet GetUseDetailTableFields(GStringHashSet useFields, out string detailTableName) { GStringHashSet oUseFields; string sDetailTableName; string sTableName; string sFieldName; sDetailTableName = string.Empty; oUseFields = new GStringHashSet(); foreach (string fieldName in useFields) { if (StrFunc.StrContains(fieldName, ".")) { // 折解資料表及欄位名稱 StrFunc.StrSplitFieldName(fieldName, out sTableName, out sFieldName); // 主檔不能同時 Join 多個明細資料表 if (StrFunc.StrIsNotEmpty(sDetailTableName) && !StrFunc.SameText(sDetailTableName, sTableName)) { throw new GException("Master Table can't Join multi Detail Table"); } sDetailTableName = sTableName; oUseFields.Add(sFieldName); } } detailTableName = sDetailTableName; return(oUseFields); }
/// <summary> /// 解析並移除不需要的 [欄位變數] 過濾條件。 /// </summary> /// <param name="programDefine">程式定義。</param> public GFilterItemCollection ParseRemoveField(GProgramDefine programDefine) { GFilterItemCollection oFilterItems; GFilterItem oFilterItem; GFieldDefine oFieldDefine; EVariableType oVariableType; string sTableName; string sFieldName; oFilterItems = new GFilterItemCollection(); foreach (GFilterItem item in this.FilterItems) { // 產生過濾條件複本 oFilterItem = item.Clone(); // 解析變數值 this.VariableParser.Parse(item.FilterValue); // 變數類型 oVariableType = this.VariableParser.VariableType; if (oVariableType == EVariableType.Field || oVariableType == EVariableType.TableField) { // 拆解字串的資料表名稱及欄位名稱 StrFunc.StrSplitFieldName(this.VariableParser.Value, out sTableName, out sFieldName); if (StrFunc.StrIsEmpty(sTableName)) { sTableName = programDefine.ProgID; } // 只保留存在的 [欄位變數] 過濾條件 oFieldDefine = programDefine.FindField(sTableName, sFieldName); if (BaseFunc.IsNotNull(oFieldDefine)) { oFilterItems.Add(oFilterItem); } } else { // 加入非 [欄位變數] 過濾條件 oFilterItems.Add(oFilterItem); } } // 移除無查詢值的條件 oFilterItems.RemoveEmpty(); return(oFilterItems); }
/// <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); }
/// <summary> /// 處理單一條件。 /// </summary> /// <param name="filterItem">資料過濾條件項目。</param> private string ProcessFilterItem(GFilterItem filterItem) { GFieldDefine oFieldDefine; string sTableName; string sFieldName; bool bDetail; StrFunc.StrSplitFieldName(filterItem.FieldName, out sTableName, out sFieldName); if (StrFunc.StrIsEmpty(sTableName)) { sTableName = this.Args.TableName; bDetail = false; } else { bDetail = true; } oFieldDefine = this.Args.ProgramDefine.Tables[sTableName].Fields[sFieldName]; if (BaseFunc.IsNull(oFieldDefine)) { return(string.Empty); } switch (filterItem.ComparisonOperator) { case EComparisonOperator.Between: return(ProcessBetween(oFieldDefine, filterItem, bDetail)); case EComparisonOperator.In: return(ProcessIn(oFieldDefine, filterItem, bDetail)); case EComparisonOperator.NotIn: return(ProcessIn(oFieldDefine, filterItem, bDetail, false)); default: return(ProcessItem(oFieldDefine, filterItem, bDetail)); } }