/// <summary>
        /// Event processor for when a user clicks the delete context menu item (which can be shown by
        /// right clicking a datagrid row)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RowContMenuDel_Click(object sender, RoutedEventArgs e)
        {
            //Grabs the InventoryInfo item stored in the datagrid row that was right-clicked
            InventoryInfo selectedItem = (InventoryInfo)gridItems.SelectedValue;

            //Make sure that the user isn't clicking on a null item (shouldn't ever happen)
            if (selectedItem != null)
            {
                //Grabs the inventory entry to delete based on the foodname and date item was entered
                InventoryEntry entryToDelete = (from entries in dbContext.GetTable <InventoryEntry>()
                                                where entries.FoodName == selectedItem.FoodName &&
                                                entries.DateEntered == selectedItem.DateEntered
                                                select entries).First();
                //Gets the food item associated with the inventory entry that the user clicks
                Food associatedFoodItem = (from items in dbContext.GetTable <Food>()
                                           where items.FoodName == entryToDelete.FoodName
                                           select items).First();
                //Removes the quantity associated with that inventory entry from the total quantity of the food
                associatedFoodItem.Quantity -= entryToDelete.ItemQty;

                //Removes item from list that the datagrid is bounded to and updates datagrid
                individualEntries.Remove(selectedItem);
                gridItems.ItemsSource = individualEntries;
                gridItems.Items.Refresh();

                //Creates a record in the audit trail
                AuditEntry auditRecord = new AuditEntry
                {
                    Action              = "DELETION",
                    ApplicationName     = APPLICATION_NAME,
                    BinId               = entryToDelete.BinId,
                    ItemQty             = entryToDelete.ItemQty,
                    Date_Action_Occured = DateTime.Now,
                    FoodName            = entryToDelete.FoodName,
                    ShelfId             = entryToDelete.ShelfId,
                    UserName            = myCurrentUser.LastName + ", " + myCurrentUser.FirstName
                };
                switch (myCurrentUser.AccessLevel)
                {
                case 0:
                    auditRecord.AccessLevel = "Administrator";
                    break;

                case 1:
                    auditRecord.AccessLevel = "Standard User";
                    break;

                default:
                    break;
                }
                //Removes inventory entry from database and adds audit record
                dbContext.InventoryEntries.DeleteOnSubmit(entryToDelete);
                dbContext.AuditEntries.InsertOnSubmit(auditRecord);
                dbContext.SubmitChanges();
            }
        }
        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            allFieldsAreFilled = true;
            try
            {
                //Get item currently being displayed in combobox
                object item = cbBinSearch.SelectedItem;
                if (item != null)
                {
                    if (currentInvEntry != null)
                    {
                        //Checks to see if any of the fields associated with the current bin are changed
                        if (Validate(cbFoodSearch.Text))
                        {
                            if (currentInvEntry.FoodName != cbFoodSearch.SelectedValue.ToString())
                            {
                                isChanged = true;
                                currentInvEntry.FoodName = cbFoodSearch.SelectedValue.ToString();
                            }
                        }
                        else
                        {
                            allFieldsAreFilled = false;
                        }
                        if (Validate(cbShelfSearch.Text))
                        {
                            if (currentInvEntry.ShelfId != cbShelfSearch.SelectedValue.ToString())
                            {
                                isChanged = true;
                                currentInvEntry.ShelfId = cbShelfSearch.SelectedValue.ToString();
                            }
                        }
                        else
                        {
                            allFieldsAreFilled = false;
                        }
                        if (Validate(txtQty.Text))
                        {
                            if (currentInvEntry.ItemQty != Convert.ToInt32(txtQty.Text))
                            {
                                isChanged = true;
                                currentInvEntry.ItemQty = Convert.ToInt32(txtQty.Text);
                            }
                        }
                        else
                        {
                            allFieldsAreFilled = false;
                        }
                        if (!allFieldsAreFilled)
                        {
                            MessageBox.Show("Please fill out all fields before submitting.", "Inventory Manager Error System");
                            return;
                        }
                        if (isChanged)
                        {
                            AuditEntry auditRecord = new AuditEntry
                            {
                                FoodName            = currentInvEntry.FoodName,
                                BinId               = currentInvEntry.BinId,
                                ShelfId             = currentInvEntry.ShelfId,
                                ItemQty             = currentInvEntry.ItemQty,
                                Date_Action_Occured = DateTime.Now,
                                UserName            = myCurrentUser.LastName + ", " + myCurrentUser.FirstName,
                                ApplicationName     = APPLICATION_NAME,
                                Action              = "UPDATE"
                            };
                            switch (myCurrentUser.AccessLevel)
                            {
                            case 0: auditRecord.AccessLevel = "Administrator";
                                break;

                            case 1: auditRecord.AccessLevel = "Standard User";
                                break;

                            default:
                                break;
                            }
                            dbContext.AuditEntries.InsertOnSubmit(auditRecord);
                            dbContext.SubmitChanges();
                        }
                    }
                    int currentIndex = cbBinSearch.SelectedIndex;

                    /*Iterates to the next inventory entry containing food in it and removes the
                     * item that has just been checked from the combobox list
                     */
                    object nextItem = cbBinSearch.Items[(currentIndex + 1) % cbBinSearch.Items.Count];
                    cbBinSearch.SelectedItem = nextItem;
                    binList.Remove(item.ToString());
                    cbBinSearch.Items.Refresh();
                }
            }
            catch (NullReferenceException)
            {
                cbFoodSearch.SelectedValue  = "";
                cbShelfSearch.SelectedValue = "";
                txtQty.Text = "";
                MessageBox.Show("There are no more items in the list to check.", "Maintenance Check Completed");
                Close();
            }
        }
Exemplo n.º 3
0
        private void Page_KeyDown(object sender, KeyEventArgs e)
        {
            TimeSpan elasped = DateTime.Now - lastKeyPress;

            if (elasped.TotalMilliseconds > 100)
            {
                textStream.Clear();
            }
            if ((e.Key >= Key.D0) && (e.Key <= Key.D9))
            {
                textStream.Add(e.Key.ToString()[1].ToString());
            }
            else if (e.Key == Key.LeftShift)
            {
                return;
            }
            else if (e.Key == Key.Space)
            {
                textStream.Add(" ");
            }
            else
            {
                textStream.Add(e.Key.ToString());
            }
            lastKeyPress = DateTime.Now;
            if (e.Key == Key.Tab && textStream.Count > 1)
            {
                string barcodeData = string.Join("", textStream).TrimEnd();
                barcodeData = barcodeData.Substring(0, barcodeData.IndexOf("Tab", StringComparison.Ordinal));

                string nums = "0123456789";

                if (barcodeData[0] == 'B' && nums.Contains(barcodeData[1]))
                {
                    List <InventoryInfo> scannedEntry = (from entries in dbContext.GetTable <InventoryEntry>()
                                                         where entries.FoodName == (from items in dbContext.GetTable <InventoryEntry>()
                                                                                    where items.BinId == barcodeData
                                                                                    select items.FoodName).First()
                                                         select new InventoryInfo
                    {
                        FoodName = entries.FoodName,
                        DateEntered = entries.DateEntered,
                        BinId = entries.BinId,
                        ShelfId = entries.ShelfId,
                        Quantity = entries.ItemQty
                    }).ToList();
                    if (scannedEntry.Count > 1)
                    {
                        DeletionManagementWindow d = new DeletionManagementWindow(myCurrentUser, scannedEntry.First(), true);
                        d.ShowInTaskbar = false;
                        d.Owner         = Application.Current.MainWindow;
                        d.ShowDialog();
                        UpdateDataGrids();
                    }
                    else
                    {
                        if (myCurrentUser.AccessLevel == 0)
                        {
                            try
                            {
                                if (sender != null)
                                {
                                    InventoryInfo selectedItem = scannedEntry.First();

                                    MessageBoxResult result = MessageBox.Show("Are you sure you want to delete this row?", "Food Bank Manager", MessageBoxButton.YesNo);

                                    if (result == MessageBoxResult.Yes)
                                    {
                                        if (!string.IsNullOrEmpty(selectedItem.FoodName))
                                        {
                                            InventoryEntry entryToDelete = (from items in dbContext.GetTable <InventoryEntry>()
                                                                            where items.FoodName == selectedItem.FoodName
                                                                            select items).First <InventoryEntry>();

                                            Food associatedFoodItem = (from items in dbContext.GetTable <Food>()
                                                                       where items.FoodName == entryToDelete.FoodName
                                                                       select items).First();

                                            associatedFoodItem.Quantity -= entryToDelete.ItemQty;

                                            AuditEntry auditRecord = new AuditEntry();
                                            auditRecord.Action              = "DELETION";
                                            auditRecord.ApplicationName     = APPLICATION_NAME;
                                            auditRecord.BinId               = entryToDelete.BinId;
                                            auditRecord.ItemQty             = -entryToDelete.ItemQty;
                                            auditRecord.Date_Action_Occured = DateTime.Now;
                                            auditRecord.FoodName            = entryToDelete.FoodName;
                                            auditRecord.ShelfId             = entryToDelete.ShelfId;
                                            auditRecord.UserName            = myCurrentUser.LastName + ", " + myCurrentUser.FirstName;
                                            switch (myCurrentUser.AccessLevel)
                                            {
                                            case 0:
                                                auditRecord.AccessLevel = "Administrator";
                                                break;

                                            case 1:
                                                auditRecord.AccessLevel = "Standard User";
                                                break;

                                            default:
                                                break;
                                            }
                                            dbContext.InventoryEntries.DeleteOnSubmit(entryToDelete);
                                            dbContext.AuditEntries.InsertOnSubmit(auditRecord);
                                            dbContext.SubmitChanges();
                                        }
                                        currentInventory.Remove((InventoryInfo)selectedItem);
                                        UpdateDataGrids();
                                    }
                                    else
                                    {
                                        return;
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.ToString());
                                MessageBox.Show("Item unable to be deleted at this time", "Food Bank Manager Error System");
                                return;
                            }
                        }
                        else
                        {
                            MessageBox.Show("Sorry, you do not have the right permission level to remove this item.");
                            return;
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void RowContMenuDel_Click(object sender, RoutedEventArgs e)
        {
            //If a food is in more than one bin, a special window will pop up allowing user to delete each individual entry
            if ((from entries in dbContext.GetTable <InventoryEntry>()
                 where entries.FoodName == ((InventoryInfo)gridItems.SelectedValue).FoodName
                 select entries)
                .ToList().Count > 1)
            {
                DeletionManagementWindow d = new DeletionManagementWindow(myCurrentUser, (InventoryInfo)gridItems.SelectedValue, false);
                d.ShowInTaskbar = false;
                d.Owner         = Application.Current.MainWindow;
                d.ShowDialog();
                UpdateDataGrids();
            }
            else
            {
                if (myCurrentUser.AccessLevel == 0)
                {
                    try
                    {
                        if (sender != null)
                        {
                            InventoryInfo selectedItem = ((InventoryInfo)gridItems.SelectedValue);

                            MessageBoxResult result = MessageBox.Show("Are you sure you want to delete this row?", "Food Bank Manager", MessageBoxButton.YesNo);

                            if (result == MessageBoxResult.Yes)
                            {
                                if (!string.IsNullOrEmpty(selectedItem.FoodName))
                                {
                                    InventoryEntry entryToDelete = (from items in dbContext.GetTable <InventoryEntry>()
                                                                    where items.FoodName == selectedItem.FoodName
                                                                    select items).First <InventoryEntry>();

                                    Food associatedFoodItem = (from items in dbContext.GetTable <Food>()
                                                               where items.FoodName == entryToDelete.FoodName
                                                               select items).First();

                                    associatedFoodItem.Quantity -= entryToDelete.ItemQty;

                                    AuditEntry auditRecord = new AuditEntry();
                                    auditRecord.Action              = "DELETION";
                                    auditRecord.ApplicationName     = APPLICATION_NAME;
                                    auditRecord.BinId               = entryToDelete.BinId;
                                    auditRecord.ItemQty             = -entryToDelete.ItemQty;
                                    auditRecord.Date_Action_Occured = DateTime.Now;
                                    auditRecord.FoodName            = entryToDelete.FoodName;
                                    auditRecord.ShelfId             = entryToDelete.ShelfId;
                                    auditRecord.UserName            = myCurrentUser.LastName + ", " + myCurrentUser.FirstName;
                                    switch (myCurrentUser.AccessLevel)
                                    {
                                    case 0:
                                        auditRecord.AccessLevel = "Administrator";
                                        break;

                                    case 1:
                                        auditRecord.AccessLevel = "Standard User";
                                        break;

                                    default:
                                        break;
                                    }
                                    dbContext.InventoryEntries.DeleteOnSubmit(entryToDelete);
                                    dbContext.AuditEntries.InsertOnSubmit(auditRecord);
                                    dbContext.SubmitChanges();
                                }
                                currentInventory.Remove((InventoryInfo)selectedItem);
                                UpdateDataGrids();
                            }
                            else
                            {
                                return;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                        MessageBox.Show("Item unable to be deleted at this time", "Food Bank Manager Error System");
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
        }
Exemplo n.º 5
0
 partial void DeleteAuditEntry(AuditEntry instance);
Exemplo n.º 6
0
 partial void UpdateAuditEntry(AuditEntry instance);
Exemplo n.º 7
0
 partial void InsertAuditEntry(AuditEntry instance);