public String generateUserInsertQuery(Staff staff) {

    StringBuffer strQuery = new StringBuffer(INSERT_USER_QUERY);
    strQuery.append(staff.getF_name());
    strQuery.append("', '");
    strQuery.append(staff.getL_name());
    strQuery.append("', '");
    strQuery.append(staff.getPassword());
    strQuery.append("', '");
    strQuery.append(staff.getEmail());
    strQuery.append("', '");
    strQuery.append(staff.getAddress());
    strQuery.append("', '");
    strQuery.append(staff.getCity());
    strQuery.append("', '");
    strQuery.append(staff.getState());
    strQuery.append("', '");
    strQuery.append(staff.getZipcode());
    strQuery.append("', '");
    strQuery.append(utility.convertStringToDate(staff.getDob()));
    strQuery.append("', '");
    strQuery.append(staff.getType());
    strQuery.append("')");

    System.out.println("Insert User query : " + strQuery.toString());

    return strQuery.toString();
  }
Ejemplo n.º 2
0
 @Override
 public String execute(HttpServletRequest request, HttpServletResponse response) {
   String login = request.getParameter("name");
   String password = request.getParameter("password");
   Authorization au = new Authorization();
   au.setLogin(login);
   au.setPassword(password);
   DaoFactory factory = DaoFactory.getDaoFactory();
   AuthorizationDao udao = factory.getAuthorizationDao();
   StaffDao sdao = factory.getStaffDao();
   DepartmentDao ddao = factory.getDepartmentDao();
   PatientDao pdao = factory.getPatientDao();
   if (udao.isAuthorization(au)) {
     HttpSession session = request.getSession(true);
     Authorization forSession = udao.readByLogin(login);
     Staff forAccess = sdao.readById(forSession.getStaff());
     String fa = forAccess.getSpecialization();
     session.setAttribute("access", fa);
     if (session.getAttribute("access").equals("admin")) {
       List<Department> departments = ddao.getAllDepartments();
       request.setAttribute("departments", departments);
       return "/views/adminUserInformation.jsp";
     } else if (session.getAttribute("access").equals("doctor")) {
       return "/views/doctorStartPage.html";
     } else if (session.getAttribute("access").equals("nurse")) {
       List<Patient> patients = pdao.getAllPatients();
       request.setAttribute("patients", patients);
       return "/views/nurseStart.jsp";
     } else {
       return "/views/test.html";
     }
   } else {
     return "../index.html";
   }
 }
  public void insertIntoStaffTable(int user_id, Staff staff) {

    StringBuffer strQuery = new StringBuffer(INSERT_STAFF_QUERY);
    strQuery.append(user_id);
    strQuery.append("', '");
    strQuery.append(staff.getStaff_ssn());
    strQuery.append("', '");
    strQuery.append(staff.getWork_desc());
    strQuery.append("', '");
    strQuery.append(staff.getPosition());
    strQuery.append("', '");
    strQuery.append(utility.convertStringToDate(staff.getHire_date()));
    strQuery.append("')");
    System.out.println("Insert Staff query : " + strQuery.toString());

    try {
      DBOperation.executeQuery(strQuery.toString());
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  public StaffMessageBean addStaff(Staff staff) {
    StaffMessageBean staffMessageBean = new StaffMessageBean();
    String insertUserQuery = generateUserInsertQuery(staff);
    try {
      // insert into User Table
      int user_id = dbOperation.executeUpdateQuery(insertUserQuery);
      System.out.println("User Id of newly added staff:: " + user_id);
      // insert into Staff Table
      insertIntoStaffTable(user_id, staff);
      // Set the return values
      staffMessageBean.setUser_id(user_id);
      staffMessageBean.setStaff(staff);
      staffMessageBean.setMessage(
          "New Staff " + staff.getF_name() + " " + staff.getL_name() + " Added Successfully");

    } catch (Exception e) {
      // TODO Auto-generated catch block
      staffMessageBean.setMessage("Error in adding New Staff!! ");
      e.printStackTrace();
    }

    return staffMessageBean;
  }
  public static List<Staff> executestaffdetailsQuery(String querystr) throws Exception {

    Connection conn = null;
    Statement stmt = null;
    ResultSet rs;
    List<Staff> staffList = new ArrayList<Staff>();
    try {
      conn = DBOperation.getConnection();
      stmt = conn.createStatement();
      // System.out.println("before execute");
      rs = stmt.executeQuery(querystr);
      // System.out.println("after execute");
      // stmt  = conn.createStatement();
      // rs.absolute(2);
      while (rs.next()) {
        System.out.println("before query");
        Staff staff = new Staff();
        staff.setUser_id(rs.getInt("user_id"));
        System.out.println("after query" + rs.getInt("user_id"));
        staff.setF_name(rs.getString("f_name"));
        staff.setL_name(rs.getString("l_name"));
        staff.setPassword(rs.getString("password"));
        staff.setEmail(rs.getString("email"));
        staff.setAddress(rs.getString("address"));
        staff.setCity(rs.getString("city"));
        staff.setState(rs.getString("state"));
        staff.setZipcode(rs.getString("zipcode"));
        staff.setDob(rs.getString("dob"));
        staff.setStaff_ssn(rs.getInt("staff_ssn"));
        staff.setWork_desc(rs.getString("work_desc"));
        staff.setPosition(rs.getString("position"));
        staff.setHire_date(rs.getString("hire_date"));
        // staff.setWork_desc(rs.getString("work_desc"));

        staffList.add(staff);
      }
    } catch (Exception e) {
      System.out.println("unable to execute customer details query" + querystr);
    }
    System.out.println("List length:: " + staffList.size());
    return staffList;
  }
 private void Fill(Staff s) {
   txtFieldID.setText("" + s.getNumber());
   txtFieldName.setText(s.getName());
   cmbBoxPersonalTypes.setSelectedItem(s.getType());
   txtFieldPrimaryAirport.setText(s.getPrimaryAirport());
 }
  private void btnSaveActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnSaveActionPerformed
    String name = txtFieldName.getText();
    int staffId = -1;
    Staff.PersonalType st = (Staff.PersonalType) cmbBoxPersonalTypes.getSelectedItem();
    String primaryAirport = txtFieldPrimaryAirport.getText();

    String errorMessage = "";
    name.trim();
    if (name.isEmpty()) {
      errorMessage += "Please enter a name first \n";
    }

    if (txtFieldID.getText().isEmpty()) {
      errorMessage += "Please enter a correct staff id first  \n";
    } else {
      try {
        staffId = Integer.parseInt(txtFieldID.getText());
      } catch (NumberFormatException exception) {
        errorMessage += "plane number isn't a number \n";
      }
    }

    if (txtFieldPrimaryAirport.getText().isEmpty()) {
      errorMessage += "Please enter a Primary Airport first  \n";
    } else {
      try {
        primaryAirport = txtFieldPrimaryAirport.getText();
      } catch (NumberFormatException exception) {
        errorMessage += "Primary Airport isn't a number \n";
      }
    }

    if (!errorMessage.isEmpty()) {
      lblErrorMessage.setText(errorMessage);
    } else {
      if (staff == null) {
        staff = new Staff();
        staff.setName(name);
        staff.setNumber(staffId);
        staff.setType(st);
        staff.setPrimaryAirport(primaryAirport);

        if (Controller.Controller.Instance().AddStaff(staff)) {
          JOptionPane.showMessageDialog(this, "Staff " + staff.getName() + " Saved");
          this.dispose();
        }
      } else {
        Staff newStaff = new Staff();
        newStaff.setName(name);
        newStaff.setNumber(staffId);
        newStaff.setType(st);
        newStaff.setPrimaryAirport(primaryAirport);

        if (Controller.Controller.Instance().ChangeStaff(newStaff, staff)) {
          JOptionPane.showMessageDialog(this, "Staff " + staff.getName() + " Saved");
          this.dispose();
        }
      }
      this.dispose();
    }
  } // GEN-LAST:event_btnSaveActionPerformed