// // DotNetNuke - http://www.dotnetnuke.com // Copyright (c) 2002-2005 // by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca ) // // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated // documentation files (the "Software"), to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and // to permit persons to whom the Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all copies or substantial portions // of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // using System; using System.Data; using System.Data.SqlClient; using Microsoft.ApplicationBlocks.Data; using DotNetNuke; using DotNetNuke.Common.Utilities; namespace DotNetNuke.Modules.Survey { public class SqlDataProvider : DataProvider { private const string ProviderType = "data"; private Framework.Providers.ProviderConfiguration _providerConfiguration = Framework.Providers.ProviderConfiguration.GetProviderConfiguration(ProviderType); private string _connectionString; private string _providerPath; private string _objectQualifier; private string _databaseOwner; public SqlDataProvider() { Framework.Providers.Provider objProvider = ((Framework.Providers.Provider)(_providerConfiguration.Providers[_providerConfiguration.DefaultProvider])); // This code handles getting the connection string from either the connectionString / appsetting section and uses the connectionstring section by default if it exists. // Get Connection string from web.config _connectionString = Config.GetConnectionString(); // If above funtion does not return anything then connectionString must be set in the dataprovider section. if ((_connectionString == "")) { // Use connection string specified in provider _connectionString = objProvider.Attributes["connectionString"]; } _providerPath = objProvider.Attributes["providerPath"]; _objectQualifier = objProvider.Attributes["objectQualifier"]; if (_objectQualifier != "" & _objectQualifier.EndsWith("_") == false) { _objectQualifier += "_"; } _databaseOwner = objProvider.Attributes["databaseOwner"]; if (_databaseOwner != "" & _databaseOwner.EndsWith(".") == false) { _databaseOwner += "."; } } public string ConnectionString { get { return _connectionString; } } public string ProviderPath { get { return _providerPath; } } public string ObjectQualifier { get { return _objectQualifier; } } public string DatabaseOwner { get { return _databaseOwner; } } private object GetNull(object Field) { return DotNetNuke.Common.Utilities.Null.GetNull(Field, DBNull.Value); } public override IDataReader GetSurveys(int ModuleId) { return ((IDataReader)(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "GetSurveys", ModuleId))); } public override IDataReader GetSurvey(int SurveyID, int ModuleId) { return ((IDataReader)(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "GetSurvey", SurveyID, ModuleId))); } public override int AddSurvey(int ModuleId, string Question, int ViewOrder, string OptionType, int UserId) { return (Convert.ToInt32((SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner + ObjectQualifier + "AddSurvey", ModuleId, Question, GetNull(ViewOrder), OptionType, UserId)))); } public override void UpdateSurvey(int SurveyId, string Question, int ViewOrder, string OptionType, int UserId, int ModuleId) { SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "UpdateSurvey", SurveyId, Question, GetNull(ViewOrder), OptionType, UserId, ModuleId); } public override void DeleteSurvey(int SurveyID, int ModuleId) { SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "DeleteSurvey", SurveyID, ModuleId); } public override IDataReader GetSurveyOptions(int SurveyId) { return ((IDataReader)(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "GetSurveyOptions", SurveyId))); } public override int AddSurveyOption(int SurveyId, string OptionName, int ViewOrder, bool IsCorrect) { return (Convert.ToInt32((SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner + ObjectQualifier + "AddSurveyOption", SurveyId, OptionName, GetNull(ViewOrder), IsCorrect)))); } public override void UpdateSurveyOption(int SurveyOptionId, string OptionName, int ViewOrder, bool IsCorrect) { SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "UpdateSurveyOption", SurveyOptionId, OptionName, GetNull(ViewOrder), IsCorrect); } public override void DeleteSurveyOption(int SurveyOptionID) { SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "DeleteSurveyOption", SurveyOptionID); } public override void AddSurveyResult(int SurveyOptionId, int UserId) { SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "AddSurveyResult", SurveyOptionId, UserId); } } }