示例#1
0
        private void TheDataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            if (e.EditAction == DataGridEditAction.Commit)
            {
                currentEditRow = e.Row.Item as LoanPaymentAggregation;
                if (currentEditRow != null)
                {
                    //
                    // Cache the value of the 4 possible field being edited
                    // DataGrid is pretty stupid here, instead of giving us an event with the value before and after editing
                    // you have to wait for the data grid to actually make the field updated before you can look at the value
                    // that the user just edited
                    // so to work around this we cache the last value, send our self and event and we compare the before and after value
                    //
                    this.editingPayementBefore   = currentEditRow.Payment;
                    this.editingPrincipalBefore  = currentEditRow.Principal;
                    this.editingInterestlBefore  = currentEditRow.Interest;
                    this.editingPercentageBefore = currentEditRow.Percentage;

                    // Note: this must be DispatcherPriority.Background otherwise Updated value are happens too soon and
                    // doesn't see the new value!
                    this.Dispatcher.BeginInvoke(new Action(Rebalance), DispatcherPriority.ApplicationIdle);
                }
            }
        }
示例#2
0
        void ExportToCsv(StreamWriter writer, IEnumerable <object> data)
        {
            bool first = true;

            foreach (object row in data)
            {
                Transaction t = row as Transaction;
                if (t != null)
                {
                    if (first)
                    {
                        first = false;
                        CsvStore.WriteTransactionHeader(writer);
                    }
                    ;
                    CsvStore.WriteTransaction(writer, t);
                }
                else
                {
                    Investment i = row as Investment;
                    if (i != null)
                    {
                        if (first)
                        {
                            first = false;
                            CsvStore.WriteInvestmentHeader(writer);
                        }
                        ;
                        CsvStore.WriteInvestment(writer, i);
                    }
                    else
                    {
                        LoanPaymentAggregation l = row as LoanPaymentAggregation;
                        if (l != null)
                        {
                            if (first)
                            {
                                first = false;
                                writer.WriteLine("Date,Account,Payment,Percentage,Principal,Interest,Balance");
                            }
                            ;

                            writer.WriteLine("\"{0}\",\"{1}\",\"{2}\",\"{3}%\",\"{4}\",\"{5}\",\"{6}\"",
                                             l.Date.ToShortDateString(),
                                             l.Account,
                                             l.Payment.ToString("C2"),
                                             l.Percentage.ToString("N3"),
                                             l.Principal.ToString("C2"),
                                             l.Interest.ToString("C2"),
                                             l.Balance.ToString("C2")
                                             );
                        }
                    }
                }
            }
        }
示例#3
0
        void Rebalance()
        {
            // Priority 1) to the PERCENTAGE FIELD
            if (this.editingPercentageBefore != this.currentEditRow.Percentage)
            {
                this.currentEditRow.Interest  = 0;
                this.currentEditRow.Principal = 0;

                //
                foreach (LoanPaymentAggregation l in loanPayementsView)
                {
                    if (l.Date >= this.currentEditRow.Date)
                    {
                        if (l.SplitForInterest != null || l.SplitForPrincipal != null)
                        {
                            l.Percentage = this.currentEditRow.Percentage;
                        }

                        if (l.SplitForInterest != null)
                        {
                            l.Interest = 0;
                        }

                        if (l.SplitForPrincipal != null)
                        {
                            l.Principal = 0;
                        }
                    }
                }
            }
            else
            {
                if (this.currentEditRow.Payment != 0)
                {
                    // Priority 2) to the PRINCIPAL field
                    if (this.editingPrincipalBefore != this.currentEditRow.Principal)
                    {
                        this.currentEditRow.Interest = this.currentEditRow.Payment - this.currentEditRow.Principal;
                    }
                    else
                    {
                        // Priority 3) to the INTEREST field
                        if (this.editingInterestlBefore != this.currentEditRow.Interest)
                        {
                            this.currentEditRow.Principal = this.currentEditRow.Payment - this.currentEditRow.Interest;
                        }
                    }
                }
            }

            LoanPaymentAggregation.CalculateTheBalances(Money, this.AccountSelected, loanPayementsView);
        }
示例#4
0
        /// <summary>
        /// Jump to the account of the associated transaction is from
        /// This will also select the related transaction inside the transaction view
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnCommandGotoRelatedTransaction(object sender, RoutedEventArgs e)
        {
            LoanPaymentAggregation l = this.CurrentSelectedItem as LoanPaymentAggregation;

            if (l != null && l.Transaction != null)
            {
                if (ServiceProvider != null)
                {
                    // Get the main service
                    IViewNavigator view = ServiceProvider.GetService(typeof(IViewNavigator)) as IViewNavigator;
                    if (view != null)
                    {
                        // Request to change the current view
                        view.NavigateToTransaction(l.Transaction);
                    }
                }
            }
        }
示例#5
0
        private void TheDataGrid_InitializingNewItem(object sender, InitializingNewItemEventArgs e)
        {
            LoanPaymentAggregation current = TheDataGrid.SelectedItem as LoanPaymentAggregation;
            LoanPaymentAggregation lvp     = e.NewItem as LoanPaymentAggregation;

            // Add new manual entry
            lvp.LoanPayementManualEntry = new LoanPayment()
            {
                AccountId = this.AccountSelected.Id
            };
            this.Money.LoanPayments.Add(lvp.LoanPayementManualEntry);

            if (current == null)
            {
                lvp.Date = DateTime.Now;
            }
            else
            {
                lvp.Date = current.Date.AddMonths(1);
            }
            lvp.Account = this.AccountSelected;
        }