%@ Page Language="C#" %>
<%
string reply="";
// don't know how to test if Request.QueryString["name"] is null in ASP.Net...
/* ---- no query parameters were provided, redirect client to "loan.html"
if(String.Compare(Request.QueryString["name"], "")!=0)
{
// don't know how to return headers and body in ASP.Net...
reply += "HTTP/1.1 302 Found\r\nContent-type:text/html\r\n"
+ "Location: loan.html\r\n\r\n"
+ ""
+ "
Redirect"
+ "Click HERE for redirect.";
}
else ---- if we have query parameters, we process a GET/POST form */
{
string szName="";
string[] Months= new string[] {"January","February","March","April","May","June",
"July", "August","September","October","November","December"};
double amount, rate, term, payment, interest, principle, cost;
int month=0, year=1, lastpayment=1;
// the form field "names" we want to find values for
string Name="-", Amount="0", Rate="0", Term="0";
DateTime start=DateTime.Now;
// get the form field values (note the ending '=' name delimiter)
Name=Request.QueryString["name"];
Amount=Request.QueryString["amount"];
Rate=Request.QueryString["rate"];
Term=Request.QueryString["term"];
// all litteral strings provided by a client must be escaped this way
// if you inject them into an HTML page
szName = HttpUtility.HtmlEncode(Name);
// filter input data to avoid all the useless/nasty cases
amount = Double.Parse(Amount); if(amount<1) amount=1;
rate = Double.Parse(Rate); if(rate> 19) rate =19; else
if(rate >1) rate /=100; else
if(rate <1) rate =1/100;
term = Double.Parse(Term); if(term<0.1) term =1/12;
// don't do this in production...
//else if(term>100) term =30;
// calculate the monthly payment amount
payment = amount*rate/12*Math.Pow(1+rate/12, term*12)
/ (Math.Pow(1+rate/12, term*12)-1);
cost = (term*12*payment)-amount;
// build the top of our HTML page
reply += ""
+ "Loan Calculator"
+ ""
+ "
Dear ";
if(szName!="" && szName!="-")
reply += szName;
else
reply += "client";
reply += ", your loan goes as follows: