📄 accountdrcraction.java
字号:
/**
* =============================================
* Copyright 2006 szmx
*
* Change Revision
* --------------------------------
* Date Author Remarks
* 2006-4-24 hliu Create com.szmx.tlms.finance.web.AccountDrCrAction
* =============================================
*/
package com.szmx.tlms.finance.web;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.util.MessageResources;
import org.springframework.dao.DataIntegrityViolationException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
import java.util.HashMap;
import com.szmx.framework.base.model.Pagination;
import com.szmx.framework.base.web.BaseAction;
import com.szmx.tlms.finance.service.AccountService;
import com.szmx.tlms.finance.service.FixedAssetsService;
import com.szmx.tlms.finance.model.Account;
import com.szmx.tlms.finance.model.AccountDrCr;
/**
* <desc>
*
* @author hliu
* @since 2006-4-24
*/
public class AccountDrCrAction extends BaseAction {
/**
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward searchAccountDrCr(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("Entering 'searchAccount' method");
}
DynaActionForm dynaForm = (DynaActionForm) form;
Map paraMap = new HashMap();
paraMap.put("searchBean", dynaForm.get("searchBean"));
Pagination pageObj = new Pagination(request, "pagination");
AccountService mgr = (AccountService) getBean("accountService");
//test
FixedAssetsService fixedAssetsService=(FixedAssetsService)getBean("fixedAssetsService");
fixedAssetsService.depricationFixedAssets();
Pagination pagination = mgr.getAccounts(pageObj, paraMap);
request.setAttribute("pagination", pagination);
return mapping.findForward("success");
}
public ActionForward initUpdateAccountDrCr(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("Entering 'initUpdateEmployee' method");
}
DynaActionForm dynaForm = (DynaActionForm) form;
Account account = (Account) dynaForm.get("accountDrCrBean");
AccountService service = (AccountService) getBean("accountService");
try {
account = service.getAccount(account.getId());
} catch (Exception e) {
saveActionErrorMessage(request, "err.admin.employee.get.noExisted", null);
return mapping.findForward("failure");
}
request.setAttribute("accountDrCrBean", account);
return mapping.findForward("success");
}
public ActionForward updateAccountDrCr(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("Entering 'addAccount' method");
}
DynaActionForm dynaForm = (DynaActionForm) form;
AccountDrCr accountDrCr = (AccountDrCr) dynaForm.get("accountBean");
//accountDrCr.setCompanyId(new Long(1)); //todo bryan: get the company from session
accountDrCr.populateUpdateBean(new Long(1));//todo bryan: get the user id form session
AccountService accountService = (AccountService) getBean("accountService");
//Get the previous account by the Id.
Account preAccount=accountService.getAccount(accountDrCr.getId());
//when update a account ,if the Sap code is changed,
//make sure the changed Sap code is not existed in the DateBase.
saveActionTripMessage(request,
"message.finance.update.success",
new String[]{MessageResources.getMessageResources("ApplicationMessages-finance").getMessage("label.account.name")});
return mapping.findForward("success");
}
public ActionForward initAddAccountDrCr(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("Entering 'initAddAccount' method");
}
Account account = new Account();
//Make sure that the textfield on the page is null
request.setAttribute("accountBean", account);
return mapping.findForward("success");
}
public ActionForward removeAccountDrCr(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("Entering 'removeEmployee' method");
}
DynaActionForm dynaForm = (DynaActionForm) form;
String[] splitString = (String[]) dynaForm.get("idArr");
AccountService service = (AccountService) getBean("accountService");
try {
service.removeAll(splitString);
saveActionTripMessage(request,
"message.finance.delete.success",
new String[]{MessageResources.getMessageResources("ApplicationMessages-finance").getMessage("label.account.name")});
}
catch (DataIntegrityViolationException e) {
saveActionErrorMessage(request,
"error.finance.delete.failure.useredByOthers", null);
return mapping.findForward("failure");
}
catch (Exception e) {
log.debug(e);
saveActionTripMessage(request,
"error.finance.delete.failure",
new String[]{MessageResources.getMessageResources("ApplicationMessages-finance").getMessage("label.account.name")});
return mapping.findForward("failure");
}
return mapping.findForward("success");
}
public ActionForward addAccountDrCr(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("Entering 'addAccount' method");
}
DynaActionForm dynaForm = (DynaActionForm) form;
Account account = (Account) dynaForm.get("accountBean");
//IF the LocalAccountCode level 2 is null,copy the LocalAccountCode level 1's value to it
if (account.getLocalAccountCode2().trim().equals("")) {
account.setLocalAccountCode2(account.getSapAccountCode());
}
account.setCompanyId(new Long(1)); //todo bryan: get the company from session
account.populateCreateBean(new Long(1));//todo bryan: get the user id form session
AccountService accountService = (AccountService) getBean("accountService");
try {
//Test if the SAP code has been used in the local system.
if (accountService.getAccountsBySAPCode(account) != null && accountService.getAccountsBySAPCode(account).size() != 0) {
request.setAttribute("accountBean", account);
saveActionErrorMessage(request, "error.finance.account.add.dupilcateRecord", null);
return mapping.findForward("failure");
}
//IF the SAP CODE not used ,save the record.
accountService.save(account);
dynaForm.set("accountBean", account);
request.setAttribute("accountBean", account);
} catch (Exception e) {
request.setAttribute("accountBean", account);
saveActionErrorMessage(request, "error.finance.add.failure", new String[]{MessageResources.getMessageResources("ApplicationMessages-finance").getMessage("label.account.name")});
e.printStackTrace();//Todo bryan: This will write into the Log file.
return mapping.findForward("failure");
}
saveActionTripMessage(request, "message.finance.add.success", new String[]{MessageResources.getMessageResources("ApplicationMessages-finance").getMessage("label.account.name")});
return mapping.findForward("success");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -