Exemple #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtName.Text.Trim() == "")
            {
                MessageBox.Show("Please provide a name for the category", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            var checkQuery = (from categories in db.Categories
                              where categories.Name == txtName.Text.Trim()
                              select categories).ToList();

            if (checkQuery.Count != 0)
            {
                MessageBox.Show("This category already exists", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            category.Name        = txtName.Text.Trim();
            category.Description = txtDescription.Text.Trim();


            db.Categories.Add(category);
            db.SaveChanges();

            MessageBox.Show("Category successfully added!");
            Clear();
            this.program_CategoryBindingSource.DataSource = db.Categories.ToList();
            this.categoryDataGridView.Refresh();
        }
Exemple #2
0
        private void btnPlaceOrder_Click(object sender, EventArgs e)
        {
            var queryForID = db.Products.FirstOrDefault(p => p.Name == txtProduct.Text.Trim());

            if (queryForID == null)
            {
                MessageBox.Show("No such product exists!", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (txtQuantity.Text.Trim() == "")
            {
                MessageBox.Show("Please provide a quantity", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            //All good so add:
            order.ProductId = queryForID.ProductID;
            order.Quantity  = Convert.ToInt32(txtQuantity.Text.Trim());
            order.Comment   = txtComment.Text;
            order.Date      = DateTime.Now;

            //Save into database:
            db.Orders.Add(order);
            db.SaveChanges();

            MessageBox.Show("Order successfully added!");
            Clear();
            this.orderGridView.DataSource = db.Orders.Where(x => x.ProductId == order.ProductId).ToList();
            this.orderGridView.Refresh();
        }
        public void Post([FromBody] NewOrder newOrder)
        {
            Order order = new Order();

            order.CompanyName = newOrder.CompanyName;
            ProdContext.Orders.Add(order);
            ProdContext.SaveChanges();
        }
        public void Post([FromBody] NewCustomer newCustomer)
        {
            Customer customer = new Customer();

            customer.CompanyName = newCustomer.CompanyName;
            customer.Description = newCustomer.Description;
            ProdContext.Customers.Add(customer);
            ProdContext.SaveChanges();
        }
        public void Post([FromBody] NewCategory NewCategory)
        {
            Category category = new Category();

            category.Name        = NewCategory.Name;
            category.Description = NewCategory.Description;
            ProdContext.Categories.Add(category);
            ProdContext.SaveChanges();
        }
        public ActionResult Create([Bind(Include = "CategoryID,Name,Description")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
        public ActionResult Create([Bind(Include = "ProductID,Name,UnitsInStock,CategoryId,UnitPrice")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }
        public void Post(int categoryId, [FromBody] NewProduct newProduct)
        {
            Category category = getCategory(categoryId);

            Product product = new Product();

            product.Name         = newProduct.Name;
            product.Unitprice    = newProduct.Unitprice;
            product.UnitsInStock = newProduct.UnitsInStock;

            category.Products.Add(product);
            ProdContext.SaveChanges();
        }
Exemple #9
0
        public UomControllerTest()
        {
            options = new DbContextOptionsBuilder <ProdContext>()
                      .UseInMemoryDatabase(databaseName: "productsdb")
                      .Options;
            var context = new ProdContext(options);

            if (!context.ProductUoms.Any())
            {
                using (context)
                {
                    context.ProductUoms.Add(new ProductUom
                    {
                        Title = "г"
                    });

                    context.ProductUoms.Add(new ProductUom
                    {
                        Title = "кг"
                    });

                    context.ProductUoms.Add(new ProductUom
                    {
                        Title = "шт"
                    });

                    context.ProductUoms.Add(new ProductUom
                    {
                        Title = "т"
                    });
                    context.SaveChanges();
                }
            }
        }
Exemple #10
0
        private void zapiszToolStripButton_Click(object sender, EventArgs e)
        {
            if (selectedCustomer == null)
            {
                string msg = "Klient nie został wybrany.";
                MessageBox.Show(msg, "Input Error", MessageBoxButtons.OK);
                return;
            }
            if (selectedProductsSource.Count <= 0)
            {
                string msg = "Nie wybrano produktów.";
                MessageBox.Show(msg, "Input Error", MessageBoxButtons.OK);
                return;
            }


            var Customer = (from customer in db.Customers.Local
                            where customer.CompanyName == selectedCustomer
                            select customer).First();

            foreach (SelectedProduct p in selectedProductsSource)
            {
                var o = new Order();
                o.Customer = Customer;
                var Product = from product in db.Products.Local
                              where product.ProductId == p.id
                              select product;
                o.Product = Product.First();

                db.Orders.Local.Add(o);
            }

            db.SaveChanges();
            this.Close();
        }
Exemple #11
0
        public bool Save()
        {
            try
            {
                ProdContext prodContext = new ProdContext();

                Customer customer = prodContext.Customers.FirstOrDefault(n => n.CompanyName == customerName);

                if (customer == null)
                {
                    return(false);
                }

                List <OrderTranferObject> orderDTO = new List <OrderTranferObject>();
                for (int i = 0; i < orderData.catName.Length; i++)
                {
                    var catTmp  = orderData.catName[i];
                    var prodTmp = orderData.prodName[i];
                    orderDTO.Add(new OrderTranferObject
                    {
                        Category = prodContext.Categories.FirstOrDefault(c => c.Name == catTmp),
                        Product  = prodContext.Products.FirstOrDefault(c => c.Name == prodTmp),
                        Quantity = orderData.quantity[i]
                    });
                }
                decimal price = 0;
                orderDTO.ForEach(n => price += n.Product.UnitPrice * n.Quantity);

                List <OrderDetails> details = new List <OrderDetails>();

                Order order = new Order {
                    CompletePrice = price,
                    Customer      = customer
                };

                foreach (var item in orderDTO)
                {
                    OrderDetails detail = new OrderDetails();
                    detail.Order     = order;
                    detail.Product   = item.Product;
                    detail.Quantity  = item.Quantity;
                    detail.UnitPrice = item.Product.UnitPrice;
                    details.Add(detail);
                }

                order.OrderDetails = details;

                prodContext.Orders.Add(order);
                details.ForEach(d => prodContext.OrderDetails.Add(d));
                prodContext.SaveChanges();
            }
            catch (Exception e)
            {
                return(false);
            }


            return(true);
        }
Exemple #12
0
        public void Post(int orderId, [FromBody] NewOrderItem newOrderItem)
        {
            Order order = getOrder(orderId);

            OrderItem orderItem = new OrderItem();

            orderItem.ProductId = newOrderItem.ProductId;
            orderItem.Count     = newOrderItem.Count;

            Product product = ProdContext.Products
                              .First(u => u.ProductId == newOrderItem.ProductId);

            product.UnitsInStock -= orderItem.Count;

            order.OrderItems.Add(orderItem);
            ProdContext.SaveChanges();
        }
Exemple #13
0
        private void registerButton_Click(object sender, EventArgs e)
        {
            bool isValid = true;

            if (String.IsNullOrEmpty(loginTextBox.Text) || String.IsNullOrEmpty(passwordTextBox.Text))
            {
                isValid = false;
            }

            if (isValid)
            {
                string login    = loginTextBox.Text;
                string password = passwordTextBox.Text;

                var users = from u in prodContext.Customers
                            select u;

                var suchUserExists = users.Where(m => m.CompanyName == login).Count() > 0 ? true : false;

                if (!suchUserExists)
                {
                    Customer customer = new Customer()
                    {
                        CompanyName = login,
                        Password    = password,
                        Description = "defaultDescription"
                    };
                    prodContext.Customers.Add(customer);
                    prodContext.SaveChanges();
                    var writer = new System.IO.StreamWriter("MyFilename.txt");
                    writer.WriteLine(login);
                    writer.Close();
                    MainForm mainForm = new MainForm();
                    mainForm.ShowDialog();
                }
                else
                {
                    MessageBox.Show(
                        "Użytkownik podanej nazwie istnieje",
                        "Zamknij",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show(
                    "Podaj login i hasło",
                    "Zamknij",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
        }
        public ProductControllerTest()
        {
            options = new DbContextOptionsBuilder <ProdContext>()
                      .UseInMemoryDatabase(databaseName: "productsdb")
                      .Options;

            var context = new ProdContext(options);

            if (!context.Prod.Any())
            {
                using (context)
                {
                    context.Prod.Add(new Product
                    {
                        Title = "Бананы", UomId = 2
                    });

                    context.Prod.Add(new Product
                    {
                        Title = "Специи", UomId = 1
                    });

                    context.Prod.Add(new Product
                    {
                        Title = "Мандарины", UomId = 2
                    });

                    context.Prod.Add(new Product
                    {
                        Title = "Авокадо", UomId = 3
                    });

                    context.Prod.Add(new Product
                    {
                        Title = "Апельсины", UomId = 2
                    });

                    context.Prod.Add(new Product
                    {
                        Title = "Груши", UomId = 2
                    });
                    context.SaveChanges();
                }
            }
        }
Exemple #15
0
        public UomController(ProdContext context)
        {
            db = context;
            if (!db.ProductUoms.Any())
            {
                db.ProductUoms.Add(new ProductUom {
                    Title = "шт"
                });
                db.ProductUoms.Add(new ProductUom {
                    Title = "г"
                });
                db.ProductUoms.Add(new ProductUom {
                    Title = "кг"
                });

                db.SaveChanges();
            }
        }
        public ProductController(ProdContext context)
        {
            db = context;
            if (!db.Prod.Any())
            {
                db.Prod.Add(new Product {
                    Title = "Бананы", UomId = 3
                });
                db.Prod.Add(new Product {
                    Title = "Специи", UomId = 2
                });
                db.Prod.Add(new Product {
                    Title = "Мандарины", UomId = 3
                });
                db.Prod.Add(new Product {
                    Title = "Авокадо", UomId = 1
                });

                db.SaveChanges();
            }
        }
Exemple #17
0
        public MovementsControllerTest()
        {
            options = new DbContextOptionsBuilder <ProdContext>()
                      .UseInMemoryDatabase(databaseName: "productsdb")
                      .Options;

            var context = new ProdContext(options);

            if (!context.Movements.Any())
            {
                using (context)
                {
                    context.Movements.Add(new ProductMovements
                    {
                        ProductId = 1, Quantity = 10
                    });

                    context.Movements.Add(new ProductMovements
                    {
                        ProductId = 2, Quantity = 100
                    });

                    context.Movements.Add(new ProductMovements
                    {
                        ProductId = 3, Quantity = 145
                    });

                    context.Movements.Add(new ProductMovements
                    {
                        ProductId = 4, Quantity = 134
                    });

                    context.Movements.Add(new ProductMovements
                    {
                        ProductId = 1, Quantity = -2
                    });
                    context.SaveChanges();
                }
            }
        }
 public MovementsController(ProdContext context)
 {
     db = context;
     if (!db.Movements.Any())
     {
         db.Movements.Add(new ProductMovements {
             ProductId = 1, Quantity = 10
         });
         db.Movements.Add(new ProductMovements {
             ProductId = 2, Quantity = 100
         });
         db.Movements.Add(new ProductMovements {
             ProductId = 3, Quantity = 145
         });
         db.Movements.Add(new ProductMovements {
             ProductId = 4, Quantity = 134
         });
         db.Movements.Add(new ProductMovements {
             ProductId = 1, Quantity = -2
         });
         db.SaveChanges();
     }
 }
Exemple #19
0
        private void zapiszToolStripButton_Click(object sender, EventArgs e)
        {
            bool inputError = false;

            foreach (DbEntityValidationResult err in db.GetValidationErrors())
            {
                inputError = true;
                foreach (DbValidationError errMsg in err.ValidationErrors)
                {
                    MessageBox.Show(errMsg.ErrorMessage, "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            if (inputError)
            {
                return;
            }

            zapiszToolStripButton.Enabled = false;
            db.SaveChanges();
            categoryDataGridView.Update();
            categoryDataGridView.Refresh();
            productDataGridView.Update();
            productDataGridView.Refresh();
        }