Dawood Abbas

Dawood Abbas

  • NA
  • 264
  • 98k

Amount Calculation logic

Feb 16 2015 1:28 AM

Package Name:

ddlPackName

No. of Extra Connection:

txtNoConn

Charges per Connection(If any):

txtChargeConn

Installation Charges:

txtInstlChrge

Discount (if any):

txtDisc

Amount to Pay:

txtAmntToPay

Paying Amount:

txtPayAmnt

Balance:

txtBlnc



How to get final result1 (txtAmntToPay.text)? and final result2 (txtBlnc)


1).if I select 'ddlPackName' then its price display in 'txtAmntToPay.text'
2).if I enter 'txtNoConn' and 'txtChargeConn' then multiple this both and add with 'ddlpackname' then display in 'txtamnttoPay'

if I not select 'ddlpackname' then display multiplied values.

3).like this all textboxes values add with 'txtPayAmnt' and subtract 'txtDisc'

I written like below code but when i enter value second time in other textboxes assing/subtracting again

public void regCustCalculation()
{
double amountToPay = double.Parse(txtAmntToPay.Text);
double noOfConn = double.Parse(txtNoOfConn.Text);
double chargePerConn = double.Parse(txtChargePerConn.Text);
double installCharge = double.Parse(txtInstallCharge.Text);
double discount = double.Parse(txtDiscount.Text);
double packPrice = double.Parse(txtAmntToPay.Text);
if (ddlPackName.SelectedIndex != 0)
{
txtAmntToPay.Text = "0";
packPrice = amountToPay;
packPrice = amountToPay + (noOfConn * chargePerConn);
packPrice = packPrice + installCharge;
packPrice = packPrice - discount;
txtAmntToPay.Text = packPrice.ToString();
}
if (ddlPackName.SelectedIndex==0)
{
txtAmntToPay.Text = "0";
packPrice = noOfConn * chargePerConn;
packPrice = packPrice + installCharge;
packPrice = packPrice - discount;
txtAmntToPay.Text = packPrice.ToString();
}
}


protected void txtNoOfConn_TextChanged(object sender, EventArgs e)
{
//regCustCalculation();
}
protected void txtChargePerConn_TextChanged(object sender, EventArgs e)
{
regCustCalculation();
}
protected void txtInstallCharge_TextChanged(object sender, EventArgs e)
{
regCustCalculation();
}
protected void txtDiscount_TextChanged(object sender, EventArgs e)
{
regCustCalculation();
}
public void ddlPackPriceBind()
{
try
{
//open the db connection if it is closed...
if (connection.State == ConnectionState.Closed)
connection.Open();
string packNameEdit = ddlPackName.SelectedItem.ToString();
command = new SqlCommand();
command.CommandText = "sp_Get_PackPrice";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@packageName", packNameEdit);
da = new SqlDataAdapter(command);
command.Connection = connection;
ds = new DataSet();
da.Fill(ds);
txtAmntToPay.Text = "";
txtAmntToPay.Text = ds.Tables[0].Rows[0]["PackagePrice"].ToString();
}


protected void ddlPackName_SelectedIndexChanged(object sender, EventArgs e)
{
ddlPackPriceBind();
regCustCalculation();
}
 

Answers (1)