public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/json";
string json=string.Empty;
string dktype = (!string.IsNullOrEmpty(context.Request.Form["dktype"]) ? context.Request.Form["dktype"].ToString().Trim() : "0");//贷款方式
string calculatype = (!string.IsNullOrEmpty(context.Request.Form["calculatype"]) ? context.Request.Form["calculatype"].ToString().Trim() : "0");//计算方式
string paymentType = (!string.IsNullOrEmpty(context.Request.Form["paymentType"]) ? context.Request.Form["paymentType"].ToString().Trim() : "0");//还款方式
string unitPrice = (!string.IsNullOrEmpty(context.Request.Form["unitPrice"]) ? context.Request.Form["unitPrice"].ToString().Trim() : "0");//单价
string acreage =(!string.IsNullOrEmpty(context.Request.Form["acreage"])?context.Request.Form["acreage"].ToString().Trim():"0");//面积
string mortgage = (!string.IsNullOrEmpty(context.Request.Form["mortgage"])?context.Request.Form["mortgage"].ToString().Trim():"0");//按揭成数
string loanceiling = (!string.IsNullOrEmpty(context.Request.Form["loanceiling"]) ? context.Request.Form["loanceiling"].ToString().Trim() : "0");//贷款总额
string countYears = (!string.IsNullOrEmpty(context.Request.Form["countYears"]) ? context.Request.Form["countYears"].ToString().Trim() : "0");//按揭年数
string lilv = (!string.IsNullOrEmpty(context.Request.Form["lilv"]) ? context.Request.Form["lilv"].ToString().Trim() : "0");//年利率 //组合型贷款
string syx_loanceiling = (!string.IsNullOrEmpty(context.Request.Form["syx_loanceiling"]) ? context.Request.Form["syx_loanceiling"].ToString().Trim() : "0");//商业贷款
string gjj_loanceiling = (!string.IsNullOrEmpty(context.Request.Form["gjj_loanceiling"]) ? context.Request.Form["gjj_loanceiling"].ToString().Trim() : "0");//公积金贷款
string sy_lilvValues = (!string.IsNullOrEmpty(context.Request.Form["sy_lilvValues"]) ? context.Request.Form["sy_lilvValues"].ToString().Trim() : "0");//商业贷款利率
string gjj_lilvValues = (!string.IsNullOrEmpty(context.Request.Form["gjj_lilvValues"]) ? context.Request.Form["gjj_lilvValues"].ToString().Trim() : "0");//公积金贷款利率
switch (dktype)
{
case "sydk"://商业贷款
case "gjjdk"://公积金贷款
switch (calculatype)
{
case "calcula_one"://根据面积,单价计算
json = returnResult(double.Parse(unitPrice), double.Parse(acreage), double.Parse(mortgage), Utils.ObjToInt(countYears, 1), double.Parse(lilv), paymentType);
break;
case "calcula_two"://根据贷款总额计算
json = returnResult(double.Parse(loanceiling), int.Parse(countYears), double.Parse(lilv), paymentType);
break;
}
break;
case "zhxdk"://组合型贷款
json = returnResult(double.Parse(syx_loanceiling), double.Parse(sy_lilvValues), double.Parse(gjj_loanceiling), double.Parse(gjj_lilvValues), Utils.ObjToInt(countYears,1), paymentType);
break;
}
context.Response.Write(json);
} /// <summary>
/// 商业贷款-根据面积,单价计算
/// </summary>
/// <param name="unitPrice">单价</param>
/// <param name="acreage">面积</param>
/// <param name="mortgage">按揭成数</param>
/// <param name="countYears">按揭年数</param>
/// <param name="lilv">年利率</param>
/// <param name="paymentType">还款方式</param>
/// <returns></returns>
private string returnResult(double unitPrice, double acreage, double mortgage, int countYears, double lilv, string paymentType)
{
StringBuilder json = new StringBuilder();
double newlilv = lilv / 100/12;//月利率
double purchase=0;//房款总额;
double Loan=0;//贷款总额
double monthlypayments=0;//平均月供
double Total=0;//还款总额
double Interest=0;//总利息
double Shoufu=0;//首付
switch (paymentType.Trim())
{
case "debx"://等额本息
purchase = Math.Round(unitPrice * acreage,2);
Loan = Math.Round(purchase * mortgage,2);
monthlypayments =Math.Round((Loan * newlilv * Math.Pow(1 + newlilv, countYears * 12)) / (Math.Pow(1 + newlilv, countYears * 12) - 1),2);
Total = Math.Round(monthlypayments * countYears * 12,2);
Interest = Math.Round(Total - Loan,2);
Shoufu = Math.Round(purchase - Loan,2);
json.Append("{\"purchase\":\"" + purchase.ToString() + "\",\"Loan\":\"" + Loan.ToString() + "\",\"Forthemonth\":\"" + monthlypayments.ToString() + "\",\"Total\":\"" + Total.ToString() + "\",\"Interest\":\"" + Interest.ToString() + "\",\"Shoufu\":\"" + Shoufu.ToString() + "\",\"months\":\"" + countYears * 12 +"(月)"+ "\"}");
break;
case "debj"://等额本金
purchase = Math.Round(unitPrice * acreage,2);
Loan =Math.Round(purchase * mortgage,2);
string monthsPay = string.Empty;
for (int i = 0; i < countYears * 12; i++)
{
monthlypayments =Loan / (countYears * 12) + (Loan - Loan / (countYears * 12) * i) * newlilv;
monthsPay +="第"+ (i + 1) + "个月," + Math.Round(monthlypayments,2) + "(元)\\r\\n";//月均金额
Total =monthlypayments + Total;//还款总额
}
Interest =Math.Round(Total - Loan,2);
Shoufu = Math.Round(purchase - Loan,2);
json.Append("{\"purchase\":\"" + purchase.ToString() + "\",\"Loan\":\"" + Loan.ToString() + "\",\"Forthemonth\":\"" + monthsPay.ToString() + "\",\"Total\":\"" + Math.Round(Total,2) + "\",\"Interest\":\"" + Interest.ToString() + "\",\"Shoufu\":\"" + Shoufu.ToString() + "\",\"months\":\"" + countYears * 12 + "(月)" + "\"}");
break;
}
return json.ToString();
} /// <summary>
/// 商业贷款-根据贷款总额计算
/// </summary>
/// <param name="countYears">贷款总额</param>
/// <param name="countYears">按揭年数</param>
/// <param name="lilv">年利率</param>
/// <param name="paymentType">还款方式</param>
/// <returns></returns>
private string returnResult(double loanceiling, int countYears, double lilv, string paymentType)
{
StringBuilder json = new StringBuilder();
double newlilv = lilv / 100 / 12;//月利率
double Loan = loanceiling;//贷款总额
double monthlypayments = 0;//平均月供
double Total = 0;//还款总额
double Interest = 0;//总利息
switch (paymentType.Trim())
{
case "debx"://等额本息
monthlypayments = Math.Round((Loan * newlilv * Math.Pow(1 + newlilv, countYears * 12)) / (Math.Pow(1 + newlilv, countYears * 12) - 1), 2); Total = Math.Round(monthlypayments * countYears * 12, 2);
Interest = Math.Round(Total - Loan, 2);
json.Append("{\"purchase\":\"略\",\"Loan\":\"" + Loan.ToString() + "\",\"Forthemonth\":\"" + monthlypayments.ToString() + "\",\"Total\":\"" + Total.ToString() + "\",\"Interest\":\"" + Interest.ToString() + "\",\"Shoufu\":\"0\",\"months\":\"" + countYears * 12 + "(月)"+"\"}");
break;
case "debj"://等额本金
string monthsPay = string.Empty;
for (int i = 0; i < countYears * 12; i++)
{
monthlypayments =Loan / (countYears * 12) + (Loan - Loan / (countYears * 12) * i) * newlilv;
monthsPay +="第"+ (i + 1) + "个月," + Math.Round(monthlypayments,2) + "(元)\\r\\n";//月均金额
Total =monthlypayments + Total;//还款总额
}
Interest = Math.Round(Total - Loan, 2);
json.Append("{\"purchase\":\"略\",\"Loan\":\"" + Math.Round(Loan,2) + "\",\"Forthemonth\":\"" + monthsPay.ToString() + "\",\"Total\":\"" + Math.Round(Total, 2) + "\",\"Interest\":\"" + Interest.ToString() + "\",\"Shoufu\":\"0\",\"months\":\"" + countYears * 12 + "(月)" + "\"}");
break;
}
return json.ToString();
} /// <summary>
/// 组合型贷款
/// </summary>
/// <param name="syx_loanceiling">商业贷款额</param>
/// <param name="sy_lilvValues">商业贷款利率(年利率)</param>
/// <param name="gjj_loanceiling">公积金贷款额</param>
/// <param name="gjj_lilvValues">公积金贷款额利率(年利率)</param>
/// <param name="countYears">贷款期限</param>
/// <param name="paymentType">还款方式</param>
/// <returns></returns>
private string returnResult(double syx_loanceiling, double sy_lilvValues, double gjj_loanceiling,double gjj_lilvValues, int countYears,string paymentType)
{
StringBuilder json = new StringBuilder();
double sy_newlilv = sy_lilvValues / 100 / 12;//月利率
double sy_Loan = syx_loanceiling;//贷款总额
double sy_monthlypayments = 0;//平均月供
double sy_Total = 0;//商业还款总额
double sy_Interest = 0;//商业贷款利息 double gjj_newlilv = gjj_lilvValues / 100 / 12;//月利率
double gjj_Loan = gjj_loanceiling;//贷款总额
double gjj_monthlypayments = 0;//平均月供
double gjj_Total = 0;//公积金还款总额
double gjj_Interest = 0;//公积金贷款利息 switch (paymentType.Trim())
{
case "debx"://等额本息
//商业贷款
sy_monthlypayments = Math.Round((sy_Loan * sy_newlilv * Math.Pow(1 + sy_newlilv, countYears * 12)) / (Math.Pow(1 + sy_newlilv, countYears * 12) - 1), 2);
sy_Total = Math.Round(sy_monthlypayments * countYears * 12, 2);
sy_Interest = Math.Round(sy_Total - sy_Loan, 2); //公积金贷款
gjj_monthlypayments = Math.Round((gjj_Loan * gjj_newlilv * Math.Pow(1 + gjj_newlilv, countYears * 12)) / (Math.Pow(1 + gjj_newlilv, countYears * 12) - 1), 2);
gjj_Total = Math.Round(gjj_monthlypayments * countYears * 12, 2);
gjj_Interest = Math.Round(gjj_Total - gjj_Loan, 2); double monthlypayments = sy_monthlypayments + gjj_monthlypayments;
double Total = sy_Total + gjj_Total;
double Interest = sy_Interest + gjj_Interest;
double Loan=Math.Round( sy_Loan + gjj_Loan,2);
json.Append("{\"purchase\":\"略\",\"Loan\":\"" + Loan.ToString() + "\",\"Forthemonth\":\"" + monthlypayments.ToString() + "\",\"Total\":\"" + Total.ToString() + "\",\"Interest\":\"" + Interest.ToString() + "\",\"Shoufu\":\"0\",\"months\":\"" + countYears * 12 + "(月)" + "\"}");
break;
case "debj"://等额本金
string monthsPay = string.Empty;
double newmonthlypayments;;
double newTotal=0;
double newInterest;
double newLoan;
for (int i = 0; i < countYears * 12; i++)
{
sy_monthlypayments = sy_Loan / (countYears * 12) + (sy_Loan - sy_Loan / (countYears * 12) * i) * sy_newlilv;
gjj_monthlypayments =gjj_Loan / (countYears * 12) + (gjj_Loan - gjj_Loan / (countYears * 12) * i) * gjj_newlilv; newmonthlypayments = sy_monthlypayments + gjj_monthlypayments; monthsPay +="第"+ (i + 1) + "个月," + Math.Round(newmonthlypayments) + "(元)\\r\\n";//月均金额 sy_Total = sy_monthlypayments + sy_Total; gjj_Total = gjj_monthlypayments + gjj_Total; newTotal = gjj_Total + sy_Total;//还款总额
}
sy_Interest =sy_Total - sy_Loan; gjj_Interest =gjj_Total - gjj_Loan; newInterest = gjj_Interest + sy_Interest; newLoan = sy_Loan + gjj_Loan; json.Append("{\"purchase\":\"略\",\"Loan\":\"" + Math.Round(newLoan, 2) + "\",\"Forthemonth\":\"" + monthsPay.ToString() + "\",\"Total\":\"" + Math.Round(newTotal,2) + "\",\"Interest\":\"" + Math.Round(newInterest, 2) + "\",\"Shoufu\":\"0\",\"months\":\"" + countYears * 12 + "(月)" + "\"}");
break;
}
return json.ToString();
}

c#实现房贷计算的方法源码的更多相关文章

  1. invalidate和requestLayout方法源码分析

    invalidate方法源码分析 在之前分析View的绘制流程中,最后都有调用一个叫invalidate的方法,这个方法是啥玩意?我们来看一下View类中invalidate系列方法的源码(ViewG ...

  2. v8--sort 方法 源码 (1) 插入排序法

    v8--sort方法源码中对于长度较短的数组使用的是插入排序法. 部分源码: function InsertionSort(a, from, to) { for (var i = from + 1; ...

  3. 从原子类和Unsafe来理解Java内存模型,AtomicInteger的incrementAndGet方法源码介绍,valueOffset偏移量的理解

    众所周知,i++分为三步: 1. 读取i的值 2. 计算i+1 3. 将计算出i+1赋给i 可以使用锁来保持操作的原子性和变量可见性,用volatile保持值的可见性和操作顺序性: 从一个小例子引发的 ...

  4. HashMap实现原理一步一步分析(1-put方法源码整体过程)

    各位同学大家好, 今天给大家分享一下HashMap内部的实现原理, 这一块也是在面试过程当中基础部分被问得比较多的一部分. 想要搞清楚HashMap内部的实现原理,我们需要先对一些基本的概念有一些了解 ...

  5. js-reduce方法源码

    // 数组中的reduce方法源码复写 //先说明一下reduce原理:总的一句,reduce方法主要是把数组遍历, //然后把数组的每个元素传入回调函数中,回调函数怎么处理,就会的到什么样的效果 A ...

  6. Java split方法源码分析

    Java split方法源码分析 public String[] split(CharSequence input [, int limit]) { int index = 0; // 指针 bool ...

  7. erlang下lists模块sort(排序)方法源码解析(二)

    上接erlang下lists模块sort(排序)方法源码解析(一),到目前为止,list列表已经被分割成N个列表,而且每个列表的元素是有序的(从大到小) 下面我们重点来看看mergel和rmergel ...

  8. erlang下lists模块sort(排序)方法源码解析(一)

    排序算法一直是各种语言最简单也是最复杂的算法,例如十大经典排序算法(动图演示)里面讲的那样 第一次看lists的sort方法的时候,蒙了,几百行的代码,我心想要这么复杂么(因为C语言的冒泡排序我记得不 ...

  9. getOrCreateEnvironment()方法源码探究

    该方法目的是创建一个环境对象,并且根据环境类型,自动判断是创建web环境对象,还是标准非web环境对象. 首先该方法源于prepareEnvironment准备环境: 然后进入该方法源码: 可以发现: ...

随机推荐

  1. HTML5 ---localStorage

    HTML5中提供了localStorage对象可以将数据长期保存在客户端,直到人为清除. localStorage提供了几个方法: 1.存储:localStorage.setItem(key,valu ...

  2. HFSS设计导入AD中

    具体过程有些繁琐,录制了一个视频放在百度网盘了.亲测有效. 网盘地址:http://pan.baidu.com/s/1gfIBhC3 密码:ayoa

  3. C#对于文件操作

    //C#追加文件 StreamWriter sw = File.AppendText(Server.MapPath(".")+"\\myText.txt"); ...

  4. [刘阳Java]_什么是MyBatis_第1讲

    1.什么MyBatis,我们先通过百度百科先进行一个简单的了解 MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation ...

  5. protobuf初体验

    概念介绍 Protocol buffers 是google公司的与语言无关.与平台无关的.可扩张的为序列化话结构数据,就像xml一样,办事更加的小巧.快速.简单.Protocol buffers 目前 ...

  6. KinectV2+Ubuntu 14.04+Ros 安装教程

    前言 个人理解错误的地方还请不吝赐教,转载请标明出处,内容如有改动更新,请看原博:http://www.cnblogs.com/hitcm/ 如有任何问题,feel free to contact m ...

  7. Android 设置代理(验证用户名和密码)

    这几天在研究在Android中,解析网页,但是公司内容,链接外网需要代理,并需要验证用户名和密码,十分头疼,网上查了下,没有头绪,最后总算在一个外国博客中看到类似的,记录下 URL url = new ...

  8. C#图片压缩处理算法

    原文链接:http://blog.csdn.net/szstephenzhou/article/details/38900345

  9. c++ 覆盖、重载与隐藏

    成员函数被重载的特征:(1)相同的范围(在同一个类中):(2)函数名字相同:(3)参数不同:(4)virtual 关键字可有可无.覆盖是指派生类函数覆盖基类函数,特征是:(1)不同的范围(分别位于派生 ...

  10. Xcode7以后 使用空模板

    Xcode7以后的版本没有空模板可以选择 习惯使用空模版的 可以自己拷贝空模版文件夹 放到模版的位置 重启就可以使用了 1:首先 需要有一个空模版 没有空模板的可以在下面路径下下载一个 并解压 htt ...