private bool isInvalid() { bool isInvalid = false; int test; if (((!int.TryParse(txtFlightNum.Text, out test)) || test < 0) || txtFlightNum.Text == string.Empty) { txtMsg.Visible = true; txtMsg.Text = "Red boxes need attention"; txtFlightNum.BackColor = Color.LightPink; isInvalid = true; } else if (a.getFlight(Convert.ToInt32(txtFlightNum.Text)) != null) { txtMsg.Visible = true; txtMsg.Text = "Red boxes need attention"; txtFlightNum.BackColor = Color.LightPink; isInvalid = true; } else { txtFlightNum.BackColor = Color.White; } if (((!int.TryParse(txtMaxCap.Text, out test)) && test > 0) || txtMaxCap.Text == string.Empty) { txtMsg.Visible = true; txtMsg.Text = "Red boxes need attention"; txtMaxCap.BackColor = Color.LightPink; isInvalid = true; } else { txtMaxCap.BackColor = Color.White; } if (!name.IsMatch(txtOrigin.Text)) { txtMsg.Visible = true; txtMsg.Text = "Red boxes need attention"; txtOrigin.BackColor = Color.LightPink; isInvalid = true; } else { txtOrigin.BackColor = Color.White; } if (!name.IsMatch(txtDest.Text)) { txtMsg.Visible = true; txtMsg.Text = "Red boxes need attention"; txtDest.BackColor = Color.LightPink; isInvalid = true; } else { txtDest.BackColor = Color.White; } return(isInvalid); }
private void BtnAddBook_Click(object sender, EventArgs e) { int fid, cid; if (int.TryParse(txtFlNum.Text, out fid) && int.TryParse(txtCustId.Text, out cid)) { Customer c = a.getCustomer(cid); Flight f = a.getFlight(fid); a.addBooking(c, f); string name = c.getFirstName() + " " + c.getLastName(); a.addPassenger(f.getFlightNumber(), c.getId(), name); txtFlNum.Text = ""; txtCustId.Text = ""; dgv_Book.DataSource = a.bookingList(); } else { txtMsg.Visible = true; txtMsg.Text = "please select a valid flight and customer"; } }