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

📄 clientaction.java

📁 EJB+Struts+Webservice实现的开放式基金管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                            // asset = asset +
                            // fdto.getTotalPrice().doubleValue();
                            FundDto fundDto = fd.fundFindByPrimaryKey(fdto
                                    .getFundNo());
                            if ((!fundDto.getStatus().equalsIgnoreCase(
                                    "Invalid"))) {
                                asset = asset
                                        +
                                        (fdto.getQuantity().doubleValue()
                                         * fundDto
                                         .getCurrentPrice()
                                         .doubleValue());
                            } else {
                                fundDto.setPrice(new Double(0));
                            }
                            // asset = asset + (fdto.getQuantity().doubleValue()
                            // * fundDto.getCurrentPrice().doubleValue() );
                            fdto.setFundName((fd.fundFindByPrimaryKey(fdto
                                    .getFundNo())).getFundName());
                            fdto.setFundDto(fundDto);
                        }

                        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) {
                    e.printStackTrace();
                }

                clientForm.setClientDto(clientDto);
                request.setAttribute("clientForm", clientForm);
            } 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);
            }
        }
        return mapping.findForward(target);
    }

    /**
     *
     * @param mapping ActionMapping
     * @param form ActionForm
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     * @return ActionForward
     */
    private ActionForward detailView(ActionMapping mapping, ActionForm form,
                                     HttpServletRequest request,
                                     HttpServletResponse response) {
        String target = "success";
        String clientNoStr = request.getParameter("clientNo");
        ClientForm clientForm = new ClientForm();
        try {
            ClientDelegate cd = new ClientDelegate();
            ClientDto clientDto = cd.clientFindByPrimaryKey(new Integer(
                    clientNoStr));
            clientForm.setClientDto(clientDto);

            // 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));
                // getting assets and fund account entries
                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();
                        FundDto fundDto = fd.fundFindByPrimaryKey(fdto
                                .getFundNo());
                      if ((!fundDto.getStatus().equalsIgnoreCase("Invalid"))) {
                            asset = asset + (fdto.getQuantity().doubleValue()
                                   * fundDto.getCurrentPrice().doubleValue());
                        } else {
                            fundDto.setPrice(new Double(0));
                        }
                        // asset = asset + (fdto.getQuantity().doubleValue() *
                        // fundDto.getCurrentPrice().doubleValue() );
                        fdto.setFundName((fd.fundFindByPrimaryKey(fdto
                                .getFundNo())).getFundName());
                        fdto.setFundDto(fundDto);
                    }
                    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));
            }

            System.out.println("Assets>>>>>>>" + clientForm.getAsset());
            System.out.println("financing>>>>>>>"
                               +
                               clientForm.getFinancialAccountDto().
                               getFinancingAmount());

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

    }

    /**
     *
     * @param mapping ActionMapping
     * @param form ActionForm
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     * @return ActionForward
     */
    private ActionForward update(ActionMapping mapping, ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response) {
        String target = "success";
        // ClientForm clientForm = (ClientForm) form;
        String clientNo = request.getParameter("clientNo");
        if (clientNo != null) { // coming to update page
            try {
                ClientForm clientForm = new ClientForm();
                ClientDelegate clientDelegate = new ClientDelegate();
                ClientDto clientDto = clientDelegate
                                      .clientFindByPrimaryKey(new Integer(
                                              clientNo));
                clientForm.setClientDto(clientDto);
                request.setAttribute("clientForm", clientForm);
            } catch (Exception e) {
                System.out.println("Error in updating client" + e);
            }
        } else {
            try { // actually updating data
                ClientForm clientForm = (ClientForm) form;
                ClientDelegate cd = new ClientDelegate();
                System.out.println("UPDATING THIS DTO"
                                   + clientForm.getClientDto());
                cd.updateClient(clientForm.getClientDto());
                ActionErrors errors = new ActionErrors();
                errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
                        "clientForm.update.success"));
                saveErrors(request, errors);

                SalesDto sdto = (SalesDto) request.getSession().getAttribute(
                        "salesDto");
                log.info(clientForm.getClientDto().logData(
                        "CLIENT UPDATED by sales having sales no="
                        + sdto.getSalesNo()));

            } catch (Exception e) {
                target = "failure";
                ActionErrors errors = new ActionErrors();
                errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
                        "clientForm.updatefailed"));
                saveErrors(request, errors);
            }
        }
        return mapping.findForward(target);
    }

    /**
     *
     * @param form DynaValidatorForm
     * @return ClientDto
     * @throws Exception e
     */
    private ClientDto getClientDto(DynaValidatorForm form) throws Exception {

        Integer clientNo = ((Integer) form.get("clientNo"));
        String idCardNo = (String) form.get("idCardNo");
        System.out.println(clientNo + ">>>" + idCardNo);
        int intClientNo = clientNo.intValue();

        ClientDelegate cd = new ClientDelegate();
        if (intClientNo == 0 && !idCardNo.equals("")) {
            System.out.println("1");
            return cd.clientFindByIdCardNo(idCardNo);
        } else if (intClientNo != 0 && idCardNo.equals("")) {
            System.out.println("2");
            return cd.clientFindByPrimaryKey(clientNo);
        } else if (intClientNo != 0 && !idCardNo.equals("")) {
            System.out.println("3");
            ClientDto clientDto = cd.clientFindByPrimaryKey(clientNo);
            if (clientDto.getIdCardNo().equals(idCardNo)) {
                System.out.println("4");
                return clientDto;
            } else {
                throw new Exception("Fund Not Found");
            }
        } else {
            throw new Exception("Fund Not Found");
        }
    }
}

⌨️ 快捷键说明

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