From ff65df05b48b8eb0fde0e07d4dfafe115106103c Mon Sep 17 00:00:00 2001 From: Pat Min Date: Sun, 20 Mar 2022 13:59:08 -0600 Subject: [PATCH 1/7] Pat changes - Mar 20 2022 afternoon --- HelloApplication.java | 75 +------------ HelloController.java | 244 ++++++++++++++++++++++++------------------ hello-view.fxml | 14 +-- module-info.java | 12 +++ 4 files changed, 160 insertions(+), 185 deletions(-) create mode 100644 module-info.java diff --git a/HelloApplication.java b/HelloApplication.java index 7254f3d..3456522 100644 --- a/HelloApplication.java +++ b/HelloApplication.java @@ -1,4 +1,4 @@ -package com.example.reportmissingguns; +package com.example._218scenebuilder; import javafx.application.Application; import javafx.fxml.FXMLLoader; @@ -27,77 +27,4 @@ public void start(Stage stage) throws IOException { public static void main(String[] args) { launch(); } - - - public class WriteIncidentsHelper_v1 { - public List[] updateIncidentsTable(String[] inputParam) { - - String url = "jdbc:mysql://localhost:3306/testdb"; - String username = "root"; - String password = "Code"; - - try { - Class.forName("com.mysql.cj.jdbc.Driver"); - } catch (ClassNotFoundException e) { - System.out.println("Class not found"); - } - - try ( - Connection conn = DriverManager.getConnection(url, username, password); - ) { - StringBuilder query = new StringBuilder(); - query.append("insert into incidents values("); - for(int i = 0; i < 16; i++) { - if(i >= 2 && i != 14) { - query.append("\"" + inputParam[i] + "\""); - } else { - query.append(inputParam[i]); - } - if(i < 15) { - query.append(", "); - } - } - query.append(");"); - - // insert into incidents values(4, 456, "2022-03-13", "10:10:00.0000000", "2022-03-13", "10:11:00.0000000", "345", "6D", "S McIntyre St", "Lakewood", "CO", "80401", "Lakewood PD", "Stolen", null, "TestDescription"); - - System.out.println(query.toString()); - - - Statement stmnt = conn.createStatement(); - int rowCount = stmnt.executeUpdate(query.toString()); - - List ids = new ArrayList<>(); - List submitterIds = new ArrayList<>(); - List datesOccurred = new ArrayList<>(); - List timesOccurred = new ArrayList<>(); - List datesReported = new ArrayList<>(); - List timesReported = new ArrayList<>(); - List incidentHouseNumbers = new ArrayList<>(); - List incidentUnitNumbers = new ArrayList<>(); - List incidentStreets = new ArrayList<>(); - List incidentCities = new ArrayList<>(); - List incidentStates = new ArrayList<>(); - List incidentZipCodes = new ArrayList<>(); - List incidentJurisdictions = new ArrayList<>(); - List lostOrStolenList = new ArrayList<>(); - List evidenceList = new ArrayList<>(); - List additionalDescriptions = new ArrayList<>(); - - - - List[] allTogether = new List[16]; - - - - return allTogether; - - - } catch (SQLException e) { - System.out.println("Error - exception"); - System.out.println(e.toString()); - } - return null; - } - } } diff --git a/HelloController.java b/HelloController.java index 340df10..4f7e7ba 100644 --- a/HelloController.java +++ b/HelloController.java @@ -1,4 +1,26 @@ -package com.example.reportmissingguns; +/* +Please use the following SQL to set up the test Incidents table: + +create table if not exists incidents( + ID int, + SUBMITTER_ID varchar(255), + DATE_OCCURRED date, + TIME_OCCURRED time, + DATETIME_REPORTED datetime, + INCIDENT_ADDRESS_LINE_1 varchar(255), + INCIDENT_ADDRESS_LINE_2 varchar(255), + INCIDENT_CITY varchar(255), + INCIDENT_STATE varchar(255), + INCIDENT_ZIP varchar(255), + INCIDENT_JURISDICTION varchar(255), + LOST_OR_STOLEN varchar(255), + EVIDENCE json, + ADDL_DESCRIPTION varchar(1000) +); + + */ + +package com.example._218scenebuilder; import javafx.fxml.FXML; import javafx.scene.control.*; @@ -18,148 +40,162 @@ public class HelloController { @FXML - private Label welcomeText; - + public Label welcomeText; @FXML - private TextField textField_first_middle; + public TextField textField_first_middle; @FXML - private TextField textField_last_name; + public TextField textField_last_name; @FXML - private DatePicker datePicker_DOB; + public DatePicker datePicker_DOB; @FXML - private TextField textField_address_line1; + public TextField textField_address_line1; @FXML - private TextField textField_address_line2; + public TextField textField_address_line2; @FXML - private TextField textField_city; + public TextField textField_city; @FXML - private TextField textField_state; + public TextField textField_state; @FXML - private TextField textField_zipcode; + public TextField textField_zipcode; @FXML - private TextField textField_email; + public TextField textField_email; @FXML - private DatePicker dataPicker_date_missing; + public DatePicker datePicker_date_missing; @FXML - private TextField textField_incident_time; + public TextField textField_incident_time; @FXML - private RadioButton radioButton_lost; + public RadioButton radioButton_lost; @FXML - private RadioButton radioButton_stolen; + public RadioButton radioButton_stolen; @FXML - private TextField textField_incident_address_line1; + public TextField textField_incident_address_line1; @FXML - private TextField textField_incident_address_line2; + public TextField textField_incident_address_line2; @FXML - private TextField textField_incident_city; + public TextField textField_incident_city; @FXML - private TextField textField_incident_state; + public TextField textField_incident_state; @FXML - private TextField textField_incident_zipcode; + public TextField textField_incident_zipcode; @FXML - private TextArea textArea_incident_addl_description; + public TextArea textArea_incident_addl_description; - String[] fieldValues = new String[16]; + String[] fieldValues = new String[14]; @FXML - protected void onHelloButtonClick() { + public void onHelloButtonClick() { welcomeText.setText("Welcome to JavaFX Application!"); } @FXML public void onSubmitClick() { -// long millis=System.currentTimeMillis(); -// java.util.Date date=new java.util.Date(millis); -// System.out.println(date); - LocalDateTime date = LocalDateTime.now(); + LocalDateTime datetime = LocalDateTime.now(); fieldValues[0] = null; // ID fieldValues[1] = textField_email.getText(); // SUBMITTER_ID (this will be the email address) - fieldValues[2] = dataPicker_date_missing.getValue().toString(); // DATE_OCCURRED + fieldValues[2] = datePicker_date_missing.getValue().toString(); // DATE_OCCURRED fieldValues[3] = textField_incident_time.getText(); // TIME_OCCURRED - fieldValues[4] = date.toString(); // DATE_REPORTED - fieldValues[5] = null; // TIME_REPORTED-old not in use - fieldValues[6] = textField_incident_address_line1.getText(); // INCIDENT_ADDRESS_LINE_1 - fieldValues[7] = textField_incident_address_line2.getText(); // INCIDENT_ADDRESS_LINE_2 - fieldValues[8] = textField_incident_city.getText(); // INCIDENT_CITY - fieldValues[9] = textField_incident_state.getText(); // INCIDENT_STATE - fieldValues[10] = textField_incident_zipcode.getText(); // INCIDENT_ZIP; - fieldValues[11] = radioButton_lost.getText(); // LOST - fieldValues[12] = radioButton_stolen.getText(); // STOLEN - fieldValues[13] = null; // EVIDENCE-not in use yet - fieldValues[14] = textArea_incident_addl_description.getText(); // ADDL_DESCRIPTION; + fieldValues[4] = datetime.toString(); // DATETIME_REPORTED + fieldValues[5] = textField_incident_address_line1.getText(); // INCIDENT_ADDRESS_LINE_1 + fieldValues[6] = textField_incident_address_line2.getText(); // INCIDENT_ADDRESS_LINE_2 + fieldValues[7] = textField_incident_city.getText(); // INCIDENT_CITY + fieldValues[8] = textField_incident_state.getText(); // INCIDENT_STATE + fieldValues[9] = textField_incident_zipcode.getText(); // INCIDENT_ZIP; + fieldValues[10] = null; // INCIDENT_JURISDICTION-not in use yet + + if (radioButton_lost.isSelected()) { + fieldValues[11] = radioButton_lost.getText(); // LOST + } else if (radioButton_stolen.isSelected()) { + fieldValues[11] = radioButton_stolen.getText(); // STOLEN + } else { + fieldValues[11] = null; + } + + fieldValues[12] = null; // EVIDENCE-not in use yet + fieldValues[13] = textArea_incident_addl_description.getText(); // ADDL_DESCRIPTION; updateIncidentsTable(fieldValues); } + public List[] updateIncidentsTable (String[]inputParam) { - public List[] updateIncidentsTable (String[]inputParam){ + String url = "jdbc:mysql://localhost:3306/testdb"; + String username = "root"; + String password = "Code"; - String url = "jdbc:mysql://localhost:3306/testdb"; - String username = "root"; - String password = "Code"; + //String url = "jdbc:mysql://localhost:3306/reportmissingguns_patmlocaltestdb_v1"; + //String username = "root"; + //String password = " "; - try { - Class.forName("com.mysql.cj.jdbc.Driver"); - } catch (ClassNotFoundException e) { - System.out.println("Class not found"); - } + try { + Class.forName("com.mysql.cj.jdbc.Driver"); + } catch (ClassNotFoundException e) { + System.out.println("Class not found"); + } - try ( - Connection conn = DriverManager.getConnection(url, username, password); - ) { - System.out.println(conn.isValid(0)); - StringBuilder query = new StringBuilder(); - query.append("insert into incidents values("); - query.append("`id` int(11) NOT NULL AUTO_INCREMENT,") - for (int i = 1; i < 16; i++) { - if (i >= 2 && i != 14) { - query.append("\"" + inputParam[i] + "\""); - } else { - query.append(inputParam[i]); - } - if (i < 15) { - query.append(", "); - } - } - query.append(");"); - - // insert into incidents values(4, 456, "2022-03-13", "10:10:00.0000000", "2022-03-13", "10:11:00.0000000", "345", "6D", "S McIntyre St", "Lakewood", "CO", "80401", "Lakewood PD", "Stolen", null, "TestDescription"); - - System.out.println(query.toString()); - - - Statement stmnt = conn.createStatement(); - int rowCount = stmnt.executeUpdate(query.toString()); - - List ids = new ArrayList<>(); - List submitterIds = new ArrayList<>(); - List datesOccurred = new ArrayList<>(); - List timesOccurred = new ArrayList<>(); - List datesReported = new ArrayList<>(); - List timesReported = new ArrayList<>(); - List incidentHouseNumbers = new ArrayList<>(); - List incidentUnitNumbers = new ArrayList<>(); - List incidentStreets = new ArrayList<>(); - List incidentCities = new ArrayList<>(); - List incidentStates = new ArrayList<>(); - List incidentZipCodes = new ArrayList<>(); - List incidentJurisdictions = new ArrayList<>(); - List lostOrStolenList = new ArrayList<>(); - List evidenceList = new ArrayList<>(); - List additionalDescriptions = new ArrayList<>(); - - - List[] allTogether = new List[16]; - - - return allTogether; - - - } catch (SQLException e) { - System.out.println("Error - exception"); - System.out.println(e.toString()); + try ( + Connection conn = DriverManager.getConnection(url, username, password); + ) { + System.out.println(conn.isValid(0)); + StringBuilder query = new StringBuilder(); + query.append("insert into incidents values("); + query.append("null, "); // This line can be removed once we figure out the ID auto-incrementing + for (int i = 1; i <= 13; i++) { + if (i >= 1 && i != 10 && i != 12) { // 10 and 13 are just excluded for now because they're nulls - thus not strings + query.append("\"" + inputParam[i] + "\""); + } else { + query.append(inputParam[i]); + } + if (i <= 12) { + query.append(", "); } - return null; } + query.append(");"); + + System.out.println(query.toString()); + + Statement stmnt = conn.createStatement(); + int rowCount = stmnt.executeUpdate(query.toString()); // rowCount is just the result. The important part is the executeUpdate. + + List ids = new ArrayList<>(); + List submitterIds = new ArrayList<>(); + List datesOccurred = new ArrayList<>(); + List timesOccurred = new ArrayList<>(); + List dateTimesReported = new ArrayList<>(); + List incidentAddrLine1s = new ArrayList<>(); + List incidentAddrLine2s = new ArrayList<>(); + List incidentCities = new ArrayList<>(); + List incidentStates = new ArrayList<>(); + List incidentZipCodes = new ArrayList<>(); + List incidentJurisdictions = new ArrayList<>(); + List lostOrStolenList = new ArrayList<>(); + List evidenceList = new ArrayList<>(); + List additionalDescriptions = new ArrayList<>(); + + List[] allTogether = new List[14]; + + allTogether[0] = ids; + allTogether[1] = submitterIds; + allTogether[2] = datesOccurred; + allTogether[3] = timesOccurred; + allTogether[4] = dateTimesReported; + allTogether[5] = incidentAddrLine1s; + allTogether[6] = incidentAddrLine2s; + allTogether[7] = incidentCities; + allTogether[8] = incidentStates; + allTogether[9] = incidentZipCodes; + allTogether[10] = incidentJurisdictions; + allTogether[11] = lostOrStolenList; + allTogether[12] = evidenceList; + allTogether[13] = additionalDescriptions; + + return allTogether; + + + } catch (SQLException e) { + System.out.println("Error - exception"); + System.out.println(e.toString()); } + return null; + } +} diff --git a/hello-view.fxml b/hello-view.fxml index 70e3eb4..473a04e 100644 --- a/hello-view.fxml +++ b/hello-view.fxml @@ -4,7 +4,7 @@ - + @@ -43,8 +43,8 @@