示例#1
0
    protected void UpdateProduct_Click(object sender, EventArgs e)
    {
        // TODO: Do any validation
        int id;

        if (int.TryParse(ProductID.Text, out id)) // If there is a Product ID
        {
            try
            {
                // Create a Product object and fill it with the data from the form
                Product item = GetProductFromUser(); // Everything but the ProductId
                item.ProductID = id;                 // The id from when they did the Lookup

                // Send the Product object to the BLL
                InventoryPurchasingController controller = new InventoryPurchasingController();
                controller.UpdateProduct(item);

                // Give the user some feedback
                PopulateProductsDropDown();
                CurrentProducts.SelectedValue = id.ToString();
                ShowMessage(item.ProductName + " was successfully updated", "success");
            }
            catch (Exception ex)
            {
                ShowMessage("Error: " + ex.Message, "danger");
            }
        }
        else
        {
            ShowMessage("Please lookup a product before clicking the Update button.", "info");
        }
    }
示例#2
0
    protected void DeleteProduct_Click(object sender, EventArgs e)
    {
        int id;

        if (int.TryParse(ProductID.Text, out id)) // If there is a Product ID
        {
            try
            {
                // Send the Product object to the BLL
                InventoryPurchasingController controller = new InventoryPurchasingController();
                controller.DeleteProduct(id);

                // Give the user some feedback
                PopulateProductsDropDown();
                CurrentProducts.SelectedIndex = 0;
                ShowMessage("Product was successfully removed", "success");
                ClearForm_Click(sender, e); // just call the ClearForm click method to clean up
            }
            catch (Exception ex)
            {
                ShowFullExceptionMessage(ex);
            }
        }
        else
        {
            ShowMessage("Please lookup a product before clicking the Delete button.", "info");
        }
    }
示例#3
0
    protected void DeleteCategory_Click(object sender, EventArgs e)
    {
        int theCategoryId;

        if (int.TryParse(CategoryID.Text, out theCategoryId))
        {
            try
            {
                InventoryPurchasingController controller = new InventoryPurchasingController();
                controller.DeleteCategory(theCategoryId);

                MessageLabel.Text = "Category " + CategoryName.Text + " deleted";
                PopulateCategoryDropdown();
                CategoryID.Text   = string.Empty;
                CategoryName.Text = string.Empty;
                Description.Text  = string.Empty;
                Picture.ImageUrl  = "~/Images/NoImage_172x120.gif";
            }
            catch (Exception ex)
            {
                MessageLabel.Text     = ex.Message;
                MessagePanel.CssClass = "alert alert-danger alert-dismissible";
                MessagePanel.Visible  = true;
            }
        }
        else
        {
            MessageLabel.Text = "Lookup and existing category before attempting to delete.";
        }
    }
示例#4
0
    protected void DeleteSupplier_Click(object sender, EventArgs e)
    {
        try
        {
            int supplierId;
            if (int.TryParse(CurrentSupplier.Text, out supplierId))
            {
                if (IsValid)
                {
                    InventoryPurchasingController Controller = new InventoryPurchasingController();
                    Controller.DeleteSupplier(supplierId);

                    // 2) Update the form and give feedback to the user
                    BindSupplierDropDown();
                    SupplierDropDownList.SelectedIndex = -1;
                    MessageLabel.Text     = "Supplier removed";
                    MessagePanel.CssClass = "alert alert-success alert-dismissible";
                    MessagePanel.Visible  = true;
                }
            }
            else
            {
                MessageLabel.Text     = "Please lookup a supplier before attempting to update";
                MessagePanel.CssClass = "alert alert-warning alert-dismissible";
                MessagePanel.Visible  = true;
            }
        }
        catch (Exception ex)
        {
            MessageLabel.Text     = ex.Message;
            MessagePanel.CssClass = "alert alert-danger alert-dismissible";
            MessagePanel.Visible  = true;
        }
    }
示例#5
0
    protected void UpdateSupplier_Click(object sender, EventArgs e)
    {
        try
        {
            int supplierId;
            if (int.TryParse(CurrentSupplier.Text, out supplierId))
            {
                if (IsValid)
                {
                    // 1) Add the product as a new item
                    // Get the Country name
                    string country = null;
                    if (CountryDropDown.SelectedIndex > 0)
                    {
                        country = CountryDropDown.SelectedValue;
                    }

                    Supplier item = new Supplier();
                    item.SupplierID    = supplierId;
                    item.CompanyName   = CompanyName.Text;
                    item.ContactName   = ContactName.Text;
                    item.ContactTitle  = ContactTitle.Text;
                    item.Address       = Address.Text;
                    item.City          = City.Text;
                    item.Region        = Region.Text;
                    item.PostalCode    = PostalCode.Text;
                    item.Country       = country;
                    item.Phone         = Phone.Text;
                    item.Fax           = Fax.Text;
                    item.HomePageTitle = HomePageTitle.Text;
                    item.HomePageUrl   = WebAddress.Text;


                    InventoryPurchasingController Controller = new InventoryPurchasingController();
                    Controller.UpdateSupplier(item);

                    // 2) Update the form and give feedback to the user
                    BindSupplierDropDown();
                    ClearForm_Click(sender, e);
                    MessageLabel.Text     = "Supplier updated";
                    MessagePanel.CssClass = "alert alert-success alert-dismissible";
                    MessagePanel.Visible  = true;
                }
            }
            else
            {
                MessageLabel.Text     = "Please lookup a supplier before attempting to update";
                MessagePanel.CssClass = "alert alert-warning alert-dismissible";
                MessagePanel.Visible  = true;
            }
        }
        catch (Exception ex)
        {
            MessageLabel.Text     = ex.Message;
            MessagePanel.CssClass = "alert alert-danger alert-dismissible";
            MessagePanel.Visible  = true;
        }
    }
示例#6
0
    protected void LookupCategory_Click(object sender, EventArgs e)
    {
        // if the user is required to make a selection or
        // enter a value for the look, ensure that it has
        // been done
        if (CurrentCategories.SelectedIndex != 0)
        {
            // you should properly handle errors in a friendly manner
            try
            {
                //connect to the BLL
                InventoryPurchasingController systemmgr = new InventoryPurchasingController();
                //set up the data catching variable
                Category aCategory; //currently null
                // issue query request (lookup)
                aCategory = systemmgr.LookupCategory(int.Parse(CurrentCategories.SelectedValue));

                // testing for not found
                if (aCategory == null)
                {
                    MessageLabel.Text = "No data from for selected category";
                    // empty display controls
                    CategoryID.Text   = "";
                    CategoryName.Text = "";
                    Description.Text  = "";
                }
                else
                {
                    // load the appropriate controls with corresponding data
                    CategoryID.Text   = aCategory.CategoryID.ToString();
                    CategoryName.Text = aCategory.CategoryName;
                    Description.Text  = aCategory.Description;

                    if (aCategory.Picture != null)
                    {
                        string base64String = Convert.ToBase64String(aCategory.Picture);
                        Picture.ImageUrl = string.Format("data:{0};base64,{1}", aCategory.PictureMimeType, base64String);
                    }
                    else
                    {
                        Picture.ImageUrl = "~/Images/NoImage_172x120.gif";
                    }
                }
            }
            catch (Exception ex)
            {
                MessageLabel.Text     = ex.Message;
                MessagePanel.CssClass = "alert alert-danger alert-dismissible";
                MessagePanel.Visible  = true;
            }
        }
        else
        {
            MessageLabel.Text     = "Select a category for searching.";
            MessagePanel.CssClass = "alert alert-info alert-dismissible";
            MessagePanel.Visible  = true;
        }
    }
示例#7
0
    private void PopulateGridView()
    {
        InventoryPurchasingController controller = new InventoryPurchasingController();
        int            searchId = int.Parse(CategoryDropDown.SelectedValue);
        List <Product> data     = controller.GetProductsByCategory(searchId);

        SearchResultsGridView.DataSource = data;
        SearchResultsGridView.DataBind();
    }
示例#8
0
    private void BindSupplierDropDown()
    {
        InventoryPurchasingController controller = new InventoryPurchasingController();

        SupplierDropDownList.DataSource     = controller.ListAllSuppliers();
        SupplierDropDownList.DataTextField  = "CompanyName";
        SupplierDropDownList.DataValueField = "SupplierID";
        SupplierDropDownList.DataBind();
        SupplierDropDownList.Items.Insert(0, new ListItem("[Select a supplier]", "-1"));
    }
示例#9
0
    private void PopulateSupplierDropDown()
    {
        InventoryPurchasingController controller = new InventoryPurchasingController();
        List <Supplier> data = controller.ListAllSuppliers();

        SupplierDropDown.DataSource     = data;
        SupplierDropDown.DataTextField  = "CompanyName";
        SupplierDropDown.DataValueField = "SupplierID";
        SupplierDropDown.DataBind();
        SupplierDropDown.Items.Insert(0, "[select a supplier]");
    }
示例#10
0
    private void PopulateCategoryDropDown()
    {
        InventoryPurchasingController controller = new InventoryPurchasingController();
        List <Category> data = controller.ListAllCategories();

        CategoryDropDown.DataSource     = data;
        CategoryDropDown.DataTextField  = "CategoryName";
        CategoryDropDown.DataValueField = "CategoryID";
        CategoryDropDown.DataBind();
        CategoryDropDown.Items.Insert(0, "[select a Category]");
    }
示例#11
0
    private void BindCountryDropDown()
    {
        InventoryPurchasingController controller = new InventoryPurchasingController();

        CountryDropDown.DataSource     = controller.ListAllCountries();
        CountryDropDown.DataTextField  = "Country";
        CountryDropDown.DataValueField = "Country";
        CountryDropDown.DataBind();
        CountryDropDown.Items.Insert(0, new ListItem("[Select a Country]", "-1"));
        CountryDropDown.Items.Insert(1, new ListItem("[no Country]", ""));
    }
示例#12
0
    private void PopulateCategoryDropdown()
    {
        // Populate Category drop-down
        InventoryPurchasingController controller = new InventoryPurchasingController();
        List <Category> categories = controller.ListAllCategories();

        CurrentCategories.DataSource     = categories;
        CurrentCategories.DataTextField  = "CategoryName";
        CurrentCategories.DataValueField = "CategoryID";
        CurrentCategories.DataBind();
        CurrentCategories.Items.Insert(0, "[select a category]");
    }
示例#13
0
    private void PopulateCategoryDropDown()
    {
        InventoryPurchasingController controller = new InventoryPurchasingController();
        List <Category> categories = controller.ListAllCategories();

        Category.DataSource     = categories;
        Category.DataTextField  = "CategoryName";
        Category.DataValueField = "CategoryID";
        Category.DataBind();
        // Let's insert a couple of options at the top of the drop-down
        Category.Items.Insert(0, new ListItem("[select a category]"));
        Category.Items.Insert(1, new ListItem("[no category]", "")); // because Product.CategoryID is nullable
    }
示例#14
0
    private void PopulateSupplierDropDown()
    {
        InventoryPurchasingController controller = new InventoryPurchasingController();
        List <Supplier> suppliers = controller.ListAllSuppliers();

        Supplier.DataSource     = suppliers;
        Supplier.DataTextField  = "CompanyName";
        Supplier.DataValueField = "SupplierID";
        Supplier.DataBind();
        // Let's insert a couple of options at the top of the drop-down
        Supplier.Items.Insert(0, new ListItem("[select a supplier]"));
        Supplier.Items.Insert(1, new ListItem("[no supplier]", "")); // because Product.SupplierID is nullable
    }
示例#15
0
    protected void AddSupplier_Click(object sender, System.EventArgs e)
    {
        try
        {
            if (IsValid)
            {
                // 1) Add the product as a new item
                // Get the Country name
                string country = null;
                if (CountryDropDown.SelectedIndex > 0)
                {
                    country = CountryDropDown.SelectedValue;
                }

                Supplier item = new Supplier();
                item.CompanyName   = CompanyName.Text;
                item.ContactName   = ContactName.Text;
                item.ContactTitle  = ContactTitle.Text;
                item.Address       = Address.Text;
                item.City          = City.Text;
                item.Region        = Region.Text;
                item.PostalCode    = PostalCode.Text;
                item.Country       = country;
                item.Phone         = Phone.Text;
                item.Fax           = Fax.Text;
                item.HomePageTitle = HomePageTitle.Text;
                item.HomePageUrl   = WebAddress.Text;


                InventoryPurchasingController Controller = new InventoryPurchasingController();
                int NewSupplierId = Controller.AddSupplier(item);

                // 2) Update the form and give feedback to the user
                BindSupplierDropDown();
                SupplierDropDownList.SelectedValue = NewSupplierId.ToString();
                CurrentSupplier.Text  = NewSupplierId.ToString();
                MessageLabel.Text     = "Supplier added";
                MessagePanel.CssClass = "alert alert-success alert-dismissible";
                MessagePanel.Visible  = true;
            }
        }
        catch (Exception ex)
        {
            MessageLabel.Text     = ex.Message;
            MessagePanel.CssClass = "alert alert-danger alert-dismissible";
            MessagePanel.Visible  = true;
        }
    }
示例#16
0
    private void PopulateProductsDropDown()
    {
        // We can populate some controls such as DropDownLists with data
        // Populate CurrentProducts with all the products in the database
        InventoryPurchasingController controller = new InventoryPurchasingController();
        // controller is a NorthwindController object
        List <Product> products = controller.ListAllProducts();

        // products is a List<Product> object
        CurrentProducts.DataSource = products;
        // CurrentProducts is a DropDownList
        CurrentProducts.DataTextField  = "ProductName"; // The property of the Product class to display
        CurrentProducts.DataValueField = "ProductID";
        CurrentProducts.DataBind();                     // Populate the DropDownList
        CurrentProducts.Items.Insert(0, "[select a product]");
    }
示例#17
0
    protected void LookupSupplier_Click(object sender, System.EventArgs e)
    {
        try
        {
            int supplierId;
            if (int.TryParse(SupplierDropDownList.SelectedValue, out supplierId) && supplierId >= 0)
            {
                Supplier item;
                InventoryPurchasingController Controller = new InventoryPurchasingController();
                item = Controller.LookupSupplier(supplierId);

                CurrentSupplier.Text          = item.SupplierID.ToString();
                CompanyName.Text              = item.CompanyName;
                ContactName.Text              = item.ContactName;
                ContactTitle.Text             = item.ContactTitle;
                Address.Text                  = item.Address;
                City.Text                     = item.City;
                Region.Text                   = item.Region;
                PostalCode.Text               = item.PostalCode;
                CountryDropDown.SelectedValue = item.Country;
                Phone.Text                    = item.Phone;
                Fax.Text           = item.Fax;
                HomePageTitle.Text = item.HomePageTitle;
                WebAddress.Text    = item.HomePageUrl;
            }
            else
            {
                MessageLabel.Text     = "Please Select a supplier before clicking Lookup";
                MessagePanel.CssClass = "alert alert-info alert-dismissible";
                MessagePanel.Visible  = true;
            }
        }
        catch (Exception ex)
        {
            MessageLabel.Text     = ex.Message;
            MessagePanel.CssClass = "alert alert-danger alert-dismissible";
            MessagePanel.Visible  = true;
        }
    }
示例#18
0
    protected void ShowProductDetails_Click(object sender, EventArgs e)
    {
        int searchId;

        if (CurrentProducts.SelectedIndex == 0)
        {
            ShowMessage("Please select a product from the dropdown before clicking [Show Product Details]", "info");
        }
        else
        {
            try
            {
                searchId = int.Parse(CurrentProducts.SelectedValue);
                InventoryPurchasingController controller = new InventoryPurchasingController();
                Product foundProduct = controller.GetProduct(searchId);

                // Unpacking the found product into the form
                ProductID.Text   = foundProduct.ProductID.ToString();
                ProductName.Text = foundProduct.ProductName;
                // Select the supplier/category for the found product
                Supplier.SelectedValue = foundProduct.SupplierID.ToString();
                Category.SelectedValue = foundProduct.CategoryID.ToString();
                // Other values that are displayed in text boxes
                QtyPerUnit.Text   = foundProduct.QuantityPerUnit;
                UnitPrice.Text    = foundProduct.UnitPrice.ToString();
                InStock.Text      = foundProduct.UnitsInStock.ToString();
                OnOrder.Text      = foundProduct.UnitsOnOrder.ToString();
                ReorderLevel.Text = foundProduct.ReorderLevel.ToString();
                // Set the checkbox for the found product's Discontinued flag
                Discontinued.Checked = foundProduct.Discontinued;

                ShowMessage("Product details found", "success");
            }
            catch (Exception ex)
            {
                ShowMessage(ex.Message, "danger");
            }
        }
    }
示例#19
0
    protected void AddCategory_Click(object sender, EventArgs e)
    {
        try
        {
            Category item = new Category();
            item.CategoryName = CategoryName.Text;
            if (!string.IsNullOrEmpty(Description.Text))
            {
                item.Description = Description.Text;
            }
            item.Picture         = ImageUploadHelpers.GetUploadedPicture(CategoryImageUpload);
            item.PictureMimeType = ImageUploadHelpers.GetMimeType(CategoryImageUpload);

            InventoryPurchasingController controller = new InventoryPurchasingController();
            int addedCategoryID = controller.AddCategory(item);
            // Update the form and give feedback to the user
            PopulateCategoryDropdown();
            CurrentCategories.SelectedValue = addedCategoryID.ToString();
            CategoryID.Text = addedCategoryID.ToString();
            if (item.Picture != null)
            {
                string base64String = Convert.ToBase64String(item.Picture);
                Picture.ImageUrl = string.Format("data:{0};base64,{1}", item.PictureMimeType, base64String);
            }
            else
            {
                Picture.ImageUrl = "~/Images/NoImage_172x120.gif";
            }
            MessageLabel.Text = "New category added";
        }
        catch (Exception ex)
        {
            MessageLabel.Text     = ex.Message;
            MessagePanel.CssClass = "alert alert-danger alert-dismissible";
            MessagePanel.Visible  = true;
        }
    }
示例#20
0
    protected void AddProduct_Click(object sender, EventArgs e)
    {
        // TODO: Do any validation
        try
        {
            // Create a Product object and fill it with the data from the form
            Product item = GetProductFromUser();

            // Send the Product object to the BLL
            InventoryPurchasingController controller = new InventoryPurchasingController();
            int newItemId = controller.AddProduct(item); // my bad ;)

            // Give the user some feedback
            PopulateProductsDropDown(); // because we have a new product for the list
            CurrentProducts.SelectedValue = newItemId.ToString();
            ProductID.Text = newItemId.ToString();

            ShowMessage("Product added", "success");
        }
        catch (Exception ex)
        {
            ShowMessage(ex.Message, "danger");
        }
    }
示例#21
0
    protected void UpdateCategory_Click(object sender, EventArgs e)
    {
        int theCategoryId;

        if (IsValid)
        {
            if (int.TryParse(CategoryID.Text, out theCategoryId))
            {
                try
                {
                    byte[] uploadedPicture = ImageUploadHelpers.GetUploadedPicture(CategoryImageUpload);
                    string mimeType        = ImageUploadHelpers.GetMimeType(CategoryImageUpload);
                    if (uploadedPicture != null && DeletePicture.Checked)
                    {
                        MessageLabel.Text = "Unclear input.<br />"
                                            + "You selected 'Check to delete picture' and uploaded an image.";
                    }
                    else
                    {
                        // 1) Get the picture to be used in the update
                        InventoryPurchasingController controller = new InventoryPurchasingController();
                        if (DeletePicture.Checked)
                        {
                            uploadedPicture = null;
                            mimeType        = null;
                        }
                        else if (uploadedPicture == null)
                        {
                            // default to the existing picture
                            Category existing = controller.LookupCategory(theCategoryId);
                            uploadedPicture = existing.Picture;
                            mimeType        = existing.PictureMimeType;
                        }

                        // 2) Create the Category object
                        Category item = new Category();
                        item.CategoryID   = theCategoryId;
                        item.CategoryName = CategoryName.Text;
                        if (!string.IsNullOrEmpty(Description.Text))
                        {
                            item.Description = Description.Text;
                        }
                        item.Picture         = uploadedPicture;
                        item.PictureMimeType = mimeType;

                        // 3) Update the database
                        controller.UpdateCategory(item);


                        PopulateCategoryDropdown();
                        CurrentCategories.SelectedValue = item.CategoryID.ToString();
                        if (item.Picture != null)
                        {
                            string base64String = Convert.ToBase64String(item.Picture);
                            Picture.ImageUrl = string.Format("data:{0};base64,{1}", item.PictureMimeType, base64String);
                        }
                        else
                        {
                            Picture.ImageUrl = "~/Images/NoImage_172x120.gif";
                        }
                        MessageLabel.Text = "Category was updated.";
                    }
                }
                catch (Exception ex)
                {
                    MessageLabel.Text     = ex.Message;
                    MessagePanel.CssClass = "alert alert-danger alert-dismissible";
                    MessagePanel.Visible  = true;
                }
            }
            else
            {
                MessageLabel.Text = "Lookup and existing category before attempting an update.";
            }
        }
    }