/*!
         * \brief This handler handles when the user clicks the "Create Order" button.
         * \details This handler verifies that the database was connected to successfully, that a contract was selected, and if both are true it assigns the details of the contract to a contract struct and moves on the "Order Display" page.
         * \param sender <b>object</b>
         * \param e <b>RoutedEventArgs</b>
         */

        private void createOrderBTN_Click(object sender, RoutedEventArgs e)
        {
            // Validate an order has been selected
            // Then transfer to new page
            if (databaseConnected == false)
            {
                errorLabel.Content = "ERROR: Must connect to database before creating an order.\n";
            }

            if (contractSelected == false)
            {
                errorLabel.Content += "ERROR: Must select a contract before creating an order.\n";
            }

            if (contractSelected == true && databaseConnected == true)
            {
                // Assign items from contracts into variables
                contractParams p = (contractParams)databaseView.SelectedItem;

                // Go to next page
                buyer_OrderDisplay order = new buyer_OrderDisplay(localUser, p);
                this.NavigationService.Navigate(order);
            }
            else
            {
                return;
            }
        }
        /*!
         * \brief This handler handles when the user selects something in the.
         * \details
         * \param sender <b>object</b>
         * \param e <b>SelectionChangedEventArgs</b>
         */
        private void orderList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            tempOrder = (contractParams)orderList.SelectedItem;
            string          conStr = ConfigurationManager.ConnectionStrings[localUser.CONSTR].ConnectionString;
            StringBuilder   cmdSB  = new StringBuilder("SELECT ca.CarrierName FROM Carrier ca, CarrierCities cac WHERE ca.CarrierID = cac.CarrierID AND cac.CityName='" + tempOrder.origin + "';");
            MySqlDataReader reader = null;

            using (MySqlConnection connection = new MySqlConnection(conStr))
            {
                MySqlCommand cmd = new MySqlCommand(cmdSB.ToString(), connection);
                try
                {
                    connection.Open();
                    reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        carrierBox.Items.Add(reader["CarrierName"].ToString());
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    connection.Close();
                }
            }

            carrierBox.IsEnabled = true;
        }
        /*!
         * \brief This handler handles the logic behind a selection in the List View.
         * \details This handler handles what happens when the user selects an contract entry in the List View.
         * \param sender <b>object</b>
         * \param e <b>SelectionChangedEventArgs</b>
         */

        private void databaseView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            contractParams s = (contractParams)databaseView.SelectedItem;

            displaySelectedContract.Content = s.clientName + "'s Contract";

            contractSelected = true;
        }
Example #4
0
        /*!
         * \brief CONSTRUCTOR - This constructor constructs the Order Display page.
         * \details This constructor initializes all the properties that are needed in order to use the Order Display page.
         * \param localUser - <b>User</b> - This User object keeps track of all of the session data.
         * \param param - <b>contractParams</b> - This parameter structure contains all of the contract information taken from the contracts page.
         */

        public buyer_OrderDisplay(User localUser, contractParams param)
        {
            InitializeComponent();
            File.AppendAllText(@"Log\Log.log", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.ff") + ": Buyer loaded order display in.\n");

            this.localUser = localUser;

            fillCityComboBox();

            order = new Order(param);

            customerName.Content = order.CUSTOMERNAME;
            origin.Content       = order.ORIGIN;
            quantity.Content     = order.QUANTITY;
            destination.Content  = order.DESTINATION;
        }
Example #5
0
        /*!
         * \brief CONSTRUCTOR
         * \details
         * \param param - <b>orderParams</b> - A object that contains all of the parameters of the order.
         */

        public Order(contractParams param)
        {
            Random rand = new Random();

            OrderID = ulong.Parse(rand.Next(100000, 100000000).ToString());

            orderDate       = DateTime.Now;
            markedForAction = false;

            customerName = param.clientName;
            jobType      = param.jobType;
            quantity     = param.quantity;
            origin       = param.origin;
            destination  = param.destination;
            vanType      = param.vanType;
        }
        private void incrementTimeBTN_Click(object sender, RoutedEventArgs e)
        {
            contractParams temp = (contractParams)orderList.SelectedItem;

            temp.duration -= 24;

            if (temp.duration < 0)
            {
                temp.duration        = 0;
                temp.markedForAction = true;
            }

            string        conStr = ConfigurationManager.ConnectionStrings[localUser.CONSTR].ConnectionString;
            StringBuilder cmdSB  = new StringBuilder("UPDATE Orders SET ETA=" + temp.duration.ToString() + ", MarkedForAction=" + temp.markedForAction.ToString() + " WHERE OrderID=" + temp.orderID.ToString() + ";");

            using (MySqlConnection connection = new MySqlConnection(conStr))
            {
                MySqlCommand cmd = new MySqlCommand(cmdSB.ToString(), connection);
                try
                {
                    connection.Open();
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    connection.Close();
                }
            }
            File.AppendAllText(@"Log\Log.log", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.ff") + ": Planner incremented time for an order.\n");
            planner_OrderStatus newPage = new planner_OrderStatus(localUser);

            this.NavigationService.Navigate(newPage);
        }
        /*!
         * \brief This handler handles when the user clicks the "Submit" button.
         * \details This method stores the completed order information into the Orders database.
         * \param sender <b>object</b>
         * \param e <b>RoutedEventArgs</b>
         */
        private void submitButton_Click(object sender, RoutedEventArgs e)
        {
            int    tripCount = 1;
            int    jobType;
            int    quantity;
            string origin;
            string destination;
            int    originInt        = 0;
            int    destinationInt   = 0;
            int    travelDifference = 0;
            int    distance         = 0;
            double time             = 4;
            double intTime          = 0;

            string          temp   = carrierBox.Text;
            string          conStr = ConfigurationManager.ConnectionStrings[localUser.CONSTR].ConnectionString;
            StringBuilder   cmdSB  = new StringBuilder("SELECT JobType, Quantity, Origin, Destination FROM Orders WHERE OrderID=" + tempOrder.orderID + ";");
            MySqlDataReader reader = null;


            using (MySqlConnection connection = new MySqlConnection(conStr))
            {
                MySqlCommand cmd = new MySqlCommand(cmdSB.ToString(), connection);
                try
                {
                    connection.Open();
                    reader = cmd.ExecuteReader();
                    reader.Read();
                    tempQO = new contractParams {
                        jobType     = int.Parse(reader["JobType"].ToString()),
                        quantity    = int.Parse(reader["Quantity"].ToString()),
                        origin      = reader["Origin"].ToString(),
                        destination = reader["Destination"].ToString(),
                    };
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    connection.Close();
                }
            }

            jobType     = tempQO.jobType;
            quantity    = tempQO.quantity;
            origin      = tempQO.origin;
            destination = tempQO.destination;

            switch (jobType)
            {
            case 0:
                tripCount = 1;
                break;

            case 1:
                var addTrip = new planner_ExtraCarriers();
                if (quantity > 26)
                {
                    if (addTrip.ShowDialog() == true)
                    {
                        // Move return string from addtrip window into variable
                        tempTripCount = addTrip.ResponseText;
                        // Convert to int
                        tripCount = Int32.Parse(tempTripCount);
                    }
                }
                break;
            }

            //assigning the origin city a integer representation
            switch (origin)
            {
            case "Windsor":
                originInt = 0;
                break;

            case "London":
                originInt = 1;
                break;

            case "Hamilton":
                originInt = 2;
                break;

            case "Toronto":
                originInt = 3;
                break;

            case "Oshawa":
                originInt = 4;
                break;

            case "Belleville":
                originInt = 5;
                break;

            case "Kingston":
                originInt = 6;
                break;

            case "Ottawa":
                originInt = 7;
                break;
            }

            //assigning the destination city a integer representation
            switch (destination)
            {
            case "Windsor":
                destinationInt = 0;
                break;

            case "London":
                destinationInt = 1;
                break;

            case "Hamilton":
                destinationInt = 2;
                break;

            case "Toronto":
                destinationInt = 3;
                break;

            case "Oshawa":
                destinationInt = 4;
                break;

            case "Belleville":
                destinationInt = 5;
                break;

            case "Kingston":
                destinationInt = 6;
                break;

            case "Ottawa":
                destinationInt = 7;
                break;
            }


            //
            if (originInt < destinationInt)
            {
                travelDifference = destinationInt - originInt;

                for (int i = originInt; i < travelDifference; i++)
                {
                    switch (i)
                    {
                    case 0:
                        distance += 191;
                        time     += 2.5;
                        break;

                    case 1:
                        distance += 128;
                        time     += 1.75;
                        break;

                    case 2:
                        distance += 68;
                        time     += 1.25;
                        break;

                    case 3:
                        distance += 60;
                        time     += 1.3;
                        break;

                    case 4:
                        distance += 134;
                        time     += 1.65;
                        break;

                    case 5:
                        distance += 82;
                        time     += 1.2;
                        break;

                    case 6:
                        distance += 196;
                        time     += 2.5;
                        break;

                    case 7:
                        distance += 0;
                        time     += 0;
                        break;
                    }

                    switch (jobType)
                    {
                    case 0:
                        intTime += time;
                        break;

                    case 1:
                        intTime = intTime + time + 2.0;
                        break;
                    }
                }
            }
            else if (originInt > destinationInt)
            {
                travelDifference = originInt - destinationInt;

                for (int i = originInt; i > 0; i--)
                {
                    switch (i)
                    {
                    case 0:
                        distance += 191;
                        time     += 2.5;
                        break;

                    case 1:
                        distance += 128;
                        time     += 1.75;
                        break;

                    case 2:
                        distance += 68;
                        time     += 1.25;
                        break;

                    case 3:
                        distance += 60;
                        time     += 1.3;
                        break;

                    case 4:
                        distance += 134;
                        time     += 1.65;
                        break;

                    case 5:
                        distance += 82;
                        time     += 1.2;
                        break;

                    case 6:
                        distance += 196;
                        time     += 2.5;
                        break;

                    case 7:
                        distance += 0;
                        time     += 0;
                        break;
                    }

                    switch (jobType)
                    {
                    case 0:
                        intTime += time;
                        break;

                    case 1:
                        intTime = intTime + time + 2.0;
                        break;
                    }
                }
            }

            using (MySqlConnection connection = new MySqlConnection(conStr))
            {
                // update order info
                cmdSB = new StringBuilder("UPDATE Orders SET CarrierName='" + temp + "', NumberOfTrips=" + tripCount.ToString() + ", ETA=" + intTime.ToString() + ", MarkedForAction=True WHERE OrderID=" + tempOrder.orderID + ";");
                MySqlCommand cmd = new MySqlCommand(cmdSB.ToString(), connection);
                try
                {
                    connection.Open();
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    connection.Close();
                }
            }

            File.AppendAllText(@"Log\Log.log", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.ff") + ": Planner completed an order.\n");
            planner_CompleteOrder newPage = new planner_CompleteOrder(localUser);

            this.NavigationService.Navigate(newPage);
        }
        private void createSummaryReport()
        {
            StringBuilder   sb          = new StringBuilder();
            MySqlDataReader reader      = null;
            bool            shownDialog = false;

            //Open up a save file dialog so that the user can choose where they want the invoice saved
            SaveFileDialog invoiceFile = new SaveFileDialog();

            invoiceFile.Filter = "Text file(*.txt)|*.txt|All Files (*.*)|*.*";
            invoiceFile.Title  = "Save an Invoice (.txt)";

            if (invoiceFile.ShowDialog() == true)
            {
                shownDialog = true;
            }

            string        conStr = ConfigurationManager.ConnectionStrings[localUser.CONSTR].ConnectionString;
            StringBuilder cmdSB  = new StringBuilder("SELECT OrderID, CustomerName, Origin, Destination, MarkedForAction, Quantity, JobType, OrderDate, CarrierName, Van_Type FROM Orders;");

            sb.Append("Displaying summary for " + getNumberOfOrders() + " orders.\n");

            using (MySqlConnection connection = new MySqlConnection(conStr))
            {
                MySqlCommand cmd = new MySqlCommand(cmdSB.ToString(), connection);
                try
                {
                    connection.Open();
                    reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        newContract = new contractParams {
                            orderID     = ulong.Parse(reader["OrderID"].ToString()),
                            orderDate   = reader["OrderDate"].ToString(),
                            clientName  = reader["CustomerName"].ToString(),
                            jobType     = int.Parse(reader["JobType"].ToString()),
                            quantity    = int.Parse(reader["Quantity"].ToString()),
                            origin      = reader["Origin"].ToString(),
                            destination = reader["Destination"].ToString(),
                            vanType     = int.Parse(reader["Van_Type"].ToString()),
                            carrierName = reader["CarrierName"].ToString()
                        };

                        var temp = simulateTravelRoute(newContract.origin, newContract.destination, newContract.quantity, newContract.jobType);


                        //Building the invoice
                        sb.Append("========================================================================\n");
                        sb.Append("Order Number: " + newContract.orderID + "\n");
                        sb.Append("Customer: " + newContract.clientName + "\n");
                        sb.Append("Origin: " + newContract.origin + "\n");
                        sb.Append("Destination: " + newContract.destination + "\n");
                        sb.Append("Total Travel Time: " + temp.travelTime.ToString() + "\n");
                        sb.Append("Total Intermediary Time: " + temp.travelIntTime.ToString() + "\n");
                        sb.Append("Total Travel Distance: " + temp.travelDist.ToString() + "\n");
                        sb.Append("Total Surcharge Cost: " + temp.surchargeCost + "\n");
                        sb.Append("Total Rate Cost: " + temp.totalRateCost.ToString() + "\n");
                        sb.Append("Total Final Cost: " + temp.totalFinalCost.ToString() + "\n");
                        sb.Append("========================================================================\n");

                        //writing the invoice to the file
                        if (shownDialog == true)
                        {
                            using (StreamWriter sw = new StreamWriter(invoiceFile.FileName, true))
                            {
                                sw.WriteLine(sb.ToString());
                                sb.Clear();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    connection.Close();
                }
            }
        }
Example #9
0
        /*!
         * \brief This method simulates the route that the trucks would need to take in order to reach their destinations.
         * \details This method calculates all of the information that is needed to create a accurate invoice of a shipping job.
         * \param origin - <b>string</b> - The origin city of the shipping contract.
         * \param destination - <b>string</b> - The destination city of the shipping contract.
         * \param job_type - <b>int</b> - A integer representation of the type of truck used for the job. (‘0’ for FTL, ‘1’ for LTL)
         * \return <b>invoiceOutParams</b> - This method returns a struct that contains all of the information gleaned from the simulation to populate the invoice.
         */
        private invoiceOutParams simulateTravelRoute(string origin, string destination, int quantity, int job_type)
        {
            invoiceOutParams ret;
            contractParams   order = (contractParams)orderList.SelectedItem;

            int originInt        = 0;
            int destinationInt   = 0;
            int travelDifference = 0;
            int distance         = 0;

            double time          = 0.0;
            double intTime       = 0.0;
            double rateCost      = 0;
            double surchargeCost = 0.0;
            double totalCost     = 0.0;

            //assigning the origin city a integer representation
            switch (origin)
            {
            case "Windsor":
                originInt = 0;
                break;

            case "London":
                originInt = 1;
                break;

            case "Hamilton":
                originInt = 2;
                break;

            case "Toronto":
                originInt = 3;
                break;

            case "Oshawa":
                originInt = 4;
                break;

            case "Belleville":
                originInt = 5;
                break;

            case "Kingston":
                originInt = 6;
                break;

            case "Ottawa":
                originInt = 7;
                break;
            }

            //assigning the destination city a integer representation
            switch (destination)
            {
            case "Windsor":
                destinationInt = 0;
                break;

            case "London":
                destinationInt = 1;
                break;

            case "Hamilton":
                destinationInt = 2;
                break;

            case "Toronto":
                destinationInt = 3;
                break;

            case "Oshawa":
                destinationInt = 4;
                break;

            case "Belleville":
                destinationInt = 5;
                break;

            case "Kingston":
                destinationInt = 6;
                break;

            case "Ottawa":
                destinationInt = 7;
                break;
            }


            //
            if (originInt < destinationInt)
            {
                travelDifference = destinationInt - originInt;

                for (int i = originInt; i < travelDifference; i++)
                {
                    switch (i)
                    {
                    case 0:
                        distance += 191;
                        time     += 2.5;
                        break;

                    case 1:
                        distance += 128;
                        time     += 1.75;
                        break;

                    case 2:
                        distance += 68;
                        time     += 1.25;
                        break;

                    case 3:
                        distance += 60;
                        time     += 1.3;
                        break;

                    case 4:
                        distance += 134;
                        time     += 1.65;
                        break;

                    case 5:
                        distance += 82;
                        time     += 1.2;
                        break;

                    case 6:
                        distance += 196;
                        time     += 2.5;
                        break;

                    case 7:
                        distance += 0;
                        time     += 0;
                        break;
                    }

                    switch (job_type)
                    {
                    case 0:
                        intTime += time;
                        break;

                    case 1:
                        intTime = intTime + time + 2.0;
                        break;
                    }
                }
            }
            else if (originInt > destinationInt)
            {
                travelDifference = originInt - destinationInt;

                for (int i = originInt; i > 0; i--)
                {
                    switch (i)
                    {
                    case 0:
                        distance += 191;
                        time     += 2.5;
                        break;

                    case 1:
                        distance += 128;
                        time     += 1.75;
                        break;

                    case 2:
                        distance += 68;
                        time     += 1.25;
                        break;

                    case 3:
                        distance += 60;
                        time     += 1.3;
                        break;

                    case 4:
                        distance += 134;
                        time     += 1.65;
                        break;

                    case 5:
                        distance += 82;
                        time     += 1.2;
                        break;

                    case 6:
                        distance += 196;
                        time     += 2.5;
                        break;

                    case 7:
                        distance += 0;
                        time     += 0;
                        break;
                    }

                    switch (job_type)
                    {
                    case 0:
                        intTime += time;
                        break;

                    case 1:
                        intTime = intTime + time + 2.0;
                        break;
                    }
                }
            }

            //calculating the rate cost
            switch (job_type)
            {
            case 0:
                rateCost = 4.985 * distance;
                break;

            case 1:
                rateCost = (0.2995 * distance) * quantity;
                break;
            }

            //calculating the surcharge
            if (intTime > 24)
            {
                for (int i = 0; i < intTime; i += 24)
                {
                    surchargeCost += 150;
                }
            }

            totalCost = surchargeCost + rateCost;

            //returning the struct with all of the calculated data
            return(new invoiceOutParams {
                travelTime = time, travelIntTime = intTime, travelDist = distance, surchargeCost = surchargeCost, totalRateCost = rateCost, totalFinalCost = totalCost
            });
        }
Example #10
0
 /*!
  * \brief This handler handles the logic behind a selection in the List View.
  * \details This handler handles what happens when the user selects an contract entry in the List View.
  * \param sender <b>object</b>
  * \param e <b>SelectionChangedEventArgs</b>
  */
 private void orderList_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     p = (contractParams)orderList.SelectedItem;
     invoiceOrderBTN.IsEnabled = true;
 }