private void btnSaveVehicle_Click(object sender, EventArgs e) { lblVehicleID.Text = null; //Create a new row that the variables will be added into DataRow newVehicleRow = DM.dtVehicle.NewRow(); //If any of the text areas are empty then do not write data and return if ((txtAddPlateNumber.Text == "") || (txtAddMake.Text == "") || (txtAddModel.Text == "") || (cboAddOwner.Text == "")) { MessageBox.Show("You must enter a value for each of the text fields.", "Error"); } else { newVehicleRow["PlateNumber"] = txtAddPlateNumber.Text; newVehicleRow["Make"] = txtAddMake.Text; newVehicleRow["Model"] = txtAddModel.Text; newVehicleRow["OwnerID"] = cboAddOwner.Text; //Add the new row to the Table DM.dtVehicle.Rows.Add(newVehicleRow); DM.UpdateVehicle(); //Give the user a success message MessageBox.Show("Vehicle added successfully.", "Success"); } return; }
private void btnDeleteVehicle_Click(object sender, EventArgs e) { DataRow deleteVehicleRow = DM.dtVehicle.Rows[currencyManager.Position]; DataRow[] ServiceRow = DM.dtService.Select("VehicleID = " + txtVehicleID.Text); if (ServiceRow.Length != 0) { MessageBox.Show("You may only delete vehicles that do not have services", "Error"); return; } else { if (MessageBox.Show("Are you sure want to delete this record?", "Warning", MessageBoxButtons.OKCancel) == DialogResult.OK) { deleteVehicleRow.Delete(); MessageBox.Show("Vehicle deleted successfully", "Success"); DM.UpdateVehicle(); return; } } }