-
Notifications
You must be signed in to change notification settings - Fork 7
/
Account.cs
232 lines (203 loc) · 9.22 KB
/
Account.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ApteanEdgeBank
{
public abstract class Account
{
public int accountID;
public string accountType;
public DateTime dateOpened;
public DateTime dateClosed;
public double Balance;
public abstract int Create(string accType,DateTime open,double balance);
public abstract void Deposit(double amount,int accId);
public void Withdraw(double amount,int accID)
{
UserDAO dao=new UserDAO();
DataTable dt=new DataTable();
string connectionstring = "Data Source=WS003LT1553PRD;Initial Catalog=ApteanEdgeBank;User=sa;Password=abc-123";
BankGeneralAccount bg = new BankGeneralAccount();
dt=dao.GetData("Select AccountBalance from Account where AccountID="+accID,connectionstring);
Balance=Convert.ToDouble(dt.Rows[0]["AccountBalance"]);
Balance = Balance - amount;
if (Balance > 0)
{
string myQuery = "Update Account set AccountBalance=" + Balance + " where AccountID="+accID;
//UserDAO dao = new UserDAO();
bg.BgaWithdraw(amount);
dao.UpdateData(myQuery, connectionstring);
AccountActivityLedger Ledger = new AccountActivityLedger();
Ledger.AddAccountActivity(accID, "Withdraw",amount, DateTime.Now);
MessageBox.Show("Amount withdraw Successful!");
}
//string myQuery="up
else
MessageBox.Show("Your balance is too low!");
}
public void Close()
{
try
{
Balance = 0;
dateClosed = DateTime.Now;
Console.WriteLine("Account closed on {0}", dateClosed.ToShortDateString());
}
catch (InvalidOperationException e)
{
Console.WriteLine("Balance is greater than 0: {0}", e);
}
}
public bool CheckAccountExistence(int accID)
{
UserDAO dao = new UserDAO();
DataTable accTable = new DataTable();
string myQuery = "select * from Account where AccountID=" + accID;
string connectionstring="Data Source=WS003LT1553PRD;Initial Catalog=ApteanEdgeBank;User=sa;Password=abc-123";
accTable = dao.GetData(myQuery, connectionstring);
if (accTable.Rows.Count > 0)
{
return true;
}
return false;
}
}
public class ChequingAccount : Account
{
public override int Create(string accType,DateTime open,double balance)
{
/* accountID=ID;
dateOpened=open;
Balance=balance;
Console.WriteLine("Chequing Acoount:");
Console.WriteLine("Account ID:{0}\nDate Opened:{1}\nBalance:{2}", accountID, dateOpened, Balance);*/
string myQuery = "insert into Account values("+accType+","+balance+","+"'"+open+"'"+","+"null"+")";
string connectionstring = "Data Source=WS003LT1553PRD;Initial Catalog=ApteanEdgeBank;User=sa;Password=abc-123";
BankGeneralAccount bg = new BankGeneralAccount();
UserDAO dao = new UserDAO();
dao.InsertData(myQuery, connectionstring);
bg.BgaDeposit(balance);
DataTable dataTable = dao.GetData("use ApteanEdgeBank select max(AccountID) as max from Account", UserDAO.connectionString);
int AccountID = Convert.ToInt32(dataTable.Rows[0]["max"]);
return AccountID;
//dao.InsertData("use ApteanEdgeBank insert into CustomerAccount values(" + CustomerID + "," + AccountID + ")", UserDAO.connectionString);
}
public override void Deposit(double amount,int accId)
{
UserDAO dao=new UserDAO();
DataTable dt=new DataTable();
string connectionstring = "Data Source=WS003LT1553PRD;Initial Catalog=ApteanEdgeBank;User=sa;Password=abc-123";
BankGeneralAccount bg = new BankGeneralAccount();
dt=dao.GetData("Select AccountBalance from Account where AccountID="+accId,connectionstring);
Balance=Convert.ToDouble(dt.Rows[0]["AccountBalance"]);
Balance=Balance+amount;
string myQuery = "Update Account set AccountBalance=" + Balance + " where AccountID="+accId;
//UserDAO dao = new UserDAO();
dao.UpdateData(myQuery, connectionstring);
bg.BgaDeposit(amount);
AccountActivityLedger Ledger = new AccountActivityLedger();
Ledger.AddAccountActivity(accId, "Deposit", amount, DateTime.Now);
}
// To make sure that only one account of each type exists
public bool DoesChequingAccountExist(int customerID)
{
UserDAO dao = new UserDAO();
DataTable customerAccounts = new DataTable();
int chequingAccount = 0;
string query = "Select * from Account where AccountID in (select AccountID from CustomerAccount where CustomerID=" + customerID + ")";
string connectionstring = "Data Source=WS003LT1553PRD;Initial Catalog=ApteanEdgeBank;User=sa;Password=abc-123";
customerAccounts = dao.GetData(query, connectionstring);
foreach (DataRow row in customerAccounts.Rows)
{
if (Convert.ToString(row["AccountType"]) == "CA")
{
chequingAccount++;
}
}
if (chequingAccount == 0)//if there is no chequing account for customer
{
return false;//there is no CA for this customer
}
return true;//this customer already has a chequing account
}
}
public class TaxFreeSavingsAccount:Account
{
public double Limit;
public TaxFreeSavingsAccount()
{
Limit=5000;
}
public override int Create(string accType,DateTime open,double balance)
{
if (balance <= Limit)
{
dateOpened = open;
Balance = balance;
string myQuery = "insert into Account values(" + accType + "," + balance + "," + "'" + open + "'" + "," + "null" + ")";
string connectionstring = "Data Source=WS003LT1553PRD;Initial Catalog=ApteanEdgeBank;User=sa;Password=abc-123";
BankGeneralAccount bg = new BankGeneralAccount();
UserDAO dao = new UserDAO();
dao.InsertData(myQuery, connectionstring);
bg.BgaDeposit(balance);
DataTable dataTable = dao.GetData("use ApteanEdgeBank select max(AccountID) as max from Account", UserDAO.connectionString);
int AccountID = Convert.ToInt32(dataTable.Rows[0]["max"]);
return AccountID;
}
else
{
MessageBox.Show("Balance is greater than limit!");
return 0;
}
}
public override void Deposit(double amount,int accID)
{
UserDAO dao = new UserDAO();
DataTable dt = new DataTable();
string connectionstring = "Data Source=WS003LT1553PRD;Initial Catalog=ApteanEdgeBank;User=sa;Password=abc-123";
BankGeneralAccount bg = new BankGeneralAccount();
dt = dao.GetData("Select AccountBalance from Account where AccountID=" + accID, connectionstring);
Balance = Convert.ToDouble(dt.Rows[0]["AccountBalance"]);
if ((Balance + amount) <= 5000)
{
Balance = Balance + amount;
string myQuery = "Update Account set AccountBalance=" + Balance + " where AccountID="+accID;
//UserDAO dao = new UserDAO();
dao.UpdateData(myQuery, connectionstring);
bg.BgaDeposit(amount);
AccountActivityLedger Ledger = new AccountActivityLedger();
Ledger.AddAccountActivity(accID, "Deposit", amount, DateTime.Now);
MessageBox.Show("Amount deposited successfully!");
}
else
{
MessageBox.Show("Balance greater than limit!");
}
}
public bool DoesTFSAccountExist(int customerID)
{
UserDAO dao = new UserDAO();
DataTable customerAccounts = new DataTable();
int TFSAccount = 0;
string query = "Select * from Account where AccountID in (select AccountID from CustomerAccount where CustomerID=" + customerID + ")";
string connectionstring = "Data Source=WS003LT1553PRD;Initial Catalog=ApteanEdgeBank;User=sa;Password=abc-123";
customerAccounts = dao.GetData(query, connectionstring);
foreach (DataRow row in customerAccounts.Rows)
{
if (Convert.ToString(row["AccountType"]) == "TFS")
{
TFSAccount++;
}
}
if (TFSAccount == 0)//if there is no TFS account for customer
{
return false;//there is no TFS for this customer
}
return true;//this customer already has a TFS account
}
}
}