void SubMenuItem_Click(object sender, EventArgs e) { Object value = null; ToolStripMenuItem MenuItem = sender as ToolStripMenuItem; if (MenuItem != null) { switch (MenuItem.Text) { case "数据列": value = new ReportCommon.DataColumn(); break; case "普通文本": value = new LiteralText(); break; case "公式": value = new Formula(); break; case "图表": value = new ChartPainter(); break; case "图片": value = new ReportCommon.Picture(); break; case "斜线": value = new Slash(); break; case "变量": value = new Variable(); break; } if (value != null) { ActiveSheet.ActiveCell.CellType = general; ReportElementEventArgs elementevent = new ReportElementEventArgs(); elementevent.Value = value; OnReportElementAdding(elementevent); } else { String msg = "当前版本不支持" + MenuItem.Text + "报表元素。"; MessageBox.Show(msg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
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); } } }