Wednesday, July 25, 2018

how to calculate Finance in asp.net | sradha webcreations

how to calculate Finance in asp.net 


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;
using System.Data.SqlClient;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class finance_calculator : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    double dSowRoomPrice;
    double dBalance;
    double dTotalFinanceAmount;

    protected void TextBoxDownPayment_TextChanged(object sender, EventArgs e)
    {
        double dDownPayment;
        double dDownpaymentAmount;
       // float fBalance;

        dSowRoomPrice = Convert.ToDouble(TextBoxShowRoomPrice.Text);
        dDownPayment = Convert.ToDouble(TextBoxDownPayment.Text);
        dDownpaymentAmount = dSowRoomPrice * 30 / 100;
 TextBoxDownPaymentAmount.Text = Convert.ToString(dDownpaymentAmount);
       dBalance = dSowRoomPrice - dDownpaymentAmount;
       TextBoxBalance.Text = Convert.ToString(dBalance);   
    }

    protected void TextBoxRateOfIntrest_TextChanged(object sender, EventArgs e)
   
{
        double dRateOfIntrest;
        double dTotalRateOfIntrestAmount;
      //  float fTotalFinanceAmount;
    
        dRateOfIntrest = Convert.ToDouble(TextBoxRateOfIntrest.Text);
        dBalance=Convert.ToDouble(TextBoxBalance.Text);
        dTotalRateOfIntrestAmount = dBalance * dRateOfIntrest / 100  TextBoxTotalIntrest.Text = Convert.ToString(dTotalRateOfIntrestAmount);
        dTotalFinanceAmount = dBalance + dTotalRateOfIntrestAmount;
TextBoxTotalFinanceAmount.Text = Convert.ToString(dTotalFinanceAmount);
    }

    protected void TextBoxDuration_TextChanged(object sender, EventArgs e)
    {
        int iDuration;
        double dEMI;

        iDuration = Convert.ToInt32(TextBoxDuration.Text);
TotalFinanceAmount = Convert.ToDouble(TextBoxTotalFinanceAmount.Text);
        dEMI = dTotalFinanceAmount / iDuration;
        TextBoxEMI.Text = Convert.ToString(dEMI);
    }

    protected void ButtonSAVE_Click(object sender, EventArgs e)
    {
        string connectionstring = ConfigurationManager.ConnectionStrings["DbConnection"].ConnectionString;

        string insertsql = "insert into financecalculator(showroomprice,downpayment,downpaymentamount,balance,rateofintrest,intrestamount,totalfinance,duration,emi)values(@showroomprice,@downpayment,@downpaymentamount,@balance,@rateofintrest,@intrestamount,@totalfinance,@duration,@emi)";

        using (SqlConnection myconnection = new SqlConnection(connectionstring))
        {
            myconnection.Open();
       SqlCommand mycommand = new SqlCommand(insertsql,myconnection);
     mycommand.Parameters.AddWithValue("@showroomprice",TextBoxShowRoomPrice.Text);
   mycommand.Parameters.AddWithValue("@downpayment",TextBoxDownPayment.Text);         mycommand.Parameters.AddWithValue("@downpaymentamount",TextBoxDownPaymentAmount.Text);
mycommand.Parameters.AddWithValue("@balance",TextBoxBalance.Text);
mycommand.Parameters.AddWithValue("@rateofintrest",TextBoxRateOfIntrest.Text);
mycommand.Parameters.AddWithValue("@intrestamount",TextBoxTotalIntrest.Text);
mycommand.Parameters.AddWithValue("@totalfinance",TextBoxTotalFinanceAmount.Text);
mycommand.Parameters.AddWithValue("@duration",TextBoxDuration.Text);
            mycommand.Parameters.AddWithValue("@emi",TextBoxEMI.Text);

            mycommand.ExecuteNonQuery();
            myconnection.Close();

        }
        TextBoxShowRoomPrice.Text = string.Empty;
        TextBoxDownPayment.Text = string.Empty;
        TextBoxDownPaymentAmount.Text = string.Empty;
        TextBoxBalance.Text = string.Empty;
        TextBoxRateOfIntrest.Text = string.Empty;
        TextBoxTotalIntrest.Text = string.Empty;
        TextBoxTotalFinanceAmount.Text = string.Empty;
        TextBoxDuration.Text = string.Empty;
        TextBoxEMI.Text = string.Empty;
    }
}


No comments:

Post a Comment