public override string[] printProperties(int ProductPlace) { Magazine myMagazine = new Magazine(); StreamReader readcustomerfile; readcustomerfile = File.OpenText(@"Products.txt"); string[] properties = new string[5]; string info = ""; string line; int control = 0; int first, last; while ((line = readcustomerfile.ReadLine()) != null) { control = line.IndexOf("ID : " + (200 + ProductPlace)); if (control != -1) { //Set ID To Magazine With Read Text File first = line.IndexOf("ID : ") + "ID : ".Length; last = line.IndexOf(",Name"); info = line.Substring(first, last - first); myMagazine.setID(Convert.ToInt32(info)); properties[0] = myMagazine.getID().ToString(); //Set Name To Magazine With Read Text File first = line.IndexOf("Name : ") + "Name : ".Length; last = line.IndexOf(",Price"); info = line.Substring(first, last - first); myMagazine.setName(info); properties[1] = myMagazine.getName(); //Set Price To Magazine With Read Text File first = line.IndexOf("Price : ") + "Price : ".Length; last = line.IndexOf(",Issue"); info = line.Substring(first, last - first); myMagazine.setPrice(Convert.ToInt32(info)); properties[2] = myMagazine.getPrice().ToString(); //Set Issue To Magazine With Read Text File first = line.IndexOf("Issue : ") + "Issue : ".Length; last = line.IndexOf(",Type"); info = line.Substring(first, last - first); myMagazine.setissue(info); properties[3] = myMagazine.getissue(); //Set Type To Magazine With Read Text File first = line.IndexOf("Type : ") + "Type : ".Length; last = line.Length; info = line.Substring(first, last - first); myMagazine.setType(info); properties[4] = myMagazine.getType(); } } return(properties); }
private void btnRemoveProduct_Click(object sender, EventArgs e) { if (cbRemovedProductQuantity.Text == "") { MessageBox.Show("Please Set Quantity!"); } else { string[] properties; int place = 0; for (int i = 0; i < listProducts.Items.Count; i++) { if (listProducts.Items[i].Selected == true) { int newQuantity = 0; if (Convert.ToInt32(listProducts.Items[i].SubItems[0].Text) > 100 && Convert.ToInt32(listProducts.Items[i].SubItems[0].Text) < 200) { properties = new string[PropertiesCountOfItem("Book")]; Book myBook = new Book(); place = Convert.ToInt32(listProducts.Items[i].SubItems[0].Text) - 100; properties = myBook.printProperties(place); myBook.setID(Convert.ToInt32(properties[0])); myBook.setName(properties[1]); myBook.setPrice(Convert.ToInt32(properties[2])); myBook.setISBN(Convert.ToInt32(properties[3])); myBook.setAuthor(properties[4]); myBook.setPublisher(properties[5]); ItemToPurchase item = new ItemToPurchase(myBook, Convert.ToInt32(cbRemovedProductQuantity.Text)); myShoppingCart.removeProduct(item); if (Convert.ToInt32(cbRemovedProductQuantity.Text) >= Convert.ToInt32(listProducts.Items[i].SubItems[3].Text)) { listProducts.Items[i].Remove(); } else { newQuantity = Convert.ToInt32(listProducts.Items[i].SubItems[3].Text) - Convert.ToInt32(cbRemovedProductQuantity.Text); listProducts.Items[i].SubItems[3].Text = newQuantity.ToString(); listProducts.Refresh(); } } else if (Convert.ToInt32(listProducts.Items[i].SubItems[0].Text) > 200 && Convert.ToInt32(listProducts.Items[i].SubItems[0].Text) < 300) { properties = new string[PropertiesCountOfItem("Magazine")]; Magazine myMagazine = new Magazine(); place = Convert.ToInt32(listProducts.Items[i].SubItems[0].Text) - 200; properties = myMagazine.printProperties(place); myMagazine.setID(Convert.ToInt32(properties[0])); myMagazine.setName(properties[1]); myMagazine.setPrice(Convert.ToInt32(properties[2])); myMagazine.setissue(properties[3]); myMagazine.setType(properties[4]); ItemToPurchase item = new ItemToPurchase(myMagazine, Convert.ToInt32(cbRemovedProductQuantity.Text)); myShoppingCart.removeProduct(item); if (Convert.ToInt32(cbRemovedProductQuantity.Text) >= Convert.ToInt32(listProducts.Items[i].SubItems[3].Text)) { listProducts.Items[i].Remove(); } else { newQuantity = Convert.ToInt32(listProducts.Items[i].SubItems[3].Text) - Convert.ToInt32(cbRemovedProductQuantity.Text); listProducts.Items[i].SubItems[3].Text = newQuantity.ToString(); listProducts.Refresh(); } } else { properties = new string[PropertiesCountOfItem("MusicCD")]; MusicCD myMusicCD = new MusicCD(); place = Convert.ToInt32(listProducts.Items[i].SubItems[0].Text) - 300; properties = myMusicCD.printProperties(place); myMusicCD.setID(Convert.ToInt32(properties[0])); myMusicCD.setName(properties[1]); myMusicCD.setPrice(Convert.ToInt32(properties[2])); myMusicCD.setsinger(properties[3]); myMusicCD.setType(properties[4]); ItemToPurchase item = new ItemToPurchase(myMusicCD, Convert.ToInt32(cbRemovedProductQuantity.Text)); myShoppingCart.removeProduct(item); if (Convert.ToInt32(cbRemovedProductQuantity.Text) >= Convert.ToInt32(listProducts.Items[i].SubItems[3].Text)) { listProducts.Items[i].Remove(); } else { newQuantity = Convert.ToInt32(listProducts.Items[i].SubItems[3].Text) - Convert.ToInt32(cbRemovedProductQuantity.Text); listProducts.Items[i].SubItems[3].Text = newQuantity.ToString(); listProducts.Refresh(); } } } } } }