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 DBPrivateMessageAttachment
{
private static readonly ILog log = LogManager.GetLogger(typeof(DBPrivateMessageAttachment));
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 AddPrivateMessageAttachment(
Guid attachmentId,
Guid messageId,
string originalFileName,
string serverFileName,
DateTime createdDate)
{
NpgsqlParameter[] arParams = new NpgsqlParameter[4];
if (ConfigurationManager.AppSettings["CachePostgreSQLParameters"].ToLower() == "true")
{
arParams = NpgsqlHelperParameterCache.GetParameterSet(GetConnectionString(),
"mp_privatemessageattachments_insert(:attachmentid,:messageid,:originalfilename,:serverfilename,:createddate)");
arParams[0].Value = attachmentId.ToString();
arParams[1].Value = messageId.ToString();
arParams[2].Value = originalFileName;
arParams[3].Value = serverFileName;
arParams[4].Value = createdDate;
}
else
{
arParams[0] = new NpgsqlParameter("attachmentid", NpgsqlTypes.NpgsqlDbType.Varchar, 36);
arParams[0].Direction = ParameterDirection.Input;
arParams[0].Value = attachmentId.ToString();
arParams[1] = new NpgsqlParameter("messageid", NpgsqlTypes.NpgsqlDbType.Varchar, 36);
arParams[1].Direction = ParameterDirection.Input;
arParams[1].Value = messageId.ToString();
arParams[2] = new NpgsqlParameter("originalfilename", NpgsqlTypes.NpgsqlDbType.Varchar, 255);
arParams[2].Direction = ParameterDirection.Input;
arParams[2].Value = originalFileName;
arParams[3] = new NpgsqlParameter("serverfilename", NpgsqlTypes.NpgsqlDbType.Varchar, 50);
arParams[3].Direction = ParameterDirection.Input;
arParams[3].Value = serverFileName;
arParams[4] = new NpgsqlParameter("createddate", NpgsqlTypes.NpgsqlDbType.Date);
arParams[4].Direction = ParameterDirection.Input;
arParams[4].Value = createdDate;
}
int rowsAffected = NpgsqlHelper.ExecuteNonQuery(GetConnectionString(),
CommandType.StoredProcedure,
"mp_privatemessageattachments_insert(:attachmentid,:messageid,:originalfilename,:serverfilename,:createddate)",
arParams);
return rowsAffected;
}
public static bool UpdatePrivateMessageAttachment(
Guid attachmentId,
Guid messageId,
string originalFileName,
string serverFileName,
DateTime createdDate)
{
NpgsqlParameter[] arParams = new NpgsqlParameter[5];
if (ConfigurationManager.AppSettings["CachePostgreSQLParameters"].ToLower() == "true")
{
arParams = NpgsqlHelperParameterCache.GetParameterSet(GetConnectionString(),
"mp_privatemessageattachments_update(:attachmentid,:messageid,:originalfilename,:serverfilename,:createddate)");
arParams[0].Value = attachmentId.ToString();
arParams[1].Value = messageId.ToString();
arParams[2].Value = originalFileName;
arParams[3].Value = serverFileName;
arParams[4].Value = createdDate;
}
else
{
arParams[0] = new NpgsqlParameter("attachmentid", NpgsqlTypes.NpgsqlDbType.Varchar, 36);
arParams[0].Direction = ParameterDirection.Input;
arParams[0].Value = attachmentId.ToString();
arParams[1] = new NpgsqlParameter("messageid", NpgsqlTypes.NpgsqlDbType.Varchar, 36);
arParams[1].Direction = ParameterDirection.Input;
arParams[1].Value = messageId.ToString();
arParams[2] = new NpgsqlParameter("originalfilename", NpgsqlTypes.NpgsqlDbType.Varchar, 255);
arParams[2].Direction = ParameterDirection.Input;
arParams[2].Value = originalFileName;
arParams[3] = new NpgsqlParameter("serverfilename", NpgsqlTypes.NpgsqlDbType.Varchar, 50);
arParams[3].Direction = ParameterDirection.Input;
arParams[3].Value = serverFileName;
arParams[4] = new NpgsqlParameter("createddate", NpgsqlTypes.NpgsqlDbType.Date);
arParams[4].Direction = ParameterDirection.Input;
arParams[4].Value = createdDate;
}
int rowsAffected = NpgsqlHelper.ExecuteNonQuery(GetConnectionString(),
CommandType.StoredProcedure,
"mp_privatemessageattachments_update(:attachmentid,:messageid,:originalfilename,:serverfilename,:createddate)",
arParams);
return (rowsAffected > -1);
}
public static bool DeletePrivateMessageAttachment(
Guid attachmentId)
{
NpgsqlParameter[] arParams = new NpgsqlParameter[1];
if (ConfigurationManager.AppSettings["CachePostgreSQLParameters"].ToLower() == "true")
{
arParams = NpgsqlHelperParameterCache.GetParameterSet(GetConnectionString(),
"mp_privatemessageattachments_delete(:attachmentid)");
arParams[0].Value = attachmentId.ToString();
}
else
{
arParams[0] = new NpgsqlParameter("attachmentid", NpgsqlTypes.NpgsqlDbType.Varchar, 36);
arParams[0].Direction = ParameterDirection.Input;
arParams[0].Value = attachmentId.ToString();
}
int rowsAffected = NpgsqlHelper.ExecuteNonQuery(GetConnectionString(),
CommandType.StoredProcedure,
"mp_privatemessageattachments_delete(:attachmentid)",
arParams);
return (rowsAffected > -1);
}
public static IDataReader GetPrivateMessageAttachment(
Guid attachmentId)
{
NpgsqlParameter[] arParams = new NpgsqlParameter[1];
if (ConfigurationManager.AppSettings["CachePostgreSQLParameters"].ToLower() == "true")
{
arParams = NpgsqlHelperParameterCache.GetParameterSet(GetConnectionString(),
"mp_privatemessageattachments_selectone(:attachmentid)");
arParams[0].Value = attachmentId.ToString();
}
else
{
arParams[0] = new NpgsqlParameter("attachmentid", NpgsqlTypes.NpgsqlDbType.Varchar, 36);
arParams[0].Direction = ParameterDirection.Input;
arParams[0].Value = attachmentId.ToString();
}
return NpgsqlHelper.ExecuteReader(
GetConnectionString(),
CommandType.StoredProcedure,
"mp_privatemessageattachments_selectone(:attachmentid)",
arParams);
}
}
}
|