Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 需要BAL类逻辑方面的帮助吗_C#_User Interface - Fatal编程技术网

C# 需要BAL类逻辑方面的帮助吗

C# 需要BAL类逻辑方面的帮助吗,c#,user-interface,C#,User Interface,在我的销售明细软件中,我想计算总成本、折扣、净总成本。从文本框中输入Quantity和rate后,应自动填充所有值。在我的程序中,它能够显示总成本和净额,但不显示折扣值,它总是只显示0。这是我的代码,请有人修改一下这里出了什么问题 public class SalesEntity { private string custid; private string custname; private string productname; private int qua

在我的销售明细软件中,我想计算总成本、折扣、净总成本。从文本框中输入Quantity和rate后,应自动填充所有值。在我的程序中,它能够显示总成本和净额,但不显示折扣值,它总是只显示0。这是我的代码,请有人修改一下这里出了什么问题

public class SalesEntity
{
    private string custid;
    private string custname;
    private string productname;
    private int quantity;
    private float rate;
    private float total;
    private float discount;
    private float NetTotal;

    public string CUSTOMERID
    {
        get
        {
            return custid;
        }
        set
        {
            custid = value;
        }
    }
    public string CUSTOMERNAME
    {
        get
        {
            return custname;
        }
        set
        {
            custname = value;
        }
    }
    public string PRODUCTNAME
    {
        get
        {
            return productname;
        }
        set
        {
            productname = value;
        }
    }
    public int QUANTITY
    {
        get
        {
            return quantity;
        }
        set
        {
            quantity = value;
        }
    }
    public float RATE
    {
        get
        {
            return rate;
        }
        set
        {
            rate = value;
        }
    }
    public float TOTAL
    {
        get
        {
            return total;
        }
        set
        {
            total = value; ;

        }
    }
    public float DISCOUNT
    {
        get
        {
            return discount;
        }
        set
        {
            discount = value;
        }
    }
    public float NETTOTAL
    {
        get
        {            
            return NetTotal;
        }
        set
        {
            NetTotal = value;
        }
    }
}
public class SalesBALManager
{  
    public SalesEntity Compute(SalesEntity salesEntity)
    {
        salesEntity.TOTAL = salesEntity.QUANTITY * salesEntity.RATE;
        salesEntity.DISCOUNT = (10 / 100 * salesEntity.TOTAL);
        salesEntity.NETTOTAL = salesEntity.TOTAL - salesEntity.DISCOUNT;
        return salesEntity;

    }
}
protected void TxtRate_TextChanged(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            SalesBALManager obj = new SalesBALManager();
            SalesEntity salesentity = new SalesEntity();

            salesentity.QUANTITY = Convert.ToInt32(TxtQuantity.Text);
            salesentity.RATE = Convert.ToInt32(TxtRate.Text);
            salesentity.CUSTOMERID = TxtCustId.Text;
            salesentity.CUSTOMERNAME = TxtCustName.Text;

            salesentity = obj.Compute(salesentity);

            TxtTotal.Text = salesentity.TOTAL.ToString();
            TxtDiscount.Text = salesentity.DISCOUNT.ToString();            
            TxtNetTotal.Text = salesentity.NETTOTAL.ToString();
        }

    }

怀疑10/100是使用整数除法计算的,给出0,然后被转换为乘法。为什么不直接用0.1来代替呢?

怀疑10/100是用整数除法计算的,给0,然后被转换为乘法。为什么不直接替换0.1?

您至少有两个问题。首先,当您应该使用十进制时,您使用浮点数;其次,当您除以10/100时,您使用整数算术。使用整数算术时,结果为零。我会将浮点数改为小数,并指定0.1M而不是10/100。我还应该更加小心我的字符串格式,这样十进制数字中的小数点的数量是固定的,例如,discount.ToString 0.00。

您至少有两个问题。首先,当您应该使用十进制时,您使用浮点数;其次,当您除以10/100时,您使用整数算术。使用整数算术时,结果为零。我会将浮点数改为小数,并指定0.1M而不是10/100。我还应该更加小心我的字符串格式,这样十进制数字中的小数点的数量是固定的,例如,discount.ToString 0.00。

10/100是整数除法,返回0的整数。将其转换为浮动以执行浮动分割

((float)10/(float)100)

10/100是整数除法,返回0的整数。将其转换为浮动以执行浮动分割

((float)10/(float)100)