public void DeleteMethodOK()
        {
            //create an instance of the class
            clsProductsCollection AllProducts = new clsProductsCollection();
            //create the item of test data
            clsProducts TestItem = new clsProducts();
            //var to store the primary key
            Int32 PrimaryKey = 0;

            //set its properties
            TestItem.ProductID   = 1;
            TestItem.ProductName = "Pokemon";
            TestItem.Price       = 15.00;
            TestItem.Quantity    = 14;
            //set ThisProduct to test data
            AllProducts.ThisProduct = TestItem;
            //add the record
            PrimaryKey = AllProducts.Add();
            //set the primary key of the test data
            TestItem.ProductID = PrimaryKey;
            //find the record
            AllProducts.ThisProduct.Find(PrimaryKey);
            //delete the record
            AllProducts.Delete();
            //noe find the record
            Boolean Found = AllProducts.ThisProduct.Find(PrimaryKey);

            //test to see that the value was not found
            Assert.IsFalse(Found);
        }
예제 #2
0
    void Update()
    {
        //create an instance of product book
        clsProductsCollection ProductBook = new clsProductsCollection();
        //validate the data on the web form
        String Error = ProductBook.ThisProduct.Valid(txtProductID.Text, txtProductName.Text, txtPrice.Text, txtQuantity.Text);

        //if the data is OK then add it to the object
        if (Error == "")
        {
            //get the data entered by user
            ProductBook.ThisProduct.ProductID   = Convert.ToInt32(txtProductID.Text);
            ProductBook.ThisProduct.ProductName = txtProductName.Text;
            ProductBook.ThisProduct.Price       = Convert.ToDouble(txtPrice.Text);
            ProductBook.ThisProduct.Quantity    = Convert.ToInt32(txtQuantity.Text);
            //update the record
            ProductBook.Update();
            //redirec to default page
            Response.Redirect("Default.aspx");
        }
        else
        {
            //report an error
            lblError.Text = "There were problems with the data entered " + Error;
        }
    }
        public void InstanceOK()
        {
            //create an instance of the class
            clsProductsCollection AllProducts = new clsProductsCollection();

            //test to see that it exists
            Assert.IsNotNull(AllProducts);
        }
예제 #4
0
    void DisplayProducts()
    {
        //create an instance of product book
        clsProductsCollection ProductBook = new clsProductsCollection();

        //find the record to update
        ProductBook.ThisProduct.Find(ProductID);
        //display the data for this record
        txtProductID.Text   = ProductBook.ThisProduct.ProductID.ToString();
        txtProductName.Text = ProductBook.ThisProduct.ProductName;
        txtPrice.Text       = ProductBook.ThisProduct.Price.ToString();
        txtQuantity.Text    = ProductBook.ThisProduct.Quantity.ToString();
    }
예제 #5
0
    Int32 DisplayFilteredProducts(string ProductNameFilter)
    {
        //create instance of products collection
        clsProductsCollection Products = new clsProductsCollection();
        //store records count
        Int32 RecordCount;
        //variables
        string ProductID;
        string ProductName;
        string Price;
        string Quantity;
        Int32  Index = 0;

        //clear list
        lstProducts.Items.Clear();
        //call the filter
        Products.ReportByProductName(ProductNameFilter);
        //count records found
        RecordCount = Products.Count;
        // loop each record
        while (Index < RecordCount)
        {
            //get the product id from the query results
            ProductID = Convert.ToString(Products.ProductsList[Index].ProductID);
            //get the product name from the query results
            ProductName = Convert.ToString(Products.ProductsList[Index].ProductName);
            //get the price from the query results
            Price = Convert.ToString(Products.ProductsList[Index].Price);
            //get the quantity from the query results
            Quantity = Convert.ToString(Products.ProductsList[Index].Quantity);
            //set up a new object of class list item
            ListItem NewItem = new ListItem("Name:" + ProductName + " " + "Price:" + Price + " " + "Quantity:" + Quantity, ProductID);
            //add the new item to the list
            lstProducts.Items.Add(NewItem);
            //increment the index
            Index++;
        }
        //return the number of records found
        return(RecordCount);
    }