Ejemplo n.º 1
0
        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();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        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();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        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();
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
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();
                    }
                }
            }
        }
Ejemplo n.º 5
0
        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();
                    }
                }
            }
        }
Ejemplo n.º 6
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();
                    }
                }
            }
        }
Ejemplo n.º 7
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();
                }
            }
        }
Ejemplo n.º 8
0
        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();
                }
            }
        }