?? accountaction.java
字號:
package com.action;
import org.apache.struts.action.*;
import java.io.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.sql.SQLException;
import com.bean.ClientTable;
import com.bean.CompUser;
import com.bean.StorehouseManager;
import com.dao.ClientTableDAO;
import com.dao.CompUserDAO;
import com.dao.AcountTableDAO;
import com.dao.AcountGroupDAO;
import com.dao.StorehouseManagerDAO;
import com.tool.pagetool.*;
import com.tool.QueryStrCreator;
import com.tool.LogTableWriter;
import com.bean.AcountTable;
import com.dao.RoleUrlDAO;
import com.dao.UrlAccountDAO;
import com.bean.UrlGroup;
import com.bean.RoleGroup;
import com.dao.RoleGroupDAO;
import com.dao.UrlGroupDAO;
import com.bean.UrlAccount;
import com.bean.AccountAndGroup;
import com.bean.AcountGroup;
import com.bean.StorehouseShmanagerView;
import com.dao.StorehouseShmanagerViewDAO;
public class AccountAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
request.setCharacterEncoding("gb2312");
response.setContentType("text/html;charset=gb2312");
String target = "";
String flag = request.getParameter("flag");
String type = request.getParameter("type");
ActionErrors actionErrors = new ActionErrors();
if (flag == null) flag = "";
if (flag.equals("add")) { //添加賬號
try {
String accountName = request.getParameter("account");
String pwd = request.getParameter("pwd");
String typeFlag = request.getParameter("type");
String idStr = request.getParameter("id");
int lastId = AcountTableDAO.getLastId() + 1;
int id = 0;
//判斷賬號名是否存在
boolean isHasFlag = AcountTableDAO.selectIsHasAccountName(
accountName);
if (isHasFlag) {
AcountTableDAO.rollback();
ActionError actionError = new ActionError(
"errors.generally.failed", "賬號已存在");
actionErrors.add("", actionError);
saveErrors(request, actionErrors);
return mapping.findForward("addAccount");
}
AcountTableDAO.startTransation();
AcountTable accountTable = new AcountTable();
accountTable.setAccountName(accountName);
accountTable.setPwd(pwd);
accountTable.setAcountId(lastId);
try {
id = new Integer(idStr).intValue();
} catch (Exception e) {
e.printStackTrace();
AcountTableDAO.rollback();
ActionError actionError = new ActionError(
"errors.generally.failed", e.getMessage());
actionErrors.add("", actionError);
saveErrors(request, actionErrors);
return mapping.findForward("addAccount");
}
byte[] tmpC = type.getBytes("ISO8859-1");
type = new String(tmpC, "gb2312");
if (type.equals("client")) {
accountTable.setClientId(id);
} else if (type.equals("compUser")) {
accountTable.setCompUserId(id);
} else if (type.equals("shm")) {
accountTable.setShmId(id);
}
AcountTableDAO.insertAcountTable(accountTable);
AcountTableDAO.commit();
ActionError actionError = new ActionError(
"errors.addSuccese");
actionErrors.add("addClientSuccese", actionError);
saveErrors(request, actionErrors);
} catch (Exception e) {
e.printStackTrace();
AcountTableDAO.rollback();
ActionError actionError = new ActionError(
"errors.generally.failed", e.getMessage());
actionErrors.add("", actionError);
saveErrors(request, actionErrors);
}
target = "addAccount";
} else if (type != null && flag.equals("")) { //打開導入信息窗口
byte[] tmpC = type.getBytes("ISO8859-1");
type = new String(tmpC, "gb2312");
if (type.equals("client")) {
target = "importClientForAddAccount";
return mapping.findForward(target);
} else if (type.equals("shm")) {
target = "importShM";
return mapping.findForward(target);
} else if (type.equals("compUser")) {
target = "importCompUserForAddAccount";
return mapping.findForward(target);
}
} else if (flag.equals("showForSetRole")) { //列賬號信息,待設置權限
initPage(request); //初始化分頁數據并放于request中
target = "setAccountRole";
} else if (flag.equals("gotoSetRole")) { //跳轉到當前賬號的權限設置界面
String acountIdStr = request.getParameter("acountId");
int acountId = -1;
try {
acountId = new Integer(acountIdStr).intValue();
List allRole = RoleUrlDAO.selectAllRoleUrl(); //查出所有權限
request.setAttribute("allRole", allRole);
List theAcountRole = UrlAccountDAO.selectRoleByAccountId(
acountId); //查出當前賬號的權限,不包括組中的權限
AcountTable acount = AcountTableDAO.selectAcountTableByacountId(
acountId); //當前賬號的基本信息
request.setAttribute("allRole", allRole);
request.setAttribute("theAcountRole", theAcountRole);
request.setAttribute("acount", acount);
target = "setAccountRoleItem";
} catch (Exception e) {
e.printStackTrace();
target = "";
}
} else if (flag.equals("setRole")) {//執行設置權限
String[] urlIdArray = request.getParameterValues("checkbox");
String acountIdStr = request.getParameter("acountId");
if (acountIdStr == null)return mapping.findForward(
"");
try {
UrlAccountDAO.startTransation();
int lastId = UrlAccountDAO.getLastId();
int acountId = new Integer(acountIdStr).intValue();
if (urlIdArray == null) { //刪除賬號自已的所有權限
UrlAccountDAO.deleteUrlAccountByurlAccountId(acountId);
} else {
UrlAccountDAO.deleteUrlAccountByurlAccountId(acountId); //先刪除再添加
int urlId = -1;
for (int i = 0; i < urlIdArray.length; i++) {
urlId = new Integer(urlIdArray[i]).intValue();
UrlAccount urlAccount = new UrlAccount();
urlAccount.setDelFlag(0);
urlAccount.setAccountId(acountId);
urlAccount.setUrlAccountId(lastId + i + 1);
urlAccount.setUrlId(urlId);
UrlAccountDAO.insertUrlAccount(urlAccount);
}
}
UrlAccountDAO.commit();
ActionError actionError = new ActionError(
"errors.generally.succese");
actionErrors.add("addGroupSuccese", actionError);
saveErrors(request, actionErrors);
List allRole = RoleUrlDAO.selectAllRoleUrl(); //查出所有權限
request.setAttribute("allRole", allRole);
List theAcountRole = UrlAccountDAO.selectRoleByAccountId(
acountId); //查出當前賬號的權限,不包括組中的權限
AcountTable acount = AcountTableDAO.selectAcountTableByacountId(
acountId); //當前賬號的基本信息
request.setAttribute("allRole", allRole);
request.setAttribute("theAcountRole", theAcountRole);
request.setAttribute("acount", acount);
} catch (Exception e) {
e.printStackTrace();
UrlGroupDAO.rollback();
ActionError actionError = new ActionError(
"errors.generally.failed", e.getMessage());
actionErrors.add("addClientSuccese", actionError);
saveErrors(request, actionErrors);
}
target = "setAccountRoleItem";
} else if (flag.equals("addAcountToTeam") || flag.equals("forAddAcount")) {
initPage(request);
String groupIdStr = request.getParameter("groupId");
try {
int groupId = new Integer(groupIdStr).intValue();
RoleGroup roleGroup = RoleGroupDAO.selectRoleGroupBygroupId(
groupId);
request.setAttribute("roleGroup", roleGroup);
target = "forTeamAAcount";
} catch (Exception e) {
e.printStackTrace();
target = "";
}
} else if (flag.equals("showAcountDetail")) {
String acountIdStr = request.getParameter("acountId");
int acountId = -1;
try {
acountId = Integer.parseInt(acountIdStr);
AccountAndGroup acountAndGroup = AcountTableDAO.
selectAcountAndGroupByAcountId(
acountId);
// System.out.println("acount.getAcountName()="+acountAndGroup.getAccountName());
request.setAttribute("acountAndGroup", acountAndGroup);
if (acountAndGroup.getClientId() > 0) {
ClientTable client = ClientTableDAO.
selectClientTableByclientId(
acountAndGroup.getClientId());
request.setAttribute("client", client);
target = "showAcountClient";
} else if (acountAndGroup.getCompUserId() > 0) {
CompUser compUser = CompUserDAO.selectCompUserBycompUserId(
acountAndGroup.getCompUserId());
request.setAttribute("compUser", compUser);
target = "showAcountCompUser";
} else if (acountAndGroup.getShmId() > 0) {
StorehouseShmanagerView shManager =
StorehouseShmanagerViewDAO.
selectStorehouseShmanagerViewByshmId(acountAndGroup.
getShmId());
request.setAttribute("shManager", shManager);
target = "showAcountSHM";
} else {
target = "";
}
} catch (Exception e) {
e.printStackTrace();
}
} else if (flag.equals("gotoEditAcount")) { //跳轉到編輯賬號
initPage(request);
List allRoleGroup = RoleGroupDAO.selectAllRoleGroup();
request.setAttribute("allRoleGroup", allRoleGroup);
target = "editAccount";
} else if (flag.equals("getToOther")) { //將所選賬號移到所選取組
String[] acountIdAndAcountGroupId = request.getParameterValues(
"checkbox"); //checkbox中的值的格式為:"acountId||acountGroupId"
String groupIdStr = request.getParameter("groupId2");
if (acountIdAndAcountGroupId == null || groupIdStr == null)return
mapping.findForward("");
int groupId = -1;
try {
groupId = Integer.parseInt(groupIdStr);
for (int i = 0; i < acountIdAndAcountGroupId.length; i++) {
String accountGroupIdStr = acountIdAndAcountGroupId[i].
substring(
acountIdAndAcountGroupId[i].indexOf("||") + 2);
AcountGroup acountGroup = new AcountGroup();
acountGroup.setGroupId(groupId);
acountGroup.setSelfId(Integer.parseInt(accountGroupIdStr));
int tmpUpdateCount = AcountGroupDAO.
updateGroupIdByAcountGroupId(
acountGroup);
if (tmpUpdateCount == 0) {
String accountIdStr = acountIdAndAcountGroupId[i].
substring(
0, acountIdAndAcountGroupId[i].indexOf("||"));
int lastId = AcountGroupDAO.getLastId();
acountGroup.setSelfId(lastId + 1);
acountGroup.setAcountId(Integer.parseInt(accountIdStr));
AcountGroupDAO.insertAcountGroup(acountGroup);
}
}
ActionError actionError = new ActionError(
"errors.generally.succese");
actionErrors.add("addGroupSuccese", actionError);
saveErrors(request, actionErrors);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -