public BestellingVerkoper()
        {
            InitializeComponent();

            lblUser.Content = $"{ActiveUser.FirstName} {ActiveUser.LastName} ({ActiveUser.Role})";

            using (var ctx = new OrderManagerContext())
            {
                var collection = ctx.OrderDetails.Join(ctx.Products,
                                                       od => od.Product.ProductId,
                                                       p => p.ProductId,
                                                       (od, p) => new { od, p })
                                 .GroupBy(c => c.od.Order.OrderId);

                dgOrders.ItemsSource = ctx.Orders.Join(collection,
                                                       o => o.OrderId,
                                                       c => c.Key,
                                                       (o, c) => new { OrderId = o.OrderId, Name = o.Customer.Name, OrderDate = o.OrderDate, TotalQ = c.Sum(s => s.od.Quantity), TotalP = c.Sum(s => s.od.Product.UnitPrice * s.od.Quantity) })
                                       .ToList();

                cbOrders.ItemsSource       = ctx.Orders.Include(o => o.OrderDetails).ToList();
                cbCustomersAdd.ItemsSource = ctx.Customers.ToList();
                cbProductsAdd.ItemsSource  = ctx.Products.ToList();
            }
        }
Esempio n. 2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            using (var ctx = new OrderManagerContext())
            {
                var user = ctx.Users.Include(nameof(Role)).FirstOrDefault(u => u.Username == txtUsername.Text);

                if (user == null)
                {
                    MessageBox.Show("Ongeldige username", "", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    if (user.Password == User.Encryption(txtPassword.Password))
                    {
                        ActiveUser.UserId    = user.UserId;
                        ActiveUser.FirstName = user.FirstName;
                        ActiveUser.LastName  = user.LastName;
                        ActiveUser.Role      = user.Role.Name;
                        MessageBox.Show($"Welkom, {ActiveUser.FirstName}!", "", MessageBoxButton.OK, MessageBoxImage.Information);
                        UserMenu menu = new UserMenu();
                        Hide();
                        menu.Show();
                    }
                    else
                    {
                        MessageBox.Show("Ongeldig password", "", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
        }
Esempio n. 3
0
        public OverzichtMagazijn()
        {
            InitializeComponent();

            lblUser.Content = $"{ActiveUser.FirstName} {ActiveUser.LastName} ({ActiveUser.Role})";

            using (var ctx = new OrderManagerContext())
            {
                var collection = ctx.Products.GroupJoin(ctx.Suppliers,
                                                        p => p.Supplier.SupplierId,
                                                        s => s.SupplierId,
                                                        (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name }).ToList();

                dgMagazijn.ItemsSource = collection;

                cbSuppliers.ItemsSource = ctx.Suppliers.ToList();

                int    stock = 0;
                double price = 0;

                foreach (var item in collection)
                {
                    stock += item.Stock;
                    price += item.Stock * item.UnitPrice;
                }

                tbAantal.Text = $"{stock} stuks";
                tbPrijs.Text  = $"€ {string.Format("{0:0.00}", price)}";
            }
        }
        private void Button_Click_AddCustomer(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(txtNaamCustomerAdd.Text) && !string.IsNullOrWhiteSpace(txtAdresCustomerAdd.Text))
            {
                using (var ctx = new OrderManagerContext())
                {
                    ctx.Customers.Add(new Customer()
                    {
                        Name = txtNaamCustomerAdd.Text, Address = txtAdresCustomerAdd.Text
                    });
                    ctx.SaveChanges();

                    dgCustomersAdd.ItemsSource = null;
                    dgCustomersAdd.ItemsSource = ctx.Customers.ToList();

                    dgCustomersEdit.ItemsSource = null;
                    dgCustomersEdit.ItemsSource = ctx.Customers.ToList();
                    cbCustomersEdit.ItemsSource = ctx.Customers.ToList();

                    dgCustomersDelete.ItemsSource = null;
                    dgCustomersDelete.ItemsSource = ctx.Customers.ToList();
                    cbCustomersDelete.ItemsSource = ctx.Customers.ToList();
                }
                MessageBox.Show("Klant werd toegevoegd.", "", MessageBoxButton.OK, MessageBoxImage.Information);
                txtNaamCustomerAdd.Clear();
                txtAdresCustomerAdd.Clear();
            }
            else
            {
                MessageBox.Show("Klant toevoegen mislukt!\nNiet alle velden werden ingevuld.", "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 5
0
        private void Button_Click_Reset(object sender, RoutedEventArgs e)
        {
            using (var ctx = new OrderManagerContext())
            {
                var collection = ctx.Products.GroupJoin(ctx.Suppliers,
                                                        p => p.Supplier.SupplierId,
                                                        s => s.SupplierId,
                                                        (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name }).ToList();

                dgMagazijn.ItemsSource = collection;

                int    stock = 0;
                double price = 0;

                foreach (var item in collection)
                {
                    stock += item.Stock;
                    price += item.Stock * item.UnitPrice;
                }

                tbAantal.Text = stock.ToString();
                tbPrijs.Text  = $"€ {price}";
            }
            txtFilterNaam.Text       = null;
            txtMinPrijs.Text         = null;
            txtMaxPrijs.Text         = null;
            txtMinStock.Text         = null;
            txtMaxStock.Text         = null;
            cbSuppliers.SelectedItem = null;
        }
        private void Button_Click_EditCustomer(object sender, RoutedEventArgs e)
        {
            if (cbCustomersEdit.SelectedItem != null)
            {
                Customer selected = cbCustomersEdit.SelectedItem as Customer;

                using (var ctx = new OrderManagerContext())
                {
                    ctx.Customers.FirstOrDefault(c => c.CustomerId == selected.CustomerId).Name    = txtNaamCustomerEdit.Text;
                    ctx.Customers.FirstOrDefault(c => c.CustomerId == selected.CustomerId).Address = txtAdresCustomerEdit.Text;
                    ctx.SaveChanges();

                    dgCustomersAdd.ItemsSource = null;
                    dgCustomersAdd.ItemsSource = ctx.Customers.ToList();

                    dgCustomersEdit.ItemsSource = null;
                    dgCustomersEdit.ItemsSource = ctx.Customers.ToList();
                    cbCustomersEdit.ItemsSource = ctx.Customers.ToList();

                    dgCustomersDelete.ItemsSource = null;
                    dgCustomersDelete.ItemsSource = ctx.Customers.ToList();
                    cbCustomersDelete.ItemsSource = ctx.Customers.ToList();
                }
                MessageBox.Show("De wijzigingen werden opgeslagen.", "", MessageBoxButton.OK, MessageBoxImage.Information);
                txtNaamCustomerEdit.Clear();
                txtAdresCustomerEdit.Clear();
            }
            else
            {
                MessageBox.Show("Gelieve eerst een klant te selecteren.", "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        public OverzichtKlanten()
        {
            InitializeComponent();

            lblUser.Content = $"{ActiveUser.FirstName} {ActiveUser.LastName} ({ActiveUser.Role})";

            using (var ctx = new OrderManagerContext())
            {
                var collection = ctx.OrderDetails.Join(ctx.Products,
                                                       od => od.Product.ProductId,
                                                       p => p.ProductId,
                                                       (od, p) => new { od, p });

                int    sales   = 0;
                double revenue = 0;

                foreach (var item in collection)
                {
                    sales   += item.od.Quantity;
                    revenue += item.p.UnitPrice * item.od.Quantity;
                }

                tbAfzet.Text = $"{sales} stuks";
                tbOmzet.Text = $"€ {string.Format("{0:0.00}", revenue)}";


                var coll = collection.GroupBy(c => c.od.Order.Customer.CustomerId);

                dgKlanten.ItemsSource = ctx.Customers.Join(coll,
                                                           cu => cu.CustomerId,
                                                           c => c.Key,
                                                           (cu, c) => new { Name = cu.Name, Address = cu.Address, Sales = c.Sum(s => s.od.Quantity), Revenue = c.Sum(s => s.p.UnitPrice * s.od.Quantity) }).ToList();
            }
        }
        private void Button_Click_Filter(object sender, RoutedEventArgs e)
        {
            if (dpVan.SelectedDate != null && dpTot.SelectedDate != null)
            {
                using (var ctx = new OrderManagerContext())
                {
                    var collection = ctx.OrderDetails.Join(ctx.Products,
                                                           od => od.Product.ProductId,
                                                           p => p.ProductId,
                                                           (od, p) => new { od, p })
                                     .GroupBy(c => c.od.Order.OrderId);

                    dgOrders.ItemsSource = ctx.Orders.Join(collection,
                                                           o => o.OrderId,
                                                           c => c.Key,
                                                           (o, c) => new { OrderId = o.OrderId, Name = o.Customer.Name, OrderDate = o.OrderDate, TotalQ = c.Sum(s => s.od.Quantity), TotalP = c.Sum(s => s.od.Product.UnitPrice * s.od.Quantity) })
                                           .Where(w => w.OrderDate >= dpVan.SelectedDate && w.OrderDate <= dpTot.SelectedDate)
                                           .ToList();

                    cbOrders.ItemsSource = ctx.Orders.Where(w => w.OrderDate >= dpVan.SelectedDate && w.OrderDate <= dpTot.SelectedDate).ToList();
                }
            }
            else
            {
                MessageBox.Show("Gelieve een begin- en einddatum in te vullen.", "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 9
0
        public OverzichtAdmin()
        {
            InitializeComponent();

            lblUser.Content = $"{ActiveUser.FirstName} {ActiveUser.LastName} ({ActiveUser.Role})";

            using (var ctx = new OrderManagerContext())
            {
                var collectionPS = ctx.Products.GroupJoin(ctx.Suppliers,
                                                          p => p.Supplier.SupplierId,
                                                          s => s.SupplierId,
                                                          (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name }).ToList();

                dgMagazijn.ItemsSource = collectionPS;

                cbSuppliers.ItemsSource = ctx.Suppliers.ToList();

                int    stock = 0;
                double price = 0;

                foreach (var item in collectionPS)
                {
                    stock += item.Stock;
                    price += item.Stock * item.UnitPrice;
                }

                tbAantal.Text = stock.ToString();
                tbPrijs.Text  = $"€ {string.Format("{0:0.00}", price)}";

                var collectionOdP = ctx.OrderDetails.Join(ctx.Products,
                                                          od => od.Product.ProductId,
                                                          p => p.ProductId,
                                                          (od, p) => new { od, p });

                int    sales   = 0;
                double revenue = 0;

                foreach (var item in collectionOdP)
                {
                    sales   += item.od.Quantity;
                    revenue += item.p.UnitPrice * item.od.Quantity;
                }

                tbAfzet.Text = $"{sales} stuks";
                tbOmzet.Text = $"€ {string.Format("{0:0.00}", revenue)}";


                var coll = collectionOdP.GroupBy(c => c.od.Order.Customer.CustomerId);

                dgKlanten.ItemsSource = ctx.Customers.Join(coll,
                                                           cu => cu.CustomerId,
                                                           c => c.Key,
                                                           (cu, c) => new { Name = cu.Name, Address = cu.Address, Sales = c.Sum(s => s.od.Quantity), Revenue = c.Sum(s => s.p.UnitPrice * s.od.Quantity) }).ToList();
            }
        }
Esempio n. 10
0
        private void Button_Click_EditSupplier(object sender, RoutedEventArgs e)
        {
            if (cbSuppliersSupplierEdit.SelectedItem != null)
            {
                Supplier selected = cbSuppliersSupplierEdit.SelectedItem as Supplier;

                using (var ctx = new OrderManagerContext())
                {
                    ctx.Suppliers.FirstOrDefault(s => s.SupplierId == selected.SupplierId).Name    = txtNaamSupplierEdit.Text;
                    ctx.Suppliers.FirstOrDefault(s => s.SupplierId == selected.SupplierId).Address = txtAdresSupplierEdit.Text;
                    ctx.SaveChanges();

                    dgSuppliersAdd.ItemsSource = null;
                    dgSuppliersAdd.ItemsSource = ctx.Suppliers.ToList();
                    cbSuppliersAdd.ItemsSource = ctx.Suppliers.ToList();

                    dgSuppliersEdit.ItemsSource         = null;
                    dgSuppliersEdit.ItemsSource         = ctx.Suppliers.ToList();
                    cbSuppliersSupplierEdit.ItemsSource = ctx.Suppliers.ToList();

                    dgSuppliersDelete.ItemsSource = null;
                    dgSuppliersDelete.ItemsSource = ctx.Suppliers.ToList();
                    cbSuppliersDelete.ItemsSource = ctx.Suppliers.ToList();

                    dgProductsAdd.ItemsSource = null;
                    dgProductsAdd.ItemsSource = ctx.Products.GroupJoin(ctx.Suppliers,
                                                                       p => p.Supplier.SupplierId,
                                                                       s => s.SupplierId,
                                                                       (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name }).ToList();

                    dgProductsEdit.ItemsSource = null;
                    dgProductsEdit.ItemsSource = ctx.Products.GroupJoin(ctx.Suppliers,
                                                                        p => p.Supplier.SupplierId,
                                                                        s => s.SupplierId,
                                                                        (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name }).ToList();
                    cbSuppliersProductEdit.ItemsSource = ctx.Suppliers.ToList();

                    dgProductsDelete.ItemsSource = null;
                    dgProductsDelete.ItemsSource = ctx.Products.GroupJoin(ctx.Suppliers,
                                                                          p => p.Supplier.SupplierId,
                                                                          s => s.SupplierId,
                                                                          (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name }).ToList();
                }
                MessageBox.Show("De wijzigingen werden opgeslagen.", "", MessageBoxButton.OK, MessageBoxImage.Information);
                txtNaamSupplierEdit.Clear();
                txtAdresSupplierEdit.Clear();
            }
            else
            {
                MessageBox.Show("Gelieve eerst een leverancier te selecteren.", "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        public void NewPDF(int orderId)
        {
            PdfDocument doc   = new PdfDocument();
            PdfPage     page  = doc.AddPage();
            XGraphics   graph = XGraphics.FromPdfPage(page);
            XFont       font  = new XFont("Calibri", 12, XFontStyle.Bold);
            XImage      logo  = XImage.FromFile("C:/Users/nickz/source/repos/Tussentijds Project/Tussentijds Project/images/logo.png");
            XPen        pen   = new XPen(XColors.Black, 2);

            List <OrderDetail> details = new List <OrderDetail>();
            Order    order;
            Customer customer;

            using (var ctx = new OrderManagerContext())
            {
                details  = ctx.OrderDetails.Where(od => od.Order.OrderId == orderId).ToList();
                order    = ctx.Orders.Where(o => o.OrderId == orderId).FirstOrDefault();
                customer = ctx.Customers.Where(c => c.CustomerId == order.Customer.CustomerId).FirstOrDefault();

                for (int i = 0; i <= details.Count - 1; i++)
                {
                    graph.DrawString($"{details[i].Product.Name}", font, XBrushes.Black, new XRect(10, 420 + (i * 20), 100, 0));
                    graph.DrawString($"{details[i].Quantity}", font, XBrushes.Black, new XRect(340, 420 + (i * 20), 100, 0));
                    graph.DrawString($"€ {string.Format("{0:0.00}", details[i].Product.UnitPrice * details[i].Quantity)}", font, XBrushes.Black, new XRect(440, 420 + (i * 20), 100, 0));
                    graph.DrawLine(pen, 10, 425 + (i * 20), 580, 425 + (i * 20));
                }
            }

            graph.DrawImage(logo, new XRect(5, 0, 100, 100));
            graph.DrawString("NZ Shipping BVBA", font, XBrushes.Black, new XRect(10, 105, 100, 0));
            graph.DrawString("Kazerneweg 71", font, XBrushes.Black, new XRect(10, 115, 100, 0));
            graph.DrawString("2950 Kapellen", font, XBrushes.Black, new XRect(10, 125, 100, 0));

            graph.DrawString($"Klant: {order.Customer.Name}", font, XBrushes.Black, new XRect(10, 200, 100, 0));
            graph.DrawString($"ID Bestelling: {order.OrderId}", font, XBrushes.Black, new XRect(10, 220, 100, 0));
            graph.DrawString($"Besteldatum: {order.OrderDate.ToString("dd/MM/yyyy")}", font, XBrushes.Black, new XRect(10, 240, 100, 0));

            graph.DrawString("Naam Product", font, XBrushes.Black, new XRect(10, 390, 100, 0));
            graph.DrawString("Aantal", font, XBrushes.Black, new XRect(340, 390, 100, 0));
            graph.DrawString("Prijs", font, XBrushes.Black, new XRect(440, 390, 100, 0));

            graph.DrawString($"Totale Prijs (excl. BTW): € {string.Format("{0:0.00}", TotalePrijs(details))}", font, XBrushes.Black, new XRect(10, 420 + (details.Count * 20), 100, 0));
            graph.DrawString("BTW: 21%", font, XBrushes.Black, new XRect(10, 420 + (details.Count * 20) + 20, 100, 0));
            graph.DrawString($"TOTALE PRIJS (incl. BTW): € {string.Format("{0:0.00}", TotalePrijsBtw(details))}", font, XBrushes.Black, new XRect(10, 420 + (details.Count * 20) + 40, 100, 0));

            string filename = "C:/Users/nickz/source/repos/Tussentijds Project/Tussentijds Project/docs/factuur.pdf";

            doc.Save(filename);
            Process.Start(filename);
        }
        private void Button_Click_Finish(object sender, RoutedEventArgs e)
        {
            if (cbCustomersAdd.SelectedItem != null && dpOrderAdd.SelectedDate != null && lbProductsAdd.Items != null)
            {
                Customer selected = cbCustomersAdd.SelectedItem as Customer;

                using (var ctx = new OrderManagerContext())
                {
                    Order order = new Order {
                        Customer = ctx.Customers.FirstOrDefault(c => c.CustomerId == selected.CustomerId), OrderDate = (DateTime)dpOrderAdd.SelectedDate, OrderDetails = new List <OrderDetail>()
                    };

                    foreach (Tuple <Product, int> item in lbProductsAdd.Items)
                    {
                        OrderDetail detail = new OrderDetail {
                            Product = ctx.Products.FirstOrDefault(p => p.ProductId == item.Item1.ProductId), Quantity = item.Item2
                        };
                        order.OrderDetails.Add(detail);
                        ctx.Products.FirstOrDefault(p => p.ProductId == detail.Product.ProductId).Stock = detail.Product.Stock - detail.Quantity;
                    }
                    ctx.Orders.Add(order);
                    ctx.SaveChanges();

                    dgOrders.ItemsSource = null;

                    var collection = ctx.OrderDetails.Join(ctx.Products,
                                                           od => od.Product.ProductId,
                                                           p => p.ProductId,
                                                           (sc, p) => new { sc, p })
                                     .GroupBy(c => c.sc.Order.OrderId);

                    dgOrders.ItemsSource = ctx.Orders.Join(collection,
                                                           o => o.OrderId,
                                                           c => c.Key,
                                                           (o, c) => new { OrderId = o.OrderId, Name = o.Customer.Name, OrderDate = o.OrderDate, TotalQ = c.Sum(s => s.sc.Quantity), TotalP = c.Sum(s => s.sc.Product.UnitPrice * s.sc.Quantity) })
                                           .ToList();

                    cbOrders.ItemsSource = ctx.Orders.ToList();
                }
                MessageBox.Show("Bestelling werd aangemaakt.", "", MessageBoxButton.OK, MessageBoxImage.Information);
                cbCustomersAdd.SelectedItem = null;
                dpOrderAdd.SelectedDate     = null;
                lbProductsAdd.Items.Clear();
            }
            else
            {
                MessageBox.Show("Bestelling aanmaken mislukt!\nNiet alle velden werden ingevuld.", "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void btnProducts_Click(object sender, RoutedEventArgs e)
        {
            dgKlanten.Visibility   = Visibility.Hidden;
            dgVerkocht.Visibility  = Visibility.Visible;
            btnCustomers.IsEnabled = true;
            btnProducts.IsEnabled  = false;

            using (var ctx = new OrderManagerContext())
            {
                dgVerkocht.ItemsSource = ctx.OrderDetails.GroupBy(od => od.Product.ProductId).Join(ctx.Products,
                                                                                                   od => od.Key,
                                                                                                   p => p.ProductId,
                                                                                                   (od, p) => new { Name = p.Name, UnitPrice = p.UnitPrice, Sales = od.Sum(s => s.Quantity), Revenue = od.Sum(s => s.Product.UnitPrice * s.Quantity) }).ToList();
            }
        }
Esempio n. 14
0
        private void Button_Click_FilterStock(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(txtMinStock.Text))
            {
                txtMinStock.Text = "0";
            }
            if (string.IsNullOrEmpty(txtMaxStock.Text))
            {
                txtMaxStock.Text = "0";
            }

            int MinStock = int.Parse(txtMinStock.Text);
            int MaxStock = int.Parse(txtMaxStock.Text);

            using (var ctx = new OrderManagerContext())
            {
                var filter = ctx.Products.GroupJoin(ctx.Suppliers,
                                                    p => p.Supplier.SupplierId,
                                                    s => s.SupplierId,
                                                    (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name })
                             .Where(f => f.Stock >= MinStock && f.Stock <= MaxStock).ToList();

                if (filter.Count != 0)
                {
                    dgMagazijn.ItemsSource = null;
                    dgMagazijn.ItemsSource = filter;

                    int    stock = 0;
                    double price = 0;

                    foreach (var item in filter)
                    {
                        stock += item.Stock;
                        price += item.Stock * item.UnitPrice;
                    }

                    tbAantal.Text = stock.ToString();
                    tbPrijs.Text  = $"€ {price}";
                }
                else
                {
                    dgMagazijn.ItemsSource = null;
                    tbAantal.Text          = "0";
                    tbPrijs.Text           = "0";
                    MessageBox.Show("Geen resultaat.", "", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
            }
        }
Esempio n. 15
0
        private void Button_Click_EditUser(object sender, RoutedEventArgs e)
        {
            if (cbUsersEdit.SelectedItem != null)
            {
                User selectedUser = cbUsersEdit.SelectedItem as User;
                Role selectedRole = cbRolesEdit.SelectedItem as Role;

                using (var ctx = new OrderManagerContext())
                {
                    ctx.Users.FirstOrDefault(u => u.UserId == selectedUser.UserId).FirstName = txtVoornaamEdit.Text;
                    ctx.Users.FirstOrDefault(u => u.UserId == selectedUser.UserId).LastName  = txtAchternaamEdit.Text;
                    ctx.Users.FirstOrDefault(u => u.UserId == selectedUser.UserId).Username  = txtUsernameEdit.Text;
                    ctx.Users.FirstOrDefault(u => u.UserId == selectedUser.UserId).Password  = Encryption(txtPasswordEdit.Text);
                    ctx.Users.FirstOrDefault(u => u.UserId == selectedUser.UserId).Role      = ctx.Roles.FirstOrDefault(r => r.RoleId == selectedRole.RoleId);
                    ctx.SaveChanges();

                    dgUsersAdd.ItemsSource = null;
                    dgUsersAdd.ItemsSource = ctx.Users.Join(ctx.Roles,
                                                            u => u.Role.RoleId,
                                                            r => r.RoleId,
                                                            (u, r) => new { FirstName = u.FirstName, LastName = u.LastName, Username = u.Username, Password = u.Password, Role = r.Name }).ToList();

                    dgUsersEdit.ItemsSource = null;
                    dgUsersEdit.ItemsSource = ctx.Users.Join(ctx.Roles,
                                                             u => u.Role.RoleId,
                                                             r => r.RoleId,
                                                             (u, r) => new { FirstName = u.FirstName, LastName = u.LastName, Username = u.Username, Password = u.Password, Role = r.Name }).ToList();
                    cbUsersEdit.ItemsSource = ctx.Users.ToList();

                    dgUsersDelete.ItemsSource = null;
                    dgUsersDelete.ItemsSource = ctx.Users.Join(ctx.Roles,
                                                               u => u.Role.RoleId,
                                                               r => r.RoleId,
                                                               (u, r) => new { FirstName = u.FirstName, LastName = u.LastName, Username = u.Username, Password = u.Password, Role = r.Name }).ToList();
                    cbUsersDelete.ItemsSource = ctx.Users.ToList();
                }
                MessageBox.Show("De wijzigingen werden opgeslagen.", "", MessageBoxButton.OK, MessageBoxImage.Information);
                txtVoornaamEdit.Clear();
                txtAchternaamEdit.Clear();
                txtUsernameEdit.Clear();
                txtPasswordEdit.Clear();
                cbRolesEdit.SelectedItem = null;
            }
            else
            {
                MessageBox.Show("Gelieve eerst een user te selecteren.", "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 16
0
        private void Button_Click_EditProduct(object sender, RoutedEventArgs e)
        {
            if (cbProductsEdit.SelectedItem != null)
            {
                Product  selectedProduct  = cbProductsEdit.SelectedItem as Product;
                Supplier selectedSupplier = cbSuppliersProductEdit.SelectedItem as Supplier;

                using (var ctx = new OrderManagerContext())
                {
                    ctx.Products.FirstOrDefault(p => p.ProductId == selectedProduct.ProductId).Name      = txtNaamProductEdit.Text;
                    ctx.Products.FirstOrDefault(p => p.ProductId == selectedProduct.ProductId).UnitPrice = Convert.ToDouble(txtPrijsEdit.Text);
                    ctx.Products.FirstOrDefault(p => p.ProductId == selectedProduct.ProductId).Stock     = Convert.ToInt32(txtAantalEdit.Text);
                    ctx.Products.FirstOrDefault(p => p.ProductId == selectedProduct.ProductId).Supplier  = ctx.Suppliers.FirstOrDefault(s => s.SupplierId == selectedSupplier.SupplierId);
                    ctx.SaveChanges();

                    dgProductsAdd.ItemsSource = null;
                    dgProductsAdd.ItemsSource = ctx.Products.GroupJoin(ctx.Suppliers,
                                                                       p => p.Supplier.SupplierId,
                                                                       s => s.SupplierId,
                                                                       (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name }).ToList();

                    dgProductsEdit.ItemsSource = null;
                    dgProductsEdit.ItemsSource = ctx.Products.GroupJoin(ctx.Suppliers,
                                                                        p => p.Supplier.SupplierId,
                                                                        s => s.SupplierId,
                                                                        (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name }).ToList();
                    cbProductsEdit.ItemsSource = ctx.Products.ToList();

                    dgProductsDelete.ItemsSource = null;
                    dgProductsDelete.ItemsSource = ctx.Products.GroupJoin(ctx.Suppliers,
                                                                          p => p.Supplier.SupplierId,
                                                                          s => s.SupplierId,
                                                                          (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name }).ToList();
                    cbProductsDelete.ItemsSource = ctx.Products.ToList();
                }
                MessageBox.Show("De wijzigingen werden opgeslagen.", "", MessageBoxButton.OK, MessageBoxImage.Information);
                txtNaamProductEdit.Clear();
                txtPrijsEdit.Clear();
                txtAantalEdit.Clear();
                cbSuppliersProductEdit.SelectedItem = null;
            }
            else
            {
                MessageBox.Show("Gelieve eerst een product te selecteren.", "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 17
0
        private void Button_Click_AddProduct(object sender, RoutedEventArgs e)
        {
            if (txtNaamProductAdd.Text != null && txtPrijsAdd.Text != null && txtAantalAdd.Text != null && cbSuppliersAdd.SelectedItem != null)
            {
                Supplier selected = cbSuppliersAdd.SelectedItem as Supplier;

                using (var ctx = new OrderManagerContext())
                {
                    ctx.Products.Add(new Product()
                    {
                        Name = txtNaamProductAdd.Text, UnitPrice = Convert.ToDouble(txtPrijsAdd.Text), Stock = Convert.ToInt32(txtAantalAdd.Text), Supplier = ctx.Suppliers.FirstOrDefault(s => s.SupplierId == selected.SupplierId)
                    });
                    ctx.SaveChanges();

                    dgProductsAdd.ItemsSource = null;
                    dgProductsAdd.ItemsSource = ctx.Products.GroupJoin(ctx.Suppliers,
                                                                       p => p.Supplier.SupplierId,
                                                                       s => s.SupplierId,
                                                                       (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name }).ToList();

                    dgProductsEdit.ItemsSource = null;
                    dgProductsEdit.ItemsSource = ctx.Products.GroupJoin(ctx.Suppliers,
                                                                        p => p.Supplier.SupplierId,
                                                                        s => s.SupplierId,
                                                                        (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name }).ToList();
                    cbProductsEdit.ItemsSource = ctx.Products.ToList();

                    dgProductsDelete.ItemsSource = null;
                    dgProductsDelete.ItemsSource = ctx.Products.GroupJoin(ctx.Suppliers,
                                                                          p => p.Supplier.SupplierId,
                                                                          s => s.SupplierId,
                                                                          (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name }).ToList();
                    cbProductsDelete.ItemsSource = ctx.Products.ToList();
                }
                MessageBox.Show("Product werd toegevoegd.", "", MessageBoxButton.OK, MessageBoxImage.Information);
                txtNaamProductAdd.Clear();
                txtPrijsAdd.Clear();
                txtAantalAdd.Clear();
                cbSuppliersAdd.SelectedItem = null;
            }
            else
            {
                MessageBox.Show("Product toevoegen mislukt!\nNiet alle velden werden ingevuld.", "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 18
0
        private void Button_Click_FilterSupplier(object sender, RoutedEventArgs e)
        {
            Supplier selected = cbSuppliers.SelectedItem as Supplier;

            using (var ctx = new OrderManagerContext())
            {
                if (cbSuppliers.SelectedItem != null)
                {
                    var filter = ctx.Products.GroupJoin(ctx.Suppliers,
                                                        p => p.Supplier.SupplierId,
                                                        s => s.SupplierId,
                                                        (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name })
                                 .Where(f => f.Supplier == selected.Name).ToList();

                    if (filter.Count != 0)
                    {
                        dgMagazijn.ItemsSource = null;
                        dgMagazijn.ItemsSource = filter;

                        int    stock = 0;
                        double price = 0;

                        foreach (var item in filter)
                        {
                            stock += item.Stock;
                            price += item.Stock * item.UnitPrice;
                        }

                        tbAantal.Text = stock.ToString();
                        tbPrijs.Text  = $"€ {price}";
                    }
                    else
                    {
                        dgMagazijn.ItemsSource = null;
                        tbAantal.Text          = "0";
                        tbPrijs.Text           = "0";
                        MessageBox.Show("Geen resultaat.", "", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    }
                }
                else
                {
                    MessageBox.Show("Gelieve eerst een leverancier te selecteren.", "", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
        public DatabeheerKlanten()
        {
            InitializeComponent();

            lblUser.Content = $"{ActiveUser.FirstName} {ActiveUser.LastName} ({ActiveUser.Role})";


            using (var ctx = new OrderManagerContext())
            {
                dgCustomersAdd.ItemsSource = ctx.Customers.ToList();

                dgCustomersEdit.ItemsSource = ctx.Customers.ToList();
                cbCustomersEdit.ItemsSource = ctx.Customers.ToList();

                dgCustomersDelete.ItemsSource = ctx.Customers.ToList();
                cbCustomersDelete.ItemsSource = ctx.Customers.ToList();
            }
        }
Esempio n. 20
0
        private void Button_Click_AddUser(object sender, RoutedEventArgs e)
        {
            if (txtVoornaamAdd.Text != null && txtAchternaamAdd.Text != null && txtUsernameAdd.Text != null && txtPasswordAdd.Text != null && cbRolesAdd.SelectedItem != null)
            {
                Role selected = cbRolesAdd.SelectedItem as Role;

                using (var ctx = new OrderManagerContext())
                {
                    ctx.Users.Add(new User(txtVoornaamAdd.Text, txtAchternaamAdd.Text, txtUsernameAdd.Text, txtPasswordAdd.Text, ctx.Roles.FirstOrDefault(r => r.RoleId == selected.RoleId)));
                    ctx.SaveChanges();

                    dgUsersAdd.ItemsSource = null;
                    dgUsersAdd.ItemsSource = ctx.Users.Join(ctx.Roles,
                                                            u => u.Role.RoleId,
                                                            r => r.RoleId,
                                                            (u, r) => new { FirstName = u.FirstName, LastName = u.LastName, Username = u.Username, Password = u.Password, Role = r.Name }).ToList();

                    dgUsersEdit.ItemsSource = null;
                    dgUsersEdit.ItemsSource = ctx.Users.Join(ctx.Roles,
                                                             u => u.Role.RoleId,
                                                             r => r.RoleId,
                                                             (u, r) => new { FirstName = u.FirstName, LastName = u.LastName, Username = u.Username, Password = u.Password, Role = r.Name }).ToList();
                    cbUsersEdit.ItemsSource = ctx.Users.ToList();

                    dgUsersDelete.ItemsSource = null;
                    dgUsersDelete.ItemsSource = ctx.Users.Join(ctx.Roles,
                                                               u => u.Role.RoleId,
                                                               r => r.RoleId,
                                                               (u, r) => new { FirstName = u.FirstName, LastName = u.LastName, Username = u.Username, Password = u.Password, Role = r.Name }).ToList();
                    cbUsersDelete.ItemsSource = ctx.Users.ToList();
                }
                MessageBox.Show("User werd toegevoegd.", "", MessageBoxButton.OK, MessageBoxImage.Information);
                txtVoornaamAdd.Clear();
                txtAchternaamAdd.Clear();
                txtUsernameAdd.Clear();
                txtPasswordAdd.Clear();
                cbRolesAdd.SelectedItem = null;
            }
            else
            {
                MessageBox.Show("User toevoegen mislukt!\nNiet alle velden werden ingevuld.", "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void Button_Click_Details(object sender, RoutedEventArgs e)
        {
            if (cbOrders.SelectedItem != null)
            {
                Order selected = cbOrders.SelectedItem as Order;

                using (var ctx = new OrderManagerContext())
                {
                    dgOrderDetails.ItemsSource = ctx.OrderDetails
                                                 .Where(od => od.Order.OrderId == selected.OrderId)
                                                 .Select(od => new { Name = od.Product.Name, Quantity = od.Quantity, UnitPrice = od.Product.UnitPrice, Total = od.Product.UnitPrice * od.Quantity })
                                                 .ToList();
                }
            }
            else
            {
                MessageBox.Show("Gelieve eerst een bestelling te selecteren.", "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void btnCustomers_Click(object sender, RoutedEventArgs e)
        {
            dgVerkocht.Visibility  = Visibility.Hidden;
            dgKlanten.Visibility   = Visibility.Visible;
            btnProducts.IsEnabled  = true;
            btnCustomers.IsEnabled = false;

            using (var ctx = new OrderManagerContext())
            {
                var collection = ctx.OrderDetails.Join(ctx.Products,
                                                       od => od.Product.ProductId,
                                                       p => p.ProductId,
                                                       (od, p) => new { od, p })
                                 .GroupBy(c => c.od.Order.Customer.CustomerId);;

                dgKlanten.ItemsSource = ctx.Customers.Join(collection,
                                                           cu => cu.CustomerId,
                                                           c => c.Key,
                                                           (cu, c) => new { Name = cu.Name, Address = cu.Address, Sales = c.Sum(s => s.od.Quantity), Revenue = c.Sum(s => s.p.UnitPrice * s.od.Quantity) }).ToList();
            }
        }
        private void Button_Click_Reset(object sender, RoutedEventArgs e)
        {
            using (var ctx = new OrderManagerContext())
            {
                var collection = ctx.OrderDetails.Join(ctx.Products,
                                                       od => od.Product.ProductId,
                                                       p => p.ProductId,
                                                       (od, p) => new { od, p })
                                 .GroupBy(c => c.od.Order.OrderId);

                dgOrders.ItemsSource = ctx.Orders.Join(collection,
                                                       o => o.OrderId,
                                                       c => c.Key,
                                                       (o, c) => new { OrderId = o.OrderId, Name = o.Customer.Name, OrderDate = o.OrderDate, TotalQ = c.Sum(s => s.od.Quantity), TotalP = c.Sum(s => s.od.Product.UnitPrice * s.od.Quantity) })
                                       .ToList();

                cbOrders.ItemsSource = ctx.Orders.ToList();
            }
            dpVan.SelectedDate = null;
            dpTot.SelectedDate = null;
        }
        private void Button_Click_DeleteCustomer(object sender, RoutedEventArgs e)
        {
            if (cbCustomersDelete.SelectedItem != null)
            {
                Customer selected = cbCustomersDelete.SelectedItem as Customer;

                using (var ctx = new OrderManagerContext())
                {
                    ctx.OrderDetails.RemoveRange(ctx.OrderDetails.Where(od => od.Order.Customer.CustomerId == selected.CustomerId));
                    ctx.Orders.RemoveRange(ctx.Orders.Where(o => o.Customer.CustomerId == selected.CustomerId));
                    ctx.Customers.Remove(ctx.Customers.FirstOrDefault(c => c.CustomerId == selected.CustomerId));

                    var collection = ctx.OrderDetails.Join(ctx.Products, od => od.Product.ProductId, p => p.ProductId, (od, p) => new { od, p })
                                     .Join(ctx.Customers, sc => sc.od.Order.Customer.CustomerId, cu => cu.CustomerId, (sc, cu) => new { sc, cu })
                                     .Where(c => c.cu.CustomerId == selected.CustomerId).ToList();

                    foreach (var item in collection)
                    {
                        ctx.Products.FirstOrDefault(p => p.ProductId == item.sc.p.ProductId).Stock = item.sc.p.Stock + item.sc.od.Quantity;
                    }
                    ctx.SaveChanges();

                    dgCustomersAdd.ItemsSource = null;
                    dgCustomersAdd.ItemsSource = ctx.Customers.ToList();

                    dgCustomersEdit.ItemsSource = null;
                    dgCustomersEdit.ItemsSource = ctx.Customers.ToList();
                    cbCustomersEdit.ItemsSource = ctx.Customers.ToList();

                    dgCustomersDelete.ItemsSource = null;
                    dgCustomersDelete.ItemsSource = ctx.Customers.ToList();
                    cbCustomersDelete.ItemsSource = ctx.Customers.ToList();
                }
                MessageBox.Show("De klant werd verwijderd.", "", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                MessageBox.Show("Gelieve eerst een klant te selecteren.", "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 25
0
        private void Button_Click_DeleteProduct(object sender, RoutedEventArgs e)
        {
            if (cbProductsDelete.SelectedItem != null)
            {
                Product selected = cbProductsDelete.SelectedItem as Product;

                using (var ctx = new OrderManagerContext())
                {
                    ctx.OrderDetails.RemoveRange(ctx.OrderDetails.Where(od => od.Product.ProductId == selected.ProductId));
                    ctx.Products.Remove(ctx.Products.FirstOrDefault(p => p.ProductId == selected.ProductId));
                    ctx.SaveChanges();

                    dgProductsAdd.ItemsSource = null;
                    dgProductsAdd.ItemsSource = ctx.Products.GroupJoin(ctx.Suppliers,
                                                                       p => p.Supplier.SupplierId,
                                                                       s => s.SupplierId,
                                                                       (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name }).ToList();

                    dgProductsEdit.ItemsSource = null;
                    dgProductsEdit.ItemsSource = ctx.Products.GroupJoin(ctx.Suppliers,
                                                                        p => p.Supplier.SupplierId,
                                                                        s => s.SupplierId,
                                                                        (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name }).ToList();
                    cbProductsEdit.ItemsSource = ctx.Products.ToList();

                    dgProductsDelete.ItemsSource = null;
                    dgProductsDelete.ItemsSource = ctx.Products.GroupJoin(ctx.Suppliers,
                                                                          p => p.Supplier.SupplierId,
                                                                          s => s.SupplierId,
                                                                          (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name }).ToList();
                    cbProductsDelete.ItemsSource = ctx.Products.ToList();
                }
                MessageBox.Show("Het product werd verwijderd.", "", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                MessageBox.Show("Gelieve eerst een product te selecteren.", "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 26
0
        public void CreateDB()
        {
            using (var ctx = new OrderManagerContext())
            {
                ctx.Roles.Add(new Role()
                {
                    Name = "Administrator"
                });
                ctx.Roles.Add(new Role()
                {
                    Name = "Magazijnier"
                });
                ctx.Roles.Add(new Role()
                {
                    Name = "Verkoper"
                });
                ctx.SaveChanges();

                ctx.Users.Add(new User("Nick", "Zubrzycki", "nickz", "nz1983", ctx.Roles.FirstOrDefault(r => r.RoleId == 1)));
                ctx.SaveChanges();
            }
        }
Esempio n. 27
0
        private void Button_Click_DeleteUser(object sender, RoutedEventArgs e)
        {
            if (cbUsersDelete.SelectedItem != null)
            {
                User selected = cbUsersDelete.SelectedItem as User;

                using (var ctx = new OrderManagerContext())
                {
                    ctx.Users.Remove(ctx.Users.FirstOrDefault(u => u.UserId == selected.UserId));
                    ctx.SaveChanges();

                    dgUsersAdd.ItemsSource = null;
                    dgUsersAdd.ItemsSource = ctx.Users.Join(ctx.Roles,
                                                            u => u.Role.RoleId,
                                                            r => r.RoleId,
                                                            (u, r) => new { FirstName = u.FirstName, LastName = u.LastName, Username = u.Username, Password = u.Password, Role = r.Name }).ToList();

                    dgUsersEdit.ItemsSource = null;
                    dgUsersEdit.ItemsSource = ctx.Users.Join(ctx.Roles,
                                                             u => u.Role.RoleId,
                                                             r => r.RoleId,
                                                             (u, r) => new { FirstName = u.FirstName, LastName = u.LastName, Username = u.Username, Password = u.Password, Role = r.Name }).ToList();
                    cbUsersEdit.ItemsSource = ctx.Users.ToList();

                    dgUsersDelete.ItemsSource = null;
                    dgUsersDelete.ItemsSource = ctx.Users.Join(ctx.Roles,
                                                               u => u.Role.RoleId,
                                                               r => r.RoleId,
                                                               (u, r) => new { FirstName = u.FirstName, LastName = u.LastName, Username = u.Username, Password = u.Password, Role = r.Name }).ToList();
                    cbUsersDelete.ItemsSource = ctx.Users.ToList();
                }
                MessageBox.Show("De user werd verwijderd.", "", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                MessageBox.Show("Gelieve eerst een user te selecteren.", "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void Button_Click_Delete(object sender, RoutedEventArgs e)
        {
            if (cbOrders.SelectedItem != null)
            {
                Order selected = cbOrders.SelectedItem as Order;

                using (var ctx = new OrderManagerContext())
                {
                    ctx.Orders.Remove(ctx.Orders.FirstOrDefault(o => o.OrderId == selected.OrderId));
                    ctx.OrderDetails.RemoveRange(ctx.OrderDetails.Where(od => od.Order.OrderId == selected.OrderId));

                    foreach (OrderDetail item in selected.OrderDetails)
                    {
                        ctx.Products.FirstOrDefault(p => p.ProductId == item.Product.ProductId).Stock = item.Product.Stock + item.Quantity;
                    }
                    ctx.SaveChanges();

                    var collection = ctx.OrderDetails.Join(ctx.Products,
                                                           od => od.Product.ProductId,
                                                           p => p.ProductId,
                                                           (sc, p) => new { sc, p })
                                     .GroupBy(c => c.sc.Order.OrderId);

                    dgOrders.ItemsSource = ctx.Orders.Join(collection,
                                                           o => o.OrderId,
                                                           c => c.Key,
                                                           (o, c) => new { OrderId = o.OrderId, Name = o.Customer.Name, OrderDate = o.OrderDate, TotalQ = c.Sum(s => s.sc.Quantity), TotalP = c.Sum(s => s.sc.Product.UnitPrice * s.sc.Quantity) })
                                           .ToList();

                    cbOrders.ItemsSource = ctx.Orders.ToList();
                }
                MessageBox.Show("De bestelling werd verwijderd.", "", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                MessageBox.Show("Gelieve eerst een bestelling te selecteren.", "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        public DatabeheerMagazijn()
        {
            InitializeComponent();

            lblUser.Content = $"{ActiveUser.FirstName} {ActiveUser.LastName} ({ActiveUser.Role})";

            using (var ctx = new OrderManagerContext())
            {
                dgProductsAdd.ItemsSource = ctx.Products.GroupJoin(ctx.Suppliers,
                                                                   p => p.Supplier.SupplierId,
                                                                   s => s.SupplierId,
                                                                   (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name }).ToList();
                cbSuppliersAdd.ItemsSource = ctx.Suppliers.ToList();

                dgProductsEdit.ItemsSource = ctx.Products.GroupJoin(ctx.Suppliers,
                                                                    p => p.Supplier.SupplierId,
                                                                    s => s.SupplierId,
                                                                    (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name }).ToList();
                cbProductsEdit.ItemsSource         = ctx.Products.Include(p => p.Supplier).ToList();
                cbSuppliersProductEdit.ItemsSource = ctx.Suppliers.ToList();

                dgProductsDelete.ItemsSource = ctx.Products.GroupJoin(ctx.Suppliers,
                                                                      p => p.Supplier.SupplierId,
                                                                      s => s.SupplierId,
                                                                      (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name }).ToList();
                cbProductsDelete.ItemsSource = ctx.Products.ToList();

                dgSuppliersAdd.ItemsSource = ctx.Suppliers.ToList();

                dgSuppliersEdit.ItemsSource         = ctx.Suppliers.ToList();
                cbSuppliersSupplierEdit.ItemsSource = ctx.Suppliers.ToList();

                dgSuppliersDelete.ItemsSource = ctx.Suppliers.ToList();
                cbSuppliersDelete.ItemsSource = ctx.Suppliers.ToList();
            }
        }
Esempio n. 30
0
        public DatabeheerAdmin()
        {
            InitializeComponent();

            lblUser.Content = $"{ActiveUser.FirstName} {ActiveUser.LastName} ({ActiveUser.Role})";


            using (var ctx = new OrderManagerContext())
            {
                dgUsersAdd.ItemsSource = ctx.Users.Join(ctx.Roles,
                                                        u => u.Role.RoleId,
                                                        r => r.RoleId,
                                                        (u, r) => new { FirstName = u.FirstName, LastName = u.LastName, Username = u.Username, Password = u.Password, Role = r.Name }).ToList();
                cbRolesAdd.ItemsSource = ctx.Roles.ToList();

                dgUsersEdit.ItemsSource = ctx.Users.Join(ctx.Roles,
                                                         u => u.Role.RoleId,
                                                         r => r.RoleId,
                                                         (u, r) => new { FirstName = u.FirstName, LastName = u.LastName, Username = u.Username, Password = u.Password, Role = r.Name }).ToList();
                cbUsersEdit.ItemsSource = ctx.Users.Include(u => u.Role).ToList();
                cbRolesEdit.ItemsSource = ctx.Roles.ToList();

                dgUsersDelete.ItemsSource = ctx.Users.Join(ctx.Roles,
                                                           u => u.Role.RoleId,
                                                           r => r.RoleId,
                                                           (u, r) => new { FirstName = u.FirstName, LastName = u.LastName, Username = u.Username, Password = u.Password, Role = r.Name }).ToList();
                cbUsersDelete.ItemsSource = ctx.Users.ToList();

                dgProductsAdd.ItemsSource = ctx.Products.GroupJoin(ctx.Suppliers,
                                                                   p => p.Supplier.SupplierId,
                                                                   s => s.SupplierId,
                                                                   (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name }).ToList();
                cbSuppliersAdd.ItemsSource = ctx.Suppliers.ToList();

                dgProductsEdit.ItemsSource = ctx.Products.GroupJoin(ctx.Suppliers,
                                                                    p => p.Supplier.SupplierId,
                                                                    s => s.SupplierId,
                                                                    (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name }).ToList();
                cbProductsEdit.ItemsSource         = ctx.Products.Include(p => p.Supplier).ToList();
                cbSuppliersProductEdit.ItemsSource = ctx.Suppliers.ToList();

                dgProductsDelete.ItemsSource = ctx.Products.GroupJoin(ctx.Suppliers,
                                                                      p => p.Supplier.SupplierId,
                                                                      s => s.SupplierId,
                                                                      (p, s) => new { Name = p.Name, UnitPrice = p.UnitPrice, Stock = p.Stock, Supplier = p.Supplier.Name }).ToList();
                cbProductsDelete.ItemsSource = ctx.Products.ToList();

                dgSuppliersAdd.ItemsSource = ctx.Suppliers.ToList();

                dgSuppliersEdit.ItemsSource         = ctx.Suppliers.ToList();
                cbSuppliersSupplierEdit.ItemsSource = ctx.Suppliers.ToList();

                dgSuppliersDelete.ItemsSource = ctx.Suppliers.ToList();
                cbSuppliersDelete.ItemsSource = ctx.Suppliers.ToList();

                dgCustomersAdd.ItemsSource = ctx.Customers.ToList();

                dgCustomersEdit.ItemsSource = ctx.Customers.ToList();
                cbCustomersEdit.ItemsSource = ctx.Customers.ToList();

                dgCustomersDelete.ItemsSource = ctx.Customers.ToList();
                cbCustomersDelete.ItemsSource = ctx.Customers.ToList();
            }
        }