/// <summary> /// Initialize data to the form /// </summary> private void InitializeData() { // Category section comboBox data source - GunsRUsEnums catSectionCB.DataSource = Enum.GetValues(typeof(GunsRUsEnums.Section)).Cast <GunsRUsEnums.Section>().Where(x => x != GunsRUsEnums.Section.AllSections).ToList(); // Manager list view display CategoryFunctions.PopulateListView(CategoryFunctions.GetCategories(), ManagerlistView); // Shop list view display CategoryFunctions.PopulateListView(CategoryFunctions.GetCategories(), ShopListView); // Manager Main section comboBox data source - GunsRUsEnums ManagerMainSectionCB.DataSource = Enum.GetValues(typeof(GunsRUsEnums.Section)); // Category Id combo box data source pMCatNameCB.DataSource = CategoryFunctions.GetCategories().Select(x => x.Name).ToArray(); // Slash Picture Box slashPicBox.Image = Properties.Resources.Slash__1_; slashPicBox.SizeMode = PictureBoxSizeMode.StretchImage; // Product quantity label QuantityTxtBox.Text = ProductFunctions.GetProducts().Count.ToString(); // Shop Main section comboBox ShopMainSecCb.DataSource = Enum.GetValues(typeof(GunsRUsEnums.Section)); // SHop Data Grid ShopProGrid.DataSource = ProductFunctions.GetProducts(); ShopProGrid.RowTemplate.Height = 100; // SHop Data Grid ManagerDataGrid.DataSource = ProductFunctions.GetProducts(); ManagerDataGrid.RowTemplate.Height = 30; }
/// <summary> /// Product update Button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnProUpdate_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(proNameTxtBox.Text) && !string.IsNullOrEmpty(proDescTextBox.Text) && !string.IsNullOrEmpty(proColorTxtBox.Text) && !string.IsNullOrEmpty(pMCatIdText.Text) && !string.IsNullOrEmpty(proPicBox.ImageLocation)) { if (!decimal.TryParse(proPriceTxtBox.Text, out decimal price)) { messageProLabel.Text = "Price Must Be A Number"; } else if (!float.TryParse(proSizeTxtBox.Text, out float size)) { messageProLabel.Text = "Size Must Be A Number"; } else { Product toUpdate = (Product)ManagerDataGrid.CurrentRow.DataBoundItem; ProductFunctions.UpdateProduct(ManagerDataGrid, proNameTxtBox.Text, proDescTextBox.Text, price, proAvailableCheckB.Checked, proColorTxtBox.Text, size, int.Parse(pMCatIdText.Text), proPicBox.ImageLocation, toUpdate.ProductId); messageProLabel.Text = "Updated successfully"; CleanProText(); } } else { messageProLabel.Text = "Missing Details..."; } }
/// <summary> /// Validates user input types /// Adds a now row to product table /// Repopulate category list view /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnProAdd_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(proNameTxtBox.Text) && !string.IsNullOrEmpty(proDescTextBox.Text) && !string.IsNullOrEmpty(proColorTxtBox.Text) && !string.IsNullOrEmpty(pMCatIdText.Text) && !string.IsNullOrEmpty(proPicBox.ImageLocation)) { if (!decimal.TryParse(proPriceTxtBox.Text, out decimal price)) { messageProLabel.Text = "Price Must Be A Number"; } else if (!float.TryParse(proSizeTxtBox.Text, out float size)) { messageProLabel.Text = "Size Must Be A Number"; } else { ProductFunctions.AddProduct(proNameTxtBox.Text, proDescTextBox.Text, price, proAvailableCheckB.Checked, proColorTxtBox.Text, size, pMCatIdText.Text, proPicBox.ImageLocation); messageProLabel.Text = "Added successfully"; CleanProText(); } } else { messageProLabel.Text = "Missing Details..."; } ManagerDataGrid.DataSource = ProductFunctions.GetProducts(); }
/// <summary> /// Shop category listview selected by categories /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ShopSectionCb_SelectedIndexChanged(object sender, EventArgs e) { if (ShopMainSecCb.SelectedItem != null || ShopMainSecCb.SelectedIndex != 0) { CategoryFunctions.CategoriesBySection(ShopMainSecCb, ShopListView); CategoryFunctions.CategoriesBySection(ShopMainSecCb, ShopListView); ShopProGrid.DataSource = ProductFunctions.GetProducts().Where(x => x.Category == ShopMainSecCb.SelectedValue.ToString()).ToList(); } else { ShopProGrid.DataSource = ProductFunctions.GetProducts(); } }
/// <summary> /// Manager section combo box /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainSectionCB_SelectedIndexChanged(object sender, EventArgs e) { if (ManagerMainSectionCB.SelectedItem != null || ManagerMainSectionCB.SelectedIndex != 0) { CategoryFunctions.CategoriesBySection(ManagerMainSectionCB, ManagerlistView); CategoryFunctions.CategoriesBySection(ManagerMainSectionCB, ManagerlistView); ManagerDataGrid.DataSource = ProductFunctions.GetProducts().Where(x => x.Category == ManagerMainSectionCB.SelectedValue.ToString()).ToList(); } else { ManagerDataGrid.DataSource = ProductFunctions.GetProducts(); } }
/// <summary> /// Deletes a row from the database and the data grid view /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnProDelete_Click(object sender, EventArgs e) { Product toDelete = (Product)ManagerDataGrid.CurrentRow.DataBoundItem; if (toDelete != null) { Functions.DeleteFromTable(toDelete.ProductId, "Product"); } else { messageProLabel.Text = "Choose Products To Delete"; } ManagerDataGrid.DataSource = ProductFunctions.GetProducts(); }
/// <summary> /// Shop Products Display /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mProCatListView1_SelectedIndexChanged(object sender, EventArgs e) { ShopProGrid.DataSource = ProductFunctions.ProductDisplayByCategory(ShopListView); if (ManagerlistView.SelectedItems.Count > 0) { QuantityTxtBox.Text = ProductFunctions.ProductDisplayByCategory(ManagerlistView).Count.ToString(); } else { QuantityTxtBox.Text = ProductFunctions.GetProducts().Count.ToString(); } // Product quantity label QuantityTxtBox.Text = ShopProGrid.Rows.Count.ToString(); }
/// <summary> /// Displays products between selected range /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Price_TextChanged(object sender, EventArgs e) { ProductFunctions.ProductByPrice(txtLowPrice.Text, txtMaxPrice.Text, ShopProGrid); }
/// <summary> /// Manager Product Display /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mCatListVew_SelectedIndexChanged(object sender, EventArgs e) { ManagerDataGrid.DataSource = ProductFunctions.ProductDisplayByCategory(ManagerlistView); }