private void SaveAndPop() { UserTable userChanges = new UserTable(); userChanges = user; userChanges.UserName = UserName.Trim(); userChanges.FirstName = FirstName.Trim(); userChanges.LastName = LastName.Trim(); userChanges.Email = Email.Trim(); userChanges.Address1 = Address1.Trim(); if (Address2 != null) { userChanges.Address2 = Address2.Trim(); } if (Address3 != null) { userChanges.Address3 = Address3.Trim(); } userChanges.PostCode = PostCode.Trim(); userChanges.City = City.Trim(); userChanges.Country = Country.Trim(); userChanges.Phone = int.Parse(Phone.Trim()); }
public override bool Equals(object obj) { if (obj is OrganisationAddress) { obj = Create((OrganisationAddress)obj); } var address = obj as AddressModel; if (address == null) { return(false); } if (obj is OrganisationAddress) { } if ((!string.IsNullOrWhiteSpace(Address1) || !string.IsNullOrWhiteSpace(address.Address1)) && Address1?.Trim() != address.Address1?.Trim()) { return(false); } if ((!string.IsNullOrWhiteSpace(Address2) || !string.IsNullOrWhiteSpace(address.Address2)) && Address2?.Trim() != address.Address2?.Trim()) { return(false); } if ((!string.IsNullOrWhiteSpace(Address3) || !string.IsNullOrWhiteSpace(address.Address3)) && Address3?.Trim() != address.Address3?.Trim()) { return(false); } if ((!string.IsNullOrWhiteSpace(City) || !string.IsNullOrWhiteSpace(address.City)) && City?.Trim() != address.City?.Trim()) { return(false); } if ((!string.IsNullOrWhiteSpace(County) || !string.IsNullOrWhiteSpace(address.County)) && County?.Trim() != address.County?.Trim()) { return(false); } if ((!string.IsNullOrWhiteSpace(Country) || !string.IsNullOrWhiteSpace(address.Country)) && Country?.Trim() != address.Country?.Trim()) { return(false); } if ((!string.IsNullOrWhiteSpace(PostCode) || !string.IsNullOrWhiteSpace(address.PostCode)) && PostCode?.Trim() != address.PostCode?.Trim()) { return(false); } if ((!string.IsNullOrWhiteSpace(PoBox) || !string.IsNullOrWhiteSpace(address.PoBox)) && PoBox?.Trim() != address.PoBox?.Trim()) { return(false); } return(true); }
/// <summary> /// Simplify address /// </summary> /// <remarks> /// This basically is intended to remove empty lines from the address fields and push the remainder up. /// It can mess up the consistency for named fields but that is always a risk with user input /// Postcode is ignored - previously it may have been added to the last line /// </remarks> public void Simplify() { var dummyLine = "##DUMMY ADDRESS LINE##"; // first tidy up Address1 = Address1 == null ? "" : Address1.Trim(); Address2 = Address2 == null ? "" : Address2.Trim(); Address3 = Address3 == null ? "" : Address3.Trim(); Address4 = Address4 == null ? "" : Address4.Trim(); Address5 = Address5 == null ? "" : Address5.Trim(); Address6 = Address6 == null ? "" : Address6.Trim(); // check for house number // we only check the first two addresses and deal if needed // house number is intended to be in address 2 but it could be swapped so we check here var houseNameIsNumeric = Address1.Trim().IsLong(); var houseNameIsPartialNumeric = Address1.Trim().FirstWord().IsLong(); var houseNumberIsNumeric = Address2.Trim().IsLong(); var houseNumberIsPartialNumeric = Address2.Trim().FirstWord().IsLong(); if (houseNameIsNumeric) { long.TryParse(Address1, out var houseNumber); // address1 is fully numeric so we swap Address1 = Address2 == null || Address2.Trim() == "" ? dummyLine : Address2; Address2 = houseNumber.ToString(); } else { if (houseNameIsPartialNumeric) { // address1 is partial numeric, if address2 is empty we move the number if (Address2 == null || Address2.Trim() == "") { long.TryParse(Address1.Trim().FirstWord(), out var houseNumber); Address1 = Address1.Substring(houseNumber.ToString().Length); Address2 = houseNumber.ToString(); } } else { if (houseNumberIsNumeric && (Address1 == null || Address1.Trim() == "")) { // housenumber is numeric and house nameis empty so we add dummy line to prevent losing empty line which will throw out the order Address1 = dummyLine; } else { if (houseNumberIsPartialNumeric && (Address1 == null || Address1.Trim() == "")) { // housenumber contains a partial numeric e.g. 32 High street so we split it out long.TryParse(Address2.Trim().FirstWord(), out var house2Number); Address1 = Address2.Substring(house2Number.ToString().Length); Address2 = house2Number.ToString(); } } } } var tempFullAddress = FullAddress(Address1, Address2, Address3, Address4, Address5, Address6, false); // remove any redundancy so that we have a comma separated string tempFullAddress.ReplaceAllMid(",,", "", 0, tempFullAddress.Length); // now split on comma var tempAddress = tempFullAddress.Split(','); var tempAddressLen = tempAddress.Length; switch (tempAddressLen) { case 1: Address1 = tempAddress[0].Trim(); Address2 = ""; Address3 = ""; Address4 = ""; Address5 = ""; Address6 = ""; break; case 2: Address1 = tempAddress[0].Trim(); Address2 = tempAddress[1].Trim(); Address3 = ""; Address4 = ""; Address5 = ""; Address6 = ""; break; case 3: Address1 = tempAddress[0].Trim(); Address2 = tempAddress[1].Trim(); Address3 = tempAddress[2].Trim(); Address4 = ""; Address5 = ""; Address6 = ""; break; case 4: Address1 = tempAddress[0].Trim(); Address2 = tempAddress[1].Trim(); Address3 = tempAddress[2].Trim(); Address4 = tempAddress[3].Trim(); Address5 = ""; Address6 = ""; break; case 5: Address1 = tempAddress[0].Trim(); Address2 = tempAddress[1].Trim(); Address3 = tempAddress[2].Trim(); Address4 = tempAddress[3].Trim(); Address5 = tempAddress[4].Trim(); Address6 = ""; break; case 6: Address1 = tempAddress[0].Trim(); Address2 = tempAddress[1].Trim(); Address3 = tempAddress[2].Trim(); Address4 = tempAddress[3].Trim(); Address5 = tempAddress[4].Trim(); Address6 = tempAddress[5].Trim(); break; default: Address1 = tempAddress[0].Trim(); Address2 = tempAddress[1].Trim(); Address3 = tempAddress[2].Trim(); Address4 = tempAddress[3].Trim(); Address5 = tempAddress[4].Trim(); Address6 = tempAddress[5].Trim(); break; } // now remove dummy if it exists if (Address1 == dummyLine) { Address1 = ""; } }
public bool hasAddress3() { return(Address3 != null && Address3.Trim().Length != 0); }
public string GenerateAddressHtmlString(string LineBreak) { StringBuilder sb = new StringBuilder(); if (Address1 != null && Address1.Trim() != "") { sb.Append(Address1 + LineBreak); } if (Address2 != null && Address2.Trim() != "") { sb.Append(Address2 + LineBreak); } if (Address3 != null && Address3.Trim() != "") { sb.Append(Address3 + LineBreak); } //CITY if (City != null && City != "") { sb.Append(City); if (StateCode != null && StateCode != "") { sb.Append(", "); } else if (PostalCode != null && PostalCode != "") { sb.Append(" "); } else if (CountryCode != null && CountryCode != "" && CountryCode.ToLower() != "us" && CountryCode.ToLower() != "usa") { sb.Append("; "); } } //STATE if (StateCode != null && StateCode != "") { sb.Append(StateCode); if (PostalCode != null && PostalCode != "") { sb.Append(" "); } else if (CountryCode != null && CountryCode != "" && CountryCode.ToLower() != "us" && CountryCode.ToLower() != "usa") { sb.Append("; "); } } //POSTAL if (PostalCode != null && PostalCode != "") { sb.Append(PostalCode); if (CountryCode != null && CountryCode != "" && CountryCode.ToLower() != "us" && CountryCode.ToLower() != "usa") { sb.Append(LineBreak); } } //COUNTRY if (CountryCode != null && CountryCode != "" && CountryCode.ToLower() != "us" && CountryCode.ToLower() != "usa") { sb.Append(CountryCode); } sb.Append(LineBreak); return(sb.ToString()); }