⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accountaction.java

📁 hibernate应用测试,初学hibernate 的会员可以看看.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
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 + -