using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Web; using System.Web.Services; using System.Web.UI; using System.Web.UI.WebControls; namespace Swarmops.Frontend.Automation { public partial class Formatting : DataV5Base { protected void Page_Load (object sender, EventArgs e) { // This page exists only for its web methods, which are called by Ajax. } /// /// Returns a culturally-formatted integer with thousands separators. /// /// The integer to format. /// The formatted integer for display. [WebMethod] public static string FormatInteger(int input) { GetAuthenticationDataAndCulture(); return input.ToString("N0"); } /// /// Returns a culturally-formatted double with thousands separators and two decimals. /// /// The double to format. /// The formatted double for display. [WebMethod] public static string FormatCurrency(double input) { GetAuthenticationDataAndCulture(); return input.ToString("N2"); } [WebMethod] public static AjaxInputCallResult FormatCurrencyString(string input) { bool success = false; Int64 cents = 0; try { cents = Swarmops.Logic.Support.Formatting.ParseDoubleStringAsCents(input); } catch (ArgumentException) { return new AjaxInputCallResult { Success = false }; } return new AjaxInputCallResult {Success = true, NewValue = (cents / 100.0).ToString("N2")}; } public class AjaxDateValidationResult: AjaxInputCallResult { public string InterpretedDate { get; set; } public string PresentedDate { get; set; } } [WebMethod] public static AjaxDateValidationResult InterpretDateString(string input) { GetAuthenticationDataAndCulture(); DateTime interpretedDate = DateTime.MinValue; bool success = DateTime.TryParse(input, out interpretedDate); if (!success) { return new AjaxDateValidationResult() {Success = false}; } return new AjaxDateValidationResult() { Success = true, InterpretedDate = interpretedDate.ToString(CultureInfo.InvariantCulture), PresentedDate = interpretedDate.ToString("yyyy MMMM dd") }; } } }