Committing for deployment
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
using Activizr.Basic.Enums;
|
||||
using Activizr.Basic.Interfaces;
|
||||
using Activizr.Basic.Types;
|
||||
|
||||
namespace Activizr.Database
|
||||
{
|
||||
public partial class PirateDb
|
||||
{
|
||||
private const string organizationFinancialAccountsDataFieldSequence =
|
||||
" OrganizationFinancialAccountTypes.Name AS OrganizationFinancialAccountType,OrganizationFinancialAccounts.OrganizationId,OrganizationFinancialAccounts.FinancialAccountId FROM OrganizationFinancialAccounts " +
|
||||
"JOIN OrganizationFinancialAccountTypes ON (OrganizationFinancialAccounts.OrganizationFinancialAccountTypeId=OrganizationFinancialAccountTypes.OrganizationFinancialAccountTypeId) ";
|
||||
|
||||
|
||||
#region Select statements - reading data
|
||||
|
||||
public int GetOrganizationFinancialAccountId(int organizationId, OrganizationFinancialAccountType organizationFinancialAccountType)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command =
|
||||
GetDbCommand(
|
||||
"SELECT" + organizationFinancialAccountsDataFieldSequence + "WHERE OrganizationFinancialAccountTypes.Name='" + organizationFinancialAccountType.ToString() + "' " +
|
||||
"AND OrganizationFinancialAccounts.Organizationid=" + organizationId.ToString() + ";", connection);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
// account Id is third in select list, just return it
|
||||
|
||||
return reader.GetInt32(2);
|
||||
}
|
||||
|
||||
// TODO: Throw instead if requested account not found?
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
public int[] GetObjectsByOptionalData(ObjectType objectType, ObjectOptionalDataType dataType, string data)
|
||||
{
|
||||
List<int> objectIds = new List<int>();
|
||||
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command =
|
||||
GetDbCommand(
|
||||
"SELECT" + objectOptionalDataFieldSequence + "WHERE ObjectTypes.Name='" + objectType.ToString() + "' " +
|
||||
"AND ObjectOptionalDataTypes.Name='" + dataType.ToString() + "' " +
|
||||
"AND ObjectOptionalData.Data='" + data.Replace("'", "''") + "';", connection);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
objectIds.Add(reader.GetInt32(1));
|
||||
}
|
||||
|
||||
return objectIds.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static private ObjectType GetObjectTypeForObject(IHasIdentity objectToIdentify)
|
||||
{
|
||||
//string objectTypeString = objectToIdentify.GetType().ToString();
|
||||
|
||||
//// Strip namespace
|
||||
|
||||
//int lastPeriodIndex = objectTypeString.LastIndexOf('.');
|
||||
//objectTypeString = objectTypeString.Substring(lastPeriodIndex + 1);
|
||||
|
||||
string objectTypeString = objectToIdentify.GetType().Name;
|
||||
|
||||
// At this point, we should be able to cast the string to an ObjectType enum
|
||||
try
|
||||
{
|
||||
return (ObjectType)Enum.Parse(typeof(ObjectType), objectTypeString);
|
||||
}
|
||||
catch
|
||||
{
|
||||
//That failed. This could be a subclass, try upwards.
|
||||
Type parentType = objectToIdentify.GetType().BaseType;
|
||||
while (parentType != typeof(Object))
|
||||
{
|
||||
try
|
||||
{
|
||||
return (ObjectType)Enum.Parse(typeof(ObjectType), parentType.Name);
|
||||
}
|
||||
catch
|
||||
{
|
||||
parentType = parentType.BaseType;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new InvalidCastException("GetObjectTypeForObject could not identify object of type " + objectToIdentify.GetType().Name);
|
||||
}*/
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Stored procedures for modifying data
|
||||
|
||||
public void SetOrganizationFinancialAccountId(int organizationId, OrganizationFinancialAccountType accountType, int financialAccountId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetOrganizationFinancialAccount", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "organizationId", organizationId);
|
||||
AddParameterWithName(command, "organizationFinancialAccountTypeName", accountType.ToString());
|
||||
AddParameterWithName(command, "financialAccountId", financialAccountId);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -89,6 +89,7 @@
|
||||
<Compile Include="Database-Motions.cs" />
|
||||
<Compile Include="Database-Optimizations.cs" />
|
||||
<Compile Include="Database-OptionalData.cs" />
|
||||
<Compile Include="Database-OrganizationFinancialAccounts.cs" />
|
||||
<Compile Include="Database-Organizations.cs" />
|
||||
<Compile Include="Database-OutboundInvoices.cs" />
|
||||
<Compile Include="Database-OutboundMailRecipients.cs" />
|
||||
|
||||
Reference in New Issue
Block a user