Esempio n. 1
0
 //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:
         * Post: If the payment information is valid, submit the shipment
         */
        protected void Submit_Click(object sender, EventArgs e)
        {
            Page.Validate("Payment");

            //collect information and enter into database
            if (Page.IsValid)
            {
                double length = Convert.ToDouble(Length.Text);
                double width = Convert.ToDouble(Width.Text);
                double height = Convert.ToDouble(Height.Text);
                double weight = Convert.ToDouble(Weight.Text);
                double cost = Convert.ToDouble(Cost.Text.Substring(1));
                Customer customer = DbInterfacePerson.GetCustomer(Session["username"].ToString());
                Address deliveryAddress = GetDeliveryAddress();
                CreditCard card = GetCreditCard();

                double value = 0;
                if (ItemValue.Text.Length > 0)
                    value = Convert.ToDouble(ItemValue.Text);

                ShipmentType type = null;
                if (ShipmentType.SelectedIndex > 0)
                    type = new ShipmentType(Convert.ToInt32(ShipmentType.SelectedValue), ShipmentType.SelectedItem.Text);

                UtilityClass.ShippingSpeed speed = UtilityClass.ShippingSpeed.Normal;
                if (ShippingSpeed.SelectedIndex == 1)
                    speed = UtilityClass.ShippingSpeed.Express;
                else if (ShippingSpeed.SelectedIndex == 2)
                    speed = UtilityClass.ShippingSpeed.Urgent;

                InsuranceType insurance = null;
                if (Insurance.SelectedIndex > 0)
                    insurance = new InsuranceType(Convert.ToInt32(Insurance.SelectedValue), Insurance.SelectedItem.Text);

                Shipment shipment = new Shipment(customer, length, width, height, weight, type, insurance,
                                                 value, cost, FirstName.Text, LastName.Text, deliveryAddress, card,
                                                 false, speed);

                //if successfully added, show confirmation message
                int id = shipment.AddToDatabase();
                if (id != -1)
                {
                    string trackingNum = GetTrackingNumber(id);
                    ConfirmLabel.Text = "Thank you for using the La Crosse Parcel Service! Your shipment has been registered and is being processed. You will be notified when your shipment is accepted";
                    MainPage.Visible = false;
                    Confirmation.Visible = true;

                    UtilityClass.SendEmail(customer.email, "Shipment in Processing", "Thank you for using the La Crosse Parcel Service!  " +
                                           "Your tracking number is " + trackingNum +
                                           ".  Please visit 138.49.101.81/Account/Login to view your shipment status.");
                }
            }
        }