我有Restaurant POS,在销售屏幕上,我在表单加载时创建一个新的发票,并在结账时,如果没有项目插入到发票中,我删除当前发票,但如果有项目,我问用户是否真的确定他想关闭发票并取消发票如果是,我删除发票,如果没有,我将他保留在销售屏幕中。在关闭表单时,我检查用户类型,如果是员工,我会关闭整个应用程序,如果是管理员,我会正常关闭表单,这样他就可以返回主页表单
但是在表单关闭时,代码执行了2次,我不知道为什么,我知道代码正在无限循环,但我改进了代码,但它现在仍然执行了2次。
下面是我的代码:
private void Sales_screen_FormClosed(object sender, FormClosedEventArgs e)
{
DBConn.Delete("Delete from invoices where ID=@ID", CommandType.Text, new SqlParameter[] { new SqlParameter("@ID", INVOICEID.ToString()) });
if (Curent_user.Utype == "employee")
{
try
{
Environment.Exit(0);
}
catch (Exception)
{
}
}
else
{
Close();
Dispose();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
private void Sales_screen_FormClosing(object sender, FormClosingEventArgs e)
{
if (GV.Rows.Count > 0)
{
var result = CmessageBox.ShowDialog(this, "confirmation", "are you sure you want to close the invoice؟");
if (result != DialogResult.Yes)
{
e.Cancel = true;
}
}
}发布于 2021-03-26 01:05:31
通过删除else中的Close()行,它不应该循环
https://stackoverflow.com/questions/66782832
复制相似问题