KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.campware.cream.modules.screens;
2
3 /* ====================================================================
4  * Copyright (C) 2003 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.Date JavaDoc;
44 import java.text.SimpleDateFormat JavaDoc;
45 import java.text.DecimalFormat JavaDoc;
46 import java.text.DecimalFormatSymbols JavaDoc;
47
48 import org.apache.turbine.util.RunData;
49
50 import org.apache.torque.util.Criteria;
51
52 import org.apache.velocity.context.Context;
53
54 import org.campware.cream.om.CustomerPeer;
55 import org.campware.cream.om.ProductPeer;
56 import org.campware.cream.om.ProjectPeer;
57 import org.campware.cream.om.CustomerCategoryPeer;
58 import org.campware.cream.om.ProjectCategoryPeer;
59 import org.campware.cream.om.ProductCategoryPeer;
60 import org.campware.cream.om.CountryPeer;
61 import org.campware.cream.om.RegionPeer;
62 import org.campware.cream.om.LanguagePeer;
63 import org.campware.cream.om.HouseholdCategoryPeer;
64 import org.campware.cream.om.EducationCategoryPeer;
65 import org.campware.cream.om.VendorPeer;
66 import org.campware.cream.om.UomPeer;
67
68 /**
69  * To read comments for this class, please see
70  * the ancestor class
71  */

72 public class ReportForm extends SecureScreen
73 {
74
75     public void doBuildTemplate(RunData data, Context context)
76     {
77         try
78         {
79             
80             context.put("df", new SimpleDateFormat JavaDoc ("dd.MM.yyyy"));
81             context.put("dtf", new SimpleDateFormat JavaDoc ("dd.MM.yyyy hh:mm:ss"));
82             
83             DecimalFormatSymbols JavaDoc symb= new DecimalFormatSymbols JavaDoc();
84             symb.setDecimalSeparator('.');
85             
86             context.put("af", new DecimalFormat JavaDoc ("0.00", symb));
87             context.put("rf", new DecimalFormat JavaDoc ("0.000000", symb));
88             context.put("today", new Date JavaDoc());
89
90             Criteria prodcrit = new Criteria();
91             prodcrit.add(ProductPeer.PRODUCT_ID, 999, Criteria.GREATER_THAN);
92             prodcrit.addAscendingOrderByColumn(ProductPeer.PRODUCT_DISPLAY);
93             context.put("products", ProductPeer.doSelect(prodcrit));
94
95             Criteria projcrit = new Criteria();
96             projcrit.add(ProjectPeer.PROJECT_ID, 999, Criteria.GREATER_THAN);
97             projcrit.addAscendingOrderByColumn(ProjectPeer.PROJECT_NAME);
98             context.put("projects", ProjectPeer.doSelect(projcrit));
99
100             Criteria custcrit = new Criteria();
101             Criteria.Criterion b1 = custcrit.getNewCriterion(CustomerPeer.CUSTOMER_ID, new Integer JavaDoc(1000), Criteria.EQUAL);
102             Criteria.Criterion b2 = custcrit.getNewCriterion(CustomerPeer.STATUS, new Integer JavaDoc(29), Criteria.GREATER_THAN);
103             custcrit.add( b1.or( b2));
104             custcrit.addAscendingOrderByColumn(CustomerPeer.CUSTOMER_DISPLAY);
105             context.put("customers", CustomerPeer.doSelect(custcrit));
106
107             Criteria custcatcrit = new Criteria();
108             custcatcrit.add(CustomerCategoryPeer.CUSTOMER_CAT_ID, 999, Criteria.GREATER_THAN);
109             custcatcrit.addAscendingOrderByColumn(CustomerCategoryPeer.CUSTOMER_CAT_NAME);
110             context.put("customercats", CustomerCategoryPeer.doSelect(custcatcrit));
111
112             Criteria countrycrit = new Criteria();
113             countrycrit.add(CountryPeer.COUNTRY_ID, 999, Criteria.GREATER_THAN);
114             countrycrit.addAscendingOrderByColumn(CountryPeer.COUNTRY_NAME);
115             context.put("countries", CountryPeer.doSelect(countrycrit));
116
117             Criteria regioncrit = new Criteria();
118             regioncrit.add(RegionPeer.REGION_ID, 999, Criteria.GREATER_THAN);
119             regioncrit.addAscendingOrderByColumn(RegionPeer.REGION_NAME);
120             context.put("regions", RegionPeer.doSelect(regioncrit));
121
122             Criteria langcrit = new Criteria();
123             langcrit.add(LanguagePeer.LANGUAGE_ID, 999, Criteria.GREATER_THAN);
124             langcrit.addAscendingOrderByColumn(LanguagePeer.LANGUAGE_NAME);
125             context.put("languages", LanguagePeer.doSelect(langcrit));
126
127             Criteria housecatcrit = new Criteria();
128             housecatcrit.add(HouseholdCategoryPeer.HOUSEHOLD_CAT_ID, 999, Criteria.GREATER_THAN);
129             housecatcrit.addAscendingOrderByColumn(HouseholdCategoryPeer.HOUSEHOLD_CAT_NAME);
130             context.put("householdcats", HouseholdCategoryPeer.doSelect(housecatcrit));
131
132             Criteria educationcrit = new Criteria();
133             educationcrit.add(EducationCategoryPeer.EDUCATION_CAT_ID, 999, Criteria.GREATER_THAN);
134             educationcrit.addAscendingOrderByColumn(EducationCategoryPeer.EDUCATION_CAT_NAME);
135             context.put("educationcats", EducationCategoryPeer.doSelect(educationcrit));
136
137             Criteria vendorcrit = new Criteria();
138             vendorcrit.add(VendorPeer.VENDOR_ID, 999, Criteria.GREATER_THAN);
139             vendorcrit.addAscendingOrderByColumn(VendorPeer.VENDOR_NAME);
140             context.put("vendors", VendorPeer.doSelect(vendorcrit));
141
142             Criteria uomcrit = new Criteria();
143             uomcrit.add(UomPeer.UOM_ID, 900, Criteria.LESS_THAN);
144             Criteria.Criterion criterion = uomcrit.getCriterion(UomPeer.UOM_ID);
145             criterion.or(
146                            uomcrit.getNewCriterion(
147                                          criterion.getTable(),
148                                          criterion.getColumn(),
149                                          new Integer JavaDoc(999),
150                                          Criteria.GREATER_THAN )
151                            );
152             uomcrit.addAscendingOrderByColumn(UomPeer.UOM_NAME);
153             context.put("uoms", UomPeer.doSelect(uomcrit));
154
155             Criteria prodcatcrit = new Criteria();
156             prodcatcrit.add(ProductCategoryPeer.PRODUCT_CAT_ID, 999, Criteria.GREATER_THAN);
157             prodcatcrit.addAscendingOrderByColumn(ProductCategoryPeer.PRODUCT_CAT_NAME);
158             context.put("productcats", ProductCategoryPeer.doSelect(prodcatcrit));
159
160             Criteria projcatcrit = new Criteria();
161             projcatcrit.add(ProjectCategoryPeer.PROJECT_CAT_ID, 999, Criteria.GREATER_THAN);
162             projcatcrit.addAscendingOrderByColumn(ProjectCategoryPeer.PROJECT_CAT_NAME);
163             context.put("projectcats", ProjectCategoryPeer.doSelect(projcatcrit));
164         }
165         catch (Exception JavaDoc e)
166         {
167             // log something ?
168
}
169     }
170
171
172     protected String JavaDoc formatDateTime(Date JavaDoc d)
173     {
174         SimpleDateFormat JavaDoc formatter = new SimpleDateFormat JavaDoc ("dd.MM.yyyy hh:mm:ss");
175         return formatter.format(d);
176     }
177
178     protected String JavaDoc formatDate(Date JavaDoc d)
179     {
180         SimpleDateFormat JavaDoc formatter = new SimpleDateFormat JavaDoc ("dd.MM.yyyy");
181         return formatter.format(d);
182     }
183     
184 }
185
Popular Tags