Browse Source

Modify SqlQueryChecker.cs

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1497 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Peter Forstmeier 19 years ago
parent
commit
31f277a686
  1. 8
      src/AddIns/Misc/SharpReport/SharpReport/SharpReportManager.cs
  2. 7
      src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportView.cs
  3. 6
      src/AddIns/Misc/SharpReport/SharpReportCore/ConnectionObject.cs
  4. 93
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/DataManager.cs
  5. 33
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/SqlQueryChecker.cs
  6. 50
      src/AddIns/Misc/SharpReport/SharpReportCore/Exceptions/IllegalQueryException.cs
  7. 4
      src/AddIns/Misc/SharpReport/SharpReportCore/Exceptions/SharpReportException.cs
  8. 7
      src/AddIns/Misc/SharpReport/SharpReportCore/Printing/AbstractDataRenderer.cs
  9. 37
      src/AddIns/Misc/SharpReport/SharpReportCore/Printing/AbstractRenderer.cs
  10. 8
      src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderDataReport.cs
  11. 5
      src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderFormSheetReport.cs
  12. 10
      src/AddIns/Misc/SharpReport/SharpReportCore/ReportSettings.cs
  13. 1
      src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportCore.csproj
  14. 122
      src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportEngine.cs

8
src/AddIns/Misc/SharpReport/SharpReport/SharpReportManager.cs

@ -189,6 +189,7 @@ namespace SharpReport{ @@ -189,6 +189,7 @@ namespace SharpReport{
/// <param name="model"><see cref="">ReportModel</see></param>
/// <param name="showInUserControl"></param>
public void ReportPreview (ReportModel model,bool standAlone) {
System.Console.WriteLine("Manager:ReportPreview");
if (model == null) {
throw new ArgumentNullException("model");
}
@ -199,16 +200,17 @@ namespace SharpReport{ @@ -199,16 +200,17 @@ namespace SharpReport{
PreviewControl.ShowPreview (abstr,1.5,standAlone);
}
} catch (Exception ) {
throw;
} catch (Exception e) {
MessageService.ShowError (e,"SharpReportManager:ReportPreview");
}
}
private AbstractRenderer BuildStandartRenderer (ReportModel model) {
System.Console.WriteLine("Manager:BuildStandartRenderr");
if (model == null) {
throw new ArgumentNullException("model");
}
if (base.ConnectionObject == null) {
base.ConnectionObject = this.BuildConnectionObject(model.ReportSettings);
}

7
src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportView.cs

@ -568,7 +568,12 @@ namespace SharpReportAddin{ @@ -568,7 +568,12 @@ namespace SharpReportAddin{
SharpReportView.DataSetFromFile());
} else {
renderer = reportManager.GetRendererForStandartReports(this.designerControl.ReportModel);
try {
renderer = reportManager.GetRendererForStandartReports(this.designerControl.ReportModel);
} catch (Exception e) {
MessageService.ShowError (e,"SharpReportManager:ReportPreview");
return null;
}
}
return renderer.ReportDocument;
}

6
src/AddIns/Misc/SharpReport/SharpReportCore/ConnectionObject.cs

@ -36,6 +36,9 @@ namespace SharpReportCore { @@ -36,6 +36,9 @@ namespace SharpReportCore {
}
public ConnectionObject( OleDbConnectionStringBuilder oleDbConnectionStringBuilder){
if (oleDbConnectionStringBuilder == null) {
throw new ArgumentNullException("oleDbConnectionStringBuilder");
}
this.oleDbConnectionStringBuilder = oleDbConnectionStringBuilder;
try {
this.connection = new OleDbConnection (this.oleDbConnectionStringBuilder.ConnectionString);
@ -45,6 +48,9 @@ namespace SharpReportCore { @@ -45,6 +48,9 @@ namespace SharpReportCore {
}
public ConnectionObject(IDbConnection connection){
if (connection == null) {
throw new ArgumentNullException("connection");
}
this.connection = connection;
this.connectionString = this.connection.ConnectionString;
}

93
src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/DataManager.cs

@ -50,16 +50,25 @@ namespace SharpReportCore { @@ -50,16 +50,25 @@ namespace SharpReportCore {
if (reportSettings == null) {
throw new ArgumentNullException("reportSettings");
}
try {
this.connectionObject = connectionObject;
CheckConnection (this.connectionObject);
CheckReportSettings(reportSettings);
CheckDataSource(this.FillDataSet().Tables[0]);
this.connectionObject = connectionObject;
CheckConnection (this.connectionObject);
CheckReportSettings(reportSettings);
CheckDataSource(this.FillDataSet().Tables[0]);
this.dataViewStrategy = new TableStrategy((DataTable)this.dataSource,
reportSettings);
this.dataViewStrategy.ListChanged += new EventHandler <ListChangedEventArgs> (NotifyListChanged);
this.dataViewStrategy = new TableStrategy((DataTable)this.dataSource,
reportSettings);
this.dataViewStrategy.ListChanged += new EventHandler <ListChangedEventArgs> (NotifyListChanged);
// this.dataViewStrategy.GroupChanged += new EventHandler<GroupChangedEventArgs> (OnGroupChange);
}
catch (Exception) {
throw;
} finally {
if (this.connectionObject.Connection.State == ConnectionState.Open) {
this.connectionObject.Connection.Close();
}
}
}
public DataManager(DataTable dataSource, ReportSettings reportSettings){
@ -115,11 +124,13 @@ namespace SharpReportCore { @@ -115,11 +124,13 @@ namespace SharpReportCore {
void CheckReportSettings(ReportSettings settings) {
try {
if (settings.DataModel != GlobalEnums.enmPushPullModel.PushData) {
SqlQueryChecker checker = new SqlQueryChecker();
checker.Check(settings.CommandText);
SqlQueryChecker.Check(settings.CommandText);
}
} catch (Exception) {
} catch (IllegalQueryException) {
throw;
}
catch (Exception) {
throw;
}
this.reportSettings = settings;
@ -196,16 +207,19 @@ namespace SharpReportCore { @@ -196,16 +207,19 @@ namespace SharpReportCore {
if (this.connection.State == ConnectionState.Closed) {
this.connection.Open();
}
OleDbCommand command = ((OleDbConnection)this.connection).CreateCommand();
command.CommandText = reportSettings.CommandText;
command.CommandType = reportSettings.CommandType;
// We have to check if there are parameters for this Query, if so
// add them to the command
CheckForAndBuildParams(command,reportSettings);
BuildQueryParameters(command,reportSettings);
OleDbDataAdapter adapter = new OleDbDataAdapter(command);
DataSet ds = new DataSet();
ds.Locale = CultureInfo.CurrentCulture;
adapter.Fill (ds);
return ds;
@ -219,7 +233,7 @@ namespace SharpReportCore { @@ -219,7 +233,7 @@ namespace SharpReportCore {
}
private static void CheckForAndBuildParams (OleDbCommand cmd,ReportSettings reportSettings) {
private static void BuildQueryParameters (OleDbCommand cmd,ReportSettings reportSettings) {
if (reportSettings.SqlParametersCollection != null && reportSettings.SqlParametersCollection.Count > 0) {
SqlParameter rpPar;
OleDbParameter oleDBPar = null;
@ -307,56 +321,7 @@ namespace SharpReportCore { @@ -307,56 +321,7 @@ namespace SharpReportCore {
return this.dataSource;
}
}
/*
public int CurrentRow {
get {
return this.dataViewStrategy.CurrentRow;
}
}
*/
/*
public int Count {
get {
return this.dataViewStrategy.Count;
}
}
*/
/*
public bool HasMoreData {
get {
if (this.dataViewStrategy.CurrentRow < this.dataViewStrategy.Count ){
return true;
} else {
return false;
}
}
}
*/
// public void Skip() {
// this.dataViewStrategy.CurrentRow ++;
// }
//
/*
public void FetchData(ReportItemCollection collection) {
foreach (IItemRenderer item in collection) {
this.dataViewStrategy.Fill(item);
}
this.NotifyGroupChanged();
}
*/
/*
/// <summary>
/// Indicate's if the current <see cref="GroupSeperator"></see> has ChildRows
/// </summary>
public bool HasChilds {
get {
return this.dataViewStrategy.HasChilds;
}
}
*/
/// <summary>
/// Returns a <see cref="SharpArrayList"></see>, be carefull, this list is only a Indexlist

33
src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/SqlQueryChecker.cs

@ -11,44 +11,23 @@ using System; @@ -11,44 +11,23 @@ using System;
using System.Globalization;
using System.Windows.Forms;
namespace SharpReportCore
{
namespace SharpReportCore{
/// <summary>
/// This Class checks for invalid SqlStatements
/// </summary>
internal class SqlQueryChecker{
internal string UPDATE = "UPDATE";
internal string DELETE = "DELETE";
internal string INSERT = "INSERT";
internal string noValidMessage = "is no valid Member of SqlString";
internal string noValidMessage = "Query should start with 'Select'";
public SqlQueryChecker(){
private SqlQueryChecker () {
}
public void Check (string queryString) {
public static void Check (string queryString) {
if (!String.IsNullOrEmpty(queryString)) {
queryString = queryString.ToUpper(CultureInfo.CurrentCulture);
if (queryString.IndexOf (this.UPDATE) > -1) {
this.Invalid (this.UPDATE);
}
if (queryString.IndexOf(this.DELETE) > -1) {
this.Invalid (this.DELETE);
}
if (queryString.IndexOf(this.INSERT) > -1) {
this.Invalid (this.INSERT);
if (queryString.IndexOf("SELECT") < 0) {
throw new SharpReportCore.IllegalQueryException();
}
}
}
private void Invalid (string invalidArgument) {
string str = String.Format(CultureInfo.CurrentCulture,
"{0} {1}",invalidArgument,this.noValidMessage);
throw new SharpReportCore.SharpReportException(str);
}
}
}

50
src/AddIns/Misc/SharpReport/SharpReportCore/Exceptions/IllegalQueryException.cs

@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
/*
* Created by SharpDevelop.
* User: Forstmeier Helmut
* Date: 15.06.2006
* Time: 17:53
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Runtime.Serialization;
namespace SharpReportCore
{
/// <summary>
/// IllegalQueryException is thrown when a QueryString contains other statements as
/// Select. So it should not happen do alter a Database while doing a Query with SharpReport
/// </summary>
public class IllegalQueryException: System.Exception{
private const string message = "Query should start with 'Select'";
string errorMessage;
public IllegalQueryException():base(message){
}
public IllegalQueryException(string errorMessage) :base (errorMessage){
this.errorMessage = errorMessage;
}
public IllegalQueryException(string errorMessage,
Exception exception):base (errorMessage,exception){
}
protected IllegalQueryException(SerializationInfo info,
StreamingContext context) : base(info, context){
// Implement type-specific serialization constructor logic.
}
public string ErrorMessage {
get {
if (String.IsNullOrEmpty(this.errorMessage)) {
return IllegalQueryException.message;
} else {
return this.errorMessage;
}
}
}
}
}

4
src/AddIns/Misc/SharpReport/SharpReportCore/Exceptions/SharpReportException.cs

@ -41,13 +41,11 @@ namespace SharpReportCore { @@ -41,13 +41,11 @@ namespace SharpReportCore {
StreamingContext context) : base(info, context){
// Implement type-specific serialization constructor logic.
}
public string ErrorMessage {
get {
return errorMessage;
}
set {
errorMessage = value;
}
}
}

7
src/AddIns/Misc/SharpReport/SharpReportCore/Printing/AbstractDataRenderer.cs

@ -27,8 +27,8 @@ namespace SharpReportCore{ @@ -27,8 +27,8 @@ namespace SharpReportCore{
}
#region overrides
protected override void ReportBegin(object sender, PrintEventArgs e){
base.ReportBegin(sender, e);
protected override void ReportBegin(object sender, PrintEventArgs pea){
base.ReportBegin(sender, pea);
}
@ -100,8 +100,9 @@ namespace SharpReportCore{ @@ -100,8 +100,9 @@ namespace SharpReportCore{
#endregion
#region IDisposable
public override void Dispose(){
public new void Dispose(){
try {
System.Console.WriteLine("Abstarct:Dispose");
if (this.dataManager != null) {
this.dataManager.Dispose();
this.dataManager = null;

37
src/AddIns/Misc/SharpReport/SharpReportCore/Printing/AbstractRenderer.cs

@ -87,7 +87,7 @@ namespace SharpReportCore { @@ -87,7 +87,7 @@ namespace SharpReportCore {
}
#endregion
protected void PageBreak(ReportPageEventArgs pea) {
protected static void PageBreak(ReportPageEventArgs pea) {
if (pea == null) {
throw new ArgumentNullException("pea");
}
@ -121,7 +121,7 @@ namespace SharpReportCore { @@ -121,7 +121,7 @@ namespace SharpReportCore {
/// Use this function to draw controlling rectangles
/// </summary>
protected void DebugRectangle (ReportPageEventArgs rpea,Rectangle rectangle) {
protected static void DebugRectangle (ReportPageEventArgs rpea,Rectangle rectangle) {
if (rpea == null) {
throw new ArgumentNullException("rpea");
}
@ -273,18 +273,18 @@ namespace SharpReportCore { @@ -273,18 +273,18 @@ namespace SharpReportCore {
section.Size.Height);
if ((section.CanGrow == true)||(section.CanShrink == true)) {
AdjustSection (section,rpea);
AbstractRenderer.AdjustSection (section,rpea);
} else {
AdjustItems (section,rpea);
AbstractRenderer.AdjustItems (section,rpea);
}
}
private void AdjustItems (BaseSection section,ReportPageEventArgs e){
private static void AdjustItems (BaseSection section,ReportPageEventArgs e){
int toFit = section.Size.Height;
foreach (BaseReportItem rItem in section.Items) {
if (!CheckItemInSection (section,rItem,e)){
if (!AbstractRenderer.CheckItemInSection (section,rItem,e)){
rItem.Size = new Size (rItem.Size.Width,
toFit - rItem.Location.Y);
@ -294,12 +294,12 @@ namespace SharpReportCore { @@ -294,12 +294,12 @@ namespace SharpReportCore {
}
private void AdjustSection (BaseSection section,ReportPageEventArgs e){
private static void AdjustSection (BaseSection section,ReportPageEventArgs e){
foreach (BaseReportItem rItem in section.Items) {
if (!CheckItemInSection (section,rItem,e)){
if (!AbstractRenderer.CheckItemInSection (section,rItem,e)){
SizeF size = MeasureReportItem (rItem,e);
SizeF size = AbstractRenderer.MeasureReportItem (rItem,e);
section.Size = new Size (section.Size.Width,
Convert.ToInt32(rItem.Location.Y + size.Height));
@ -309,9 +309,9 @@ namespace SharpReportCore { @@ -309,9 +309,9 @@ namespace SharpReportCore {
}
private bool CheckItemInSection (BaseSection section,BaseReportItem item ,ReportPageEventArgs e) {
private static bool CheckItemInSection (BaseSection section,BaseReportItem item ,ReportPageEventArgs e) {
Rectangle secRect = new Rectangle (0,0,section.Size.Width,section.Size.Height);
SizeF size = MeasureReportItem(item,e);
SizeF size = AbstractRenderer.MeasureReportItem(item,e);
Rectangle itemRect = new Rectangle (item.Location.X,
item.Location.Y,
(int)size.Width,
@ -322,12 +322,13 @@ namespace SharpReportCore { @@ -322,12 +322,13 @@ namespace SharpReportCore {
return false;
}
private SizeF MeasureReportItem(IItemRenderer item,
private static SizeF MeasureReportItem(IItemRenderer item,
ReportPageEventArgs e) {
SizeF sizeF = new SizeF ();
BaseTextItem myItem = item as BaseTextItem;
if (myItem != null) {
string str = String.Empty;
if (item is BaseTextItem) {
BaseTextItem it = item as BaseTextItem;
str = it.Text;
@ -335,7 +336,7 @@ namespace SharpReportCore { @@ -335,7 +336,7 @@ namespace SharpReportCore {
BaseDataItem it = item as BaseDataItem;
str = it.DbValue;
}
sizeF = e.PrintPageEventArgs.Graphics.MeasureString(str,
myItem.Font,
myItem.Size.Width,
@ -350,8 +351,8 @@ namespace SharpReportCore { @@ -350,8 +351,8 @@ namespace SharpReportCore {
#region virtuals
protected virtual void ReportQueryPage (object sender,QueryPageSettingsEventArgs e) {
e.PageSettings.Margins = reportSettings.DefaultMargins;
protected virtual void ReportQueryPage (object sender,QueryPageSettingsEventArgs qpea) {
qpea.PageSettings.Margins = reportSettings.DefaultMargins;
}
@ -429,11 +430,12 @@ namespace SharpReportCore { @@ -429,11 +430,12 @@ namespace SharpReportCore {
}
}
protected int Gap {
protected static int Gap {
get {
return gap;
}
}
protected Point DetailEnds {
get {
return detailEnds;
@ -454,7 +456,8 @@ namespace SharpReportCore { @@ -454,7 +456,8 @@ namespace SharpReportCore {
#endregion
#region IDispoable
public virtual void Dispose(){
public void Dispose(){
System.Console.WriteLine("base:Dispose()");
if (this.reportDocument != null) {
this.reportDocument.Dispose();
}

8
src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderDataReport.cs

@ -187,7 +187,7 @@ namespace SharpReportCore { @@ -187,7 +187,7 @@ namespace SharpReportCore {
this.currentPoint = new PointF (base.CurrentSection.Location.X,
this.DetailStart.Y);
base.CurrentSection.SectionOffset = (int)this.DetailStart.Y + base.Gap;
base.CurrentSection.SectionOffset = (int)this.DetailStart.Y + AbstractRenderer.Gap;
// base.DebugRectangle(rpea,base.DetailRectangle(rpea));
// no loop if there is no data
@ -205,7 +205,7 @@ namespace SharpReportCore { @@ -205,7 +205,7 @@ namespace SharpReportCore {
base.RenderSection (base.CurrentSection,rpea);
if (!firstOnPage) {
base.CurrentSection.SectionOffset = base.CurrentSection.SectionOffset + base.CurrentSection.Size.Height + 2 * base.Gap;
base.CurrentSection.SectionOffset = base.CurrentSection.SectionOffset + base.CurrentSection.Size.Height + 2 * AbstractRenderer.Gap;
}
@ -218,7 +218,7 @@ namespace SharpReportCore { @@ -218,7 +218,7 @@ namespace SharpReportCore {
base.CurrentSection.Size.Height);
if (!base.DetailRectangle(rpea).Contains(sectionRect)) {
base.PageBreak(rpea);
AbstractRenderer.PageBreak(rpea);
return;
}
@ -228,7 +228,7 @@ namespace SharpReportCore { @@ -228,7 +228,7 @@ namespace SharpReportCore {
if (this.dataNavigator.CurrentRow < this.dataNavigator.Count -1) {
if (base.CurrentSection.PageBreakAfter) {
base.PageBreak(rpea);;
AbstractRenderer.PageBreak(rpea);;
return;
}
}

5
src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderFormSheetReport.cs

@ -78,8 +78,7 @@ namespace SharpReportCore { @@ -78,8 +78,7 @@ namespace SharpReportCore {
this.RemoveSectionEvents();
if (base.CheckPageBreakAfter()) {
// base.PageBreak(rpea,base.CurrentSection);
base.PageBreak(rpea);
AbstractRenderer.PageBreak(rpea);
base.CurrentSection.PageBreakAfter = false;
return new PointF();
}
@ -159,7 +158,7 @@ namespace SharpReportCore { @@ -159,7 +158,7 @@ namespace SharpReportCore {
base.PrintBodyStart (sender,rpea);
// BaseSection section = base.CurrentSection;
base.CurrentSection.SectionOffset = (int)this.currentPoint.Y + base.Gap;
base.CurrentSection.SectionOffset = (int)this.currentPoint.Y + AbstractRenderer.Gap;
FitSectionToItems (base.CurrentSection,rpea);

10
src/AddIns/Misc/SharpReport/SharpReportCore/ReportSettings.cs

@ -210,6 +210,9 @@ namespace SharpReportCore{ @@ -210,6 +210,9 @@ namespace SharpReportCore{
public void SetSettings(XmlElement xmlSettings) {
if (xmlSettings == null) {
throw new ArgumentNullException("xmlSettings");
}
XmlNodeList nodeList = xmlSettings.ChildNodes;
XmlFormReader xmlFormReader = new XmlFormReader();
base.InitDone = false;
@ -492,6 +495,7 @@ namespace SharpReportCore{ @@ -492,6 +495,7 @@ namespace SharpReportCore{
return reportType;
}
set {
System.Console.WriteLine("ReportType set to {0}",value);
if (reportType != value) {
reportType = value;
this.NotifyPropertyChanged("ReportType");
@ -622,6 +626,12 @@ namespace SharpReportCore{ @@ -622,6 +626,12 @@ namespace SharpReportCore{
set {
if (dataModel != value) {
dataModel = value;
System.Console.WriteLine("DataModel type = {0}",this.dataModel.ToString());
if (this.dataModel != GlobalEnums.enmPushPullModel.FormSheet) {
this.reportType = GlobalEnums.enmReportType.DataReport;
} else {
this.reportType = GlobalEnums.enmReportType.FormSheet;
}
this.NotifyPropertyChanged("DataModel");
}
}

1
src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportCore.csproj

@ -130,6 +130,7 @@ @@ -130,6 +130,7 @@
<Compile Include="Interfaces\IDataNavigator.cs" />
<Compile Include="Events\PrintEventArgs.cs" />
<Compile Include="BaseItems\TableItem.cs" />
<Compile Include="Exceptions\IllegalQueryException.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="BaseItems" />

122
src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportEngine.cs

@ -59,7 +59,7 @@ namespace SharpReportCore { @@ -59,7 +59,7 @@ namespace SharpReportCore {
if (model.ReportSettings.ReportType != GlobalEnums.enmReportType.FormSheet) {
if (this.connectionObject == null) {
if (String.IsNullOrEmpty(model.ReportSettings.ConnectionString)) {
if (!String.IsNullOrEmpty(model.ReportSettings.ConnectionString)) {
this.connectionObject = new ConnectionObject (model.ReportSettings.ConnectionString);
}
@ -93,7 +93,7 @@ namespace SharpReportCore { @@ -93,7 +93,7 @@ namespace SharpReportCore {
}
void SetSqlParameters (ReportModel model,AbstractParametersCollection sqlParams) {
private static void SetSqlParameters (ReportModel model,AbstractParametersCollection sqlParams) {
if ((sqlParams == null)||(sqlParams.Count == 0)) {
return;
}
@ -112,18 +112,6 @@ namespace SharpReportCore { @@ -112,18 +112,6 @@ namespace SharpReportCore {
}
private void ApplyReportParameters (ReportModel model,ReportParameters parameters){
if (model == null) {
throw new MissingModelException();
}
if (parameters == null ){
throw new ArgumentNullException("parameters");
}
SetSqlParameters (model,parameters.SqlParameters);
SetCustomSorting (model,parameters.SortColumnCollection);
}
#endregion
#region Setup for print/preview
@ -136,7 +124,7 @@ namespace SharpReportCore { @@ -136,7 +124,7 @@ namespace SharpReportCore {
}
private void InitDataContainer (ReportSettings settings) {
System.Console.WriteLine("Engine:InitDataContainer eortType {0}",settings.ReportType);
if (settings.ReportType == GlobalEnums.enmReportType.DataReport) {
if (settings.CommandText != null) {
try {
@ -147,8 +135,6 @@ namespace SharpReportCore { @@ -147,8 +135,6 @@ namespace SharpReportCore {
settings);
this.dataManager.DataBind();
}else {
throw new NullReferenceException("SetupContainer:connectionObject is missing");
}
}
@ -183,46 +169,49 @@ namespace SharpReportCore { @@ -183,46 +169,49 @@ namespace SharpReportCore {
protected SharpReportCore.AbstractRenderer SetupStandartRenderer (ReportModel model) {
AbstractRenderer abstr = null;
switch (model.ReportSettings.ReportType) {
//FormSheets reports
case GlobalEnums.enmReportType.FormSheet:
abstr = new RendererFactory().Create (model,null);
break;
//Databased reports
case GlobalEnums.enmReportType.DataReport :
// DataManager dataManager = SetupDataContainer (model.ReportSettings);
InitDataContainer (model.ReportSettings);
if (this.dataManager != null) {
if (this.dataManager.DataSource != null) {
abstr = new RendererFactory().Create (model,dataManager);
}
} else {
if (NoData != null) {
SharpReportEventArgs e = new SharpReportEventArgs();
e.PageNumber = 0;
e.Cancel = false;
NoData (this,e);
if (e.Cancel == true) {
// If we cancel, we have to create an instance of any kind of renderer
//to set the cancel flag to true
abstr = new RendererFactory().Create (model,null);
abstr.Cancel = true;
} else {
// Print the report only as Formsheet -> only Text and Graphic Items
abstr = new RendererFactory().Create (model,null);
try {
switch (model.ReportSettings.ReportType) {
//FormSheets reports
case GlobalEnums.enmReportType.FormSheet:
abstr = new RendererFactory().Create (model,null);
break;
//Databased reports
case GlobalEnums.enmReportType.DataReport :
InitDataContainer (model.ReportSettings);
if (this.dataManager != null) {
if (this.dataManager.DataSource != null) {
abstr = new RendererFactory().Create (model,dataManager);
}
} else {
if (NoData != null) {
SharpReportEventArgs e = new SharpReportEventArgs();
e.PageNumber = 0;
e.Cancel = false;
NoData (this,e);
if (e.Cancel == true) {
// If we cancel, we have to create an instance of any kind of renderer
//to set the cancel flag to true
abstr = new RendererFactory().Create (model,null);
abstr.Cancel = true;
} else {
// Print the report only as Formsheet -> only Text and Graphic Items
abstr = new RendererFactory().Create (model,null);
}
}
}
}
break;
default:
throw new SharpReportException ("SharpReportmanager:SetupRenderer -> Unknown Reporttype");
break;
default:
throw new SharpReportException ("SharpReportmanager:SetupRenderer -> Unknown Reporttype");
}
return abstr;
} catch (Exception) {
throw;
}
return abstr;
}
@ -268,8 +257,13 @@ namespace SharpReportCore { @@ -268,8 +257,13 @@ namespace SharpReportCore {
if (model == null) {
throw new MissingModelException();
}
AbstractRenderer abstr = SetupStandartRenderer(model);
return abstr;
try {
AbstractRenderer abstr = SetupStandartRenderer(model);
return abstr;
} catch (Exception) {
throw;
}
}
@ -316,6 +310,7 @@ namespace SharpReportCore { @@ -316,6 +310,7 @@ namespace SharpReportCore {
public void PreviewStandartReport (string fileName,ReportParameters reportParameters) {
if (String.IsNullOrEmpty(fileName)) {
throw new ArgumentNullException("fileName");
}
@ -361,7 +356,7 @@ namespace SharpReportCore { @@ -361,7 +356,7 @@ namespace SharpReportCore {
PreviewControl.ShowPreview(renderer,1.5,false);
}
} catch (Exception) {
throw;
}
}
@ -369,16 +364,18 @@ namespace SharpReportCore { @@ -369,16 +364,18 @@ namespace SharpReportCore {
#region Printing
private void ReportToPrinter (AbstractRenderer renderer,ReportModel model) {
private static void ReportToPrinter (AbstractRenderer renderer,ReportModel model) {
if (renderer == null) {
throw new NullReferenceException("SparpReportEngine:ReportToPrinter: No valid Renderer");
throw new ArgumentNullException("renderer");
}
if (model == null) {
throw new ArgumentNullException("model");
}
PrintDocument doc = null;
if (renderer.Cancel == false) {
doc = renderer.ReportDocument;
using (PrintDialog dlg = new PrintDialog()) {
dlg.Document = doc;
// MessageBox.Show (model.ReportSettings.UseStandartPrinter.ToString());
if (model.ReportSettings.UseStandartPrinter == true) {
dlg.Document.Print();
} else {
@ -417,12 +414,13 @@ namespace SharpReportCore { @@ -417,12 +414,13 @@ namespace SharpReportCore {
model = ModelFromFile (fileName);
if (CheckReportParameters (model,reportParameters)) {
renderer = SetupStandartRenderer (model);
this.ReportToPrinter (renderer,model);
SharpReportEngine.ReportToPrinter (renderer,model);
}
} catch (Exception) {
throw;
}
}
/// <summary>
/// Print a PullModel Report
/// </summary>
@ -450,9 +448,10 @@ namespace SharpReportCore { @@ -450,9 +448,10 @@ namespace SharpReportCore {
}
renderer = SetupPushDataRenderer (model,dataTable);
this.ReportToPrinter(renderer,model);
SharpReportEngine.ReportToPrinter(renderer,model);
} catch (Exception) {
throw;
}
@ -481,9 +480,10 @@ namespace SharpReportCore { @@ -481,9 +480,10 @@ namespace SharpReportCore {
}
renderer = this.SetupPushDataRenderer (model,dataTable);
this.ReportToPrinter(renderer,model);
SharpReportEngine.ReportToPrinter(renderer,model);
} catch (Exception) {
throw;
}
}

Loading…
Cancel
Save