Ejemplo n.º 1
0
        //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();
            }
        }
Ejemplo n.º 2
0
        }     // 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:");
            }
        }