コード例 #1
0
        /*
         * Pre:
         * Post: If all entered values are valid, the new driver is added to the system
         */
        protected void Hire_Click(object sender, EventArgs e)
        {
            Page.Validate();
            if (!Page.IsValid) return;

            Address address = new Address(Street.Text, City.Text, State.SelectedValue, Convert.ToInt32(Zip.Text));
            Driver driver = new Driver(FirstName.Text, LastName.Text, String.Format("{0}-{1}-{2}", PhoneAreaCode.Text,
                                       Phone2.Text, Phone3.Text), Email.Text, address, LicenseNum.Text, LicenseState.SelectedValue,
                                       Convert.ToDateTime(LicenseExpiration.Text), UtilityClass.DriverStatus.Available, Remark.Text,
                                       LocalDriver.Checked);

            lbDriverExists.Visible = false;
            if (!DbInterfaceDriver.DriverExists(LicenseNum.Text, LicenseState.SelectedValue))
            {
                if (DbInterfaceDriver.HireDriver(driver.firstName, driver.lastName, address.street, address.city, address.state,
                        address.zip, driver.phone, driver.email, driver.licenseNum, driver.licenseState, driver.licenseExpiration.ToString(),
                        driver.remark, driver.localDriver))
                {
                    MainForm.Visible = false;
                    Confirmation.Visible = true;
                }
            }
            else
            {
                lbDriverExists.Visible = true;
            }
        }
コード例 #2
0
 //used when info is only needed for truck data
 public Shipment(double length, double width, double height, double weight, Address deliveryAddress, UtilityClass.ShippingSpeed shippingSpeed)
 {
     this.length = length;
     this.width = width;
     this.height = height;
     this.weight = weight;
     this.deliveryAddress = deliveryAddress;
     this.shippingSpeed = shippingSpeed;
 }
コード例 #3
0
 public CreditCard(string nameOnCard, string cardType, string cardNum, int securityCode, int expirationMonth,
                   int expirationYear, Address billingAddress)
 {
     this.nameOnCard = nameOnCard;
     this.cardType = cardType;
     this.cardNum = cardNum;
     this.securityCode = securityCode;
     this.expirationMonth = expirationMonth;
     this.expirationYear = expirationYear;
     this.billingAddress = billingAddress;
 }
コード例 #4
0
 //existing driver
 public Driver(int id, string firstName, string lastName, string phone, string email, Address address, string licenseNum,
               string licenseState, DateTime licenseExpiration, UtilityClass.DriverStatus status, string remark, bool localDriver)
     : base(firstName, lastName, phone, email)
 {
     this.id = id;
     this.address = address;
     this.licenseNum = licenseNum;
     this.licenseState = licenseState;
     this.licenseExpiration = licenseExpiration;
     this.status = status;
     this.remark = remark;
     this.localDriver = localDriver;
 }
コード例 #5
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;
 }
コード例 #6
0
        /* Pre:
         * Post: Retrieves a list of all shipments loaded onto the input truck
         * @returns a list of shipments
         */
        public static List<Shipment> GetTruckShipments(int truckId)
        {
            List<Shipment> shipments = new List<Shipment>();
            DataTable table = new DataTable();
            SqlConnection connection = new
                SqlConnection(ConfigurationManager.ConnectionStrings["GoodsDeliveryConnectionString"].ConnectionString);

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

                SqlCommand cmd = new SqlCommand(storedProc, connection);

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

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

                adapter.Fill(table);

                for (int i = 0; i < table.Rows.Count; i++)
                {
                    double length = Convert.ToDouble(table.Rows[i]["Length"]);
                    double width = Convert.ToDouble(table.Rows[i]["Width"]);
                    double height = Convert.ToDouble(table.Rows[i]["Height"]);
                    double weight = Convert.ToDouble(table.Rows[i]["MaxWeight"]);
                    string street = table.Rows[i]["ShippingStreet"].ToString();
                    string city = table.Rows[i]["ShippingCity"].ToString();
                    string state = table.Rows[i]["ShippingState"].ToString();
                    int zip = Convert.ToInt32(table.Rows[i]["ShippingZip"]);
                    UtilityClass.ShippingSpeed speed = (UtilityClass.ShippingSpeed)table.Rows[0]["ShippingSpeedId"];

                    Address address = new Address(street, city, state, zip);
                    Shipment shipment = new Shipment(length, width, height, weight, address, speed);

                    shipments.Add(shipment);
                }
            }
            catch (Exception e)
            {
            }

            connection.Close();

            return shipments;
        }
コード例 #7
0
        /*
         * Pre:  Delivery address information must be complete and valid
         * Post: An address object is made out of the delivery address information
         */
        private Address GetDeliveryAddress()
        {
            int zip = Convert.ToInt32(Zip.Text);

            Address address = new Address(Street.Text, City.Text, State.SelectedValue, zip);

            return address;
        }
コード例 #8
0
        /*
         * Pre:  Credit card information must be complete and valid
         * Post: A credit card object is made out of the input information
         */
        private CreditCard GetCreditCard()
        {
            string cardNum = Regex.Replace(CardNumber.Text, "[^0-9]", "");
            int securityCode = Convert.ToInt32(SecurityCode.Text);
            int expirationMonth = Convert.ToInt32(Month.SelectedValue);
            int expirationYear = Convert.ToInt32(Year.SelectedValue);

            //billing address
            int zip = Convert.ToInt32(ZipPay.Text);
            Address address = new Address(StreetPay.Text, CityPay.Text, StatePay.SelectedValue, zip);

            CreditCard card = new CreditCard(NameOnCard.Text, CardType.SelectedValue, cardNum, securityCode,
                                             expirationMonth, expirationYear, address);

            return card;
        }
コード例 #9
0
        /*
         * 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;
        }