Browse Source

Merge branch 'reports' of github.com:icsharpcode/SharpDevelop into reports

pull/15/head^2
Peter Forstmeier 15 years ago
parent
commit
d6ac8a11af
  1. 127
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/WizardPanels/PullModelPanel.cs
  2. 29
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/WizardPanels/ResultPanel.cs

127
src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/WizardPanels/PullModelPanel.cs

@ -148,75 +148,76 @@ namespace ICSharpCode.Reports.Addin.ReportWizard
firstDrag = false; firstDrag = false;
} }
// Drag and drop isn't working via e.Data.GetData, so I'm using reflection here - took me a lot of time to figure out how this works... // Drag and drop isn't working via e.Data.GetData, so I'm using reflection here - took me a lot of time to figure out how this works...
// Still don't know why they implemented dnd so buggy and uncomfortable... // Still don't know why they implemented dnd so buggy and uncomfortable...
string draggedFormat = e.Data.GetFormats()[0]; string draggedFormat = e.Data.GetFormats()[0];
IDatabaseObjectBase draggedObject = null; IDatabaseObjectBase draggedObject = null;
if (e.Data.GetDataPresent(draggedFormat)) if (e.Data.GetDataPresent(draggedFormat))
{ {
object tempDraggedObject = null; object tempDraggedObject = null;
FieldInfo info; FieldInfo info;
info = e.Data.GetType().GetField("innerData", BindingFlags.NonPublic | BindingFlags.Instance); info = e.Data.GetType().GetField("innerData", BindingFlags.NonPublic | BindingFlags.Instance);
tempDraggedObject = info.GetValue(e.Data); tempDraggedObject = info.GetValue(e.Data);
info = tempDraggedObject.GetType().GetField("innerData", BindingFlags.NonPublic | BindingFlags.Instance); info = tempDraggedObject.GetType().GetField("innerData", BindingFlags.NonPublic | BindingFlags.Instance);
System.Windows.DataObject dataObject = info.GetValue(tempDraggedObject) as System.Windows.DataObject; System.Windows.DataObject dataObject = info.GetValue(tempDraggedObject) as System.Windows.DataObject;
draggedObject = dataObject.GetData(draggedFormat) as IDatabaseObjectBase; draggedObject = dataObject.GetData(draggedFormat) as IDatabaseObjectBase;
} }
switch (CheckCurrentNode(draggedObject)) switch (CheckCurrentNode(draggedObject))
{ {
case NodeType.TableImage: case NodeType.TableImage:
// we insert Select * from.... otherwise we have to scan // we insert Select * from.... otherwise we have to scan
//the whole string for incorrect columnNames //the whole string for incorrect columnNames
this.txtSqlString.Clear(); this.txtSqlString.Clear();
ITable table = draggedObject as ITable; ITable table = draggedObject as ITable;
this.txtSqlString.Text = "SELECT * FROM " + table.Name; this.txtSqlString.Text = "SELECT * FROM " + table.Name;
reportStructure.CommandType = CommandType.Text; reportStructure.CommandType = CommandType.Text;
reportStructure.IDatabaseObjectBase = table; reportStructure.IDatabaseObjectBase = table;
break; break;
case NodeType.ColumnImage: case NodeType.ColumnImage:
IColumn column = draggedObject as IColumn; IColumn column = draggedObject as IColumn;
string colName = column.Name; string colName = column.Name;
if (this.txtSqlString.Text.Length == 0) if (this.txtSqlString.Text.Length == 0)
{ {
this.txtSqlString.AppendText("SELECT "); this.txtSqlString.AppendText("SELECT ");
this.txtSqlString.AppendText(colName); this.txtSqlString.AppendText(colName);
} }
else if (this.txtSqlString.Text.ToUpper(CultureInfo.InvariantCulture).IndexOf("where", StringComparison.OrdinalIgnoreCase) > 0) else if (this.txtSqlString.Text.ToUpper(CultureInfo.InvariantCulture).IndexOf("where", StringComparison.OrdinalIgnoreCase) > 0)
{ {
this.txtSqlString.AppendText(colName + " = ?"); this.txtSqlString.AppendText(colName + " = ?");
} }
else else
{ {
this.txtSqlString.AppendText(", "); this.txtSqlString.AppendText(", ");
this.txtSqlString.AppendText(colName); this.txtSqlString.AppendText(colName);
} }
reportStructure.CommandType = CommandType.Text; reportStructure.CommandType = CommandType.Text;
reportStructure.IDatabaseObjectBase = column; reportStructure.IDatabaseObjectBase = column;
break; break;
case NodeType.ProcedureImage: case NodeType.ProcedureImage:
this.txtSqlString.Clear(); this.txtSqlString.Clear();
// we can't use the dragobject because it returns an string like 'EXECUTE ProcName' // we can't use the dragobject because it returns an string like 'EXECUTE ProcName'
IProcedure procedure = draggedObject as IProcedure; IProcedure procedure = draggedObject as IProcedure;
this.txtSqlString.Text = "[" + procedure.Name + "]"; this.txtSqlString.Text = "[" + procedure.Name + "]";
reportStructure.CommandType = CommandType.StoredProcedure; reportStructure.CommandType = CommandType.StoredProcedure;
reportStructure.IDatabaseObjectBase = procedure; reportStructure.IDatabaseObjectBase = procedure;
break; break;
/*
case NodeType.ViewImage: case NodeType.ViewImage:
this.txtSqlString.Text = String.Empty; this.txtSqlString.Text = String.Empty;
this.txtSqlString.Text = "No idea how to handle views"; this.txtSqlString.Text = "No idea how to handle views";
break; break;
default: */
break; default:
} break;
base.EnableNext = true; }
base.EnableNext = true;
} }

29
src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/WizardPanels/ResultPanel.cs

@ -68,11 +68,10 @@ namespace ICSharpCode.Reports.Addin.ReportWizard
this.txtSqlString.Text = model.ReportSettings.CommandText; this.txtSqlString.Text = model.ReportSettings.CommandText;
switch (model.ReportSettings.CommandType) { switch (model.ReportSettings.CommandType) {
case CommandType.Text: case CommandType.Text:
ITable t = reportStructure.IDatabaseObjectBase as ITable; this.connectionObject = CreateConnection ();
this.connectionObject = CreateConnection (t);
var dataAccess = new SqlDataAccessStrategy(model.ReportSettings,connectionObject); var dataAccess = new SqlDataAccessStrategy(model.ReportSettings,connectionObject);
dataSet = dataAccess.ReadData(); dataSet = dataAccess.ReadData();
dataSet.Tables[0].TableName = t.Name; dataSet.Tables[0].TableName = CreateTableName (reportStructure);
break; break;
case CommandType.StoredProcedure: case CommandType.StoredProcedure:
dataSet = DatasetFromStoredProcedure(); dataSet = DatasetFromStoredProcedure();
@ -87,8 +86,7 @@ namespace ICSharpCode.Reports.Addin.ReportWizard
} }
ConnectionObject CreateConnection()
ConnectionObject CreateConnection(IDatabaseObjectBase t)
{ {
var conobj = ConnectionObject.CreateInstance(this.model.ReportSettings.ConnectionString, var conobj = ConnectionObject.CreateInstance(this.model.ReportSettings.ConnectionString,
@ -99,16 +97,27 @@ namespace ICSharpCode.Reports.Addin.ReportWizard
} }
string CreateTableName(ReportStructure reportStructure)
{
ITable t = reportStructure.IDatabaseObjectBase as ITable;
string str = String.Empty;
if (t != null) {
str = t.Name;
}
else
{
str = reportStructure.IDatabaseObjectBase.Parent.Name;
}
return str;
}
DataSet DatasetFromStoredProcedure() DataSet DatasetFromStoredProcedure()
{ {
this.connectionObject = CreateConnection();
IProcedure procedure = reportStructure.IDatabaseObjectBase as IProcedure;
this.connectionObject = CreateConnection(procedure);
DataSet dataSet = ResultPanel.CreateDataSet(); DataSet dataSet = ResultPanel.CreateDataSet();
IProcedure procedure = reportStructure.IDatabaseObjectBase as IProcedure;
var paramCollection = CheckParameters(procedure); var paramCollection = CheckParameters(procedure);

Loading…
Cancel
Save