Browse Source

Worked on ParameterHandling for StoredProcedures (SQl Server)

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1713 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Peter Forstmeier 19 years ago
parent
commit
e6df090a1f
  1. 41
      src/AddIns/Misc/SharpReport/SharpReport/ParameterDialog.cs
  2. 1
      src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportView.cs
  3. 14
      src/AddIns/Misc/SharpReport/SharpReportCore/BaseClasses/SqlParameter.cs
  4. 14
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/DataManager.cs
  5. 37
      src/AddIns/Misc/SharpReport/SharpReportCore/ReportSettings.cs
  6. 66
      src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportEngine.cs
  7. 3
      src/AddIns/Misc/SharpReport/SharpReportWizard/SqlParameterConverter.cs

41
src/AddIns/Misc/SharpReport/SharpReport/ParameterDialog.cs

@ -63,19 +63,15 @@ namespace SharpReport{ @@ -63,19 +63,15 @@ namespace SharpReport{
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.cancelButton = new System.Windows.Forms.Button();
this.okButton = new System.Windows.Forms.Button();
this.groupBox = new System.Windows.Forms.GroupBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.tableLayoutPanel1.SuspendLayout();
this.groupBox.SuspendLayout();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(46, 87);
this.dataGrid1.Location = new System.Drawing.Point(48, 26);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(363, 120);
this.dataGrid1.TabIndex = 1;
@ -88,7 +84,7 @@ namespace SharpReport{ @@ -88,7 +84,7 @@ namespace SharpReport{
this.tableLayoutPanel1.Controls.Add(this.cancelButton, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.okButton, 0, 0);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.tableLayoutPanel1.Location = new System.Drawing.Point(10, 233);
this.tableLayoutPanel1.Location = new System.Drawing.Point(10, 175);
this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(10, 3, 10, 3);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 1;
@ -119,40 +115,13 @@ namespace SharpReport{ @@ -119,40 +115,13 @@ namespace SharpReport{
this.okButton.Text = "Ok";
this.okButton.UseVisualStyleBackColor = true;
//
// groupBox
//
this.groupBox.Controls.Add(this.label2);
this.groupBox.Controls.Add(this.label1);
this.groupBox.Location = new System.Drawing.Point(46, 13);
this.groupBox.Name = "groupBox";
this.groupBox.Size = new System.Drawing.Size(363, 56);
this.groupBox.TabIndex = 5;
this.groupBox.TabStop = false;
//
// label2
//
this.label2.Location = new System.Drawing.Point(109, 17);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(248, 17);
this.label2.TabIndex = 5;
this.label2.Text = "label2";
//
// label1
//
this.label1.Location = new System.Drawing.Point(6, 17);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(97, 17);
this.label1.TabIndex = 3;
this.label1.Text = "Stored Procedure:";
//
// ParameterDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(477, 273);
this.ClientSize = new System.Drawing.Size(477, 215);
this.ControlBox = false;
this.Controls.Add(this.groupBox);
this.Controls.Add(this.tableLayoutPanel1);
this.Controls.Add(this.dataGrid1);
this.Name = "ParameterDialog";
@ -162,15 +131,11 @@ namespace SharpReport{ @@ -162,15 +131,11 @@ namespace SharpReport{
this.Text = "ParameterDialog";
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.tableLayoutPanel1.ResumeLayout(false);
this.groupBox.ResumeLayout(false);
this.ResumeLayout(false);
}
private System.Windows.Forms.GroupBox groupBox;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button okButton;
private System.Windows.Forms.Button cancelButton;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.DataGrid dataGrid1;
#endregion
}

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

@ -280,7 +280,6 @@ namespace SharpReportAddin{ @@ -280,7 +280,6 @@ namespace SharpReportAddin{
private void PreviewStandartReport(bool standAlone){
reportManager.ParametersRequest -= new EventHandler<SharpReportParametersEventArgs> (OnParametersRequest);
reportManager.ParametersRequest += new EventHandler<SharpReportParametersEventArgs>(OnParametersRequest);

14
src/AddIns/Misc/SharpReport/SharpReportCore/BaseClasses/SqlParameter.cs

@ -41,23 +41,21 @@ namespace SharpReportCore { @@ -41,23 +41,21 @@ namespace SharpReportCore {
public SqlParameter(string parameterName,
DbType dataType,
object value)
:this(parameterName,dataType,value,String.Empty,ParameterDirection.Input){
object parameterValue)
:this(parameterName,dataType,parameterValue,ParameterDirection.Input){
}
public SqlParameter(string parameterName,
DbType dataType,
object value,
string prompt,
object parameterValue,
ParameterDirection parameterDirection):base(){
base.ParameterName = parameterName;
this.DataType = dataType;
// base.DefaultValue = value;
// base.Nullable = false;
// base.Prompt = prompt;
this.parameterValue = parameterValue;
this.parameterDirection = parameterDirection;
}

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

@ -215,7 +215,7 @@ namespace SharpReportCore { @@ -215,7 +215,7 @@ namespace SharpReportCore {
// We have to check if there are parameters for this Query, if so
// add them to the command
BuildQueryParameters(command,reportSettings);
BuildOleDbParameters(command,reportSettings.SqlParametersCollection);
OleDbDataAdapter adapter = new OleDbDataAdapter(command);
@ -234,14 +234,12 @@ namespace SharpReportCore { @@ -234,14 +234,12 @@ namespace SharpReportCore {
}
private static void BuildQueryParameters (OleDbCommand cmd,ReportSettings reportSettings) {
if (reportSettings.SqlParametersCollection != null && reportSettings.SqlParametersCollection.Count > 0) {
SqlParameter rpPar;
private static void BuildOleDbParameters (OleDbCommand cmd,SqlParametersCollection sqlParametersCollection) {
if (sqlParametersCollection != null && sqlParametersCollection.Count > 0) {
OleDbParameter oleDBPar = null;
for (int i = 0;i < reportSettings.SqlParametersCollection.Count ; i++) {
rpPar = (SqlParameter)reportSettings.SqlParametersCollection[i];
foreach (SqlParameter rpPar in sqlParametersCollection) {
if (rpPar.DataType != System.Data.DbType.Binary) {
oleDBPar = new OleDbParameter(rpPar.ParameterName,
rpPar.DataType);
@ -253,8 +251,8 @@ namespace SharpReportCore { @@ -253,8 +251,8 @@ namespace SharpReportCore {
oleDBPar.Direction = rpPar.ParameterDirection;
cmd.Parameters.Add(oleDBPar);
}
}
}

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

@ -115,21 +115,36 @@ namespace SharpReportCore{ @@ -115,21 +115,36 @@ namespace SharpReportCore{
/// <param name="reader">See XMLFormReader</param>
/// <param name="parElement">XmlElement ReportParameter</param>
/// <param name="item"><see cref="ReportParameter"</param>
private static void BuildReportParameter(XmlFormReader reader,
XmlElement parElement,
SharpReportCore.AbstractParameter item) {
// private static void BuildReportParameter(XmlFormReader reader,
// XmlElement parElement,
// SharpReportCore.AbstractParameter item) {
//
// XmlNodeList nodeList = parElement.ChildNodes;
// foreach (XmlNode node in nodeList) {
// XmlElement elem = node as XmlElement;
// if (elem != null) {
// if (elem.HasAttribute("value")) {
// reader.SetValue ((SqlParameter)item,elem.Name,elem.GetAttribute("value"));
// }
// }
// }
// }
private static SqlParameter BuildReportParameter (XmlFormReader reader,
XmlElement parElement) {
SqlParameter parameter = new SqlParameter();
XmlNodeList nodeList = parElement.ChildNodes;
foreach (XmlNode node in nodeList) {
XmlElement elem = node as XmlElement;
if (elem != null) {
if (elem.HasAttribute("value")) {
reader.SetValue ((SqlParameter)item,elem.Name,elem.GetAttribute("value"));
reader.SetValue (parameter,elem.Name,elem.GetAttribute("value"));
}
}
}
return parameter;
}
#endregion
#region RestoreItems
@ -191,15 +206,15 @@ namespace SharpReportCore{ @@ -191,15 +206,15 @@ namespace SharpReportCore{
foreach( XmlNode node in nodeList) {
XmlElement elem = node as XmlElement;
if (elem != null) {
SqlParameter parameter = new SqlParameter();
ReportSettings.BuildReportParameter (xmlReader,
elem,
parameter);
SqlParameter parameter = ReportSettings.BuildReportParameter (xmlReader,
elem);
reportParametersCollection.Add(parameter);
}
}
break;
}
}
}
}

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

@ -61,32 +61,35 @@ namespace SharpReportCore { @@ -61,32 +61,35 @@ namespace SharpReportCore {
}
#region ParameterHandling
private bool CheckReportParameters (ReportModel model,ReportParameters reportParameters) {
if (model.ReportSettings.ReportType != GlobalEnums.ReportTypeEnum.FormSheet) {
if (this.connectionObject == null) {
if (!String.IsNullOrEmpty(model.ReportSettings.ConnectionString)) {
this.connectionObject = new ConnectionObject (model.ReportSettings.ConnectionString);
}
if (reportParameters != null) {
this.connectionObject = reportParameters.ConnectionObject;
}
if (this.connectionObject.Connection != null) {
return true;
} else {
throw new SharpReportException("SharpReportEngine:CheckReportParameters : No valid Connection");
}
private void UpdateSqlParameters (ReportModel model,
SqlParametersCollection sqlParameters) {
if (sqlParameters != null) {
foreach (SqlParameter sourcePar in sqlParameters) {
SqlParameter destinationPar = model.ReportSettings.SqlParametersCollection.Find(sourcePar.ParameterName);
destinationPar.ParameterValue = sourcePar.ParameterValue;
}
}
}
private void CheckAllReportParameters (ReportModel model,
ReportParameters reportParameters) {
if (this.connectionObject == null) {
if (!String.IsNullOrEmpty(model.ReportSettings.ConnectionString)) {
this.connectionObject = new ConnectionObject (model.ReportSettings.ConnectionString);
}
} else {
return true;
}
return false;
if (reportParameters != null) {
this.connectionObject = reportParameters.ConnectionObject;
UpdateSqlParameters (model,reportParameters.SqlParameters);
}
}
void GrapSqlParameters (ReportSettings settings) {
if (settings.SqlParametersCollection != null && settings.SqlParametersCollection.Count > 0) {
if (this.ParametersRequest != null) {
@ -301,6 +304,7 @@ namespace SharpReportCore { @@ -301,6 +304,7 @@ namespace SharpReportCore {
model = ModelFromFile (fileName);
ReportParameters pars = new ReportParameters();
pars.ConnectionObject = null;
pars.SqlParameters.AddRange (model.ReportSettings.SqlParametersCollection);
return pars;
} catch (Exception) {
@ -334,18 +338,18 @@ namespace SharpReportCore { @@ -334,18 +338,18 @@ namespace SharpReportCore {
if (String.IsNullOrEmpty(fileName)) {
throw new ArgumentNullException("fileName");
}
ReportModel model = null;
AbstractRenderer renderer = null;
try {
model = ModelFromFile (fileName);
if (CheckReportParameters (model,reportParameters)) {
renderer = SetupStandartRenderer (model);
if (renderer != null) {
PreviewControl.ShowPreview(renderer,1.5,false);
}
CheckAllReportParameters (model,reportParameters);
renderer = SetupStandartRenderer (model);
if (renderer != null) {
PreviewControl.ShowPreview(renderer,1.5,false);
}
} catch (Exception) {
throw;
}
@ -455,10 +459,10 @@ namespace SharpReportCore { @@ -455,10 +459,10 @@ namespace SharpReportCore {
AbstractRenderer renderer = null;
try {
model = ModelFromFile (fileName);
if (CheckReportParameters (model,reportParameters)) {
renderer = SetupStandartRenderer (model);
SharpReportEngine.ReportToPrinter (renderer,model);
}
CheckAllReportParameters (model,reportParameters);
renderer = SetupStandartRenderer (model);
SharpReportEngine.ReportToPrinter (renderer,model);
} catch (Exception) {
throw;
}

3
src/AddIns/Misc/SharpReport/SharpReportWizard/SqlParameterConverter.cs

@ -54,8 +54,7 @@ namespace ReportGenerator @@ -54,8 +54,7 @@ namespace ReportGenerator
foreach (SharpQueryParameter par in tmp){
SqlParameter reportPar = new SqlParameter();
reportPar = new SqlParameter (par.Name,
par.DataType,
null,
par.DataType,
String.Empty,
par.Type);

Loading…
Cancel
Save