Esempio n. 1
0
        public BuildingDialog(MyMoney money)
        {
            this.money = money;

            InitializeComponent();
            UpdateUI();
        }
Esempio n. 2
0
        public AccountDialog(MyMoney money, Account a, IServiceProvider sp)
        {
            InitializeComponent();

            this.serviceProvider = sp;

            onlineAccounts.Add(string.Empty); // so you can clear it out.
            this.money      = money;
            this.Owner      = Application.Current.MainWindow;
            this.TheAccount = a;
            onlineAccounts.Add(NewLabel); // so you can add new online accounts.

            List <string> currencies = new List <string>(Enum.GetNames(typeof(RestfulWebServices.CurrencyCode)));

            currencies.Sort();
            ComboBoxCurrency.ItemsSource = currencies;

            comboBoxOnlineAccount.ItemsSource = onlineAccounts;

            UpdateUI();

            money.Changed += new EventHandler <ChangeEventArgs>(OnMoneyChanged);


            CheckButtonStates();

            this.TextBoxName.Focus();

            this.Closed += AccountDialog_Closed;
        }
Esempio n. 3
0
        protected override void OnClosed(EventArgs e)
        {
            this.money.Payees.Changed -= handler;
            this.money = null;

            base.OnClosed(e);
        }
Esempio n. 4
0
 public ChangeTracker(MyMoney money, IViewNavigator navigator)
 {
     myMoney          = money;
     myMoney.Changed += new EventHandler <ChangeEventArgs>(OnMoneyChanged);
     this.navigator   = navigator;
     Clear();
 }
Esempio n. 5
0
        /// <summary>
        /// Easy wrapper for launching the Category Dialog
        /// </summary>
        /// <param name="myMoney"></param>
        /// <param name="categoryName"></param>
        /// <returns></returns>
        public static CategoryDialog ShowDialogCategory(MyMoney myMoney, string categoryName)
        {
            CategoryDialog dialog = new CategoryDialog(myMoney, categoryName);

            dialog.Owner = Application.Current.MainWindow;
            return(dialog);
        }
 public void BeginDownload(MyMoney money, List <OnlineAccount> accounts)
 {
     this.myMoney  = money;
     this.accounts = accounts;
     this.ofxFiles = null;
     Start();
 }
Esempio n. 7
0
 public FreeStyleQueryDialog(MyMoney m, IDatabase database)
 {
     this.database = database;
     InitializeComponent();
     this.Owner = Application.Current.MainWindow;
     myMoney    = m;
 }
Esempio n. 8
0
 public TaxReport(FlowDocumentView view, MyMoney money, int fiscalYearStart)
 {
     this.fiscalYearStart = fiscalYearStart;
     this.view            = view;
     SetStartDate(DateTime.Now.Year);
     this.money = money;
 }
Esempio n. 9
0
        private MyMoney Load()
        {
            MyMoney result = database.Load(null);

            database.Disconnect();
            return(result);
        }
Esempio n. 10
0
        public StockQuoteManager(IServiceProvider provider, List <StockServiceSettings> settings, string logPath)
        {
            this._logPath = logPath;
            EnsurePathExists(logPath);
            this.Settings         = settings;
            this.provider         = provider;
            this.myMoney          = (MyMoney)provider.GetService(typeof(MyMoney));
            this.status           = (IStatusService)provider.GetService(typeof(IStatusService));
            this.myMoney.Changed += new EventHandler <ChangeEventArgs>(OnMoneyChanged);

            // assume we have fetched all securities.
            // call UpdateQuotes to refetch them all again, otherwise this
            // class will track changes and automatically fetch any new securities that it finds.
            foreach (Security s in myMoney.Securities.AllSecurities)
            {
                if (!string.IsNullOrEmpty(s.Symbol))
                {
                    lock (fetched)
                    {
                        fetched.Add(s.Symbol);
                    }
                }
            }
            _downloadLog = DownloadLog.Load(logPath);
        }
Esempio n. 11
0
        public void CostBasisAcrossTransfers()
        {
            UiDispatcher.CurrentDispatcher = System.Windows.Threading.Dispatcher.CurrentDispatcher;
            MyMoney  m = new MyMoney();
            Security s = m.Securities.NewSecurity();

            s.Name = "MSFT";
            Account a  = m.Accounts.AddAccount("Ameritrade");
            Account a2 = m.Accounts.AddAccount("Fidelity");

            AddInvestment(m, s, a, DateTime.Parse("1/1/2000"), 10, 1, InvestmentType.Buy);
            m.StockSplits.AddStockSplit(new StockSplit()
            {
                Date        = DateTime.Parse("6/1/2000"),
                Numerator   = 2,
                Denominator = 1,
                Security    = s
            });
            AddInvestment(m, s, a, DateTime.Parse("1/1/2001"), 20, 2, InvestmentType.Buy);

            Transaction transfer = AddInvestment(m, s, a, DateTime.Parse("1/1/2002"), 30, 2, InvestmentType.Remove);

            m.Transfer(transfer, a2);

            // now should be able to sell 10 left in this account (after split)
            AddInvestment(m, s, a, DateTime.Parse("1/1/2003"), 10, 3, InvestmentType.Sell);

            // and we should have 30 in the other account
            AddInvestment(m, s, a2, DateTime.Parse("1/1/2004"), 30, 5, InvestmentType.Sell);

            // Ok, now let's if the cost basis is correct!
            CostBasisCalculator     calc     = new CostBasisCalculator(m, DateTime.Now);
            List <SecurityPurchase> holdings = new List <SecurityPurchase>(calc.GetHolding(a).GetHoldings());

            Assert.AreEqual <int>(0, holdings.Count); // should have nothing left.

            // should have 3 separate cost basis records to cover what we sold.
            List <SecuritySale> sales = new List <SecuritySale>(calc.GetSales());

            Assert.AreEqual <int>(3, sales.Count);

            SecuritySale s1 = sales[0];
            SecuritySale s2 = sales[1];
            SecuritySale s3 = sales[2];

            // since the sale from Ameritrade account happened first it should be returned first
            Assert.AreEqual <decimal>(2, s1.CostBasisPerUnit); // $2, no splits
            Assert.AreEqual(a, s1.Account);                    // Ameritrade
            Assert.AreEqual <decimal>(Math.Round(10M, 5), Math.Round(s1.UnitsSold, 5));

            // Notice here that the Fidelity account inherited the cost basis records correctly
            // from the Ameritrade account as a result of the "Transfer" that happened above.
            Assert.AreEqual <decimal>(Math.Round(1M / 2M, 5), Math.Round(s2.CostBasisPerUnit, 5)); // $1 after 2:1 split
            Assert.AreEqual(a2, s2.Account);                                                       // Fidelity
            Assert.AreEqual <decimal>(Math.Round(20M, 5), Math.Round(s2.UnitsSold, 5));

            Assert.AreEqual <decimal>(2, s3.CostBasisPerUnit); // $2, no splits
            Assert.AreEqual(a2, s2.Account);                   // Fidelity
            Assert.AreEqual <decimal>(Math.Round(10M, 5), Math.Round(s3.UnitsSold, 5));
        }
Esempio n. 12
0
        static public Account PickAccount(MyMoney money, string id)
        {
            SelectAccountDialog frm = new SelectAccountDialog();

            frm.Title = "Select Account for: " + id;
            frm.SetAccounts(money.Accounts.GetAccounts());
            frm.Owner = App.Current.MainWindow;
            Account a = null;

            if (frm.ShowDialog() == true)
            {
                a = frm.SelectedAccount;
                Debug.Assert(a != null, "FormAccountSelect should have selected an account");
            }
            if (frm.AddAccount)
            {
                AccountDialog newAccountDialog = new AccountDialog(money, a, App.Current.MainWindow as IServiceProvider);
                newAccountDialog.Owner = App.Current.MainWindow;
                if (newAccountDialog.ShowDialog() == true)
                {
                    a = newAccountDialog.TheAccount;
                    money.Accounts.Add(a);
                }
            }
            else if (frm.Cancel)
            {
                return(null);
            }
            return(a);
        }
        private void ImportMoneyFile(MyMoney newMoney, AttachmentManager newAttachments)
        {
            this.dispatcher.Invoke(new Action(() =>
            {
                // gather accounts to be merged (skipping closed accounts).
                foreach (var acct in newMoney.Accounts)
                {
                    if (!acct.IsClosed && !acct.IsCategoryFund)
                    {
                        list.Add(new AccountImportState()
                        {
                            Dispatcher = this.dispatcher,
                            Account    = acct,
                            Name       = acct.Name,
                        });
                    }
                }
            }));

            foreach (AccountImportState a in list)
            {
                ImportAccount(newMoney, a, newAttachments);
            }

            ShowStatus("Done");
        }
Esempio n. 14
0
 /// <summary>
 /// Create new PortfolioReport.
 /// </summary>
 /// <param name="money">The money data</param>
 /// <param name="account">The account, or null to get complete portfolio</param>
 public PortfolioReport(FrameworkElement view, MyMoney money, Account account, IServiceProvider serviceProvider, DateTime asOfDate)
 {
     this.myMoney                   = money;
     this.account                   = account;
     this.serviceProvider           = serviceProvider;
     this.view                      = view;
     this.reportDate                = asOfDate;
     view.PreviewMouseLeftButtonUp += OnPreviewMouseLeftButtonUp;
 }
Esempio n. 15
0
        void AddSampleData()
        {
            ContextMenu subMenu = window.MainMenu.OpenSubMenu("MenuHelp");

            subMenu.InvokeMenuItem("MenuSampleData");

            AutomationElement msgbox = window.FindChildWindow("Add Sample Data", 5);

            if (msgbox != null)
            {
                MessageBoxWrapper mbox = new MessageBoxWrapper(msgbox);
                mbox.ClickYes();
            }

            AutomationElement child = window.FindChildWindow("Sample Database Options", 10);

            if (child != null)
            {
                SampleDataDialogWrapper cd = new SampleDataDialogWrapper(child);
                cd.ClickOk();
            }

            Thread.Sleep(5000);
            window.WaitForInputIdle(5000);

            Save();

            sampleData = true;

            // give database time to flush...
            Thread.Sleep(2000);

            // now load the database and pull out the categories.
            MyMoney money = Load();

            List <string> categories = new List <string>();

            foreach (Category c in money.Categories)
            {
                string cat = c.GetFullName();
                categories.Add(cat);
            }
            categories.Sort();
            SampleCategories = categories.ToArray();


            List <string> payees = new List <string>();

            foreach (Payee p in money.Payees)
            {
                payees.Add(p.Name);
            }
            payees.Sort();
            SamplePayees = payees.ToArray();

            ClearTransactionViewState();
        }
Esempio n. 16
0
        public static void UserDefined()
        {
            MyMoney myMoney = new MyMoney(42.43M);

            decimal dMoney = myMoney;
            int     iMoney = (int)myMoney;

            Console.WriteLine($"Implicit decimal value: {dMoney}, Explicit int value: {iMoney}");
        }
Esempio n. 17
0
        public RecategorizeDialog(MyMoney money)
        {
            InitializeComponent();
            this.myMoney = money;

            var source = new ListCollectionView(((List <Category>)myMoney.Categories.SortedCategories).ToArray());

            ComboToCategory.ItemsSource = source;
        }
Esempio n. 18
0
 public W2Report(FlowDocumentView view, MyMoney money, IServiceProvider sp)
 {
     this.myMoney                   = money;
     this.year                      = DateTime.Now.Year;
     this.view                      = view;
     this.serviceProvider           = sp;
     view.PreviewMouseLeftButtonUp += OnPreviewMouseLeftButtonUp;
     this.taxCategories             = new TaxCategoryCollection();
 }
Esempio n. 19
0
        private void ReverseTransfer(Transaction t)
        {
            MyMoney.BeginUpdate();
            decimal amount = -t.Amount;

            t.IsBudgeted = false;
            t.Transfer.Transaction.IsBudgeted = false;
            this.MyMoney.RemoveTransaction(t);
            MyMoney.EndUpdate();
        }
Esempio n. 20
0
 public W2Report(FlowDocumentView view, MyMoney money, IServiceProvider sp, int fiscalYearStart)
 {
     this.myMoney         = money;
     this.fiscalYearStart = fiscalYearStart;
     SetStartDate(DateTime.Now.Year);
     this.view                      = view;
     this.serviceProvider           = sp;
     view.PreviewMouseLeftButtonUp += OnPreviewMouseLeftButtonUp;
     this.taxCategories             = new TaxCategoryCollection();
 }
Esempio n. 21
0
        public BudgetReport(FlowDocumentView view, MyMoney money)
        {
            this.money = money;

            if (view != null)
            {
                var doc = view.DocumentViewer.Document;
                doc.Blocks.InsertAfter(doc.Blocks.FirstBlock, new BlockUIContainer(CreateExportReportButton()));
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Easy wrapper for launching the Rename Payee Dialog
        /// This version allows you to set the "Rename To" field, used in the Drag and Drop scenario
        /// </summary>
        /// <param name="myMoney"></param>
        /// <param name="fromPayee"></param>
        /// <param name="renameToThisPayee"></param>
        /// <returns></returns>
        public static RenamePayeeDialog ShowDialogRenamePayee(IServiceProvider sp, MyMoney myMoney, Payee fromPayee, Payee renameToThisPayee)
        {
            RenamePayeeDialog dialog = new RenamePayeeDialog();

            dialog.Owner           = Application.Current.MainWindow;
            dialog.MyMoney         = myMoney;
            dialog.ServiceProvider = sp;
            dialog.Payee           = fromPayee;
            dialog.RenameTo        = renameToThisPayee;
            return(dialog);
        }
Esempio n. 23
0
        public CashFlowReport(FlowDocumentView view, MyMoney money, IServiceProvider sp)
        {
            this.myMoney         = money;
            this.year            = DateTime.Now.Year;
            this.month           = DateTime.Now.Month;
            this.byYear          = true;
            this.columnCount     = 3;
            this.view            = view;
            this.serviceProvider = sp;

            view.PreviewMouseLeftButtonUp += OnPreviewMouseLeftButtonUp;
        }
Esempio n. 24
0
        public Account DeleteAccount(Account account)
        {
            string caption = "Delete Account: " + account.Name;

            if (MessageBoxEx.Show(string.Format("Are you sure you want to delete account '{0}'?\nThis is not undoable operation.", account.Name),
                                  caption, MessageBoxButton.YesNo) != MessageBoxResult.Yes)
            {
                return(null);
            }

            // figure out which account to select next.
            List <object> data  = (List <object>) this.listBox1.DataContext;
            Account       prev  = null;
            Account       next  = null;
            bool          found = false;

            for (int i = 0; i < data.Count; i++)
            {
                Account a = data[i] as Account;
                if (a != null)
                {
                    if (a == account)
                    {
                        found = true;
                    }
                    else if (!found)
                    {
                        prev = a;
                    }
                    else if (next == null)
                    {
                        next = a;
                        break;
                    }
                }
                else if (found && prev != null)
                {
                    // if we reach a section header then prefer the 'previous' account.
                    break;
                }
            }

            // mark it as deleted.
            MyMoney myMoney = this.MyMoney;

            myMoney.Accounts.RemoveAccount(account);

            // Rebind should have already happened, so we can now select the neighboring account.
            this.Selected = (next != null) ? next : prev;

            return(account);
        }
Esempio n. 25
0
        private static Transaction AddInvestment(MyMoney m, Security s, Account a, DateTime date, decimal units, decimal unitPrice, InvestmentType type)
        {
            Transaction t = m.Transactions.NewTransaction(a);

            t.Date = date;
            Investment i = t.GetOrCreateInvestment();

            i.Security  = s;
            i.Units     = units;
            i.UnitPrice = unitPrice;
            i.Type      = type;
            m.Transactions.AddTransaction(t);
            return(t);
        }
Esempio n. 26
0
 static public void ShowDetails(MyMoney money, Category c)
 {
     if (c != null)
     {
         CategoryDialog dialog = CategoryDialog.ShowDialogCategory(money, c.Name);
         dialog.Owner = App.Current.MainWindow;
         if (dialog.ShowDialog() == false)
         {
             // User clicked cancel
             return;
         }
         // todo: a bit ambiguous here what to do if they renamed the category...
         // for example, do we move all subcategories with it?
     }
 }
        static public Account PickAccount(MyMoney money, Account accountTemplate, string prompt)
        {
            SelectAccountDialog frm = new SelectAccountDialog();

            if (accountTemplate != null)
            {
                frm.Title = "Select Account for: " + accountTemplate.AccountId;
            }
            if (!string.IsNullOrEmpty(prompt))
            {
                frm.SetUnknownAccountPrompt(prompt);
            }
            frm.SetAccounts(money.Accounts.GetAccounts());
            frm.Owner = App.Current.MainWindow;
            Account a = null;

            if (frm.ShowDialog() == true)
            {
                a = frm.SelectedAccount;
                Debug.Assert(a != null, "FormAccountSelect should have selected an account");
            }
            if (frm.AddAccount)
            {
                AccountDialog newAccountDialog = new AccountDialog(money, accountTemplate, App.Current.MainWindow as IServiceProvider);
                newAccountDialog.Owner = App.Current.MainWindow;
                if (newAccountDialog.ShowDialog() == true)
                {
                    a = newAccountDialog.TheAccount;
                    money.Accounts.Add(a);
                }
            }
            else if (frm.Cancel)
            {
                return(null);
            }
            else if (a != null && accountTemplate != null)
            {
                if (a.AccountId != accountTemplate.AccountId)
                {
                    // then make an alias for this account so we don't have to ask again next time.
                    money.AccountAliases.AddAlias(new AccountAlias()
                    {
                        AliasType = AliasType.None, Pattern = accountTemplate.AccountId, AccountId = a.AccountId
                    });
                }
            }
            return(a);
        }
Esempio n. 28
0
        public AccountDialog(MyMoney money, Account a, IServiceProvider sp)
        {
            InitializeComponent();

            this.serviceProvider = sp;

            onlineAccounts.Add(string.Empty); // so you can clear it out.
            this.money      = money;
            this.Owner      = Application.Current.MainWindow;
            this.TheAccount = a;
            onlineAccounts.Add(NewLabel); // so you can add new online accounts.

            List <string> currencies = new List <string>(Enum.GetNames(typeof(RestfulWebServices.CurrencyCode)));

            currencies.Sort();
            ComboBoxCurrency.ItemsSource = currencies;

            comboBoxOnlineAccount.ItemsSource = onlineAccounts;

            foreach (var alias in money.AccountAliases)
            {
                if (alias.AccountId == a.AccountId && !alias.IsDeleted)
                {
                    comboBoxAccountAliases.Items.Add(alias);
                }
            }
            if (comboBoxAccountAliases.Items.Count > 0)
            {
                comboBoxAccountAliases.SelectedIndex = 0;
            }

            foreach (var field in typeof(TaxStatus).GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static))
            {
                var value = (TaxStatus)field.GetValue(null);
                ComboBoxTaxStatus.Items.Add(value);
            }

            UpdateUI();

            money.Changed += new EventHandler <ChangeEventArgs>(OnMoneyChanged);


            CheckButtonStates();

            this.TextBoxName.Focus();

            this.Closed += AccountDialog_Closed;
        }
Esempio n. 29
0
        public void SimpleCostBasis()
        {
            UiDispatcher.CurrentDispatcher = System.Windows.Threading.Dispatcher.CurrentDispatcher;
            MyMoney  m = new MyMoney();
            Security s = m.Securities.NewSecurity();

            s.Name = "MSFT";
            Account a = m.Accounts.AddAccount("Checking");

            AddInvestment(m, s, a, DateTime.Parse("1/1/2000"), 10, 1, InvestmentType.Add);
            m.StockSplits.AddStockSplit(new StockSplit()
            {
                Date        = DateTime.Parse("6/1/2000"),
                Numerator   = 2,
                Denominator = 1,
                Security    = s
            });
            AddInvestment(m, s, a, DateTime.Parse("1/1/2001"), 10, 2, InvestmentType.Sell);
            AddInvestment(m, s, a, DateTime.Parse("1/1/2002"), 20, 2, InvestmentType.Buy);

            m.StockSplits.AddStockSplit(new StockSplit()
            {
                Date        = DateTime.Parse("6/1/2002"),
                Numerator   = 3,
                Denominator = 1,
                Security    = s
            });

            AddInvestment(m, s, a, DateTime.Parse("1/1/2003"), 10, 3, InvestmentType.Buy);
            AddInvestment(m, s, a, DateTime.Parse("1/1/2004"), 20, 3, InvestmentType.Sell);

            Transaction sale = AddInvestment(m, s, a, DateTime.Parse("1/1/2005"), 20, 5, InvestmentType.Sell);


            CapitalGainsTaxCalculator calc     = new CapitalGainsTaxCalculator(m, DateTime.Now, false, false);
            List <SecurityPurchase>   holdings = new List <SecurityPurchase>(calc.GetHolding(a).GetHoldings());

            Assert.AreEqual <int>(2, holdings.Count); // should have only 2 buys left, the first buy is all used up.
            SecurityPurchase c1 = holdings[0];
            SecurityPurchase c2 = holdings[1];

            Assert.AreEqual <decimal>(50, c1.UnitsRemaining);                                      // 50 shares left in this one (after stock splits)
            Assert.AreEqual <decimal>(10, c2.UnitsRemaining);                                      // 10 shares still in this one (has no stock spits)
            Assert.AreEqual <decimal>(Math.Round(2M / 3M, 5), Math.Round(c1.CostBasisPerUnit, 5)); // a 3:1 split
            Assert.AreEqual <decimal>(Math.Round(3M, 5), Math.Round(c2.CostBasisPerUnit, 5));      // no splits apply.
        }
Esempio n. 30
0
        public StockQuotes(IServiceProvider provider)
        {
            this.provider         = provider;
            this.myMoney          = (MyMoney)provider.GetService(typeof(MyMoney));
            this.status           = (IStatusService)provider.GetService(typeof(IStatusService));
            this.myMoney.Changed += new EventHandler <ChangeEventArgs>(OnMoneyChanged);

            // assume we have fetched all securities.
            // call UpdateQuotes to refetch them all again, otherwise this
            // class will track changes and automatically fetch any new securities that it finds.
            foreach (Security s in myMoney.Securities.AllSecurities)
            {
                if (!string.IsNullOrEmpty(s.Symbol))
                {
                    fetched.Add(s.Symbol);
                }
            }
        }