private void buttonAdd_Click(object sender, EventArgs e) { try { if (this.textBoxCategoryType.Text.Trim().ToString().Length != 0 && this.comboBoxCategory.SelectedValue != null) { CategoryType newCategory = new CategoryType { Title = this.textBoxCategoryType.Text.Trim().ToString(), CategoryId = Int32.Parse(this.comboBoxCategory.SelectedValue.ToString()) }; repository.Add(newCategory); this.textBoxCategoryType.Text = string.Empty; this.comboBoxCategory.ResetText(); MessageBox.Show("New stock category type has been added.", "Add New Category Type"); } else { MessageBox.Show("Please enter the category type and category type.", "Add New Category Type"); } } catch (Exception) { MessageBox.Show("ERROR: Adding new category type failed.", "Add New Category Type", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void comboBoxBarcode_SelectedIndexChanged(object sender, EventArgs e) { try { //Load the form details. int itemId = Int32.Parse(this.comboBoxBarcode.SelectedValue.ToString()); StockItemViewModel item = this.itemRepo.Get(itemId); #region Load the textbox controls this.textBoxDescription.Text = item.Description; this.textBoxMinStockLevel.Text = item.MinStockLevel.ToString(); this.labelItemId.Text = item.Id.ToString(); this.labelStockCount.Text = item.StockLevel.ToString(); this.checkBoxDiscontinued.Checked = (bool)item.Discontinued; #endregion #region Load the category and type details CategoryType itemCategoryType = new CategoryType(); itemCategoryType = typeRepo.GetCategoryType(item.CategoryType); this.comboBoxCategory.DisplayMember = "Name"; this.comboBoxCategory.ValueMember = "Id"; this.comboBoxCategory.DataSource = typeRepo.GetCategories().ToList(); this.comboBoxCategory.SelectedValue = item.Category; this.comboBoxCategoryType.DisplayMember = "Title"; this.comboBoxCategoryType.ValueMember = "Id"; this.comboBoxCategoryType.DataSource = typeRepo.GetCategoryTypes().ToList(); this.comboBoxCategoryType.SelectedValue = item.CategoryType; #endregion } catch (Exception) { MessageBox.Show("ERROR: Form failed to load.", "EastSeat Point of Sale", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } }