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; }
public static long? AddCustomer(Customer customer) { if(customer.PersonType == Person.PersonTypes.ResponsibleParty) { customer.Address.AddressID = AddressDB.AddAddress(customer.Address); } customer.PersonID = PersonDB.AddPerson(customer); string _query = string.Format("INSERT INTO Customer (PersonID, ResponsiblePartyID, Type) " + "VALUES({0}, {1}, '{2}')", customer.PersonID, customer.ResponsiblePartyID == null? 0 : customer.ResponsiblePartyID, customer.PersonType); return CaseStudyDB.ExecuteNonQuery(_query); }
public frmModifyCustomer(Customer customer) { if(customer != null) { _customerToModify = customer; } else { this.Close(); } InitializeComponent(); FillFormData(); }
public static void DeleteCustomer(Customer customer) { if(customer.PersonType == Person.PersonTypes.ResponsibleParty) { AddressDB.DeleteAddress(customer.Address.AddressID); } TransactionDB.DeleteTransactionsByCustomer((long)customer.CustomerID); PersonDB.DeletePerson(customer.PersonID); string _query = string.Format("DELETE FROM Customer WHERE CustomerID = {0}", customer.CustomerID); CaseStudyDB.ExecuteNonQuery(_query); }
private void lstCustomers_SelectedIndexChanged(object sender, EventArgs e) { if(lstCustomers.SelectedIndex != -1) { if (lstProducts.SelectedIndex != -1) { numQuantity.Enabled = true; } _customer = _customers[lstCustomers.SelectedIndex]; } }
public void AddDependent(Customer dependent) { if (this.PersonType == PersonTypes.ResponsibleParty && dependent.PersonType == PersonTypes.Customer) { if (_dependents == null) { _dependents = new List<Customer>(); } _dependents.Add(dependent); dependent.ResponsibleParty = this; CustomerDB.ModifyCustomer(this); } }
public void RemoveDependent(Customer dependent) { if(_dependents != null) { _dependents.Remove(dependent); CustomerDB.ModifyCustomer(this); } }
internal virtual void comboResponsibleParty_IndexChanged(object sender, EventArgs e) { if (!chkResponsibleParty.Checked) { responsibleParty = (Customer)comboResponsibleParty.SelectedItem; if (responsibleParty != null) { FillAddressWithResponsibleParty(); } } }
public static void ModifyCustomer(Customer customer) { if(customer.PersonType == Person.PersonTypes.ResponsibleParty) { AddressDB.UpdateAddress(customer.Address); } PersonDB.UpdatePerson(customer); string _query = string.Format("UPDATE Customer " + "SET ResponsiblePartyID={0}, Type='{1}' WHERE CustomerID = {2}", customer.ResponsiblePartyID == null ? 0 : customer.ResponsiblePartyID, customer.PersonType, customer.CustomerID); CaseStudyDB.ExecuteNonQuery(_query); }