//Deletes an item private void btnDelete_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Are you sure you want to delete this item?", "Confirm", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { dbFunctions.Delete(Convert.ToInt32(txtProductUPC.Text)); recordsProcessedCount++; FormController.clear(this); } }
//*****This section has the forms load and closing events // This sub is called when the form is loaded private void frmBookCDDVDShop_Load(System.Object sender, System.EventArgs e) { // Read serialized binary data file SFManager.readFromFile(ref thisProductList, FileName); FormController.clear(this); // Set initial Tooltips toolTip1.SetToolTip(btnCreateBookCIS, ttCreateBookCIS); toolTip1.SetToolTip(btnCreateBook, ttCreateBook); toolTip1.SetToolTip(btnCreateCDChamber, ttCreateCDOrchestra); toolTip1.SetToolTip(btnCreateCDOrchestra, ttCreateDVD); toolTip1.SetToolTip(btnCreateDVD, ttCreateCDChamber); toolTip1.SetToolTip(btnClear, ttClear); toolTip1.SetToolTip(btnDelete, ttDelete); toolTip1.SetToolTip(btnEdit, ttEdit); toolTip1.SetToolTip(btnFind, ttFind); toolTip1.SetToolTip(btnExit, ttExit); toolTip1.SetToolTip(txtProductUPC, ttProductUPC); toolTip1.SetToolTip(txtProductPrice, ttProductPrice); toolTip1.SetToolTip(txtProductQuantity, ttProductQuantity); toolTip1.SetToolTip(txtProductTitle, ttProductTitle); toolTip1.SetToolTip(txtCDOrchestraConductor, ttCDOrchestraConductor); toolTip1.SetToolTip(txtBookISBNLeft, ttBookISBN); toolTip1.SetToolTip(txtBookAuthor, ttBookAuthor); toolTip1.SetToolTip(txtBookPages, ttBookPages); toolTip1.SetToolTip(txtDVDLeadActor, ttDVDLeadActor); toolTip1.SetToolTip(txtDVDReleaseDate, ttDVDReleaseDate); toolTip1.SetToolTip(txtDVDRunTime, ttDVDRunTime); toolTip1.SetToolTip(txtCDClassicalLabel, ttCDClassicalLabel); toolTip1.SetToolTip(txtCDClassicalArtists, ttCDClassicalArtists); toolTip1.SetToolTip(txtCDOrchestraConductor, ttCDOrchestraConductor); toolTip1.SetToolTip(txtCDChamberInstrumentList, ttCDChamberInstrumentList); toolTip1.SetToolTip(txtBookCISCISArea, ttBookCISCISArea); toolTip1.SetToolTip(btnCreateBookCIS, ttCreateBookCIS); } // end frmEBookCDDVDShop_Load
//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"); } } } } }
//Create Buttons on Form End //Clear all text boxes private void btnClear_Click(object sender, EventArgs e) { FormController.clear(this); }
} // end frmEBookCDDVDShop_Load // Clear textboxes private void btnClear_Click(System.Object sender, System.EventArgs e) { FormController.clear(this); } // end btnClear_Click
}//end of create chamber on click method private void btnResetForm_Click(object sender, EventArgs e) { FormController.clear(this); //clears form btnEnterUPC.Text = "Click HERE to enter a UPC"; //not covered in clear method btnDelete.Text = "Delete"; //not covered in clear method }