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

📄 clientaction.java

📁 EJB+Struts+Webservice实现的开放式基金管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.fund.client;

import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
import com.fund.SuperAction;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
import org.apache.struts.validator.DynaValidatorForm;
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
import com.fund.fund.FundDelegate;
import com.fund.fund.FundDto;
import com.fund.sales.SalesDto;

/**
 *
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class ClientAction extends SuperAction {
    /**
     *
     * @param mapping ActionMapping
     * @param form ActionForm
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     * @return ActionForward
     */
    public ActionForward doExecute(ActionMapping mapping, ActionForm form,
                                   HttpServletRequest request,
                                   HttpServletResponse response) {
        String parameter = mapping.getParameter();
        System.out.println("Mapping=" + parameter);
        if (parameter.equals("add")) {
            return add(mapping, form, request, response);
        } else if (parameter.equals("view")) {
            return view(mapping, form, request, response);
        } else if (parameter.equals("detailView")) {
            return detailView(mapping, form, request, response);
        } else { // parameter.equals("edit")
            return update(mapping, form, request, response);
        }

    }

    /**
     *
     * @param mapping ActionMapping
     * @param form ActionForm
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     * @return ActionForward
     */
    private ActionForward add(ActionMapping mapping, ActionForm form,
                              HttpServletRequest request,
                              HttpServletResponse response) {
        String target = "success";
        ClientForm clientForm = (ClientForm) form;
        clientForm.getClientDto().setCreatedDate(
                new java.sql.Timestamp((new java.util.Date()).getTime()));
        try {
            ClientDelegate clientDelegate = new ClientDelegate();
            clientDelegate.createClient(clientForm.getClientDto());
            // getting fresh dto to get the client no
            clientForm.setClientDto(clientDelegate
                                    .clientFindByIdCardNo(clientForm.
                    getClientDto()
                    .getIdCardNo()));
            clientForm.getFinancialAccountDto().setFinancingAmount(
                    new Double(0));
            clientForm.setAsset(new Double(0));
            ActionErrors errors = new ActionErrors();
            errors.add("clientForm.add.success", new ActionError(
                    "clientForm.add.success"));
            saveErrors(request, errors);
            ClientDto cdto = clientDelegate.clientFindByIdCardNo(clientForm
                    .getClientDto().getIdCardNo());
            SalesDto sdto = (SalesDto) request.getSession().getAttribute(
                    "salesDto");
            log.info(cdto.logData("CLIENT ADDED by sales having sales no="
                                  + sdto.getSalesNo()));

        } catch (Exception e) {
            System.out.println("Error in adding client" + e);
            target = "failure";
            ActionErrors errors = new ActionErrors();
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
                    " clientForm.add.failure"));
            saveErrors(request, errors);
        }
        return mapping.findForward(target);
    }

    /**
     *
     * @param mapping ActionMapping
     * @param form ActionForm
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     * @return ActionForward
     */
    private ActionForward view(ActionMapping mapping, ActionForm form,
                               HttpServletRequest request,
                               HttpServletResponse response) {

        String target = "success";
        ClientForm clientForm = new ClientForm();
        String clientNoStr = request.getParameter("uClientNo");
        System.out.println("Client No" + clientNoStr);
        if (clientNoStr != null && (!clientNoStr.trim().equals(""))) { // on
            // clicking
            // cancel
            // button
            // in
            // update
            // interface
            try {
                // getting client dto
                ClientDelegate cd = new ClientDelegate();
                clientForm.setClientDto(cd.clientFindByPrimaryKey(new Integer(
                        clientNoStr)));
                // getting financing from financing account of the client
                try {
                    FinancialAccountDelegate financialAccountDelegate = new
                            FinancialAccountDelegate();
                    clientForm.setFinancialAccountDto(financialAccountDelegate
                            .financialAccountFindByClientNo(clientForm
                            .getClientDto().getClientNo()));
                    clientForm.setAsset(new Double(0.0));
                    // getting assets
                    try {
                        FundAccountDelegate fundAccountDelegate = new
                                FundAccountDelegate();
                        List fundAccountList = Arrays
                                               .asList(fundAccountDelegate
                                .fundAccountFindByFundAccNo(clientForm
                                .getFinancialAccountDto()
                                .getAccountNo()));
                        Iterator iter = fundAccountList.iterator();
                        FundDelegate fd = new FundDelegate();
                        double asset = 0;
                        while (iter.hasNext()) {
                            FundAccountDto fdto = (FundAccountDto) iter.next();
                            // asset = asset +
                            // fdto.getTotalPrice().doubleValue();
                            asset = asset
                                    + (fdto.getQuantity().doubleValue() * fd
                                       .fundFindByPrimaryKey(
                                               fdto.getFundNo())
                                       .getCurrentPrice().doubleValue());
                            fdto.setFundName((fd.fundFindByPrimaryKey(fdto
                                    .getFundNo())).getFundName());
                        }
                        Double totalAsset = null;
                        java.text.DecimalFormat obDF = new java.text.
                                DecimalFormat(
                                        "#.##");
                        totalAsset = new Double(obDF.format(asset
                                + clientForm.getFinancialAccountDto()
                                .getFinancingAmount().doubleValue()));
                        clientForm.setAsset(totalAsset);
                        clientForm.setFundList(fundAccountList);
                    } catch (Exception e) {
                        // no entries for particular client/financial account in
                        // fund account
                        System.out.println("catch 1:" + e.getMessage());
                    }
                } catch (Exception e) {
                    // financing account does not exist for this client
                    System.out.println("Catch 2:" + e.getMessage());
                    clientForm.getFinancialAccountDto().setFinancingAmount(
                            new Double(0));
                }
            } catch (Exception e) {
                // did not retrive the clientDto for specified search
                target = "failure";
                ActionErrors errors = new ActionErrors();
                errors.add("clientForm.invalidclient", new ActionError(
                        "clientForm.invalidclient"));
                saveErrors(request, errors);
            }
            request.setAttribute("clientForm", clientForm);
        } else { // from search screen
            DynaValidatorForm searchForm = (DynaValidatorForm) form;

            try {
                // Retriving clientDto for the specified search
                ClientDto clientDto = getClientDto(searchForm);
                Integer clientNo = ((Integer) searchForm.get("clientNo"));
                String idCardNo = (String) searchForm.get("idCardNo");

                if ((clientNo != null && clientNo.intValue() != 0)
                    && idCardNo != null && !idCardNo.equals("")) {
                    if ((clientDto.getClientNo().intValue() != clientNo
                         .intValue())
                        && !clientDto.getIdCardNo().equals(idCardNo)) {
                        target = "failure";
                        ActionErrors errors = new ActionErrors();
                        errors.add("clientForm.invalidclient", new ActionError(
                                "clientForm.invalidclient"));
                        saveErrors(request, errors);

                    }
                }
                try {
                    FinancialAccountDelegate financialAccountDelegate = new
                            FinancialAccountDelegate();
                    FinancialAccountDto financialAccountDto =
                            financialAccountDelegate
                            .financialAccountFindByClientNo(clientDto
                            .getClientNo());
                    clientForm.setFinancialAccountDto(financialAccountDto);
                    clientForm.setAsset(new Double(0.0));
                    // getting assets
                    try {
                        FundAccountDelegate fundAccountDelegate = new
                                FundAccountDelegate();
                        List fundAccountList = Arrays
                                               .asList(fundAccountDelegate
                                .fundAccountFindByFundAccNo(financialAccountDto
                                .getAccountNo()));
                        Iterator iter = fundAccountList.iterator();
                        FundDelegate fd = new FundDelegate();
                        double asset = 0;

                        while (iter.hasNext()) {
                            FundAccountDto fdto = (FundAccountDto) iter.next();

⌨️ 快捷键说明

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