private void btnSavePlane_Click(object sender, EventArgs e) { try { int planeCapacity = 0, passengersNum = 0; string planeName = txtPlaneName.Text.Trim(); string planeType = ddlPlaneType.SelectedItem.ToString(); int.TryParse(txtMaxCapacity.Text.Trim(), out planeCapacity); int.TryParse(txtPassNumber.Text.Trim(), out passengersNum); if (planeName == "" && planeType == "Select Plane Type" && planeCapacity == 0 && passengersNum == 0) { MessageBox.Show("All fields are required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (planeName == "") { MessageBox.Show("Plane name is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (planeType == "Select Plane Type") { MessageBox.Show("Select a plane type", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (planeCapacity == 0) { MessageBox.Show("Plane Capacity is required and must be a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (passengersNum == 0) { MessageBox.Show("Number of passengers is required and must be a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Plane plane = new Plane { PlaneName = planeName, PlaneType = planeType, Capacity = planeCapacity, PassengerNumber = passengersNum }; if (btnSavePlane.Text == "Save") { int planeSucc = _planeService.SaveUpdatePlane(plane); if (planeSucc > 0) { MessageBox.Show("Plane data saved successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { plane.Id = planeId; int planeSucc = _planeService.SaveUpdatePlane(plane); if (planeSucc > 0) { MessageBox.Show("Plane data updated successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } PlaneClearance(); LoadAllPlane(); } } } catch (Exception ex) { throw; } }