internal virtual void btnSubmit_Click(object sender, EventArgs e) { if (IsValidData()) { Address address = new Address(); customer = new Customer(); customer.FirstName = txtFirstName.Text; customer.LastName = txtLastName.Text; customer.Email = txtEmail.Text; customer.Password = txtPassword.Text; customer.DateOfBirth = dateDOB.Value; customer.Type = (Customer.Types)Enum.Parse(typeof(Customer.Types), comboType.SelectedItem.ToString()); if(chkResponsibleParty.Checked) { customer.PersonType = Person.PersonTypes.ResponsibleParty; address.Street = txtStreet.Text; address.City = txtCity.Text; address.State = txtState.Text; address.Zip = Int32.Parse(txtZip.Text); } else { address = responsibleParty.Address; customer.PersonType = Person.PersonTypes.Customer; customer.ResponsiblePartyID = responsibleParty.CustomerID; } customer.SetAddress(address); this.Close(); } }
public static Customer GetCustomerFromReader(SqlCeDataReader reader) { if (reader != null) { Customer customer = new Customer(); customer.CustomerID = (long)reader["CustomerID"]; if (!reader.IsDBNull(reader.GetOrdinal("ResponsiblePartyID"))) { customer.ResponsiblePartyID = (long)reader["ResponsiblePartyID"]; } Customer.Types type; Enum.TryParse<Customer.Types>(reader["Type"].ToString(), out type); customer.Type = type; customer.PersonID = (long)reader["PersonID"]; customer.FirstName = reader["FirstName"].ToString(); customer.LastName = reader["LastName"].ToString(); customer.DateOfBirth = DateTime.Parse(reader["DateOfBirth"].ToString()); Person.PersonTypes personType; Enum.TryParse<Person.PersonTypes>(reader["PersonType"].ToString(), out personType); customer.PersonType = personType; customer.Email = reader["Email"].ToString(); customer.Password = reader["Password"].ToString(); customer.SetAddress(AddressDB.GetAddressFromReader(reader)); return customer; } return null; }