Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Vernon Hills Mail-Order Company often sends multiple packages per order. For

ID: 3647730 • Letter: T

Question

The Vernon Hills Mail-Order Company often sends multiple packages per order. For each customer order, output enough mailing labels to use on each of the boxes that will be mailed. The mailing labels contain the customer

Explanation / Answer

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class frmCreateOrder : Form { public frmCreateOrder() { InitializeComponent(); } private void btnlblCreate_Click(object sender, EventArgs e) { //Read from text file 'VernonHillMailOrderBoxes.txt' String line; String filePath = @"F:\Lorimodule7Chapter.07DataFilesForExercisesVernonHillsMailOrderBoxes.txt"; //Pass the file path and file name to the StreamReader constructor if (File.Exists(filePath)) { StreamReader sr = null; //Enclose the file opening, reading, and closing //operations in a try catch block to gracefully //recover from and handle any exceptions from //'File.IO' operations try { sr = new StreamReader(filePath); //Continue to read until you reach end of file while ((line = sr.ReadLine()) != null) { //Get name, address, and number of boxes //Parse the string by separating items //Read the first line from the text file string[] linefromFile = line.Split(','); int boxNum = 0; int boxLength = 0; int count = 0; string name = String.Empty; string address = String.Empty; string addressNum = String.Empty; string numBoxes = String.Empty; //Parse each string in the array then start building //the label by combining array indexes 0, 1, and 2 //for the name and title. The array element with index //3 hold the address number, array elements 4, 5, 6 hold //rest of the address. Finally the last element in the //array is the number of boxes index 7. foreach (string s in linefromFile) { boxLength = linefromFile.Length; boxNum = Convert.ToInt32(linefromFile[boxLength - 1].ToString()); if (count < 3) name += s; if (count > 2 && count < 4) addressNum += s; if (count > 3 && count < 7) address += s; count++; } //Create the label by combining name, address, //and the number of boxes in the form "Box 1 of 5" for (int i = 0; i != boxNum; i++) { int boxCount = i + 1; txtOrder.AppendText( " "); txtOrder.AppendText(name); txtOrder.AppendText(" "); txtOrder.AppendText(addressNum.Trim()); txtOrder.AppendText(" "); txtOrder.AppendText(address.Trim()); numBoxes = "Box " + boxCount.ToString() + " of " + boxNum.ToString(); txtOrder.AppendText(" "); txtOrder.AppendText(numBoxes); txtOrder.AppendText(" "); } } } catch (Exception ex) { //Log the exception information to the form txtOrder.Text = ("Exception: " + ex.Message); } finally { //Close the file if (sr != null) sr.Close(); } } } //Close the form by clicking the ‘QUIT’ button private void btnQuit_Click(object sender, EventArgs e) { frmCreateOrder.ActiveForm.Close(); } } } ‘Program.cs’ source: using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace WindowsFormsApplication1 { static class Program { /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frmCreateOrder()); } } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote