Пример #1
0
        /// <summary>
        /// Helper method to clear local and remove and create the database again
        /// </summary>
        private void CleanDatabaseAndEntities()
        {
            //Clear all the records to prevent exceptions
            context.Categories.Local.Clear();
            context.Businesses.Local.Clear();
            context.Products.Local.Clear();
            context.Orders.Local.Clear();
            context.SaveChanges();

            context.Database.Delete();
            context.Database.Create();
            context.SaveChanges();
        }
        /// <summary>
        /// Load the data to the list box
        /// </summary>
        private void ReloadListBoxData()
        {
            context.SaveChanges();
            context.Products.Load();

            // We force the refresh of the listbox since without reassigning the data source
            // the listBox data doesn't change
            listBoxProduct.DataSource = null;
            listBoxProduct.DataSource = context.Products.Local.Where(p => p.Business == business).ToArray();
        }
        /// <summary>
        /// Load the data to the list box
        /// </summary>
        private void ReloadListBoxData()
        {
            context.SaveChanges();
            context.Businesses.Load();

            // We force the refresh of the listbox since without reassigning the data source
            // the listBox data doesn't change
            listBoxBusinessName.DataSource = null;
            listBoxBusinessName.DataSource = context.Businesses.Local.ToBindingList();
        }
        private void ShopForm_Load(object sender, EventArgs e)
        {
            context.SaveChanges();
            context.Products.Load();
            context.Businesses.Load();
            context.Categories.Load();
            order = new Order {
                TotalPrice = 0, Business = business
            };

            //Display all business expect the business who is buying in the filters
            comboBoxBusiness.DataSource = context.Businesses.Local.Where(b => b != business).ToArray();
            comboBoxCategory.DataSource = context.Categories.Local.ToBindingList();

            //Diplay which business is shopping
            groupBoxShop.Text = $"{business.Name} is shopping";

            ResetControlsToDefault();
            MapOrderToForm();
        }
        /// <summary>
        /// Display the business' orders
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OrdersForm_Load(object sender, EventArgs e)
        {
            context.SaveChanges();
            context.Products.Load();
            context.Orders.Load();

            groupBoxOrders.Text = $"{business.Name} Orders";

            var ordersFiltered = context.Orders.Local.Where(o => o.Business == business).ToArray();

            FormUtils.InitalizeDataGridView(dataGridViewOrders, ordersFiltered, false, "Id", "BusinessId", "Products", "Business", "OrderDate", "TotalPrice");
            labelOrdersCountData.Text = ordersFiltered.Count().ToString();

            dataGridViewOrders.SelectionChanged += DataGridViewOrders_SelectionChanged;
        }