我的功能是在有预订请求时保存客户数据。有两个条件:即使尚未填写客户数据也强制保存预订或使用已完成的客户数据保存预订。
如果程序发现该客户不存在以确认用户是否想要创建新的客户数据,我会尝试捕获并向用户提出异常。如果是,则打开新表单,如果不是,则强制程序保存。
在强制程序保存内部,我想捕获其他异常(如果存在)。
目前,我正在这样做。
try
{
booking = new Booking();
booking.RoomID = roomID;
booking.Tel = txtTel.Text;
booking.PersonalID = txtId.Text;
booking.Name = txtBookBy.Text;
booking.CheckinDate = dtpCheckin.Value;
booking.CheckoutDate = dtpCheckin.Value.AddDays(Convert.ToDouble(cbNight.SelectedItem));
mng.SaveBooking(booking, false);
if (MessageBox.Show("Data is saved") == DialogResult.OK)
{
this.Close();
}
}
catch (NewCustomerException ex)
{
DialogResult dialog = MessageBox.Show("Customer doesn't exist in database. Do you want to create new customer?", "Please confirm", MessageBoxButtons.YesNo);
if (dialog == DialogResult.Yes)
{
String param = txtBookBy.Text + "," + txtTel.Text + "," + txtId.Text;
CustomerForm oForm = new CustomerForm(param);
oForm.Show();
}
else if (dialog == DialogResult.No)
{
try
{
mng.SaveBooking(booking, true);
}
catch (Exception ex1)
{
MessageBox.Show(ex1.Message);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}