-
Notifications
You must be signed in to change notification settings - Fork 1
/
Transfer.aspx.cs
74 lines (72 loc) · 2.85 KB
/
Transfer.aspx.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
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Security.Principal;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
namespace MyBank
{
public partial class Transfer : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserId"] == null)
{
Response.Redirect("login.aspx");
}
string status = UserLogic.getCutsomer(Session["UserId"].ToString()).Rows[0]["status"].ToString();
if (status == "freeze")
{
Response.Write("<script>alert('account is freeze, cant transfer amount....!')</script>");
HtmlMeta meta = new HtmlMeta();
meta.HttpEquiv = "Refresh";
meta.Content = "0;url=Dashboard.aspx";
this.Page.Controls.Add(meta);
}
}
protected void btn_Click(object sender, EventArgs e)
{
string UserId = Session["UserId"].ToString();
string toAccountNo = accountNo.Value;
if (toAccountNo==UserId)
{
Response.Write("<script>alert('you cant transfer on your account....!')</script>");
return;
}
if (UserLogic.getCutsomer(toAccountNo).Rows.Count == 0) {
Response.Write("<script>alert('invalid account number....!')</script>");
return;
}
DataRow toAccountRow = UserLogic.getCutsomer(toAccountNo).Rows[0];
int transferAmount = int.Parse(amount.Value);
DataRow user = UserLogic.getCutsomer(UserId).Rows[0];
int fromBalance = int.Parse(user["balance"].ToString());
int minAmount = int.Parse(user["minAmount"].ToString());
int maxAmount = int.Parse(user["maxAmount"].ToString());
if ((fromBalance - transferAmount) < minAmount)
{
Response.Write("<script>alert('insufficient balance....!')</script>");
return;
}
if (transferAmount > maxAmount)
{
Response.Write($"<script>alert('yout maximum transfer limit is {maxAmount} ....!')</script>");
return;
}
int toAmount = int.Parse(toAccountRow["balance"].ToString()) + transferAmount;
int fromAmount = fromBalance - transferAmount;
int x = UserLogic.transferAmount(transferAmount, toAmount, fromAmount, toAccountNo, UserId);
if (x > -1)
{
Response.Write("<script>alert('transfer successfully....!')</script>");
}
else
{
Response.Write("<script>alert('transfer failed....!')</script>");
}
}
}
}