From b0fa82c8ff4915d91c999b0ab0f85ff66329c4da Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Wed, 7 Jul 2021 10:55:56 +0200 Subject: [PATCH] Added Date control, and to Create Invoice --- Site/Automation/Formatting.aspx.cs | 30 ++++++++++ Site/Controls/v5/Base/DateTextBox.ascx | 59 +++++++++++++++++++ Site/Controls/v5/Base/DateTextBox.ascx.cs | 38 ++++++++++++ .../v5/Base/DateTextBox.ascx.designer.cs | 33 +++++++++++ .../v5/Financial/CreateInboundInvoice.aspx | 6 +- .../v5/Financial/CreateInboundInvoice.aspx.cs | 4 +- .../CreateInboundInvoice.aspx.designer.cs | 45 ++++++++------ Site/Site.csproj | 8 +++ 8 files changed, 201 insertions(+), 22 deletions(-) create mode 100644 Site/Controls/v5/Base/DateTextBox.ascx create mode 100644 Site/Controls/v5/Base/DateTextBox.ascx.cs create mode 100644 Site/Controls/v5/Base/DateTextBox.ascx.designer.cs diff --git a/Site/Automation/Formatting.aspx.cs b/Site/Automation/Formatting.aspx.cs index 352f7db6..c35ebaa6 100644 --- a/Site/Automation/Formatting.aspx.cs +++ b/Site/Automation/Formatting.aspx.cs @@ -2,6 +2,7 @@ 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; @@ -40,6 +41,7 @@ namespace Swarmops.Frontend.Automation return input.ToString("N2"); } + [WebMethod] public static AjaxInputCallResult FormatCurrencyString(string input) { @@ -57,5 +59,33 @@ namespace Swarmops.Frontend.Automation 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 MMM dd") + }; + } } } \ No newline at end of file diff --git a/Site/Controls/v5/Base/DateTextBox.ascx b/Site/Controls/v5/Base/DateTextBox.ascx new file mode 100644 index 00000000..7b1debaf --- /dev/null +++ b/Site/Controls/v5/Base/DateTextBox.ascx @@ -0,0 +1,59 @@ +<%@ Control Language="C#" AutoEventWireup="true" Inherits="Swarmops.Frontend.Controls.Base.DateTextBox" Codebehind="DateTextBox.ascx.cs" %> +<%@ Import Namespace="Swarmops.Common.Enums" %> + + + + <% if (this.Layout == LayoutDirection.Vertical) { %>
<% } %> + + <% if (this.Layout == LayoutDirection.Vertical) { %>
<% } %> + + + diff --git a/Site/Controls/v5/Base/DateTextBox.ascx.cs b/Site/Controls/v5/Base/DateTextBox.ascx.cs new file mode 100644 index 00000000..0a7c4681 --- /dev/null +++ b/Site/Controls/v5/Base/DateTextBox.ascx.cs @@ -0,0 +1,38 @@ +using System; +using System.Globalization; +using Swarmops.Common.Enums; +using System.Web.UI; +using Swarmops.Logic.Financial; +using Swarmops.Logic.Support; + +namespace Swarmops.Frontend.Controls.Base +{ + /// + /// This is an ordinary textbox, except it does culture-sensitive and + /// asynchronous validation of currency input. + /// + public partial class DateTextBox : ControlV5Base + { + protected void Page_Load (object sender, EventArgs e) + { + this.TextInput.Attributes["role"] = "note"; // disable Lastpass trying to autofill + + if (this.Layout == LayoutDirection.Unknown) + { + this.Layout = LayoutDirection.Vertical; + } + } + + public DateTime Value + { + get { return DateTime.Parse(this.InterpretedDate.Value, CultureInfo.InvariantCulture); } + set + { + this.InterpretedDate.Value = Value.ToString(CultureInfo.InvariantCulture); + this.TextInput.Text = Value.ToString("YYYY MMM dd"); + } + } + + public LayoutDirection Layout { get; set; } + } +} \ No newline at end of file diff --git a/Site/Controls/v5/Base/DateTextBox.ascx.designer.cs b/Site/Controls/v5/Base/DateTextBox.ascx.designer.cs new file mode 100644 index 00000000..b8e19c7f --- /dev/null +++ b/Site/Controls/v5/Base/DateTextBox.ascx.designer.cs @@ -0,0 +1,33 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Swarmops.Frontend.Controls.Base { + + + public partial class DateTextBox { + + /// + /// TextInput control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.TextBox TextInput; + + /// + /// InterpretedDate control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.HiddenField InterpretedDate; + } +} diff --git a/Site/Pages/v5/Financial/CreateInboundInvoice.aspx b/Site/Pages/v5/Financial/CreateInboundInvoice.aspx index a6880fa6..53fc7606 100644 --- a/Site/Pages/v5/Financial/CreateInboundInvoice.aspx +++ b/Site/Pages/v5/Financial/CreateInboundInvoice.aspx @@ -2,6 +2,7 @@ <%@ Register src="~/Controls/v5/Base/FileUpload.ascx" tagname="FileUpload" tagprefix="Swarmops5" %> <%@ Register TagPrefix="Swarmops5" TagName="ComboBudgets" Src="~/Controls/v5/Financial/ComboBudgets.ascx" %> <%@ Register TagPrefix="Swarmops5" TagName="CurrencyAmount" Src="~/Controls/v5/Financial/CurrencyTextBox.ascx" %> +<%@ Register TagPrefix="Swarmops5" TagName="DateTextBox" Src="~/Controls/v5/Financial/DateTextBox.ascx" %> @@ -145,12 +146,13 @@

+
+
-
"> 
@@ -172,8 +174,8 @@


-

+

<%# Eval("TagSetLocalizedName") %>

diff --git a/Site/Pages/v5/Financial/CreateInboundInvoice.aspx.cs b/Site/Pages/v5/Financial/CreateInboundInvoice.aspx.cs index 969ce699..b93bf9c4 100644 --- a/Site/Pages/v5/Financial/CreateInboundInvoice.aspx.cs +++ b/Site/Pages/v5/Financial/CreateInboundInvoice.aspx.cs @@ -103,8 +103,8 @@ namespace Swarmops.Frontend.Pages.v5.Financial this.CurrencyAmount.Cents = 0; this.CurrencyVat.Cents = 0; this.TextSupplier.Focus(); - this.TextDueDate.Text = DateTime.Today.AddDays (30).ToShortDateString(); // Use current culture - this.TextInvoiceDate.Text = DateTime.Today.ToShortDateString(); + this.DateInvoiceIssued.Value = DateTime.Today; + this.DateInvoiceDue.Value = DateTime.Today.AddDays(30); Localize(); } diff --git a/Site/Pages/v5/Financial/CreateInboundInvoice.aspx.designer.cs b/Site/Pages/v5/Financial/CreateInboundInvoice.aspx.designer.cs index a40c33b1..68cddbdc 100644 --- a/Site/Pages/v5/Financial/CreateInboundInvoice.aspx.designer.cs +++ b/Site/Pages/v5/Financial/CreateInboundInvoice.aspx.designer.cs @@ -48,6 +48,15 @@ namespace Swarmops.Frontend.Pages.v5.Financial { /// protected global::System.Web.UI.WebControls.HiddenField HiddenTagSetIdentifiers; + /// + /// DateInvoiceIssued control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.UserControl DateInvoiceIssued; + /// /// TextInvoiceDate control. /// @@ -84,6 +93,15 @@ namespace Swarmops.Frontend.Pages.v5.Financial { /// protected global::Swarmops.Frontend.Controls.Financial.CurrencyTextBox CurrencyVat; + /// + /// DateInvoiceDue control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.UserControl DateInvoiceDue; + /// /// TextPurpose control. /// @@ -93,15 +111,6 @@ namespace Swarmops.Frontend.Pages.v5.Financial { /// protected global::System.Web.UI.WebControls.TextBox TextPurpose; - /// - /// TextDueDate control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.TextBox TextDueDate; - /// /// ComboBudgets control. /// @@ -192,15 +201,6 @@ namespace Swarmops.Frontend.Pages.v5.Financial { /// protected global::System.Web.UI.WebControls.Label LabelVat; - /// - /// LabelPurpose control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.Label LabelPurpose; - /// /// LabelDueDate control. /// @@ -210,6 +210,15 @@ namespace Swarmops.Frontend.Pages.v5.Financial { /// protected global::System.Web.UI.WebControls.Label LabelDueDate; + /// + /// LabelPurpose control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label LabelPurpose; + /// /// LabelBudget control. /// diff --git a/Site/Site.csproj b/Site/Site.csproj index d5ac4a7f..1591719a 100644 --- a/Site/Site.csproj +++ b/Site/Site.csproj @@ -152,6 +152,13 @@ AjaxDropDown.ascx + + DateTextBox.ascx + ASPXCodeBehind + + + DateTextBox.ascx + DocumentDownloader.ascx ASPXCodeBehind @@ -864,6 +871,7 @@ +