private void button_additem_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         string item_name = (string)dropdown_item.SelectedItem;
         string quantity  = textbox_quantity.Text;
         int    i         = getitems.ReturnStockLevel(item_name) - Convert.ToInt32(quantity);
         if (i >= 0) //if stock level will be zero or above after sale, go ahead with it
         {
             string item_price = findItemPrice(item_name);
             getitems.UpdateStock(item_name, Convert.ToInt32(quantity));
             current_so.AddItem(item_name, Convert.ToDouble(quantity));
             running_total += (Convert.ToDouble(quantity) * Convert.ToDouble(item_price));
             int item_quantity;
             if (int.TryParse(quantity, out item_quantity))
             {
                 textbox_listitems.Text     += item_name + "\n";
                 textbox_listunitprice.Text += "$" + item_price + "\n";
                 textbox_listquantity.Text  += item_quantity.ToString() + "\n";
                 textbox_total.Text          = "$" + running_total.ToString();
                 string ul = "Added item: " + item_name;
                 userLog.Log(ul);
             }
             if (getitems.ReturnStockLevel(item_name) < getitems.ReturnThresh(item_name))
             {
                 textboxNotification.Text = item_name + " is below threshold\nIt's current stock: " + getitems.ReturnStockLevel(item_name);
             }
             //else
             //{
             //    textbox_error.Text = "Please enter a number into the quantity field!";
             //    return;
             //}
             //dropdown_item.SelectedItem = "";
             textbox_quantity.Text = "";
             textbox_error.Text    = "";
             salesOrder.UpdateStockText(getitems);
         }
         else
         {
             textboxNotification.Text = "Cannot add " + item_name + " as stock will be negative.\nIt's current stock: " + getitems.ReturnStockLevel(item_name);
         }
     }
     catch
     {
         string error = "Error in CreateSalesOrder.xaml.cs - button_additem_Click";
         errorObject.Log(error);
     }
     finally
     {
         //what do I do in here?
     }
 }
Пример #2
0
        private void button_makechange_Click(object sender, RoutedEventArgs e)
        {
            string itemName    = (string)dropdown_items.SelectedItem;
            string quantity    = textbox_quantity.Text;
            int    oldQuantity = 0;

            switch (currentMode)
            {
            case "edit":
                foreach (Items i in currentSO.items)
                {
                    if (i.item_name == itemName)
                    {
                        string ul = "Edited quantity of" + itemName;
                        userLog.Log(ul);
                        oldQuantity     = Convert.ToInt32(i.item_quantity);
                        i.item_quantity = Convert.ToDouble(quantity);
                        break;
                    }
                }
                break;

            case "add":
                Items newItem = new Items(itemName, Convert.ToDouble(quantity));
                currentSO.items.Add(newItem);
                break;
            }
            refreshTable();

            try
            {
                int i           = getitems.ReturnStockLevel(itemName) - Convert.ToInt32(quantity);
                int newQuantity = Convert.ToInt32(quantity);

                if (oldQuantity > newQuantity)
                {
                    getitems.UpdateStock(itemName, newQuantity - oldQuantity);
                }
                else if (oldQuantity < newQuantity)
                {
                    if (i >= 0) //if stock level will be zero or above after sale, go ahead with it
                    {
                        getitems.UpdateStock(itemName, newQuantity - oldQuantity);
                    }
                    else
                    {
                        textboxNotification.Text = "Cannot edit " + itemName + " as stock will be negative.\nIt's current stock: " + getitems.ReturnStockLevel(itemName);
                    }
                }
                else if (oldQuantity == newQuantity)
                {
                    textboxNotification.Text = "To edit stock for " + itemName + " please enter a value other than its current stock level: " + getitems.ReturnStockLevel(itemName);
                    return;
                }

                if (getitems.ReturnStockLevel(itemName) < getitems.ReturnThresh(itemName))
                {
                    textboxNotification.Text = itemName + " is below threshold\nIt's current stock: " + getitems.ReturnStockLevel(itemName);
                }

                salesOrder.UpdateStockText(getitems);
            }
            catch
            {
                string error = "Error in EditSalesOrder.xaml.cs - button_makechange_Click";
                errorObject.Log(error);
            }
        }