private void button1_Click(object sender, EventArgs e) { if (txtName.Text == "") { toolStripStatusLabel1.Text = "Enter an item name!"; System.Media.SystemSounds.Exclamation.Play(); return; } int quantity = (int)numQuant.Value; if (txtCost.Text == "") { toolStripStatusLabel1.Text = "Enter an item cost!"; System.Media.SystemSounds.Exclamation.Play(); return; } //make sure at least one checkbox is checked if (!boxEd.Checked && !boxMatt.Checked && !boxMel.Checked && !boxMike.Checked) { toolStripStatusLabel1.Text = "Check at least one person!"; System.Media.SystemSounds.Exclamation.Play(); return; } decimal cost; decimal.TryParse(txtCost.Text.Substring(1), out cost); int payers = 0; if (boxEd.Checked) { payers += (int)Payer.Ed; } if (boxMatt.Checked) { payers += (int)Payer.Matt; } if (boxMel.Checked) { payers += (int)Payer.Mel; } if (boxMike.Checked) { payers += (int)Payer.Mike; } GroceryItem newItem = new GroceryItem(txtName.Text, cost, boxTax.Checked, payers, quantity); m_LastAddedItem = newItem.GetListItem(); ((Form1)myParent).AddItem(m_LastAddedItem); }
private void button1_Click(object sender, EventArgs e) { if (txtName.Text == "") { toolStripStatusLabel1.Text = "Enter an item name!"; System.Media.SystemSounds.Exclamation.Play(); return; } int quantity = (int)numQuant.Value; if (txtCost.Text == "") { toolStripStatusLabel1.Text = "Enter an item cost!"; System.Media.SystemSounds.Exclamation.Play(); return; } //make sure at least one checkbox is checked if (!boxEd.Checked && !boxMatt.Checked && !boxMel.Checked && !boxMike.Checked) { toolStripStatusLabel1.Text = "Check at least one person!"; System.Media.SystemSounds.Exclamation.Play(); return; } decimal cost; decimal.TryParse(txtCost.Text.Substring(1), out cost); int payers = 0; if (boxEd.Checked) payers += (int)Payer.Ed; if (boxMatt.Checked) payers += (int)Payer.Matt; if (boxMel.Checked) payers += (int)Payer.Mel; if (boxMike.Checked) payers += (int)Payer.Mike; GroceryItem newItem = new GroceryItem(txtName.Text, cost, boxTax.Checked, payers, quantity); m_LastAddedItem = newItem.GetListItem(); ((Form1)myParent).AddItem(m_LastAddedItem); }
private void loadFile(string filepath) { //open the file stream System.IO.StreamReader file = new System.IO.StreamReader(filepath); string line; string[] entries = new string[5]; //clear our current list listItems.Items.Clear(); //loop through all the items while (!file.EndOfStream) { line = file.ReadLine(); entries = line.Split('\t'); string name = entries[0]; int quantity; int.TryParse(entries[1], out quantity); decimal cost; decimal.TryParse( entries[2].TrimStart('$'), out cost ); bool taxed; if (entries[3] == "Y") taxed = true; else taxed = false; string payersString = entries[4]; int payersInt = 0; if (payersString.Contains("Ed")) { payersInt += (int)Payer.Ed; } if (payersString.Contains("Matt")) { payersInt += (int)Payer.Matt; } if (payersString.Contains("Mel")) { payersInt += (int)Payer.Mel; } if (payersString.Contains("Mike")) { payersInt += (int)Payer.Mike; } GroceryItem item = new GroceryItem(name, cost, taxed, payersInt, quantity); AddItem(item.GetListItem()); } file.Close(); }
private void loadFile(string filepath) { //open the file stream System.IO.StreamReader file = new System.IO.StreamReader(filepath); string line; string[] entries = new string[5]; //clear our current list listItems.Items.Clear(); //loop through all the items while (!file.EndOfStream) { line = file.ReadLine(); entries = line.Split('\t'); string name = entries[0]; int quantity; int.TryParse(entries[1], out quantity); decimal cost; decimal.TryParse(entries[2].TrimStart('$'), out cost); bool taxed; if (entries[3] == "Y") { taxed = true; } else { taxed = false; } string payersString = entries[4]; int payersInt = 0; if (payersString.Contains("Ed")) { payersInt += (int)Payer.Ed; } if (payersString.Contains("Matt")) { payersInt += (int)Payer.Matt; } if (payersString.Contains("Mel")) { payersInt += (int)Payer.Mel; } if (payersString.Contains("Mike")) { payersInt += (int)Payer.Mike; } GroceryItem item = new GroceryItem(name, cost, taxed, payersInt, quantity); AddItem(item.GetListItem()); } file.Close(); }