// Event for when the Add Shoe button is clicked private void addShoeButton_Click(object sender, EventArgs e) { try { // Creates a new object tempShoe that will hold all the properties the user has input shoe tempShoe = new shoe(); // Throws an exception if any of the text boxes in the panel are left blank by the user if (addBrandTextbox.Text == "" || addModelTextbox.Text == "" || addColorTextbox.Text == "") { throw new ArgumentNullException(); } // Sets the tempShoe object properties to the values the user has input tempShoe.Brand = addBrandTextbox.Text; tempShoe.Model = addModelTextbox.Text; tempShoe.Color = addColorTextbox.Text; // Adds the tempShoe to the currrent list shoeList.Add(tempShoe); // Updates the label on the panel to alert the user which shoe they have added addedShoeLabel.Text = ("Added " + tempShoe.Brand + " " + tempShoe.Model + " " + tempShoe.Color); // Resets the fields on the panel addBrandTextbox.Text = null; addModelTextbox.Text = null; addColorTextbox.Text = null; addBrandTextbox.Focus(); } catch { MessageBox.Show("Please fill out all the required information"); } }
// Event for when the Import Collection button on the Main Menu Group Box is clicked private void importCollectionButton_Click(object sender, EventArgs e) { try { // Clears the current shoe list to make room for the list being imported shoeList.Clear(); // Creates a new OpenFileDialog object named openCollection OpenFileDialog openCollection = new OpenFileDialog(); openCollection.FileName = "DefaultOutput.txt"; openCollection.Filter = "Text File | *.txt"; if (openCollection.ShowDialog() == DialogResult.OK) { // Creates a StreamReader object called inputFile // Also declared inputLine variable (to hold the entire line) // and shoeComponents array (to hold each individual shoe component from inputLine) StreamReader inputFile = new StreamReader(openCollection.OpenFile()); string inputLine; string[] shoeComponents; // Reads the inputFile until the end while (!inputFile.EndOfStream) { // Creates new shoe object called tempShoe to hold the current shoe being input shoe tempShoe = new shoe(); // Sets inputLine = to the shoe on the line being read // shoeComponents = the individual components of the shoes inputLine = inputFile.ReadLine(); shoeComponents = inputLine.Split('|'); tempShoe.Brand = shoeComponents[0]; tempShoe.Model = shoeComponents[1]; tempShoe.Color = shoeComponents[2]; // Adds tempShoe to the current list shoeList.Add(tempShoe); } // Disposes and closes inputFile inputFile.Dispose(); inputFile.Close(); } // Makes the Main Menu GroupBox invisible, calls printList function, makes the Edit Menu Panel visible mainMenuBox.Visible = false; printList(); editMenuPanel.Visible = true; } catch { MessageBox.Show("Error"); } }