private void btnCreateCDChamber_Click(object sender, EventArgs e) { txtCDClassicalArtists.ReadOnly = false; txtCDClassicalLabel.ReadOnly = false; txtCDChamberInstrumentList.ReadOnly = false; FormController.activateCDClassical(this); FormController.activateCDChamber(this); btnCreateBook.Enabled = false; btnCreateBookCIS.Enabled = false; btnCreateDVD.Enabled = false; btnCreateCDOrchestra.Enabled = false; btnSave.Enabled = true; clickedBtn = "create_CD_chamber"; }
void DisplayCDChamberForm() { // Display form for Create/Insert or Find/SELECT or Edit/Update or Delete a Chamber Music CD btnCreateCDChamber.Enabled = true; btnCreateCDChamber.Text = "Save CD Chamber"; FormController.formAddMode(this); txtProductUPC.Enabled = true; txtProductPrice.Enabled = true; txtProductTitle.Enabled = true; txtProductQuantity.Enabled = true; txtDVDLeadActor.Enabled = false; txtDVDReleaseDate.Enabled = false; txtDVDRunTime.Enabled = false; txtBookISBNLeft.Enabled = false; txtBookISBNRight.Enabled = false; txtBookAuthor.Enabled = false; txtBookPages.Enabled = false; txtBookCISCISArea.Enabled = false; txtCDClassicalLabel.Enabled = true; txtCDClassicalArtists.Enabled = true; txtCDOrchestraConductor.Enabled = false; txtCDChamberInstrumentList.Enabled = true; btnCreateBookCIS.Enabled = false; btnCreateBook.Enabled = false; btnCreateDVD.Enabled = false; btnCreateCDOrchestra.Enabled = false; FormController.activateCDChamber(this); FormController.deactivateCDOrchestra(this); FormController.deactivateDVD(this); FormController.deactivateBook(this); FormController.deactivateBookCIS(this); toolTip1.SetToolTip(btnCreateCDChamber, ttSaveCDChamber); txtProductUPC.Focus(); } // end DisplayCDChamberForm
} // end getItem //Searches item by the UPC number since it is guarenteed that this will be a unique identifier private void btnProductUPCSearch_Click(object sender, EventArgs e) { bool temp = Validation.validateProductUPC(txtProductUPCSearch.Text); //first make sure the format is correct if (temp) { bool found; // boolean reference for search success string pstring; // Product string updated upon product DB search call. Product prod; // this returns an OleDbDataReader object, but you don't really need to use it // the boolean flag and string that are returned are important // pstring will hold the attributes of a product from the database in a single string, separated by newline characters // split it below OleDbDataReader odb = dbFunctions.SelectProductFromProduct(Convert.ToInt32(txtProductUPCSearch.Text), out found, out pstring); if (!found) //not found { MessageBox.Show("Product not found"); txtProductUPCSearch.Clear(); txtProductUPCSearch.Focus(); } // Creates a new product to display in form. else { txtProductUPC.ReadOnly = true; txtProductTitle.ReadOnly = true; txtProductQuantity.ReadOnly = true; txtProductPrice.ReadOnly = true; btnDelete.Enabled = true; string[] attributes = pstring.Split('\n'); // splits product attributes into array for (int i = 0; i < attributes.Length; i++) { attributes[i] = attributes[i].Trim('\r'); // clears "junk" from each field } string ptype = attributes[4]; // gets the product type from this attribute and then creates new product to display in form if (ptype == "DVD") { txtDVDLeadActor.ReadOnly = true; txtDVDReleaseDate.ReadOnly = true; txtDVDRunTime.ReadOnly = true; prod = new DVD(Convert.ToInt32(attributes[0]), Convert.ToDecimal(attributes[1]), attributes[2], Convert.ToInt32(attributes[3]), attributes[5], DateTime.Parse(attributes[6]), Convert.ToInt32(attributes[7])); prod.Display(this); FormController.searchForm(this); FormController.activateDVD(this); thisProductList.Add(prod); currentIndex++; } if (ptype == "Book") { String isbnS = attributes[5]; String isbn1 = isbnS.Substring(0, 3); String isbn2 = isbnS.Substring(3, 3); txtBookISBNLeft.ReadOnly = true; txtBookISBNRight.ReadOnly = true; txtBookAuthor.ReadOnly = true; txtBookPages.ReadOnly = true; prod = new Book(Convert.ToInt32(attributes[0]), Convert.ToDecimal(attributes[1]), attributes[2], Convert.ToInt32(attributes[3]), Convert.ToInt32(isbn1), Convert.ToInt32(isbn2), attributes[6], Convert.ToInt32(attributes[7])); prod.Display(this); FormController.searchForm(this); FormController.activateBook(this); thisProductList.Add(prod); currentIndex++; } if (ptype == "BookCIS") { String isbnS = attributes[5]; String isbn1 = isbnS.Substring(0, 3); String isbn2 = isbnS.Substring(3, 3); txtBookISBNLeft.ReadOnly = true; txtBookISBNRight.ReadOnly = true; txtBookAuthor.ReadOnly = true; txtBookPages.ReadOnly = true; txtBookCISCISArea.ReadOnly = true; prod = new BookCIS(Convert.ToInt32(attributes[0]), Convert.ToDecimal(attributes[1]), attributes[2], Convert.ToInt32(attributes[3]), Convert.ToInt32(isbn1), Convert.ToInt32(isbn2), attributes[6], Convert.ToInt32(attributes[7]), attributes[8]); prod.Display(this); FormController.searchForm(this); FormController.activateBookCIS(this); thisProductList.Add(prod); currentIndex++; } if (ptype == "CDOrchestra") { txtCDClassicalArtists.ReadOnly = true; txtCDClassicalLabel.ReadOnly = true; txtCDOrchestraConductor.ReadOnly = true; prod = new CDOrchestra(Convert.ToInt32(attributes[0]), Convert.ToDecimal(attributes[1]), attributes[2], Convert.ToInt32(attributes[3]), attributes[5], attributes[6], attributes[7]); prod.Display(this); FormController.searchForm(this); FormController.activateCDOrchestra(this); thisProductList.Add(prod); currentIndex++; } if (ptype == "CDChamber") { txtCDClassicalArtists.ReadOnly = true; txtCDClassicalLabel.ReadOnly = true; txtCDChamberInstrumentList.ReadOnly = true; //String[] InstrumentList = attributes[6].Split(' '); prod = new CDChamber(Convert.ToInt32(attributes[0]), Convert.ToDecimal(attributes[1]), attributes[2], Convert.ToInt32(attributes[3]), attributes[5], attributes[6], attributes[7]); prod.Display(this); FormController.searchForm(this); FormController.activateCDChamber(this); thisProductList.Add(prod); currentIndex++; } /* * * add else ifs for the other product types and handle each accordingly * */ else { // this is an invalid record (since it does not fit one of our types) } } } else { // UPC is invalid MessageBox.Show("Invalid URL", "Error:"); } }
//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 }
}//end of saveEditUpdate on click method private void btnDelete_Click(object sender, EventArgs e) { if (btnDelete.Text == "Delete") { btnFind.Enabled = false; btnEdit.Enabled = false; bool OkayFlag; string productFields; dbFunctions.SelectProductFromProduct(Convert.ToInt32(txtProductUPC.Text), out OkayFlag, out productFields); //returns out variable values string[] productFieldArray = handleFieldOutput(productFields); //splits and trims productFields //Product p = thisProductList.getAnItem(Convert.ToInt32(txtProductUPC.Text));// product to be found //sets textboxes to proper values in product field array txtProductPrice.Text = productFieldArray[1]; txtProductUPC.Text = productFieldArray[0]; txtProductQuantity.Text = productFieldArray[3]; txtProductTitle.Text = productFieldArray[2]; if (productFieldArray[4] == "CDChamber")//handles cd chamber { FormController.activateCDChamber(this); FormController.deactivateAllButCDChamber(this); FormController.deactivateAddButtons(this); txtCDClassicalLabel.Text = productFieldArray[5]; txtCDClassicalArtists.Text = productFieldArray[6]; txtCDChamberInstrumentList.Text = productFieldArray[7]; } else if (productFieldArray[4] == "CDOrchestra")//handles cd orchestra { FormController.activateCDOrchestra(this); FormController.deactivateAllButCDOrchestra(this); txtCDClassicalLabel.Text = productFieldArray[5]; txtCDClassicalArtists.Text = productFieldArray[6]; txtCDOrchestraConductor.Text = productFieldArray[7]; } else if (productFieldArray[4] == "Book")//handles book { FormController.activateBook(this); FormController.deactivateAllButBook(this); FormController.deactivateAddButtons(this); string leftISBN = ""; string rightISBN = ""; for (int j = 0; j < productFieldArray[5].Length; j++)//seperates ISBN for 2 seperate textboxes { if (leftISBN.Length != 3) { leftISBN += productFieldArray[5][j]; } else { rightISBN += productFieldArray[5][j]; } } txtBookISBNLeft.Text = leftISBN; txtBookISBNRight.Text = rightISBN; txtBookAuthor.Text = productFieldArray[6]; txtBookPages.Text = productFieldArray[7]; } else if (productFieldArray[4] == "BookCIS")//handles book cis { FormController.activateBookCIS(this); FormController.deactivateAllButBookCIS(this); string leftISBN = ""; string rightISBN = ""; for (int j = 0; j < productFieldArray[5].Length; j++)//seperates ISBN for 2 seperate textboxes { if (leftISBN.Length != 3) { leftISBN += productFieldArray[5][j]; } else { rightISBN += productFieldArray[5][j]; } } txtBookISBNLeft.Text = leftISBN; txtBookISBNRight.Text = rightISBN; txtBookAuthor.Text = productFieldArray[6]; txtBookPages.Text = productFieldArray[7]; txtBookCISCISArea.Text = productFieldArray[8]; } // end multiple alternative if else if (productFieldArray[4] == "DVD")//handles dvd { FormController.activateDVD(this); FormController.deactivateAllButDVD(this); txtDVDLeadActor.Text = productFieldArray[5]; txtDVDReleaseDate.Text = productFieldArray[6]; txtDVDRunTime.Text = productFieldArray[7]; } 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 FormController.disableTextBoxes(this);//make sure user cannot change info during delete MessageBox.Show("Are you sure you want to delete this product? Confirm delete action below."); btnDelete.Text = "Confirm Delete"; } else//confirm { //Product p = thisProductList.getAnItem(Convert.ToInt32(txtProductUPC.Text));// product to be deleted //thisProductList.removeAnItem(p); dbFunctions.Delete(Convert.ToInt32(txtProductUPC.Text)); btnDelete.Enabled = false; MessageBox.Show("Product Deleted"); } }//end of delete click method
}//end display CD Orchestra private void btnEdit_Click(object sender, EventArgs e) { bool OkayFlag; string productFields; btnFind.Enabled = false; btnDelete.Enabled = false; btnSaveEditUpdate.Enabled = false; dbFunctions.SelectProductFromProduct(Convert.ToInt32(txtProductUPC.Text), out OkayFlag, out productFields); //returns values to out parameters string[] productFieldArray = handleFieldOutput(productFields); //splits and trims productFields if (OkayFlag) //if a product was found { btnSaveEditUpdate.Enabled = true; btnEdit.Enabled = false; //setting textboxes to correct values in field array txtProductPrice.Text = productFieldArray[1]; txtProductUPC.Text = productFieldArray[0]; txtProductQuantity.Text = productFieldArray[3]; txtProductTitle.Text = productFieldArray[2]; MessageBox.Show("Edit/UPDATE current Product (as shown). Press Save Updates Button", "Edit/Update Notice", MessageBoxButtons.OK); if (productFieldArray[4] == "CDChamber")//handles cd Chamber { FormController.activateCDChamber(this); FormController.deactivateAllButCDChamber(this); FormController.deactivateAddButtons(this); txtCDClassicalLabel.Text = productFieldArray[5]; txtCDClassicalArtists.Text = productFieldArray[6]; txtCDChamberInstrumentList.Text = productFieldArray[7]; } else if (productFieldArray[4] == "CDOrchestra")//handles cd orchestra { FormController.activateCDOrchestra(this); FormController.deactivateAllButCDOrchestra(this); txtCDClassicalLabel.Text = productFieldArray[5]; txtCDClassicalArtists.Text = productFieldArray[6]; txtCDOrchestraConductor.Text = productFieldArray[7]; } else if (productFieldArray[4] == "Book")//handles book { FormController.activateBook(this); FormController.deactivateAllButBook(this); FormController.deactivateAddButtons(this); string leftISBN = ""; string rightISBN = ""; for (int j = 0; j < productFieldArray[5].Length; j++)//seperates ISBN for 2 seperate textboxes { if (leftISBN.Length != 3) { leftISBN += productFieldArray[5][j]; } else { rightISBN += productFieldArray[5][j]; } } txtBookISBNLeft.Text = leftISBN; txtBookISBNRight.Text = rightISBN; txtBookAuthor.Text = productFieldArray[6]; txtBookPages.Text = productFieldArray[7]; } else if (productFieldArray[4] == "BookCIS")//handles book cis { FormController.activateBookCIS(this); FormController.deactivateAllButBookCIS(this); string leftISBN = ""; string rightISBN = ""; for (int j = 0; j < productFieldArray[5].Length; j++)//seperates ISBN for 2 seperate textboxes { if (leftISBN.Length != 3) { leftISBN += productFieldArray[5][j]; } else { rightISBN += productFieldArray[5][j]; } } txtBookISBNLeft.Text = leftISBN; txtBookISBNRight.Text = rightISBN; txtBookAuthor.Text = productFieldArray[6]; txtBookPages.Text = productFieldArray[7]; txtBookCISCISArea.Text = productFieldArray[8]; } // end multiple alternative if else if (productFieldArray[4] == "DVD")//handles dvd { FormController.activateDVD(this); FormController.deactivateAllButDVD(this); txtDVDLeadActor.Text = productFieldArray[5]; txtDVDReleaseDate.Text = productFieldArray[6]; txtDVDRunTime.Text = productFieldArray[7]; } 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 } //end of edit on click method