showcompanies2action.java

来自「开源项目CRM之OpenCustomer」· Java 代码 · 共 136 行

JAVA
136
字号
/*******************************************************************************
 * ***** 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.company;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
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.opencustomer.application.db.dao.crm.CompanyStateDAO;
import org.opencustomer.application.db.dao.crm.CompanyTypeDAO;
import org.opencustomer.application.db.dao.crm.SectorDAO;
import org.opencustomer.application.db.dao.crm.custom.CompanyListDAO;
import org.opencustomer.application.web.module.crm.company.edit.SaveAction;
import org.opencustomer.application.web.struts.Action;
import org.opencustomer.application.web.util.Settings;
import org.opencustomer.web.util.MessageUtil;
import org.opencustomer.web.util.Page;
import org.opencustomer.web.util.ScrollBean;
import org.opencustomer.web.util.Sort;

public class ShowCompanies2Action extends Action<ShowCompanies2Form>
{
    private static Logger log = Logger.getLogger(ShowCompanies2Action.class);

    public ActionForward execute(ActionMapping mapping, ShowCompanies2Form form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
    {
        SaveAction.removeAttributes(request);

        List list = null;
        int count = 0;

        Sort sort = null;
        if (form.getSort() == null)
            sort = new Sort(CompanyListDAO.SORT_COMPANY_NAME, true);
        else
            sort = Sort.parseParam(form.getSort());

        Page page = new Page(Settings.getInstance().getMaxRows(), form.getPage());

        String paramCompanyName = form.getCompanyName();
        Integer paramCompanyStateId = null;
        Integer paramCompanyTypeId = null;
        Integer paramSectorId = null;

        if (form.getCompanyStateId() > 0)
            paramCompanyStateId = new Integer(form.getCompanyStateId());
        if (form.getCompanyTypeId() > 0)
            paramCompanyTypeId = new Integer(form.getCompanyTypeId());
        if (form.getSectorId() > 0)
            paramSectorId = new Integer(form.getSectorId());

        Date paramLastContactDateStart = null;
        Date paramLastContactDateEnd = null;
        String format = MessageUtil.message(request, "format.input.date");
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        try
        {
            if (form.getLastContactDateStart() != null)
                paramLastContactDateStart = sdf.parse(form.getLastContactDateStart());
            if (form.getLastContactDateEnd() != null)
            {
                paramLastContactDateEnd = sdf.parse(form.getLastContactDateEnd());
                Calendar cal = GregorianCalendar.getInstance();
                cal.setTime(paramLastContactDateEnd);
                cal.add(Calendar.DAY_OF_MONTH, 1);
                cal.add(Calendar.SECOND, -1);
                paramLastContactDateEnd = cal.getTime();
            }
        }
        catch (ParseException e)
        {
            log.error("bad form validation", e);
        }

        CompanyListDAO dao = new CompanyListDAO();

        count = dao.countList(paramCompanyName, paramCompanyStateId, paramCompanyTypeId, paramSectorId, paramLastContactDateStart, paramLastContactDateEnd);
        if (count < page.getFirstEntry())
            page.setPage(1);

        if (count > 0)
            list = dao.getList(paramCompanyName, paramCompanyStateId, paramCompanyTypeId, paramSectorId, paramLastContactDateStart, paramLastContactDateEnd, sort, page);
        else
            list = new ArrayList();

        ScrollBean scroll = new ScrollBean();
        scroll.setCount(count);
        scroll.setPage(page);

        request.setAttribute("crm.overview.companyListScroll", scroll);
        request.setAttribute("crm.overview.companyList", list);

        if (request.getSession().getAttribute(Constants.COMPANY_LIST2_SECTOR_LIST) == null)
            request.getSession().setAttribute(Constants.COMPANY_LIST2_SECTOR_LIST, new SectorDAO().getAll());
        if (request.getSession().getAttribute(Constants.COMPANY_LIST2_COMPANYTYPE_LIST) == null)
            request.getSession().setAttribute(Constants.COMPANY_LIST2_COMPANYTYPE_LIST, new CompanyTypeDAO().getAll());
        if (request.getSession().getAttribute(Constants.COMPANY_LIST2_COMPANYSTATE_LIST) == null)
            request.getSession().setAttribute(Constants.COMPANY_LIST2_COMPANYSTATE_LIST, new CompanyStateDAO().getAll());

        return mapping.getInputForward();
    }

}

⌨️ 快捷键说明

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