Esempio n. 1
0
 // move the product to another category
 protected void moveButton_Click(object sender, EventArgs e)
 {
     // Check if a category was selected
     if (categoriesListMove.SelectedIndex != -1)
     {
         // Get the category ID that was selected in the DropDownList
         string newCategoryId = categoriesListMove.SelectedItem.Value;
         // Move the product to the category
         bool success = CatalogBLO.MoveProductToCategory(currentProductId, currentCategoryId, newCategoryId);
         // In case the operation was successful, reload the page,
         // so the new category will reflect in the query string
         if (!success)
         {
             statusLabel.Text = "Couldn't move the product to the specified category";
         }
         else
         {
             Response.Redirect(Request.ApplicationPath + "/CatalogAdmin.aspx" +
                               "?DepartmentID=" + currentDepartmentId +
                               "&CategoryID=" + newCategoryId +
                               "&ProductID=" + currentProductId);
         }
     }
     else
     {
         statusLabel.Text = "You need to select a category";
     }
 }
 // Populate the GridView with data
 private void BindGrid()
 {
     // Get a DataTable object containing the catalog departments
     grid.DataSource = CatalogBLO.GetDepartments();
     // Bind the data bound controls to the data source
     grid.DataBind();
 }
Esempio n. 3
0
 // upload product's second image
 protected void upload2Button_Click(object sender, EventArgs e)
 {
     // proceed with uploading only if the user selected a file
     if (image2FileUpload.HasFile)
     {
         try
         {
             string fileName = image2FileUpload.FileName;
             string location = Server.MapPath("./ProductImages/") + fileName;
             // save image to server
             image2FileUpload.SaveAs(location);
             // update database with new product details
             ProductDetails pd = CatalogBLO.GetProductDetails(currentProductId);
             CatalogBLO.UpdateProduct(currentProductId, pd.Name, pd.Description, pd.Price.ToString(), pd.Image1FileName, fileName, pd.OnDepartmentPromotion.ToString(), pd.OnCatalogPromotion.ToString());
             // reload the page
             Response.Redirect(Request.ApplicationPath + "/CatalogAdmin.aspx" +
                               "?DepartmentID=" + currentDepartmentId +
                               "&CategoryID=" + currentCategoryId +
                               "&ProductID=" + currentProductId);
         }
         catch
         {
             statusLabel.Text = "Uploading image 2 failed";
         }
     }
 }
Esempio n. 4
0
    // Fill the page with data
    private void PopulateControls()
    {
        // Retrieve DepartmentID from the query string
        string departmentId = Request.QueryString["DepartmentID"];
        // Retrieve CategoryID from the query string
        string categoryId = Request.QueryString["CategoryID"];

        // If browsing a category...
        if (categoryId != null)
        {
            // Retrieve category details and display them
            CategoryDetails cd = CatalogBLO.GetCategoryDetails(categoryId);
            catalogTitleLabel.Text       = cd.Name;
            catalogDescriptionLabel.Text = cd.Description;
            // Set the title of the page
            this.Title = ShopConfiguration.SiteName +
                         " : Category : " + cd.Name;
        }
        // If browsing a department...
        else if (departmentId != null)
        {
            // Retrieve department details and display them
            DepartmentDetails dd = CatalogBLO.GetDepartmentDetails(departmentId);
            catalogTitleLabel.Text       = dd.Name;
            catalogDescriptionLabel.Text = dd.Description;
            // Set the title of the page
            this.Title = ShopConfiguration.SiteName +
                         " : Department : " + dd.Name;
        }
    }
Esempio n. 5
0
 // delete a product from the catalog
 protected void deleteButton_Click(object sender, EventArgs e)
 {
     // Delete the product from the catalog
     CatalogBLO.DeleteProduct(currentProductId);
     // Need to go back to the categories page now
     Response.Redirect(Request.ApplicationPath + "/CatalogAdmin.aspx" +
                       "?DepartmentID=" + currentDepartmentId +
                       "&CategoryID=" + currentCategoryId);
 }
    // Create a new department
    protected void createDepartment_Click(object sender, EventArgs e)
    {
        // Execute the insert command
        bool success = CatalogBLO.AddDepartment(newName.Text, newDescription.Text);

        // Display status message
        statusLabel.Text = success ? "Insert successful" : "Insert failed";
        // Reload the grid
        BindGrid();
    }
    // Populate the GridView with data
    private void BindGrid()
    {
        // Get DepartmentID from the query string
        string departmentId = Request.QueryString["DepartmentID"];

        // Get a DataTable object containing the categories
        grid.DataSource = CatalogBLO.GetCategoriesInDepartment(departmentId);
        // Bind the data grid to the data source
        grid.DataBind();
    }
Esempio n. 8
0
    // Populate the GridView with data
    private void BindGrid()
    {
        // Get CategoryID from the query string
        string categoryId = Request.QueryString["CategoryID"];

        // Get a DataTable object containing the products
        grid.DataSource = CatalogBLO.GetAllProductsInCategory(categoryId);
        // Needed to bind the data bound controls to the data source
        grid.DataBind();
    }
Esempio n. 9
0
    // Create a new product
    protected void createProduct_Click(object sender, EventArgs e)
    {
        // Get CategoryID from the query string
        string categoryId = Request.QueryString["CategoryID"];
        // Execute the insert command
        bool success = CatalogBLO.CreateProduct(categoryId, newName.Text, newDescription.Text, newPrice.Text, newImage1FileName.Text, newImage2FileName.Text, newOnDepartmentPromotion.Checked.ToString(), newOnCatalogPromotion.Checked.ToString());

        // Display status message
        statusLabel.Text = success ? "Insert successful" : "Insert failed";
        // Reload the grid
        BindGrid();
    }
Esempio n. 10
0
 // Load department details into the DataList
 protected void Page_Load(object sender, EventArgs e)
 {
     // don't reload data during postbacks
     if (!IsPostBack)
     {
         // CatalogAccess.GetDepartments returns a DataTable object containing
         // department data, which is read in the ItemTemplate of the DataList
         list.DataSource = CatalogBLO.GetDepartments();
         // Needed to bind the data bound controls to the data source
         list.DataBind();
     }
 }
    // Create a new category
    protected void createCategory_Click(object sender, EventArgs e)
    {
        // Get DepartmentID from the query string
        string departmentId = Request.QueryString["DepartmentID"];
        // Execute the insert command
        bool success = CatalogBLO.CreateCategory(departmentId, newName.Text, newDescription.Text);

        // Display results
        statusLabel.Text = success ? "Insert successful" : "Insert failed";
        // Reload the grid
        BindGrid();
    }
    // Delete a record
    protected void grid_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        // Get the ID of the record to be deleted
        string id = grid.DataKeys[e.RowIndex].Value.ToString();
        // Execute the delete command
        bool success = CatalogBLO.DeleteCategory(id);

        // Cancel edit mode
        grid.EditIndex = -1;
        // Display status message
        statusLabel.Text = success ? "Delete successful" : "Delete failed";
        // Reload the grid
        BindGrid();
    }
Esempio n. 13
0
    protected void Page_PreRender(object sender, EventArgs e)
    {
        // Get the currently loaded page
        string currentLocation = Request.AppRelativeCurrentExecutionFilePath;

        // If we're in Product.aspx...
        if (currentLocation == "~/Product.aspx")
        {
            // get the product ID
            string productId = Request.QueryString["ProductID"];
            // get product recommendations
            DataTable table;
            // display recommendations
            table           = CatalogBLO.GetRecommendations(productId);
            list.DataSource = table;
            list.DataBind();
            // display header
            if (table.Rows.Count > 0)
            {
                recommendationsHeader.Text =
                    "Customers who bought this product also bought:";
            }
            else
            {
                recommendationsHeader.Text = "";
            }
        }
        // If we're in ShoppingCart.aspx...
        else if (currentLocation == "~/ShoppingCart.aspx")
        {
            // get product recommendations
            DataTable table;
            // display recommendations
            table           = ShoppingCartBLO.GetRecommendations();
            list.DataSource = table;
            list.DataBind();
            // display header
            if (table.Rows.Count > 0)
            {
                recommendationsHeader.Text =
                    "Customers who bought these products also bought:";
            }
            else
            {
                recommendationsHeader.Text = "";
            }
        }
    }
    // Update row
    protected void grid_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        // Retrieve updated data
        string id          = grid.DataKeys[e.RowIndex].Value.ToString();
        string name        = ((TextBox)grid.Rows[e.RowIndex].Cells[0].Controls[0]).Text;
        string description = ((TextBox)grid.Rows[e.RowIndex].FindControl("descriptionTextBox")).Text;
        // Execute the update command
        bool success = CatalogBLO.UpdateCategory(id, name, description);

        // Cancel edit mode
        grid.EditIndex = -1;
        // Display status message
        statusLabel.Text = success ? "Update successful" : "Update failed";
        // Reload the grid
        BindGrid();
    }
Esempio n. 15
0
    // Fill the control with data
    private void PopulateControls()
    {
        // Retrieve ProductID from the query string
        string productId = Request.QueryString["ProductID"];
        // stores product details
        ProductDetails pd;

        // Retrieve product details
        pd = CatalogBLO.GetProductDetails(productId);
        // Display product details
        titleLabel.Text       = pd.Name;
        descriptionLabel.Text = pd.Description;
        priceLabel.Text       = String.Format("{0:c}", pd.Price);
        productImage.ImageUrl = "ProductImages/" + pd.Image2FileName;
        // Set the title of the page
        this.Title = ShopConfiguration.SiteName +
                     " : Product : " + pd.Name;
    }
 protected void Page_Load(object sender, EventArgs e)
 {
     // Load the grid only the first time the page is loaded
     if (!Page.IsPostBack)
     {
         // Load the categories grid
         BindGrid();
         // Get DepartmentID from the query string
         string departmentId = Request.QueryString["DepartmentID"];
         // Obtain the department's name
         DepartmentDetails dd             = CatalogBLO.GetDepartmentDetails(departmentId);
         string            departmentName = dd.Name;
         // Set controls' properties
         statusLabel.ForeColor = System.Drawing.Color.Red;
         locationLabel.Text    = "Displaying categories for department <b> "
                                 + departmentName + "</b>";
     }
 }
Esempio n. 17
0
 protected void Page_Load(object sender, EventArgs e)
 {
     // Load the grid only the first time the page is loaded
     if (!Page.IsPostBack)
     {
         // Get CategoryID from the query string
         string categoryId = Request.QueryString["CategoryID"];
         // Obtain the category's name
         CategoryDetails cd           = CatalogBLO.GetCategoryDetails(categoryId);
         string          categoryName = cd.Name;
         // Set controls' properties
         statusLabel.ForeColor = System.Drawing.Color.Red;
         locationLabel.Text    = "Displaying products for category <b> "
                                 + categoryName + "</b>";
         // Load the products grid
         BindGrid();
     }
 }
Esempio n. 18
0
 // assign the product to a new category
 protected void assignButton_Click(object sender, EventArgs e)
 {
     // Check if a category was selected
     if (categoriesListAssign.SelectedIndex != -1)
     {
         // Get the category ID that was selected in the DropDownList
         string categoryId = categoriesListAssign.SelectedItem.Value;
         // Assign the product to the category
         bool success = CatalogBLO.AssignProductToCategory(currentProductId, categoryId);
         // Display status message
         statusLabel.Text = success ? "Product assigned successfully" : "Product assignation failed";
         // Refresh the page
         PopulateControls();
     }
     else
     {
         statusLabel.Text = "You need to select a category";
     }
 }
Esempio n. 19
0
 protected void Page_Load(object sender, EventArgs e)
 {
     // don't reload data during postbacks
     if (!IsPostBack)
     {
         // Obtain the ID of the selected department
         string departmentId = Request.QueryString["DepartmentID"];
         // Continue only if DepartmentID exists in the query string
         if (departmentId != null)
         {
             // Catalog.GetCategoriesInDepartment returns a DataTable object containing
             // category data, which is displayed by the DataList
             list.DataSource = CatalogBLO.GetCategoriesInDepartment(departmentId);
             // Needed to bind the data bound controls to the data source
             list.DataBind();
             // Make space for the next control
             brLabel.Text = "<br />";
         }
     }
 }
Esempio n. 20
0
    // Update a product
    protected void grid_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        // Retrieve updated data
        string id                    = grid.DataKeys[e.RowIndex].Value.ToString();
        string name                  = ((TextBox)grid.Rows[e.RowIndex].FindControl("nameTextBox")).Text;
        string description           = ((TextBox)grid.Rows[e.RowIndex].FindControl("descriptionTextBox")).Text;
        string price                 = ((TextBox)grid.Rows[e.RowIndex].FindControl("priceTextBox")).Text;
        string image1FileName        = ((TextBox)grid.Rows[e.RowIndex].FindControl("image1TextBox")).Text;
        string image2FileName        = ((TextBox)grid.Rows[e.RowIndex].FindControl("image2TextBox")).Text;
        string onDepartmentPromotion = ((CheckBox)grid.Rows[e.RowIndex].Cells[6].Controls[0]).Checked.ToString();
        string onCatalogPromotion    = ((CheckBox)grid.Rows[e.RowIndex].Cells[7].Controls[0]).Checked.ToString();
        // Execute the update command
        bool success = CatalogBLO.UpdateProduct(id, name, description, price, image1FileName, image2FileName, onDepartmentPromotion, onCatalogPromotion);

        // Cancel edit mode
        grid.EditIndex = -1;
        // Display status message
        statusLabel.Text = success ? "Product update successful" : "Product update failed";
        // Reload grid
        BindGrid();
    }
Esempio n. 21
0
    private void PopulateControls()
    {
        // Retrieve DepartmentID from the query string
        string departmentId = Request.QueryString["DepartmentID"];
        // Retrieve CategoryID from the query string
        string categoryId = Request.QueryString["CategoryID"];
        // Retrieve Page from the query string
        string page = Request.QueryString["Page"];

        if (page == null)
        {
            page = "1";
        }
        // Retrieve Search string from query string
        string searchString = Request.QueryString["Search"];
        // How many pages of products?
        int howManyPages = 1;

        // If performing a product search
        if (searchString != null)
        {
            // Retrieve AllWords from query string
            string allWords = Request.QueryString["AllWords"];
            // Perform search
            list.DataSource = CatalogBLO.Search(searchString, allWords, page, out howManyPages);
            list.DataBind();
        }
        // If browsing a category...
        else if (categoryId != null)
        {
            // Retrieve list of products in a category
            list.DataSource = CatalogBLO.GetProductsInCategory(categoryId, page, out howManyPages, odr);
            list.DataBind();
        }
        else if (departmentId != null)
        {
            // Retrieve list of products on department promotion
            list.DataSource = CatalogBLO.GetProductsOnDepartmentPromotion(departmentId, page, out howManyPages, odr);
            list.DataBind();
        }
        else
        {
            // Retrieve list of products on catalog promotion
            //list.DataSource = CatalogAccess.GetProductsOnCatalogPromotion(page, out howManyPages);
            list.DataBind();
        }
        if (list.Items.Count > 0)
        {
            dropDown.Visible = true;
        }
        else
        {
            dropDown.Visible = false;
        }
        // display paging controls
        if (howManyPages > 1)
        {
            // have the current page as integer
            int currentPage = Int32.Parse(page);
            // make controls visible
            pagingLabel.Visible  = true;
            previousLink.Visible = true;
            nextLink.Visible     = true;
            // set the paging text
            pagingLabel.Text = "Page " + page + " of " + howManyPages.ToString();
            // create the Previous link
            if (currentPage == 1)
            {
                previousLink.Enabled = false;
            }
            else
            {
                NameValueCollection query = Request.QueryString;
                string paramName, newQueryString = "?";
                for (int i = 0; i < query.Count; i++)
                {
                    if (query.AllKeys[i] != null)
                    {
                        if ((paramName = query.AllKeys[i].ToString()).ToUpper() != "PAGE")
                        {
                            newQueryString += paramName + "=" + query[i] + "&";
                        }
                    }
                }
                previousLink.NavigateUrl = Request.Url.AbsolutePath + newQueryString + "Page=" + (currentPage - 1).ToString();
            }
            // create the Next link
            if (currentPage == howManyPages)
            {
                nextLink.Enabled = false;
            }
            else
            {
                NameValueCollection query = Request.QueryString;
                string paramName, newQueryString = "?";
                for (int i = 0; i < query.Count; i++)
                {
                    if (query.AllKeys[i] != null)
                    {
                        if ((paramName = query.AllKeys[i].ToString()).ToUpper() != "PAGE")
                        {
                            newQueryString += paramName + "=" + query[i] + "&";
                        }
                    }
                }
                nextLink.NavigateUrl = Request.Url.AbsolutePath + newQueryString + "Page=" + (currentPage + 1).ToString();
            }
        }
    }
Esempio n. 22
0
    // Populate the controls
    private void PopulateControls()
    {
        // Set the "go back to products" link
        goBackLink.NavigateUrl = Request.ApplicationPath +
                                 String.Format("/CatalogAdmin.aspx?DepartmentID={0}&CategoryID={1}",
                                               currentDepartmentId, currentCategoryId);
        // Retrieve product details and category details from database
        ProductDetails  productDetails  = CatalogBLO.GetProductDetails(currentProductId);
        CategoryDetails categoryDetails = CatalogBLO.GetCategoryDetails(currentCategoryId);

        // Set up labels and images
        productNameLabel.Text = productDetails.Name;
        moveLabel.Text        = "Move product from category <b>" + categoryDetails.Name + "</b> to this category: ";
        image1.ImageUrl       = Request.ApplicationPath + "/ProductImages/" + productDetails.Image1FileName;
        image2.ImageUrl       = Request.ApplicationPath + "/ProductImages/" + productDetails.Image2FileName;
        // Clear form
        categoriesLabel.Text = "";
        categoriesListAssign.Items.Clear();
        categoriesListMove.Items.Clear();
        categoriesListRemove.Items.Clear();
        // Fill categoriesLabel and categoriesListRemove with data
        string    categoryId, categoryName;
        DataTable productCategories = CatalogBLO.GetCategoriesWithProduct(currentProductId);

        for (int i = 0; i < productCategories.Rows.Count; i++)
        {
            // obtain category id and name
            categoryId   = productCategories.Rows[i]["CategoryId"].ToString();
            categoryName = productCategories.Rows[i]["Name"].ToString();
            // add a link to the category admin page
            categoriesLabel.Text += (categoriesLabel.Text == "" ? "" : ", ") +
                                    "<a href=\"" + Request.ApplicationPath + "/CatalogAdmin.aspx" +
                                    "?DepartmentID=" + CatalogBLO.GetCategoryDetails(currentCategoryId).DepartmentId +
                                    "&CategoryID=" + categoryId + "\">" +
                                    categoryName + "</a>";
            // populate the categoriesListRemove combo box
            categoriesListRemove.Items.Add(new ListItem(categoryName, categoryId));
        }
        // Delete from catalog or remove from category?
        if (productCategories.Rows.Count > 1)
        {
            deleteButton.Visible = false;
            removeButton.Enabled = true;
        }
        else
        {
            deleteButton.Visible = true;
            removeButton.Enabled = false;
        }
        // Fill categoriesListMove and categoriesListAssign with data
        productCategories = CatalogBLO.GetCategoriesWithoutProduct(currentProductId);
        for (int i = 0; i < productCategories.Rows.Count; i++)
        {
            // obtain category id and name
            categoryId   = productCategories.Rows[i]["CategoryId"].ToString();
            categoryName = productCategories.Rows[i]["Name"].ToString();
            // populate the list boxes
            categoriesListAssign.Items.Add(new ListItem(categoryName, categoryId));
            categoriesListMove.Items.Add(new ListItem(categoryName, categoryId));
        }
    }