comparison Demo/Asp.Net/Web/Controls/AddressForm.ascx.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2 using System.Text.RegularExpressions;
3
4 using PetShop.ObjectModel;
5
6 namespace PetShop.Web
7 {
8 public partial class AddressForm : System.Web.UI.UserControl
9 {
10 /// <summary>
11 /// Control property to set or get the address
12 /// </summary>
13 public Address Address
14 {
15 get
16 {
17 // Return null if control is empty.
18 //
19 if (string.IsNullOrEmpty(txtFirstName.Text) &&
20 string.IsNullOrEmpty(txtLastName. Text) &&
21 string.IsNullOrEmpty(txtAddress1. Text) &&
22 string.IsNullOrEmpty(txtAddress2. Text) &&
23 string.IsNullOrEmpty(txtCity. Text) &&
24 string.IsNullOrEmpty(txtZip. Text) &&
25 string.IsNullOrEmpty(txtEmail. Text) &&
26 string.IsNullOrEmpty(txtPhone. Text))
27 return null;
28
29 Address addr = new Address();
30
31 // Make sure we clean the input.
32 //
33 addr.FirstName = WebUtility.InputText(txtFirstName.Text, 50);
34 addr.LastName = WebUtility.InputText(txtLastName. Text, 50);
35 addr.Line1 = WebUtility.InputText(txtAddress1. Text, 50);
36 addr.Line2 = WebUtility.InputText(txtAddress2. Text, 50);
37 addr.City = WebUtility.InputText(txtCity. Text, 50);
38 addr.Zip = WebUtility.InputText(txtZip. Text, 10);
39 addr.Phone = WebUtility.InputText(WebUtility.CleanNonWord(txtPhone.Text), 10);
40 addr.Email = WebUtility.InputText(txtEmail.Text, 80);
41 addr.State = WebUtility.InputText(listState. SelectedItem.Value, 2);
42 addr.Country = WebUtility.InputText(listCountry.SelectedItem.Value, 50);
43
44 return addr;
45 }
46
47 set
48 {
49 if (value != null)
50 {
51 txtFirstName.Text = value.FirstName;
52 txtLastName. Text = value.LastName;
53 txtAddress1. Text = value.Line1;
54 txtAddress2. Text = value.Line2;
55 txtCity. Text = value.City;
56 txtZip. Text = value.Zip;
57 txtPhone. Text = value.Phone;
58 txtEmail. Text = value.Email;
59
60 if (!string.IsNullOrEmpty(value.State))
61 {
62 listState.ClearSelection();
63 listState.SelectedValue = value.State;
64 }
65
66 if (!string.IsNullOrEmpty(value.Country))
67 {
68 listCountry.ClearSelection();
69 listCountry.SelectedValue = value.Country;
70 }
71 }
72 }
73 }
74 }
75 }