private void Application_Startup(object sender, StartupEventArgs e) { //get the data from storage _expenses = MyStorage.ReadXML <ObservableCollection <Expense> >("Expenses.xml"); if (_expenses == null) { _expenses = new ObservableCollection <Expense>(); // _expenses = Generateexpenses(20); } ObservableCollection <string> uniqueDates = new ObservableCollection <string>(); foreach (Expense ex in _expenses) { if (uniqueDates.IndexOf(ex.Datetime) < 0) { uniqueDates.Add(ex.Datetime); } } ObservableCollection <TotalAmount> amountList = new ObservableCollection <TotalAmount>();; for (int i = 0; i < uniqueDates.Count(); i++) { double toAm = 0.0; for (int j = 0; j < _expenses.Count(); j++) { if (uniqueDates[i] == _expenses[j].Datetime.ToString()) { toAm += _expenses[j].Amount; } } amountList.Add(new TotalAmount { CurrentDate = uniqueDates[i], Amount = toAm }); } _uniqueDates = uniqueDates; _DatesTotalAmount = amountList; }
private void Application_Exit(object sender, ExitEventArgs e) { MyStorage.WriteXml <ObservableCollection <Expense> >(_expenses, "Expenses.xml"); }