/// <summary> /// Updates the two rows with new values. /// </summary> /// <param name="sender">The member of totals that was changed.</param> /// <param name="e">The arguments</param> public void UpdateBudgetAndSum(object sender, PropertyChangedEventArgs e) { netBudgetRow.Values.Values = new decimal[12]; for (int i = 0; i < _totals.Count; i++) { MoneyGridRow row = _totals.ElementAt(i); for (int j = 0; j < row.Values.Count; j++) { if (IsComparison) //Checks if object is part of comparison view. { netBudgetRow.Values[j] += row.Values[j]; continue; } //Values have sign changed if it is from an expenditure group. if (row.Group.IsIncome) { netBudgetRow.Values[j] += row.Values[j]; } else { netBudgetRow.Values[j] -= row.Values[j]; } } } netSumRow.Values[0] = netBudgetRow.Values[0]; for (int i = 1; i < netBudgetRow.Values.Count; i++) { netSumRow.Values[i] = netSumRow.Values[i - 1] + netBudgetRow.Values[i]; } }
/// <summary> /// Moves the specified group closer to the front (0-index) of the collection. /// </summary> /// <param name="group">The group to move</param> private void MoveGroupUp(Group group) { if (group == null) { return; } int index = _groups.IndexOf(group); if (index < 0) { throw new ArgumentException("Group " + group.Name + " does not exist"); } if (index > 0) { int startIndex = this.sessionService.BudgetValues.IndexOf(this.sessionService.BudgetValues.First(x => x.Group == group)); int targetIndex = this.sessionService.BudgetValues.IndexOf(this.sessionService.BudgetValues.First(x => x.Group == _groups.ElementAt(index - 1))); int endIndex = this.sessionService.BudgetValues.IndexOf(this.sessionService.BudgetValues.Last(x => x.Group == group)); _groups.Move(index, index - 1); this.sessionService.MoveTotalRows(index, index - 1); int offset = targetIndex - startIndex; //Move each row in the Values grids for (int i = 0; i <= endIndex - startIndex; i++) { this.sessionService.MoveValueRows(startIndex + i, startIndex + i + offset); } this.sessionService.RefreshListViews(); //Refresh grouping this.SelectedGroupItem = group; } }