Click here to Skip to main content
15,885,000 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
public void SalePrice()
    {
        double originalPrice, discountPercentage, discountAmount, salePrice;
        con.Open();
        SqlCommand sqlcom = new SqlCommand("USP_SalePriceCalculation", con);
        sqlcom.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter da = new SqlDataAdapter(sqlcom);
        DataTable dt = new DataTable();
        da.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            // Get item's original price.
            originalPrice = double.Parse(dt.Rows[0]["actprice"].ToString());

            // Get discount percentage.
            discountPercentage = double.Parse(dt.Rows[0]["Discount"].ToString());

            // Create decimal representation of %  (move point left two places)
            discountPercentage = discountPercentage / 100;

            // Calculate amount of the discount.
            discountAmount = originalPrice * discountPercentage;

            // Calculate sale price.
            salePrice = originalPrice - discountAmount;

            // Display sale price as Currency ("c")
            lblPrice.Text = salePrice.ToString("c", Cultures.INDIA);
        }
        con.Close();        
    }
    public static class Cultures
    {
        public static readonly CultureInfo INDIA =
            CultureInfo.GetCultureInfo("en-IN");
    }


Now i want to Calcualate SubTotal Based on that SalePrice and Quantity(textbox)
Any one help me that how to calculate SubTotal?
Posted
Comments
deepankarbhatnagar 18-Sep-15 7:17am    
Not understanding your query, what is your subtotal??
Member 11878541 18-Sep-15 8:27am    
SubTotal= Price after discount and quantity(that selected by customer)

Total =sum of all SubTotals
vagelis1 18-Sep-15 10:13am    
And still price * qty doesn't answer you question???

It is simple
C#
SalePrice();
var unitPrice =  long.Parse(lblPrice.Text);
var qty = int.Parse(txbQty.Text);

var subTotal = unitPrice * qty;

By salePrice() you have the discounted price that applies to all products. So subtotal is the sum of all totals.
 
Share this answer
 
v2
Hi,

Why can't you implement the same in SQL Server,try below query to achieve the same in SQL server side.

SQL
select sum(col) as SubTotal
from tablename
Group by Quantity, Price
 
Share this answer
 
Comments
Member 11878541 23-Sep-15 4:15am    
can you please give a complete query to calculate saleprice besed on Actual Price and Discount....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900