/// <summary> /// Change selected DirectProductCost /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgDPPC_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (dgDPPC.SelectedItem != null) { objToAdd = dgDPPC.SelectedItem as DirectProductCost; } }
/// <summary> /// Connect a new product to the selected account /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSelectProduct_Click(object sender, RoutedEventArgs e) { Department test = (Department)cbDepartments.SelectedItem; ProductGUI.ProductRegister pr = new ProductGUI.ProductRegister(true, test.DepartmentID); pr.ShowDialog(); if (pr.DialogResult == true) { product = pr.SelectedProduct; // Check if user attempts to add a product that is already connected to the selected account bool productConnected = DCPPDManagement.Instance.CheckIfProductConnected(product.ProductID, DepartmentID); if (productConnected) { MessageBox.Show(String.Format ("Du försöker lägga till en produkt som redan är kopplad till konto {0}.", account.AccountName), "Produkt redan kopplad"); return; } objToAdd = new DirectProductCost { AccountID = account.AccountID, ProductID = product.ProductID }; DCPPDManagement.Instance.SaveNewProduct(objToAdd, dgAccounts.SelectedItem as Account); } lblSum.Content = "Summa: " + DCPPDManagement.Instance.CalculateSum(account, DepartmentID); }
/// <summary> /// Save the edits in a datagrid cell /// </summary> /// <param name="objToAdd"></param> /// <param name="account"></param> public void SaveEditing(DirectProductCost objToAdd, Account account) { ExpenseBudget eb = null; int id = ExpenseBudgetManagement.Instance.GetExpenseBudgetID(); var listOfExpenseBudgets = ExpenseBudgetManagement.Instance.GetExpenseBudgets(); foreach (var expenseBudget in listOfExpenseBudgets.Where(expenseBudget => expenseBudget.ExpenseBudgetID.Equals(id))) { eb = expenseBudget; } objToAdd.ExpenseBudgetID = eb.ExpenseBudgetID; objToAdd.AccountID = account.AccountID; Update(); }
/// <summary> /// Create a new DirectProductCost /// </summary> /// <param name="dpc"></param> public void CreateDirectProductCosts(DirectProductCost dpc) { DirectProductCosts.Add(dpc); db.DirectProductCost.Add(dpc); db.SaveChanges(); }