/// <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); }); }
private async void btnShowFrom_Click(object sender, EventArgs e) { var vivibleRowsCount = gvTransactions.DisplayedRowCount(true); var firstDisplayedRowIndex = gvTransactions.FirstDisplayedCell.RowIndex; var lastvibileRowIndex = (firstDisplayedRowIndex + vivibleRowsCount) - 1; for (int rowIndex = firstDisplayedRowIndex; rowIndex <= lastvibileRowIndex; rowIndex++) { var row = gvTransactions.Rows[rowIndex]; var cell = row.Cells.OfType <DataGridViewLinkCell>().FirstOrDefault(); if (string.IsNullOrEmpty(cell.Value as string)) { await Task.Factory.StartNew(() => { Journal.ITransaction trans = row.DataBoundItem as Journal.ITransaction; Journal.ITransaction oppositeTrans = tranList.FirstOrDefault(i => i.BankAccountTransactionK == trans.BankAccountTransactionFK); if (oppositeTrans != null) { AccountSummary oppositeAccount = accList.FirstOrDefault(i => i.Value == oppositeTrans.BankAccountFK); if (oppositeAccount != null) { this.MainThreadInvoke(() => { cell.Value = oppositeAccount.Name; }); } } else { this.MainThreadInvoke(() => { cell.LinkBehavior = LinkBehavior.NeverUnderline; cell.LinkColor = System.Drawing.Color.Gray; cell.Value = "{Unknown}"; }); } }); } } }