Beispiel #1
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;
                }
            }
        }
Beispiel #2
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;
                        }
                    }
                }
            }
        }
Beispiel #3
0
 private void detach_InventoryEntries(InventoryEntry entity)
 {
     this.SendPropertyChanging();
     entity.User = null;
 }
Beispiel #4
0
 partial void DeleteInventoryEntry(InventoryEntry instance);
Beispiel #5
0
 partial void UpdateInventoryEntry(InventoryEntry instance);
Beispiel #6
0
 partial void InsertInventoryEntry(InventoryEntry instance);
Beispiel #7
0
 private void attach_InventoryEntries(InventoryEntry entity)
 {
     this.SendPropertyChanging();
     entity.Shelf = this;
 }