我正在以Windows形式构建这些POS桌面应用程序,它几乎完成了,但是在处理客户账单时遇到了问题。
要具体:
SIMSProduct用户控件
ProcessCart表单
注意:lbl对应于Windows窗体标签
问题是当我尝试输入txt_amount时,假设我输入了5000,而5000并没有计算lbl_price的值,lbl_totalprice也等于我输入txt_amount的值。在这些代码下面,我在这里做错了什么?我不应该做的事情?还是我忘记了什么?我希望有人能够在这些问题上提供帮助。谢谢
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();
}
答案 0 :(得分:0)
我认为您的问题属于强制性问题。看起来您正在尝试将小数转换为整数值。尝试用此代码替换。
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;
}
}