private DataSet FillGrid() { SqlQueryChecker.Check(model.ReportSettings.CommandType, model.ReportSettings.CommandText); DataSet dataSet = ResultPanel.CreateDataSet(); this.txtSqlString.Text = model.ReportSettings.CommandText; var dataAccess = new SqlDataAccessStrategy(model.ReportSettings); switch (model.ReportSettings.CommandType) { case CommandType.Text: dataSet = DataSetFromSqlText(dataAccess); break; case CommandType.StoredProcedure: dataSet = DataSetFromStoredProcedure(dataAccess); break; case CommandType.TableDirect: MessageService.ShowError("TableDirect is not suppurted at the moment"); break; default: throw new Exception("Invalid value for CommandType"); } return(dataSet); }
private DataSet FillGrid() { this.connectionObject = ConnectionObject.CreateInstance(this.model.ReportSettings.ConnectionString, System.Data.Common.DbProviderFactories.GetFactory("System.Data.OleDb")); this.txtSqlString.Text = String.Empty; SqlQueryChecker.Check(model.ReportSettings.CommandType, model.ReportSettings.CommandText); DataSet dataSet = ResultPanel.CreateDataSet(); switch (model.ReportSettings.CommandType) { case CommandType.Text: this.txtSqlString.Text = model.ReportSettings.CommandText; dataSet = BuildFromSqlString(); break; case CommandType.StoredProcedure: MessageService.ShowError("Stored Procedures are not suppurted at the moment"); break; case CommandType.TableDirect: MessageService.ShowError("TableDirect is not suppurted at the moment"); break; default: throw new Exception("Invalid value for CommandType"); } if (model.ReportSettings.CommandType == CommandType.StoredProcedure) { /* * if (reportStructure.SharpQueryProcedure == null) { * throw new IllegalQueryException(); * } * * SharpQueryProcedure procedure = reportStructure.SharpQueryProcedure; * SharpQuerySchemaClassCollection sc = procedure.GetSchemaParameters(); * * if ((sc != null) && sc.Count > 0) { * dataSet = ExecuteStoredProc (procedure); * }else { * dataSet = ExecuteStoredProc (); * } */ } // from here we create from an SqlString like "Select...." // if (model.ReportSettings.CommandType == CommandType.Text){ // this.txtSqlString.Text = model.ReportSettings.CommandText; // dataSet = BuildFromSqlString(); // } return(dataSet); }
private DataSet ExecuteStoredProc(SharpQueryProcedure procedure) { SharpQuerySchemaClassCollection tmp = procedure.GetSchemaParameters(); this.sqlParamsCollection = new ParameterCollection(); SqlParameterConverter converter = new SqlParameterConverter(); if (converter.CanConvertFrom(typeof(SharpQuerySchemaClassCollection))) { if (converter.CanConvertTo(null, typeof(ParameterCollection))) { sqlParamsCollection = (ParameterCollection)converter.ConvertTo(null, CultureInfo.InstalledUICulture, tmp, typeof(ParameterCollection)); } } if (sqlParamsCollection.Count > 0) { using (ParameterDialog inputform = new ParameterDialog(sqlParamsCollection)) { if (inputform.ShowDialog() != DialogResult.OK) { return(null); } else { IDbCommand command = this.BuildCommand(); DbDataAdapter adapter = this.BuildAdapter(); DataSet dataSet = ResultPanel.CreateDataSet(); try { SqlDataAccessStrategy.BuildQueryParameters(command, sqlParamsCollection); adapter.SelectCommand = (DbCommand)command; adapter.Fill(dataSet); return(dataSet); } catch (Exception e) { MessageService.ShowError(e.Message); } finally { if (adapter.SelectCommand.Connection.State == ConnectionState.Open) { adapter.SelectCommand.Connection.Close(); } } } } } return(null); }
private DataSet BuildFromSqlString() { DbDataAdapter adapter = null; try { adapter = this.BuildAdapter(); DataSet dataSet = ResultPanel.CreateDataSet(); adapter.Fill(dataSet); return(dataSet); } finally { if (adapter.SelectCommand.Connection.State == ConnectionState.Open) { adapter.SelectCommand.Connection.Close(); } } }
private DataSet DataSetFromStoredProcedure(IDataAccessStrategy dataAccess) { DataSet dataSet = ResultPanel.CreateDataSet(); IProcedure procedure = reportStructure.IDatabaseObjectBase as IProcedure; var sqlParamCollection = CreateSqlParameters(procedure); if (sqlParamCollection.Count > 0) { reportStructure.SqlQueryParameters.AddRange(sqlParamCollection); model.ReportSettings.SqlParameters.AddRange(sqlParamCollection); CollectParamValues(model.ReportSettings); } dataSet = dataAccess.ReadData(); dataSet.Tables[0].TableName = procedure.Name; return(dataSet); }
private DataSet FillGrid() { this.connectionObject = ConnectionObject.CreateInstance(this.model.ReportSettings.ConnectionString, System.Data.Common.DbProviderFactories.GetFactory("System.Data.OleDb")); this.txtSqlString.Text = String.Empty; SqlQueryChecker.Check(model.ReportSettings.CommandType, model.ReportSettings.CommandText); DataSet dataSet = ResultPanel.CreateDataSet(); this.txtSqlString.Text = model.ReportSettings.CommandText; if (model.ReportSettings.CommandType == CommandType.StoredProcedure) { if (reportStructure.SharpQueryProcedure == null) { throw new IllegalQueryException(); } SharpQueryProcedure procedure = reportStructure.SharpQueryProcedure; SharpQuerySchemaClassCollection sc = procedure.GetSchemaParameters(); if ((sc != null) && sc.Count > 0) { dataSet = ExecuteStoredProc(procedure); } else { dataSet = ExecuteStoredProc(); } } // from here we create from an SqlString like "Select...." if (model.ReportSettings.CommandType == CommandType.Text) { this.txtSqlString.Text = model.ReportSettings.CommandText; dataSet = BuildFromSqlString(); } return(dataSet); }
DataSet DatasetFromStoredProcedure() { this.connectionObject = CreateConnection(); DataSet dataSet = ResultPanel.CreateDataSet(); IProcedure procedure = reportStructure.IDatabaseObjectBase as IProcedure; var paramCollection = CheckParameters(procedure); if (paramCollection.Count > 0) { FillParameters(paramCollection); reportStructure.SqlQueryParameters.AddRange(paramCollection); } var dataAccess = new SqlDataAccessStrategy(model.ReportSettings, connectionObject); dataSet = dataAccess.ReadData(); dataSet.Tables[0].TableName = procedure.Name; return(dataSet); }