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
  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