ユーザーが配列に保存した値を入力するフォームがありますが、ユーザーがキャンセルしたい場合、ユーザーが先に進んで予約をキャンセルしたいかどうかをユーザーに最後に尋ねてもらいたいです。ユーザーがこの最後の時間を拒否した場合、プログラムを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;
}
}