using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Configuration;
using log4net;
using Npgsql;
using NpgsqlTypes;
namespace SiteOffice.Data{
/// <summary>
/// Author: Joe Audette
/// Created: 2007-11-15
/// Last Modified: 2007-11-15
///
///
/// The use and distribution terms for this software are covered by the
/// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
/// which can be found in the file CPL.TXT at the root of this distribution.
/// By using this software in any fashion, you are agreeing to be bound by
/// the terms of this license.
///
/// You must not remove this notice, or any other, from this software.
///
/// </summary>
public static class DBPrivateMessagePriority
{
private static readonly ILog log = LogManager.GetLogger(typeof(DBPrivateMessagePriority));
public static String DBPlatform()
{
return "pgsql";
}
private static string GetConnectionString()
{
string connectionString = ConfigurationManager.AppSettings["PostgreSQLConnectionString"];
if (ConfigurationManager.AppSettings["SiteOfficePostgreSQLConnectionString"] != null)
{
connectionString = ConfigurationManager.AppSettings["SiteOfficePostgreSQLConnectionString"];
}
return connectionString;
}
public static int AddPrivateMessagePriority(
Guid priorityId,
string priority)
{
NpgsqlParameter[] arParams = new NpgsqlParameter[1];
if (ConfigurationManager.AppSettings["CachePostgreSQLParameters"].ToLower() == "true")
{
arParams = NpgsqlHelperParameterCache.GetParameterSet(GetConnectionString(),
"mp_privatemessagepriority_insert(:priorityid,:priority)");
arParams[0].Value = priorityId.ToString();
arParams[1].Value = priority;
}
else
{
arParams[0] = new NpgsqlParameter("priorityid", NpgsqlTypes.NpgsqlDbType.Varchar, 36);
arParams[0].Direction = ParameterDirection.Input;
arParams[0].Value = priorityId.ToString();
arParams[1] = new NpgsqlParameter("priority", NpgsqlTypes.NpgsqlDbType.Varchar, 50);
arParams[1].Direction = ParameterDirection.Input;
arParams[1].Value = priority;
}
int rowsAffected = NpgsqlHelper.ExecuteNonQuery(GetConnectionString(),
CommandType.StoredProcedure,
"mp_privatemessagepriority_insert(:priorityid,:priority)",
arParams);
return rowsAffected;
}
public static bool UpdatePrivateMessagePriority(
Guid priorityId,
string priority)
{
NpgsqlParameter[] arParams = new NpgsqlParameter[2];
if (ConfigurationManager.AppSettings["CachePostgreSQLParameters"].ToLower() == "true")
{
arParams = NpgsqlHelperParameterCache.GetParameterSet(GetConnectionString(),
"mp_privatemessagepriority_update(:priorityid,:priority)");
arParams[0].Value = priorityId.ToString();
arParams[1].Value = priority;
}
else
{
arParams[0] = new NpgsqlParameter("priorityid", NpgsqlTypes.NpgsqlDbType.Varchar, 36);
arParams[0].Direction = ParameterDirection.Input;
arParams[0].Value = priorityId.ToString();
arParams[1] = new NpgsqlParameter("priority", NpgsqlTypes.NpgsqlDbType.Varchar, 50);
arParams[1].Direction = ParameterDirection.Input;
arParams[1].Value = priority;
}
int rowsAffected = NpgsqlHelper.ExecuteNonQuery(GetConnectionString(),
CommandType.StoredProcedure,
"mp_privatemessagepriority_update(:priorityid,:priority)",
arParams);
return (rowsAffected > -1);
}
public static bool DeletePrivateMessagePriority(
Guid priorityId)
{
NpgsqlParameter[] arParams = new NpgsqlParameter[1];
if (ConfigurationManager.AppSettings["CachePostgreSQLParameters"].ToLower() == "true")
{
arParams = NpgsqlHelperParameterCache.GetParameterSet(GetConnectionString(),
"mp_privatemessagepriority_delete(:priorityid)");
arParams[0].Value = priorityId.ToString();
}
else
{
arParams[0] = new NpgsqlParameter("priorityid", NpgsqlTypes.NpgsqlDbType.Varchar, 36);
arParams[0].Direction = ParameterDirection.Input;
arParams[0].Value = priorityId.ToString();
}
int rowsAffected = NpgsqlHelper.ExecuteNonQuery(GetConnectionString(),
CommandType.StoredProcedure,
"mp_privatemessagepriority_delete(:priorityid)",
arParams);
return (rowsAffected > -1);
}
public static IDataReader GetPrivateMessagePriority(
Guid priorityId)
{
NpgsqlParameter[] arParams = new NpgsqlParameter[1];
if (ConfigurationManager.AppSettings["CachePostgreSQLParameters"].ToLower() == "true")
{
arParams = NpgsqlHelperParameterCache.GetParameterSet(GetConnectionString(),
"mp_privatemessagepriority_selectone(:priorityid)");
arParams[0].Value = priorityId.ToString();
}
else
{
arParams[0] = new NpgsqlParameter("priorityid", NpgsqlTypes.NpgsqlDbType.Varchar, 36);
arParams[0].Direction = ParameterDirection.Input;
arParams[0].Value = priorityId.ToString();
}
return NpgsqlHelper.ExecuteReader(
GetConnectionString(),
CommandType.StoredProcedure,
"mp_privatemessagepriority_selectone(:priorityid)",
arParams);
}
}
}
|