private void addeffortActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_addeffortActionPerformed // TODO add your handling code here: if (requirementmodel.isEmpty()) { JOptionPane.showMessageDialog( this, "You must create a requirement before entering efforts", "First create requirement", INFORMATION_MESSAGE); return; } String[] phases = { "Project Management", "Requirements Analysis", "Design", "Coding", "Testing" }; JComboBox typeList = new JComboBox(phases); typeList.setSelectedIndex(0); List<String> reqs = new ArrayList(); for (int i = 0; i < currentProject.getRequirements().size(); i++) { reqs.add(currentProject.getRequirements().get(i).getRequirementDescription()); } JComboBox reqList = new JComboBox(reqs.toArray()); JTextField date = new JTextField(); JTextField hours = new JTextField(); Object[] message = { "For requirement:", reqList, "During SDLC Phase:", typeList, "On Date:", date, "Hours:", hours, }; int option = JOptionPane.showConfirmDialog( this, message, "Enter Effort Information", JOptionPane.OK_CANCEL_OPTION); if (option == JOptionPane.OK_OPTION) { Effort effort = new Effort(); effort.setEffortDate(date.getText()); effort.setEffortDevPhase(typeList.getSelectedItem().toString()); effort.setEffortHours(Integer.parseInt(hours.getText())); // effort.setRequirementID(reqList.getSelectedIndex()); for (int i = 0; i < currentProject.getRequirements().size(); i++) { if (currentProject .getRequirements() .get(i) .getRequirementDescription() .equals(reqList.getSelectedItem().toString())) { effort.setRequirementID(i); effort.setRequirementDesc( currentProject.getRequirements().get(i).getRequirementDescription()); } } currentProject.getEfforts().add(effort); effortmodel.addElement( "For req:" + " " + reqList.getSelectedItem() + " " + typeList.getSelectedItem() + " " + date.getText() + hours.getText()); effortlist.setModel(effortmodel); } } // GEN-LAST:event_addeffortActionPerformed
public ViewProject(int id) { initComponents(); currentProject = new Project(); currentProject.setProjectID(id); try { Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection( "jdbc:mysql://127.0.0.1:3306/projectmanagementsystem?zeroDateTimeBehavior=convertToNull", "root", "password"); String query2 = "select * from project where idproject = ?"; PreparedStatement pst2 = con.prepareStatement(query2); int projectid = id + 1; pst2.setInt(1, projectid); ResultSet rs = pst2.executeQuery(); if (rs.next()) { projectname.setText(rs.getString("projectname")); projectdescription.setText(rs.getString("projectdesc")); } String query3 = "select * from teammember where teammember_FK = ?"; PreparedStatement pst3 = con.prepareStatement(query3); pst3.setInt(1, projectid); ResultSet rs2 = pst3.executeQuery(); while (rs2.next()) { Person p = new Person(); p.setFirstName(rs2.getString("firstname")); p.setLastName(rs2.getString("lastname")); p.setPosition(rs2.getString("position")); p.setPersonID(rs2.getInt("idteammember")); teammembers.add(p); teammodel.addElement(p.getFirstName() + " " + p.getLastName() + " " + p.getPosition()); } teamlist.setModel(teammodel); String query4 = "select * from goal where goal_FK = ?"; PreparedStatement pst4 = con.prepareStatement(query4); pst4.setInt(1, projectid); ResultSet rs3 = pst4.executeQuery(); while (rs3.next()) { Goal g = new Goal(); g.setGoalID(rs3.getInt("idgoal")); g.setGoalDesc(rs3.getString("goaldesc")); g.setGoalType(rs3.getString("goaltype")); goals.add(g); goalmodel.addElement(g.getGoalType() + " " + g.getGoalDesc()); } goallist.setModel(goalmodel); String query5 = "select * from requirement where requirement_FK = ?"; PreparedStatement pst5 = con.prepareStatement(query5); pst5.setInt(1, projectid); ResultSet rs4 = pst5.executeQuery(); while (rs4.next()) { Requirement r = new Requirement(); String type; r.setRequirementID(rs4.getInt("idrequirement")); r.setRequirementDescription(rs4.getString("requirementdesc")); if (rs4.getInt("isFunctionalRequirement") == 0) { r.setIsFunctionalRequirement(false); type = "Non-functional"; } else type = "Functional"; requirements.add(r); requirementmodel.addElement(type + " " + r.getRequirementDescription()); } requirementlist.setModel(requirementmodel); String query6 = "select * from risk where risk_FK = ?"; PreparedStatement pst6 = con.prepareStatement(query6); pst6.setInt(1, projectid); ResultSet rs5 = pst6.executeQuery(); while (rs5.next()) { Risk r = new Risk(); r.setRiskID(rs5.getInt("idrisk")); r.setRiskName(rs5.getString("riskname")); r.setRiskStatus(rs5.getString("riskstatus")); risks.add(r); riskmodel.addElement(r.getRiskStatus() + " " + r.getRiskName()); } risklist.setModel(riskmodel); String query7 = "select * from effort join requirement on effort.effort_FK = requirement.idrequirement" + " where requirement.requirement_FK = ?"; PreparedStatement pst7 = con.prepareStatement(query7); pst7.setInt(1, projectid); ResultSet rs6 = pst7.executeQuery(); while (rs6.next()) { Effort e = new Effort(); e.setEffortID(rs6.getInt("ideffort")); e.setEffortDate(rs6.getString("effortdate")); e.setEffortDevPhase(rs6.getString("effortdevphase")); e.setEffortHours(rs6.getInt("efforthours")); e.setRequirementID(rs6.getInt("effort_FK")); e.setRequirementDesc(rs6.getString("requirementdesc")); efforts.add(e); effortmodel.addElement( "For req: " + e.getRequirementDesc() + " " + e.getEffortDevPhase() + " " + e.getEffortDate() + " " + e.getEffortHours()); } effortlist.setModel(effortmodel); } catch (Exception e) { System.out.println(e.toString()); } }