Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            var vCompanyName = textBox1.Text;
            var vDescription = textBox2.Text;

            using (var prodDB = new ProdContent())
            {
                var isCompanyNameExists = from c in prodDB.Customers
                                          where c.CompanyName == vCompanyName
                                          select c.CompanyName;

                if (isCompanyNameExists.Contains(vCompanyName))
                {
                    MessageBox.Show("Company with this name exists");
                    return;
                }

                var newCustomer = new Customer();
                newCustomer.CompanyName = vCompanyName;
                newCustomer.Description = vDescription;
                prodDB.Customers.Add(newCustomer);
                prodDB.SaveChanges();
            }

            Hide();
            DestroyHandle();
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            var vCategoryName = textBox1.Text;
            var vDescription  = textBox2.Text;

            using (var prodDB = new ProdContent())
            {
                var isCategoryExists = prodDB.Category
                                       .Where(cat => cat.Name == vCategoryName)
                                       .Select(c => c.Name);

                if (isCategoryExists.Contains(vCategoryName))
                {
                    MessageBox.Show("Category with this name already exists");
                    return;
                }

                var newCategory = new Category();
                newCategory.Name        = vCategoryName;
                newCategory.Description = vDescription;
                prodDB.Category.Add(newCategory);
                prodDB.SaveChanges();
            }

            Hide();
            DestroyHandle();
        }
Exemplo n.º 3
0
        public NewOrder()
        {
            InitializeComponent();

            using (var prodDB = new ProdContent())
            {
                var customers = from c in prodDB.Customers
                                orderby c.CompanyName
                                select c.CompanyName;

                foreach (var c in customers)
                {
                    comboBox1.Items.Add(c);
                }

                var categories = from c in prodDB.Category
                                 orderby c.Name
                                 select c.Name;

                foreach (var c in categories)
                {
                    comboBox3.Items.Add(c);
                }
            }
        }
Exemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            var selectedCustomer = (string)comboBox1.SelectedItem;
            var selectedProduct  = (string)comboBox2.SelectedItem;
            int selectedQuantity = Int32.Parse(textBox1.Text);

            using (var prodDB = new ProdContent())
            {
                var availableQuantity = from p in prodDB.Product
                                        where p.Name == selectedProduct
                                        select p.UnitsInStock;

                if (selectedQuantity > availableQuantity.First())
                {
                    MessageBox.Show("Do not have enough product available");
                    return;
                }

                var selectedProductID = from p in prodDB.Product
                                        where p.Name == selectedProduct
                                        select p.ProductID;

                var vOrder = new Order();
                vOrder.CompanyName = selectedCustomer;
                vOrder.ProductID   = selectedProductID.First();
                vOrder.Quantity    = selectedQuantity;

                prodDB.Orders.Add(vOrder);
                prodDB.SaveChanges();
            }

            Hide();
            DestroyHandle();
        }
Exemplo n.º 5
0
 private void statisticsForm_Load(object sender, EventArgs e)
 {
     using (var prodDB = new ProdContent())
     {
         label7.Text  = prodDB.Customers.Count().ToString();
         label8.Text  = prodDB.Category.Count().ToString();
         label9.Text  = prodDB.Product.Count().ToString();
         label10.Text = prodDB.Orders.Count().ToString();
     }
 }
Exemplo n.º 6
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (var prodDB = new ProdContent())
            {
                var orders = prodDB.Customers.Include("Orders")
                             .Where(c => c.CompanyName == comboBox1.SelectedItem.ToString())
                             .Select(c => c.Orders).ToList();

                foreach (List <Order> o in orders)
                {
                    dataGridView1.DataSource = o;
                }
                dataGridView1.Update();
            }
        }
Exemplo n.º 7
0
        public findClientOrdersForm()
        {
            InitializeComponent();

            using (var prodDB = new ProdContent())
            {
                var customers = from c in prodDB.Customers
                                orderby c.CompanyName
                                select c.CompanyName;

                foreach (var c in customers)
                {
                    comboBox1.Items.Add(c);
                }
            }
        }
Exemplo n.º 8
0
        public newProductForm()
        {
            InitializeComponent();
            pDB = new ProdContent();

            using (var prodDB = new ProdContent())
            {
                var categories = from c in prodDB.Category
                                 orderby c.Name
                                 select c.Name;

                foreach (var c in categories)
                {
                    comboBox2.Items.Add(c);
                }
            }
        }
Exemplo n.º 9
0
        private void button1_Click(object sender, EventArgs e)
        {
            var vProductName  = textBox1.Text;
            var vUnitsInStock = Int32.Parse(textBox2.Text);
            var vCategory     = (String)comboBox2.SelectedItem;
            var vUnitPrice    = textBox3.Text;

            using (var prodDB = new ProdContent())
            {
                var catId = (from c in prodDB.Category
                             where c.Name == vCategory
                             select c.CategoryId).FirstOrDefault();

                if (catId == 0)
                {
                    MessageBox.Show("You have to choose category!");
                    return;
                }

                var isProductExists = from p in prodDB.Product
                                      where p.Name == vProductName
                                      select p.Name;

                if (isProductExists.Contains(vProductName))
                {
                    MessageBox.Show("Product with this name already exists");
                    return;
                }

                var newProduct = new Product();
                newProduct.Name         = vProductName;
                newProduct.UnitsInStock = vUnitsInStock;
                newProduct.CategoryId   = catId;
                newProduct.Unitprice    = Decimal.Parse(vUnitPrice);
                prodDB.Product.Add(newProduct);
                prodDB.SaveChanges();
            }

            Hide();
            DestroyHandle();
        }
Exemplo n.º 10
0
        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            using (var prodDB = new ProdContent())
            {
                var selectedCategory = (string)comboBox3.SelectedItem;

                var selectedCategoryID = (from c in prodDB.Category
                                          where c.Name == selectedCategory
                                          select c.CategoryId).First();

                var products = from p in prodDB.Product
                               where p.CategoryId == selectedCategoryID
                               select p.Name;

                comboBox2.Items.Clear();
                foreach (var p in products)
                {
                    comboBox2.Items.Add(p);
                }
            }
        }
Exemplo n.º 11
0
 public NewCustomerForm()
 {
     InitializeComponent();
     pDB = new ProdContent();
 }
Exemplo n.º 12
0
 public newCategoryForm()
 {
     InitializeComponent();
     prodDB = new ProdContent();
 }
Exemplo n.º 13
0
 public StartForm()
 {
     InitializeComponent();
     prodDB = new ProdContent();
 }