Ejemplo n.º 1
0
        /// <summary>
        /// event is based on previous methods. if update will update description and or cost based on itemCode. if new will add new item with auto
        /// generated itemCode, inputed descritpion and cost. If delete will delete based on ItemCode
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnAdd_Click(object sender, RoutedEventArgs e)
        {
            _item.ItemDesc = textBoxDescription.Text;
            _item.ItemCode = _logic.GetId();

            if (textBoxDescription.Text == string.Empty)
            {
                _item.ItemDesc = "NULL";
            }

            if (radioButtonAdd.IsChecked == true && ValidateAdd())
            {
                _logic.AddItem(_item);
                _items.Add(_item);
            }

            if (radioButtonDelete.IsChecked == true && ValidateDelete())
            {
                _logic.DeleteItem(_item);
                _items.Remove(_items.FirstOrDefault(x => x.ItemCode == int.Parse(textBoxCode.Text)));
            }

            if (radioButtonUpdate.IsChecked == true && ValidateUpdate())
            {
                _logic.UpdateItem(_item);
                _items = _logic.GetItems();
            }

            _item = new ItemDescription();

            UpdateTable();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Updates item in database, list, and datagrid
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void editItemButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         ErrorItemCode.Content = ErrorItemCost.Content = ErrorItemDesc.Content = "";
         if (itemCodeText.Text == "")
         {
             ErrorItemCode.Content = "Name cannot be empty.";
             return;
         }
         else if (itemDescText.Text == "")
         {
             ErrorItemDesc.Content = "Item description cannot be empty.";
             return;
         }
         string pKey  = itemCodeText.Text;
         string iDesc = itemDescText.Text;
         double cost  = 0;
         //if string to double failed
         if (!double.TryParse(itemCostText.Text, out cost))
         {
             ErrorItemCost.Content = "Value must only be numbers and one decimal.";
             return;
         }
         Item newItem = myLogic.UpdateItem(pKey, iDesc, cost);
         if (newItem == null)
         {
             ErrorItemCode.Content = "That Item Name is not valid";
             return;
         }
         RefreshItemDataGrid();
     }
     catch (Exception ex)
     {
         HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name, MethodInfo.GetCurrentMethod().Name, ex.Message);
     }
 }