package zr.zrpower.web.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import zr.zrpower.web.bean.MessageBox;
import zr.zrpower.ejb.sys.UserService;

public class ActionUser
    extends MessageBox {
  private static final String CONTENT_TYPE = "text/html; charset=GBK";

  //Initialize global variables
  public void init() throws ServletException {
  }

  //Process the HTTP Get request
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws
      ServletException, IOException {
    response.setContentType(CONTENT_TYPE);
    String strAct = request.getParameter("Act");
    String strUserID= request.getParameter("userid");
    String strUnitID = request.getParameter("unitid");
    try {
      UserService userMgr = new UserService();
      if (strAct != null) {
        if (strAct.equals("repw")) {
          String strPw = request.getParameter("loginid");
          isOk = userMgr.ResetPassword1(strUserID, strPw);
          if (isOk) {
               Msg = "密码已重置成功！";
          }
        }
        if (strAct.equals("stop")) {
          isOk = userMgr.StopUser(strUserID);
          if (isOk) {
            Msg = "用户编号为［" + strUserID + "］的用户已被停用！";
          }
        }
        if (strAct.equals("unstop")) {
          isOk = userMgr.unStopUser(strUserID);
          if (isOk) {
            Msg = "用户编号为［" + strUserID + "］的用户停用状态已被解除！";
          }
        }
      }
      if (strUnitID != null) {
        response.sendRedirect("zrsysmanage/UserList.jsp?nodeId=" + strUnitID);
      }
      else {
        response.sendRedirect("individual/modifyPW.jsp");
      }
      userMgr = null;
    }
    catch (Exception ex) {
      Msg = "请求失败，未能连接到中间件服务器！\n详细错误信息：\n"+ex.toString();
    }
    this.out = response.getWriter();
    //this.GetBox();

  }

  //Process the HTTP Post request
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws
      ServletException, IOException {
    doGet(request, response);
  }

  //Clean up resources
  public void destroy() {
  }
}
