问题描述
我正在以Windows形式构建这些POS桌面应用程序,它几乎已经完成,但我在处理客户账单方面遇到了问题。
具体如下:
SIMSProduct Usercontrol
- cart.lbl_price.Text = lbl_totalprice.Text;
首先,购买的客户总数为lbl_totalprice.Text
接下来,该总数用于ProcessCart表格,即cart.lbl_price.Text
- lbl_price.Text现已成功获取lbl_totalprice.Text的值
ProcessCart表格
- txt_amount(文本框)是用户输入应该减去lbl_price.Text失败的客户付款价值的地方。
- lbl_totalprice.Text对应于减去的lbl_price和txt_amount的输出也是失败的。
$
注意:lbl对应Windows窗体标签
问题是当我尝试输入我的txt_amount时,假设我输入5000并且5000没有减去lbl_price的值,lbl_totalprice也等于我输入的txt_amount。在这些代码下面,我在这里做错了什么?,
我不应该做的事情?或者我忘记了什么?我希望有人能够帮助解决这些问题。谢谢
I'm building these POS Desktop application in Windows form and it's almost done but i'm having problem in processing the customer bills.
To be specific:
SIMSProduct Usercontrol
- cart.lbl_price.Text = lbl_totalprice.Text;
First the total of the customer bought is in lbl_totalprice.Text
Next that total is used to ProcessCart Form which is the cart.lbl_price.Text
- lbl_price.Text is now successfully getting the value of lbl_totalprice.Text
ProcessCart Form
- txt_amount(Textbox) is where user input the pay value of customer that should be subracted to the lbl_price.Text which is fail.
- lbl_totalprice.Text corresponds to the output of subracted lbl_price and txt_amount which is fail too
Note: lbl corresponds to Windows form Label
The problem is when i tried to input to my txt_amount, let's say i input 5000 and that 5000 is not subracting the value of lbl_price, also the lbl_totalprice is equal to what i type to txt_amount. Below these code, What I've done wrong here ?, something that i should not made? or i forgot something ?. I hope someone would be able to help in these matter. Thank you
public partial class SIMSProduct : UserControl
{
ITEMCount item;
ProcessCart cart;
public SIMSProduct()
{
InitializeComponent();
}
private void btn_process_Click(object sender, EventArgs e)
{
cart = new ProcessCart();
cart.Show();
cart.lbl_price.Text = lbl_totalprice.Text;
}
}
public partial class ProcessCart : Form
{
public ProcessCart()
{
InitializeComponent();
}
private void txt_amount_TextChanged(object sender, EventArgs e)
{
decimal value1;
decimal value2;
decimal value3;
if (decimal.TryParse(lbl_price.Text.Trim(), out value1))
{
Total = Convert.ToInt32(lbl_price.Text);
}
if (decimal.TryParse(txt_amount.Text.Trim(), out value2))
{
Paid = Convert.ToDecimal(txt_amount.Text);
}
if (decimal.TryParse(lbl_totalprice.Text.Trim(), out value3))
{
Change = Convert.ToDecimal(lbl_totalprice.Text);
}
Change = Paid - Total;
}
}
推荐答案
我不确定我是否完全理解这个问题,但至少有一个明显的问题。
I'm not sure I completely understand the issue, but there is at least one obvious problem.
你正在计算两次改变。我确定第一个不对。
You are calculating Change twice. I'm sure the first one can't be right.
if (decimal.TryParse(lbl_totalprice.Text.Trim(), out value3))
{
// This looks wrong. Are you sure this should be Change here, and not something else?
Change = Convert.ToDecimal(lbl_totalprice.Text);
}
Change = Paid - Total; // You calculate Change here, which looks like the above line can't be right.
这篇关于C#将输入的文本框值减去Label值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!