} // end btnClear_Click // Checks if Product List is empty and, if not, copies the data for the // ith Product to the appropriate group textboxes using the display sub. // Also checks to determine if the next button should be enabled. private void getItem(int i) { if (thisProductList.Count() == 0) { btnDelete.Enabled = false; btnEdit.Enabled = false; // btnToString.Enabled = false; lblUserMessage.Text = "Please select an operation"; } else if (i < 0 || i >= thisProductList.Count()) { MessageBox.Show("getItem error: index out of range"); return; } else { currentIndex = i; thisProductList.getAnItem(i).Display(this); // ***************** // thisOwlList.RemoveAt(i); lblUserMessage.Text = "Object Type: " + thisProductList.getAnItem(i).GetType().ToString() + " List Index: " + i.ToString(); btnFind.Enabled = true; btnDelete.Enabled = true; btnEdit.Enabled = true; } // end else } // end getItem
//Edit button - Checks to see what type of object is being edited. private void btnEditUpdate_Click(object sender, EventArgs e) { bool success; btnDelete.Enabled = false; btnSave.Enabled = false; success = findAnItem("Edit/Update"); if (success) { btnSave.Enabled = true; btnEditUpdate.Enabled = false; txtProductUPC.ReadOnly = false; txtProductTitle.ReadOnly = false; txtProductQuantity.ReadOnly = false; txtProductPrice.ReadOnly = false; Product p = thisProductList.getAnItem(currentIndex); txtProductPrice.Text = p.ProductPrice.ToString(); txtProductUPC.Text = p.ProductUPC.ToString(); txtProductQuantity.Text = p.ProductQuantity.ToString(); txtProductTitle.Text = p.ProductTitle.ToString(); MessageBox.Show("Edit/UPDATE current Product (as shown). Press Save Updates Button", "Edit/Update Notice", MessageBoxButtons.OK); if (p.GetType() == typeof(CDChamber)) { FormController.activateCDChamber(this); FormController.deactivateAllButCDChamber(this); FormController.deactivateAddButtons(this); txtCDClassicalArtists.ReadOnly = false; txtCDClassicalLabel.ReadOnly = false; txtCDChamberInstrumentList.ReadOnly = false; txtCDClassicalLabel.Text = ((CDClassical)p).CDClassicalLabel; txtCDClassicalArtists.Text = ((CDClassical)p).CDClassicalArtists; txtCDChamberInstrumentList.Text = ((CDChamber)p).getCDChamberInstrumentList(); recordsProcessedCount++; } else if (p.GetType() == typeof(CDOrchestra)) { FormController.activateCDOrchestra(this); FormController.deactivateAllButCDOrchestra(this); txtCDClassicalArtists.ReadOnly = false; txtCDClassicalLabel.ReadOnly = false; txtCDOrchestraConductor.ReadOnly = false; txtCDClassicalLabel.Text = ((CDClassical)p).CDClassicalLabel; txtCDClassicalArtists.Text = ((CDClassical)p).CDClassicalArtists; txtCDOrchestraConductor.Text = ((CDOrchestra)p).getCDOrchestraConductor(); recordsProcessedCount++; } else if (p.GetType() == typeof(Book)) { FormController.activateBook(this); FormController.deactivateAllButBook(this); FormController.deactivateAddButtons(this); txtBookISBNLeft.ReadOnly = false; txtBookISBNRight.ReadOnly = false; txtBookAuthor.ReadOnly = false; txtBookPages.ReadOnly = false; txtBookISBNLeft.Text = (((Book)p).BookISBNLeft).ToString(); txtBookISBNRight.Text = (((Book)p).BookISBNRight).ToString(); txtBookAuthor.Text = ((Book)p).BookAuthor; txtBookPages.Text = ((Book)p).BookPages.ToString(); recordsProcessedCount++; } else if (p.GetType() == typeof(BookCIS)) { FormController.activateBookCIS(this); FormController.deactivateAllButBookCIS(this); txtBookISBNLeft.ReadOnly = false; txtBookISBNRight.ReadOnly = false; txtBookAuthor.ReadOnly = false; txtBookPages.ReadOnly = false; txtBookCISCISArea.ReadOnly = false; txtBookISBNLeft.Text = (((Book)p).BookISBNLeft).ToString(); txtBookISBNRight.Text = (((Book)p).BookISBNRight).ToString(); txtBookAuthor.Text = ((Book)p).BookAuthor; txtBookPages.Text = (((Book)p).BookPages).ToString(); txtBookCISCISArea.Text = ((BookCIS)p).BookCISCISArea; recordsProcessedCount++; } // end multiple alternative if else if (p.GetType() == typeof(DVD)) { FormController.activateDVD(this); FormController.deactivateAllButDVD(this); txtDVDLeadActor.ReadOnly = false; txtDVDReleaseDate.ReadOnly = false; txtDVDRunTime.ReadOnly = false; txtDVDLeadActor.Text = ((DVD)p).DVDLeadActor; txtDVDReleaseDate.Text = ((DateTime)((DVD)p).DVDReleaseDate).ToString("MM/dd/yyyy"); txtDVDRunTime.Text = (((DVD)p).DVDRunTime).ToString(); recordsProcessedCount++; } else { MessageBox.Show("Fatal error. Data type not Book, BookCIS, DVD, DC Chamber or CD Orchestra. Program Terminated. ", "Mis-typed Object", MessageBoxButtons.OK); this.Close(); } // end multiple alternative if } // end if on success }