Chapter 2 – MegaZillionaire Application
Figure 8 Entry form
One thing which might not be obvious is the “ Deleted:” prompt. You cannot enter a value
here, but when a record which has been flagged for deletion is displayed “*” will display in this
box. Unless you use a lot of VCRtype software the row of buttons containing lessthan and
greaterthan signs might not be intuitive. A single lessthan sign moves towards the beginning,
multiples move to the very beginning. A single greaterthan moves towards the end and multiples
move to the very end.
It probably wasn't the best choice of labels, but “OK” performs either an Add or an Update
depending upon which mode you are currently in. There is no button to set the mode per se. If
you find a record via the “Find” button or one of the navigation buttons, you will be in find mode.
By default the screen starts out in add mode. If you need to get back to add mode you must
“Clear,” which will both clear all entries on the screen and reset the screen back to add mode.
101
Chapter 2 – MegaZillionaire Application
Figure 9 Browse form
Although it is against my religion to design applications which load every record from a
database into a spreadsheet, that is what end users have come to expect thanks to the world's
lowest quality software vendor, Microsoft. Nobody with even the tiniest shred of computer
science education would ever consider getting users
used
to seeing data displayed this way. It
works only under the condition which lets it work here: a very limited set of data stored locally
and access read only. I did it because most of you were going to whine and snivel about wanting
to do it.
Most of you reading this book will not have had professional software development training.
I cover this topic quite a bit in the OpenVMS Application Developer book (ISBN13
9780977086603) and the SOA book (ISBN13 9780977086665). The spreadsheet design
is horribly inefficient. I'm not talking about the code to create the spreadsheet itself, I'm talking
about the concepts behind the design. It is a resourceintensive pig that imposes severe data
access restrictions by requiring either exclusive access to the entire data set, or a live data monitor
a user clicked on the Search or Find button the application would perform indexed look up logic
against the database and display up to 5 records. While that design may not seem as slick as being
able to drag a scroll bar through a spreadsheet, it works at all resource levels. The poor Schmoe
who was given a corporate desktop running Windows XP with only 256Meg of RAM can use it
just as easily as the power user and their 2+Ghz multicore CPU with 4GB or RAM.
103
Chapter 2 – MegaZillionaire Application
2.2
2.22.2
2.22.2
2.2
Supporting Classes
Supporting ClassesSupporting Classes
Supporting ClassesSupporting Classes
Supporting Classes
MegaDBF.java
1) package com.logikal.megazillxBaseJ;
2)
3) import java.io.*;
4) import java.util.*;
5) import org.xBaseJ.*;
6) import org.xBaseJ.fields.*;
7) import org.xBaseJ.Util.*;
8) import org.xBaseJ.indexes.NDX;
9)
10) public class MegaDBF {
11)
12) // variables used by the class
13) //
14) private DBF aDB = null;
45)
46)
47) //;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
48) // Method to populate known class level field objects.
49) // This was split out into its own method so it could be used
50) // by either the open or the create.
51) //;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
52) private void attach_fields( boolean created_flg) {
53) try {
54) if ( created_flg) {
55) //Create the fields
56) Draw_Dt = new DateField( "DrawDt");
57) No_1 = new NumField( "No1", 2, 0);
58) No_2 = new NumField( "No2", 2, 0);
59) No_3 = new NumField( "No3", 2, 0);
104
Chapter 2 – MegaZillionaire Application
60) No_4 = new NumField( "No4", 2, 0);
61) No_5 = new NumField( "No5", 2, 0);
62) Mega_No = new NumField( "MegaNo", 2, 0);
63)
64) //Add field definitions to database
65) aDB.addField(Draw_Dt);
66) aDB.addField(No_1);
67) aDB.addField(No_2);
68) aDB.addField(No_3);
69) aDB.addField(No_4);
70) aDB.addField(No_5);
71) aDB.addField(Mega_No);
72)
103) }
104) } catch (IOException i) {}
105)
106) } // end close_database method
107)
108) //;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
109) // Method to create a shiny new database
110) //;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
111) public void create_database() {
112) try {
113) //Create a new dbf file
114) aDB=new DBF(DEFAULT_DB_NAME,true);
115)
116) attach_fields(true);
117)
118) aDB.createIndex(DEFAULT_K0_NAME,"DrawDt",true,true);
119) dbOpen = true;
120) } catch( xBaseJException j){
121) System.out.println( "xBaseJ Error creating database");
122) j.printStackTrace();
105
Chapter 2 – MegaZillionaire Application
123) continue_flg = false;
124) } // end catch
125) catch( IOException i){
126) System.out.println( "IO Error creating database");
127) i.printStackTrace();
128) continue_flg = false;
129) } // end catch IOException
130) } // end create_database method
161) aDB.useIndex( DEFAULT_K0_NAME);
162) dbOpen = true;
163) reIndex(); // gets around problem with stale index info
164)
165) } catch( xBaseJException j){
166) continue_flg = false;
167) } // end catch
168) catch( IOException i){
169) continue_flg = false;
170) } // end catch IOException
171)
172) if (!continue_flg) {
173) continue_flg = true;
174) System.out.println( "Open failed, attempting create");
175) create_database();
176) } // end test for open failure
177)
178) if (isOpen())
179) return MEGA_SUCCESS;
180) else
181) return MEGA_FILE_OPEN_ERR;
182) } // end open_database method
183)
184) //;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
185) // Method to re-index all of the associated index files.
106
Chapter 2 – MegaZillionaire Application
186) //;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
187) public void reIndex() {
188) if (aDB != null) {
218) ret_val = MEGA_KEY_NOT_FOUND;
219) }
220) } catch( xBaseJException j){
221) System.out.println( j.getMessage());
222) ret_val = MEGA_KEY_NOT_FOUND;
223) } // end catch
224) catch( IOException i){
225) ret_val = MEGA_KEY_NOT_FOUND;
226) } // end catch IOException
227)
228) return ret_val;
229) } // end find_EQ_record method
230)
231) public int find_GE_record( String d) {
232) int ret_val = MEGA_SUCCESS;
233)
234) if (!dbOpen)
235) return MEGA_FILE_OPEN_ERR;
236)
237) try {
238) aDB.find( d);
239) } catch( xBaseJException j){
240) ret_val = MEGA_KEY_NOT_FOUND;
241) } // end catch
242) catch( IOException i){
243) ret_val = MEGA_KEY_NOT_FOUND;
244) } // end catch IOException
245)
246) return ret_val;
247) } // end find_GE_record method
your application on your computer, you should always call reIndex() after opening an existing
NDX file anyway.
StatElms.java
1) package com.logikal.megazillxBaseJ;
2)
3) public class StatElms extends Object {
4) public int elmNo, hitCount, lastDrawNo, sinceLast, currSeq,
5) longestSeq, maxBtwn;
6) public double pctHits, aveBtwn;
7) } // end StatElms class
108