예제 #1
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;
 }
예제 #2
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;
 }
        public UserCredentials(string username, string password, UtilityClass.UserTypes userType, bool encodePassword)
        {
            this.username = username;
            this.userType = userType;

            if (encodePassword)
            {
                using (MD5 md5Hash = MD5.Create())
                {
                    string hash = GetMd5Hash(md5Hash, password);

                    this.password = hash;
                }
            }
            else
                this.password = password;
        }
예제 #4
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: The user type of the user with the input username is updated
         * @param username is the username of the user to update
         * @param newUserType is the new user type/role of the user
         * @returns true if the update is successful and false otherwise
         */
        public static bool UpdateUserType(string username, UtilityClass.UserTypes newUserType)
        {
            bool success = true;
            DataTable table = new DataTable();
            SqlConnection connection = new
                SqlConnection(ConfigurationManager.ConnectionStrings["GoodsDeliveryConnectionString"].ConnectionString);

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

                SqlCommand cmd = new SqlCommand(storedProc, connection);

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

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

                adapter.Fill(table);
            }
            catch (Exception e)
            {
                success = false;
            }

            connection.Close();

            return success;
        }
        /*
         * Pre:  An existing user may not have the same email address
         * Post: The new user is added to the system
         * @returns the user id if the user is successfully added and -1 otherwise
         */
        public static int RegisterUser(string firstName, string lastName, string phone, string email, string username, 
                                       string password, UtilityClass.UserTypes userType, bool changePassword)
        {
            int userId = -1;
            DataTable table = new DataTable();
            SqlConnection connection = new
                SqlConnection(ConfigurationManager.ConnectionStrings["GoodsDeliveryConnectionString"].ConnectionString);

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

                SqlCommand cmd = new SqlCommand(storedProc, connection);

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

                cmd.Parameters.AddWithValue("@firstName", firstName);
                cmd.Parameters.AddWithValue("@lastName", lastName);
                cmd.Parameters.AddWithValue("@phone", phone);
                cmd.Parameters.AddWithValue("@email", email);
                cmd.Parameters.AddWithValue("@username", username);
                cmd.Parameters.AddWithValue("@password", password);
                cmd.Parameters.AddWithValue("@userType", userType);
                cmd.Parameters.AddWithValue("@needPasswordReset", changePassword);

                adapter.Fill(table);

                if (table.Rows.Count == 1)
                    userId = Convert.ToInt32(table.Rows[0]["UserId"]);
            }
            catch (Exception e)
            {
                userId = -1;
            }

            connection.Close();

            return userId;
        }
        /*
         * Pre:
         * Post: Determines whether or not a correct username and password were entered
         * @param username is the entered username
         * @param password is the encoded password
         * @returns true if the login information is valid and false otherwise
         */
        public static bool Login(string username, string password, UtilityClass.UserTypes userType)
        {
            bool loggedIn = false;
            DataTable table = new DataTable();
            SqlConnection connection = new
                SqlConnection(ConfigurationManager.ConnectionStrings["GoodsDeliveryConnectionString"].ConnectionString);

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

                SqlCommand cmd = new SqlCommand(storedProc, connection);

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

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

                adapter.Fill(table);

                if (table.Rows.Count == 1)
                    loggedIn = true;
            }
            catch (Exception e)
            {

            }

            connection.Close();

            return loggedIn;
        }
        /* Pre:
        * Post: Starts a new delivery truck with a new shipment
        */
        public static void StartNewTruckWithShipment(int shipmentId, int truckId, UtilityClass.ShippingSpeed speed, int pathId, int driverId)
        {
            List<Shipment> shipments = new List<Shipment>();
            DataTable table = new DataTable();
            SqlConnection connection = new
                SqlConnection(ConfigurationManager.ConnectionStrings["GoodsDeliveryConnectionString"].ConnectionString);

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

                SqlCommand cmd = new SqlCommand(storedProc, connection);

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

                cmd.Parameters.AddWithValue("@shipmentId", shipmentId);
                cmd.Parameters.AddWithValue("@truckId", truckId);
                cmd.Parameters.AddWithValue("@shippingSpeedId", speed);
                cmd.Parameters.AddWithValue("@pathId", pathId);
                cmd.Parameters.AddWithValue("@driverId", driverId);

                adapter.Fill(table);
            }
            catch (Exception e)
            {

            }

            connection.Close();
        }
        /* Pre:
         * Post: Retrieves a list of all idle trucks
         * @returns a list of available trucks
         */
        public static List<Truck> GetTrucksByStatus(UtilityClass.TruckStatus status)
        {
            List<Truck> trucks = new List<Truck>();
            DataTable table = new DataTable();
            SqlConnection connection = new
                SqlConnection(ConfigurationManager.ConnectionStrings["GoodsDeliveryConnectionString"].ConnectionString);

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

                SqlCommand cmd = new SqlCommand(storedProc, connection);

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

                cmd.Parameters.AddWithValue("@statusId", status);

                adapter.Fill(table);

                for (int i = 0; i < table.Rows.Count; i++)
                {
                    int id = Convert.ToInt32(table.Rows[i]["Id"]);
                    string licenseNum = table.Rows[i]["LicensePlateNum"].ToString();
                    string licenseState = table.Rows[i]["LicensePlateState"].ToString();
                    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"]);
                    int modelId = Convert.ToInt32(table.Rows[i]["ModelId"]);
                    double fuelTankSize = Convert.ToDouble(table.Rows[i]["FuelTankSize"]);
                    double odometer = Convert.ToDouble(table.Rows[i]["OdometerReading"]);
                    string remark = table.Rows[i]["Remark"].ToString();

                    //find if truck is for local deliveries
                    bool local = false;
                    if (!table.Rows[i]["LocalTruck"].ToString().Equals(""))
                        local = Convert.ToBoolean(table.Rows[i]["LocalTruck"]);

                    Truck truck = new Truck(id, licenseNum, licenseState, modelId, fuelTankSize, odometer, length,
                                            width, height, weight, remark, local);
                    truck.status = status;

                    trucks.Add(truck);
                }
            }
            catch (Exception e)
            {
                trucks = null;
            }

            connection.Close();

            return trucks;
        }
예제 #10
0
 //constructor for existing customer
 public Customer(int id, string firstName, string lastName, string phone, string email, string password, UtilityClass.UserTypes userType)
     : base(id, firstName, lastName, phone, email)
 {
     credentials = new UserCredentials(email, password, userType, false);
 }