需要帮忙!在C#桌面应用程序中遇到基本数学运算问题。 [英] Need help! Having problem with basic mathematical operations in C# desktop app.

查看:61
本文介绍了需要帮忙!在C#桌面应用程序中遇到基本数学运算问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我有一个非常愚蠢的问题,我不知道如何解决。用桌面应用程序工作了一段时间,但我没有这样的情况(这个程序需要一些基本的数学运算)。

所以这就是问题。

我有下拉列表,当用户选择制造商及其产品时,价格显示在两个文本框中(第一个价格为制造商价格,第二个价格为增值税)。

接下来我需要做的就是当我在其他文本框中添加一些值(某些买家的折扣等),我想在下面显示所有计算。

主要问题是我无法进行任何计算!

Im有一个类对象和情况例如像这样不起作用。



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.

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





如果它不太混乱对于你们,我真的很感谢你的帮助。



好​​的,所以我使用查询通过他的id找到所选产品:



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:

        public static dboProducts getProduct(int id)
{
 var query = (from x in dc.dboProducts
                        where x.ProductID == id
                        select x).SingleOrDefault();
            return query;
}





在selectIndexChanged事件中,我这样做:





On event selectedIndexChanged, I`m doing this:

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:

txt_NewPrice.Text = (product.Price - ((product.Price * Convert.ToDouble(txt_NewData.Text)) / 100)).ToString();





在文本框中txt_NewPrice什么都没有显示:/



如果我写的例如:



txt_NewPrice.Text =(product.Price * 123).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.

推荐答案

问题是十进制。

抱歉你的麻烦,我编码最后10个小时,所以我没有看到错误。

感谢您的评论。
Problem was in decimal.
Sorry for your trouble, I`m coding last 10 hours, so I didnt see mistake.
Thank you for your comments.


您是否将值转换为int,因为下拉列表中的值是字符串格式。
Are you converting the values to int because values from dropdown lists are in string format.


这篇关于需要帮忙!在C#桌面应用程序中遇到基本数学运算问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆