-
Notifications
You must be signed in to change notification settings - Fork 0
/
transactions.cs
100 lines (74 loc) · 2.97 KB
/
transactions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System.Data;
namespace Banking_App
{
public partial class Transactions : DataForm
{
private readonly int rowLength = 0;
public Transactions(Dictionary<string, string> loggedInUser, DashboardShowD dashboardShowB)
: base(loggedInUser, dashboardShowB)
{
var userTransRows = FileSystemCus.FindAll("transactions", user["id"]);
InitializeComponent();
rowLength = userTransRows.Count;
userTransRows.Reverse();
var dataTable = new DataTable();
dataTable.Columns.Add("Reference");
dataTable.Columns.Add("Amount");
dataTable.Columns.Add("Date");
foreach (var rowData in userTransRows)
{
var transAmount = rowData["amount"];
var transferred_by_crUser = false;
if (rowData["from"] == user["id"])
{
transAmount = "-" + transAmount;
transferred_by_crUser = true;
}
string? reference;
if (rowData["from"] == "none")
reference = "Money Deposited";
else if (rowData["to"] == "none")
reference = "Money Withdrew";
else
{
string? otherUserCond;
// if the transaction is done by current loggedin user to some other user
if (transferred_by_crUser)
{
otherUserCond = rowData["to"];
reference = "Money Tranfered to: ";
}
else
{
otherUserCond = user["id"];
reference = "Money Tranfered by: ";
}
var userTransdata = FileSystemCus.FindOne("users", otherUserCond);
reference += userTransdata["email"] + " - " + userTransdata["cnic"];
}
dataTable.Rows.Add(reference, transAmount, rowData["date"]);
}
transaction_data.DataSource = dataTable;
}
private void Transaction_data_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
var targetColumnIndex = 1;
if (e.ColumnIndex != targetColumnIndex || e.CellStyle == null)
return;
if (Convert.ToInt32(e.Value) < 0)
e.CellStyle.ForeColor = Color.Red;
else
e.CellStyle.ForeColor = Color.Green;
}
private void Back_button_Click(object sender, EventArgs e)
{
Close();
dashboardShow();
}
private void Transactions_Load(object sender, EventArgs e)
{
if (rowLength == 0)
MessageBox.Show("There are no transaction.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}