Beispiel #1
0
  /**
   * 修改
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  public ActionForward ok(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    DynaActionForm dForm = (DynaActionForm) form;
    ActionMessages error = new ActionMessages(); // 建立共用錯誤訊息
    ActionMessages msg = new ActionMessages();
    CourseManager manager = (CourseManager) getBean("courseManager");

    String no[] = dForm.getStrings("no");
    String sname[] = dForm.getStrings("sname");
    String school_name[] = dForm.getStrings("school_name");
    String fname[] = dForm.getStrings("fname");
    String dname[] = dForm.getStrings("dname");
    String engname[] = dForm.getStrings("engname");
    String Oid[] = dForm.getStrings("Oid");
    String editCheck[] = dForm.getStrings("editCheck");

    Member me = getUserCredential(request.getSession(false)).getMember();
    for (int i = 1; i < Oid.length; i++) {
      // System.out.println("editCheck["+i+"]="+editCheck[i]);
      if (!editCheck[i].equals("")) {

        if (!no[i].equals("")) {

          Dept dept = (Dept) manager.hqlGetBy("FROM Dept WHERE Oid='" + Oid[i] + "'").get(0);
          dept.setDname(dname[i]);
          dept.setEngname(engname[i]);
          dept.setFname(fname[i]);
          dept.setLastEditUser(me.getIdno());
          dept.setNo(no[i]);
          dept.setSchoolName(school_name[i]);
          dept.setLastEditTime(new Date());
          dept.setSname(sname[i]);

          try {
            manager.updateObject(dept);
          } catch (Exception e) {
            e.printStackTrace();
            error.add(
                ActionErrors.GLOBAL_MESSAGE,
                new ActionError("Course.messageN1", dept.getFname() + "修改失敗"));
          }
        }
      }
    }

    if (!error.isEmpty()) {
      saveErrors(request, error);
      return unspecified(mapping, form, request, response);
    } else {
      // msg.add(ActionErrors.GLOBAL_MESSAGE, new ActionMessage("Course.messageN1", "修改完成"));
      saveMessages(request, msg);
    }
    return unspecified(mapping, form, request, response);
  }
Beispiel #2
0
  /**
   * 新增
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  public ActionForward create(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    // HttpSession session = request.getSession(false);
    DynaActionForm dForm = (DynaActionForm) form;
    ActionMessages error = new ActionMessages(); // 建立共用錯誤訊息
    ActionMessages msg = new ActionMessages();
    CourseManager manager = (CourseManager) getBean("courseManager");

    String no[] = dForm.getStrings("no");
    String sname[] = dForm.getStrings("sname");
    String school_name[] = dForm.getStrings("school_name");
    String fname[] = dForm.getStrings("fname");
    String dname[] = dForm.getStrings("dname");
    String engname[] = dForm.getStrings("engname");

    if (no[0].equals("") || school_name[0].equals("") || fname[0].equals("")) {

      error.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("Course.messageN1", "某些必要欄位不得空白"));
      saveErrors(request, error);
      return mapping.findForward("Main");
    }
    Member me = getUserCredential(request.getSession(false)).getMember();
    Dept dept = new Dept();
    dept.setDname(dname[0]);
    dept.setEngname(engname[0]);
    dept.setFname(fname[0]);
    dept.setLastEditUser(me.getIdno());
    dept.setNo(no[0]);
    dept.setSchoolName(school_name[0]);
    dept.setLastEditTime(new Date());
    dept.setSname(sname[0]);

    try {
      manager.updateObject(dept);
    } catch (Exception e) {
      e.printStackTrace();
      error.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("Course.messageN1", "儲存失敗"));
      saveErrors(request, error);
      return mapping.findForward("Main");
    }

    return unspecified(mapping, form, request, response);
  }