KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > campware > cream > modules > screens > OrderList


1 package org.campware.cream.modules.screens;
2
3 /* ====================================================================
4  * Copyright (C) 2003-2005 Media Development Loan Fund
5  *
6  * * contact: contact@campware.org - http://www.campware.org
7  * Campware encourages further development. Please let us know.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
24  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
27  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  * ====================================================================
36  *
37  * This software consists of voluntary contributions made by many
38  * individuals on behalf of the Apache Software Foundation. For more
39  * information on the Apache Software Foundation, please see
40  * <http://www.apache.org/>.
41  */

42
43 import java.util.List JavaDoc;
44 import java.util.Date JavaDoc;
45 import java.util.Calendar JavaDoc;
46
47 import org.apache.turbine.util.RunData;
48
49 import org.apache.torque.util.Criteria;
50 import org.campware.cream.om.SorderPeer;
51 import org.campware.cream.om.CustomerPeer;
52 import org.campware.cream.om.CurrencyPeer;
53
54 /**
55  * To read comments for this class, please see
56  * the ancestor class
57  */

58 public class OrderList extends CreamList
59 {
60
61     protected void initScreen()
62     {
63         setModuleType(DOCUMENT);
64         setModuleName("SORDER");
65         setIdName(SorderPeer.SORDER_ID);
66         setDefOrderColumn(SorderPeer.ISSUED_DATE);
67     }
68
69     protected String JavaDoc getSortColumn(int sortNo)
70     {
71         if (sortNo==1){
72             return SorderPeer.SORDER_CODE;
73         } else if (sortNo==2){
74             return CustomerPeer.CUSTOMER_DISPLAY;
75         } else if (sortNo==3){
76             return SorderPeer.PAY_TERM;
77         } else if (sortNo==4){
78             return SorderPeer.CURRENCY_AMOUNT;
79         } else if (sortNo==5){
80             return CurrencyPeer.CURRENCY_CODE;
81         } else if (sortNo==6){
82             return SorderPeer.ISSUED_DATE;
83         }
84         
85         return "";
86     }
87
88     protected void setFind(String JavaDoc findStr, Criteria listCriteria)
89     {
90         try
91         {
92             listCriteria.add(SorderPeer.SORDER_CODE, (Object JavaDoc)findStr, Criteria.LIKE);
93         }
94         catch (Exception JavaDoc e)
95         {
96         }
97     }
98
99     protected void setFilter(int filterNo, Criteria listCriteria, RunData data)
100     {
101         int nowDay, nowMonth, nowYear;
102         
103         Calendar JavaDoc rightNow = Calendar.getInstance();
104         nowMonth= rightNow.get(Calendar.MONTH);
105         nowYear= rightNow.get(Calendar.YEAR);
106
107         rightNow.set(nowYear, nowMonth, 1);
108         Date JavaDoc fDayThisMonth= rightNow.getTime();
109         rightNow.set(nowYear, nowMonth + 1, 1);
110         Date JavaDoc fDayNextMonth= rightNow.getTime();
111         rightNow.set(nowYear, nowMonth - 1, 1);
112         Date JavaDoc fDayLastMonth= rightNow.getTime();
113         rightNow.set(nowYear, 1, 1);
114         Date JavaDoc fDayThisYear= rightNow.getTime();
115         rightNow.set(nowYear + 1, 1, 1);
116         Date JavaDoc fDayNextYear= rightNow.getTime();
117         rightNow.set(nowYear - 1, 1, 1);
118         Date JavaDoc fDayLastYear= rightNow.getTime();
119
120         try
121         {
122             if (filterNo==1001){
123                 listCriteria.add(SorderPeer.ISSUED_DATE, new Date JavaDoc(), Criteria.EQUAL);
124             } else if (filterNo==1002){
125                 Criteria.Criterion b1 = listCriteria.getNewCriterion(SorderPeer.ISSUED_DATE, fDayThisMonth, Criteria.GREATER_EQUAL);
126                 Criteria.Criterion b2 = listCriteria.getNewCriterion(SorderPeer.ISSUED_DATE, fDayNextMonth, Criteria.LESS_THAN);
127                 listCriteria.add( b1.and( b2));
128             } else if (filterNo==1003){
129                 Criteria.Criterion b1 = listCriteria.getNewCriterion(SorderPeer.ISSUED_DATE, fDayLastMonth, Criteria.GREATER_EQUAL);
130                 Criteria.Criterion b2 = listCriteria.getNewCriterion(SorderPeer.ISSUED_DATE, fDayThisMonth, Criteria.LESS_THAN);
131                 listCriteria.add( b1.and( b2));
132             } else if (filterNo==1004){
133                 Criteria.Criterion b1 = listCriteria.getNewCriterion(SorderPeer.ISSUED_DATE, fDayThisYear, Criteria.GREATER_EQUAL);
134                 Criteria.Criterion b2 = listCriteria.getNewCriterion(SorderPeer.ISSUED_DATE, fDayNextYear, Criteria.LESS_THAN);
135                 listCriteria.add( b1.and( b2));
136             } else if (filterNo==1005){
137                 Criteria.Criterion b1 = listCriteria.getNewCriterion(SorderPeer.ISSUED_DATE, fDayLastYear, Criteria.GREATER_EQUAL);
138                 Criteria.Criterion b2 = listCriteria.getNewCriterion(SorderPeer.ISSUED_DATE, fDayThisYear, Criteria.LESS_THAN);
139                 listCriteria.add( b1.and( b2));
140             } else if (filterNo==1006){
141                 listCriteria.add(SorderPeer.STATUS, new Integer JavaDoc(10), Criteria.EQUAL);
142             } else if (filterNo==1007){
143                 listCriteria.add(SorderPeer.STATUS, new Integer JavaDoc(30), Criteria.EQUAL);
144             } else if (filterNo==1008){
145                 listCriteria.add(SorderPeer.STATUS, new Integer JavaDoc(50), Criteria.EQUAL);
146             } else if (filterNo==1009){
147                 listCriteria.add(SorderPeer.CREATED_BY, (Object JavaDoc) data.getUser().getName(), Criteria.EQUAL);
148             }
149         }
150         catch (Exception JavaDoc e)
151         {
152         }
153     }
154
155
156     protected List JavaDoc getEntries(Criteria criteria)
157     {
158         try
159         {
160             criteria.addJoin(CustomerPeer.CUSTOMER_ID, SorderPeer.CUSTOMER_ID);
161             criteria.addJoin(CurrencyPeer.CURRENCY_ID, SorderPeer.CURRENCY_ID);
162             return SorderPeer.doSelect(criteria);
163         }
164         catch (Exception JavaDoc e)
165         {
166             return null;
167         }
168     }
169
170 }
171
Popular Tags