예제 #1
0
        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();
            }
        }
예제 #2
0
        public static Address GetAddressFromReader(SqlCeDataReader reader)
        {
            Address address = new Address();
            address.AddressID = (long)reader["AddressID"];
            address.Street = reader["Street"].ToString();
            address.City = reader["City"].ToString();
            address.State = reader["State"].ToString();
            address.Zip = (int)reader["Zip"];

            return address;
        }
예제 #3
0
 public static long? AddAddress(Address address)
 {
     string _query = string.Format("INSERT INTO Address(Street, City, State, Zip) " +
          "VALUES('{0}', '{1}', '{2}', {3})", address.Street, address.City, address.State, address.Zip);
     try
     {
         return (CaseStudyDB.ExecuteNonQuery(_query));
     }
     catch (Exception ex)
     {
         MessageBox.Show(string.Format("Error Adding Address {0}", ex.Message));
         return null;
     }
 }
예제 #4
0
 internal static void UpdateAddress(Address address)
 {
     string _query = string.Format("UPDATE Address " +
         "SET Street='{0}', City='{1}', State='{2}', Zip={3} " +
         "WHERE AddressID = {4}", address.Street, address.City,
          address.State, address.Zip, address.AddressID);
     try
     {
         CaseStudyDB.ExecuteNonQuery(_query);
     }
     catch (Exception ex)
     {
         MessageBox.Show(string.Format("Error Adding Address {0}", ex.Message));
     }
 }
예제 #5
0
 public void SetAddress(Address address)
 {
     _address = address;
 }
예제 #6
0
        public static List<Customer> GetCustomers()
        {
            List<Customer> customers = new List<Customer>();

            XmlTextReader reader = new XmlTextReader(path);
            while (reader.Read())
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(reader);
                XmlNodeList xmlCustomers = xmlDoc.GetElementsByTagName("customer");
                for (int i = 0; i < xmlCustomers.Count; i++)
                {
                    long? customerID = null;
                    long? personID = null;
                    Customer.Types customerType = Customer.Types.Unknown;
                    Customer.PersonTypes personType = Person.PersonTypes.Customer;
                    string firstName = "";
                    string lastName = "";
                    DateTime? dob = null;
                    long? addressID = null;
                    string street = "";
                    string city = "";
                    string state = "";
                    int? zip = null;
                    foreach (XmlAttribute attribute in xmlCustomers[i].Attributes)
                    {
                        switch (attribute.Name)
                        {
                            case "id":
                                customerID = long.Parse(attribute.Value);
                                break;
                            case "personID":
                                personID = long.Parse(attribute.Value);
                                break;
                            case "customerType":
                                customerType = (Customer.Types)Enum.Parse(typeof(Customer.Types), attribute.Value);
                                break;
                            case "personType":
                                personType = (Person.PersonTypes)Enum.Parse(typeof(Person.PersonTypes), attribute.Value);
                                break;
                            default:
                                break;
                        }
                    }

                    foreach(XmlNode node in xmlCustomers[i].ChildNodes)
                    {
                        switch (node.Name)
                        {
                            case "name":
                                foreach(XmlNode childNode in node.ChildNodes)
                                {
                                    if (childNode.Name == "firstname")
                                    {
                                        firstName = childNode.InnerText;
                                    }
                                    else
                                    {
                                        lastName = childNode.InnerText;
                                    }
                                }
                                break;
                            case "dob":
                                dob = DateTime.Parse(node.InnerText);
                                break;
                            case "address":
                                XmlAttribute attribute = node.Attributes[0];
                                addressID = long.Parse(attribute.Value);
                                foreach (XmlNode childNode in node.ChildNodes)
                                {
                                    switch (childNode.Name)
                                    {
                                        case "street":
                                            street = childNode.InnerText;
                                            break;
                                        case "city":
                                            city = childNode.InnerText;
                                            break;
                                        case "state":
                                            state = childNode.InnerText;
                                            break;
                                        case "zipcode":
                                            zip = int.Parse(childNode.InnerText);
                                            break;
                                        default:
                                            break;
                                    }
                                }
                                break;
                            default:
                                break;
                        }
                    }
                    Address address = new Address(addressID, street, city, state, zip);
                    //Customer customer = new Customer(customerID, customerType, personID, firstName, lastName, dob, personType);
                    //customer.SetAddress(address);
                    //customers.Add(customer);
                }
            }
            reader.Close();
            return customers;
        }