}//end of create book button click method private void btnCreateBookCIS_Click(object sender, EventArgs e) { if (btnCreateBookCIS.Text == "Create Book CIS") { DisplayBookCISForm(); //shows proper textboxes for bookCIS btnEnterUPC.Enabled = false; //cannot try another action while adding } else { MessageBox.Show("Saving"); if (Validators.ValidateBookCIS(txtProductUPC.Text, txtProductPrice.Text, txtProductTitle.Text, txtProductQuantity.Text, txtBookISBNLeft.Text, txtBookISBNRight.Text, txtBookAuthor.Text, txtBookPages.Text, txtBookCISCISArea.Text))//validating bookCIS { MessageBox.Show("Passed CIS Book Test"); BookCIS x = new BookCIS(); x.Save(this);//x now has all values in textboxes MessageBox.Show(x.ToString()); thisProductList.addAnItem(x); dbFunctions.InsertProduct(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), "BookCIS"); //add to product table string ISBN = txtBookISBNLeft.Text + txtBookISBNRight.Text; //makes one isbn dbFunctions.InsertBook(Convert.ToInt32(txtProductUPC.Text), Convert.ToInt32(ISBN), txtBookAuthor.Text, Convert.ToInt32(txtBookPages.Text)); //adds to book table dbFunctions.InsertBookCIS(Convert.ToInt32(txtProductUPC.Text), txtBookCISCISArea.Text); //adds to bookCIS table btnCreateBookCIS.Enabled = false; //cannot accidently add a book twice } } }//end of create book cis click method
//this is what happens when we try to save an object //validate text box attributes then insert into the database based on type (which parts of form are enabled) private void BtnSave_Click(object sender, EventArgs e) { //first check that all product attrs have the correct formats bool correct = Validator.validateUPC(txtProductUPC.Text) && Validator.validatePrice(txtProductPrice.Text) && Validator.validateTitle(txtProductTitle.Text) && Validator.validateIntNumber(txtProductQuantity.Text); if (correct) //next check each if the upc entered is not already taken (unique) { bool j; string pstring; OleDbDataReader odb = pdb.SelectProductFromProduct(Convert.ToInt32(txtProductUPC.Text), out j, out pstring); if (!j) //not found == means unique == ok to continue { //check each product types' specific attr formats depending on the product type //create the product if format is ok and add it to the database if (i == 1) { // validation is correct the the boolean would be true and would add to the datatbase bool temp = Validator.validateName(txtBookAuthor.Text) && Validator.validateISBN(txtBookISBNLeft.Text) && Validator.validateISBN(txtBookISBNRight.Text) && Validator.validateIntNumber(txtBookPages.Text); if (temp) { Book book = new Book(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), txtBookISBNLeft.Text, txtBookISBNRight.Text, txtBookAuthor.Text, Convert.ToInt32(txtBookPages.Text)); //productList.add(book); MessageBox.Show("Book Added to Library"); // Using Frank's method in PrductDB to add to the library pdb.InsertProduct(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), "Book"); pdb.InsertBook(Convert.ToInt32(txtProductUPC.Text), Convert.ToInt32(txtBookISBNLeft.Text + txtBookISBNRight.Text), txtBookAuthor.Text, Convert.ToInt32(txtBookPages.Text)); FormController.resetForm(this); } else { MessageBox.Show("Please check input in Book Fields"); } } else if (i == 2) { bool temp = Validator.validateName(txtBookAuthor.Text) && Validator.validateISBN(txtBookISBNLeft.Text) && Validator.validateISBN(txtBookISBNRight.Text) && Validator.validateIntNumber(txtBookPages.Text) && (txtBookCISCISArea.Text != ""); if (temp) { BookCIS book = new BookCIS(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), txtBookISBNLeft.Text, txtBookISBNRight.Text, txtBookAuthor.Text, Convert.ToInt32(txtBookPages.Text), txtBookCISCISArea.Text); // productList.add(book); MessageBox.Show("Book Added to Library"); pdb.InsertProduct(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), "BookCIS"); pdb.InsertBook(Convert.ToInt32(txtProductUPC.Text), Convert.ToInt32(txtBookISBNLeft.Text + txtBookISBNRight.Text), txtBookAuthor.Text, Convert.ToInt32(txtBookPages.Text)); pdb.InsertBookCIS(Convert.ToInt32(txtProductUPC.Text), txtBookCISCISArea.Text); FormController.resetForm(this); } else { MessageBox.Show("Please check input in Book Fields"); } } else if (i == 3) { bool temp = Validator.validateName(txtDVDLeadActor.Text) && Validator.validateRunTime(txtDVDRunTime.Text) && Validator.validateReleaseDate(txtDVDReleaseDate.Value); if (temp) { DVD dvd = new DVD(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), txtDVDLeadActor.Text, txtDVDReleaseDate.Value, Convert.ToInt32(txtDVDRunTime.Text)); // productList.add(dvd); MessageBox.Show("DVD Added to Library"); pdb.InsertProduct(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), "DVD"); pdb.InsertDVD(Convert.ToInt32(txtProductUPC.Text), txtDVDLeadActor.Text, txtDVDReleaseDate.Value, Convert.ToInt32(txtDVDRunTime.Text)); FormController.resetForm(this); } else { MessageBox.Show("Please check input in DVD Fields"); } } else if (i == 4) { bool temp = Validator.validateName(txtCDClassicalLabel.Text) && Validator.validateArtists(txtCDClassicalArtists.Text) && Validator.validateName(txtCDOrchestraConductor.Text); if (temp) { CDOrchestra cd = new CDOrchestra(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), txtCDClassicalLabel.Text, txtCDClassicalArtists.Text, txtCDOrchestraConductor.Text); // productList.add(cd); MessageBox.Show("CD Added to Library"); pdb.InsertProduct(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), "CDOrchestra"); pdb.InsertCDClassical(Convert.ToInt32(txtProductUPC.Text), txtCDClassicalLabel.Text, txtCDClassicalArtists.Text); pdb.InsertCDOrchestra(Convert.ToInt32(txtProductUPC.Text), txtCDOrchestraConductor.Text); FormController.resetForm(this); } else { MessageBox.Show("Please check input in CD Fields"); } } else if (i == 5) { bool temp = Validator.validateName(txtCDClassicalLabel.Text) && Validator.validateArtists(txtCDClassicalArtists.Text) && Validator.validateInstruments(txtCDChamberInstrumentList.Text); if (temp) { CDChamber cd = new CDChamber(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), txtCDClassicalLabel.Text, txtCDClassicalArtists.Text, txtCDChamberInstrumentList.Text); //productList.add(cd); MessageBox.Show("CD Added to Library"); pdb.InsertProduct(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), "CDChamber"); pdb.InsertCDClassical(Convert.ToInt32(txtProductUPC.Text), txtCDClassicalLabel.Text, txtCDClassicalArtists.Text); pdb.InsertCDChamber(Convert.ToInt32(txtProductUPC.Text), txtCDChamberInstrumentList.Text); FormController.resetForm(this); } else { MessageBox.Show("Please check input in CD Fields"); } } } else //not unique { MessageBox.Show("Product with same UPC already exists"); } } else //incorrect format used in general product fields { MessageBox.Show("Please check input in Prodcut Fields"); } }
//this is what happens when you click search //use output of productdb query to build an object to then display its attributes on the form private void BtnSearchUPC_Click(object sender, EventArgs e) { bool temp = Validator.validateUPC(txtProductUPCSearch.Text); //first make sure the format is correct if (temp) { bool j; // boolean object reference for return string pstring; // Product string updated upon product DB search call. //p = productList.find(Convert.ToInt32(txtProductUPCSearch.Text)); //search our list for this upc Product k; //used to create an object after learning which type we have //get table from database to read row attributes for our product OleDbDataReader odb = pdb.SelectProductFromProduct(Convert.ToInt32(txtProductUPCSearch.Text), out j, out pstring); //MessageBox.Show(pstring); if (!j) //not found { MessageBox.Show("Product not found"); txtProductUPCSearch.Clear(); txtProductUPCSearch.Focus(); } // Creates a ne product to dislay in form. else { string[] attributes = pstring.Split('\n'); // splits product attributes into array for (int i = 0; i < attributes.Length; i++) { attributes[i] = attributes[i].Trim('\r'); } string ptype = attributes[4]; // gets the product type from this attribute and then creates new product to display in form if (ptype == "Book") { string left = attributes[5].Substring(0, 3); string right = attributes[5].Substring(3); k = new Book(Convert.ToInt32(attributes[0]), Convert.ToDecimal(attributes[1]), attributes[2], Convert.ToInt32(attributes[3]), left, right, attributes[6], Convert.ToInt32(attributes[7])); k.Display(this); FormController.searchForm(this); txtProductUPCSearch.Clear(); } else if (ptype == "BookCIS") { string left = attributes[5].Substring(0, 3); string right = attributes[5].Substring(3); k = new BookCIS(Convert.ToInt32(attributes[0]), Convert.ToDecimal(attributes[1]), attributes[2], Convert.ToInt32(attributes[3]), left, right, attributes[6], Convert.ToInt32(attributes[7]), attributes[8]); k.Display(this); FormController.searchForm(this); txtProductUPCSearch.Clear(); } else if (ptype == "DVD") { k = 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])); k.Display(this); FormController.searchForm(this); txtProductUPCSearch.Clear(); } else if (ptype == "CDOrchestra") { k = new CDOrchestra(Convert.ToInt32(attributes[0]), Convert.ToDecimal(attributes[1]), attributes[2], Convert.ToInt32(attributes[3]), attributes[5], attributes[6], attributes[7]); k.Display(this); FormController.searchForm(this); txtProductUPCSearch.Clear(); } else if (ptype == "CDChamber") { k = new CDChamber(Convert.ToInt32(attributes[0]), Convert.ToDecimal(attributes[1]), attributes[2], Convert.ToInt32(attributes[3]), attributes[5], attributes[6], attributes[7]); k.Display(this); FormController.searchForm(this); txtProductUPCSearch.Clear(); } } } else //user needs to fix format { MessageBox.Show("Invalid UPC format"); txtProductUPCSearch.Clear(); txtProductUPCSearch.Focus(); } }
//Saves item to database private void btnSave_Click(object sender, EventArgs e) { bool productValidated; productValidated = Validation.validateProductUPC(txtProductUPC.Text) && Validation.validateProductPrice(txtProductPrice.Text) && Validation.validateAnything(txtProductTitle.Text) && Validation.validatePositiveInteger(txtProductQuantity.Text); if (productValidated == false) { MessageBox.Show("You have errors with your product information! Please check the product information and try again.", "Product Input Error"); } else { bool found; // boolean reference for search success string pstring; // Product string updated upon product DB search call. //Product prod; OleDbDataReader odb = dbFunctions.SelectProductFromProduct(Convert.ToInt32(txtProductUPC.Text), out found, out pstring); if (!found) { //works if (clickedBtn == "create_book") { bool bookValidated; bookValidated = Validation.validateBookISBN(txtBookISBNLeft.Text) && Validation.validateBookISBN(txtBookISBNRight.Text) && Validation.validatePersonName(txtBookAuthor.Text) && Validation.validatePositiveInteger(txtBookPages.Text); if (bookValidated == true) { Book saveBook = new Book(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), Convert.ToInt32(txtBookISBNLeft.Text), Convert.ToInt32(txtBookISBNRight.Text), txtBookAuthor.Text, Convert.ToInt32(txtBookPages.Text)); dbFunctions.InsertProduct(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), "Book"); dbFunctions.InsertBook(Convert.ToInt32(txtProductUPC.Text), Convert.ToInt32(txtBookISBNLeft.Text + txtBookISBNRight.Text), txtBookAuthor.Text, Convert.ToInt32(txtBookPages.Text)); MessageBox.Show("Book successfully inserted into database!", "Success"); recordsProcessedCount++; FormController.clear(this); } else { MessageBox.Show("There was a problem inserting the book into the file. Check the entered information and try again!", "Error"); } } //works else if (clickedBtn == "create_book_CIS") { bool bookCISValidated; bookCISValidated = Validation.validateBookISBN(txtBookISBNLeft.Text) && Validation.validateBookISBN(txtBookISBNRight.Text) && Validation.validatePersonName(txtBookAuthor.Text) && Validation.validatePositiveInteger(txtBookPages.Text) && Validation.validateAnything(txtBookCISCISArea.Text); if (bookCISValidated == true) { BookCIS saveCISBook = new BookCIS(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), Convert.ToInt32(txtBookISBNLeft.Text), Convert.ToInt32(txtBookISBNRight.Text), txtBookAuthor.Text, Convert.ToInt32(txtBookPages.Text), txtBookCISCISArea.Text); dbFunctions.InsertProduct(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), "BookCIS"); dbFunctions.InsertBook(Convert.ToInt32(txtProductUPC.Text), Convert.ToInt32(txtBookISBNLeft.Text + txtBookISBNRight.Text), txtBookAuthor.Text, Convert.ToInt32(txtBookPages.Text)); dbFunctions.InsertBookCIS(Convert.ToInt32(txtProductUPC.Text), txtBookCISCISArea.Text); MessageBox.Show("Book successfully inserted into database!", "Success"); recordsProcessedCount++; FormController.clear(this); } else { MessageBox.Show("There was a problem inserting the book into the file. Check the entered information and try again!", "Error"); } } //works else if (clickedBtn == "create_DVD") { bool dvdValidated; dvdValidated = Validation.validatePersonName(txtDVDLeadActor.Text) && Validation.validateDate(Convert.ToDateTime(txtDVDReleaseDate.Text)) && Validation.validatePositiveInteger(txtDVDRunTime.Text); if (dvdValidated == true) { DVD saveDVD = new DVD(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), txtDVDLeadActor.Text, Convert.ToDateTime(txtDVDReleaseDate.Text), Convert.ToInt32(txtDVDRunTime.Text)); dbFunctions.InsertProduct(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), "DVD"); dbFunctions.InsertDVD(Convert.ToInt32(txtProductUPC.Text), txtDVDLeadActor.Text, Convert.ToDateTime(txtDVDReleaseDate.Text), Convert.ToInt32(txtDVDRunTime.Text)); MessageBox.Show("DVD successfully inserted into database!", "Success"); recordsProcessedCount++; FormController.clear(this); } else { MessageBox.Show("There was a problem inserting the DVD into the file. Check the entered information and try again!", "Error"); } } //works else if (clickedBtn == "create_CD_chamber") { bool chamberValidated; chamberValidated = Validation.validateAnything(txtCDClassicalLabel.Text) && Validation.validatePersonName(txtCDClassicalArtists.Text) && Validation.validateAnything(txtCDChamberInstrumentList.Text); if (chamberValidated == true) { dbFunctions.InsertProduct(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), "CDChamber"); dbFunctions.InsertCDClassical(Convert.ToInt32(txtProductUPC.Text), txtCDClassicalLabel.Text, txtCDClassicalArtists.Text); dbFunctions.InsertCDChamber(Convert.ToInt32(txtProductUPC.Text), txtCDChamberInstrumentList.Text); MessageBox.Show("Chamber CD successfully inserted into database!", "Success"); recordsProcessedCount++; FormController.clear(this); } else { MessageBox.Show("There was a problem inserting the chamber CD into the file. Check the entered information and try again!", "Error"); } } //works else if (clickedBtn == "create_CD_orchestra") { bool orchestraValidated; orchestraValidated = Validation.validateAnything(txtCDClassicalLabel.Text) && Validation.validatePersonName(txtCDClassicalArtists.Text) && Validation.validatePersonName(txtCDOrchestraConductor.Text); if (orchestraValidated == true) { dbFunctions.InsertProduct(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), "CDOrchestra"); dbFunctions.InsertCDClassical(Convert.ToInt32(txtProductUPC.Text), txtCDClassicalLabel.Text, txtCDClassicalArtists.Text); dbFunctions.InsertCDOrchestra(Convert.ToInt32(txtProductUPC.Text), txtCDOrchestraConductor.Text); MessageBox.Show("Orchestra CD successfully inserted into database!", "Success"); recordsProcessedCount++; FormController.clear(this); } else { MessageBox.Show("There was a problem inserting the orchestra CD into the file. Check the entered information and try again!", "Error"); } } } //his is for updating else { 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 //Works if (ptype == "Book") { bool bookValidated; bookValidated = Validation.validateBookISBN(txtBookISBNLeft.Text) && Validation.validateBookISBN(txtBookISBNRight.Text) && Validation.validatePersonName(txtBookAuthor.Text) && Validation.validatePositiveInteger(txtBookPages.Text); if (bookValidated == true) { Book saveBook = new Book(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), Convert.ToInt32(txtBookISBNLeft.Text), Convert.ToInt32(txtBookISBNRight.Text), txtBookAuthor.Text, Convert.ToInt32(txtBookPages.Text)); dbFunctions.UpdateProduct(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text)); dbFunctions.UpdateBook(Convert.ToInt32(txtProductUPC.Text), Convert.ToInt32(txtBookISBNLeft.Text + txtBookISBNRight.Text), txtBookAuthor.Text, Convert.ToInt32(txtBookPages.Text)); MessageBox.Show("Book successfully updated to database!", "Success"); FormController.clear(this); } else { MessageBox.Show("There was a problem inserting the book into the file. Check the entered information and try again!", "Error"); } } //Works if (ptype == "BookCIS") { bool bookCISValidated; bookCISValidated = Validation.validateBookISBN(txtBookISBNLeft.Text) && Validation.validateBookISBN(txtBookISBNRight.Text) && Validation.validateAnything(txtBookAuthor.Text) && Validation.validatePositiveInteger(txtBookPages.Text) && Validation.validateAnything(txtBookCISCISArea.Text); if (bookCISValidated == true) { BookCIS saveCISBook = new BookCIS(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), Convert.ToInt32(txtBookISBNLeft.Text), Convert.ToInt32(txtBookISBNRight.Text), txtBookAuthor.Text, Convert.ToInt32(txtBookPages.Text), txtBookCISCISArea.Text); dbFunctions.UpdateProduct(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text)); dbFunctions.UpdateBook(Convert.ToInt32(txtProductUPC.Text), Convert.ToInt32(txtBookISBNLeft.Text + txtBookISBNRight.Text), txtBookAuthor.Text, Convert.ToInt32(txtBookPages.Text)); dbFunctions.UpdateBookCIS(Convert.ToInt32(txtProductUPC.Text), txtBookCISCISArea.Text); MessageBox.Show("BookCIS successfully updated to database!", "Success"); FormController.clear(this); } else { MessageBox.Show("There was a problem inserting the book into the file. Check the entered information and try again!", "Error"); } } if (ptype == "DVD") { bool dvdValidated; dvdValidated = Validation.validatePersonName(txtDVDLeadActor.Text) && Validation.validateDate(Convert.ToDateTime(txtDVDReleaseDate.Text)) && Validation.validatePositiveInteger(txtDVDRunTime.Text); if (dvdValidated == true) { DVD saveDVD = new DVD(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text), txtDVDLeadActor.Text, Convert.ToDateTime(txtDVDReleaseDate.Text), Convert.ToInt32(txtDVDRunTime.Text)); dbFunctions.UpdateProduct(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text)); dbFunctions.UpdateDVD(Convert.ToInt32(txtProductUPC.Text), txtDVDLeadActor.Text, Convert.ToDateTime(txtDVDReleaseDate.Text), Convert.ToInt32(txtDVDRunTime.Text)); MessageBox.Show("DVD successfully updated to database!", "Success"); FormController.clear(this); } else { MessageBox.Show("There was a problem inserting the DVD into the file. Check the entered information and try again!", "Error"); } } if (ptype == "CDOrchestra") { bool orchestraValidated; orchestraValidated = Validation.validateAnything(txtCDClassicalLabel.Text) && Validation.validatePersonName(txtCDClassicalArtists.Text) && Validation.validatePersonName(txtCDOrchestraConductor.Text); if (orchestraValidated == true) { dbFunctions.UpdateProduct(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text)); dbFunctions.UpdateCDClassical(Convert.ToInt32(txtProductUPC.Text), txtCDClassicalLabel.Text, txtCDClassicalArtists.Text); dbFunctions.UpdateCDOrchestra(Convert.ToInt32(txtProductUPC.Text), txtCDOrchestraConductor.Text); MessageBox.Show("CDOrchestra successfully updated to database!", "Success"); FormController.clear(this); } else { MessageBox.Show("There was a problem inserting the orchestra CD into the file. Check the entered information and try again!", "Error"); } } if (ptype == "CDChamber") { bool chamberValidated; chamberValidated = Validation.validateAnything(txtCDClassicalLabel.Text) && Validation.validateAnything(txtCDClassicalArtists.Text) && Validation.validateAnything(txtCDChamberInstrumentList.Text); if (chamberValidated == true) { dbFunctions.UpdateProduct(Convert.ToInt32(txtProductUPC.Text), Convert.ToDecimal(txtProductPrice.Text), txtProductTitle.Text, Convert.ToInt32(txtProductQuantity.Text)); dbFunctions.UpdateCDClassical(Convert.ToInt32(txtProductUPC.Text), txtCDClassicalLabel.Text, txtCDClassicalArtists.Text); dbFunctions.UpdateCDChamber(Convert.ToInt32(txtProductUPC.Text), txtCDChamberInstrumentList.Text); MessageBox.Show("CDChamber successfully updated to database!", "Success"); FormController.clear(this); } else { MessageBox.Show("There was a problem inserting the chamber CD into the file. Check the entered information and try again!", "Error"); } } } } }
} // 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:"); } }