Click here to Skip to main content
15,914,416 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I have a really stupid problem, which I dont know how to solve. Been working for a while with desktop application, but I havent had situation like this (this program needs some basic math operations).
So here is the problem.
I have a dropdown list and when user select the manufacturer and its product, the price shows in two textboxes (first price as a manufacturer price and second price with VAT).
Next thing I need to do is when I add in other textbox some value (discount for some buyers etc), I want to show below all calculation.
The main problem is that I cannot make any calculation!
Im having an class object and situation for example like this doesnt work.

C#
dboProducts product=new dboProducts();
txtPrice1.Text=(product.PriceVAT * product.PriceWithoutVAT).toString();


If its not too confusing for you guys, I would really appreciate your help.

Ok, so I`m using the query to find selected product by his id:
C#
        public static dboProducts getProduct(int id)
{
 var query = (from x in dc.dboProducts
                        where x.ProductID == id
                        select x).SingleOrDefault();
            return query;
}


On event selectedIndexChanged, I`m doing this:

C#
if (cbox_product.SelectedValue is int)
            {
                int id = Convert.ToInt32(cbox_product.SelectedValue);
                dboProducts product = ProductController.getProduct(id);
             
                if (product != null)
                {
                   lbl_group.Text =product.Group.Name;
                   
                   txtPrice=product.Price.ToString(); 
                   txtPriceVAT=product.PriceVAT.ToString();


                }
            }


This above works well, but when I`m try to do some calculation, like this:
C#
txt_NewPrice.Text = (product.Price - ((product.Price * Convert.ToDouble(txt_NewData.Text)) / 100)).ToString();


In textbox txt_NewPrice nothing shows :/

If I write for example:

txt_NewPrice.Text=(product.Price * 123).toString() // or any number, it works.
But with two instances of class, no.
Posted
Updated 14-Feb-13 0:01am
v2
Comments
Anurag Sinha V 14-Feb-13 5:49am    
Hi,

Can you post some more code?
Need to see how you have defined your class.
Does it have any parameters being passed or else?
Posting more relevant code will help us to assist you better.

regards
anurag
ellisbay 14-Feb-13 6:02am    
I updated my code. Hope it will help.

Problem was in decimal.
Sorry for your trouble, I`m coding last 10 hours, so I didnt see mistake.
Thank you for your comments.
 
Share this answer
 
Are you converting the values to int because values from dropdown lists are in string format.
 
Share this answer
 

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