private void CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } var gridView = (DataGridView)sender; var row = gridView.Rows[e.RowIndex]; var cell = row.Cells[e.ColumnIndex]; var cellName = cell.OwningColumn.Name; TxTag txTag = cell.Tag as TxTag; if (txTag == null) { return; } Tx tx = _accountService.GetTx(txTag.Id); if (!tx.Teammate.Team.IsInNormalState) { return; } if (cellName == ColFrom) { OpenBrowser(tx.Teammate.TeamId, null, tx.Teammate.Id, false); } if (cellName == ColTo) { var output = tx.Outputs.OrderByDescending(x => x.AmountBTC).ToList()[_curSubRow]; OpenBrowser(tx.Teammate.TeamId, null, output.PayTo.Teammate.Id, false); } if (cellName == ColDescription && tx.Kind == TxKind.Payout) { OpenBrowser(tx.Teammate.TeamId, tx.ClaimId.Value, null, false); } if (cellName == ColDescription && tx.Kind == TxKind.Withdraw) { OpenBrowser(tx.Teammate.TeamId, null, null, true); } if (cellName == ColApprove && cell is DataGridViewButtonCell) { _accountService.ChangeTxResolution(tx, TxClientResolution.Approved); UpdateTxStatus(_accountService, row); _accountService.SaveChanges(); } if (cellName == ColBlock && cell is DataGridViewButtonCell) { _accountService.ChangeTxResolution(tx, tx.Resolution == TxClientResolution.Blocked ? TxClientResolution.Received : TxClientResolution.Blocked); UpdateTxStatus(_accountService, row); _accountService.SaveChanges(); } }
private void UpdateTxStatus(AccountService accountService, DataGridViewRow row) { TxTag txTag = (TxTag)row.Tag; Tx tx = accountService.GetTx(txTag.Id); var isMyTX = accountService.IsMyTx(tx.TeammateId); var gridView = isMyTX ? _myTxGridView : _cosignTxGridView; row.Cells[ColStatus].Value = accountService.GetTxStatusText(tx, isMyTX); Padding newPadding = new Padding(0, 2, 2, 1 + Math.Max(1, (tx.Outputs.Count - 1) * _cellFontHeight)); if (accountService.CanApproveTx(tx)) { row.Cells[ColApprove] = new DataGridViewButtonCell(); row.Cells[ColApprove].Tag = txTag; row.Cells[ColApprove].Value = "Approve"; row.Cells[ColApprove].Style.Padding = newPadding; } else { row.Cells[ColApprove] = new DataGridViewTextBoxCell { }; } if (accountService.CanBlockTx(tx) || accountService.CanUnblockTx(tx)) { if (false == row.Cells[ColBlock] is DataGridViewButtonCell) { row.Cells[ColBlock] = new DataGridViewButtonCell { }; } row.Cells[ColBlock].Tag = txTag; row.Cells[ColBlock].Style.Padding = newPadding; if (accountService.CanBlockTx(tx)) { row.Cells[ColBlock].Value = isMyTX ? "Block" : "Decline"; } else { row.Cells[ColBlock].Value = isMyTX ? "Unblock" : "Revise"; } } else { row.Cells[ColBlock] = new DataGridViewTextBoxCell { }; } }
public static bool Equals(TxTag t1, TxTag t2) { if (ReferenceEquals(t1, t2)) { return(true); } if (t1 == null || t2 == null) { return(false); } return(t1.Id == t2.Id); }
private void AddOrUpdateTxInGrid(AccountService accountService, Tx tx) { bool isMyTx = accountService.IsMyTx(tx.TeammateId); var gridView = isMyTx ? _myTxGridView : _cosignTxGridView; var txTag = GetFromTx(tx); DataGridViewRow row = null; foreach (DataGridViewRow r in gridView.Rows) { if (TxTag.Equals(r.Tag as TxTag, txTag)) { row = r; break; } } if (row == null) { row = new DataGridViewRow(); row.Tag = txTag; row.CreateCells(gridView); gridView.Rows.Insert(0, row); row = gridView.Rows[0]; } row.Cells[ColInitiated].Value = tx.InitiatedTime.ToString(); row.Cells[ColInitiated].Tag = tx.InitiatedTime; if (!isMyTx) { row.Cells[ColFrom].Value = tx.Teammate.Name.Replace(' ', NBSP); row.Cells[ColFrom].Tag = txTag; } var amounts = ""; var destinations = ""; var descriptions = ""; int subRow = 0; row.Cells[ColAmount].Tag = txTag; row.Cells[ColTo].Tag = txTag; row.Cells[ColDescription].Tag = txTag; row.Cells[ColStatus].Tag = txTag; foreach (var txOutput in tx.Outputs.OrderByDescending(x => x.AmountBTC)) { if (amounts.Length > 0) { amounts += Environment.NewLine; destinations += Environment.NewLine; descriptions += Environment.NewLine; } amounts += GetSubRowText(tx, row.Cells[ColAmount], subRow); destinations += GetSubRowText(tx, row.Cells[ColTo], subRow); descriptions += GetSubRowText(tx, row.Cells[ColDescription], subRow); subRow++; } row.Cells[ColAmount].Value = amounts; row.Cells[ColTo].Value = destinations; row.Cells[ColDescription].Value = descriptions; UpdateTxStatus(accountService, row); }
private void CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e.RowIndex == -1) { return; } var gridView = (DataGridView)sender; var cell = gridView.Rows[e.RowIndex].Cells[e.ColumnIndex]; var cellName = cell.OwningColumn.Name; var isSubrowCell = (cellName == ColAmount || cellName == ColTo || cellName == ColDescription); var isDateCell = (cellName == ColInitiated); var isFromCell = (cellName == ColFrom); var isStatusCell = (cellName == ColStatus); if (!isSubrowCell && !isDateCell && !isStatusCell && !isFromCell) { return; } using ( Brush gridBrush = new SolidBrush(gridView.GridColor), backColorBrush = new SolidBrush(e.CellStyle.BackColor)) { using (Pen gridLinePen = new Pen(gridBrush)) { e.Graphics.FillRectangle(backColorBrush, e.CellBounds); e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, e.CellBounds.Bottom - 1); } } var startPoint = new PointF(e.CellBounds.X + cell.OwningColumn.DefaultCellStyle.Padding.Left, e.CellBounds.Y + cell.OwningColumn.DefaultCellStyle.Padding.Top); if (e.Value != null && isSubrowCell) { TxTag txTag = (TxTag)cell.Tag; Tx tx = _accountService.GetTx(txTag.Id); int subRow = 0; foreach (var txOutput in tx.Outputs.OrderByDescending(x => x.AmountBTC)) { var text = GetSubRowText(tx, cell, subRow); SizeF textArea = _graphics.MeasureString(text, _underlinedFont); var startPoint2 = new PointF { X = startPoint.X + textArea.Width, Y = startPoint.Y }; var brush = Brushes.Black; var font = e.CellStyle.Font; if (cellName == ColTo || cellName == ColDescription && tx.Kind == TxKind.Payout || cellName == ColDescription && tx.Kind == TxKind.Withdraw) { brush = Brushes.RoyalBlue; if (_curSubRow == subRow && _curRow == e.RowIndex && _curColumn == e.ColumnIndex) { font = _underlinedFont; } } e.Graphics.DrawString(text, font, brush, startPoint, StringFormat.GenericDefault); bool goodPayToAddress = _accountService.IsPayToAddressOkAge(txOutput); if (cellName == ColTo && !goodPayToAddress) { e.Graphics.DrawString("\xEA", _iconsFont, Brushes.Goldenrod, startPoint.X, startPoint.Y - 2, StringFormat.GenericDefault); e.Graphics.DrawString("!", _icons2Font, Brushes.Goldenrod, startPoint.X + 8F, startPoint.Y + 2, StringFormat.GenericDefault); } if (cellName == ColTo && goodPayToAddress) { e.Graphics.DrawString("\u25CF", _icons2Font, Brushes.MediumSeaGreen, startPoint.X + 6, startPoint.Y + 2, StringFormat.GenericDefault); } if (cellName == ColDescription && tx.Kind == TxKind.Payout) { string reason = " - reimbursement"; if (txOutput.PayTo.TeammateId != tx.ClaimTeammateId) { reason = " - for voting"; } e.Graphics.DrawString(reason, e.CellStyle.Font, Brushes.Black, startPoint2, StringFormat.GenericDefault); } startPoint.Y += (_cellFontHeight + 1); subRow++; } } if (e.Value != null && isFromCell) { var font = _mainFont; if (_curSubRow == 0 && _curRow == e.RowIndex && _curColumn == e.ColumnIndex) { font = _underlinedFont; } TxTag txTag = (TxTag)cell.Tag; Tx tx = _accountService.GetTx(txTag.Id); var text = GetSubRowText(tx, cell, 0); e.Graphics.DrawString(text, font, Brushes.RoyalBlue, startPoint, StringFormat.GenericDefault); } if (e.Value != null && isDateCell) { string textDate = ((DateTime)cell.Tag).ToShortDateString(); string textTime = ((DateTime)cell.Tag).ToLongTimeString(); SizeF textArea = _graphics.MeasureString(textDate, _underlinedFont); var startPoint2 = new PointF { X = startPoint.X + textArea.Width, Y = startPoint.Y }; e.Graphics.DrawString(textDate, e.CellStyle.Font, Brushes.Black, startPoint, StringFormat.GenericDefault); e.Graphics.DrawString(textTime, e.CellStyle.Font, Brushes.Silver, startPoint2, StringFormat.GenericDefault); } if (e.Value != null && isStatusCell) { TxTag txTag = (TxTag)cell.Tag; Tx tx = _accountService.GetTx(txTag.Id); var statusText = _accountService.GetTxStatusText(tx, gridView == _myTxGridView); e.Graphics.DrawString(statusText, e.CellStyle.Font, Brushes.Black, startPoint, StringFormat.GenericDefault); } e.Handled = true; }
private static TxTag GetFromTx(Tx tx) { var res = new TxTag(tx.Id); return(res); }