/*
         * Pre:  The entered email address must be unique
         * Post: The new user is registered in the system and redirected
         */
        public void RegisterUser(object sender, EventArgs e)
        {
            Page.Validate();
            if (!Page.IsValid) return;

            Customer customer = new Customer(FirstName.Text, LastName.Text, String.Format("{0}-{1}-{2}",PhoneAreaCode.Text,
                                             Phone2.Text, Phone3.Text), Email.Text, Password.Text, UtilityClass.UserTypes.Customer);

            if (!DbInterfacePerson.EmailExists(customer.email))
            {
                customer.Register();

                Response.Redirect("/Default.aspx");
            }
            else
            {
                FailureText.Text = "There is already an account associated with this email.";
                ErrorMessage.Visible = true;
            }
        }
 //new shipment
 public Shipment(Customer customer, double length, double width, double height, double weight, ShipmentType shipmentType,
                 InsuranceType insuranceType, double itemValue, double cost, string firstName, string lastName, 
                 Address deliveryAddress, CreditCard creditCard, bool approved, UtilityClass.ShippingSpeed shippingSpeed)
 {
     this.customer = customer;
     this.length = length;
     this.width = width;
     this.height = height;
     this.weight = weight;
     this.shipmentType = shipmentType;
     this.insuranceType = insuranceType;
     this.itemValue = itemValue;
     this.cost = cost;
     this.firstName = firstName;
     this.lastName = lastName;
     this.deliveryAddress = deliveryAddress;
     this.creditCard = creditCard;
     this.approved = approved;
     this.shippingSpeed = shippingSpeed;
 }
        /*
         * Pre:  Customer exists with input username
         * Post: The customer information is retrieved based on the input username
         */
        public static Customer GetCustomer(string username)
        {
            Customer customer = null;
            DataTable table = new DataTable();
            SqlConnection connection = new
                SqlConnection(ConfigurationManager.ConnectionStrings["GoodsDeliveryConnectionString"].ConnectionString);

            try
            {
                connection.Open();
                string storedProc = "UserSelect";

                SqlCommand cmd = new SqlCommand(storedProc, connection);

                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@username", username);

                adapter.Fill(table);

                if (table.Rows.Count == 1)
                {
                    int id = Convert.ToInt32(table.Rows[0]["UserId"]);
                    string firstName = table.Rows[0]["FirstName"].ToString();
                    string lastName = table.Rows[0]["LastName"].ToString();
                    string email = table.Rows[0]["Email"].ToString();
                    string phone = table.Rows[0]["Phone"].ToString();
                    string password = table.Rows[0]["Password"].ToString();
                    int userType = Convert.ToInt32(table.Rows[0]["UserType"]);

                    customer = new Customer(id, firstName, lastName, phone, email, password, (UtilityClass.UserTypes)userType);
                }
            }
            catch (Exception e)
            {
                customer = null;
            }

            connection.Close();

            return customer;
        }
        /*
         * Pre:
         * Post: Retrieves the shipment information neded for truck placement
         * @returns the info of the shipment
         */
        public static Shipment GetShipmentForTruck(int shipmentId)
        {
            Shipment shipment = null;
            DataTable table = new DataTable();
            SqlConnection connection = new
                SqlConnection(ConfigurationManager.ConnectionStrings["GoodsDeliveryConnectionString"].ConnectionString);

            try
            {
                connection.Open();
                string storedProc = "ShipmentSelectTruckInfo";

                SqlCommand cmd = new SqlCommand(storedProc, connection);

                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@shipmentId", shipmentId);

                adapter.Fill(table);

                //get shipment info
                if (table.Rows.Count == 1)
                {
                    double length = Convert.ToDouble(table.Rows[0]["Length"]);
                    double width = Convert.ToDouble(table.Rows[0]["Width"]);
                    double height = Convert.ToDouble(table.Rows[0]["Height"]);
                    double weight = Convert.ToDouble(table.Rows[0]["Weight"]);
                    string street = table.Rows[0]["ShippingStreet"].ToString();
                    string city = table.Rows[0]["ShippingCity"].ToString();
                    string state = table.Rows[0]["ShippingState"].ToString();
                    int zip = Convert.ToInt32(table.Rows[0]["ShippingZip"]);
                    string username = table.Rows[0]["Username"].ToString();
                    string password = table.Rows[0]["Password"].ToString();
                    string firstName = table.Rows[0]["FirstName"].ToString();
                    string lastName = table.Rows[0]["LastName"].ToString();
                    string phone = table.Rows[0]["Phone"].ToString();
                    int customerId = Convert.ToInt32(table.Rows[0]["PersonId"]);
                    string email = table.Rows[0]["Email"].ToString();

                    UtilityClass.ShippingSpeed speed = (UtilityClass.ShippingSpeed)table.Rows[0]["ShippingSpeedId"];
                    Customer customer = new Customer(customerId, firstName, lastName, phone, email, password, UtilityClass.UserTypes.Customer);
                    Address address = new Address(street, city, state, zip);

                    shipment = new Shipment(length, width, height, weight, address, speed);
                    shipment.customer = customer;
                }
            }
            catch (Exception e)
            {
                shipment = null;
            }

            connection.Close();

            return shipment;
        }