}//end of display dvd void DisplayCDOrchestra() { btnCreateCDOrchestra.Enabled = true; btnCreateCDOrchestra.Text = "Save CD Orchestra"; 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 = true; txtCDChamberInstrumentList.Enabled = false; btnCreateBook.Enabled = false; btnCreateBookCIS.Enabled = false; btnCreateDVD.Enabled = false; btnCreateCDChamber.Enabled = false; FormController.activateCDOrchestra(this); FormController.deactivateBook(this); FormController.deactivateBookCIS(this); FormController.deactivateCDChamber(this); FormController.deactivateDVD(this); toolTip1.SetToolTip(btnCreateCDOrchestra, ttSaveCDOrchestra); txtProductUPC.Focus(); }//end display CD Orchestra
} // end deactivateAllButCDChamber // Deactivate all but CDChamber public static void deactivateAllButCDChamber(frmBookCDDVDShop f) { FormController.deactivateBook(f); FormController.deactivateBookCIS(f); FormController.deactivateCDOrchestra(f); FormController.deactivateDVD(f); FormController.deactivateAddButtons(f); } // end deactivateAllButCDOrchestra
//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); } }
private void btnCreateBookCIS_Click(object sender, EventArgs e) { txtBookISBNLeft.ReadOnly = false; txtBookISBNRight.ReadOnly = false; txtBookAuthor.ReadOnly = false; txtBookPages.ReadOnly = false; txtBookCISCISArea.ReadOnly = false; FormController.activateBookCIS(this); clickedBtn = "create_book_CIS"; btnSave.Enabled = true; }
private void btnCreateDVD_Click(object sender, EventArgs e) { txtDVDLeadActor.ReadOnly = false; txtDVDReleaseDate.ReadOnly = false; txtDVDRunTime.ReadOnly = false; FormController.activateDVD(this); btnCreateBook.Enabled = false; btnCreateBookCIS.Enabled = false; btnCreateCDChamber.Enabled = false; btnCreateCDOrchestra.Enabled = false; btnSave.Enabled = true; clickedBtn = "create_DVD"; }
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"; }
} // end Validate Product data //Create Buttons on Form Begin private void btnCreateBook_Click(object sender, EventArgs e) { txtBookISBNLeft.ReadOnly = false; txtBookISBNRight.ReadOnly = false; txtBookAuthor.ReadOnly = false; txtBookPages.ReadOnly = false; FormController.activateBook(this); FormController.activateProduct(this); btnCreateBookCIS.Enabled = true; btnCreateCDChamber.Enabled = false; btnCreateCDOrchestra.Enabled = false; btnCreateDVD.Enabled = false; btnSave.Enabled = true; clickedBtn = "create_book"; }
//*****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
} //end of edit on click method private void btnEnterUPC_Click(object sender, EventArgs e) { if (btnEnterUPC.Text == "Click HERE to enter a UPC") { FormController.deactivateAddButtons(this); //add buttons cannot be clicked txtProductUPC.Enabled = true; //lets user add a upc MessageBox.Show("Enter the desired product UPC above. Then click 'Check for Product' to continue."); btnEnterUPC.Text = "Check for Product"; } else { if (Validators.ValidateProductUPC(txtProductUPC.Text))//validates product upc { bool OkayFlag; string productFields; dbFunctions.SelectProductFromProduct(Convert.ToInt32(txtProductUPC.Text), out OkayFlag, out productFields);//returns out variable values //if (thisProductList.checkForDuplicate(Convert.ToInt32(txtProductUPC.Text)))//checks product list for same value if (OkayFlag)//will be true if product is found in database { MessageBox.Show("Match Found!"); btnEnterUPC.Enabled = false; btnEdit.Enabled = true;//allows for display/edit/delete options btnDelete.Enabled = true; btnFind.Enabled = true; txtProductUPC.Enabled = false;//cannot change the UPC } else//OKFlag = false { MessageBox.Show("Match Not Found"); } } } }//end of UPC enter on click method
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
//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 }
//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 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
} // 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:"); } }
//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 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 }