diff --git a/Site5/Controls/v5/Financial/CurrencyTextBox.ascx b/Site5/Controls/v5/Financial/CurrencyTextBox.ascx index 87e23c61..84c0bcf5 100644 --- a/Site5/Controls/v5/Financial/CurrencyTextBox.ascx +++ b/Site5/Controls/v5/Financial/CurrencyTextBox.ascx @@ -1 +1,5 @@ <%@ Control Language="C#" AutoEventWireup="true" CodeFile="CurrencyTextBox.ascx.cs" Inherits="Swarmops.Frontend.Controls.v5.Financial.CurrencyTextBox" %> + + + + \ No newline at end of file diff --git a/Site5/Controls/v5/Financial/CurrencyTextBox.ascx.cs b/Site5/Controls/v5/Financial/CurrencyTextBox.ascx.cs index 65ac1e09..e507e18b 100644 --- a/Site5/Controls/v5/Financial/CurrencyTextBox.ascx.cs +++ b/Site5/Controls/v5/Financial/CurrencyTextBox.ascx.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.Web.UI; namespace Swarmops.Frontend.Controls.v5.Financial @@ -12,5 +13,31 @@ namespace Swarmops.Frontend.Controls.v5.Financial protected void Page_Load (object sender, EventArgs e) { } + + public double Value + { + get + { + // Try to parse the Double in two steps: first as a Culture.CurrentCulture, and if that doesn't work out, as a Culture.InvariantCulture. + + double outParse = 0.0; + string contents = Input.Text; + + if (Double.TryParse (contents, NumberStyles.Currency, CultureInfo.CurrentCulture, out outParse)) + { + return outParse; + } + if (Double.TryParse (contents, NumberStyles.Currency, CultureInfo.InvariantCulture, out outParse)) + { + return outParse; + } + + // Unparsable. Sorry. + + throw new InvalidCastException("The text field cannot be parsed to a Double: \"" + contents + "\""); + + } + set { this.Input.Text = value.ToString ("N2", CultureInfo.CurrentCulture); } + } } } \ No newline at end of file diff --git a/Site5/Pages/v5/Financial/RequestCashAdvance.aspx b/Site5/Pages/v5/Financial/RequestCashAdvance.aspx index e9d14c1e..84edabd4 100644 --- a/Site5/Pages/v5/Financial/RequestCashAdvance.aspx +++ b/Site5/Pages/v5/Financial/RequestCashAdvance.aspx @@ -1,5 +1,6 @@ <%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="RequestCashAdvance.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Financial.RequestCashAdvance" %> <%@ Register TagPrefix="Swarmops5" TagName="ComboBudgets" Src="~/Controls/v5/Financial/ComboBudgets.ascx" %> +<%@ Register TagPrefix="Swarmops5" TagName="CurrencyTextBox" Src="~/Controls/v5/Financial/CurrencyTextBox.ascx" %> @@ -20,7 +21,7 @@ isValid = validateTextField('#<%=this.TextPurpose.ClientID %>', "") && isValid; var jsonData = {}; - jsonData.amount = $('#<%=this.TextAmount.ClientID %>').val(); + jsonData.amount = $('#<%=this.TextAmount.ClientID %>_Input').val(); $.ajax({ type: "POST", @@ -33,7 +34,7 @@ if (msg.d != true) { isValid = false; alertify.error(""); - $('#<%=this.TextAmount.ClientID %>').addClass("entryError").focus(); + $('#<%=this.TextAmount.ClientID %>_Input').addClass("entryError").focus(); } } }); @@ -59,7 +60,7 @@

- ​
+ ​
​
 
 
diff --git a/Site5/Pages/v5/Financial/RequestCashAdvance.aspx.cs b/Site5/Pages/v5/Financial/RequestCashAdvance.aspx.cs index 7165d0e4..88232c01 100644 --- a/Site5/Pages/v5/Financial/RequestCashAdvance.aspx.cs +++ b/Site5/Pages/v5/Financial/RequestCashAdvance.aspx.cs @@ -26,7 +26,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial this.TextBank.Text = CurrentUser.BankName; this.TextClearing.Text = CurrentUser.BankClearing; this.TextAccount.Text = CurrentUser.BankAccount; - this.TextAmount.Text = 0.ToString ("N2"); + this.TextAmount.Value = 0.0; this.TextAmount.Focus(); Localize(); @@ -62,8 +62,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial { // The data has been validated client-side already. We'll throw unfriendly exceptions if invalid data is passed here. - double amount = Double.Parse (this.TextAmount.Text, NumberStyles.Number); - // parses in current culture - intentional + double amount = this.TextAmount.Value; Int64 amountCents = (Int64) amount*100; string description = this.TextPurpose.Text;