Exemple #1
0
        private void CustomerOrderDetails_Load(object sender, EventArgs e)
        {
            using (var ctx = new WarehouseDataEntity())
            {
                tbCustomer.Text = _selectedCustomer.FullName;
                tbOrderID.Text  = _selectedOrder.OrderID.ToString();
                //tbEmployee.Text = _selectedOrder.Employee.FullName;
                tbDateCreated.Text = _selectedOrder.DateCreated.ToShortDateString();

                var productlist = ctx.OrderProducts.Where(x => x.OrderID == _selectedOrder.OrderID).Select(x => x).ToList();

                foreach (var item in productlist)
                {
                    var listproduct = new SelectedProduct
                    {
                        Name      = item.Product.Name,
                        ProductID = item.ProductID,
                        Amount    = item.Amount
                    };

                    _productsinorder.Add(listproduct);
                }

                lbProducts.DataSource    = null;
                lbProducts.DisplayMember = "NameAndAmount";
                lbProducts.ValueMember   = "ProductID";
                lbProducts.DataSource    = _productsinorder;
            }
        }
        private void OrderOverview_Load(object sender, EventArgs e)
        {
            using (var ctx = new WarehouseDataEntity())
            {
                if (_loggedInEmployee.AccessID == 3)
                {
                    lblObject.Text = "Customer:";
                    var customerlist = ctx.Customers.ToList();
                    cbObject.DataSource    = null;
                    cbObject.DisplayMember = "FullName";
                    cbObject.ValueMember   = "CustomerID";
                    cbObject.DataSource    = customerlist;
                }

                else if (_loggedInEmployee.AccessID == 2)
                {
                    lblObject.Text = "Supplier:";
                    var supplierlist = ctx.Suppliers.ToList();
                    cbObject.DataSource    = null;
                    cbObject.DisplayMember = "Name";
                    cbObject.ValueMember   = "SupplierID";
                    cbObject.DataSource    = supplierlist;
                }
            }
        }
        private void cbObject_SelectedIndexChanged(object sender, EventArgs e)
        {
            using (var ctx = new WarehouseDataEntity())
            {
                if (_loggedInEmployee.AccessID == 3)
                {
                    var selectedcustomer = (Customer)cbObject.SelectedItem;
                    var customerorders   = ctx.Orders.Where(x => x.CustomerID == selectedcustomer.CustomerID).ToList();
                    lbOrders.DataSource    = null;
                    lbOrders.DisplayMember = "ShowOrder";
                    lbOrders.ValueMember   = "OrderID";
                    lbOrders.DataSource    = customerorders;
                }

                else if (_loggedInEmployee.AccessID == 2)
                {
                    var selectedsupplier = (Supplier)cbObject.SelectedItem;
                    var supplierorders   = ctx.Orders.Where(x => x.SupplierID == selectedsupplier.SupplierID).ToList();
                    lbOrders.DataSource    = null;
                    lbOrders.DisplayMember = "ShowOrder";
                    lbOrders.ValueMember   = "OrderID";
                    lbOrders.DataSource    = supplierorders;
                }
            }
        }
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (tbNew.Text != tbConfirm.Text)
            {
                MessageBox.Show("Passwords do not match.");
            }

            else
            {
                var hasher  = new Hashing();
                var salt    = hasher.GetHashString(hasher.CreateSalt());
                var hash    = hasher.sha256encrypt(tbConfirm.Text, salt);
                var success = hasher.VerifyHash(tbConfirm.Text, salt, hash);

                if (success)
                {
                    using (var ctx = new WarehouseDataEntity())
                    {
                        var login = new Login()
                        {
                            EmployeeID   = _selectedEmployee.EmployeeID,
                            LastLoggedIn = DateTime.Now
                        };

                        var employee = ctx.Employees.Single(x => x.EmployeeID == _selectedEmployee.EmployeeID);
                        employee.Password = hash;
                        employee.Salt     = salt;
                        ctx.Logins.Add(login);
                        ctx.SaveChanges();
                        Close();
                    }
                }
            }
        }
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (_selectedCustomer == null)
            {
                var dialogResult = MessageBox.Show("Are you sure you want to create this new customer?", "New customer", MessageBoxButtons.YesNo);

                if (dialogResult == DialogResult.Yes)
                {
                    using (var ctx = new WarehouseDataEntity())
                    {
                        var newCustomer = new Customer()
                        {
                            Firstname   = tbFirstname.Text,
                            Lastname    = tbLastname.Text,
                            Address     = tbAddress.Text,
                            Housenumber = tbNumber.Text,
                            Bus         = tbBus.Text,
                            ZIP_code    = Convert.ToInt32(tbZIP.Text),
                            City        = tbCity.Text,
                            Phonenumber = tbPhone.Text,
                            e_mail      = tbemail.Text,
                            Note        = tbNote.Text,
                            JoinDate    = DateTime.Now
                        };

                        ctx.Customers.Add(newCustomer);
                        ctx.SaveChanges();
                        MessageBox.Show("Customer added.");
                        Close();
                    }
                }
            }

            else
            {
                var dialogResult = MessageBox.Show("Are you sure you want to edit this customer?", "Edit customer", MessageBoxButtons.YesNo);

                if (dialogResult == DialogResult.Yes)
                {
                    using (var ctx = new WarehouseDataEntity())
                    {
                        var getCustomer = ctx.Customers.Find(_selectedCustomer.CustomerID);
                        getCustomer.Firstname   = tbFirstname.Text;
                        getCustomer.Lastname    = tbLastname.Text;
                        getCustomer.Address     = tbAddress.Text;
                        getCustomer.Housenumber = tbNumber.Text;
                        getCustomer.Bus         = tbBus.Text;
                        getCustomer.ZIP_code    = Convert.ToInt32(tbZIP.Text);
                        getCustomer.City        = tbCity.Text;
                        getCustomer.Phonenumber = tbPhone.Text;
                        getCustomer.e_mail      = tbemail.Text;
                        getCustomer.Note        = tbNote.Text;
                        ctx.SaveChanges();
                        MessageBox.Show("Changes saved.");
                        Close();
                    }
                }
            }
        }
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (_selectedProduct == null)
            {
                var newProduct = new Product()
                {
                    Name          = tbName.Text,
                    Cost          = decimal.Parse(tbCost.Text),
                    Margin        = decimal.Parse(tbMargin.Text),
                    Tax           = Convert.ToInt32(cbTax.SelectedValue),
                    CategoryID    = Convert.ToInt32(cbCategory.SelectedValue),
                    SupplierID    = Convert.ToInt32(cbSupplier.SelectedValue),
                    InStock       = rbYes.Checked ? true : false,
                    AmountInStock = tbAmount.Text == string.Empty ? 0 : int.Parse(tbAmount.Text),
                };

                using (var ctx = new WarehouseDataEntity())
                {
                    var dialogResult = MessageBox.Show("Are you sure you want to create this new product?", "New product", MessageBoxButtons.YesNo);

                    if (dialogResult == DialogResult.Yes)
                    {
                        ctx.Products.Add(newProduct);
                        ctx.SaveChanges();
                        Close();
                    }
                }
            }

            else
            {
                using (var ctx = new WarehouseDataEntity())
                {
                    var dialogResult = MessageBox.Show("Are you sure you want to save changes?", "Edit product", MessageBoxButtons.YesNo);

                    if (dialogResult == DialogResult.Yes)
                    {
                        var productToEdit = ctx.Products.Find(_selectedProduct.ProductID);

                        if (productToEdit == null)
                        {
                            MessageBox.Show("Something went wrong.");
                        }
                        else
                        {
                            productToEdit.Name       = tbName.Text;
                            productToEdit.Cost       = decimal.Parse(tbCost.Text);
                            productToEdit.Margin     = decimal.Parse(tbMargin.Text);
                            productToEdit.Tax        = Convert.ToInt32(cbTax.SelectedValue);
                            productToEdit.CategoryID = Convert.ToInt32(cbCategory.SelectedValue);
                            productToEdit.SupplierID = Convert.ToInt32(cbSupplier.SelectedValue);
                            productToEdit.InStock    = rbYes.Checked ? true : false;
                            ctx.SaveChanges();
                            Close();
                        }
                    }
                }
            }
        }
Exemple #7
0
 private void CustomerOrderOverview_Load(object sender, EventArgs e)
 {
     using (var ctx = new WarehouseDataEntity())
     {
         var customerlist = ctx.Customers.ToList();
         cbCustomer.DisplayMember = "FullName";
         cbCustomer.ValueMember   = "CustomerID";
         cbCustomer.DataSource    = customerlist;
     }
 }
Exemple #8
0
 private void NewUser_Load(object sender, EventArgs e)
 {
     using (var ctx = new WarehouseDataEntity())
     {
         var accesslist = ctx.Accesses.ToList();
         cbDepartment.DisplayMember = "AccessName";
         cbDepartment.ValueMember   = "AccessID";
         cbDepartment.DataSource    = accesslist;
     }
 }
Exemple #9
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (_selectedSupplier == null)
            {
                var dialogResult = MessageBox.Show("Are you sure you want to create this new supplier?", "New supplier", MessageBoxButtons.YesNo);

                if (dialogResult == DialogResult.Yes)
                {
                    using (var ctx = new WarehouseDataEntity())
                    {
                        var newSupplier = new Supplier()
                        {
                            Name        = tbName.Text,
                            Phonenumber = tbPhone.Text,
                            e_mail      = tbEmail.Text,
                            Address     = tbAddress.Text,
                            HouseNumber = int.Parse(tbNumber.Text),
                            Bus         = tbBus.Text,
                            ZIP_Code    = int.Parse(tbZIP.Text),
                            City        = tbCity.Text
                        };

                        ctx.Suppliers.Add(newSupplier);
                        ctx.SaveChanges();
                        MessageBox.Show("Supplier added.");
                        Close();
                    }
                }
            }

            else
            {
                var dialogResult = MessageBox.Show("Are you sure you want to edit this supplier?", "Edit supplier", MessageBoxButtons.YesNo);

                if (dialogResult == DialogResult.Yes)
                {
                    using (var ctx = new WarehouseDataEntity())
                    {
                        var getSupplier = ctx.Suppliers.Find(_selectedSupplier.SupplierID);

                        getSupplier.Name        = tbName.Text;
                        getSupplier.Phonenumber = tbPhone.Text;
                        getSupplier.e_mail      = tbEmail.Text;
                        getSupplier.Address     = tbAddress.Text;
                        getSupplier.HouseNumber = int.Parse(tbNumber.Text);
                        getSupplier.Bus         = tbBus.Text;
                        getSupplier.ZIP_Code    = int.Parse(tbZIP.Text);
                        getSupplier.City        = tbCity.Text;
                        ctx.SaveChanges();
                        MessageBox.Show("Changes saved.");
                        Close();
                    }
                }
            }
        }
Exemple #10
0
 private void StockOverview_Load(object sender, EventArgs e)
 {
     using (var ctx = new WarehouseDataEntity())
     {
         var categorylist = ctx.Categories.ToList();
         cbCategories.DataSource    = null;
         cbCategories.DisplayMember = "CategoryName";
         cbCategories.ValueMember   = "CategoryID";
         cbCategories.DataSource    = categorylist;
     }
 }
 private void SupplierOrdersOverview_Load(object sender, EventArgs e)
 {
     using (var ctx = new WarehouseDataEntity())
     {
         var supplierlist = ctx.Suppliers.ToList();
         cbSuppliers.DataSource    = null;
         cbSuppliers.DisplayMember = "Name";
         cbSuppliers.ValueMember   = "SupplierID";
         cbSuppliers.DataSource    = supplierlist;
     }
 }
 private void cbCategories_SelectedIndexChanged(object sender, EventArgs e)
 {
     using (var ctx = new WarehouseDataEntity())
     {
         var selectedCategory = (Category)cbCategories.SelectedItem;
         var productList      = ctx.Products.Where(x => x.CategoryID == selectedCategory.CategoryID).ToList();
         cbProducts.DisplayMember = "Name";
         cbProducts.ValueMember   = "ProductID";
         cbProducts.DataSource    = productList;
     }
 }
Exemple #13
0
 private void cbCustomer_SelectedIndexChanged(object sender, EventArgs e)
 {
     using (var ctx = new WarehouseDataEntity())
     {
         var selectedCustomer  = (Customer)cbCustomer.SelectedItem;
         var customerOrderlist = ctx.OrderProducts.Where(x => x.Order.CustomerID == selectedCustomer.CustomerID);
         lbOrders.DisplayMember = "GetProductName";
         lbOrders.ValueMember   = "OrderProductID";
         lbOrders.DataSource    = customerOrderlist;
     }
 }
 private void cbCustomers_SelectedIndexChanged(object sender, EventArgs e)
 {
     using (var ctx = new WarehouseDataEntity())
     {
         var selectedCustomer = (Customer)cbCustomers.SelectedItem;
         var orderlist        = ctx.Orders.Where(x => x.CustomerID == selectedCustomer.CustomerID).ToList();
         lbOrders.DisplayMember = "ShowOrder";
         lbOrders.ValueMember   = "OrderID";
         lbOrders.DataSource    = orderlist;
     }
 }
 private void CustomerOverview_Load(object sender, EventArgs e)
 {
     if (_loggedInEmployee.AccessID == 3 || _loggedInEmployee.AccessID == 1)
     {
         using (var ctx = new WarehouseDataEntity())
         {
             var customerlist = ctx.Customers.ToList();
             cbCustomers.DataSource    = null;
             cbCustomers.DisplayMember = "FullName";
             cbCustomers.ValueMember   = "CustomerID";
             cbCustomers.DataSource    = customerlist;
         }
     }
 }
 public void FillCategoryBox()
 {
     using (var ctx = new WarehouseDataEntity())
     {
         var categorylist = ctx.Categories.ToList();
         cbCategory.DisplayMember = "CategoryName";
         cbCategory.ValueMember   = "CategoryID";
         cbCategory.DataSource    = categorylist;
         if (_selectedProduct != null)
         {
             cbCategory.SelectedValue = _selectedProduct.CategoryID;
         }
     }
 }
 private void SupplierOverview_Load(object sender, EventArgs e)
 {
     if (_loggedInEmployee.AccessID == 2 || _loggedInEmployee.AccessID == 1)
     {
         using (var ctx = new WarehouseDataEntity())
         {
             var supplierlist = ctx.Suppliers.ToList();
             cbSuppliers.DataSource    = null;
             cbSuppliers.DisplayMember = "Name";
             cbSuppliers.ValueMember   = "SupplierID";
             cbSuppliers.DataSource    = supplierlist;
         }
     }
 }
        public void FillSupplierBox()
        {
            using (var ctx = new WarehouseDataEntity())
            {
                var supplierlist = ctx.Suppliers.ToList();
                cbSupplier.DisplayMember = "Name";
                cbSupplier.ValueMember   = "SupplierID";
                cbSupplier.DataSource    = supplierlist;

                if (_selectedProduct != null)
                {
                    cbSupplier.SelectedValue = _selectedProduct.SupplierID;
                }
            }
        }
Exemple #19
0
        private void ObjectManagementOverview_Load(object sender, EventArgs e)
        {
            using (var ctx = new WarehouseDataEntity())
            {
                switch (_userchoice)
                {
                case "Employees":
                    var employeelist = ctx.Employees.ToList();
                    lbObjects.DisplayMember = "FullName";
                    lbObjects.ValueMember   = "EmployeeID";
                    lbObjects.DataSource    = employeelist;
                    break;

                case "Stock":
                    var productlist = ctx.Products.ToList();
                    lbObjects.DisplayMember = "Name";
                    lbObjects.ValueMember   = "ProductID";
                    lbObjects.DataSource    = productlist;
                    break;

                case "Customers":
                    var customerlist = ctx.Customers.ToList();
                    lbObjects.DisplayMember = "FullName";
                    lbObjects.ValueMember   = "CustomerID";
                    lbObjects.DataSource    = customerlist;
                    break;

                case "Suppliers":
                    var supplierlist = ctx.Suppliers.ToList();
                    lbObjects.DisplayMember = "Name";
                    lbObjects.ValueMember   = "SupplierID";
                    lbObjects.DataSource    = supplierlist;
                    break;

                case "Categories":
                    var categorylist = ctx.Categories.ToList();
                    lbObjects.DisplayMember = "CategoryName";
                    lbObjects.ValueMember   = "CategoryID";
                    lbObjects.DataSource    = categorylist;
                    break;

                case "Customer Orders":
                    break;
                }
            }
        }
        private void OrderOverview_Load(object sender, EventArgs e)
        {
            using (var ctx = new WarehouseDataEntity())
            {
                if (_selectedSupplier != null)
                {
                    lblObject.Text = _selectedSupplier.Name;
                }

                else if (_selectedCustomer != null)
                {
                    lblObject.Text = _selectedCustomer.FullName;
                }

                if (_selectedOrder != null)
                {
                    btnCreate.Text = "Edit order";

                    if (_selectedOrder.CustomerID != null)
                    {
                        _selectedProducts = ctx.OrderProducts.Where(x => x.OrderID == _selectedOrder.OrderID).Select(x => new SelectedProduct {
                            ProductID = x.ProductID, Name = x.Product.Name, Amount = x.Amount
                        }).ToList();
                        RefreshProductlist();
                    }

                    else
                    {
                        _selectedProducts = ctx.OrderProducts.Where(x => x.OrderID == _selectedOrder.OrderID).Select(x => new SelectedProduct {
                            ProductID = x.ProductID, Name = x.Product.Name, Amount = x.Amount
                        }).ToList();
                        RefreshProductlist();
                    }
                }

                else
                {
                    btnCreate.Text = "Create order";
                }

                var categoryList = ctx.Categories.ToList();
                cbCategories.DisplayMember = "CategoryName";
                cbCategories.ValueMember   = "CategoryID";
                cbCategories.DataSource    = categoryList;
            }
        }
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (_selectedEmployee == null)
            {
                var dialogResult = MessageBox.Show("Are you sure you want to create this new employee?", "New employee", MessageBoxButtons.YesNo);

                if (dialogResult == DialogResult.Yes)
                {
                    using (var ctx = new WarehouseDataEntity())
                    {
                        var newEmployee = new Employee()
                        {
                            Firstname      = tbFirstname.Text,
                            Lastname       = tbLastname.Text,
                            EmploymentDate = dtpEmploymentDate.Value,
                            StartingSalary = decimal.Parse(tbStartingSalary.Text),
                            AccessID       = Convert.ToInt32(cbAccess.SelectedValue),
                            Password       = "******"
                        };

                        ctx.Employees.Add(newEmployee);
                        ctx.SaveChanges();
                        Close();
                    }
                }
            }

            else
            {
                var dialogResult = MessageBox.Show("Are you sure you want to edit this employee?", "Edit employee", MessageBoxButtons.YesNo);

                if (dialogResult == DialogResult.Yes)
                {
                    using (var ctx = new WarehouseDataEntity())
                    {
                        var editEmployeeQuery = ctx.Employees.Single(x => x.EmployeeID == _selectedEmployee.EmployeeID);
                        editEmployeeQuery.Firstname      = tbFirstname.Text;
                        editEmployeeQuery.Lastname       = tbLastname.Text;
                        editEmployeeQuery.AccessID       = Convert.ToInt32(cbAccess.SelectedValue);
                        editEmployeeQuery.EmploymentDate = dtpEmploymentDate.Value;
                        ctx.SaveChanges();
                    }
                }
            }
        }
Exemple #22
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (_selectedCategory == null)
            {
                var dialogResult = MessageBox.Show("Are you sure you want to create this new category?", "New category", MessageBoxButtons.YesNo);

                if (dialogResult == DialogResult.Yes)
                {
                    using (var ctx = new WarehouseDataEntity())
                    {
                        var newCategory = new Category()
                        {
                            CategoryName = tbName.Text
                        };

                        ctx.Categories.Add(newCategory);
                        ctx.SaveChanges();
                        MessageBox.Show("Category added.");
                        Close();
                    }
                }
            }

            else
            {
                var dialogResult = MessageBox.Show("Are you sure you want to edit this category?", "Edit category", MessageBoxButtons.YesNo);

                if (dialogResult == DialogResult.Yes)
                {
                    using (var ctx = new WarehouseDataEntity())
                    {
                        var getCategory = ctx.Categories.Find(_selectedCategory.CategoryID);
                        getCategory.CategoryName = tbName.Text;
                        ctx.SaveChanges();
                        MessageBox.Show("Changes saved.");
                        Close();
                    }
                }
            }
        }
Exemple #23
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(tbName.Text) && !string.IsNullOrEmpty(tbSurname.Text))
            {
                Employee newEmployee = new Employee
                {
                    Firstname      = tbName.Text,
                    Lastname       = tbSurname.Text,
                    Password       = string.Empty,
                    AccessID       = (int)cbDepartment.SelectedValue,
                    StartingSalary = int.Parse(tbStartingSalary.Text),
                    EmploymentDate = dtpEmployment.Value
                };

                using (var ctx = new WarehouseDataEntity())
                {
                    ctx.Employees.Add(newEmployee);
                    ctx.SaveChanges();
                    Close();
                }
            }
        }
        private void StockDetails_Load(object sender, EventArgs e)
        {
            if (_selectedProduct != null)
            {
                using (var ctx = new WarehouseDataEntity())
                {
                    tbName.Text   = _selectedProduct.Name;
                    tbCost.Text   = _selectedProduct.Cost.ToString();
                    tbMargin.Text = _selectedProduct.Margin.ToString();

                    FillTaxBox();
                    FillCategoryBox();
                    FillSupplierBox();

                    cbTax.Text = _selectedProduct.Tax.ToString();

                    if (_selectedProduct.InStock)
                    {
                        rbYes.Checked = true;
                        tbAmount.Text = _selectedProduct.AmountInStock.ToString();
                    }

                    else
                    {
                        rbNo.Checked     = true;
                        tbAmount.Enabled = false;
                    }
                }
            }

            else
            {
                FillTaxBox();
                FillCategoryBox();
                FillSupplierBox();
            }
        }
        private void EmployeeDetails_Load(object sender, EventArgs e)
        {
            using (var ctx = new WarehouseDataEntity())
            {
                var accesslist = ctx.Accesses.ToList();
                cbAccess.DisplayMember = "AccessName";
                cbAccess.ValueMember   = "AccessID";
                cbAccess.DataSource    = accesslist;

                if (_selectedEmployee != null)
                {
                    tbFirstname.Text        = _selectedEmployee.Firstname;
                    tbLastname.Text         = _selectedEmployee.Lastname;
                    tbStartingSalary.Text   = _selectedEmployee.StartingSalary.ToString();
                    dtpEmploymentDate.Value = _selectedEmployee.EmploymentDate;
                    cbAccess.SelectedValue  = _selectedEmployee.AccessID;
                }

                else
                {
                    return;
                }
            }
        }
        private void btnCreate_Click(object sender, EventArgs e)
        {
            using (var ctx = new WarehouseDataEntity())
            {
                if (_selectedOrder == null)
                {
                    if (_selectedSupplier == null)
                    {
                        var newOrder = new Order
                        {
                            DateCreated = DateTime.Now,
                            EmployeeID  = _loggedInEmployee.EmployeeID,
                            CustomerID  = _selectedCustomer.CustomerID
                        };

                        ctx.Orders.Add(newOrder);
                        ctx.SaveChanges();

                        foreach (var item in _selectedProducts)
                        {
                            var newOrderProduct = new OrderProduct
                            {
                                OrderID   = newOrder.OrderID,
                                ProductID = item.ProductID,
                                Amount    = item.Amount
                            };

                            ctx.OrderProducts.Add(newOrderProduct);
                            ctx.SaveChanges();

                            var dialogresult = MessageBox.Show("Orders created, do you wish to print the invoice?", "Created", MessageBoxButtons.YesNo);

                            if (dialogresult == DialogResult.Yes)
                            {
                                var newInvoice = new Invoice();
                                newInvoice.GenerateInvoice(newOrder.OrderID);
                            }

                            Close();
                        }
                    }

                    else
                    {
                        var newOrder = new Order
                        {
                            DateCreated = DateTime.Now,
                            EmployeeID  = _loggedInEmployee.EmployeeID,
                            SupplierID  = _selectedSupplier.SupplierID
                        };

                        ctx.Orders.Add(newOrder);
                        ctx.SaveChanges();

                        foreach (var item in _selectedProducts)
                        {
                            var newOrderProduct = new OrderProduct
                            {
                                OrderID   = newOrder.OrderID,
                                ProductID = item.ProductID,
                                Amount    = item.Amount
                            };

                            ctx.OrderProducts.Add(newOrderProduct);
                            ctx.SaveChanges();
                            var reactionresult = MessageBox.Show("Order created, do you wish to print the invoice?", "Created", MessageBoxButtons.YesNo);

                            if (reactionresult == DialogResult.Yes)
                            {
                                var newInvoice = new Invoice();
                                newInvoice.GenerateInvoice(newOrder.OrderID);
                            }
                            Close();
                        }
                    }
                }

                else
                {
                    var editOrder = ctx.Orders.Single(x => x.OrderID == _selectedOrder.OrderID);
                    editOrder.EmployeeID = _loggedInEmployee.EmployeeID;

                    var orderProductList = ctx.OrderProducts.Where(x => x.OrderID == _selectedOrder.OrderID).ToList();

                    var orderproducttodelete = ctx.OrderProducts.Where(x => x.OrderID == _selectedOrder.OrderID && _productsToRemove.Contains(x.ProductID));
                    ctx.OrderProducts.RemoveRange(orderproducttodelete);
                    ctx.SaveChanges();

                    foreach (var item in _selectedProducts)
                    {
                        var newOrderProduct = new OrderProduct
                        {
                            OrderID   = editOrder.OrderID,
                            ProductID = item.ProductID,
                            Amount    = item.Amount
                        };

                        if (orderProductList.Contains(newOrderProduct))
                        {
                            continue;
                        }

                        else
                        {
                            ctx.OrderProducts.Add(newOrderProduct);
                            ctx.SaveChanges();
                        }
                    }

                    MessageBox.Show("Order edited", "Edited");
                    Close();
                }
            }
        }