/// <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> /// Creating a product list according to selected categories /// </summary> /// <param name="categoryListView"></param> /// <returns></returns> public static List <Product> ProductDisplayByCategory(ListView categoryListView) { List <Product> resultProList = new List <Product>(); if (categoryListView.SelectedItems.Count > 0) { foreach (ListViewItem item in categoryListView.SelectedItems) { foreach (Category cat in CategoryFunctions.GetCategories()) { if (cat.Name == Functions.StringConverter(item.Text, ' ', '_')) // Fix the syntax { var buildIt = GetProducts("Select * from Product " + // Multi Category selection "Where Product.Category = '" + cat.Id + "'"); foreach (Product temp in buildIt) { resultProList.Add(temp); } } } } } else { resultProList = GetProducts(); } return(resultProList); }
/// <summary> /// Changes category read only text box acording to selected category id /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ProCatIndexCB_SelectedIndexChanged(object sender, EventArgs e) { if (pMCatNameCB.SelectedItem != null) { pMCatIdText.Text = CategoryFunctions.GetCategories(). Where(x => x.Name == pMCatNameCB.Text). Select(x => x.Id.ToString()).FirstOrDefault(); } }
/// <summary> /// Updates selected category in the data base and list view /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnCategoryUpdate_Click(object sender, EventArgs e) { if ((GunsRUsEnums.Section)catSectionCB.SelectedItem != GunsRUsEnums.Section.AllSections) { CategoryFunctions.UpdateCategory(ManagerlistView, catName.Text, (GunsRUsEnums.Section)catSectionCB.SelectedItem, catPicBox.ImageLocation); } else { messageLabel.Text = "Can't update a category to All Sections,\nChoose a section"; } }
/// <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> /// Adds a new category to the database using user input /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnCategoryAdd_Click(object sender, EventArgs e) { if (catPicBox.Image != null && !string.IsNullOrEmpty(catName.Text)) { if ((GunsRUsEnums.Section)catSectionCB.SelectedItem != GunsRUsEnums.Section.AllSections) { CategoryFunctions.AddCategory(catName.Text, catSectionCB.Text, catPicBox.ImageLocation); CategoryFunctions.PopulateListView(CategoryFunctions.GetCategories("SELECT * FROM Category"), ManagerlistView); // Category Id combo box data source pMCatNameCB.DataSource = CategoryFunctions.GetCategories().Select(x => x.Id).ToArray(); } else { messageLabel.Text = "Can't add to All Sections, Choose a section"; } } else { messageLabel.Text = "Must choose a name and load image first"; } }
static private string GetCatName(int _id) { return(CategoryFunctions.GetCategories().Where(x => x.Id == _id).Select(x => x.Name).FirstOrDefault()); }
/// <summary> /// Deletes all selected categories /// Reseting the list view /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnCategoryDelete_Click(object sender, EventArgs e) { CategoryFunctions.CategoryListViewDelete(ManagerlistView); }