public DataView FilterDataTable(BE_Extend paramBE_Extend, DataTable paramDataTable, GridElement Element) { DataTable ds = GetFilterTable(paramBE_Extend, paramDataTable, Element, true); DataTable paramData = (ds != null ? ds : paramDataTable); DataTable result = GetFilterTable(paramBE_Extend, paramData, Element, false); return(result.DefaultView); }
private DataTable GetFilterTable(BE_Extend paramBE_Extend, DataTable paramDataTable, GridElement Element, Boolean IsLeftParent) { if (paramBE_Extend == null) { return(new DataTable()); } else { List <DataTable> ParentDataTable = new List <DataTable>(); List <DataTable> SubDataTable = new List <DataTable>(); List <String> ParentPrimaryColumns = new List <string>(); List <String> ChildPrimaryColumns = new List <string>(); Dictionary <String, List <String> > RowFilters = new Dictionary <string, List <string> >(); ReportCommon.DataColumn DataColumn = Element.Value as ReportCommon.DataColumn; GridElement ChildElement = Element; ReportCommon.DataColumn ChildColumn = ChildElement.Value as ReportCommon.DataColumn; PE paramPE = paramBE_Extend; while (paramPE != null) { GridElement ParentElement = null; ReportCommon.DataColumn ParentColumn = null; if (paramPE is BE_Extend) { BE_Extend temp = paramPE as BE_Extend; ParentElement = temp.beb.ce_from as GridElement; ParentColumn = ParentElement.Value as ReportCommon.DataColumn; } else if (paramPE is CE_Extend) { CE_Extend temp = paramPE as CE_Extend; ParentElement = temp.be_from.beb.ce_from as GridElement; ParentColumn = ParentElement.Value as ReportCommon.DataColumn; } if (ParentElement == null || ParentColumn == null) { break; } if (IsLeftParent) { if (Element.ExpandOrientation.Orientation == ExpandOrientation.TopToBottom && ParentElement.ExpandOrientation.Orientation == ExpandOrientation.LeftToRight) { break; } } else { if (Element.ExpandOrientation.Orientation == ExpandOrientation.LeftToRight && ParentElement.ExpandOrientation.Orientation == ExpandOrientation.TopToBottom) { break; } } if (!RowFilters.ContainsKey(ParentColumn.TableName.ToLower())) { RowFilters.Add(ParentColumn.TableName.ToLower(), new List <String>()); } DataTable ds = (ParentColumn.TableName.ToLower() == paramDataTable.TableName.ToLower() ? paramDataTable : dataSources[ParentColumn.TableName.ToLower()]); ParentDataTable.Add(ds); String strFilter = ""; if (paramPE is CE_Extend) { CE_Extend temp = paramPE as CE_Extend; strFilter = GetField_ValueString(ds, ParentColumn.FieldName, CompareOperation.等于, temp.obj); } RowFilters[ParentColumn.TableName.ToLower()].Add(strFilter); DataTable subds = (ChildColumn.TableName.ToLower() == paramDataTable.TableName.ToLower() ? paramDataTable : dataSources[ChildColumn.TableName.ToLower()]); SubDataTable.Add(subds); List <FilterCondition> FilterConditions = ChildColumn.DataFilter.FilterConditions; Boolean HaveRelation = true; foreach (FilterCondition FilterCondition in FilterConditions) { String str; Item Item = FilterCondition.RightItem; switch (Item.Style) { case FilterStyle.DataColumn: ChildPrimaryColumns.Add(FilterCondition.LeftItem.FieldName); ParentPrimaryColumns.Add(FilterCondition.RightItem.FieldName); break; case FilterStyle.Value: str = GetField_ValueString(subds, FilterCondition.LeftItem.FieldName, FilterCondition.CompareOperation, Item.Value); RowFilters[ChildColumn.TableName.ToLower()].Add(str); break; case FilterStyle.Parameter: ReportParameter param = parameterList[Item.ParameterName] as ReportParameter; str = GetField_ValueString(subds, FilterCondition.LeftItem.FieldName, FilterCondition.CompareOperation, param.Value); RowFilters[ChildColumn.TableName.ToLower()].Add(str); break; } HaveRelation = HaveRelation && Item.Style == FilterStyle.DataColumn; } if (!HaveRelation || ChildColumn.DataFilter.FilterConditions.Count == 0) { ChildPrimaryColumns.Add(""); ParentPrimaryColumns.Add(""); } ChildElement = ParentElement; ChildColumn = ChildElement.Value as ReportCommon.DataColumn; if (paramPE is BE_Extend) { BE_Extend temp = paramPE as BE_Extend; paramPE = (IsLeftParent ? temp.left : temp.up); } else if (paramPE is CE_Extend) { CE_Extend temp = paramPE as CE_Extend; paramPE = (IsLeftParent ? temp.be_from.left : temp.be_from.up); } } if (ParentDataTable.Count > 0) { DataTable TemTable = ParentDataTable[ParentDataTable.Count - 1]; for (int i = ParentDataTable.Count - 1; i >= 0; i--) { List <String> Filters = RowFilters[TemTable.TableName.ToLower()]; List <String> temp = new List <string>(); foreach (String str in Filters) { if (str != "") { temp.Add(str); } } String strFilters = ""; if (temp.Count > 0) { strFilters = string.Join(" and ", temp.ToArray()); } TemTable = GetRelationTable(TemTable, SubDataTable[i], ParentPrimaryColumns[i], ChildPrimaryColumns[i], strFilters); } DataTable Result = TemTable.DefaultView.ToTable(); return(Result); } else { DataTable Result = dataSources[DataColumn.TableName.ToLower()].DefaultView.ToTable(); return(Result); } } }