static void updateMaxi(MaxiVehicle maxi, int vID) { try { maxi.validateEntry(); SqlCommand cmd = new SqlCommand("UPDATE Vehicle SET fuelType = @fuelType, vehicleMake = @vehicleMake, vehicleType = @vehicleType, noOfKiloMeters = @noOfKM WHERE vehicleID = @vehicleID;" + "UPDATE Maxi SET loadInKG = @loadInKG WHERE vehicleID = @vehicleID;" + "UPDATE Bill SET billAmount = @billAmount WHERE vehicleID = @vehicleID;", con); cmd.Parameters.AddWithValue("@vehicleID", vID); cmd.Parameters.AddWithValue("@fuelType", maxi.getFuelType()); cmd.Parameters.AddWithValue("@vehicleMake", maxi.getVehicleMake()); cmd.Parameters.AddWithValue("@vehicleType", maxi.getVehicleType()); cmd.Parameters.AddWithValue("@noOfKM", maxi.getNoOfKiloMeters()); cmd.Parameters.AddWithValue("@loadInKG", maxi.getLoadInKG()); cmd.Parameters.AddWithValue("@billAmount", maxi.calculateBill()); con.Open(); if (cmd.ExecuteNonQuery() == 3) { Console.WriteLine("\nThe Vehicle updated successfully."); } else { throw new Exception("\nVehicle details not updated."); } } catch (Exception e) { Console.WriteLine(e.Message); } finally { con.Close(); } }
static void addToDBMaxi(MaxiVehicle maxi) { try { maxi.validateEntry(); SqlCommand cmd = new SqlCommand("INSERT INTO Vehicle VALUES (@fuelType, @vehicleMake, @vehicleType, @noOfKM);" + "INSERT INTO Maxi VALUES(IDENT_CURRENT('Vehicle'), @loadInKG);" + "INSERT INTO Bill(vehicleID, billAmount) VALUES(IDENT_CURRENT('Vehicle'), @billAmount);", con); cmd.Parameters.AddWithValue("@fuelType", maxi.getFuelType()); cmd.Parameters.AddWithValue("@vehicleMake", maxi.getVehicleMake()); cmd.Parameters.AddWithValue("@vehicleType", maxi.getVehicleType()); cmd.Parameters.AddWithValue("@noOfKm", maxi.getNoOfKiloMeters()); cmd.Parameters.AddWithValue("@loadInKG", maxi.getLoadInKG()); cmd.Parameters.AddWithValue("@billAmount", maxi.calculateBill()); con.Open(); if (cmd.ExecuteNonQuery() != 0) { Console.WriteLine("\nThe Vehicle added successfully."); } else { throw new Exception(); } } catch (Exception e) { Console.WriteLine("\nVehicle Not Added."); Console.WriteLine(e.Message); } finally { con.Close(); } }