Browse Source

ResultPanel.cs and TableName

pull/15/head^2
peterforstmeier 15 years ago
parent
commit
b039d9763c
  1. 131
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/WizardPanels/PullModelPanel.cs
  2. 27
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/WizardPanels/ResultPanel.cs

131
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:
IColumn column = draggedObject as IColumn;
string colName = column.Name;
if (this.txtSqlString.Text.Length == 0)
{
this.txtSqlString.AppendText("SELECT ");
this.txtSqlString.AppendText(colName);
}
else if (this.txtSqlString.Text.ToUpper(CultureInfo.InvariantCulture).IndexOf("where", StringComparison.OrdinalIgnoreCase) > 0) case NodeType.ColumnImage:
{ IColumn column = draggedObject as IColumn;
this.txtSqlString.AppendText(colName + " = ?"); string colName = column.Name;
}
else if (this.txtSqlString.Text.Length == 0)
{ {
this.txtSqlString.AppendText(", "); this.txtSqlString.AppendText("SELECT ");
this.txtSqlString.AppendText(colName); this.txtSqlString.AppendText(colName);
} }
reportStructure.CommandType = CommandType.Text;
reportStructure.IDatabaseObjectBase = column; else if (this.txtSqlString.Text.ToUpper(CultureInfo.InvariantCulture).IndexOf("where", StringComparison.OrdinalIgnoreCase) > 0)
break; {
this.txtSqlString.AppendText(colName + " = ?");
case NodeType.ProcedureImage: }
this.txtSqlString.Clear(); else
{
// we can't use the dragobject because it returns an string like 'EXECUTE ProcName' this.txtSqlString.AppendText(", ");
IProcedure procedure = draggedObject as IProcedure; this.txtSqlString.AppendText(colName);
this.txtSqlString.Text = "[" + procedure.Name + "]"; }
reportStructure.CommandType = CommandType.StoredProcedure; reportStructure.CommandType = CommandType.Text;
reportStructure.IDatabaseObjectBase = procedure; reportStructure.IDatabaseObjectBase = column;
break; break;
case NodeType.ViewImage: case NodeType.ProcedureImage:
this.txtSqlString.Text = String.Empty; this.txtSqlString.Clear();
this.txtSqlString.Text = "No idea how to handle views";
break; // we can't use the dragobject because it returns an string like 'EXECUTE ProcName'
default: IProcedure procedure = draggedObject as IProcedure;
break; this.txtSqlString.Text = "[" + procedure.Name + "]";
} reportStructure.CommandType = CommandType.StoredProcedure;
base.EnableNext = true; reportStructure.IDatabaseObjectBase = procedure;
break;
/*
case NodeType.ViewImage:
this.txtSqlString.Text = String.Empty;
this.txtSqlString.Text = "No idea how to handle views";
break;
*/
default:
break;
}
base.EnableNext = true;
} }

27
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