gpt4 book ai didi

c# - 无法在此循环中找到问题

转载 作者:太空宇宙 更新时间:2023-11-03 20:24:01 25 4
gpt4 key购买 nike

我有一个表单,用户可以输入我保存在数组中的值,但是当用户想要取消时,我希望最后一次询问用户是否要继续并取消预订。如果用户最后一次拒绝,我希望程序返回到 GUI 并关注包含所有预订行的文本框,而不是取消,但我会向您展示我编写的代码,它会询问用户是否当然,如果不是,它仍然会删除预订,然后将焦点放在文本框上。我的代码有什么问题?

public void Cancelreservation()
{
int index = lstReservations.SelectedIndex;
bool checkedindex = m_seatMngr.CheckIndex(index);
if (checkedindex)
{

if (!m_seatMngr.CancelSeat(index))
{
if (lstReservations.SelectedIndex == -1)
{
MessageBox.Show("You need to select a row.", "Error!",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
lstReservations.Focus();
}
else
{
MessageBox.Show("The seat is not reserved! No need to cancel
reservation.", "Important Query",
MessageBoxButtons.OK);
lstReservations.Focus();
}
}
else
{
if (MessageBox.Show("Continue to cancel the reservation?",
"Important Query", MessageBoxButtons.YesNo)
== DialogResult.No)
{
lstReservations.Focus();
}
else
{
m_seatMngr.CancelSeat(index);
}
}
}

m_seatMngr

         public bool CancelSeat(int index)
{

if (m_vacantList[index] == "Reserved")
{
m_nameList[index] = " - ";
m_priceList[index] = 0;
m_vacantList[index] = "Vacant";
return true;
}
else
{
return false;
}

}

最佳答案

假设 m_seatMngr.CancelSeat(index) 是实际取消座位的方法,您将调用该方法两次。第二个 if 语句,在你的代码中有六行,是这样的:

if (!m_seatMngr.CancelSeat(index))

...而且似乎(鉴于上述假设)这条线甚至会在您显示 MessageBox 之前取消座位。

关于c# - 无法在此循环中找到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11759042/

25 4 0
文章推荐: c# - switch cases .NET 中的代码优化
文章推荐: matlab - 在 MATLAB 中从 4 个点计算二维齐次透视变换矩阵
文章推荐: html - 无论浏览器大小如何,如何让
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com