From 9f7b8f44b8659cce44d4ce7b52bb9404e4dd92c0 Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Sat, 23 Aug 2014 16:24:01 +0200 Subject: [PATCH] PushModel generation --- .../ICSharpCode.Reporting.Addin.csproj | 5 ++ .../src/DesignableItems/ReportSettings.cs | 2 + .../src/Globals/GlobalLists.cs | 2 +- .../Dialog/BaseSettingsPage.xaml.cs | 4 +- .../ReportWizard/Dialog/PushDataReport.xaml | 18 +++++-- .../Dialog/PushDataReport.xaml.cs | 47 ++++++++++++++++++- .../src/ReportWizard/ReportGenerator.cs | 31 ++++++------ .../Src/BaseClasses/AbstractColumn.cs | 29 ++---------- .../Src/BaseClasses/ExtensionMethods.cs | 9 +++- .../Src/Items/BaseTextItem.cs | 2 +- .../Src/ReportingFactory.cs | 19 +++++++- 11 files changed, 115 insertions(+), 53 deletions(-) diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj index 6213368704..35fdf67bba 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj @@ -213,6 +213,11 @@ + + {3B2A5653-EC97-4001-BB9B-D90F1AF2C371} + ICSharpCode.NRefactory + False + {2748AD25-9C63-4E12-877B-4DCE96FBED54} ICSharpCode.SharpDevelop diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/ReportSettings.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/ReportSettings.cs index 43a4f72fdf..ff04752a03 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/ReportSettings.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/ReportSettings.cs @@ -145,5 +145,7 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems public SortColumnCollection SortColumnsCollection {get;private set;} public GroupColumnCollection GroupColumnsCollection {get;private set;} + + } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Globals/GlobalLists.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Globals/GlobalLists.cs index c6ad60e79a..684d501278 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Globals/GlobalLists.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Globals/GlobalLists.cs @@ -28,7 +28,7 @@ namespace ICSharpCode.Reporting.Addin.Globals "System.DateTime", "System.TimeSpan", "System.Decimal", - "System.Int"}; + "System.Int32"}; #endregion diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml.cs index adacd5af0d..2061e2316f 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml.cs @@ -56,12 +56,12 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard.Dialog{ var cbo = (ComboBox) sender; var pushPullModel = (PushPullModel)cbo.SelectedItem; - + switch (pushPullModel) { case PushPullModel.PushData: { this._ReportType.SelectedItem = ReportType.DataReport; this.CanFinish = false; - this.CanSelectNextPage = true; + this.CanSelectNextPage = true; break; } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/PushDataReport.xaml b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/PushDataReport.xaml index 9a30f432ee..65c71efe10 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/PushDataReport.xaml +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/PushDataReport.xaml @@ -6,7 +6,7 @@ xmlns:sdr="clr-namespace:ICSharpCode.Reporting.Globals;assembly=ICSharpCode.Reporting" Name="PushData" Title="SharpDevelop Reporting" - Description="Create Columns for a PusData Report" + PageType="Interior" CanFinish="true" CancelButtonVisibility="Visible" @@ -14,20 +14,28 @@ CanSelectNextPage="false"> + + + + + + + + + + AutoGenerateColumns="False" Grid.Row="1" Grid.RowSpan="2" Margin="30,10,30,5" Width="400" Grid.Column="1"> - - + + diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/PushDataReport.xaml.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/PushDataReport.xaml.cs index d08ce70bd8..51cc316010 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/PushDataReport.xaml.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/PushDataReport.xaml.cs @@ -8,9 +8,12 @@ */ using System; using System.Collections.Generic; +using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.Reporting.BaseClasses; using Xceed.Wpf.Toolkit; +using ICSharpCode.Reporting.Addin.Globals; using ICSharpCode.Reporting.Addin.ReportWizard.ViewModels; +using System.Linq; namespace ICSharpCode.Reporting.Addin.ReportWizard.Dialog { @@ -20,21 +23,59 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard.Dialog public partial class PushDataReport : WizardPage,IHasContext { List items; + List types; + PushModelContext context; public PushDataReport() { InitializeComponent(); items = new List(); + types = new List(); _DataGrid.ItemsSource = items; this.context = new PushModelContext(); var data = new AbstractColumn("MyColumn",typeof(string)); items.Add(data); + cboType.ItemsSource = GlobalLists.DataTypeList(); + var definitions = GetTypeDefinitions(); + + if (definitions != null) { + _cboTypes.Visibility = System.Windows.Visibility.Visible; + _cboTypes.ItemsSource = definitions; + _cboTypes.SelectedIndex = 0; + } + } - - void UpdateContext() + static IEnumerable GetTypeDefinitions() { + var currentProject = SharpDevelop.SD.ProjectService.CurrentProject; + var compilation = SharpDevelop.SD.ParserService.GetCompilation(currentProject); + var definitions = compilation.MainAssembly.TopLevelTypeDefinitions.Where(x => x.Properties.Any()); + return definitions; + } + + + #region Combo + + void _cboTypes_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e){ + + var s = (ITypeDefinition)e.AddedItems[0]; + var l = CreateItemsSource(s); + if (l.Count > 0) { + _DataGrid.ItemsSource = l; + } + } + + static List CreateItemsSource(ITypeDefinition s){ + return s.Properties.Select(p => new AbstractColumn(){ + ColumnName = p.Name, + DataTypeName = p.ReturnType.ReflectionName + }).ToList(); + } + #endregion + + void UpdateContext(){ context.Items = (List)_DataGrid.ItemsSource; } @@ -51,6 +92,8 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard.Dialog public WizardPageType ReportPageType { get {return WizardPageType.PushModelPage;} } + + #endregion } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs index 2c01bb8749..42947cd5e2 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs @@ -11,7 +11,7 @@ using System.Drawing; using ICSharpCode.Reporting.Factories; using ICSharpCode.Reporting.Globals; using ICSharpCode.Reporting.Interfaces; - +using ICSharpCode.Reporting.BaseClasses; using ICSharpCode.Reporting.Items; using ICSharpCode.Reporting.Addin.ReportWizard.ViewModels; @@ -35,8 +35,8 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard if (context == null) throw new ArgumentNullException("context"); - var poc = (PageOneContext)context.PageOneContext; - if (IsDataReport(poc)) { + + if (IsDataReport(context)) { CreateDataReport (context); } else { CreateFormSheetReport(context); @@ -90,25 +90,28 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard void CreateReportHeader(ReportWizardContext context){ var pageOneContext = (PageOneContext)context.PageOneContext; - var headerText = new BaseTextItem(); - if (String.IsNullOrEmpty(pageOneContext.ReportName)) { - headerText.Text = GlobalValues.DefaultReportName; - } else { - headerText.Text = pageOneContext.ReportName; - } + var headerText = new BaseTextItem(); - headerText.Size = GlobalValues.PreferedSize; - var printableWith = ReportModel.ReportSettings.PageSize.Width - ReportModel.ReportSettings.LeftMargin - ReportModel.ReportSettings.RightMargin; + headerText.Text = String.IsNullOrEmpty(pageOneContext.ReportName) ? GlobalValues.DefaultReportName : pageOneContext.ReportName; - var x = (int)(printableWith - headerText.Size.Width) / 2; - headerText.Location = new Point(x,4); + var xLoc = (ReportModel.ReportSettings.PrintableWidth() - headerText.Size.Width) / 2; + headerText.Location = new Point(xLoc,4); ReportModel.ReportHeader.Items.Add(headerText); + xLoc = ReportModel.ReportSettings.PrintableWidth() - GlobalValues.PreferedSize.Width - 20; + + var dateText = new BaseTextItem(){ + Text ="= Today.Today", + Location = new Point(xLoc ,10) + }; + ReportModel.ReportHeader.Items.Add(dateText); } - static bool IsDataReport(PageOneContext poc) + + static bool IsDataReport(ReportWizardContext context) { + var poc = (PageOneContext)context.PageOneContext; return poc.ReportType.Equals(ReportType.DataReport); } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/AbstractColumn.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/AbstractColumn.cs index ed3bff6643..616cb28d72 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/AbstractColumn.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/AbstractColumn.cs @@ -26,42 +26,19 @@ namespace ICSharpCode.Reporting.BaseClasses /// public class AbstractColumn { - Type dataType; - string dataTypeName; public AbstractColumn() { - this.dataType = typeof(System.String); + this.DataTypeName = typeof(String).FullName; } - public AbstractColumn(string columnName, Type dataType){ this.ColumnName = columnName; - this.dataType = dataType; + this.DataTypeName = dataType.FullName; } public string ColumnName {get;set;} + public string DataTypeName {get;set;} - - public string DataTypeName { - get { - return this.dataType.ToString(); - } - set { - dataTypeName = value; - this.dataType = Type.GetType(dataTypeName,true,true); - } - } - -// [XmlIgnoreAttribute] - public Type DataType { - get { - return dataType; - } - set { - dataType = value; - } - } - } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/ExtensionMethods.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/ExtensionMethods.cs index a73d3984fc..e47c5d5f2e 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/ExtensionMethods.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/ExtensionMethods.cs @@ -20,6 +20,8 @@ using System; using System.Collections.Generic; using System.Windows; using System.Windows.Media; +using ICSharpCode.Reporting.Items; + namespace ICSharpCode.Reporting.BaseClasses { /// @@ -28,7 +30,7 @@ namespace ICSharpCode.Reporting.BaseClasses /// ///