📄 accounthistorybean.java
字号:
/* * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. U.S. * Government Rights - Commercial software. Government users are subject * to the Sun Microsystems, Inc. standard license agreement and * applicable provisions of the FAR and its supplements. Use is subject * to license terms. * * This distribution may include materials developed by third parties. * Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks * or registered trademarks of Sun Microsystems, Inc. in the U.S. and * other countries. * * Copyright (c) 2006 Sun Microsystems, Inc. Tous droits reserves. * * Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel * commercial. Les utilisateurs gouvernementaux sont soumis au contrat de * licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions * en vigueur de la FAR (Federal Acquisition Regulations) et des * supplements a celles-ci. Distribue par des licences qui en * restreignent l'utilisation. * * Cette distribution peut comprendre des composants developpes par des * tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE * sont des marques de fabrique ou des marques deposees de Sun * Microsystems, Inc. aux Etats-Unis et dans d'autres pays. */package com.sun.tutorial.javaee.dukesbank.web;import javax.faces.context.FacesContext;import javax.faces.model.SelectItem;import java.math.BigDecimal;import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.Date;import java.util.Iterator;import java.util.List;import com.sun.tutorial.javaee.dukesbank.exception.InvalidParameterException;import com.sun.tutorial.javaee.dukesbank.util.AccountDetails;import com.sun.tutorial.javaee.dukesbank.util.Debug;import com.sun.tutorial.javaee.dukesbank.util.TxDetails;import com.sun.tutorial.javaee.dukesbank.web.Util.Navigation;public class AccountHistoryBean { protected ArrayList AVOptions = null; protected ArrayList beginDayOptions = null; protected ArrayList beginMonthOptions = null; protected ArrayList endDayOptions = null; protected ArrayList endMonthOptions = null; protected ArrayList sinceDayOptions = null; protected ArrayList sinceMonthOptions = null; protected ArrayList sortOptions = null; protected ArrayList yearOptions = null; private AccountDetails selectedAccount; private ArrayList<TxDetails> selectedTransactions; private BigDecimal beginningBalance; private BigDecimal credits; private BigDecimal debits; private BigDecimal endingBalance; private CustomerBean customer; private String range; private String since; private String sinceOrRange; private int activityView; private int beginDay; private int beginMonth; private int date; private int endDay; private int endMonth; private int sinceDay; private int sinceMonth; private int sortOption; private int year; public AccountHistoryBean() { sinceOrRange = "since"; range = "range"; since = "since"; sinceMonth = 1; sinceDay = 1; beginMonth = 1; beginDay = 1; endMonth = 12; endDay = 31; year = 2006; } public void doTx() { BigDecimal amount; TxDetails td = null; Date startDate = null; Date endDate = null; if (sinceOrRange != null) { if (sinceOrRange.equals(range)) { date = 1; } } else { date = 0; } try { switch (date) { case 0: startDate = com.sun.tutorial.javaee.dukesbank.util.DateHelper .getDate(year, sinceMonth, sinceDay); endDate = new Date(); break; case 1: startDate = com.sun.tutorial.javaee.dukesbank.util.DateHelper .getDate(year, beginMonth, beginDay); endDate = com.sun.tutorial.javaee.dukesbank.util.DateHelper .getDate(year, endMonth, endDay); break; } List<TxDetails> transactions = customer.getTxController() .getTxsOfAccount( startDate, endDate, customer.getActiveAccount()); switch (sortOption) { case 0: Collections.sort( transactions, new Comparator<TxDetails>() { public int compare( TxDetails tx1, TxDetails tx2) { return (tx1.getTimeStamp().compareTo( tx2.getTimeStamp())); } }); break; case 1: Collections.sort( transactions, new Comparator<TxDetails>() { public int compare( TxDetails tx1, TxDetails tx2) { return (tx2.getTimeStamp().compareTo( tx1.getTimeStamp())); } }); break; case 2: Collections.sort( transactions, new Comparator<TxDetails>() { public int compare( TxDetails tx1, TxDetails tx2) { return (tx1.getDescription().compareTo( tx2.getDescription())); } }); break; case 3: Collections.sort( transactions, new Comparator<TxDetails>() { public int compare( TxDetails tx1, TxDetails tx2) { return (tx1.getAmount().compareTo( tx2.getAmount())); } }); break; } credits = new BigDecimal("0.00"); debits = new BigDecimal("0.00"); selectedAccount = customer.getAccountDetails(); beginningBalance = selectedAccount.getBalance(); endingBalance = selectedAccount.getBalance(); boolean isCreditAcct = false; if (selectedAccount.getType() .equals("Credit")) { isCreditAcct = true; } Iterator<TxDetails> i = transactions.iterator(); if (i.hasNext()) { td = i.next(); beginningBalance = td.getBalance() .subtract(td.getAmount()); } i = transactions.iterator(); if (i.hasNext()) { Debug.print("adding to credits and debits."); while (i.hasNext()) { td = i.next(); amount = td.getAmount(); if (isCreditAcct) { if (amount.floatValue() < 0) { credits = credits.add(amount); } else { debits = debits.subtract(amount); } } else { if (amount.floatValue() > 0) { Debug.print("Adding " + amount + "to credits."); credits = credits.add(amount); } else { Debug.print( "Subtracting " + amount + "from debits."); debits = debits.subtract(amount); } } } } if (td != null) { endingBalance = td.getBalance(); } selectedTransactions = new ArrayList<TxDetails>(); i = transactions.iterator(); if (i.hasNext()) { switch (activityView) { case 0: while (i.hasNext()) { td = i.next(); selectedTransactions.add(td); } break; case 1: while (i.hasNext()) { td = i.next(); if (isCreditAcct) { if (td.getAmount() .floatValue() < 0) { selectedTransactions.add(td); } } else { if (td.getAmount() .floatValue() > 0) { selectedTransactions.add(td); } } } break; case 2: while (i.hasNext()) { td = i.next(); if (isCreditAcct) { if (td.getAmount() .floatValue() > 0) { selectedTransactions.add(td); } } else { if (td.getAmount() .floatValue() < 0) { selectedTransactions.add(td); } } } break; } } else { Debug.print("No matching transactions."); } } catch (InvalidParameterException e) { e.printStackTrace(); } } public void setCustomer(CustomerBean customer) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -