/*! * \brief This handler handles when the user clicks the "Complete Order" button. * \details This handler brings up the admin backup button page. * \param sender <b>object</b> * \param e <b>RoutedEventArgs</b> */ private void completeOrderBTN_Click(object sender, RoutedEventArgs e) { // Transfer to completeOrder Page planner_CompleteOrder orderPage = new planner_CompleteOrder(localUser); PlannerFrame.NavigationService.Navigate(orderPage); }
/*! * \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); }