html
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CreateForm.aspx.cs" Inherits="Loan" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>DIST Banking</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="CSS/styles.css" rel="stylesheet" type="text/css" media="screen" />
<style type="text/css">
.auto-style1 {
height: 37px;
}
.auto-style2 {
height: 19px;
}
.auto-style3 {
height: 28px;
}
.auto-style4 {
height: 23px;
}
</style>
</head>
<body >
<div id="wrap">
<div id="header">
<div id="logo">
<div class="wid_center">
<a href="#"> <h1 style="font-family: 'Exo', sans-serif; color: #fff; font-weight: 100; padding-top:8px; font-size:20px;">DIST<span style="color: #5379fa !important;"> Banking</span></h1></a>
<a href="#"><small>A refreshing change in banking</small></a> <a href="#"> <small>Log Out</small></a>
</div>
</div>
<div id="menu">
<ul>
<li><a href="HomePage.aspx">Home</a></li>
<li><a href="#">Account </a></li>
<li><a href="#"> Fund Transfer</a></li>
<li><a href="#" class="select"> Cards</a></li>
<li><a href="#"> Loans</a></li>
<li><a href="#"> About us</a></li>
</ul>
</div>
</div>
<div id="intro">
<h2>Loan</h2>
<p>All Loans available for you right </p>
</div>
<h1 style="text-align: center">Create Form</h1>
</div >
<form id="form2" runat="server">
<table class="table" align="center">
<tr>
<td>Customer NRIC:</td>
<td id="LblCustId0">
<asp:Label ID="LblCustId" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>Customer Name:</td>
<td>
<asp:Label ID="LblCustname" runat="server"></asp:Label>
</td>
</tr>
<tr><td class="auto-style4">
Loan Type
</td><td class="auto-style4">
<asp:DropDownList ID="DDlLoanType" runat="server" AutoPostBack="True">
</asp:DropDownList>
</td></tr>
<tr>
<td>Principal:</td>
<td>
<asp:TextBox ID="TbPrincipal" runat="server"></asp:TextBox>
<asp:Label ID="LblErr" runat="server"></asp:Label>
<asp:Button ID="btnCalculate" runat="server" OnClick="btnCalculate_Click" Text="Calculate" />
</td>
</tr>
<tr>
<td>Term (years):</td>
<td>
<asp:DropDownList ID="DdlTerm" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DdlTerm_SelectedIndexChanged1">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="auto-style2">Interest Rate:</td>
<td class="auto-style2">
<asp:Label ID="LblIntRte" runat="server"></asp:Label>
</td>
</tr>
<tr><td>
StarLoanate:
</td>
<td>
<asp:Label ID="LblStrLoanate" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>Maturity Date:</td>
<td>
<asp:Label ID="LblMaturedDte" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>Interest</td>
<td>
<asp:Label ID="LblInterest" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style1">Total Amount:</td>
<td class="auto-style1">
<asp:Label ID="LblMaturedAmt" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
Monthly Payment</td>
<td>
<asp:Label ID="LblMthlyP" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style3"></td>
<td class="auto-style3">
<asp:Button ID="BtnConfirm" runat="server" OnClick="BtnConfirm_Click" Text="Confirm" />
<asp:Button ID="BtnBack" runat="server" OnClick="BtnBack_Click" OnClientClick="window.location.href='GetValue.aspx'; return false;" Text="Back" />
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
<asp:Label ID="lbl_msg" runat="server"></asp:Label>
</td>
</tr>
</table>
</form>
<div id="wrap">
<div class="razd_bor"></div>
<div class="prew_box prew_bg1">
</div>
</div >
<br /> <br /> <br />
<br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br />
<br /> <br /> <br /> <br />
<div class="clear"></div>
<div id="footer">
<div class="wid_center" style="padding-bottom:2px;">
<div class="foot_column4">
<div class="foot_col1">
<h4>Services</h4>
</div>
<div class="foot_col2">
<h4>Contact Information</h4>
</div>
<div class="foot_col3">
<h4>Tools For You</h4>
</div>
<div class="foot_col4">
<h4>Follow Us</h4>
</div>
<div style="clear: both"></div>
</div>
<div class="foot_column4 foot_bg">
<div class="foot_col1">
<ul class="ls">
<li><a href="#">Service Number 1</a></li>
<li><a href="#">Service Number 2</a></li>
<li><a href="#">Service Number 3</a></li>
<li><a href="#">Service Number 4</a></li>
<li><a href="#">Service Number 5</a></li>
<li><a href="#">Service Number 6</a></li>
<li><a href="#">Service Number 7</a></li>
</ul>
</div>
<div class="foot_col2">
<p>Dist Banking</p>
<p>180 Ang Mo Kio Avenue 8
</p>
<p>Singapore 569830</p>
<p>Tel:
6451 5115</p>
<p>E-mail: DistBanking@yahoo.com</p>
</div>
<div class="foot_col3">
<p><a href="#">Foreign Rate Calculator</a><br />
</p>
<p><a href="#">Loan Calculator</a><br />
</a></p>
<p><a href="#">Credit Card Expense Planner</a><br />
</a></p>
</div>
<div class="foot_col4">
<div class="link1"><a href="#">Subscribe to Blog</a></div>
<div class="link2"><a href="#">Be a fan on Facebook</a></div>
<div class="link3"><a href="#">RSS Feed</a></div>
<div class="link4"><a href="#">Follow us on Twitter</a></div>
</div>
<div style="clear: both"></div>
</div>
</div>
<div id="footer_bot">
<p>Copyright 2016. <!-- Do not remove -->Designed by Us</a>, coded by Us</p>
<p><a href="#">Privacy Policy</a> | <a href="#">Terms of Use</a> | <a href="http://validator.w3.org/check/referer" title="This page validates as XHTML 1.0 Transitional"><abbr title="eXtensible HyperText Markup Language">XHTML</abbr></a> | <a href="http://jigsaw.w3.org/css-validator/check/referer" title="This page validates as CSS"><abbr title="Cascading Style Sheets">CSS</abbr></a></p>
</div>
</div>
</div>
</body>
</html>
.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Text;
public partial class Loan : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string custId = string.Empty;
if (Page.IsPostBack == false)
{
// step 1: Assign session variables to the respective label for customer NRIC and Name
if (Session["SScustId"] != null)
{
LblCustId.Text = Session["SScustId"].ToString();
LblCustname.Text = Session["SScustName"].ToString();
}
// step 2: Instantiate the interestRte class to a new instance named as fmLoanRte
// Instantiate the list named LoanRteList to hold list of Loan term and rate
// Call the getCurrentLoanRte() from fmLoanRte object and assign to the List LoanRteList
interestRte fmLoanRte = new interestRte();
List<interestRte> LoanRteList = new List<interestRte>();
LoanRteList = fmLoanRte.getCurrentLoanRte();
// Step 3: propogate LoanTerm as dropdown list text , propogate intRte as dropdown list value
DdlTerm.Items.Clear();
DdlTerm.Items.Insert(0, new ListItem("--Select--", "0"));
//AppendDataBoundItems property allows you to add items to the ListControl object before data binding occurs.
DdlTerm.AppendDataBoundItems = true;
DdlTerm.DataTextField = "LoanTerm";
DdlTerm.DataValueField = "intRte";
DdlTerm.DataSource = LoanRteList;
DdlTerm.DataBind();
LoanType fmLoanType = new LoanType();
List<LoanType> LoanTypeList = new List<LoanType>();
LoanTypeList = fmLoanType.getCurrentType();
DDlLoanType.Items.Clear();
DDlLoanType.Items.Insert(0, new ListItem("--Select--", "0"));
//AppendDataBoundItems property allows you to add items to the ListControl object before data binding occurs.
DDlLoanType.AppendDataBoundItems = true;
DDlLoanType.DataTextField = "Type";
DDlLoanType.DataValueField = "Id";
DDlLoanType.DataSource = LoanTypeList;
DDlLoanType.DataBind();
String defaultvalue;
string value;
if (Request.QueryString["LoanType"] != null)
{
value = Request.QueryString["id"].ToString();
DDlLoanType.SelectedValue = value;
}
if (Request.QueryString["term"] != null & Request.QueryString["rate"]!=null)
{
defaultvalue = Request.QueryString["rate"].ToString();
DdlTerm.SelectedValue = defaultvalue;
}
}
}
public double caluculateMonthP(double fmMaturedAmt, int fmTerm)
{
int n = 12;
double MP = ((fmMaturedAmt / fmTerm) / n);
MP = Math.Round(MP, 2);
return MP;
}
public double calculateMaturity(double fmPrincipal, int fmTerm, float fmIntRte)
{
// A = P x (1 + r/n)nt
// r is annual interest rate (1.5% per annual is 0.015
// n - number of time interest compounded. Monthly compounding, n will be 12
// half yearly compounding will be 2, quarter compounding, n will be 4
// This practical assume quarter compounding
// t - number of year
int n = 12;
float r = fmIntRte / 100;
int t = fmTerm;
int nt = n * t / 12;
double fmMaturity = fmPrincipal * Math.Pow((1 + (r / n)), nt);
fmMaturity = Math.Round(fmMaturity, 2);
return fmMaturity;
}
protected void BtnConfirm_Click(object sender, EventArgs e)
{
String con = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
SqlConnection myConn = new SqlConnection(con);
string str = "insert into LoanMaster(apply, custId, principal,LoanTerm,LoanEffectFrom,LoanMaturity,LoanInterest,LoanMaturedAmt,LoanRate, Loanloantype, Loanmonthlyp) ";
str += " values(@apply, @custId, @principal,@LoanTerm,@LoanEffectFrom,@LoanMaturity,@LoanInterest,@LoanMaturedAmt,@LoanRate,@Loanloantype,@Loanmonthlyp)";
// SqlCommand insert = new SqlCommand("insert into LoanMaster(LoanAccount, custId, principal,LoanTerm,LoanEffectFrom,LoanMaturity,LoanInterest,LoanMaturedAmt,LoanRate,LoanRenewMode) values(@LoanAccount, @custId, @ principal,@LoanTerm)", myConn);
SqlCommand insert = new SqlCommand(str, myConn);
insert.Parameters.AddWithValue("@custId", LblCustId.Text);
insert.Parameters.AddWithValue("@principal", double.Parse(TbPrincipal.Text));
insert.Parameters.AddWithValue("@LoanTerm", int.Parse(DdlTerm.SelectedItem.Text));
insert.Parameters.AddWithValue("@LoanEffectFrom", DateTime.Parse(LblStrLoanate.Text));
insert.Parameters.AddWithValue("@LoanMaturity", DateTime.Parse(LblMaturedDte.Text));
insert.Parameters.AddWithValue("@LoanMaturedAmt", double.Parse(LblMaturedAmt.Text));
insert.Parameters.AddWithValue("@LoanRate", double.Parse(LblIntRte.Text));
insert.Parameters.AddWithValue("@LoanInterest", double.Parse(LblInterest.Text));
insert.Parameters.AddWithValue("@Loanloantype", DDlLoanType.SelectedItem.Text);
insert.Parameters.AddWithValue("@Loanmonthlyp", double.Parse(LblMthlyP.Text));
try
{
myConn.Open();
int insertcount = insert.ExecuteNonQuery();
Response.Write("<script>alert('Successfully applied');</script>");
Response.Redirect("HomeLoan.aspx");
}
catch (Exception ex)
{
double dummy;
if (double.TryParse(TbPrincipal.Text, out dummy)) { }
else
{
Response.Write("<script>alert('Enter a correct value for principal');</script>");
}
myConn.Close();
}
}
protected void BtnBack_Click(object sender, EventArgs e)
{
}
protected void DdlTerm_SelectedIndexChanged1(object sender, EventArgs e)
{
double fmPrincipal;
DateTime fmLoanMatureDte;
DateTime fmLoanstarLoante;
double fmInterest, fmMaturedAmt, fmMonthlyP;
int fmTerm;
float fmIntRte;
int itemidx = DdlTerm.SelectedIndex;
if (DdlTerm.SelectedIndex > 0)
{
try
{
// Step 1: Get the Principal amount and
// selected values from the Terms (drop down list)
fmPrincipal = Convert.ToDouble(TbPrincipal.Text);
fmIntRte = Convert.ToSingle(DdlTerm.SelectedValue);
fmTerm = Convert.ToInt32(DdlTerm.SelectedItem.Text);
// Step 2: Call the method calculateMaturity to calculate the
// amount after deposit matured
fmMaturedAmt = calculateMaturity(fmPrincipal, fmTerm, fmIntRte);
fmMonthlyP = caluculateMonthP(fmMaturedAmt, fmTerm);
fmInterest = Math.Round((fmMaturedAmt - fmPrincipal), 1);
fmLoanMatureDte = DateTime.Now.AddYears(fmTerm);
fmLoanstarLoante = DateTime.Now;
LblIntRte.Text = DdlTerm.SelectedValue;
LblMaturedDte.Text = fmLoanMatureDte.ToString();
LblInterest.Text = fmInterest.ToString();
LblMaturedAmt.Text = fmMaturedAmt.ToString();
LblStrLoanate.Text = fmLoanstarLoante.ToString();
LblMthlyP.Text = fmMonthlyP.ToString();
}
catch (FormatException)
{
LblErr.Text = "Please input an numeric dollar amount!";
}
}
else
{
//LblErr2.Text = "Select a valid term!";
}
}
protected void DdlRenew_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void btnCalculate_Click(object sender, EventArgs e)
{
double fmPrincipal;
DateTime fmLoanMatureDte;
DateTime fmLoanstarLoante;
double fmInterest, fmMaturedAmt, fmMonthlyP;
int fmTerm;
float fmIntRte;
int itemidx = DdlTerm.SelectedIndex;
if (DdlTerm.SelectedIndex > 0)
{
try
{
// Step 1: Get the Principal amount and
// selected values from the Terms (drop down list)
fmPrincipal = Convert.ToDouble(TbPrincipal.Text);
fmIntRte = Convert.ToSingle(DdlTerm.SelectedValue);
fmTerm = Convert.ToInt32(DdlTerm.SelectedItem.Text);
// Step 2: Call the method calculateMaturity to calculate the
// amount after deposit matured
fmMaturedAmt = calculateMaturity(fmPrincipal, fmTerm, fmIntRte);
fmMonthlyP = caluculateMonthP(fmMaturedAmt, fmTerm);
fmInterest = Math.Round((fmMaturedAmt - fmPrincipal), 1);
fmLoanMatureDte = DateTime.Now.AddYears(fmTerm);
fmLoanstarLoante = DateTime.Now;
LblIntRte.Text = DdlTerm.SelectedValue;
LblMaturedDte.Text = fmLoanMatureDte.ToString();
LblInterest.Text = fmInterest.ToString();
LblMaturedAmt.Text = fmMaturedAmt.ToString();
LblStrLoanate.Text = fmLoanstarLoante.ToString();
LblMthlyP.Text = fmMonthlyP.ToString();
}
catch (FormatException)
{
LblErr.Text = "Please input an numeric dollar amount!";
}
}
else
{
//LblErr2.Text = "Select a valid term!";
}
}
}