コード例 #1
0
        /// <summary>
        /// Fires when a user wants to delete some transactions
        /// </summary>
        private async void ctxDeleteTransactionConfirm_Click(object sender, EventArgs e)
        {
            gvTransactions.Enabled  = false;
            gvAccounts.Enabled      = false;
            btnRefreshTrans.Enabled = false;
            btnResetTrans.Enabled   = false;

            await 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.IBankAccount bankAccount;
                        Journal.ITransaction selectedTrans = selectedItem.DataBoundItem as Journal.ITransaction;

                        if (selectedTrans != null)
                        {
                            bankAccount = selectedTrans.BankAccount;

                            //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);
                            });

                            bankAccount.Transactions.Remove(selectedTrans);
                        }
                    }
                }
            });

            this.MainThreadInvoke(async() => {
                AccountSummary summary = gvAccounts.SelectedRows[0].DataBoundItem as AccountSummary;
                Journal.IBankAccount selectedUserAccount = SEconomyPlugin.Instance.RunningJournal.BankAccounts.FirstOrDefault(i => i.BankAccountK == summary.Value);

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

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

                toolStripProgressBar1.Value = 100;
                gvTransactions.Enabled      = true;
                gvAccounts.Enabled          = true;
                btnRefreshTrans.Enabled     = true;
                btnResetTrans.Enabled       = true;
                btnShowFrom.Enabled         = true;

                await LoadTransactionsForUser(summary.Value);
            });
        }
コード例 #2
0
        private async 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)
            {
                Journal.IBankAccount account = SecInstance.RunningJournal.GetBankAccount(currentlySelectedAccount.Value);

                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;


                await Task.Factory.StartNew(() => {
                    account.Transactions.Clear();
                });

                Journal.IBankAccount selectedUserAccount = SecInstance.RunningJournal.GetBankAccount(currentlySelectedAccount.Value);
                if (selectedUserAccount != null)
                {
                    await selectedUserAccount.SyncBalanceAsync();

                    AccountSummary summary = accList.FirstOrDefault(i => i.Value == selectedUserAccount.BankAccountK);

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

                    this.MainThreadInvoke(async() => {
                        toolStripProgressBar1.Value = 100;
                        toolStripProgressBar1.Style = ProgressBarStyle.Continuous;
                        gvTransactions.DataSource   = null;
                        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();

                        await LoadTransactionsForUser(currentlySelectedAccount.Value);
                    });
                }
            }
        }
コード例 #3
0
        async Task LoadTransactionsForUser(long BankAccountK)
        {
            Journal.IBankAccount selectedAccount = null;
            TSPlayer             player;
            List <ITransaction>  qTransactions;

            if (selectionEnabled == false)
            {
                return;
            }

            selectedAccount = SecInstance.RunningJournal.GetBankAccount(BankAccountK);
            qTransactions   = selectedAccount.Transactions;

            gvTransactions.DataSource = null;
            gvTransactions.DataSource = qTransactions;
            tranList = SecInstance.RunningJournal.Transactions;

            player = TShock.Players.FirstOrDefault(i => i != null && i.UserAccountName == selectedAccount.UserAccountName);

            lblStatus.Text = string.Format("Loaded {0} transactions for {1}.", qTransactions.Count(), selectedAccount.UserAccountName);
            if (player != null)
            {
                lblOnline.Text      = "Online";
                lblOnline.ForeColor = System.Drawing.Color.DarkGreen;
            }
            else
            {
                lblOnline.Text      = "Offline";
                lblOnline.ForeColor = System.Drawing.Color.Red;
            }

            await selectedAccount.SyncBalanceAsync();

            AccountSummary summary = accList.FirstOrDefault(i => i.Value == BankAccountK);

            if (summary != null)
            {
                summary.Balance = selectedAccount.Balance;
            }
            this.MainThreadInvoke(() => {
                lblBalance.Text = selectedAccount.Balance.ToLongString(true);
                lblName.Text    = string.Format("{0}, acccount ID {1}", selectedAccount.UserAccountName, selectedAccount.BankAccountK);
            });
        }