如何用约会日期填充组合框?

您好,很抱歉,我想确保我提供所有信息, 我正在创建一个约会应用程序,用户可以在其中约会,修改并返回约会。在我的修改约会屏幕上,我无法根据需要在组合框中填充正确的值。该信息应包括在现有约会中。例如,bill在5/19的9有一个约会。弹出窗口应该已经在9点显示5/19了。我试图设置诸如getDateonly和getTimeonly之类的内容,但是失败了,无法弄清楚。我已经附上了它的外观和外观的屏幕截图。

如何用约会日期填充组合框?

如何用约会日期填充组合框?

    ModifyAppointmentController:
    
        public class ModifyAppointmentController implements Initializable {
    
        @FXML
        private TextField modifyContactNameText;
        @FXML
        private TextField modifyTitleText;
        @FXML
        private ComboBox<String> modifyLocationComboBox;
        @FXML
        private TextField modifyTypeText;
        @FXML
        private TextField modifyURLText;
        @FXML
        private ComboBox<String> modifyDescriptionComboBox;
        @FXML
        private DatePicker modifyDate;
        @FXML
        private ComboBox<String> modifyStartComboBox;
        @FXML
        private ComboBox<String> modifyEndComboBox;
        @FXML
        private Button saveModifyAppointmentButton;
        @FXML
        private Button cancelModifyAppointmentButton;
    
        Appointment selectedAppointment;
        int selectedIndex;
        
        ObservableList<String> appointmentTime = FXCollections.observableArrayList("09:00:00","10:00:00","11:00:00","12:00:00","13:00:00","14:00:00","15:00:00","16:00:00","17:00:00");
        ObservableList<String> appointmentLocation = FXCollections.observableArrayList("Phoenix","New York","London","Internet");
        ObservableList<String> appointmentDescription = FXCollections.observableArrayList("There will be a meeting","Documentation Discussion","Planning & Coordination");
        
        /*Initializes the controller class.*/
        @Override
        public void initialize(URL url,ResourceBundle rb) {
            
            modifyStartComboBox.setItems(appointmentTime);
            modifyEndComboBox.setItems(appointmentTime);
            modifyDescriptionComboBox.setItems(appointmentDescription);
            modifyLocationComboBox.setItems(appointmentLocation);
    
        }    

   // Sets the information in the Modify Appointment pop up from the table
   // This is the part I am struggling with ******
public void setappointment(Appointment appointment,int index) {

        LocalDate date = modifyDate.getvalue();
        selectedAppointment = appointment;
        selectedIndex = index;
        
        Appointment newAppointment = (Appointment) appointment;           


        this.modifyContactNameText.setText(newAppointment.getcontact());
        this.modifyTitleText.setText((newAppointment.getTitle()));
        this.modifyURLText.setText((newAppointment.getUrl()));
        this.modifyTypeText.setText((newAppointment.getType()));
        this.modifyDescriptionComboBox.setvalue((newAppointment.getDescription()));
        this.modifyLocationComboBox.setvalue((newAppointment.getLocation()));   




//Not sure if this would be relevant but I included it just in case
private void saveMondifyAppointmentHandler(actionEvent event) throws IOException {
    
    try {
    
    int appointmentId = selectedAppointment.getappointmentId();
    int customerId = selectedAppointment.getcustomerId();
    int userId = selectedAppointment.getUserId();
    
    String title = modifyTitleText.getText();
    String description = modifyDescriptionComboBox.getSelectionmodel().getSelectedItem();
    String location = modifyLocationComboBox.getSelectionmodel().getSelectedItem();
    String assignedContact = modifyContactNameText.getText();
    String type = modifyTypeText.getText();
    String url = modifyURLText.getText();
    
    
    LocalDate date = modifyDate.getvalue();
    String startTime = modifyStartComboBox.getSelectionmodel().getSelectedItem();
    String endTime = modifyEndComboBox.getSelectionmodel().getSelectedItem();
    String selectedStartTime = date + " " + startTime;
    String selectedEndTime = date + " " + endTime;
    
    if(startTime == null || endTime == null) {
        
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle("Error");
        alert.setHeaderText("No appointment time selected");
        alert.setContentText("Please select a start and end time to add to this appointment!");
        alert.showAndWait();  
    }
    
    if(location == null) {
                    
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle("Error");
        alert.setHeaderText("No location selected");
        alert.setContentText("Please select a location to add to this appointment!");
        alert.showAndWait();  
    }
    
    if(description == null) {
                    
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle("Error");
        alert.setHeaderText("No description selected");
        alert.setContentText("Please select a description to add to this appointment!");
        alert.showAndWait();
        
    }
    
    if(date == null) {
                   
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle("Error");
        alert.setHeaderText("No date selected");
        alert.setContentText("Please select a valid date to add to this appointment!");
        alert.showAndWait();
    }
    
    
    
    LocalDateTime localTime = LocalDateTime.now();
    ZoneId localZoneId = ZoneId.of(TimeZone.getDefault().getID());
    
    DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    
    
    LocalDateTime startDateTime = LocalDateTime.parse(selectedStartTime,format);
    LocalDateTime endDateTime = LocalDateTime.parse(selectedEndTime,format);
    
    ZonedDateTime zonedStartLocal = ZonedDateTime.of(startDateTime,localZoneId);
    ZonedDateTime zonedStartUTC = zonedStartLocal.withZonesameInstant(ZoneId.of("UTC"));
    
    ZonedDateTime zonedEndLocal = ZonedDateTime.of(endDateTime,localZoneId);
    ZonedDateTime zonedEndUTC = zonedEndLocal.withZonesameInstant(ZoneId.of("UTC"));
    
    int startUTCYear = zonedStartUTC.getYear();
    int startUTCMonth = zonedStartUTC.getMonthValue();
    int startUTCDay = zonedStartUTC.getDayOfMonth();
    int startUTCHour = zonedStartUTC.getHour();
    int startUTCMinute = zonedStartUTC.getMinute();
    
    String testZonedStart = Integer.toString(startUTCYear) + "-" + Integer.toString(startUTCMonth) + "-" + Integer.toString(startUTCDay) + " " 
            + Integer.toString(startUTCHour) + ":" + Integer.toString(startUTCMinute) + ":" + Integer.toString(startUTCMinute);
    
    int endUTCYear = zonedEndUTC.getYear();
    int endUTCMonth = zonedEndUTC.getMonthValue();
    int endUTCDay = zonedEndUTC.getDayOfMonth();
    int endUTCHour = zonedEndUTC.getHour();
    int endUTCMinute = zonedEndUTC.getMinute();
    
    String testZonedEnd = Integer.toString(endUTCYear) + "-" + Integer.toString(endUTCMonth) + "-" + Integer.toString(endUTCDay) + " " 
            + Integer.toString(endUTCHour) + ":" + Integer.toString(endUTCMinute) + ":" + Integer.toString(endUTCMinute);
    
    String startConstructorValue = zonedStartLocal.toString();
    String endConstructorValue = zonedEndLocal.toString();
    
    if(AddAppointmentController.validateAppointmentStart(testZonedStart,testZonedEnd)) {
    
    Appointment appointment = new Appointment(appointmentId,customerId,userId,title,description,location,assignedContact,type,url,startConstructorValue,endConstructorValue);
    DataProvider.getallAppointmentsTableList().set(selectedIndex,appointment);
   
    Statement statement = DBConnection.getconnection().createStatement();
    ResultSet selectAppointment = statement.executeQuery("SELECT * FROM appointment WHERE appointmentId = " + appointmentId + "");
    
    while(selectAppointment.next()) {
        
        customerId = selectAppointment.getInt("customerId");
    }
    
    
    String updateAppointment = "UPDATE appointment SET title = '" + title + "',description = '" + description + "',location = '" + location + "',contact = '"
            + assignedContact + "',type = '" + type + "',url = '" + url + "',start = '" + testZonedStart + "',end = '" + testZonedEnd + "' WHERE appointmentId = " + appointmentId;
    int updatedAppointment = statement.executeUpdate(updateAppointment);
    if(updatedAppointment == 1) {
        System.out.println("Appointment was updated successfully!");
         
            }
        }
    }
    catch(SQLException ex) {
        System.out.println("Error " + ex.getMessage());
    }
    
    catch(NullPointerException ex) {   
        System.out.println("Error " + ex.getMessage());  
    }
    
    catch(DateTimeParseException ex) {
        System.out.println("Error " + ex.getMessage());
    }
    
    Stage stage = (Stage)((Button)event.getsource()).getScene().getWindow();
    Object scene = FXMLLoader.load(getclass().getResource("/View_Controller/AppointmentScreen.fxml"));
    stage.setScene(new Scene((Parent) scene));
    stage.show();
    
}
iCMS 回答:如何用约会日期填充组合框?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1904496.html

大家都在问