📄 financialaccountaction.java
字号:
package com.fund.client;
import com.fund.SuperAction;
import com.fund.sales.SalesDto;
import org.apache.struts.action.ActionForward;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.validator.DynaValidatorForm;
/**
*
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class FinancialAccountAction 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();
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("addMoney")) {
return update(mapping, form, request, response);
} else if (parameter.equals("takeMoney")) {
return update(mapping, form, request, response);
} else if (parameter.equals("updateStatus")) {
return update(mapping, form, request, response);
} else {
return null;
}
}
/**
*
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return ActionForward
*/
public ActionForward add(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
String target = "success";
FinancialAccountForm financingAccountForm = (FinancialAccountForm) form;
FinancialAccountDto finDto = financingAccountForm.
getFinancialAccountDto();
// validations
Integer clientNo = finDto.getClientNo();
String passwd = finDto.getPassword();
//String repeatPasswd = request.getParameter("cpassword");
String repeatPasswd = financingAccountForm.getCpassword();
if (repeatPasswd == null || passwd == null
|| !passwd.equals(repeatPasswd)) {
target = "failure";
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("financialAccount.passwordmismatch"));
saveErrors(request, errors);
return mapping.findForward(target);
}
// validation end
finDto.setCreatedDate(
new java.sql.Timestamp((new java.util.Date()).getTime()));
financingAccountForm.getFinancialAccountDto().setStatus("正常");
try {
ClientDelegate cd = new ClientDelegate();
ClientDto clientDto = null;
try {
clientDto = cd.clientFindByPrimaryKey(clientNo);
} catch (Exception e) {
target = "failure";
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("financialAccount.invalidclient"));
saveErrors(request, errors);
return mapping.findForward(target);
}
FinancialAccountDelegate financialAccountDelegate = new
FinancialAccountDelegate();
financialAccountDelegate.createFinancialAccount(
financingAccountForm
.getFinancialAccountDto());
//getting fresh dto to get the client no
financingAccountForm.setFinancialAccountDto(
financialAccountDelegate.financialAccountFindByClientNo(
clientNo));
SalesDto sdto = (SalesDto) request.getSession().getAttribute(
"salesDto");
log.info(financingAccountForm.getFinancialAccountDto().logData(
"FINANCING ACCOUNT ADDED by sales having sales no="
+ sdto.getSalesNo()));
financingAccountForm.setClientDto(clientDto);
} catch (Exception e) {
System.out.println("Error in financial account" + e);
target = "failure";
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("financialAccount.accountExist"));
saveErrors(request, errors);
}
return mapping.findForward(target);
}
/**
*
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return ActionForward
*/
public ActionForward view(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
String target = "success";
FinancialAccountForm financialAccountForm = new FinancialAccountForm();
String financialAccountNoStr = request.getParameter(
"financialAccountNo");
if (financialAccountNoStr != null
&& (!financialAccountNoStr.trim().equals(""))) {
try {
FinancialAccountDelegate fd = new FinancialAccountDelegate();
financialAccountForm.setFinancialAccountDto(fd.
financialAccountFindByPrimaryKey(new Integer(
financialAccountNoStr)));
request.setAttribute("financialAccountForm",
financialAccountForm);
} catch (Exception e) {
System.out.println("Exception encountered: " + e);
}
} else { //from search screen
DynaValidatorForm searchForm = (DynaValidatorForm) form;
try {
//Retriving financialAccountDto for the specified search
financialAccountForm.setFinancialAccountDto(
getFinancialAccountDto(searchForm));
ClientDelegate cd = new ClientDelegate();
financialAccountForm.setClientDto(cd.clientFindByPrimaryKey(
financialAccountForm.getFinancialAccountDto().
getClientNo()));
request.setAttribute("financialAccountForm",
financialAccountForm);
} catch (Exception e) {
//did not retrive the financialAccountDto for specified search
target = "failure";
ActionErrors errors = new ActionErrors();
errors.add("financialAccountForm.invalidfinancialAccount",
new ActionError(
"financialAccountForm.invalidfinancialAccount"));
saveErrors(request, errors);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -