diff Demo/Asp.Net/Web/Controls/CreditCardForm.ascx.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Demo/Asp.Net/Web/Controls/CreditCardForm.ascx.cs	Thu Mar 27 21:46:09 2014 +0400
@@ -0,0 +1,50 @@
+using System;
+using System.Web.UI.WebControls;
+
+using PetShop.ObjectModel;
+
+namespace PetShop.Web
+{
+	public partial class CreditCardForm : System.Web.UI.UserControl
+	{
+		/// <summary>
+		/// Custom validator to check the expiration date
+		/// </summary>
+		protected void ServerValidate(object source, ServerValidateEventArgs value)
+		{
+			DateTime dt;
+
+			if (DateTime.TryParse(value.Value, out dt))
+				value.IsValid = dt > DateTime.Now;
+			else
+				value.IsValid = false;
+		}
+
+		/// <summary>
+		/// Property to set/get credit card info
+		/// </summary>
+		public CreditCard CreditCard
+		{
+			get
+			{
+				CreditCard cc = new CreditCard();
+
+				cc.Type       = WebUtility.InputText(listCctype.SelectedValue, 40);
+				cc.Expiration = WebUtility.InputText(txtExpdate. Text,          7);
+				cc.Number     = WebUtility.InputText(txtCcnumber.Text,         20);
+
+				return cc;
+			}
+
+			set
+			{
+				if (value != null)
+				{
+					if (!string.IsNullOrEmpty(value.Number))     txtCcnumber.Text = value.Number;
+					if (!string.IsNullOrEmpty(value.Expiration)) txtExpdate. Text = value.Expiration;
+					if (!string.IsNullOrEmpty(value.Type))       listCctype.Items.FindByValue(value.Type).Selected = true;	  
+				}
+			}
+		}
+	}
+}
\ No newline at end of file