private void cancelOrderButton_Click(object sender, EventArgs e) { prodContext.Dispose(); prodContext = new ProdContext(); prodContext.Categories.Load(); prodContext.Products.Load(); prodContext.Orders.Load(); prodContext.Orders.Local.Clear(); this.orderBindingSource.DataSource = prodContext.Orders.Local.Where(ord => ord.CompanyName == companyName).ToList(); this.categoryBindingSource.DataSource = prodContext.Categories.Local.ToBindingList(); this.productBindingSource.DataSource = (from prod in prodContext.Products where prod.CategoryID == currentCategoryID select prod).ToList(); this.totalPrice = 0; this.totalPriceLabel.Text = Convert.ToString(this.totalPrice); }
protected override void OnLoad(EventArgs e) { prodContext = new ProdContext(); prodContext.Categories.Load(); prodContext.Products.Load(); prodContext.Orders.Load(); isSavingMode = false; if (companyName == "Admin") { this.saveButton.Enabled = false; this.switchModeButton.Text = "Edit mode"; } else { this.saveButton.Visible = false; this.switchModeButton.Visible = false; } this.productDataGridView.AllowUserToAddRows = false; this.productDataGridView.AllowUserToDeleteRows = false; this.categoryDataGridView.AllowUserToAddRows = false; this.categoryDataGridView.AllowUserToDeleteRows = false; this.orderDataGridView.AllowUserToAddRows = false; this.orderDataGridView.AllowUserToDeleteRows = false; this.categoryBindingSource.DataSource = prodContext.Categories.Local.ToBindingList(); this.productBindingSource.DataSource = prodContext.Products.Local.ToBindingList(); this.orderBindingSource.DataSource = prodContext.Orders.Local.Where(ord => ord.CompanyName == companyName).ToList(); this.totalPrice = 0; foreach (Order order in (List <Order>)orderBindingSource.DataSource) { Product currentProduct = order.Product; this.totalPrice += currentProduct.UnitPrice * order.NumberOfUnits; } this.totalPriceLabel.Text = Convert.ToString(this.totalPrice); }
private void ChooseCustomer_Load(object sender, EventArgs e) { prodContext = new ProdContext(); }