protected Vehicle CreateVehicle() { try { //Creating the vehicle Vehicle vehicle = new Vehicle(); VehicleType vehicleType = new VehicleType(); vehicle.VehiclePlate = textboxLicense.Value; if (hiddenTypeValue.Value.Equals(string.Empty)) { vehicleType.Id = Convert.ToInt32(selectType.Items[0].Value); vehicleType.Name = selectType.Items[0].Text; } else { vehicleType.Id = Convert.ToInt32(hiddenTypeValue.Value); vehicleType.Name = selectType.Items.FindByValue(hiddenTypeValue.Value).Text; } vehicle.Type = vehicleType; return vehicle; } catch (FormatException) { return null; } }
public void InsertVehicleType(VehicleType vehicleType) { SqlConnection connection = ManageDatabaseConnection("Open"); using (SqlCommand insert = new SqlCommand(@"InsertVehicleType", connection)) { insert.CommandType = CommandType.StoredProcedure; insert.Parameters.Add("@Name", SqlDbType.VarChar).Value = vehicleType.Name; insert.ExecuteNonQuery(); } connection = ManageDatabaseConnection("Close"); }
public void UpdateVehicleType(VehicleType vehicleType) { SqlConnection connection = ManageDatabaseConnection("Open"); using (SqlCommand update = new SqlCommand(@"UpdateVehicleType", connection)) { update.CommandType = CommandType.StoredProcedure; update.Parameters.Add("@Id", SqlDbType.Int).Value = vehicleType.Id; update.Parameters.Add("@Name", SqlDbType.VarChar).Value = vehicleType.Name; update.ExecuteNonQuery(); } connection = ManageDatabaseConnection("Close"); }
protected VehicleType CreateVehicleType() { VehicleType vehicleType = new VehicleType(); try { vehicleType.Name = textboxVehicleType.Value; return vehicleType; } catch (FormatException) { buttonStyle.buttonStyleRed(buttonErrors, "Invalid data, please check it or contact with us."); return null; } }
public int UpdateVehicleType(VehicleType vehicleType) { try { if (vehicleType.Name.Equals(string.Empty)) { return 1; } else { vehicleTypeData.UpdateVehicleType(vehicleType); return 0; } } catch (SqlException) { return 2; } }
protected void UpdateVehicleType(VehicleType vehicleType) { if (vehicleType != null) { switch (vehicleTypeRules.UpdateVehicleType(vehicleType)) { case 0: textboxVehicleType.Value = ""; buttonStyle.buttonStyleBlue(buttonErrors, "Vehicle type updated successful."); break; case 1: buttonStyle.buttonStyleWhite(buttonErrors, "Vehicle type name field is empty."); break; case 2: buttonStyle.buttonStyleRed(buttonErrors, "An error ocurred updating the Vehicle type, please check data or contact we us."); break; } } }