[英]C# Subracting Inputted Textbox Value to the Label value
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. 我正在以Windows形式构建这些POS桌面应用程序,并且几乎完成了,但是在处理客户账单时遇到了问题。
To be specific: 再具体一点:
SIMSProduct Usercontrol SIMS产品用户控件
ProcessCart Form ProcessCart表格
Note: lbl corresponds to Windows form Label 注意:lbl对应于Windows窗体标签
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. 问题是当我尝试输入txt_amount时,假设我输入了5000,而5000并未计算lbl_price的值,lbl_totalprice也等于我输入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)
{
int value1;
int value2;
decimal value3;
if (int.TryParse(lbl_price.Text.Trim(), out value1))
{
Total = Convert.ToInt32(lbl_price.Text);
}
if (int.TryParse(txt_amount.Text.Trim(), out value2))
{
Paid = Convert.ToInt32(txt_amount.Text);
}
lbl_totalprice.Text = (Paid - Total).ToString();
}
I think your issue is a casting issue. 我认为您的问题是决定性的问题。 Looks like you're attempting to cast a decimal to an integer value.
看起来您正在尝试将小数转换为整数值。 Try replacing with this code.
尝试用此代码替换。
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.ToDecimal(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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.