private void btnSaveChangesProduct_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using (InventoryDBEntitiesFK ctx = new InventoryDBEntitiesFK())
         {
             Product p = ctx.Products.Find(Convert.ToInt32(lblProductIdEdit.Content));
             p.ProductName  = tbProductNameEdit.Text;
             p.Category     = tbCategoryEdit.Text;
             p.Description  = tbDescriptionEdit.Text;
             p.Price        = Convert.ToDecimal(this.tbPriceEdit.Text);
             p.SCU          = Convert.ToInt32(this.tbSCUEdit.Text);
             p.Quantity     = Convert.ToInt32(this.tbQuantityEdit.Text);
             p.Location     = tbLocationEdit.Text;
             p.SupplierName = tbSupplierEdit.Text;
             ctx.SaveChanges();
             this.Close();
             man.refreshProductsList();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #2
0
 private void btnDeleteUser_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using (InventoryDBEntitiesFK ctx = new InventoryDBEntitiesFK())
         {
             User selected = (User)lvUsersList.SelectedItem;
             User u        = ctx.Users.Find(Convert.ToInt32(selected.EmployeeId));
             ctx.Users.Remove(u);
             ctx.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     refreshUsersList();
 }
 private void btnSaveChanges_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using (InventoryDBEntitiesFK ctx = new InventoryDBEntitiesFK())
         {
             User u = ctx.Users.Find(Convert.ToInt32(lblUserId.Content));
             u.EmployeeName = tbUserNameInModify.Text;
             u.Password     = tbPasswordInmodify.Text;
             u.Role         = comboBoxRoleInModify.Text;
             ctx.SaveChanges();
             MessageBox.Show("Cogradulations!!! Record has been modified");
             //  win.refreshUsersList();
             this.Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private void btnAddProductToInventory_Click(object sender, RoutedEventArgs e)
        {
            Product product1 = new Product();

            product1.ProductName  = tbProductName.Text;
            product1.Category     = tbCategory.Text;
            product1.Description  = tbDescription.Text;
            product1.Price        = Convert.ToDecimal(this.tbPrice.Text);
            product1.SCU          = Convert.ToInt32(this.tbSCU.Text);
            product1.Quantity     = Convert.ToInt32(this.tbQuantity.Text);
            product1.Location     = tbLocation.Text;
            product1.SupplierName = tbSupplier.Text;

            try
            {
                db.Products.Add(product1);
                db.SaveChanges();
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }