/********************************************************************************************* * Submit Quote * This button will validate all data entered, and prompt user to enter valid data if there is * an error. * If the data is valid, the method will commit all variavles to the DeskQuote object to store * ******************************************************************************************/ private void submitQuoteButton_Click(object sender, EventArgs e) { // Create a new desk and populate it with the selected values Desk desk = new Desk(); desk.setWidth(Convert.ToInt32(Math.Round(deskWidthText.Value, 0))); desk.setDepth(Convert.ToInt32(Math.Round(deskDepthText.Value, 0))); desk.setNumdrawers(Convert.ToInt32(Math.Round(deskDrawersText.Value, 0))); desk.Material = (DeskMaterial)deskMaterialComboBox.SelectedValue; // Create the customer and rushDays preference string custName = custNameText.Text; int rushDays = 14; // Determine if default rush days is changed if (threeDayRadio.Checked) { rushDays = 3; } if (fiveDayRadio.Checked) { rushDays = 5; } if (sevenDayRadio.Checked) { rushDays = 7; } // Set the quote date to now DateTime quoteDate = DateTime.Now; // Create the quote object DeskQuote newQuote = new DeskQuote(custName, rushDays, quoteDate, desk); // Calculate quote total int totalQuote = newQuote.calcuateQuote(desk); newQuote.setTotalQuote(totalQuote); // Write the quote to file in CSV format var QuoteOutput = custName + "," + quoteDate + "," + desk.getWidth() + "," + desk.getDepth() + "," + desk.getDrawers() + "," + desk.Material + "," + rushDays + "," + totalQuote; string cFile = @"quotes.txt"; // if file does not exist, create a file if (!File.Exists(cFile)) { using (StreamWriter sw = File.CreateText(cFile)) {} } // file exists, write the data using (StreamWriter swa = File.AppendText(cFile)) { swa.WriteLine(QuoteOutput); swa.Close(); } // Quote file is created at this point. Display the quote in a new form DisplayQuote displayQuoteView = new DisplayQuote(newQuote); displayQuoteView.Tag = this; displayQuoteView.Show(this); }
// methods public int calcuateQuote(Desk desk) { // Declare and initialize quote variable with base cost int totalQuote = BASE_DESK_PRICE; // Determine desk area cost if any if (desk.getArea() > DESK_AREA_THRESHOLD) { totalQuote += desk.getArea() * DESK_AREA_PRICE; } // Determine drawer cost totalQuote += desk.getDrawers() * DRAWER_PRICE; // Determine material cost using enum values totalQuote += (int)desk.Material; // Determine rush order cost by rush days - 14 days has no additional cost switch (getRushDays()) { // 3 day rush order case 3: // desk area less than 1000 if (desk.getArea() < 1000) { totalQuote += 60; } // desk area 1000 to 2000 else if (desk.getArea() >= 1000 && desk.getArea() <= 2000) { totalQuote += 70; } // desk area greater than 2000 else { totalQuote += 80; } break; // 5 day rush order case 5: // desk area less than 1000 if (desk.getArea() < 1000) { totalQuote += 40; } // desk area 1000 to 2000 else if (desk.getArea() >= 1000 && desk.getArea() <= 2000) { totalQuote += 50; } // desk area greater than 2000 else { totalQuote += 60; } break; // 7 day rush order case 7: // desk area less than 1000 if (desk.getArea() < 1000) { totalQuote += 30; } // desk area 1000 to 2000 else if (desk.getArea() >= 1000 && desk.getArea() <= 2000) { totalQuote += 35; } // desk area greater than 2000 else { totalQuote += 40; } break; } // total desk quote should be calculated at this point. Return the quote price return(totalQuote); }