Esempio n. 1
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);
        }
        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);
        }