private void loadBudgetItems() { budgetItemList = new List<BudgetItemState>(); BudgetHelper client = new BudgetHelper(); try { decimal totalAmount = 0; OptimizedBudgetItems budgetItems = client.GetBudgetItem(event_.EventID); if (budgetItems != null) { List<OptimizedBudgetItemsDetails> budgetItemsList = budgetItems.BudgetItemsList.ToList<OptimizedBudgetItemsDetails>(); foreach (OptimizedBudgetItemsDetails budgetItem in budgetItemsList) { Items item = client.GetItemDetail(budgetItem); BudgetItemState bis = new BudgetItemState(item, budgetItem.IsBought); if (budgetItem.IsBought) { totalAmount += item.ActualPrice; } else { item.ActualPrice = 0; totalAmount += item.EstimatedPrice; } budgetItemList.Add(bis); } lvBudgetItem.ItemsSource = budgetItemList; } //.ItemsSource = incomeList; txtTotalExpenditure.Text = "$" + totalAmount.ToString("0.00"); expenditure = totalAmount; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { client.Close(); } }
private void btnSave_Click(object sender, RoutedEventArgs e) { BudgetHelper client = new BudgetHelper(); OptimizedBudgetItems budget = client.GetBudgetItem(event_.EventID); client.Close(); if (budget != null) { if (MessageBox.Show("You already have an optimized item list, all previous changes will be overwritten" + Environment.NewLine + Environment.NewLine + "Do you want to overwrite? (It cannot be undone)", "Confirm Overwrite", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { save(); } else { return; } } else { save(); } }
private void loadBudgetItems() { BudgetHelper client = new BudgetHelper(); try { OptimizedBudgetItems budget = client.GetBudgetItem(event_.EventID); txtTotalPrice.Text = budget.TotalEstimatedPrice.ToString("0.00"); txtTotalSat.Text = budget.TotalSatisfaction.ToString(); txtGenDate.Text = budget.GeneratedDate.ToString("dd MMM yyyy"); btnCancelEditItem.IsEnabled = btnUpdateItem.IsEnabled = true; //loadList lvBItem.SetExistingSource(budget.BudgetItemsList.ToList<OptimizedBudgetItemsDetails>()); lvBItem.lv.SelectedIndex = -1; } catch (NullReferenceException) { txtTotalPrice.Text = "N.A"; txtTotalSat.Text = "N.A"; txtGenDate.Text = "N.A"; btnCancelEditItem.IsEnabled = btnUpdateItem.IsEnabled = false; lvBItem.lv.SelectedIndex = -1; MessageBox.Show("There is no optimized list yet"); } catch (Exception ex) { txtTotalPrice.Text = "N.A"; txtTotalSat.Text = "N.A"; txtGenDate.Text = "N.A"; btnCancelEditItem.IsEnabled = btnUpdateItem.IsEnabled = false; lvBItem.lv.SelectedIndex = -1; MessageBox.Show("An error has occured: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { client.Close(); } }