Fix for another loc bug
This commit is contained in:
@@ -4,6 +4,8 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Web;
|
||||
using Swarmops.Logic.Structure;
|
||||
using Swarmops.Logic.Swarm;
|
||||
|
||||
/// <summary>
|
||||
/// Summary description for CommonV5Base
|
||||
@@ -66,4 +68,42 @@ public class CommonV5Base
|
||||
|
||||
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
|
||||
}
|
||||
|
||||
public static AuthenticationData GetAuthenticationDataAndCulture(HttpContext suppliedContext)
|
||||
{
|
||||
// This function is called from static page methods in AJAX calls to get
|
||||
// the current set of authentication data. Static page methods cannot access
|
||||
// the instance data of PageV5Base.
|
||||
|
||||
AuthenticationData result = new AuthenticationData();
|
||||
|
||||
// Find various credentials
|
||||
|
||||
string identity = suppliedContext.User.Identity.Name;
|
||||
string[] identityTokens = identity.Split(',');
|
||||
|
||||
string userIdentityString = identityTokens[0];
|
||||
string organizationIdentityString = identityTokens[1];
|
||||
|
||||
int currentUserId = Convert.ToInt32(userIdentityString);
|
||||
int currentOrganizationId = Convert.ToInt32(organizationIdentityString);
|
||||
|
||||
result.CurrentUser = Person.FromIdentity(currentUserId);
|
||||
result.CurrentOrganization = Organization.FromIdentity(currentOrganizationId);
|
||||
|
||||
CommonV5Base.CulturePreInit(HttpContext.Current.Request); // OnPreInit() isn't called in the static methods calling this fn
|
||||
|
||||
/*
|
||||
string userCultureString = result.CurrentUser.PreferredCulture;
|
||||
|
||||
if (!string.IsNullOrEmpty(userCultureString))
|
||||
{
|
||||
CultureInfo userCulture = new CultureInfo(userCultureString); // may throw on invalid database data
|
||||
Thread.CurrentThread.CurrentCulture = userCulture;
|
||||
Thread.CurrentThread.CurrentUICulture = userCulture;
|
||||
}*/
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -130,47 +130,9 @@ public class DataV5Base : System.Web.UI.Page
|
||||
|
||||
protected static AuthenticationData GetAuthenticationDataAndCulture()
|
||||
{
|
||||
return GetAuthenticationDataAndCulture(HttpContext.Current);
|
||||
return CommonV5Base.GetAuthenticationDataAndCulture(HttpContext.Current);
|
||||
}
|
||||
|
||||
protected static AuthenticationData GetAuthenticationDataAndCulture(HttpContext suppliedContext)
|
||||
{
|
||||
// This function is called from static page methods in AJAX calls to get
|
||||
// the current set of authentication data. Static page methods cannot access
|
||||
// the instance data of PageV5Base.
|
||||
|
||||
AuthenticationData result = new AuthenticationData();
|
||||
|
||||
// Find various credentials
|
||||
|
||||
string identity = suppliedContext.User.Identity.Name;
|
||||
string[] identityTokens = identity.Split(',');
|
||||
|
||||
string userIdentityString = identityTokens[0];
|
||||
string organizationIdentityString = identityTokens[1];
|
||||
|
||||
int currentUserId = Convert.ToInt32(userIdentityString);
|
||||
int currentOrganizationId = Convert.ToInt32(organizationIdentityString);
|
||||
|
||||
result.CurrentUser = Person.FromIdentity(currentUserId);
|
||||
result.CurrentOrganization = Organization.FromIdentity(currentOrganizationId);
|
||||
|
||||
CommonV5Base.CulturePreInit(HttpContext.Current.Request); // OnPreInit() isn't called in the static methods calling this fn
|
||||
|
||||
/*
|
||||
string userCultureString = result.CurrentUser.PreferredCulture;
|
||||
|
||||
if (!string.IsNullOrEmpty(userCultureString))
|
||||
{
|
||||
CultureInfo userCulture = new CultureInfo(userCultureString); // may throw on invalid database data
|
||||
Thread.CurrentThread.CurrentCulture = userCulture;
|
||||
Thread.CurrentThread.CurrentUICulture = userCulture;
|
||||
}*/
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
protected static string JsonSanitize (string input)
|
||||
{
|
||||
return input.Replace("\"", "\\\"").Replace(" ", " ").Trim();
|
||||
|
||||
@@ -127,32 +127,7 @@ public class PageV5Base : System.Web.UI.Page
|
||||
// the current set of authentication data. Static page methods cannot access
|
||||
// the instance data of PageV5Base.
|
||||
|
||||
AuthenticationData result = new AuthenticationData();
|
||||
|
||||
// Find various credentials
|
||||
|
||||
string identity = HttpContext.Current.User.Identity.Name;
|
||||
string[] identityTokens = identity.Split(',');
|
||||
|
||||
string userIdentityString = identityTokens[0];
|
||||
string organizationIdentityString = identityTokens[1];
|
||||
|
||||
int currentUserId = Convert.ToInt32(userIdentityString);
|
||||
int currentOrganizationId = Convert.ToInt32(organizationIdentityString);
|
||||
|
||||
result.CurrentUser = Person.FromIdentity(currentUserId);
|
||||
result.CurrentOrganization = Organization.FromIdentity(currentOrganizationId);
|
||||
|
||||
string userCultureString = result.CurrentUser.PreferredCulture;
|
||||
|
||||
if (!string.IsNullOrEmpty(userCultureString))
|
||||
{
|
||||
CultureInfo userCulture = new CultureInfo(userCultureString); // may throw on invalid database data
|
||||
Thread.CurrentThread.CurrentCulture = userCulture;
|
||||
Thread.CurrentThread.CurrentUICulture = userCulture;
|
||||
}
|
||||
|
||||
return result;
|
||||
return CommonV5Base.GetAuthenticationDataAndCulture(HttpContext.Current);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -157,7 +157,7 @@ namespace Swarmops.Frontend.Automation
|
||||
HttpPostedFile file = context.Request.Files[i];
|
||||
string fullName = Path.GetFileName (file.FileName);
|
||||
|
||||
AuthenticationData authData = GetAuthenticationDataAndCulture (context);
|
||||
AuthenticationData authData = CommonV5Base.GetAuthenticationDataAndCulture (context);
|
||||
|
||||
Person uploadingPerson = authData.CurrentUser;
|
||||
Organization currentOrg = authData.CurrentOrganization;
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Web.Services;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using Swarmops.Basic.Enums;
|
||||
using Swarmops.Database;
|
||||
using Swarmops.Logic.Financial;
|
||||
using Swarmops.Logic.Security;
|
||||
using Swarmops.Logic.Support;
|
||||
@@ -212,47 +213,61 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
[WebMethod]
|
||||
public static ChangeAccountDataResult SetAccountBudget(int accountId, string budget)
|
||||
{
|
||||
AuthenticationData authData = GetAuthenticationDataAndCulture();
|
||||
FinancialAccount account = FinancialAccount.FromIdentity(accountId);
|
||||
|
||||
if (!PrepareAccountChange(account, authData, false))
|
||||
try
|
||||
{
|
||||
return new ChangeAccountDataResult
|
||||
AuthenticationData authData = GetAuthenticationDataAndCulture();
|
||||
FinancialAccount account = FinancialAccount.FromIdentity(accountId);
|
||||
|
||||
if (!PrepareAccountChange(account, authData, false))
|
||||
{
|
||||
Result = ChangeAccountDataOperationsResult.NoPermission
|
||||
};
|
||||
return new ChangeAccountDataResult
|
||||
{
|
||||
Result = ChangeAccountDataOperationsResult.NoPermission
|
||||
};
|
||||
}
|
||||
|
||||
Int64 newTreeBudget;
|
||||
budget = budget.Replace("%A0", "%20"); // some very weird browser space-to-otherspace translation weirds out number parsing
|
||||
budget = HttpContext.Current.Server.UrlDecode(budget);
|
||||
|
||||
if (budget.Trim().Length > 0 && Int64.TryParse(budget, NumberStyles.Currency, CultureInfo.CurrentCulture, out newTreeBudget))
|
||||
{
|
||||
newTreeBudget *= 100; // convert to cents
|
||||
|
||||
int year = DateTime.Today.Year;
|
||||
FinancialAccounts accountTree = account.GetTree();
|
||||
Int64 currentTreeBudget = accountTree.GetBudgetSumCents(year);
|
||||
Int64 currentSingleBudget = account.GetBudgetCents(year);
|
||||
Int64 suballocatedBudget = currentTreeBudget - currentSingleBudget;
|
||||
|
||||
Int64 newSingleBudget = newTreeBudget - suballocatedBudget;
|
||||
|
||||
account.SetBudgetCents(DateTime.Today.Year, newSingleBudget);
|
||||
return new ChangeAccountDataResult
|
||||
{
|
||||
Result = ChangeAccountDataOperationsResult.Changed,
|
||||
NewData = (newTreeBudget/100).ToString("N0", CultureInfo.CurrentCulture)
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ChangeAccountDataResult
|
||||
{
|
||||
Result = ChangeAccountDataOperationsResult.Invalid
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception weirdException)
|
||||
{
|
||||
// Exceptions are happening here in deployment ONLY. We're logging it to find which one and why.
|
||||
// TODO: This really needs to be in Logic. DO NOT DO NOT DO NOT call Database layer directly from Site layer.
|
||||
|
||||
SwarmDb.GetDatabaseForWriting().CreateExceptionLogEntry(DateTime.UtcNow, "AccountPlan-SetBudget", weirdException);
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
Int64 newTreeBudget;
|
||||
budget = budget.Replace("%A0", "%20"); // some very weird browser space-to-otherspace translation weirds out number parsing
|
||||
budget = HttpContext.Current.Server.UrlDecode(budget);
|
||||
|
||||
if (budget.Trim().Length > 0 && Int64.TryParse(budget, NumberStyles.Currency, CultureInfo.CurrentCulture, out newTreeBudget))
|
||||
{
|
||||
newTreeBudget *= 100; // convert to cents
|
||||
|
||||
int year = DateTime.Today.Year;
|
||||
FinancialAccounts accountTree = account.GetTree();
|
||||
Int64 currentTreeBudget = accountTree.GetBudgetSumCents(year);
|
||||
Int64 currentSingleBudget = account.GetBudgetCents(year);
|
||||
Int64 suballocatedBudget = currentTreeBudget - currentSingleBudget;
|
||||
|
||||
Int64 newSingleBudget = newTreeBudget - suballocatedBudget;
|
||||
|
||||
account.SetBudgetCents(DateTime.Today.Year, newSingleBudget);
|
||||
return new ChangeAccountDataResult
|
||||
{
|
||||
Result = ChangeAccountDataOperationsResult.Changed,
|
||||
NewData = (newTreeBudget/100).ToString("N0", CultureInfo.CurrentCulture)
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ChangeAccountDataResult
|
||||
{
|
||||
Result = ChangeAccountDataOperationsResult.Invalid
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
|
||||
@@ -99,10 +99,8 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
}
|
||||
|
||||
private int _year = 2012;
|
||||
private CultureInfo _renderCulture;
|
||||
private AuthenticationData _authenticationData;
|
||||
private Dictionary<int, FinancialAccounts> _hashedAccounts;
|
||||
|
||||
// private Dictionary<int, FinancialAccounts> _hashedAccounts;
|
||||
|
||||
private string PrintNullableCents (string currency, long cents)
|
||||
{
|
||||
@@ -135,7 +133,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* -- is this even used?
|
||||
private string GetAccountGroup (FinancialAccountType type, string localizedGroupName)
|
||||
{
|
||||
string childrenString = GetAccountsRecurse(type, 0);
|
||||
@@ -212,7 +210,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
}
|
||||
|
||||
return String.Join(",", childStrings.ToArray());
|
||||
}
|
||||
}*/
|
||||
|
||||
private Dictionary<int, Int64> _singleBalanceLookup;
|
||||
private Dictionary<int, Int64> _treeBalanceLookup;
|
||||
@@ -293,11 +291,11 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
{
|
||||
if (treeValue != 0 && singleValue == 0)
|
||||
{
|
||||
return string.Format(_renderCulture,
|
||||
return string.Format(CultureInfo.CurrentCulture,
|
||||
"<span class=\\\"accountplandata-collapsed-{0}\\\"><strong>Σ</strong> {1:N0}</span><span class=\\\"accountplandata-expanded-{0}\\\" style=\\\"display:none\\\"> </span>",
|
||||
accountId, treeValue / 100.00);
|
||||
}
|
||||
return string.Format(_renderCulture,
|
||||
return string.Format(CultureInfo.CurrentCulture,
|
||||
"<span class=\\\"accountplandata-collapsed-{0}\\\"><strong>Σ</strong> {1:N0}</span><span class=\\\"accountplandata-expanded-{0}\\\" style=\\\"display:none\\\">{2:N0}</span>",
|
||||
accountId, treeValue / 100.0, singleValue / 100.0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user