Example #1
0
        Journal.XBankAccount CreateAccount()
        {
            Journal.XBankAccount newAccount = new Journal.XBankAccount(this.TSPlayer.UserAccountName, Terraria.Main.worldID, Journal.BankAccountFlags.Enabled, "");
            TShockAPI.Log.ConsoleInfo(string.Format("seconomy: bank account for {0} created.", TSPlayer.UserAccountName));

            return(Journal.TransactionJournal.AddBankAccount(newAccount));
        }
Example #2
0
        /// <summary>
        /// Fires when a user wants to delete some transactions
        /// </summary>
        private void ctxDeleteTransactionConfirm_Click(object sender, EventArgs e)
        {
            gvTransactions.Enabled  = false;
            gvAccounts.Enabled      = false;
            btnRefreshTrans.Enabled = false;
            btnResetTrans.Enabled   = false;

            Task.Factory.StartNew(() => {
                int count = gvTransactions.SelectedRows.Count;

                for (int i = 0; i < gvTransactions.SelectedRows.Count; i++)
                {
                    DataGridViewRow selectedItem = gvTransactions.SelectedRows[i];

                    if (selectedItem.DataBoundItem != null)
                    {
                        Journal.XTransaction selectedTrans = selectedItem.DataBoundItem as Journal.XTransaction;

                        if (selectedTrans != null)
                        {
                            //invoke GUI updates on gui thread
                            this.MainThreadInvoke(() => {
                                lblStatus.Text = string.Format("Deleted transaction {0} for {1}", selectedTrans.BankAccountTransactionK, ((Money)selectedTrans.Amount).ToLongString(true));
                                toolStripProgressBar1.Value = Convert.ToInt32(((double)i / (double)count) * 100);
                            });

                            ((XElement)selectedTrans).Remove();
                        }
                    }
                }
            }).ContinueWith((task) => {
                this.MainThreadInvoke(() => {
                    AccountSummary summary = gvAccounts.SelectedRows[0].DataBoundItem as AccountSummary;
                    Journal.XBankAccount selectedUserAccount = Journal.TransactionJournal.GetBankAccount(summary.Value);

                    if (selectedUserAccount != null)
                    {
                        selectedUserAccount.SyncBalanceAsync().ContinueWith((t) => {
                            AccountSummary selectedSummary = accList.FirstOrDefault(i => i.Value == selectedUserAccount.BankAccountK);

                            if (summary != null)
                            {
                                summary.Balance = selectedUserAccount.Balance;
                            }
                        });
                    }

                    toolStripProgressBar1.Value = 100;

                    gvTransactions.Enabled  = true;
                    gvAccounts.Enabled      = true;
                    btnRefreshTrans.Enabled = true;
                    btnResetTrans.Enabled   = true;
                    btnShowFrom.Enabled     = true;

                    LoadTransactionsForUser(summary.Value);
                });
            });
        }
Example #3
0
        /// <summary>
        /// Constructs a new BankAccount from the supplied database object.
        /// </summary>
        public BankAccount(Journal.XBankAccount Account)
        {
            // this.DatabaseBankAccount = Account;
            _flags               = Account.Flags;
            this.BankAccountK    = Account.BankAccountK;
            this.BankAccountName = Account.UserAccountName;
            this.WorldID         = Account.WorldID;

            //refresh the balance from the database, money will be set when the async I/O finishes
            //this.DatabaseBankAccount.GetBalanceFromDatabaseAsync().ContinueWith((balanceResult) => {
            //    _money = balanceResult.Result;
            //});
        }
Example #4
0
        /// <summary>
        /// Ensures a bank account exists for the logged-in user and makes sure it's loaded properly.
        /// </summary>
        public void EnsureBankAccountExists()
        {
            Guid p = SEconomyPlugin.Profiler.Enter("BankAccount Load: " + this.TSPlayer.Name);

            Journal.XBankAccount account = Journal.TransactionJournal.GetBankAccountByName(this.TSPlayer.UserAccountName);
            if (account == null)
            {
                account = CreateAccount();
            }

            this.BankAccount = account;

            BankAccount.SyncBalanceAsync().ContinueWith((task) => {
                OnAccountLoaded();
                SEconomyPlugin.Profiler.ExitLog(p);
            });
        }
Example #5
0
        void LoadTransactionsForUser(string BankAccountK)
        {
            Journal.XBankAccount selectedAccount = Journal.TransactionJournal.GetBankAccount(BankAccountK);

            var qTransactions = (from i in Journal.TransactionJournal.Transactions
                                 where i.BankAccountFK == BankAccountK
                                 orderby i.TransactionDateUtc
                                 select i).ToArray();

            gvTransactions.DataSource = null;
            gvTransactions.DataSource = qTransactions;

            tranList = Journal.TransactionJournal.Transactions.ToList();

            lblStatus.Text = string.Format("Loaded {0} transactions for {1}.", qTransactions.Count(), BankAccountK);


            if (selectedAccount.Owner != null)
            {
                lblOnline.Text      = "Online";
                lblOnline.ForeColor = System.Drawing.Color.DarkGreen;
            }
            else
            {
                lblOnline.Text      = "Offline";
                lblOnline.ForeColor = System.Drawing.Color.Red;
            }

            selectedAccount.SyncBalanceAsync().ContinueWith((task) => {
                AccountSummary summary = accList.FirstOrDefault(i => i.Value == BankAccountK);

                if (summary != null)
                {
                    summary.Balance = selectedAccount.Balance;
                }

                lblBalance.Text = selectedAccount.Balance.ToLongString(true);
                lblName.Text    = string.Format("{0}, acccount ID {1}", selectedAccount.UserAccountName, selectedAccount.BankAccountK);
            });
        }
Example #6
0
        void LoadBankAccount(string BankAccountK)
        {
            Guid profile = SEconomyPlugin.Profiler.Enter(this.TSPlayer.UserAccountName + " LoadBankAccount");

            Journal.XBankAccount account = Journal.TransactionJournal.GetBankAccount(BankAccountK);

            if (account != null)
            {
                this.BankAccount = account;

                BankAccount.SyncBalanceAsync().ContinueWith((task) => {
                    OnAccountLoaded();
                    TShockAPI.Log.ConsoleInfo(string.Format("seconomy: bank account for {0} loaded.", TSPlayer.UserAccountName));
                    SEconomyPlugin.Profiler.ExitLog(profile);
                });
            }
            else
            {
                TShockAPI.Log.ConsoleError(string.Format("seconomy: bank account for {0} failed.", TSPlayer.UserAccountName));
                this.TSPlayer.SendErrorMessage("It appears you don't have a bank account.");
            }
        }
Example #7
0
        Task LoadAccountsAsync()
        {
            return(Task.Factory.StartNew(() => {
                List <Journal.XBankAccount> accountList = Journal.TransactionJournal.BankAccounts.ToList();
                List <Journal.XTransaction> transList = Journal.TransactionJournal.Transactions.ToList();

                this.MainThreadInvoke(() => {
                    gvTransactions.Enabled = false;
                    gvAccounts.Enabled = false;
                    btnRefreshTrans.Enabled = false;
                    btnResetTrans.Enabled = false;

                    lblStatus.Text = "Syncing accounts";
                });

                //Sync the account list
                for (int i = 0; i < accountList.Count; i++)
                {
                    Journal.XBankAccount account = accountList.ElementAt(i);

                    sourceAccList.Add(new AccountSummary()
                    {
                        Name = account.UserAccountName, Balance = account.Balance, Value = account.BankAccountK
                    });

                    int p = Convert.ToInt32(((double)i / (double)accountList.Count) * 100);

                    this.MainThreadInvoke(() => {
                        toolStripProgressBar1.Value = p;
                    });
                }

                this.MainThreadInvoke(() => {
                    lblStatus.Text = "Syncing transactions";
                });

                //Sync balances into accounts
                for (int i = 0; i < transList.Count; i++)
                {
                    Journal.XTransaction trans = transList.ElementAt(i);

                    if (trans != null)
                    {
                        AccountSummary summary = sourceAccList.FirstOrDefault(x => x.Value == trans.BankAccountFK);

                        if (summary != null)
                        {
                            summary.Balance += trans.Amount;
                        }
                    }

                    int p = Convert.ToInt32(((double)i / (double)transList.Count) * 100);
                    this.MainThreadInvoke(() => {
                        toolStripProgressBar1.Value = p;
                    });
                }

                this.MainThreadInvoke(() => {
                    accList = new BindingList <AccountSummary>(sourceAccList.OrderByDescending(x => (long)x.Balance).ToList());
                    gvAccounts.DataSource = accList;

                    gvTransactions.Enabled = true;
                    gvAccounts.Enabled = true;
                    btnRefreshTrans.Enabled = true;
                    btnResetTrans.Enabled = true;

                    lblStatus.Text = "Done.";
                });
            }));
        }
Example #8
0
        private void btnResetTrans_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("This will delete all transactions for this user.  This could take a long time and SEconomy performance could be impacted.  The user's balance will be reset to 0 copper.", "Delete all Transactions", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)
            {
                gvTransactions.Enabled  = false;
                gvAccounts.Enabled      = false;
                btnRefreshTrans.Enabled = false;
                btnResetTrans.Enabled   = false;
                btnShowFrom.Enabled     = false;

                lblStatus.Text = "Resetting all transactions for " + currentlySelectedAccount.Name;
                toolStripProgressBar1.Value = 0;
                toolStripProgressBar1.Style = ProgressBarStyle.Marquee;


                Task.Factory.StartNew(() => {
                    Journal.TransactionJournal.XmlJournal.Element("Journal").Element("Transactions").Elements("Transaction").Where(i => i.Attribute("BankAccountFK").Value == currentlySelectedAccount.Value).Remove();


                    List <Journal.XTransaction> tranList = Journal.TransactionJournal.Transactions.Where(i => i.BankAccountFK == currentlySelectedAccount.Value).ToList();

                    int count = tranList.Count();

                    for (int i = 0; i < count; i++)
                    {
                        Journal.XTransaction selectedTrans = Journal.TransactionJournal.Transactions.FirstOrDefault(x => x.BankAccountTransactionK == tranList.ElementAt(i).BankAccountTransactionK);


                        if (selectedTrans != null)
                        {
                            //invoke GUI updates on gui thread
                            this.MainThreadInvoke(() => {
                                lblStatus.Text = string.Format("Deleted transaction {0} for {1}", selectedTrans.BankAccountTransactionK, ((Money)selectedTrans.Amount).ToLongString(true));
                                toolStripProgressBar1.Value = Convert.ToInt32(((double)i / (double)count) * 100);
                            });

                            ((XElement)selectedTrans).Remove();
                        }
                    }
                }).ContinueWith((task) => {
                    Journal.XBankAccount selectedUserAccount = Journal.TransactionJournal.GetBankAccount(currentlySelectedAccount.Value);

                    if (selectedUserAccount != null)
                    {
                        selectedUserAccount.SyncBalanceAsync().ContinueWith((t) => {
                            AccountSummary summary = accList.FirstOrDefault(i => i.Value == selectedUserAccount.BankAccountK);

                            if (summary != null)
                            {
                                summary.Balance = selectedUserAccount.Balance;
                            }

                            this.MainThreadInvoke(() => {
                                toolStripProgressBar1.Value = 100;
                                toolStripProgressBar1.Style = ProgressBarStyle.Continuous;

                                gvTransactions.Enabled  = true;
                                gvAccounts.Enabled      = true;
                                btnRefreshTrans.Enabled = true;
                                btnResetTrans.Enabled   = true;

                                //force the bindinglist to raise the reset event updating the right hand side
                                accList.ResetBindings();

                                LoadTransactionsForUser(currentlySelectedAccount.Value);
                            });
                        });
                    }
                });
            }
        }
        Journal.XBankAccount CreateAccount() {
            Journal.XBankAccount newAccount = new Journal.XBankAccount(this.TSPlayer.UserAccountName, Terraria.Main.worldID, Journal.BankAccountFlags.Enabled, "");
            TShockAPI.Log.ConsoleInfo(string.Format("seconomy: bank account for {0} created.", TSPlayer.UserAccountName));

            return Journal.TransactionJournal.AddBankAccount(newAccount);
        }