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

📄 page1action.java

📁 开源项目CRM之OpenCustomer
💻 JAVA
字号:
/*******************************************************************************
 * ***** BEGIN LICENSE BLOCK Version: MPL 1.1
 * 
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * 
 * The Original Code is the OpenCustomer CRM.
 * 
 * The Initial Developer of the Original Code is Thomas Bader (Bader & Jene
 * Software-Ingenieurb黵o). Portions created by the Initial Developer are
 * Copyright (C) 2005 the Initial Developer. All Rights Reserved.
 * 
 * Contributor(s): Thomas Bader <thomas.bader@bader-jene.de>
 * 
 * ***** END LICENSE BLOCK *****
 */

package org.opencustomer.application.web.module.crm.contact.edit;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessages;
import org.opencustomer.application.db.vo.crm.ContactVO;
import org.opencustomer.application.db.vo.crm.PersonContactVO;
import org.opencustomer.application.db.vo.system.UserVO;
import org.opencustomer.application.web.Globals;
import org.opencustomer.application.web.module.crm.contact.Constants;
import org.opencustomer.util.EnumUtility;
import org.opencustomer.web.util.MessageUtil;

public class Page1Action extends DefaultPageAction<Page1Form>
{
    private static Logger log = Logger.getLogger(Page1Action.class);

    protected static final int STATUS_JUMPCOMPANY = 10;

    protected static final int STATUS_JUMPPERSON = 11;

    protected static final int STATUS_ADDPERSON = 12;

    protected static final int STATUS_DELETEPERSON = 13;

    protected static final int STATUS_ADDOWNPERSON = 14;

    protected static final int STATUS_ADDCOMPANY = 15;

    public ActionForward execute(ActionMapping mapping, Page1Form form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
    {
        if (log.isDebugEnabled())
            log.debug("called action");

        int status = STATUS_DEFAULT;

        ActionMessages errors = new ActionMessages();

        if (this.isTokenValid(request) && (form.getDoSave() != null || form.isAnyPage() || form.getDoAddPerson().isSelected() || form.getDoAddCompany().isSelected() || form.getDoJumpCompany().isSelected() || form.getJumpPersonId() > 0 || form.getDeletePersonId() > 0))
        {
            if (log.isDebugEnabled())
                log.debug("save button pressed");

            ContactVO contact = (ContactVO) request.getSession().getAttribute(Constants.CONTACT_CONTACT);

            contact.setSubject(form.getSubject());
            contact.setContent(form.getContent());
            contact.setContactName(form.getContactName());
            contact.setContactType(EnumUtility.valueOf(ContactVO.ContactType.class, form.getContactType()));
            contact.setBoundType(EnumUtility.valueOf(ContactVO.BoundType.class, form.getBoundType()));

            String formatDate = MessageUtil.message(request, "format.input.date");
            String formatTime = MessageUtil.message(request, "format.input.time");
            SimpleDateFormat sdf = new SimpleDateFormat(formatDate + " '-' " + formatTime);
            try
            {
                contact.setContactTimestamp(sdf.parse(form.getContactDate() + " - " + form.getContactTime()));
            }
            catch (ParseException e)
            {
                log.error("problems parsing contact timestamp", e);
            }

            if (form.isAnyPage())
                status = STATUS_PAGE;
            else if (form.getDoAddPerson().isSelected())
                status = STATUS_ADDPERSON;
            else if (form.getDeletePersonId() > 0)
                status = STATUS_DELETEPERSON;
            else if (form.getJumpPersonId() > 0)
                status = STATUS_JUMPPERSON;
            else if (form.getDoJumpCompany().isSelected())
                status = STATUS_JUMPCOMPANY;
            else if (form.getDoAddCompany().isSelected())
                status = STATUS_ADDCOMPANY;
            else
                status = STATUS_SAVE;
        }
        else if (this.isTokenValid(request) && form.getDoDelete() != null)
        {
            if (log.isDebugEnabled())
                log.debug("delete button pressed");
            status = STATUS_DELETE;
        }
        else if (this.isTokenValid(request) && form.getDoAddOwnPerson().isSelected())
        {
            if (log.isDebugEnabled())
                log.debug("add own person button pressed");

            UserVO user = (UserVO) request.getSession().getAttribute(Globals.USER_KEY);
            ContactVO contact = (ContactVO) request.getSession().getAttribute(Constants.CONTACT_CONTACT);
            List<PersonContactVO> pcList = (List<PersonContactVO>) request.getSession().getAttribute(Constants.CONTACT_PERSONS);

            if (user.getPerson() != null)
            {
                PersonContactVO pc = new PersonContactVO(user.getPerson(), contact);

                if (!pcList.contains(pc))
                    pcList.add(pc);
            }

            status = STATUS_ADDOWNPERSON;
        }
        else if (this.isTokenValid(request) && form.getDoCancel() != null)
        {
            if (log.isDebugEnabled())
                log.debug("cancel button pressed");
            status = STATUS_BACK;
        }
        else
        {
            if (log.isDebugEnabled())
                log.debug("fill form from session");

            ContactVO contact = (ContactVO) request.getSession().getAttribute(Constants.CONTACT_CONTACT);

            form.setSubject(contact.getSubject());
            form.setContent(contact.getContent());
            form.setContactName(contact.getContactName());
            if (contact.getContactType() != null)
                form.setContactType(contact.getContactType().toString());
            if (contact.getBoundType() != null)
                form.setBoundType(contact.getBoundType().toString());

            if (contact.getContactTimestamp() != null)
            {
                SimpleDateFormat sdfDate = new SimpleDateFormat(MessageUtil.message(request, "format.input.date"));
                form.setContactDate(sdfDate.format(contact.getContactTimestamp()));

                SimpleDateFormat sdfTime = new SimpleDateFormat(MessageUtil.message(request, "format.input.time"));
                form.setContactTime(sdfTime.format(contact.getContactTimestamp()));
            }
        }

        if (!errors.isEmpty())
            saveErrors(request, errors);

        if (log.isDebugEnabled())
            log.debug("status = " + status);

        switch (status)
        {
            case STATUS_BACK:
                if (request.getSession().getAttribute(org.opencustomer.application.web.module.crm.company.Constants.COMPANY_COMPANY) != null)
                    return mapping.findForward("company.edit.page4");
                else if (request.getSession().getAttribute(org.opencustomer.application.web.module.crm.person.Constants.PERSON_PERSON) != null)
                    return mapping.findForward("person.edit.pageContact");
                else
                {
                    log.error("invalid selection for forward");
                    return mapping.findForward("back");
                }
            case STATUS_DELETE:
                return mapping.findForward("contact.edit.delete");
            case STATUS_ADDPERSON:
                return mapping.findForward("addPerson");
            case STATUS_ADDCOMPANY:
                return mapping.findForward("addCompany");
            case STATUS_JUMPCOMPANY:
                ContactVO contact = (ContactVO) request.getSession().getAttribute(Constants.CONTACT_CONTACT);
                if (contact.getCompany() != null)
                    request.setAttribute(org.opencustomer.application.web.module.crm.company.Constants.COMPANY_EXTERNCALL, contact.getCompany().getId());
                request.setAttribute("page", new Integer(1));
                return mapping.findForward("save"); // gehe 黚er save
            case STATUS_JUMPPERSON:
                if (form.getJumpPersonId() > 0)
                    request.setAttribute(org.opencustomer.application.web.module.crm.person.Constants.PERSON_EXTERNCALL, new Integer(form.getJumpPersonId()));
                request.setAttribute("page", new Integer(1));
                return mapping.findForward("save"); // gehe 黚er save
            case STATUS_DELETEPERSON:
                if (form.getDeletePersonId() > 0)
                    request.setAttribute(Constants.CONTACT_PERSON_DELETECALL, new Integer(form.getDeletePersonId()));
                request.setAttribute("page", new Integer(1));
                return mapping.findForward("deletePerson");
            case STATUS_SAVE:
                request.setAttribute("page", new Integer(1));
                return mapping.findForward("save");
            case STATUS_ADDOWNPERSON:
                return findPageForward(mapping, form);
            default:
                return findPageForward(mapping, form);
        }

    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -