@Override
  public void dataBind() {
    tableComponent.setParentModel(department);

    tableComponent.setModel(department.getDivisions());

    tableComponent.dataBind();

    if (getModel() != null) tableComponent.setSelectedValue(getModel().getBean());
  }
示例#2
0
  public void departTest() {
    Department department1 = depDAO.getDepartment(1);
    Department department2 = depDAO.getDepartment(2);
    Department department3 = depDAO.getDepartment(3);
    Worker worker1 = new Worker("jaku", 18);
    worker1.setWorkerPassword("111111");
    worker1.setDepartment(department1);
    worker1.setWorkerLevel(1);

    Worker worker2 = new Worker("balen", 28);
    worker2.setWorkerPassword("111111");
    worker2.setDepartment(department2);
    worker2.setWorkerLevel(2);

    Worker worker3 = new Worker("admin", 38);
    worker3.setWorkerPassword("111111");
    worker3.setDepartment(department3);
    worker3.setWorkerLevel(3);

    department1.addWorker(worker1);
    department2.addWorker(worker2);
    department3.addWorker(worker3);
    depDAO.saveDepart(department1);
    depDAO.saveDepart(department2);
    depDAO.saveDepart(department3);
  }
  /*
   * Add a new record to the Organization table,
   * creates an admin account when SA creates a new consulting company
   * @param OrganizationCode (based on Company Name)
   * @param OrganizationName (based on Company Description)
   * @param FKCompanyID
   * @param NameSequence
   * @param PKUser
   * @param nomRater
   * @throws SQLException
   * @throws Exception
   * @author: Mark Oei
   * @since v.1.3.12.63 09 Mar 2010
   */
  public boolean addOrganisationByCons(
      String OrganizationCode,
      String OrganizationName,
      int FKCompanyID,
      int NameSequence,
      int PKUser,
      String nomRater)
      throws SQLException, Exception {
    Connection con = null;
    Statement st = null;

    boolean bIsAdded = false;

    String sql =
        "INSERT INTO tblOrganization (OrganizationCode, OrganizationName, FKCompanyID, NameSequence, NominationModule)";
    sql =
        sql
            + " VALUES ('"
            + OrganizationCode
            + "', '"
            + OrganizationName
            + "', "
            + FKCompanyID
            + ", "
            + NameSequence
            + ", '"
            + Boolean.parseBoolean(nomRater)
            + "')";
    try {
      con = ConnectionBean.getConnection();
      st = con.createStatement();
      int iSuccess = st.executeUpdate(sql);
      System.out.println(iSuccess);
      if (iSuccess != 0) bIsAdded = true;
    } catch (Exception E) {
      System.err.println("Organization.java - AddRecord - " + E);
    } finally {
      ConnectionBean.closeStmt(st); // Close statement
      ConnectionBean.close(con); // Close connection
    }

    System.out.println("1. Add Organization");

    // add default under the organization.
    String defaultName = "NA";
    int FKOrganization = checkOrgExist(OrganizationCode, OrganizationName, FKCompanyID);
    // Change to disable print statement. Used for debugging only
    // Mark Oei 19 Mar 2010
    // System.out.println("testing " + FKOrganization);
    System.out.println("2. Check Organization Exist");
    if (FKOrganization != 0) {
      // Add Division
      div.addRecord(defaultName, FKOrganization, PKUser);
      System.out.println("3. Add Division");
      // Add Department
      dept.addRecord(defaultName, FKOrganization, PKUser);
      System.out.println("4. Add Department");
      // Add Group
      G.addRecord(defaultName, FKOrganization, PKUser);
      System.out.println("5. Add Group");
      // Check whether exists
      int FKDivision = div.checkDivExist(defaultName, FKOrganization);
      int FKDepartment = dept.checkDeptExist(defaultName, FKOrganization);
      int FKGroup = G.checkGroupExist(defaultName, FKOrganization);
      // Create links
      dept.linkDepartment(FKDivision, FKDepartment);
      G.linkGroup(FKDepartment, FKGroup);
      // Establish new admin account and password
      Date timeStamp = new java.util.Date();
      SimpleDateFormat dFormat = new SimpleDateFormat("ddMMyyHHmmss");
      String temp = dFormat.format(timeStamp);
      String loginName = OrganizationCode + "admin";
      String password = OrganizationCode + temp;
      int userType = 6;
      // Insert record into database
      U.addRecord(
          FKDepartment,
          FKDivision,
          userType,
          "Admin",
          "Admin",
          loginName,
          "NA",
          "NA",
          FKGroup,
          password,
          1,
          FKCompanyID,
          FKOrganization,
          "NA",
          PKUser);

      System.out.println("6. Add User");
      int userExist =
          U.checkUserExist(
              FKDepartment,
              FKDivision,
              userType,
              "Admin",
              "Admin",
              loginName,
              "NA",
              "NA",
              FKGroup,
              password,
              1,
              FKCompanyID,
              FKOrganization);

      System.out.println(
          "FKDivision = "
              + FKDivision
              + ", FKDepartment = "
              + FKDepartment
              + ", FKGroup = "
              + FKGroup
              + " and User Exist = "
              + userExist);

      if (userExist != 0) {
        try {
          U.insertRelation(userExist, userExist, 0);
        } catch (SQLException SE) {
          System.out.println(SE.getMessage());
        }
        // Send email notification
        String content = template.ForgotPass_temp(loginName, password);
        String email = "*****@*****.**";
        // Edited By Roger 13 June 2008
        Email.sendMail(
            server.getAdminEmail(),
            email,
            "New Admin Assignment for " + OrganizationName,
            content,
            FKOrganization);
      }

      System.out.println("8. Add User Relation");
    }

    sDetail = detail.getUserDetail(PKUser);
    ev.addRecord("Insert", itemName, OrganizationName, sDetail[2], sDetail[11], sDetail[10]);

    return bIsAdded;
  } // End Method for addOrganisationByCons