001: /*
002: Copyright (C) 2003-2006 Know Gate S.L. All rights reserved.
003: C/Oņa, 107 1š2 28050 Madrid (Spain)
004:
005: Redistribution and use in source and binary forms, with or without
006: modification, are permitted provided that the following conditions
007: are met:
008:
009: 1. Redistributions of source code must retain the above copyright
010: notice, this list of conditions and the following disclaimer.
011:
012: 2. The end-user documentation included with the redistribution,
013: if any, must include the following acknowledgment:
014: "This product includes software parts from hipergate
015: (http://www.hipergate.org/)."
016: Alternately, this acknowledgment may appear in the software itself,
017: if and wherever such third-party acknowledgments normally appear.
018:
019: 3. The name hipergate must not be used to endorse or promote products
020: derived from this software without prior written permission.
021: Products derived from this software may not be called hipergate,
022: nor may hipergate appear in their name, without prior written
023: permission.
024:
025: This library is distributed in the hope that it will be useful,
026: but WITHOUT ANY WARRANTY; without even the implied warranty of
027: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
028:
029: You should have received a copy of hipergate License with this code;
030: if not, visit http://www.hipergate.org or mail to info@hipergate.org
031: */
032:
033: package com.knowgate.training;
034:
035: import java.sql.SQLException;
036: import java.sql.PreparedStatement;
037: import java.sql.ResultSet;
038:
039: import java.math.BigDecimal;
040:
041: import com.knowgate.jdc.JDCConnection;
042: import com.knowgate.dataobjs.DB;
043: import com.knowgate.dataobjs.DBPersist;
044: import com.knowgate.crm.Contact;
045:
046: /**
047: * Booking for an academic course
048: * @author Sergio Montoro Ten
049: * @version 1.0
050: */
051: public class AcademicCourseBooking extends DBPersist {
052:
053: public AcademicCourseBooking() {
054: super (DB.k_x_course_bookings, "AcademicCourseBooking");
055: }
056:
057: // ---------------------------------------------------------------------------
058:
059: public AcademicCourseBooking(String sAcademicCourseId,
060: String sContactId) {
061: super (DB.k_x_course_bookings, "AcademicCourseBooking");
062: put(DB.gu_acourse, sAcademicCourseId);
063: put(DB.gu_contact, sContactId);
064: }
065:
066: // ---------------------------------------------------------------------------
067:
068: public AcademicCourseBooking(JDCConnection oConn,
069: String sAcademicCourseId, String sContactId)
070: throws SQLException {
071: super (DB.k_x_course_bookings, "AcademicCourseBooking");
072: load(oConn, new Object[] { sAcademicCourseId, sContactId });
073: }
074:
075: // ---------------------------------------------------------------------------
076:
077: public boolean confirmed() {
078: boolean bRetVal;
079: if (isNull(DB.bo_confirmed))
080: bRetVal = false;
081: else
082: bRetVal = (getShort(DB.bo_confirmed) == (short) 1);
083: return bRetVal;
084: }
085:
086: // ---------------------------------------------------------------------------
087:
088: public boolean paid() {
089: boolean bRetVal;
090: if (isNull(DB.bo_paid))
091: bRetVal = false;
092: else
093: bRetVal = (getShort(DB.bo_paid) == (short) 1);
094: return bRetVal;
095: }
096:
097: // ---------------------------------------------------------------------------
098:
099: public BigDecimal amount() {
100: return getDecimal(DB.im_paid);
101: }
102:
103: // ---------------------------------------------------------------------------
104:
105: public boolean waiting() {
106: boolean bRetVal;
107: if (isNull(DB.bo_waiting))
108: bRetVal = false;
109: else
110: bRetVal = (getShort(DB.bo_waiting) == (short) 1);
111: return bRetVal;
112: }
113:
114: // ---------------------------------------------------------------------------
115:
116: public boolean canceled() {
117: boolean bRetVal;
118: if (isNull(DB.bo_canceled))
119: bRetVal = false;
120: else
121: bRetVal = (getShort(DB.bo_canceled) == (short) 1);
122: return bRetVal;
123: }
124:
125: // ---------------------------------------------------------------------------
126:
127: public AcademicCourseAlumni createAlumni(JDCConnection oConn)
128: throws SQLException {
129: AcademicCourseAlumni oAlmn = new AcademicCourseAlumni();
130: oAlmn.put(DB.gu_acourse, get(DB.gu_acourse));
131: oAlmn.put(DB.gu_alumni, get(DB.gu_contact));
132: if (!isNull(DB.tp_register))
133: oAlmn.put(DB.tp_register, get(DB.tp_register));
134: if (!isNull(DB.id_classroom))
135: oAlmn.put(DB.id_classroom, get(DB.id_classroom));
136: oAlmn.store(oConn);
137: return oAlmn;
138: } // createAlumni
139:
140: // ---------------------------------------------------------------------------
141:
142: public Contact getContact(JDCConnection oConn) throws SQLException,
143: IllegalStateException {
144: if (isNull(DB.gu_contact))
145: throw new IllegalStateException(
146: "AcademicCourseBooking.getContact() gu_contact not set");
147: return new Contact(oConn, getString(DB.gu_contact));
148: }
149:
150: // ---------------------------------------------------------------------------
151:
152: public AcademicCourseAlumni getAlumni(JDCConnection oConn)
153: throws SQLException, IllegalStateException {
154: if (isNull(DB.gu_acourse))
155: throw new IllegalStateException(
156: "AcademicCourseBooking.getAlumni() gu_acourse not set");
157: if (isNull(DB.gu_contact))
158: throw new IllegalStateException(
159: "AcademicCourseBooking.getAlumni() gu_contact not set");
160: return new AcademicCourseAlumni(oConn,
161: getString(DB.gu_acourse), getString(DB.gu_contact));
162: }
163:
164: // ---------------------------------------------------------------------------
165:
166: public boolean isAlumni(JDCConnection oConn) throws SQLException,
167: IllegalStateException {
168: if (isNull(DB.gu_acourse))
169: throw new IllegalStateException(
170: "AcademicCourseBooking.getAlumni() gu_acourse not set");
171: if (isNull(DB.gu_contact))
172: throw new IllegalStateException(
173: "AcademicCourseBooking.getAlumni() gu_contact not set");
174: PreparedStatement oStmt = oConn
175: .prepareStatement("SELECT NULL FROM "
176: + DB.k_x_course_alumni + " WHERE "
177: + DB.gu_acourse + "=? AND " + DB.gu_alumni
178: + "=?");
179: oStmt.setString(1, getString(DB.gu_acourse));
180: oStmt.setString(2, getString(DB.gu_contact));
181: ResultSet oRSet = oStmt.executeQuery();
182: boolean bIsAlumni = oRSet.next();
183: oRSet.close();
184: oStmt.close();
185: return bIsAlumni;
186: } // isAlumni
187:
188: // **********************************************************
189: // Public Constants
190:
191: public static final short ClassId = 65;
192: }
|