コード例 #1
0
  private void addgoalinfoActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_addgoalinfoActionPerformed
    // TODO add your handling code here:
    String[] types = {"Product", "Project"};
    JComboBox typeList = new JComboBox(types);
    typeList.setSelectedIndex(0);
    JTextArea description = new JTextArea();
    description.setRows(5);
    description.setColumns(10);
    description.setLineWrap(true);
    JScrollPane pane = new JScrollPane(description);
    Object[] message = {
      "Goal type:", typeList,
      "Goal Description:", pane,
    };
    int option =
        JOptionPane.showConfirmDialog(
            this, message, "Enter Goal Information", JOptionPane.OK_CANCEL_OPTION);

    if (option == JOptionPane.OK_OPTION) {
      Goal goal = new Goal();
      goal.setGoalDesc(description.getText());
      goal.setGoalType(typeList.getSelectedItem().toString());
      currentProject.getGoals().add(goal);
      goalmodel.addElement(typeList.getSelectedItem().toString() + " " + description.getText());
      goallist.setModel(goalmodel);
    }
  } // GEN-LAST:event_addgoalinfoActionPerformed
コード例 #2
0
  private void saveActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_saveActionPerformed
    // TODO add your handling code here:
    currentProject.setProjectName(projectname.getText());
    currentProject.setProjectDescription(projectdescription.getText());
    try {

      File file = new File("projects.txt");

      // if file doesnt exists, then create it
      if (!file.exists()) {
        file.createNewFile();
      }

      // true = append file
      FileWriter fileWritter = new FileWriter(file.getName(), true);
      BufferedWriter bufferWritter = new BufferedWriter(fileWritter);

      bufferWritter.write(
          currentProject.getProjectID()
              + " "
              + currentProject.getProjectName()
              + " "
              + currentProject.getProjectDescription());

      for (int i = 0; i < currentProject.getRequirements().size(); i++) {
        bufferWritter.write(
            currentProject.getRequirements().get(i).getRequirementID()
                + " "
                + currentProject.getRequirements().get(i).getRequirementDescription());
        if (currentProject.getRequirements().get(i).getIsFunctionalRequirement() == false) {
          bufferWritter.write(" non-functional");
        } else bufferWritter.write(" functional");
      }

      for (int i = 0; i < currentProject.getTeamMembers().size(); i++) {
        bufferWritter.write(
            currentProject.getTeamMembers().get(i).getPersonID()
                + " "
                + currentProject.getTeamMembers().get(i).getFirstName()
                + " "
                + currentProject.getTeamMembers().get(i).getLastName()
                + "  "
                + currentProject.getTeamMembers().get(i).getPosition());
      }

      for (int i = 0; i < currentProject.getEfforts().size(); i++) {
        bufferWritter.write(
            currentProject.getEfforts().get(i).getEffortID()
                + " "
                + currentProject.getEfforts().get(i).getRequirementID()
                + " "
                + currentProject.getEfforts().get(i).getEffortDevPhase()
                + " "
                + currentProject.getEfforts().get(i).getEffortDate()
                + " "
                + currentProject.getEfforts().get(i).getEffortHours());
      }

      for (int i = 0; i < currentProject.getGoals().size(); i++) {
        bufferWritter.write(
            currentProject.getGoals().get(i).getGoalID()
                + " "
                + currentProject.getGoals().get(i).getGoalType()
                + " "
                + currentProject.getGoals().get(i).getGoalDesc());
      }

      for (int i = 0; i < currentProject.getRisks().size(); i++) {
        bufferWritter.write(
            currentProject.getRisks().get(i).getRiskID()
                + " "
                + currentProject.getRisks().get(i).getRiskName()
                + " "
                + currentProject.getRisks().get(i).getRiskStatus());
      }
      bufferWritter.close();

    } catch (IOException e) {
      JOptionPane.showMessageDialog(this, "Couldn't save", "Didn't work", INFORMATION_MESSAGE);
    }
    JOptionPane.showMessageDialog(
        this, "Project Successfully saved", "Success", INFORMATION_MESSAGE);

    try {
      Class.forName("com.mysql.jdbc.Driver");
      Connection con =
          DriverManager.getConnection(
              "jdbc:mysql://127.0.0.1:3306/projectmanagementsystem?zeroDateTimeBehavior=convertToNull",
              "root",
              "password");

      String query = "insert into project(projectname, projectdesc) values (?, ?)";
      PreparedStatement pst = con.prepareStatement(query);
      pst.setString(1, currentProject.getProjectName());
      pst.setString(2, currentProject.getProjectDescription());
      pst.executeUpdate();

      String query2 = "select idproject from project where projectdesc = ?";
      PreparedStatement pst2 = con.prepareStatement(query2);
      String desc = currentProject.getProjectDescription();
      pst2.setString(1, desc);
      ResultSet rs = pst2.executeQuery();
      int id = 0;
      if (rs.next()) {
        id = rs.getInt("idproject");
      }
      System.out.println(id);

      for (int i = 0; i < currentProject.getTeamMembers().size(); i++) {
        String query3 =
            "insert into teammember(firstname,lastname,position,teammember_FK) values (?,?,?,?)";
        PreparedStatement pst3 = con.prepareStatement(query3);
        pst3.setString(1, currentProject.getTeamMembers().get(i).getFirstName());
        pst3.setString(2, currentProject.getTeamMembers().get(i).getLastName());
        pst3.setString(3, currentProject.getTeamMembers().get(i).getPosition());
        pst3.setInt(4, id);
        pst3.executeUpdate();
      }

      for (int i = 0; i < currentProject.getGoals().size(); i++) {
        String query3 = "insert into goal(goaldesc,goaltype,goal_FK) values (?,?,?)";
        PreparedStatement pst3 = con.prepareStatement(query3);
        pst3.setString(1, currentProject.getGoals().get(i).getGoalDesc());
        pst3.setString(2, currentProject.getGoals().get(i).getGoalType());
        pst3.setInt(3, id);
        pst3.executeUpdate();
      }

      for (int i = 0; i < currentProject.getRequirements().size(); i++) {
        int functional = 0;
        if (currentProject.getRequirements().get(i).getIsFunctionalRequirement() == true) {
          functional = 1;
        }

        String query3 =
            "insert into requirement(isFunctionalRequirement,requirementdesc,requirement_FK) values (?,?,?)";
        PreparedStatement pst3 = con.prepareStatement(query3);
        pst3.setInt(1, functional);
        pst3.setString(2, currentProject.getRequirements().get(i).getRequirementDescription());
        pst3.setInt(3, id);
        pst3.executeUpdate();
      }

      for (int i = 0; i < currentProject.getRisks().size(); i++) {
        String query3 = "insert into risk(riskname,riskstatus,risk_FK) values (?,?,?)";
        PreparedStatement pst3 = con.prepareStatement(query3);
        pst3.setString(1, currentProject.getRisks().get(i).getRiskName());
        pst3.setString(2, currentProject.getRisks().get(i).getRiskStatus());
        pst3.setInt(3, id);
        pst3.executeUpdate();
      }

      for (int i = 0; i < currentProject.getEfforts().size(); i++) {
        String query4 = "select idrequirement from requirement where requirementdesc = ?";
        PreparedStatement pst4 = con.prepareStatement(query4);
        String desc2 = currentProject.getEfforts().get(i).getRequirementDesc();
        pst4.setString(1, desc2);
        ResultSet rs2 = pst4.executeQuery();
        int reqid = 0;
        if (rs.next()) {
          reqid = rs2.getInt("idrequirement");
        }
        System.out.println(reqid);

        String query3 =
            "insert into effort(effortdate,efforthours,effortdevphase,effort_FK) values (?,?,?,?)";
        PreparedStatement pst3 = con.prepareStatement(query3);
        pst3.setString(1, currentProject.getEfforts().get(i).getEffortDate());
        pst3.setInt(2, currentProject.getEfforts().get(i).getEffortHours());
        pst3.setString(3, currentProject.getEfforts().get(i).getEffortDevPhase());
        pst3.setInt(4, reqid);
        pst3.executeUpdate();
      }
    } catch (Exception e) {
      System.out.println(e.toString());
    }
  } // GEN-LAST:event_saveActionPerformed