From 43ae1764569d9dc78ff8385b74ac7631f9337734 Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Sun, 5 Feb 2006 17:31:43 +0000 Subject: [PATCH] Further refactoring of ReportGenerator, new Exception MissingModelException.cs added git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1071 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../SharpReport/SharpReport/AutoReport.cs | 70 ++++++--- .../Functions/MiscFunctions/PageNumber.cs | 1 + .../SharpReport/SharpReportManager.cs | 9 +- .../FieldsExplorer/FieldsExplorer.cs | 2 +- .../BaseItems/Graphics/BaseImageItem.cs | 16 +- .../Exceptions/MissingModelException.cs | 37 +++++ .../Printing/AbstractRenderer.cs | 1 - .../Printing/RenderDataReport.cs | 1 - .../Printing/ReportDocument.cs | 3 - .../SharpReportCore/SharpReportCore.csproj | 1 + .../SharpReportCore/SharpReportEngine.cs | 20 +-- .../SharpReportWizard/GeneratorCommands.cs | 106 +++---------- .../Generators/AbstractReportGenerator.cs | 147 +++++------------- .../Generators/GeneratePullDataReport.cs | 42 ++--- .../Generators/GeneratePushDataReport.cs | 18 +-- .../SharpReportWizard/ReportGenerator.cs | 16 +- .../WizardPanels/BaseSettingsPanel.cs | 22 ++- .../WizardPanels/PullModelPanel.cs | 3 + .../WizardPanels/PushModelPanel.cs | 50 ++++-- .../WizardPanels/ResultPanel.cs | 70 +++++---- 20 files changed, 302 insertions(+), 333 deletions(-) create mode 100644 src/AddIns/Misc/SharpReport/SharpReportCore/Exceptions/MissingModelException.cs diff --git a/src/AddIns/Misc/SharpReport/SharpReport/AutoReport.cs b/src/AddIns/Misc/SharpReport/SharpReport/AutoReport.cs index deadcd1600..182e88cc24 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/AutoReport.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/AutoReport.cs @@ -76,7 +76,32 @@ namespace SharpReport { } return itemCol; } + + /// + /// Build a this collection holds all the fields + /// comming from the DataSource + /// + + public ColumnCollection AbstractColumnsFromDataSet(DataSet dataSet) { + if (dataSet.Tables.Count > 1) { + MessageService.ShowError ("AutoBuildFromDataSet : at this time no more than one table is allowed " + dataSet.Tables.Count.ToString()); + throw new ArgumentException ("Too much Tables in DataSet"); + } + ColumnCollection collection = new ColumnCollection(); + foreach (DataTable tbl in dataSet.Tables) { + DataColumn col; + for (int i = 0;i < tbl.Columns.Count ;i++ ) { + col = tbl.Columns[i]; + AbstractColumn abstrColumn = new AbstractColumn(); + abstrColumn.ColumnName = col.ColumnName; + abstrColumn.DataType = col.DataType; + collection.Add (abstrColumn); + } + } + return collection; + } + /// /// Build BaseDataItems from a *.xsd File /// @@ -160,30 +185,33 @@ namespace SharpReport { } - public ReportItemCollection AutoHeaderFromReportItems(ReportItemCollection col,BaseSection section,bool setOnTop) { - if (col != null) { - ReportItemCollection itemCol = new ReportItemCollection(); - ReportDataItem sourceItem = null; - for (int i = 0;i < col.Count ;i++ ){ - BaseTextItem rItem = (BaseTextItem)iDesignableFactory.Create("ReportTextItem"); - if (rItem != null) { - sourceItem = (ReportDataItem)col[i]; - - rItem.Text = sourceItem.ColumnName; - rItem.Text = sourceItem.ColumnName; - if (setOnTop) { - rItem.Location = new Point (i * 30,1); - } else { - int y = section.Size.Height - rItem.Size.Height - 5; - rItem.Location = new Point (i * 30,y); - } - itemCol.Add(rItem); + public ReportItemCollection AutoHeaderFromReportItems(ReportItemCollection reportItemCollection,BaseSection section,bool setOnTop) { + if (reportItemCollection == null) { + throw new ArgumentNullException ("reportItemCollection"); + } + if (section == null) { + throw new ArgumentNullException ("section"); + } + + ReportItemCollection itemCol = new ReportItemCollection(); + ReportDataItem sourceItem = null; + for (int i = 0;i < reportItemCollection.Count ;i++ ){ + BaseTextItem rItem = (BaseTextItem)iDesignableFactory.Create("ReportTextItem"); + if (rItem != null) { + sourceItem = (ReportDataItem)reportItemCollection[i]; + + rItem.Text = sourceItem.ColumnName; + rItem.Text = sourceItem.ColumnName; + if (setOnTop) { + rItem.Location = new Point (i * 30,1); + } else { + int y = section.Size.Height - rItem.Size.Height - 5; + rItem.Location = new Point (i * 30,y); } + itemCol.Add(rItem); } - return itemCol; - }else { - throw new ArgumentNullException ("AutoReport:ReportItemCollection"); } + return itemCol; } #endregion diff --git a/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/Functions/MiscFunctions/PageNumber.cs b/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/Functions/MiscFunctions/PageNumber.cs index 1918d81b2c..1311bc5f58 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/Functions/MiscFunctions/PageNumber.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/Functions/MiscFunctions/PageNumber.cs @@ -47,6 +47,7 @@ namespace SharpReport.ReportItems.Functions { ItemsHelper.UpdateTextControl (this.visualControl,this); this.Text = functionName; + this.visualControl.FunctionValue = String.Empty; GrapFromBase(); this.initDone = true; } diff --git a/src/AddIns/Misc/SharpReport/SharpReport/SharpReportManager.cs b/src/AddIns/Misc/SharpReport/SharpReport/SharpReportManager.cs index 3d13406996..5b894862ef 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/SharpReportManager.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/SharpReportManager.cs @@ -187,6 +187,7 @@ namespace SharpReport{ #endregion #region HeaderColumns + /* /// /// Builds ColumHeaders for Reports, we take the ColumnNames as Text Property /// @@ -207,7 +208,7 @@ namespace SharpReport{ } } } - + */ /// /// Create ColumHeaders for Reports /// @@ -232,7 +233,7 @@ namespace SharpReport{ #region Create report from Query - + /* /// /// Create Columns from SchemaTable /// @@ -258,6 +259,7 @@ namespace SharpReport{ } } } + */ #endregion #region Create Reports from .Xsd Files @@ -291,9 +293,8 @@ namespace SharpReport{ public AbstractRenderer GetRendererForStandartReports (ReportModel model) { - System.Console.WriteLine("Manager.GetRenderer"); if (model == null) { - throw new ArgumentException("SharpReportManager:GetRendererForStandartReports 'ReportModel'"); + throw new ArgumentNullException("model"); } return this.BuildStandartRenderer (model); } diff --git a/src/AddIns/Misc/SharpReport/SharpReportAddin/FieldsExplorer/FieldsExplorer.cs b/src/AddIns/Misc/SharpReport/SharpReportAddin/FieldsExplorer/FieldsExplorer.cs index b44172edec..dcc6da129c 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportAddin/FieldsExplorer/FieldsExplorer.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportAddin/FieldsExplorer/FieldsExplorer.cs @@ -253,7 +253,7 @@ namespace SharpReportAddin { } } catch (Exception er) { - System.Console.WriteLine("\t{0}",er.Message); + System.Console.WriteLine("\tFieldsExplorer {0}",er.Message); } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/Graphics/BaseImageItem.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/Graphics/BaseImageItem.cs index eab504dcb0..9f32e3a0eb 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/Graphics/BaseImageItem.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/Graphics/BaseImageItem.cs @@ -35,19 +35,21 @@ namespace SharpReportCore { public BaseImageItem():base() { } - private void LoadImage (string fName) { - if (fName == "") { - throw new ArgumentException("BaseImageItem:FileName"); + private void LoadImage (string fileName) { + if (String.IsNullOrEmpty(fileName)) { + throw new ArgumentNullException("fileName"); } try { this.image = null; - this.image = Image.FromFile (fName); + this.image = Image.FromFile (fileName); if (image == null) { string str = String.Format(CultureInfo.InvariantCulture, - "Unable to Load {0}",fName); - throw new ApplicationException(str); + "Unable to Load {0}",fileName); + throw new SharpReportException(str); } - } catch (Exception) { + } catch (System.OutOfMemoryException) { + throw; + } catch (System.IO.FileNotFoundException) { throw; } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Exceptions/MissingModelException.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Exceptions/MissingModelException.cs new file mode 100644 index 0000000000..5cf5b35e19 --- /dev/null +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Exceptions/MissingModelException.cs @@ -0,0 +1,37 @@ +/* + * Created by SharpDevelop. + * User: Forstmeier Peter + * Date: 03.02.2006 + * Time: 13:57 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ + +using System; +using System.Runtime.Serialization; +/// +/// Description of MissingModelException. +/// +namespace SharpReportCore{ + + [Serializable()] + public class MissingModelException: System.Exception + { + + public MissingModelException():base(){ + + } + public MissingModelException(string errorMessage) :base (errorMessage){ + + } + public MissingModelException(string errorMessage, + Exception exception):base (errorMessage,exception){ + + } + + protected MissingModelException(SerializationInfo info, + StreamingContext context) : base(info, context){ + // Implement type-specific serialization constructor logic. + } + } +} diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/AbstractRenderer.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/AbstractRenderer.cs index cce58491b8..4310811284 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/AbstractRenderer.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/AbstractRenderer.cs @@ -331,7 +331,6 @@ namespace SharpReportCore { #region property's public ReportDocument ReportDocument { get { - System.Console.WriteLine("Get the AbstractRenderer:ReportDocument"); return reportDocument; } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderDataReport.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderDataReport.cs index e06a1b78f7..91911f95bd 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderDataReport.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderDataReport.cs @@ -61,7 +61,6 @@ namespace SharpReportCore { } protected override void ReportBegin(object sender, ReportPageEventArgs e) { - System.Console.WriteLine("\tRenderDataReport:ReportBegin"); base.ReportBegin (sender,e); //allways reset the dataManager before printing if (this.dataManager != null) { diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/ReportDocument.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/ReportDocument.cs index a9093c3c16..45ad4f5efc 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/ReportDocument.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/ReportDocument.cs @@ -33,7 +33,6 @@ namespace SharpReportCore { public ReportDocument():base() { - System.Console.WriteLine("ReportDocument Constructor"); base.BeginPrint += new PrintEventHandler (ReportDocumentBeginPrint); base.PrintPage += new PrintPageEventHandler (ReportDocumentPrintPage); @@ -43,7 +42,6 @@ namespace SharpReportCore { } void GeneratePage (SharpReportCore.ReportPageEventArgs page) { - System.Console.WriteLine("\tGeneratePage"); if (PrintPageBegin != null) { PrintPageBegin (this,page); } @@ -71,7 +69,6 @@ namespace SharpReportCore { #region events //this events are also used by PrintPreviewControl public void ReportDocumentBeginPrint (object sender,PrintEventArgs e) { - System.Console.WriteLine("\tReportDocument BeginPrint"); pageNr = 0; } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportCore.csproj b/src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportCore.csproj index b980707db9..7fd28a14d4 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportCore.csproj +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportCore.csproj @@ -129,6 +129,7 @@ + diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportEngine.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportEngine.cs index 0183732e89..d93f004f81 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportEngine.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportEngine.cs @@ -336,11 +336,11 @@ namespace SharpReportCore { /// Filename to the location of the ReportFile /// a Datatable, containing the data public void PreviewPushDataReport (string fileName,DataTable dataTable) { - if (fileName.Length == 0) { - throw new ArgumentException("PreviewPushDataReport fileName"); + if (String.IsNullOrEmpty(fileName)) { + throw new ArgumentNullException("fileName"); } if (dataTable == null) { - throw new ArgumentNullException("PreviewPushDataReport dataTable"); + throw new ArgumentNullException("dataTable"); } ReportModel model = null; AbstractRenderer renderer = null; @@ -394,16 +394,16 @@ namespace SharpReportCore { /// Type of renderer currently only "ToText" is implemented public void PrintStandartReport (string fileName) { - if (fileName.Length == 0) { - throw new ArgumentException("PreviewPushDataReport fileName"); + if (String.IsNullOrEmpty(fileName)) { + throw new ArgumentNullException("fileName"); } PrintStandartReport (fileName,null); } public void PrintStandartReport (string fileName,ReportParameters reportParameters) { - if (fileName.Length == 0) { - throw new ArgumentException("PreviewPushDataReport fileName"); + if (String.IsNullOrEmpty(fileName)) { + throw new ArgumentNullException("fileName"); } ReportModel model = null; @@ -430,11 +430,11 @@ namespace SharpReportCore { DataTable dataTable, bool showPrintDialog) { - if (fileName.Length == 0) { - throw new ArgumentException("PreviewPushDataReport fileName"); + if (String.IsNullOrEmpty(fileName)) { + throw new ArgumentNullException("fileName"); } if (dataTable == null) { - throw new ArgumentNullException("PreviewPushDataReport dataTable"); + throw new ArgumentNullException("dataTable"); } ReportModel model = null; AbstractRenderer renderer = null; diff --git a/src/AddIns/Misc/SharpReport/SharpReportWizard/GeneratorCommands.cs b/src/AddIns/Misc/SharpReport/SharpReportWizard/GeneratorCommands.cs index 546417f211..03bd25814d 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportWizard/GeneratorCommands.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportWizard/GeneratorCommands.cs @@ -13,24 +13,13 @@ /// using System; using System.Windows.Forms; -using System.Drawing.Printing; - -using System.Data; -using System.Data.OleDb; using ICSharpCode.Core; -using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Gui; using SharpReport; using SharpReportCore; -using SharpReport.Designer; - -using SharpQuery.SchemaClass; -using SharpQuery.Collections; -using System.Diagnostics; - namespace ReportGenerator{ /// @@ -43,11 +32,14 @@ namespace ReportGenerator{ private Properties customizer = new Properties(); - public CreateReport() { + public CreateReport() { } public CreateReport(ReportModel reportModel){ + if (reportModel == null) { + throw new ArgumentNullException("reportModel"); + } this.reportModel = reportModel; } @@ -58,13 +50,11 @@ namespace ReportGenerator{ customizer.Set("Language", ".XSD"); using (WizardDialog wizard = new WizardDialog("Report Wizard", customizer, WizardPath)) { if (wizard.ShowDialog() == DialogResult.OK) { - Debug.Assert (reportModel != null,"No report model"); + try { gen.FillReportModel (reportModel); DoCreate(reportModel); } catch (Exception) { -// MessageService.ShowError (e,e.Message); -// return; throw; } } else { @@ -81,90 +71,38 @@ namespace ReportGenerator{ dataModel = model.DataModel; switch (dataModel) { case GlobalEnums.enmPushPullModel.PullData: - GeneratePullReport (model); + GeneratePullDataReport generatePullDataReport = new GeneratePullDataReport(customizer,model); + generatePullDataReport.GenerateReport(); break; case GlobalEnums.enmPushPullModel.PushData: - GeneratePushReport (model); + GeneratePushDataReport generatePushDataReport = new GeneratePushDataReport(customizer,model); + generatePushDataReport.GenerateReport(); break; case GlobalEnums.enmPushPullModel.FormSheet: - GenerateFormSheet (model); + model.ReportSettings.ReportType = GlobalEnums.enmReportType.FormSheet; break; } } - /// - /// Generate a report - /// Pull - Report fill's data be themselve - /// - /// ReportModel - - void GeneratePullReport (ReportModel model) { - - try { - GeneratePullDataReport generator = new GeneratePullDataReport(customizer,model); - if (generator != null) { - generator.GenerateReport(); - } else { - throw new NullReferenceException ("GeneratePullDataReport"); + public class WriteXsdComplete : AbstractMenuCommand { + public override void Run() { + ResultPanel resultPanel = base.Owner as ResultPanel; + if (resultPanel != null) { + resultPanel.SaveXsdFile (false); } - } catch (Exception) { - throw; + } } - /// - /// Push Model Report - /// Report is created by an .Xsd File - /// - /// ReportModel - void GeneratePushReport (ReportModel model) { - try { - GeneratePushDataReport generator = new GeneratePushDataReport(customizer,model); - if (generator != null) { - generator.GenerateReport(); - } else { - throw new NullReferenceException ("GeneratePullDataReport"); + public class WriteXsdSchema : AbstractMenuCommand { + public override void Run() { + ResultPanel resultPanel = base.Owner as ResultPanel; + if (resultPanel != null) { + resultPanel.SaveXsdFile (true); } - } catch (Exception) { - throw; - } - } - - - - private static void GenerateFormSheet (ReportModel model) { - if (model.ReportSettings.DataModel != GlobalEnums.enmPushPullModel.FormSheet) { - throw new ArgumentNullException ("model"); - } - - try { - model.ReportSettings.ReportType = GlobalEnums.enmReportType.FormSheet; - } catch (Exception) { - throw; + } } } - - public class WriteXsdComplete : AbstractMenuCommand { - public override void Run() { - ResultPanel resultPanel = base.Owner as ResultPanel; - if (resultPanel != null) { - resultPanel.SaveXsdFile (false); - } - - } - } - - public class WriteXsdSchema : AbstractMenuCommand { - public override void Run() { - ResultPanel resultPanel = base.Owner as ResultPanel; - if (resultPanel != null) { - resultPanel.SaveXsdFile (true); - } - - } - - - } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportWizard/Generators/AbstractReportGenerator.cs b/src/AddIns/Misc/SharpReport/SharpReportWizard/Generators/AbstractReportGenerator.cs index ece547a60b..2dc23152b4 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportWizard/Generators/AbstractReportGenerator.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportWizard/Generators/AbstractReportGenerator.cs @@ -19,20 +19,19 @@ using ICSharpCode.Core; using SharpReport; using SharpReportCore; -using SharpQuery; -using SharpQuery.Collections; -using SharpQuery.Connection; -using SharpQuery.SchemaClass; - /// - /// Abstract Class for all ReportGenerators - /// - /// - /// created by - Forstmeier Peter - /// created on - 07.09.2005 14:21:07 - /// +/// +/// Abstract Class for all ReportGenerators +/// +/// +/// created by - Forstmeier Peter +/// created on - 07.09.2005 14:21:07 +/// +/// +using System.Windows.Forms; namespace ReportGenerator { - public class AbstractReportGenerator : IReportGenerator { + public class AbstractReportGenerator : IReportGenerator,IDisposable { + private ReportModel reportModel; private ReportGenerator reportGenerator; private Properties customizer; @@ -42,11 +41,15 @@ namespace ReportGenerator { } public AbstractReportGenerator(Properties customizer,ReportModel reportModel){ - this.customizer = customizer; - this.reportModel = reportModel; if (reportModel == null) { throw new ArgumentNullException("reportModel"); } + if (customizer == null) { + throw new ArgumentNullException("customizer"); + } + this.customizer = customizer; + this.reportModel = reportModel; + reportGenerator = (ReportGenerator)customizer.Get("Generator"); manager = new SharpReportManager(); } @@ -54,103 +57,15 @@ namespace ReportGenerator { #region ReportGenerator.IReportGenerator interface implementation public virtual void GenerateReport() { if (this.reportModel == null) { - throw new NullReferenceException("ReportModel"); + throw new MissingModelException(); } BuildStandartSections(); - manager.CreatePageHeader (reportModel); - manager.CreatePageNumber(reportModel); + manager.CreatePageHeader (this.reportModel); + manager.CreatePageNumber(this.reportModel); } #endregion - /* - protected ColumnCollection AvailableColumnsFromTable (DataTable table) { - - if (table == null) { - throw new ArgumentNullException("table"); - } - - ColumnCollection collection = new ColumnCollection(); - AbstractColumn abstr; - foreach (DataRow row in table.Rows) { - abstr = new AbstractColumn(); - abstr.ColumnName = Convert.ToString(row["ColumnName"],CultureInfo.InvariantCulture); - collection.Add (abstr); - } - return collection; - } - */ - protected DataTable GenerateFieldsTable(ReportModel reportModel) { - if (reportModel == null) { - throw new ArgumentNullException("reportModel"); - } - if (reportModel.ReportSettings.ConnectionString.Length == 0) { - throw new ArgumentException("CreateOLEDB Connection : No ConnectionString"); - } - OleDbConnection connection = null; - OleDbCommand command = null; - try { - - connection = new OleDbConnection(reportModel.ReportSettings.ConnectionString); - connection.Open(); - - if (connection == null) { - throw new ArgumentNullException("AbstractReportGenerator:GenerateFieldsTable 0) { - int rpc = reportModel.ReportSettings.SqlParametersCollection.Count; - OleDbParameter oleDBPar = null; - SqlParameter rpPar; - for (int i = 0;i < rpc ;i++) { - rpPar = (SqlParameter)reportModel.ReportSettings.SqlParametersCollection[i]; -// System.Console.WriteLine("{0} {1} {2}",rpPar.ParameterName,rpPar.DataType,rpPar.DefaultValue); - - - if (rpPar.DataType != System.Data.DbType.Binary) { - oleDBPar = new OleDbParameter(rpPar.ParameterName, - rpPar.DataType); - oleDBPar.Value = rpPar.DefaultValue; - } else { -// System.Console.WriteLine("binary"); - oleDBPar = new OleDbParameter(rpPar.ParameterName, - System.Data.DbType.Binary); - } - oleDBPar.Direction = rpPar.ParameterDirection; - command.Parameters.Add(oleDBPar); - - } - } - } catch (Exception) { - throw; - } - OleDbDataReader reader = null; - DataTable schemaTable = null; - try { - if (connection.State != ConnectionState.Open) { - connection.Open(); - } - reader = command.ExecuteReader(CommandBehavior.KeyInfo); - schemaTable = reader.GetSchemaTable(); - return schemaTable; - } catch (Exception e) { - - throw e; - } finally { - if (reader != null) { - reader.Close(); - } - - connection.Close(); - } - } - protected void BuildStandartSections () { foreach (ReportSection section in this.reportModel.SectionCollection) { @@ -197,5 +112,27 @@ namespace ReportGenerator { #endregion + public void Dispose(){ + this.Dispose(true); + GC.SuppressFinalize(this); + } + + ~AbstractReportGenerator(){ + Dispose(false); + } + + protected void Dispose(bool disposing){ + if (disposing) { + // Free other state (managed objects). + if (this.manager != null) { + this.manager.Dispose(); + } + } + + // Release unmanaged resources. + // Set large fields to null. + // Call Dispose on your base class. + } + } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportWizard/Generators/GeneratePullDataReport.cs b/src/AddIns/Misc/SharpReport/SharpReportWizard/Generators/GeneratePullDataReport.cs index fdddaa6b78..2fab2e32ae 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportWizard/Generators/GeneratePullDataReport.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportWizard/Generators/GeneratePullDataReport.cs @@ -8,9 +8,9 @@ // //------------------------------------------------------------------------------ using System; -using System.Data; using ICSharpCode.Core; + using SharpReportCore; /// /// This class is used to AutoGenerate a (PullData) Report @@ -26,52 +26,38 @@ namespace ReportGenerator { public class GeneratePullDataReport : AbstractReportGenerator { public GeneratePullDataReport(Properties customizer, - ReportModel reportModel):base(customizer,reportModel){ + ReportModel reportModel):base(customizer,reportModel){ if (base.ReportModel.ReportSettings.DataModel != GlobalEnums.enmPushPullModel.PullData) { throw new ArgumentException ("Wrong DataModel in GeneratePullDataReport"); } } - - #region ReportGenerator.IReportGenerator interface implementation public override void GenerateReport() { try { base.ReportModel.ReportSettings.ReportType = GlobalEnums.enmReportType.DataReport; - DataTable tableFields = null; - if (base.ReportGenerator.CommandType == CommandType.StoredProcedure) { - // we have Storedprocedure - if (base.ReportGenerator.SharpQueryProcedure.GetSchemaParameters() != null && - base.ReportGenerator.SharpQueryProcedure.GetSchemaParameters().Count > 0) { - // with parameters so we have prepare build the ParametersCollection here - base.ReportModel.ReportSettings.SqlParametersCollection = base.ReportGenerator.BuildSqlParameterList(); - tableFields = base.GenerateFieldsTable (base.ReportModel); - } else { - // no params, just run - tableFields = base.GenerateFieldsTable (base.ReportModel); - } - } else { - // just run - tableFields = base.GenerateFieldsTable (base.ReportModel); - } + base.ReportModel.ReportSettings.DataModel = GlobalEnums.enmPushPullModel.PullData; + + ReportItemCollection col = (ReportItemCollection)base.Customizer.Get ("ReportItemCollection"); + ColumnCollection columnCollection = (ColumnCollection)base.Customizer.Get ("ColumnCollection"); + this.ReportModel.ReportSettings.AvailableFieldsCollection = columnCollection; + base.GenerateReport(); - base.Manager.HeaderColumnsFromTable(base.ReportModel.PageHeader, - tableFields); - - base.Manager.DataColumnsFromTable (base.ReportModel, - tableFields); + base.Manager.HeaderColumnsFromReportItems (base.ReportModel.PageHeader,col); + base.Manager.DataColumnsFromReportItems (base.ReportModel.DetailSection,col); - using (TableLayout layout = new TableLayout(base.ReportModel)){ layout.BuildLayout(); } + base.AdjustAll(); - } catch (Exception e) { - throw e; + } catch (Exception) { + throw; } } + #endregion } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportWizard/Generators/GeneratePushDataReport.cs b/src/AddIns/Misc/SharpReport/SharpReportWizard/Generators/GeneratePushDataReport.cs index fad7df27e7..9c9422c86f 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportWizard/Generators/GeneratePushDataReport.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportWizard/Generators/GeneratePushDataReport.cs @@ -9,12 +9,11 @@ //------------------------------------------------------------------------------ using System; -using System.Data; - + using ICSharpCode.Core; using SharpReportCore; -using System.Windows.Forms; + /// /// This class is used to generate PushDataReports /// (Reports, that are feed with an DataSet etc) @@ -39,23 +38,22 @@ namespace ReportGenerator { } public override void GenerateReport() { + base.ReportModel.ReportSettings.ReportType = GlobalEnums.enmReportType.DataReport; + base.ReportModel.ReportSettings.DataModel = GlobalEnums.enmPushPullModel.PushData; - - ReportItemCollection col = (ReportItemCollection)base.Customizer.Get ("ReportItemCollection"); -// MessageBox.Show (col.Count.ToString()); + //we can't use the customizer here + ReportItemCollection col = base.ReportGenerator.ReportItemCollection; + base.ReportModel.ReportSettings.AvailableFieldsCollection = base.ReportGenerator.ColumnCollection; base.GenerateReport(); - base.Manager.HeaderColumnsFromReportItems (base.ReportModel.PageHeader,col); - base.Manager.DataColumnsFromReportItems (base.ReportModel.DetailSection,col); - - using (TableLayout layout = new TableLayout(base.ReportModel)){ layout.BuildLayout(); } base.AdjustAll(); + } } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportWizard/ReportGenerator.cs b/src/AddIns/Misc/SharpReport/SharpReportWizard/ReportGenerator.cs index 69737f4355..00b50f1f59 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportWizard/ReportGenerator.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportWizard/ReportGenerator.cs @@ -53,6 +53,7 @@ namespace ReportGenerator { private CommandType commandType; private SharpQueryProcedure sharpQueryProcedure; private ReportItemCollection reportItemCollection; + private ColumnCollection columnCollection; private SharpQuerySchemaClassCollection queryParameters; public ReportGenerator() { @@ -224,7 +225,19 @@ namespace ReportGenerator { #endregion - #region PushModelpanel + + #region PushModelPanel + + public ColumnCollection ColumnCollection { + get { + return columnCollection; + } + set { + columnCollection = value; + } + } + + public ReportItemCollection ReportItemCollection { get { return reportItemCollection; @@ -235,5 +248,6 @@ namespace ReportGenerator { } #endregion + } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportWizard/WizardPanels/BaseSettingsPanel.cs b/src/AddIns/Misc/SharpReport/SharpReportWizard/WizardPanels/BaseSettingsPanel.cs index 649f448aa2..282bdc6636 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportWizard/WizardPanels/BaseSettingsPanel.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportWizard/WizardPanels/BaseSettingsPanel.cs @@ -15,7 +15,7 @@ using System.Globalization; using System.Windows.Forms; using ICSharpCode.Core; -using ICSharpCode.SharpDevelop; +//using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Gui; using SharpReportCore; @@ -80,9 +80,8 @@ namespace ReportGenerator{ public override bool ReceiveDialogMessage(DialogMessage message){ if (message == DialogMessage.Finish) { -// System.Console.WriteLine(" resiveMessage Finish"); + } else if ( message == DialogMessage.Next) { -// System.Console.WriteLine(" resiveMessage Next"); base.EnableFinish = true; } return true; @@ -93,7 +92,9 @@ namespace ReportGenerator{ return customizer; } set { - + if (value == null) { + throw new ArgumentNullException("value"); + } this.customizer = (Properties)value; generator = (ReportGenerator)customizer.Get("Generator"); } @@ -159,16 +160,13 @@ namespace ReportGenerator{ void Button1Click(object sender, System.EventArgs e) { try { ICSharpCode.SharpDevelop.Gui.FolderDialog ff = new ICSharpCode.SharpDevelop.Gui.FolderDialog(); - ff.DisplayDialog(""); + ff.DisplayDialog(String.Empty); if (!String.IsNullOrEmpty(ff.Path)) { - if (!ff.Path.EndsWith(@"\")){ - + if (!ff.Path.EndsWith(@"\")){ this.txtPath.Text = ff.Path + @"\"; - System.Console.WriteLine("added slash"); } else { this.txtPath.Text = ff.Path; - System.Console.WriteLine("no slash added"); } generator.Path = this.txtPath.Text; } @@ -257,7 +255,7 @@ namespace ReportGenerator{ this.txtPath.Name = "txtPath"; this.txtPath.Size = new System.Drawing.Size(224, 20); this.txtPath.TabIndex = 13; - this.txtPath.Text = ""; + this.txtPath.Text = String.Empty; this.txtPath.TextChanged += new System.EventHandler(this.ChangedEvent); // // txtFileName @@ -266,7 +264,7 @@ namespace ReportGenerator{ this.txtFileName.Name = "txtFileName"; this.txtFileName.Size = new System.Drawing.Size(248, 20); this.txtFileName.TabIndex = 11; - this.txtFileName.Text = ""; + this.txtFileName.Text = String.Empty; // // cboGraphicsUnit // @@ -290,7 +288,7 @@ namespace ReportGenerator{ this.txtReportName.Name = "txtReportName"; this.txtReportName.Size = new System.Drawing.Size(248, 20); this.txtReportName.TabIndex = 0; - this.txtReportName.Text = ""; + this.txtReportName.Text = String.Empty; this.txtReportName.TextChanged += new System.EventHandler(this.ChangedEvent); // // groupBox1 diff --git a/src/AddIns/Misc/SharpReport/SharpReportWizard/WizardPanels/PullModelPanel.cs b/src/AddIns/Misc/SharpReport/SharpReportWizard/WizardPanels/PullModelPanel.cs index 370fef0c85..3dc55ba0d7 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportWizard/WizardPanels/PullModelPanel.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportWizard/WizardPanels/PullModelPanel.cs @@ -110,6 +110,9 @@ namespace ReportGenerator public override object CustomizationObject { get { return customizer; } set { + if (value == null) { + throw new ArgumentNullException("value"); + } this.customizer = (Properties)value; generator = (ReportGenerator)customizer.Get("Generator"); } diff --git a/src/AddIns/Misc/SharpReport/SharpReportWizard/WizardPanels/PushModelPanel.cs b/src/AddIns/Misc/SharpReport/SharpReportWizard/WizardPanels/PushModelPanel.cs index c515b303fa..b60aaeee55 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportWizard/WizardPanels/PushModelPanel.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportWizard/WizardPanels/PushModelPanel.cs @@ -16,7 +16,6 @@ using System.Collections; using System.Windows.Forms; using ICSharpCode.Core; -using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Gui; using SharpReport; @@ -39,7 +38,8 @@ namespace ReportGenerator private ReportGenerator generator; private Properties customizer; - private ReportItemCollection colDetail; + private ReportItemCollection reportItems; + private ColumnCollection columnCollection; public PushModelPanel(){ InitializeComponent(); @@ -74,47 +74,63 @@ namespace ReportGenerator DataSet ds = new DataSet(); ds.Locale = CultureInfo.CurrentCulture; ds.ReadXml (fileName); + base.EnableNext = true; + base.EnableFinish = true; + base.IsLastPanel = true; using (AutoReport auto = new AutoReport()){ ReportModel model = generator.FillReportModel (new ReportModel()); - colDetail = auto.ReportItemsFromSchema(model,ds); + columnCollection = auto.AbstractColumnsFromDataSet (ds); + reportItems = auto.ReportItemsFromSchema(model,ds); - if (colDetail != null) { - foreach (ReportDataItem item in colDetail) { + if (reportItems != null) { + foreach (ReportDataItem item in reportItems) { this.checkedListBox.Items.Add (item.MappingName,CheckState.Checked); } } } - base.EnableNext = true; - base.EnableFinish = true; - base.IsLastPanel = true; } #endregion #region overrides + public override object CustomizationObject { get { return customizer; } set { + if (value == null) { + throw new ArgumentNullException("value"); + } this.customizer = (Properties)value; generator = (ReportGenerator)customizer.Get("Generator"); } } public override bool ReceiveDialogMessage(DialogMessage message){ - - if (message == DialogMessage.Finish) { - - ReportItemCollection itemCol = new ReportItemCollection (); - if (this.colDetail != null) { +// base.EnableNext = true; +// base.EnableFinish = true; + if (message == DialogMessage.Activated) { +// base.EnableNext = true; +// base.EnableFinish = true; +// base.IsLastPanel = true; + } + else if (message == DialogMessage.Finish) { + + ReportItemCollection itemCollection = new ReportItemCollection (); + if (this.reportItems != null) { foreach (int ind in this.checkedListBox.CheckedIndices) { - IItemRenderer item = this.colDetail[ind]; - itemCol.Add(item); + IItemRenderer item = this.reportItems[ind]; + itemCollection.Add(item); } } - - customizer.Set ("ReportItemCollection",itemCol); + base.EnableNext = true; + base.EnableFinish = true; + base.IsLastPanel = true; + //We can't use the customizer here, because Resultpanel is called later on + // and null's the proerties + generator.ReportItemCollection = itemCollection; + generator.ColumnCollection = columnCollection; } return true; } diff --git a/src/AddIns/Misc/SharpReport/SharpReportWizard/WizardPanels/ResultPanel.cs b/src/AddIns/Misc/SharpReport/SharpReportWizard/WizardPanels/ResultPanel.cs index d35c816181..186fdeeda2 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportWizard/WizardPanels/ResultPanel.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportWizard/WizardPanels/ResultPanel.cs @@ -16,7 +16,6 @@ using System.Drawing; using System.Windows.Forms; using System.Xml; - using ICSharpCode.Core; using ICSharpCode.SharpDevelop; @@ -45,10 +44,12 @@ namespace ReportGenerator{ private ReportGenerator generator; private Properties customizer; - + private ReportModel model; private SharpQuerySchemaClassCollection parametersClass; private DataSet resultDataSet; + private ReportItemCollection colDetail; + private ColumnCollection abstractColumns; public ResultPanel(){ InitializeComponent(); @@ -57,16 +58,16 @@ namespace ReportGenerator{ base.EnableNext = true; base.Refresh(); this.label1.Text = ResourceService.GetString("SharpReport.Wizard.PullModel.CommandText"); + } #region Fill data - private void FillGrid() { + private DataSet FillGrid() { this.grdQuery.DataSource = null; this.txtSqlString.Text = null; - ReportModel model = generator.FillReportModel(new ReportModel()); - - resultDataSet = new DataSet(); - resultDataSet.Locale = CultureInfo.CurrentCulture; + + DataSet dataSet = new DataSet(); + dataSet.Locale = CultureInfo.CurrentCulture; this.txtSqlString.Text = model.ReportSettings.CommandText; if (model.ReportSettings.CommandType == CommandType.StoredProcedure){ @@ -100,7 +101,7 @@ namespace ReportGenerator{ }else{ parametersClass = parameters.ToBaseSchemaCollection(); if (parametersClass != null) { - resultDataSet = (DataSet) proc.Execute(0,parametersClass); + dataSet = (DataSet) proc.Execute(0,parametersClass); generator.Parameters = parametersClass; } } @@ -111,7 +112,7 @@ namespace ReportGenerator{ System.Console.WriteLine("\t\t No params"); try { // Stored Proc without Parameters - resultDataSet = (DataSet) proc.Execute(0,proc.GetSchemaParameters()); + dataSet = (DataSet) proc.Execute(0,proc.GetSchemaParameters()); } catch (Exception) { throw; } @@ -125,24 +126,26 @@ namespace ReportGenerator{ try { generator.Parameters = null; this.txtSqlString.Text = model.ReportSettings.CommandText; - resultDataSet = BuildFromSqlString(model.ReportSettings); + dataSet = BuildFromSqlString(model.ReportSettings); - } catch (OleDbException oleDbex) { - throw oleDbex; + } catch (OleDbException) { + throw; } - catch (Exception e) { - throw e; + catch (Exception) { + throw; } } - //For now we show only the first table, but we should find a better solution? - if (resultDataSet != null) { - this.grdQuery.DataSource = resultDataSet.Tables[0]; - } else { - NullReferenceException e = new NullReferenceException("ResultPanel:FillGrid"); - throw e; - } + CreateCollections (dataSet); + + return dataSet; } + private void CreateCollections (DataSet dataSet) { + using (AutoReport auto = new AutoReport()){ + abstractColumns = auto.AbstractColumnsFromDataSet (dataSet); + colDetail = auto.ReportItemsFromSchema(this.model,dataSet); + } + } private static DataSet BuildFromSqlString(ReportSettings settings) { OLEDBConnectionWrapper con = null; @@ -167,8 +170,8 @@ namespace ReportGenerator{ } #endregion - #region Create *.Xsd File - public void GrdQueryMouseUp(object sender, System.Windows.Forms.MouseEventArgs e){ + #region Create a *.Xsd File + private void GrdQueryMouseUp(object sender, System.Windows.Forms.MouseEventArgs e){ if (e.Button == MouseButtons.Right) { ContextMenuStrip ctMen = MenuService.CreateContextMenu (this,contextMenuPath); ctMen.Show (this.grdQuery,new Point (e.X,e.Y)); @@ -196,9 +199,9 @@ namespace ReportGenerator{ xmlWriter.WriteStartDocument(true); if (schemaOnly) { - resultDataSet.WriteXmlSchema(xmlWriter); + this.resultDataSet.WriteXmlSchema(xmlWriter); } else { - resultDataSet.WriteXml(xmlWriter,XmlWriteMode.WriteSchema); + this.resultDataSet.WriteXml(xmlWriter,XmlWriteMode.WriteSchema); } xmlWriter.Close(); } @@ -212,11 +215,17 @@ namespace ReportGenerator{ #endregion #region overrides - public override bool ReceiveDialogMessage(DialogMessage message) - { + public override bool ReceiveDialogMessage(DialogMessage message){ if (message == DialogMessage.Activated) { try { - FillGrid(); + this.resultDataSet = new DataSet(); + this.resultDataSet.Locale = CultureInfo.InvariantCulture; + this.model = generator.FillReportModel(new ReportModel()); + this.resultDataSet = FillGrid(); + if (this.resultDataSet != null) { + this.grdQuery.DataSource = this.resultDataSet.Tables[0]; + + } base.EnableNext = true; base.EnableFinish = true; } catch (Exception e) { @@ -224,6 +233,11 @@ namespace ReportGenerator{ base.EnableNext = false; base.EnableFinish = false; } + } else if (message == DialogMessage.Finish) { + customizer.Set ("ColumnCollection",abstractColumns); + customizer.Set ("ReportItemCollection",colDetail); + base.EnableNext = true; + base.EnableFinish = true; } return true; }