Exemplo n.º 1
0
        private void categoryFilterButton_Click(object sender, EventArgs e)
        {
            ProdContext prodContext = new ProdContext();
            Boolean     parse1;
            Boolean     parse2;
            Decimal     minPrice = 0;
            Decimal     maxPrice = Decimal.MaxValue;

            if (this.minPriceTextBox.Text == "" || this.maxPriceTextBox.Text == "")
            {
                if (minPriceTextBox.Text == "")
                {
                    minPrice = 0;
                }
                if (maxPriceTextBox.Text == "")
                {
                    maxPrice = Decimal.MaxValue;
                }
            }
            else if (!Decimal.TryParse(this.minPriceTextBox.Text, out minPrice) ||
                     !Decimal.TryParse(this.maxPriceTextBox.Text, out maxPrice) || minPrice > maxPrice)
            {
                MessageBox.Show("Bad price filters");
            }
            ;



            this.categoryDataGridView.DataSource = prodContext.Categories.Where(category => (filterButton.Text != "" &&
                                                                                             category.Name.ToString().Contains(categoryNameFilterTextBox.Text) == true)).ToList();

            if (checkBox1.Checked == true)
            {
                this.productsDataGridView.DataSource = prodContext.Products.Where(product => ((product.Name.ToString().Contains(this.productNameFiltertextBox.Text)) == true) &&
                                                                                  (product.UnitPrice > minPrice) && product.UnitPrice < maxPrice && product.UnitsInStock > 0).ToList();
            }
            else
            {
                this.productsDataGridView.DataSource = prodContext.Products.Where(product => ((product.Name.ToString().Contains(this.productNameFiltertextBox.Text)) == true) &&
                                                                                  (product.UnitPrice > minPrice) && product.UnitPrice < maxPrice).ToList();
            }

            this.categoryDataGridView.Update();
            this.productsDataGridView.Refresh();
            this.productsDataGridView.Update();
            this.categoryDataGridView.Refresh();
        }
Exemplo n.º 2
0
        private static void showCategoriesWithAmout(ProdContext context)
        {
            var query = from category in context.Categories
                        join product in context.Products
                        on category.CategoryID equals product.CategoryID
                        into categorygroup
                        select new
            {
                Category = category.CategoryID,
                Ammount  = categorygroup.Count()
            };

            foreach (var item in query)
            {
                Console.WriteLine(item);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            using (ProdContext db = new ProdContext())
            {
                // Create and save a new Blog
                //Console.Write("Enter a name for a new Category: ");
                //String cat_name = Console.ReadLine();

                //Category category = new Category { Name = cat_name };
                //db.Categories.Add(category);
                //db.SaveChanges();

                var query = from c in db.Categories
                            orderby c.Name descending
                            select c.Name;

                foreach (var cat in query)
                {
                    Console.WriteLine("----" + cat);
                }
                ;

                showCategories(db);
                showProductsWithCategories(db);
                showCategoriesWithAmout(db);
                showCategoriesWithAmout2(db);


                //OrderHistoryForm orderHistoryForm = new OrderHistoryForm();
                //orderHistoryForm.ShowDialog();
                CategoryForm categoryForm = new CategoryForm();
                categoryForm.ShowDialog();
                //AddCategoryForm addCat = new AddCategoryForm();
                //addCat.ShowDialog();
                //AddOrderForm addOrderForm = new AddOrderForm();
                //addOrderForm.ShowDialog();

                //AddCustomer addCustomer = new AddCustomer();
                //addCustomer.ShowDialog();
            }
        }
Exemplo n.º 4
0
 private void AddCustomer_Load(object sender, EventArgs e)
 {
     prodContext = new ProdContext();
     prodContext.Customers.Load();
     this.customerBindingSource.DataSource = prodContext.Customers.Local.ToBindingList();
 }
Exemplo n.º 5
0
 public AddCustomer()
 {
     InitializeComponent();
     this.prodContext = new ProdContext();
 }
Exemplo n.º 6
0
 public void OrderHistoryForm_Load(object sender, EventArgs e)
 {
     this.prodContext = new ProdContext();
     this.prodContext.Orders.Load();
     this.orderBindingSource.DataSource = prodContext.Orders.Local.ToBindingList();
 }