-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventData.java
299 lines (252 loc) · 11 KB
/
eventData.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
//******************************************************************************
// Filename : eventData.java
// Project : PhotoMarathon
// Description : Data Relating to Event
// Author : Simon Thompson
// Requires : Java 1.7 or later
// Licence : GPL v3
// Copyright : Simon Thompson MMXIV
//
// This file is part of PhotoMarathon.
//
// PhotoMarathon is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PhotoMarathon is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
//******************************************************************************
package photomarathon;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import photomarathon.sqlLiteHandler.sqliteFile;
/**
*
* @author cy
*/
public class eventData {
String eventName = "PhotoMarathon";
String eventLocation = "";
String eventAddress = "";
String eventLogoFilename = "";
Date competitionStart;
Date competitionEnd;
Date deliveryStart;
Date deliveryEnd;
String deliveryAddress = "";
String deliveryMapFilename = "";
String organisers = "";
sqliteFile sqf;
Statement stmt = null;
String tableName = "EVENTS";
Connection c;
boolean tableExists = false;
int maxId = 0;
public eventData(String eventName, String eventLocation, String eventAddress, String eventLogoFilename, Date competitionStart, Date competitionEnd, Date deliveryStart, Date deliveryEnd, String deliveryAddress, String deliveryMapFilename, String organisers, sqliteFile sqf) {
this.eventName = eventName;
this.eventLocation = eventLocation;
this.eventAddress = eventAddress;
this.eventLogoFilename = eventLogoFilename;
this.competitionStart = competitionStart;
this.competitionEnd = competitionEnd;
this.deliveryStart = deliveryStart;
this.deliveryEnd = deliveryEnd;
this.deliveryAddress = deliveryAddress;
this.deliveryMapFilename = deliveryMapFilename;
this.organisers = organisers;
this.sqf = sqf;
this.c = sqf.getC();
}
public eventData(sqliteFile sqf) {
this.sqf = sqf;
this.c = sqf.getC();
}
public void addEventData(String eventName, String eventLocation, String eventAddress, String eventLogoFilename, Date competitionStart, Date competitionEnd, Date deliveryStart, Date deliveryEnd, String deliveryAddress, String deliveryMapFilename, String organisers) {
this.eventName = eventName;
this.eventLocation = eventLocation;
this.eventAddress = eventAddress;
this.eventLogoFilename = eventLogoFilename;
this.competitionStart = competitionStart;
this.competitionEnd = competitionEnd;
this.deliveryStart = deliveryStart;
this.deliveryEnd = deliveryEnd;
this.deliveryAddress = deliveryAddress;
this.deliveryMapFilename = deliveryMapFilename;
this.organisers = organisers;
}
public void testAndCreateTable() {
Vector v = sqf.listTables(false);
for (int i = 0; i < v.size(); i++) {
String test = (String)v.elementAt(i);
if(test.equalsIgnoreCase(tableName)) {
tableExists = true;
System.out.println("......TABLE FOUND: " + tableName);
}
}
if(!tableExists) {
System.out.println("......CREATING TABLE: " + tableName);
try {
stmt = c.createStatement();
String sql = "CREATE TABLE " + tableName + " " +
"(ID INT PRIMARY KEY NOT NULL," +
" NAME CHAR(200) NOT NULL," +
" LOCATION CHAR(200) NOT NULL," +
" ADDRESS CHAR(200) NOT NULL," +
" LOGO CHAR(200) NOT NULL," +
" START CHAR(200) NOT NULL," +
" END CHAR(200) NOT NULL," +
" DSTART CHAR(200) NOT NULL," +
" DEND CHAR(200) NOT NULL," +
" DADDRESS CHAR(200) NOT NULL," +
" DMAP CHAR(200) NOT NULL," +
" ORGANISER CHAR(200) NOT NULL);";
System.out.println(sql);
stmt.executeUpdate(sql);
stmt.close();
c.commit();
} catch (SQLException ex) {
Logger.getLogger(eventData.class.getName()).log(Level.SEVERE, null, ex);
}
}
else if(tableExists) {
System.out.println(".........Reading Table");
try {
//SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm");
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
stmt = c.createStatement();
ResultSet rs = stmt.executeQuery( "SELECT * FROM " + tableName + ";" );
while ( rs.next() ) {
int id = rs.getInt("id");
this.eventName = rs.getString("name");
System.out.println("............Name: " + eventName);
this.eventLocation = rs.getString("location");
System.out.println("............Location: " + eventLocation);
this.eventAddress = rs.getString("address");
System.out.println("............Address: " + eventAddress);
this.eventLogoFilename = rs.getString("logo");
System.out.println("............Logo File: " + eventLogoFilename);
this.competitionStart = sdf.parse(rs.getString("start"));
System.out.println("............Start: " + competitionStart);
this.competitionEnd = sdf.parse(rs.getString("end"));
System.out.println("............End: " + competitionEnd);
this.deliveryStart = sdf.parse(rs.getString("dstart"));
System.out.println("............Delivery Start: " + deliveryStart);
this.deliveryEnd = sdf.parse(rs.getString("dend"));
System.out.println("............DeliveryEnd: " + deliveryEnd);
this.deliveryAddress = rs.getString("daddress");
System.out.println("............Delivery Address: " + deliveryAddress);
this.deliveryMapFilename = rs.getString("dmap");
System.out.println("............Delivery Map: " + deliveryMapFilename);
this.organisers = rs.getString("organiser");
System.out.println("............Organiser: " + organisers);
}
rs.close();
stmt.close();
c.commit();
}
catch (Exception e) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0);
}
}
}
public void addToSql() {
maxId++;
try{
stmt = c.createStatement();
String sql = "INSERT INTO " + tableName + " (ID,NAME,LOCATION,ADDRESS,LOGO,START,END,DSTART,DEND,DADDRESS,DMAP,ORGANISER) " +
"VALUES (" + maxId + ",'" + eventName + "','"+eventLocation+"','"+eventAddress+"','"+eventLogoFilename+"','"+competitionStart +"','"+competitionEnd+"','"+deliveryStart+"','"+deliveryEnd+"','"+deliveryAddress+"','"+deliveryMapFilename +"','"+organisers + "');";
System.out.println(sql);
stmt.executeUpdate(sql);
stmt.close();
c.commit();
}
catch(Exception e){
System.err.println( e );
System.exit(0);
}
}
public Date getCompetitionEnd() {
return competitionEnd;
}
public void setCompetitionEnd(Date competitionEnd) {
this.competitionEnd = competitionEnd;
}
public Date getCompetitionStart() {
return competitionStart;
}
public void setCompetitionStart(Date competitionStart) {
this.competitionStart = competitionStart;
}
public String getDeliveryAddress() {
return deliveryAddress;
}
public void setDeliveryAddress(String deliveryAddress) {
this.deliveryAddress = deliveryAddress;
}
public Date getDeliveryEnd() {
return deliveryEnd;
}
public void setDeliveryEnd(Date deliveryEnd) {
this.deliveryEnd = deliveryEnd;
}
public String getDeliveryMapFilename() {
return deliveryMapFilename;
}
public void setDeliveryMapFilename(String deliveryMapFilename) {
this.deliveryMapFilename = deliveryMapFilename;
}
public Date getDeliveryStart() {
return deliveryStart;
}
public void setDeliveryStart(Date deliveryStart) {
this.deliveryStart = deliveryStart;
}
public String getEventAddress() {
return eventAddress;
}
public void setEventAddress(String eventAddress) {
this.eventAddress = eventAddress;
}
public String getEventLocation() {
return eventLocation;
}
public void setEventLocation(String eventLocation) {
this.eventLocation = eventLocation;
}
public String getEventLogoFilename() {
return eventLogoFilename;
}
public void setEventLogoFilename(String eventLogoFilename) {
this.eventLogoFilename = eventLogoFilename;
}
public String getEventName() {
return eventName;
}
public void setEventName(String eventName) {
this.eventName = eventName;
}
public String getOrganisers() {
return organisers;
}
public void setOrganisers(String organisers) {
this.organisers = organisers;
}
@Override
public String toString() {
return "eventData{" + "eventName=" + eventName + ", eventLocation=" + eventLocation + ", eventAddress=" + eventAddress + ", eventLogoFilename=" + eventLogoFilename + ", competitionStart=" + competitionStart + ", competitionEnd=" + competitionEnd + ", deliveryStart=" + deliveryStart + ", deliveryEnd=" + deliveryEnd + ", deliveryAddress=" + deliveryAddress + ", deliveryMapFilename=" + deliveryMapFilename + ", organisers=" + organisers + '}';
}
}