/// <summary>
 /// Deletes a shelf from the database, as long as it doesn't have any bins on it with food in it
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void RowContMenuDelShelf_Click(object sender, RoutedEventArgs e)
 {
     if (sender != null)
     {
         ShelfInfo             selectedItem    = (ShelfInfo)dgridShelf.SelectedValue;
         List <InventoryEntry> matchingShelves = (from shelves in dbContext.GetTable <InventoryEntry>() //checks to see if there are any
                                                  where shelves.ShelfId == selectedItem.ShelfId         //shelves that have bins with food in them on it
                                                  select shelves).ToList();
         if (matchingShelves.Count != 0)
         {
             MessageBox.Show("There are inventory entries containing " + selectedItem.ShelfId + ". To prevent " +
                             "unintentional data loss please delete those entries before deleting this item.", "Unable to Delete", MessageBoxButton.OK);
         }
         else
         {
             allShelves.Remove(selectedItem); //Removes shelf from database and datagrid
             dgridShelf.ItemsSource = allShelves;
             dgridShelf.Items.Refresh();
             Shelf shelfToBeRemoved = (from shelves in dbContext.GetTable <Shelf>()
                                       where shelves.ShelfId == selectedItem.ShelfId
                                       select shelves).First();
             dbContext.Shelfs.DeleteOnSubmit(shelfToBeRemoved);
             dbContext.SubmitChanges();
         }
     }
 }
        /// <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 btnRmvFromInv_Click(object sender, RoutedEventArgs e)
        {
            //string[] foodQuery = (from food in dbContext.GetTable<InvBin>() where food.FoodCode == txtFood.Text orderby food.DateEntered select food).ToArray<string>();
            //Gathers info from Bins for oldest to newest
            //IQueryable < InvBin > dateQuery = from database in foodQuery orderby database.DateEntered select database;
            var oldestItem = (from food in dbContext.GetTable <InventoryEntry>() where food.FoodId == txtFood.Text orderby food.DateEntered select food).First();

            txtBinRemove.Text   = oldestItem.BinId;
            txtShelfRemove.Text = oldestItem.ShelfId;

            //delete from InvBin based on BinCode
            dbContext.InventoryEntries.DeleteOnSubmit(oldestItem);
            dbContext.SubmitChanges();
        }
예제 #4
0
 private void btnSubmit_Click(object sender, RoutedEventArgs e)
 {
     //If all of the fields are filled out, submits food item to the database
     if (Validate(txtMinQty.Text) && Validate(txtFoodName.Text))
     {
         Food toBeAdded = new Food
         {
             FoodName   = myFoodName,
             MinimumQty = Convert.ToInt32(txtMinQty.Text)
         };
         toBeAdded.Quantity += 0;
         dbContext.Foods.InsertOnSubmit(toBeAdded);
         dbContext.SubmitChanges();
     }
     else
     {
         MessageBox.Show("Please fill out all fields.", "Inventory Manager Error System");
     }
     Close();
 }
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            //If user enters a password that matches the database, user's password is changed to desired new password
            User myCurrentUser = new User();

            if (Validate(txtEmail.Text))
            {
                myCurrentUser = (from users in dbContext.GetTable <User>()
                                 where users.Email == txtEmail.Text
                                 select users).First();
            }
            if (BCrypt.CheckPassword(pwBoxCurrent.Password, myCurrentUser.Password))
            {
                string myHash = "";
                if (Validate(pwBoxNew.Password))
                {
                    string mySalt = BCrypt.GenerateSalt();
                    myHash = BCrypt.HashPassword(pwBoxNew.Password, mySalt);
                }
                else
                {
                    MessageBox.Show("Please enter a password.", "Inventory Manager Error System");
                }
                if (Validate(pwBoxConfirm.Password) && BCrypt.CheckPassword(pwBoxConfirm.Password, myHash))
                {
                    //For some reason you have to query for the user instead of being able to use
                    //the one passed to you (i.e. myCurrentUser), or at least that's only what works for me
                    User user = (from users in dbContext.GetTable <User>()
                                 where users.Email == myCurrentUser.Email
                                 select users).First <User>();
                    user.Password = myHash;
                    dbContext.SubmitChanges();
                    MessageBox.Show("Password successfully changed!");
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("Incorrect password provided.", "Inventory Manager Error System");
            }
        }
        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();
            }
        }
        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            if (Validate(txtFoodName.Text))
            {
                if (myFoodName != txtFoodName.Text)
                {
                    MessageBoxResult result = MessageBox.Show("Are you sure you want to change " + myFoodName + " to " + txtFoodName.Text + "?",
                                                              "Confirm Change",
                                                              MessageBoxButton.YesNo);
                    if (result == MessageBoxResult.Yes)
                    {
                        string newFoodName = txtFoodName.Text;
                        Food   changedFood = (from foods in dbContext.GetTable <Food>() //Queries for old food name, and
                                              where foods.FoodName == myFoodName        //then sets it to new food name
                                              select foods).First();
                        changedFood.FoodName = newFoodName;

                        dbContext.SubmitChanges();
                        MessageBox.Show(myFoodName + " successfully changed to " + newFoodName + ".");
                        myFoodName = newFoodName;
                    }
                    else
                    {
                        return;
                    }
                }
                if (Validate(txtMinQty.Text))
                {
                    //if food with matching foodname exists and the desired min quantity is different from current, change the current min quantity to desired
                    if ((from foods in dbContext.GetTable <Food>()
                         where foods.FoodName == myFoodName
                         select foods).ToList().Count != 0)
                    {
                        if ((from foods in dbContext.GetTable <Food>()
                             where foods.FoodName == myFoodName
                             select foods.MinimumQty).First() != Convert.ToInt32(txtMinQty.Text))
                        {
                            int oldQty = (from foods in dbContext.GetTable <Food>()
                                          where foods.FoodName == myFoodName
                                          select foods.MinimumQty).First();
                            MessageBoxResult result = MessageBox.Show("Are you sure you want to change the minimum quantity of " + myFoodName + "?",
                                                                      "Confirm Change",
                                                                      MessageBoxButton.YesNo);
                            if (result == MessageBoxResult.Yes)
                            {
                                string newFoodName = txtFoodName.Text;
                                int    newQty      = Convert.ToInt32(txtMinQty.Text);
                                Food   changedFood = (from foods in dbContext.GetTable <Food>()
                                                      where foods.FoodName == newFoodName
                                                      select foods).First();
                                changedFood.MinimumQty = newQty;

                                dbContext.SubmitChanges();
                                MessageBox.Show("Minimum threshold of " + newFoodName + " changed from " + oldQty + " to " + newQty + " successfully!");
                            }
                        }
                    }
                }
            }
            Close();
        }
예제 #8
0
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            //Set first name and last name of user if fields are filled out
            if (Validate("First Name", txtFirstName.Text))
            {
                myAccount.FirstName = txtFirstName.Text;
            }
            if (Validate("Last Name", txtLastName.Text))
            {
                myAccount.LastName = txtLastName.Text;
            }

            /*
             * Makes sure that the text in both fields match and that the text in both
             * fields is in a valid format before setting the account's email as the
             * user's input
             */
            if (Validate("Email", txtEmail.Text) &&
                Validate("Confirm Email", txtConfirmEmail.Text) &&
                txtEmail.Text == txtConfirmEmail.Text &&
                isValidEmailFormat(txtEmail.Text) &&
                isValidEmailFormat(txtConfirmEmail.Text))
            {
                myAccount.Email = txtEmail.Text;
            }
            else
            {
                MessageBox.Show("Emails do not match.", "Inventory Manager Error System");
                return;
            }

            /*
             * Encrypts and salts a user's password using BCrypt. Might eventually want
             * to change to PBKDF2 since that's the only NIST-approved encryption algorithm
             * for C#
             */
            string mySalt = BCrypt.GenerateSalt();
            string myHash = "";

            if (Validate("Password", pwBoxPassword.Password))
            {
                myHash = BCrypt.HashPassword(pwBoxPassword.Password, mySalt);
            }
            if (Validate("Confirm Password", pwBoxConfirmPassword.Password) &&
                BCrypt.CheckPassword(pwBoxConfirmPassword.Password, myHash))    //CheckPassword() checks a plaintext string to a hashed password
            {
                myAccount.Password = myHash;
            }
            else
            {
                MessageBox.Show("Passwords do not match.", "Inventory Manager Error System");
                return;
            }
            //Sets user's access level if an option is chosen
            if (cBoxAccessLevel.SelectedIndex != -1)
            {
                if (nonEmptyFields.ContainsKey("Access Level"))
                {
                    nonEmptyFields.Remove("Access Level");
                }
                nonEmptyFields.Add("Access Level", true);
                myAccount.AccessLevel = cBoxAccessLevel.SelectedIndex;
            }
            else
            {
                nonEmptyFields.Add("Access Level", false);
            }
            //String that will be used in a messagebox to show the user what fields are not yet filled out
            string strEmptyReporter = "";

            foreach (KeyValuePair <string, bool> entry in nonEmptyFields)
            {
                if (!entry.Value)
                {
                    readyToSubmit     = false;
                    strEmptyReporter += entry.Key + ", ";
                }
            }
            //If everything is filled out successfully, a user object is created
            if (readyToSubmit)
            {
                dbContext.Users.InsertOnSubmit(myAccount);
                dbContext.SubmitChanges();
            }
            else
            {
                strEmptyReporter = strEmptyReporter.Substring(0, strEmptyReporter.Length - 2);
                MessageBox.Show(this, "The following fields have not been filled out yet: " + strEmptyReporter);
            }

            /*TODO: Eventually use google's api for securing an oauth token in order
             * to login into email in most updated secure way (only an "issue" with gmail, outlook
             * doesn't care)
             */
            if (readyToSubmit)
            {
                try
                {
                    MailMessage mail = new MailMessage();
                    //Gmail
                    SmtpClient gmailServer = new SmtpClient("smtp.gmail.com");
                    //Outlook
                    SmtpClient outlookServer = new SmtpClient("smtp-mail.outlook.com");
                    mail.From = new MailAddress("*****@*****.**");
                    mail.To.Add(myAccount.Email);
                    mail.Subject = "Account Created for " + myAccount.LastName + ", " + myAccount.FirstName;
                    mail.Body    = "You have successfully created an account! Below is a summary of your account information: \n" +
                                   "Name: " + string.Format("{0} {1}\n", myAccount.FirstName, myAccount.LastName) +
                                   "Access Level: " + cBoxAccessLevel.Items[myAccount.AccessLevel].ToString() + "\n" +//Determines access level based on access level value
                                   "Time of Account Creation: " + DateTime.Now;
                    //Useful to know for later when sending exported spreadsheet for quarterly inventory reports
                    //Attachment attachment = new Attachment("filename");

                    //For outlook, this could also be 25
                    gmailServer.Port   = 587;
                    outlookServer.Port = 587;

                    //Account information for gmail account that emails will be sent from
                    gmailServer.Credentials = new NetworkCredential("*****@*****.**", "5LWP5MhOetfhFVlZv1bg");
                    //Ensures that the client uses Secure Socket Layer (SSL) to encrypt the connection
                    gmailServer.EnableSsl = true;

                    //Sends an email to the user's email with their account creation details
                    gmailServer.Send(mail);
                    MessageBox.Show("Mail successfully sent to " + myAccount.Email);
                    Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
        }
예제 #9
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;
                }
            }
        }