R
RFleming
I am using Netbeans 5.5.1. I am using the designer to create a JFrame
with some swing components. One of them is a third party datepicker.
It requires a JAR file. I have tried two different datepickers. I have
the same problem (Described Below).
I can run the application just fine when not using WebStart. I can run
the application using WebStart if I delete the datepicker control.
I edit the JNLP file and add the datepicker.jar file as eager and also
tried as lazy using Netbeans.
When I run the application using Web Start a java.exe process is
created I have to kill the process as I can not exit it because no
Jframe is loaded.
If I use Debug and Webstart, the code goes into the init method and
works fine until it gets to the DatePicker dp = new DatePicker();
No errors are generated, but no GUI is drawn and the NetBeans IDE
stops stepping through the code at this point.
Any Suggestions would be greatly appreciated!
Here is an example of the code, note where the program stops is all
'automagically' done by netbeans. The program when using webstart
never makes it to my code.... I added comments in the Init method
around the code that stops the program, it is only about 50 lines down
from here.
Here is the code..... Below the code is a copy of the JNLP file as
well.....
/*
* frmRaceRepor.java
*
* Created on November 22, 2007, 3:50 PM
*/
package racereporter;
import java.sql.SQLException;
import java.text.FieldPosition;
import java.text.ParsePosition;
import java.util.ArrayList;
/**
*
* @author rtf
*/
public class frmRaceReport extends javax.swing.JFrame {
/** Creates new form frmRaceRepor */
public frmRaceReport() {
initComponents();
blnStartup = false;
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code
">
private void initComponents() {
jSeparator1 = new javax.swing.JSeparator();
cmbRaceReport = new javax.swing.JComboBox();
cmbRaceClass = new javax.swing.JComboBox();
cmbRaceEvents = new javax.swing.JComboBox();
btExit = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
txtRiderInfo = new javax.swing.JTextArea();
//
***************************************************************************************************
// ************************* CODE STOPS STEPPING HERE
*****************************
dtpDateTime = new datechooser.beans.DateChooserCombo();
//
***************************************************************************************************
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
cmbRaceReport.setMaximumRowCount(100);
cmbRaceReport.setToolTipText("Select A Race Venue To View
Reports");
cmbRaceReport.setBorder(null);
cmbRaceReport.setMaximumSize(new java.awt.Dimension(200, 20));
cmbRaceReport.setMinimumSize(new java.awt.Dimension(100, 20));
cmbRaceReport.setPreferredSize(new java.awt.Dimension(100,
20));
cmbRaceReport.setVisible(false);
cmbRaceReport.removeAllItems();
cmbRaceReport.addItem("Please Select A Report");
cmbRaceReport.addItem("Current Class Race Results");
cmbRaceReport.addItem("Preliminary Results Elapsed Times");
cmbRaceReport.addItem("Preliminary Results Lap Times");
cmbRaceReport.addItem("Rider Race Position By Lap");
cmbRaceReport.addItem("Fastest Lap Times Lap 1");
cmbRaceReport.addItem("Fastest Lap Times All Others");
cmbRaceReport.addItem("Race Official Report");
cmbRaceReport.addItem("Current Season Points");
cmbRaceReport.addItem("Various Rider Statistics");
cmbRaceReport.addItemListener(new
java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt)
{
cmbRaceReportItemStateChanged(evt);
}
});
cmbRaceClass.setMaximumRowCount(100);
cmbRaceClass.setToolTipText("Select A Race Venue To View
Reports");
cmbRaceClass.setBorder(null);
cmbRaceClass.setMaximumSize(new java.awt.Dimension(51, 20));
cmbRaceClass.setMinimumSize(new java.awt.Dimension(51, 20));
cmbRaceClass.setPreferredSize(new java.awt.Dimension(51, 20));
cmbRaceClass.setVisible(false);
cmbRaceClass.addItemListener(new java.awt.event.ItemListener()
{
public void itemStateChanged(java.awt.event.ItemEvent evt)
{
cmbRaceClassItemStateChanged(evt);
}
});
cmbRaceEvents.setMaximumRowCount(100);
cmbRaceEvents.setToolTipText("Select A Race Venue To View
Reports");
cmbRaceEvents.setBorder(null);
cmbRaceEvents.setMaximumSize(new java.awt.Dimension(51, 20));
cmbRaceEvents.setMinimumSize(new java.awt.Dimension(51, 20));
cmbRaceEvents.setPreferredSize(new java.awt.Dimension(51,
20));
cmbRaceEvents.setVisible(false);
cmbRaceEvents.addItemListener(new
java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt)
{
cmbRaceEventsItemStateChanged(evt);
}
});
btExit.setBackground(new java.awt.Color(255, 204, 204));
btExit.setText("EXIT");
btExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
btExitActionPerformed(evt);
}
});
txtRiderInfo.setColumns(20);
txtRiderInfo.setEditable(false);
txtRiderInfo.setFont(new java.awt.Font("Courier New", 0, 12));
txtRiderInfo.setRows(5);
jScrollPane1.setViewportView(txtRiderInfo);
dtpDateTime.addCommitListener(new
datechooser.events.CommitListener() {
public void onCommit(datechooser.events.CommitEvent evt) {
dtpDateTimeOnCommit(evt);
}
});
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(dtpDateTime,
javax.swing.GroupLayout.PREFERRED_SIZE, 191,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmbRaceEvents,
javax.swing.GroupLayout.PREFERRED_SIZE, 165,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmbRaceClass,
javax.swing.GroupLayout.PREFERRED_SIZE, 165,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmbRaceReport,
javax.swing.GroupLayout.PREFERRED_SIZE, 165,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
155, Short.MAX_VALUE)
.addComponent(btExit)
.addContainerGap())
.addComponent(jSeparator1,
javax.swing.GroupLayout.DEFAULT_SIZE, 934, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1,
javax.swing.GroupLayout.DEFAULT_SIZE, 914, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmbRaceEvents,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cmbRaceClass,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cmbRaceReport,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btExit,
javax.swing.GroupLayout.PREFERRED_SIZE, 23,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(dtpDateTime,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator1,
javax.swing.GroupLayout.PREFERRED_SIZE, 10,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1,
javax.swing.GroupLayout.DEFAULT_SIZE, 455, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void dtpDateTimeOnCommit(datechooser.events.CommitEvent
evt) {
if (openRaceDatabase()){
long lngCount = 0;
try {
java.sql.Statement stmt;
stmt = cnRaceDatabase.createStatement();
java.sql.ResultSet rs = stmt.executeQuery("Select
count(*) From [Master Race Table] Where [Race Date] = #" +
dtpDateTime.getText() + "#");
while (rs.next()){
lngCount = rs.getLong(1);
}
rs.close();
if (lngCount > 0){
rs = stmt.executeQuery("Select [ID], [Race Venue],
[Classes Allowed] From [Master Race Table] Where [Race Date] = #" +
dtpDateTime.getText() + "#");
aryMasterRaceClassesAllowed.clear();
aryRaceID.clear();
cmbRaceEvents.removeAllItems();
//Add Combo Instruction
aryMasterRaceClassesAllowed.add("");
aryRaceID.add(-1);
cmbRaceEvents.addItem("Please Select A Race
Event");
while (rs.next()){
aryMasterRaceClassesAllowed.add(rs.getString("Classes Allowed"));
aryRaceID.add(rs.getInt("ID"));
cmbRaceEvents.addItem(rs.getString("Race
Venue"));
}
cmbRaceEvents.setVisible(true);
} else{
cmbRaceEvents.setVisible(false);
cmbRaceClass.setVisible(false);
cmbRaceReport.setVisible(false);
javax.swing.JOptionPane.showMessageDialog(null,
"No Race Events Found For This Date", "No Races Found",
javax.swing.JOptionPane.OK_OPTION);
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
private void btExitActionPerformed(java.awt.event.ActionEvent evt)
{
System.exit(0);
}
private void
cmbRaceEventsItemStateChanged(java.awt.event.ItemEvent evt)
{
if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED
&& blnBuildingRaceEvents == false && cmbRaceEvents.getSelectedIndex()
aryMasterRaceClassesAllowed.get(cmbRaceEvents.getSelectedIndex()).split(",");
String strClassQuery = "";
for (int i=0; i < strClassesAllowed.length; i++){
if (i == (strClassesAllowed.length - 1)){
strClassQuery = strClassQuery +
strClassesAllowed;
} else {
strClassQuery = strClassQuery +
strClassesAllowed + " Or [ID] = ";
}
}
if (openRaceDatabase()){
try {
java.sql.Statement
stmt=cnRaceDatabase.createStatement();
stmt=cnRaceDatabase.createStatement();
java.sql.ResultSet rs=stmt.executeQuery("Select *
From [Master Class Table] Where [ID] = " + strClassQuery);
blnBuildingRaceClasses = true;
aryClassID.clear();
cmbRaceClass.removeAllItems();
cmbRaceClass.addItem("Please Select A Class");
aryClassID.add(-1);
cmbRaceClass.addItem("All Classes");
aryClassID.add(0);
while(rs.next()){
cmbRaceClass.addItem(rs.getString("Class
Description"));
aryClassID.add(rs.getInt("ID"));
}
cmbRaceClass.setVisible(true);
blnBuildingRaceClasses = false;
stmt.close();
} catch(java.sql.SQLException e){
System.err.println("SQL Exception found! " +
e.getMessage());
}
}
} else if (cmbRaceClass.getSelectedIndex() == 0){
cmbRaceReport.setVisible(false);
cmbRaceClass.setVisible(false);
}
}
private void cmbRaceClassItemStateChanged(java.awt.event.ItemEvent
evt) {
if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED
&& blnBuildingRaceClasses == false && cmbRaceClass.getSelectedIndex()
cmbRaceReport.setSelectedIndex(0);
} else if (cmbRaceClass.getSelectedIndex() == 0){
cmbRaceReport.setVisible(false);
}
}
private void
cmbRaceReportItemStateChanged(java.awt.event.ItemEvent evt)
{
if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED
&& cmbRaceReport.getSelectedIndex() > 0) {
//Build Class Query String
String strClassString;
if (cmbRaceClass.getSelectedIndex() == 1) { //All
Classes
strClassString = "> 0";
} else {
strClassString = " = " +
Integer.toString(aryClassID.get(cmbRaceClass.getSelectedIndex()));
}
//Build Database Variables
java.sql.Statement stmt;
java.sql.Statement stmt_modified;
java.sql.ResultSet rs;
java.sql.ResultSet rs_modified;
if (cmbRaceReport.getSelectedIndex() == 1){
if (openRaceDatabase()){
readAndSort();
String QueryString1 = "Select * FROM [Master Rider
Table] Where [Race ID] = " +
Integer.toString(aryRaceID.get(cmbRaceEvents.getSelectedIndex())) + "
AND [Class ID]" + strClassString + " Order By [Rider Disqualified]
DESC, [Laps Completed] DESC";
String QueryString2 = "Select * FROM [Modified
Rider Records] Where [Race ID] = " +
Integer.toString(aryRaceID.get(cmbRaceEvents.getSelectedIndex())) + "
AND [Class ID]" + strClassString + " Order By [Rider Disqualified]
DESC, [Laps Completed] DESC";
try {
stmt =
cnRaceDatabase.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
stmt_modified =
cnRaceDatabase.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(QueryString1);
rs_modified =
stmt_modified.executeQuery(QueryString2);
int intPosition = 1;
String strRiderInfo = "";
strRiderInfo =
(String)cmbRaceClass.getSelectedItem() + " Preliminary Race Results
Report.\r\nAll Total Elapsed Times Are Based From The Start Of The
First Heat.\r\n\r\n";
strRiderInfo = strRiderInfo + "|Place|
Number| Rider Name | Rider Ride |DIST|LAPS| DNF |Total
Time |\r\n";
strRiderInfo = strRiderInfo + "|_____|
______|___________________|________________|____|____|_____|
______________|\r\n";
for (int intReportIndex = 1;
intReportIndex <= intRacerCount; intReportIndex++){
if (blnRiderModified[intReportIndex]
== false){
rs.beforeFirst();
while (rs.next()){
if
(lngRiderIDValue[intReportIndex] == rs.getLong("ID")){
if (rs.getBoolean("Rider
Present") == true){
String strRiderNumber
= rs.getString("Rider Number");
String
strRiderFirstName = rs.getString("First Name");
String
strRiderLastName = rs.getString("Last Name");
String strRiderBrand =
rs.getString("Brand");
String
strRiderDisplacement = rs.getString("Displacement");
String
strRiderDistrict = rs.getString("Rider District Number");
String
strRiderLapsCompleted = rs.getString("Laps Completed");
String strRiderDNF =
"False";
if
(rs.getBoolean("Rider DNF")){
strRiderDNF =
"True";
}
if
(rs.getBoolean("Rider Disqualified") == true){
strRiderInfo =
strRiderInfo + " DQ" + " " + retForceStringWidth(strRiderNumber, 6,
InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderFirstName + " " + strRiderLastName, 19,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderBrand
+ " " + strRiderDisplacement, 16, InsertionLocation.inCenter) + " " +
retForceStringWidth(strRiderDistrict, 4, InsertionLocation.inCenter) +
" " + retForceStringWidth(strRiderLapsCompleted, 4,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderDNF,
5, InsertionLocation.inCenter) + " ";
} else{
strRiderInfo =
strRiderInfo + " " +
retForceStringWidth(Integer.toString(intPosition), 3,
InsertionLocation.inLeft) + " " + retForceStringWidth(strRiderNumber,
6, InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderFirstName + " " + strRiderLastName, 19,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderBrand
+ " " + strRiderDisplacement, 16, InsertionLocation.inCenter) + " " +
retForceStringWidth(strRiderDistrict, 4, InsertionLocation.inCenter) +
" " + retForceStringWidth(strRiderLapsCompleted, 4,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderDNF,
5, InsertionLocation.inCenter) + " ";
intPosition =
intPosition + 1;
}
if
(Integer.parseInt(strRiderLapsCompleted) > 0){
long lngTotalTime
= rs.getLong("Lap" + strRiderLapsCompleted);
java.util.Date
dtNow = new java.util.Date();
java.util.Date
dtStartTime = new java.util.Date();
dtStartTime.setTime(dtNow.getTime() - (lngTotalTime * 1000)); //
Subtract TotalTime in milliseconds (lngTotalTime is in Seconds So must
Be Converted)
strRiderInfo =
strRiderInfo + retForceStringWidth(retElapsedTime(dtStartTime, dtNow,
true), 14, InsertionLocation.inCenter) + "\r\n";
} else{
strRiderInfo =
strRiderInfo + retForceStringWidth("---", 14,
InsertionLocation.inCenter) + "\r\n";
}
}
break;
}
}
} else{
rs_modified.beforeFirst();
while (rs_modified.next()) {
if
(lngRiderIDValue[intReportIndex] == rs_modified.getLong("ID")){
if
(rs_modified.getBoolean("Rider Present") == true){
String strRiderNumber
= rs_modified.getString("Rider Number");
String
strRiderFirstName = rs_modified.getString("First Name");
String
strRiderLastName = rs_modified.getString("Last Name");
String strRiderBrand =
rs_modified.getString("Brand");
String
strRiderDisplacement = rs_modified.getString("Displacement");
String
strRiderDistrict = rs_modified.getString("Rider District Number");
String
strRiderLapsCompleted = rs_modified.getString("Laps Completed");
String strRiderDNF =
"False";
if
(rs_modified.getBoolean("Rider DNF")){
strRiderDNF =
"True";
}
if
(rs_modified.getBoolean("Rider Disqualified") == true){
strRiderInfo =
strRiderInfo + " DQ" + " " + retForceStringWidth(strRiderNumber, 6,
InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderFirstName + " " + strRiderLastName, 19,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderBrand
+ " " + strRiderDisplacement, 16, InsertionLocation.inCenter) + " " +
retForceStringWidth(strRiderDistrict, 4, InsertionLocation.inCenter) +
" " + retForceStringWidth(strRiderLapsCompleted, 4,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderDNF,
5, InsertionLocation.inCenter) + " ";
} else{
strRiderInfo =
strRiderInfo + " " +
retForceStringWidth(Integer.toString(intPosition), 3,
InsertionLocation.inLeft) + " " + retForceStringWidth(strRiderNumber,
6, InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderFirstName + " " + strRiderLastName, 19,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderBrand
+ " " + strRiderDisplacement, 16, InsertionLocation.inCenter) + " " +
retForceStringWidth(strRiderDistrict, 4, InsertionLocation.inCenter) +
" " + retForceStringWidth(strRiderLapsCompleted, 4,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderDNF,
5, InsertionLocation.inCenter) + " ";
intPosition =
intPosition + 1;
}
if
(Integer.parseInt(strRiderLapsCompleted) > 0){
long lngTotalTime
= rs_modified.getLong("Lap" + strRiderLapsCompleted);
java.util.Date
dtNow = new java.util.Date();
java.util.Date
dtStartTime = new java.util.Date();
dtStartTime.setTime(dtNow.getTime() - (lngTotalTime * 1000)); //
Subtract TotalTime in milliseconds (lngTotalTime is in Seconds So must
Be Converted)
strRiderInfo =
strRiderInfo + retForceStringWidth(retElapsedTime(dtStartTime, dtNow,
true), 14, InsertionLocation.inCenter) + "\r\n";
} else{
strRiderInfo =
strRiderInfo + retForceStringWidth("---", 14,
InsertionLocation.inCenter) + "\r\n";
}
}
}
}
}
}
txtRiderInfo.setText(strRiderInfo);
} catch (SQLException ex) {
ex.printStackTrace();
}
}
} else if (cmbRaceReport.getSelectedIndex() == 2 ||
cmbRaceReport.getSelectedIndex() == 3){
readAndSort();
String QueryString1 = "Select * FROM [Master Rider
Table] Where [Race ID] = " +
Integer.toString(aryRaceID.get(cmbRaceEvents.getSelectedIndex())) + "
AND [Class ID]" + strClassString + " Order By [Rider Disqualified]
DESC, [Laps Completed] DESC";
String QueryString2 = "Select * FROM [Modified
Rider Records] Where [Race ID] = " +
Integer.toString(aryRaceID.get(cmbRaceEvents.getSelectedIndex())) + "
AND [Class ID]" + strClassString + " Order By [Rider Disqualified]
DESC, [Laps Completed] DESC";
try {
stmt =
cnRaceDatabase.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
stmt_modified =
cnRaceDatabase.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(QueryString1);
rs_modified =
stmt_modified.executeQuery(QueryString2);
int intPosition = 1;
String strRiderInfo = "";
if (cmbRaceReport.getSelectedIndex() == 2){
strRiderInfo =
(String)cmbRaceClass.getSelectedItem() + " Preliminary Race Results
Report.\r\nAll Total Elapsed Times Are Based From The Start Of The
First Heat.\r\n\r\n";
} else{
strRiderInfo =
(String)cmbRaceClass.getSelectedItem() + " Preliminary Race Results
Report.\r\nAll Lap Times Are Based From The Start Of Each Riders Class.
\r\n\r\n";
}
strRiderInfo = strRiderInfo + "|Number|
Rider Name |DIST|LAPS|POS|Disql| DNF |";
int intNumberOfLaps =
this.getNumberOfLaps(aryRaceID.get(cmbRaceEvents.getSelectedIndex()));
for (int intLap = 1; intLap <=
intNumberOfLaps; intLap++){
strRiderInfo = strRiderInfo + " Lap" +
intLap + " Time " + "|";
}
strRiderInfo = strRiderInfo + " Total Time |
\r\n";
strRiderInfo = strRiderInfo + "|______|
___________________|____|____|___|_____|_____|";
for (int intLap = 1; intLap <=
intNumberOfLaps; intLap++){
strRiderInfo = strRiderInfo +
"_____________|";
}
strRiderInfo = strRiderInfo + "______________|
\r\n";
for (int intReportIndex = 1; intReportIndex <=
intRacerCount; intReportIndex++){
if (blnRiderModified[intReportIndex] ==
false){
rs.beforeFirst();
while(rs.next()){
System.out.println(lngRiderIDValue[intReportIndex] + " = " +
rs.getLong("ID"));
if
(lngRiderIDValue[intReportIndex] == rs.getLong("ID")){
if (rs.getBoolean("Rider
Present") == true){
String strRiderNumber =
rs.getString("Rider Number");
String strRiderFirstName =
rs.getString("First Name");
String strRiderLastName =
rs.getString("Last Name");
String strRiderBrand =
rs.getString("Brand");
String
strRiderDisplacement = rs.getString("Displacement");
String strRiderDistrict =
rs.getString("Rider District Number");
String
strRiderLapsCompleted = rs.getString("Laps Completed");
long lngClassOffset =
rs.getLong("Class Offset");
String
strRiderDisqualified = "False";
if (rs.getBoolean("Rider
Disqualified")){
strRiderDisqualified =
"True";
}
String strRiderDNF =
"False";
if (rs.getBoolean("Rider
DNF")){
strRiderDNF = "True";
}
if
(cmbRaceReport.getSelectedIndex() == 2){
if
(rs.getBoolean("Rider Disqualified") == true){
//strRiderInfo =
strRiderInfo + " " + retForceStringWidth(rsReports![Rider Number], 6,
inright) & " " & ForceStringWidth(rsReports!
[First Name] & " " & rsReports![Last Name], 19, InCenter) & " "
& ForceStringWidth(rsReports![Rider District Number], 4,
InCenter) & " " & ForceStringWidth(rsReports![Laps Completed], 4,
InCenter) & " " & ForceStringWidth("DQ", 3, inleft)
& " " & ForceStringWidth(rsReports![Rider
Disqualified], 5, InCenter) & " " &
ForceStringWidth(rsReports![Rider DNF], 5, InCenter) & " "
strRiderInfo =
strRiderInfo + " " + retForceStringWidth(strRiderNumber, 6,
InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderFirstName + " " + strRiderLastName, 19,
InsertionLocation.inCenter) + " " +
retForceStringWidth(strRiderDistrict, 4, InsertionLocation.inCenter) +
" " + retForceStringWidth(strRiderLapsCompleted, 4,
InsertionLocation.inCenter) + " " + retForceStringWidth("DQ", 3,
InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderDisqualified, 5,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderDNF,
5, InsertionLocation.inCenter) + " ";
} else{
// txtRiderInfo.Text =
txtRiderInfo.Text & " " & ForceStringWidth(rsReports![Rider Number],
6, inright) & " " & ForceStringWidth(rsReports!
[First Name] & " " & rsReports![Last Name], 19, InCenter) & " "
& ForceStringWidth(rsReports![Rider District Number], 4,
InCenter) & " " & ForceStringWidth(rsReports![Laps Completed], 4,
InCenter) & " " & ForceStringWidth(CStr(Position), 3,
inleft) & " " &
ForceStringWidth(rsReports![Rider Disqualified], 5, InCenter) & " " &
ForceStringWidth(rsReports![Rider DNF], 5, InCenter) & " "
strRiderInfo =
strRiderInfo + " " + retForceStringWidth(strRiderNumber, 6,
InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderFirstName + " " + strRiderLastName, 19,
InsertionLocation.inCenter) + " " +
retForceStringWidth(strRiderDistrict, 4, InsertionLocation.inCenter) +
" " + retForceStringWidth(strRiderLapsCompleted, 4,
InsertionLocation.inCenter) + " " +
retForceStringWidth(Integer.toString(intPosition), 3,
InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderDisqualified, 5,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderDNF,
5, InsertionLocation.inCenter) + " ";
}
} else{
if
(rs.getBoolean("Rider Disqualified") == true){
// txtRiderInfo.Text =
txtRiderInfo.Text & " " & ForceStringWidth(rsReports![Rider Number],
6, inright) & " " &
ForceStringWidth(rsReports![First Name] & " " & rsReports![Last Name],
19, InCenter) & " " & ForceStringWidth(rsReports![Rider
District Number], 4, InCenter) & " " & ForceStringWidth(rsReports!
[Laps Completed], 4, InCenter) & " " &
ForceStringWidth("DQ", 3, inleft) & " " &
ForceStringWidth(rsReports![Rider Disqualified], 5, InCenter) & " "
& ForceStringWidth(rsReports![Rider DNF], 5, InCenter) & "
"
strRiderInfo =
strRiderInfo + " " + retForceStringWidth(strRiderNumber, 6,
InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderFirstName + " " + strRiderLastName, 19,
InsertionLocation.inCenter) + " " +
retForceStringWidth(strRiderDistrict, 4, InsertionLocation.inCenter) +
" " + retForceStringWidth(strRiderLapsCompleted, 4,
InsertionLocation.inCenter) + " " + retForceStringWidth("DQ", 3,
InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderDisqualified, 5,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderDNF,
5, InsertionLocation.inCenter) + " ";
} else{
// txtRiderInfo.Text =
txtRiderInfo.Text & " " & ForceStringWidth(rsReports![Rider Number],
6, inright) & " " & ForceStringWidth(rsReports![First Name] & " " &
rsReports![Last Name], 19, InCenter) & " " &
ForceStringWidth(rsReports![Rider District Number], 4, InCenter) & " "
& ForceStringWidth(rsReports![Laps Completed], 4, InCenter) & " " &
ForceStringWidth("N/A", 3, inleft) & " " & ForceStringWidth(rsReports!
[Rider Disqualified], 5, InCenter) & " " & ForceStringWidth(rsReports!
[Rider DNF], 5, InCenter) & " "
strRiderInfo =
strRiderInfo + " " + retForceStringWidth(strRiderNumber, 6,
InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderFirstName + " " + strRiderLastName, 19,
InsertionLocation.inCenter) + " " +
retForceStringWidth(strRiderDistrict, 4, InsertionLocation.inCenter) +
" " + retForceStringWidth(strRiderLapsCompleted, 4,
InsertionLocation.inCenter) + " " + retForceStringWidth("N/A", 3,
InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderDisqualified, 5,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderDNF,
5, InsertionLocation.inCenter) + " ";
}
}
long
lngLastCompletedLapTime = 0;
for (int intLap = 1;
intLap <= intNumberOfLaps; intLap++){
long lngTotalTime =
rs.getLong("Lap" + intLap);
if (lngTotalTime > 0){
if
(cmbRaceReport.getSelectedIndex() == 2) {
java.util.Date
dtNow = new java.util.Date();
java.util.Date
dtStartTime = new java.util.Date();
dtStartTime.setTime(dtNow.getTime() - (lngTotalTime * 1000)); //
Subtract TotalTime in milliseconds (lngTotalTime is in Seconds So must
Be Converted)
//
txtRiderInfo.Text = txtRiderInfo.Text &
ForceStringWidth(ElapsedTime(Now, DateAdd("s", rsReports.Fields("Lap"
& Lap).value, Now), True), 13, InCenter) & " "
strRiderInfo =
strRiderInfo + retForceStringWidth(retElapsedTime(dtStartTime, dtNow,
true), 13, InsertionLocation.inCenter) + " ";
} else{
if (intLap ==
1){
java.util.Date dtNow = new java.util.Date();
java.util.Date dtStartTime = new java.util.Date();
dtStartTime.setTime(dtNow.getTime() - ((lngTotalTime - lngClassOffset)
* 1000)); //Subtract TotalTime in milliseconds and the Class Offset
(lngTotalTime is in Seconds So must Be Converted)
//
txtRiderInfo.Text = txtRiderInfo.Text &
ForceStringWidth(ElapsedTime(Now, DateAdd("s", rsReports.Fields("Lap"
& Lap).value - rsReports![Class Offset], Now), True), 13, InCenter) &
" "
strRiderInfo = strRiderInfo +
retForceStringWidth(retElapsedTime(dtStartTime, dtNow, true), 13,
InsertionLocation.inCenter) + " ";
} else{
java.util.Date dtNow = new java.util.Date();
java.util.Date dtLastLapTime = new java.util.Date();
java.util.Date dtCurrentLapTime = new java.util.Date();
dtLastLapTime.setTime(dtNow.getTime() - (lngLastCompletedLapTime *
1000));
dtCurrentLapTime.setTime(dtNow.getTime() - (lngTotalTime * 1000)); //
Subtract TotalTime in milliseconds and the Class Offset (lngTotalTime
is in Seconds So must Be Converted)
// Offset =
rsReports.Fields("lap" & Lap).value - rsReports.Fields("lap" & Lap -
1).value
//
txtRiderInfo.Text = txtRiderInfo.Text &
ForceStringWidth(ElapsedTime(Now, DateAdd("s", Offset, Now), True),
13, InCenter) & " "
strRiderInfo = strRiderInfo +
retForceStringWidth(retElapsedTime(dtCurrentLapTime, dtLastLapTime,
true), 13, InsertionLocation.inCenter) + " ";
}
}
lngLastCompletedLapTime = lngTotalTime;
} else{
// txtRiderInfo.Text =
txtRiderInfo.Text & ForceStringWidth("---", 13, InCenter) & " "
strRiderInfo =
strRiderInfo + retForceStringWidth("---", 13,
InsertionLocation.inCenter) + " ";
}
}
if (rs.getInt("Laps
Completed") > 0){
// txtRiderInfo.Text =
txtRiderInfo.Text & ForceStringWidth(ElapsedTime(DateAdd("s", -
TotalTime, Now), Now, True), 14, InCenter) & vbCrLf
java.util.Date dtNow =
new java.util.Date();
java.util.Date
dtStartTime = new java.util.Date();
dtStartTime.setTime(dtNow.getTime() - (lngLastCompletedLapTime *
1000)); //Subtract TotalTime in milliseconds (lngTotalTime is in
Seconds So must Be Converted)
strRiderInfo =
strRiderInfo + retForceStringWidth(retElapsedTime(dtStartTime, dtNow,
true), 14, InsertionLocation.inCenter) + "\r\n";
} else{
strRiderInfo =
strRiderInfo + retForceStringWidth("---", 14,
InsertionLocation.inCenter) + "\r\n";
// txtRiderInfo.Text =
txtRiderInfo.Text & ForceStringWidth("---", 14, InCenter) & vbCrLf
}
}
break;
}
}
} else{
// rsBackup.MoveFirst
// Do Until rsBackup.BOF = True Or rsBackup.EOF
= True
// If RiderIDValue(ReportIndex) = rsBackup!
[Original ID] Then
// If rsBackup![Rider Present] = "True"
Then
// If cmbReport.ListIndex = 1 Then
// If rsBackup![Rider
Disqualified] = True Then
// txtRiderInfo.Text =
txtRiderInfo.Text & " " & ForceStringWidth(rsBackup![Rider Number], 6,
inright) & " " & ForceStringWidth(rsBackup![First Name] & " " &
rsBackup![Last Name], 19, InCenter) & " " & ForceStringWidth(rsBackup!
[Rider District Number], 4, InCenter) & " " &
ForceStringWidth(rsBackup![Laps Completed], 4, InCenter) & " " &
ForceStringWidth("DQ", 3, inleft) & " " & ForceStringWidth(rsBackup!
[Rider Disqualified], 5, InCenter) & " " & ForceStringWidth(rsBackup!
[Rider DNF], 5, InCenter) & " "
// Else
// txtRiderInfo.Text =
txtRiderInfo.Text & " " & ForceStringWidth(rsBackup![Rider Number], 6,
inright) & " " & ForceStringWidth(rsBackup![First Name] & " " &
rsBackup![Last Name], 19, InCenter) & " " & ForceStringWidth(rsBackup!
[Rider District Number], 4, InCenter) & " " &
ForceStringWidth(rsBackup![Laps Completed], 4, InCenter) & " " &
ForceStringWidth(CStr(Position), 3, inleft) & " " &
ForceStringWidth(rsBackup![Rider Disqualified], 5, InCenter) & " " &
ForceStringWidth(rsBackup![Rider DNF], 5, InCenter) & " "
// End If
// Else
// If rsBackup![Rider
Disqualified] = True Then
// txtRiderInfo.Text =
txtRiderInfo.Text & " " & ForceStringWidth(rsBackup![Rider Number], 6,
inright) & " " & ForceStringWidth(rsBackup![First Name] & " " &
rsBackup![Last Name], 19, InCenter) & " " & ForceStringWidth(rsBackup!
[Rider District Number], 4, InCenter) & " " &
ForceStringWidth(rsBackup![Laps Completed], 4, InCenter) & " " &
ForceStringWidth("DQ", 3, inleft) & " " & ForceStringWidth(rsBackup!
[Rider Disqualified], 5, InCenter) & " " & ForceStringWidth(rsBackup!
[Rider DNF], 5, InCenter) & " "
// Else
// txtRiderInfo.Text =
txtRiderInfo.Text & " " & ForceStringWidth(rsBackup![Rider Number], 6,
inright) & " " & ForceStringWidth(rsBackup![First Name] & " " &
rsBackup![Last Name], 19, InCenter) & " " & ForceStringWidth(rsBackup!
[Rider District Number], 4, InCenter) & " " &
ForceStringWidth(rsBackup![Laps Completed], 4, InCenter) & " " &
ForceStringWidth("N/A", 3, inleft) & " " & ForceStringWidth(rsBackup!
[Rider Disqualified], 5, InCenter) & " " & ForceStringWidth(rsBackup!
[Rider DNF], 5, InCenter) & " "
// End If
// End If
// For Lap = 1 To NumberOfLaps
// If rsBackup.Fields("Lap" &
Lap).value > 0 Then
// If cmbReport.ListIndex =
1 Then
// TotalTime =
rsBackup.Fields("Lap" & Lap).value
// txtRiderInfo.Text =
txtRiderInfo.Text & ForceStringWidth(ElapsedTime(Now, DateAdd("s",
rsBackup.Fields("Lap" & Lap).value, Now), True), 13, InCenter) & " "
// Else
// Debug.Print rsBackup!
[Class Offset]
// TotalTime =
rsBackup.Fields("Lap" & Lap).value - rsBackup![Class Offset]
// If Lap = 1 Then
// Debug.Print
rsBackup![Class Offset]
//
txtRiderInfo.Text = txtRiderInfo.Text &
ForceStringWidth(ElapsedTime(Now, DateAdd("s", rsBackup.Fields("Lap" &
Lap).value - rsBackup![Class Offset], Now), True), 13, InCenter) & " "
// Else
// Offset =
rsBackup.Fields("lap" & Lap).value - rsBackup.Fields("lap" & Lap -
1).value
//
txtRiderInfo.Text = txtRiderInfo.Text &
ForceStringWidth(ElapsedTime(Now, DateAdd("s", Offset, Now), True),
13, InCenter) & " "
// End If
// End If
// Else
// txtRiderInfo.Text =
txtRiderInfo.Text & ForceStringWidth("---", 13, InCenter) & " "
// End If
// Next Lap
// If rsBackup![Laps Completed] > 0
Then
// txtRiderInfo.Text =
txtRiderInfo.Text & ForceStringWidth(ElapsedTime(DateAdd("s", -
TotalTime, Now), Now, True), 14, InCenter) & vbCrLf
// Else
// txtRiderInfo.Text =
txtRiderInfo.Text & ForceStringWidth("---", 14, InCenter) & vbCrLf
// End If
// End If
// Exit Do
// End If
// rsBackup.MoveNext
// Loop
}
intPosition++;
}
txtRiderInfo.setText(strRiderInfo);
} catch (java.sql.SQLException ex) {
ex.printStackTrace();
}
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new frmRaceReport().setVisible(true);
}
});
}
private int getNumberOfLaps(long lngRaceID){
java.sql.Statement stmt;
java.sql.ResultSet rs;
int intNumberOfLaps = 0;
if (openRaceDatabase()){
try {
stmt = cnRaceDatabase.createStatement();
rs = stmt.executeQuery("SELECT [ID], [Laps Completed]
FROM [Master Rider Table] Where [Race ID] = " + lngRaceID + " Order By
[Laps Completed] DESC");
while (rs.next()){
intNumberOfLaps = rs.getInt("Laps Completed");
break;
}
rs.close();
stmt.close();
stmt = cnRaceDatabase.createStatement();
rs = stmt.executeQuery("SELECT [ID], [Laps Completed]
FROM [Modified Rider Records] Where [Race ID] = " + lngRaceID + "
Order By [Laps Completed] DESC");
while (rs.next()){
int intTemp = rs.getInt("Laps Completed");
if (intTemp > intNumberOfLaps){
intNumberOfLaps = intTemp;
}
break;
}
rs.close();
stmt.close();
} catch(java.sql.SQLException ex){
}
}
return intNumberOfLaps;
}
public static String left(String strval, int length){
if (length < 1 || strval.length() < length){
return "";
}
return strval.substring(0,length);
}
private void readAndSort(){
if (openRaceDatabase()){
String strClassString;
if (cmbRaceClass.getSelectedIndex() == 1) { //All
Classes
strClassString = "> 0";
} else {
strClassString = " = " +
Integer.toString(aryClassID.get(cmbRaceClass.getSelectedIndex()));
}
//Build Database Variables
java.sql.Statement stmt;
java.sql.Statement stmt_modified;
java.sql.ResultSet rs;
java.sql.ResultSet rs_modified;
//Build Report Arrays
String QueryString1 = "Select Count (*) FROM [Master Rider
Table] Where [Race ID] = " +
Integer.toString(aryRaceID.get(cmbRaceEvents.getSelectedIndex())) + "
AND [Class ID]" + strClassString;
String QueryString2 = "";
try {
stmt = cnRaceDatabase.createStatement();
rs = stmt.executeQuery(QueryString1);
if (rs.next()){
intRacerCount = (int)rs.getLong(1);
}
rs.close();
stmt.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
if (intRacerCount > 0){
//Do Nothing
} else{
javax.swing.JOptionPane.showMessageDialog(null, "No
Riders Available For This Class.", "Report Not Available",
javax.swing.JOptionPane.OK_OPTION);
//Need To Leave The Method here
}
//Must Add One To Array as Array 0 is Special For Sorting
lngRiderLapTime = new long[intRacerCount + 1];
intRiderLapCount = new int[intRacerCount + 1];
lngRiderIDValue = new long[intRacerCount + 1];
blnRiderModified = new boolean[intRacerCount + 1];
blnRiderDisqualified = new boolean[intRacerCount + 1];
//Sort Riders By Lap Time
QueryString1 = "Select * FROM [Master Rider Table] Where
[Race ID] = " +
Integer.toString(aryRaceID.get(cmbRaceEvents.getSelectedIndex())) + "
AND [Class ID]" + strClassString + " Order By [Rider Disqualified]
DESC, [Laps Completed] DESC";
QueryString2 = "Select * FROM [Modified Rider Records]
Where [Race ID] = " +
Integer.toString(aryRaceID.get(cmbRaceEvents.getSelectedIndex())) + "
AND [Class ID]" + strClassString + " Order By [Rider Disqualified]
DESC, [Laps Completed] DESC";
try {
stmt =
cnRaceDatabase.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
stmt_modified =
cnRaceDatabase.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(QueryString1);
rs_modified =
stmt_modified.executeQuery(QueryString2);
int intReportIndex = 0;
while (rs.next()){
intReportIndex++;
long lngRiderID = rs.getLong("ID");
boolean blnModifiedRecordFound = false;
rs_modified.beforeFirst();
while (rs_modified.next()){
long lngRiderID_modified =
rs_modified.getLong("Original ID");
if (lngRiderID == lngRiderID_modified){
blnModifiedRecordFound = true;
blnRiderModified[intReportIndex] = true;
intRiderLapCount[intReportIndex] =
rs_modified.getInt("Laps Completed");
if (intRiderLapCount[intReportIndex] >
0){
lngRiderLapTime[intReportIndex] =
rs_modified.getLong("Lap" + intRiderLapCount[intReportIndex]);
}
blnRiderDisqualified[intReportIndex] =
rs_modified.getBoolean("Rider Disqualified");
lngRiderIDValue[intReportIndex] =
lngRiderID_modified;
break;
}
}
if (blnModifiedRecordFound == false){
blnRiderModified[intReportIndex] = false;
intRiderLapCount[intReportIndex] =
rs.getInt("Laps Completed");
if (intRiderLapCount[intReportIndex] > 0){
lngRiderLapTime[intReportIndex] =
rs.getLong("Lap" + intRiderLapCount[intReportIndex]);
}
blnRiderDisqualified[intReportIndex] =
rs.getBoolean("Rider Disqualified");
lngRiderIDValue[intReportIndex] = lngRiderID;
} else{
//Do Nothing
}
}
for (int intSortIndex=1; intSortIndex <=
intRacerCount; intSortIndex++){
boolean blnRecordMoved = false;
for (int intHighestValueIndex = intRacerCount;
intHighestValueIndex >= (intSortIndex + 1); intHighestValueIndex--){
if ((intRiderLapCount[intHighestValueIndex] ==
intRiderLapCount[intSortIndex] &&
lngRiderLapTime[intHighestValueIndex] < lngRiderLapTime[intSortIndex])
|| (intRiderLapCount[intHighestValueIndex] >
intRiderLapCount[intSortIndex])){
blnRiderModified[0] =
blnRiderModified[intHighestValueIndex];
intRiderLapCount[0] =
intRiderLapCount[intHighestValueIndex];
lngRiderLapTime[0] =
lngRiderLapTime[intHighestValueIndex];
lngRiderIDValue[0] =
lngRiderIDValue[intHighestValueIndex];
blnRiderDisqualified[0] =
blnRiderDisqualified[intHighestValueIndex];
blnRiderModified[intHighestValueIndex] =
blnRiderModified[intSortIndex];
intRiderLapCount[intHighestValueIndex] =
intRiderLapCount[intSortIndex];
lngRiderLapTime[intHighestValueIndex] =
lngRiderLapTime[intSortIndex];
lngRiderIDValue[intHighestValueIndex] =
lngRiderIDValue[intSortIndex];
blnRiderDisqualified[intHighestValueIndex]
= blnRiderDisqualified[intSortIndex];
blnRiderModified[intSortIndex] =
blnRiderModified[0];
intRiderLapCount[intSortIndex] =
intRiderLapCount[0];
lngRiderLapTime[intSortIndex] =
lngRiderLapTime[0];
lngRiderIDValue[intSortIndex] =
lngRiderIDValue[0];
blnRiderDisqualified[intSortIndex] =
blnRiderDisqualified[0];
blnRecordMoved = true;
}
}
if (blnRecordMoved == true){intSortIndex = 0;}
}
for (int intSortIndex = 1; intSortIndex <=
intRacerCount; intSortIndex++){
boolean blnRecordMoved = false;
for (int intHighestValueIndex = intSortIndex;
intHighestValueIndex >= (intRacerCount - 1); intHighestValueIndex-- ){
if (blnRiderDisqualified[intHighestValueIndex]
== true && blnRiderDisqualified[intHighestValueIndex + 1] == false) {
blnRiderModified[0] =
blnRiderModified[intHighestValueIndex];
intRiderLapCount[0] =
intRiderLapCount[intHighestValueIndex];
lngRiderLapTime[0] =
lngRiderLapTime[intHighestValueIndex];
lngRiderIDValue[0] =
lngRiderIDValue[intHighestValueIndex];
blnRiderDisqualified[0] =
blnRiderDisqualified[intHighestValueIndex];
blnRiderModified[intHighestValueIndex] =
blnRiderModified[intHighestValueIndex + 1];
intRiderLapCount[intHighestValueIndex] =
intRiderLapCount[intHighestValueIndex + 1];
lngRiderLapTime[intHighestValueIndex] =
lngRiderLapTime[intHighestValueIndex + 1];
lngRiderIDValue[intHighestValueIndex] =
lngRiderIDValue[intHighestValueIndex + 1];
blnRiderDisqualified[intHighestValueIndex]
= blnRiderDisqualified[intHighestValueIndex + 1];
blnRiderModified[intHighestValueIndex + 1]
= blnRiderModified[0];
intRiderLapCount[intHighestValueIndex + 1]
= intRiderLapCount[0];
lngRiderLapTime[intHighestValueIndex + 1]
= lngRiderLapTime[0];
lngRiderIDValue[intHighestValueIndex + 1]
= lngRiderIDValue[0];
blnRiderDisqualified[intHighestValueIndex
+ 1] = blnRiderDisqualified[0];
blnRecordMoved = true;
}
}
if (blnRecordMoved == true){intSortIndex = 0;}
}
} catch(java.sql.SQLException ex){
}
}
}
public static long retDateDiffInSeconds(java.util.Date date1,
java.util.Date date2){
long returnvalue = -9999;
returnvalue = ((date1.getTime() - date2.getTime()) / 1000);
return returnvalue;
}
private static String retDateFormat(java.util.Date datetime,
String format){
java.text.Format formatter = new java.text.SimpleDateFormat(format);
String s = formatter.format(datetime);
return s;
}
private static String retElapsedTime(java.util.Date dtStartTime,
java.util.Date dtCurrentTime, boolean blnShortHand ){
float[] fltClockValue = new float[5];
String[] strLabel = new String[5];
strLabel[1] = "Second";
fltClockValue[1] =
java.lang.Math.abs((float)retDateDiffInSeconds(dtStartTime,
dtCurrentTime)); //Make Sure Value Is Positive
strLabel[4] = "Day";
fltClockValue[4] = (int)(fltClockValue[1] / 86400);
strLabel[3] = "Hour";
fltClockValue[3] = (int)((fltClockValue[1] - (fltClockValue[4]
* 86400)) / 3600);
strLabel[2] = "Minute";
fltClockValue[2] = (int)(fltClockValue[1] / 60);
fltClockValue[2] = fltClockValue[2] % 60;
fltClockValue[1] = fltClockValue[1] % 60;
for (int intIndex = 1; intIndex <= 4; intIndex++){
if (fltClockValue[intIndex] != 1.0){strLabel[intIndex] =
strLabel[intIndex] + "s";}
}
String strElapsedTime = "";
if (blnShortHand == false){
if (fltClockValue[4] > 0){
strElapsedTime = fltClockValue[4] + " " + strLabel[4]
+ " " + fltClockValue[3] + " " + strLabel[3] + " " + fltClockValue[2]
+ " " + strLabel[2] + " " + fltClockValue[1] + " " + strLabel[1];
} else{
strElapsedTime = fltClockValue[3] + " " + strLabel[3]
+ " " + fltClockValue[2] + " " + strLabel[2] + " " + fltClockValue[1]
+ " " + strLabel[1];
}
} else{
java.text.NumberFormat formatter = new
java.text.DecimalFormat("00");
if (fltClockValue[4] > 0) {
strElapsedTime = fltClockValue[4] + "D " +
formatter.format(fltClockValue[3]) + "H " +
formatter.format(fltClockValue[2]) + "M " +
formatter.format(fltClockValue[1]) + "S";
} else{
strElapsedTime = formatter.format(fltClockValue[3]) +
"H " + formatter.format(fltClockValue[2]) + "M " +
formatter.format(fltClockValue[1]) + "S";
}
}
return strElapsedTime;
}
private static String retForceStringWidth(String strStringData,
int intStringLength, InsertionLocation InsertionPoint){
String strNameString = "";
if (strStringData.length() > intStringLength) {
strStringData = left(strStringData, intStringLength);
}
String strForceStringWidth = strStringData;
if (strForceStringWidth.length() > intStringLength){
strNameString = left(strForceStringWidth,
intStringLength);
} else{
while (strForceStringWidth.length() < intStringLength){
if (InsertionPoint == InsertionLocation.inRight){
strForceStringWidth = strForceStringWidth + " ";
} else if (InsertionPoint == InsertionLocation.inLeft)
{
strForceStringWidth = " " + strForceStringWidth;
} else if (InsertionPoint ==
InsertionLocation.inCenter){
strForceStringWidth = " " + strForceStringWidth;
if (strForceStringWidth.length() < intStringLength)
{
strForceStringWidth = strForceStringWidth + "
";
}
}
}
}
return strForceStringWidth;
}
public boolean openRaceDatabase(){
boolean dbopen = false;
if (cnRaceDatabase != null){
try {
cnRaceDatabase.getMetaData(); //recommended way to
check connection
dbopen = true;
} catch (java.sql.SQLException ex) {
ex.printStackTrace();
try {
cnRaceDatabase.close();
} catch (java.sql.SQLException ex1) {
ex.printStackTrace();
}
}
}
if (dbopen == false){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cnRaceDatabase =
java.sql.DriverManager.getConnection("jdbcdbcriver={Microsoft
Access Driver
(*.mdb)};DBQ=RaceDatabase.mdb;DriverID=22;READONLY=true");
cnRaceDatabase.getMetaData();
dbopen = true;
}catch (java.sql.SQLException se) {
javax.swing.JOptionPane.showMessageDialog(null, "Error
Opening Database.\r\n" + se.getErrorCode() + ":" + se.getMessage(),
"Database Error", javax.swing.JOptionPane.ERROR_MESSAGE);
System.exit(1); // Note that this is an abnormal
termination of the program.
} catch (ClassNotFoundException cnfe) {
//MainSettings.notifier.logProgramNote("Open Settings
Derby Driver Error:", cnfe.getMessage());
}
}
return dbopen;
}
// Variables declaration - do not modify
private javax.swing.JButton btExit;
private javax.swing.JComboBox cmbRaceClass;
private javax.swing.JComboBox cmbRaceEvents;
private javax.swing.JComboBox cmbRaceReport;
private datechooser.beans.DateChooserCombo dtpDateTime;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JTextArea txtRiderInfo;
// End of variables declaration
private java.sql.Connection cnRaceDatabase;
private boolean blnStartup = true;
private boolean blnBuildingRaceEvents = false;
private boolean blnBuildingRaceClasses = false;
private String strDateTime = "";
private java.util.ArrayList<String> aryMasterRaceClassesAllowed =
new java.util.ArrayList<String>();
private java.util.ArrayList<Integer> aryClassID = new
java.util.ArrayList<Integer>();
private java.util.ArrayList<Integer> aryRaceID = new
java.util.ArrayList<Integer>();
long[] lngRiderLapTime;
int[] intRiderLapCount;
long[] lngRiderIDValue;
boolean[] blnRiderModified;
boolean[] blnRiderDisqualified;
int intRacerCount = 0;
private enum InsertionLocation{
inLeft,
inRight,
inCenter
}
}
*****************************************************************************************
JNLP FILE BELOW
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jnlp PUBLIC "-//Sun Microsystems, Inc.//DTD JNLP 1.5//EN"
"http://www.netbeans.org/jnlp/DTD/jnlp.dtd">
<jnlp codebase="file:///C:/JavaCode/RaceReporter"
href="RaceReporter.jnlp">
<information>
<title>RaceReporter</title>
<vendor>R--Y--E, Inc.</vendor>
<homepage href="homepage.html"/>
<description> </description>
<icon href="default"/>
<offline-allowed/>
<shortcut online="true">
<desktop/>
</shortcut>
</information>
<resources>
<j2se href="http://java.sun.com/products/autodl/j2se"
version="1.4+"/>
</resources>
<resources>
<jar download="eager" href="dist/RaceReporter.jar" main="false"/>
</resources>
<resources locale="" os="">
<jar download="eager" href="DateChooser.jar" main="false"
version=""/>
</resources>
<application-desc main-class="racereporter.frmRaceReport"/>
</jnlp>
with some swing components. One of them is a third party datepicker.
It requires a JAR file. I have tried two different datepickers. I have
the same problem (Described Below).
I can run the application just fine when not using WebStart. I can run
the application using WebStart if I delete the datepicker control.
I edit the JNLP file and add the datepicker.jar file as eager and also
tried as lazy using Netbeans.
When I run the application using Web Start a java.exe process is
created I have to kill the process as I can not exit it because no
Jframe is loaded.
If I use Debug and Webstart, the code goes into the init method and
works fine until it gets to the DatePicker dp = new DatePicker();
No errors are generated, but no GUI is drawn and the NetBeans IDE
stops stepping through the code at this point.
Any Suggestions would be greatly appreciated!
Here is an example of the code, note where the program stops is all
'automagically' done by netbeans. The program when using webstart
never makes it to my code.... I added comments in the Init method
around the code that stops the program, it is only about 50 lines down
from here.
Here is the code..... Below the code is a copy of the JNLP file as
well.....
/*
* frmRaceRepor.java
*
* Created on November 22, 2007, 3:50 PM
*/
package racereporter;
import java.sql.SQLException;
import java.text.FieldPosition;
import java.text.ParsePosition;
import java.util.ArrayList;
/**
*
* @author rtf
*/
public class frmRaceReport extends javax.swing.JFrame {
/** Creates new form frmRaceRepor */
public frmRaceReport() {
initComponents();
blnStartup = false;
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code
">
private void initComponents() {
jSeparator1 = new javax.swing.JSeparator();
cmbRaceReport = new javax.swing.JComboBox();
cmbRaceClass = new javax.swing.JComboBox();
cmbRaceEvents = new javax.swing.JComboBox();
btExit = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
txtRiderInfo = new javax.swing.JTextArea();
//
***************************************************************************************************
// ************************* CODE STOPS STEPPING HERE
*****************************
dtpDateTime = new datechooser.beans.DateChooserCombo();
//
***************************************************************************************************
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
cmbRaceReport.setMaximumRowCount(100);
cmbRaceReport.setToolTipText("Select A Race Venue To View
Reports");
cmbRaceReport.setBorder(null);
cmbRaceReport.setMaximumSize(new java.awt.Dimension(200, 20));
cmbRaceReport.setMinimumSize(new java.awt.Dimension(100, 20));
cmbRaceReport.setPreferredSize(new java.awt.Dimension(100,
20));
cmbRaceReport.setVisible(false);
cmbRaceReport.removeAllItems();
cmbRaceReport.addItem("Please Select A Report");
cmbRaceReport.addItem("Current Class Race Results");
cmbRaceReport.addItem("Preliminary Results Elapsed Times");
cmbRaceReport.addItem("Preliminary Results Lap Times");
cmbRaceReport.addItem("Rider Race Position By Lap");
cmbRaceReport.addItem("Fastest Lap Times Lap 1");
cmbRaceReport.addItem("Fastest Lap Times All Others");
cmbRaceReport.addItem("Race Official Report");
cmbRaceReport.addItem("Current Season Points");
cmbRaceReport.addItem("Various Rider Statistics");
cmbRaceReport.addItemListener(new
java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt)
{
cmbRaceReportItemStateChanged(evt);
}
});
cmbRaceClass.setMaximumRowCount(100);
cmbRaceClass.setToolTipText("Select A Race Venue To View
Reports");
cmbRaceClass.setBorder(null);
cmbRaceClass.setMaximumSize(new java.awt.Dimension(51, 20));
cmbRaceClass.setMinimumSize(new java.awt.Dimension(51, 20));
cmbRaceClass.setPreferredSize(new java.awt.Dimension(51, 20));
cmbRaceClass.setVisible(false);
cmbRaceClass.addItemListener(new java.awt.event.ItemListener()
{
public void itemStateChanged(java.awt.event.ItemEvent evt)
{
cmbRaceClassItemStateChanged(evt);
}
});
cmbRaceEvents.setMaximumRowCount(100);
cmbRaceEvents.setToolTipText("Select A Race Venue To View
Reports");
cmbRaceEvents.setBorder(null);
cmbRaceEvents.setMaximumSize(new java.awt.Dimension(51, 20));
cmbRaceEvents.setMinimumSize(new java.awt.Dimension(51, 20));
cmbRaceEvents.setPreferredSize(new java.awt.Dimension(51,
20));
cmbRaceEvents.setVisible(false);
cmbRaceEvents.addItemListener(new
java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt)
{
cmbRaceEventsItemStateChanged(evt);
}
});
btExit.setBackground(new java.awt.Color(255, 204, 204));
btExit.setText("EXIT");
btExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
btExitActionPerformed(evt);
}
});
txtRiderInfo.setColumns(20);
txtRiderInfo.setEditable(false);
txtRiderInfo.setFont(new java.awt.Font("Courier New", 0, 12));
txtRiderInfo.setRows(5);
jScrollPane1.setViewportView(txtRiderInfo);
dtpDateTime.addCommitListener(new
datechooser.events.CommitListener() {
public void onCommit(datechooser.events.CommitEvent evt) {
dtpDateTimeOnCommit(evt);
}
});
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(dtpDateTime,
javax.swing.GroupLayout.PREFERRED_SIZE, 191,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmbRaceEvents,
javax.swing.GroupLayout.PREFERRED_SIZE, 165,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmbRaceClass,
javax.swing.GroupLayout.PREFERRED_SIZE, 165,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmbRaceReport,
javax.swing.GroupLayout.PREFERRED_SIZE, 165,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
155, Short.MAX_VALUE)
.addComponent(btExit)
.addContainerGap())
.addComponent(jSeparator1,
javax.swing.GroupLayout.DEFAULT_SIZE, 934, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1,
javax.swing.GroupLayout.DEFAULT_SIZE, 914, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmbRaceEvents,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cmbRaceClass,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cmbRaceReport,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btExit,
javax.swing.GroupLayout.PREFERRED_SIZE, 23,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(dtpDateTime,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator1,
javax.swing.GroupLayout.PREFERRED_SIZE, 10,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1,
javax.swing.GroupLayout.DEFAULT_SIZE, 455, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void dtpDateTimeOnCommit(datechooser.events.CommitEvent
evt) {
if (openRaceDatabase()){
long lngCount = 0;
try {
java.sql.Statement stmt;
stmt = cnRaceDatabase.createStatement();
java.sql.ResultSet rs = stmt.executeQuery("Select
count(*) From [Master Race Table] Where [Race Date] = #" +
dtpDateTime.getText() + "#");
while (rs.next()){
lngCount = rs.getLong(1);
}
rs.close();
if (lngCount > 0){
rs = stmt.executeQuery("Select [ID], [Race Venue],
[Classes Allowed] From [Master Race Table] Where [Race Date] = #" +
dtpDateTime.getText() + "#");
aryMasterRaceClassesAllowed.clear();
aryRaceID.clear();
cmbRaceEvents.removeAllItems();
//Add Combo Instruction
aryMasterRaceClassesAllowed.add("");
aryRaceID.add(-1);
cmbRaceEvents.addItem("Please Select A Race
Event");
while (rs.next()){
aryMasterRaceClassesAllowed.add(rs.getString("Classes Allowed"));
aryRaceID.add(rs.getInt("ID"));
cmbRaceEvents.addItem(rs.getString("Race
Venue"));
}
cmbRaceEvents.setVisible(true);
} else{
cmbRaceEvents.setVisible(false);
cmbRaceClass.setVisible(false);
cmbRaceReport.setVisible(false);
javax.swing.JOptionPane.showMessageDialog(null,
"No Race Events Found For This Date", "No Races Found",
javax.swing.JOptionPane.OK_OPTION);
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
private void btExitActionPerformed(java.awt.event.ActionEvent evt)
{
System.exit(0);
}
private void
cmbRaceEventsItemStateChanged(java.awt.event.ItemEvent evt)
{
if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED
&& blnBuildingRaceEvents == false && cmbRaceEvents.getSelectedIndex()
String[] strClassesAllowed =0) {
aryMasterRaceClassesAllowed.get(cmbRaceEvents.getSelectedIndex()).split(",");
String strClassQuery = "";
for (int i=0; i < strClassesAllowed.length; i++){
if (i == (strClassesAllowed.length - 1)){
strClassQuery = strClassQuery +
strClassesAllowed;
} else {
strClassQuery = strClassQuery +
strClassesAllowed + " Or [ID] = ";
}
}
if (openRaceDatabase()){
try {
java.sql.Statement
stmt=cnRaceDatabase.createStatement();
stmt=cnRaceDatabase.createStatement();
java.sql.ResultSet rs=stmt.executeQuery("Select *
From [Master Class Table] Where [ID] = " + strClassQuery);
blnBuildingRaceClasses = true;
aryClassID.clear();
cmbRaceClass.removeAllItems();
cmbRaceClass.addItem("Please Select A Class");
aryClassID.add(-1);
cmbRaceClass.addItem("All Classes");
aryClassID.add(0);
while(rs.next()){
cmbRaceClass.addItem(rs.getString("Class
Description"));
aryClassID.add(rs.getInt("ID"));
}
cmbRaceClass.setVisible(true);
blnBuildingRaceClasses = false;
stmt.close();
} catch(java.sql.SQLException e){
System.err.println("SQL Exception found! " +
e.getMessage());
}
}
} else if (cmbRaceClass.getSelectedIndex() == 0){
cmbRaceReport.setVisible(false);
cmbRaceClass.setVisible(false);
}
}
private void cmbRaceClassItemStateChanged(java.awt.event.ItemEvent
evt) {
if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED
&& blnBuildingRaceClasses == false && cmbRaceClass.getSelectedIndex()
cmbRaceReport.setVisible(true);0) {
cmbRaceReport.setSelectedIndex(0);
} else if (cmbRaceClass.getSelectedIndex() == 0){
cmbRaceReport.setVisible(false);
}
}
private void
cmbRaceReportItemStateChanged(java.awt.event.ItemEvent evt)
{
if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED
&& cmbRaceReport.getSelectedIndex() > 0) {
//Build Class Query String
String strClassString;
if (cmbRaceClass.getSelectedIndex() == 1) { //All
Classes
strClassString = "> 0";
} else {
strClassString = " = " +
Integer.toString(aryClassID.get(cmbRaceClass.getSelectedIndex()));
}
//Build Database Variables
java.sql.Statement stmt;
java.sql.Statement stmt_modified;
java.sql.ResultSet rs;
java.sql.ResultSet rs_modified;
if (cmbRaceReport.getSelectedIndex() == 1){
if (openRaceDatabase()){
readAndSort();
String QueryString1 = "Select * FROM [Master Rider
Table] Where [Race ID] = " +
Integer.toString(aryRaceID.get(cmbRaceEvents.getSelectedIndex())) + "
AND [Class ID]" + strClassString + " Order By [Rider Disqualified]
DESC, [Laps Completed] DESC";
String QueryString2 = "Select * FROM [Modified
Rider Records] Where [Race ID] = " +
Integer.toString(aryRaceID.get(cmbRaceEvents.getSelectedIndex())) + "
AND [Class ID]" + strClassString + " Order By [Rider Disqualified]
DESC, [Laps Completed] DESC";
try {
stmt =
cnRaceDatabase.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
stmt_modified =
cnRaceDatabase.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(QueryString1);
rs_modified =
stmt_modified.executeQuery(QueryString2);
int intPosition = 1;
String strRiderInfo = "";
strRiderInfo =
(String)cmbRaceClass.getSelectedItem() + " Preliminary Race Results
Report.\r\nAll Total Elapsed Times Are Based From The Start Of The
First Heat.\r\n\r\n";
strRiderInfo = strRiderInfo + "|Place|
Number| Rider Name | Rider Ride |DIST|LAPS| DNF |Total
Time |\r\n";
strRiderInfo = strRiderInfo + "|_____|
______|___________________|________________|____|____|_____|
______________|\r\n";
for (int intReportIndex = 1;
intReportIndex <= intRacerCount; intReportIndex++){
if (blnRiderModified[intReportIndex]
== false){
rs.beforeFirst();
while (rs.next()){
if
(lngRiderIDValue[intReportIndex] == rs.getLong("ID")){
if (rs.getBoolean("Rider
Present") == true){
String strRiderNumber
= rs.getString("Rider Number");
String
strRiderFirstName = rs.getString("First Name");
String
strRiderLastName = rs.getString("Last Name");
String strRiderBrand =
rs.getString("Brand");
String
strRiderDisplacement = rs.getString("Displacement");
String
strRiderDistrict = rs.getString("Rider District Number");
String
strRiderLapsCompleted = rs.getString("Laps Completed");
String strRiderDNF =
"False";
if
(rs.getBoolean("Rider DNF")){
strRiderDNF =
"True";
}
if
(rs.getBoolean("Rider Disqualified") == true){
strRiderInfo =
strRiderInfo + " DQ" + " " + retForceStringWidth(strRiderNumber, 6,
InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderFirstName + " " + strRiderLastName, 19,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderBrand
+ " " + strRiderDisplacement, 16, InsertionLocation.inCenter) + " " +
retForceStringWidth(strRiderDistrict, 4, InsertionLocation.inCenter) +
" " + retForceStringWidth(strRiderLapsCompleted, 4,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderDNF,
5, InsertionLocation.inCenter) + " ";
} else{
strRiderInfo =
strRiderInfo + " " +
retForceStringWidth(Integer.toString(intPosition), 3,
InsertionLocation.inLeft) + " " + retForceStringWidth(strRiderNumber,
6, InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderFirstName + " " + strRiderLastName, 19,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderBrand
+ " " + strRiderDisplacement, 16, InsertionLocation.inCenter) + " " +
retForceStringWidth(strRiderDistrict, 4, InsertionLocation.inCenter) +
" " + retForceStringWidth(strRiderLapsCompleted, 4,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderDNF,
5, InsertionLocation.inCenter) + " ";
intPosition =
intPosition + 1;
}
if
(Integer.parseInt(strRiderLapsCompleted) > 0){
long lngTotalTime
= rs.getLong("Lap" + strRiderLapsCompleted);
java.util.Date
dtNow = new java.util.Date();
java.util.Date
dtStartTime = new java.util.Date();
dtStartTime.setTime(dtNow.getTime() - (lngTotalTime * 1000)); //
Subtract TotalTime in milliseconds (lngTotalTime is in Seconds So must
Be Converted)
strRiderInfo =
strRiderInfo + retForceStringWidth(retElapsedTime(dtStartTime, dtNow,
true), 14, InsertionLocation.inCenter) + "\r\n";
} else{
strRiderInfo =
strRiderInfo + retForceStringWidth("---", 14,
InsertionLocation.inCenter) + "\r\n";
}
}
break;
}
}
} else{
rs_modified.beforeFirst();
while (rs_modified.next()) {
if
(lngRiderIDValue[intReportIndex] == rs_modified.getLong("ID")){
if
(rs_modified.getBoolean("Rider Present") == true){
String strRiderNumber
= rs_modified.getString("Rider Number");
String
strRiderFirstName = rs_modified.getString("First Name");
String
strRiderLastName = rs_modified.getString("Last Name");
String strRiderBrand =
rs_modified.getString("Brand");
String
strRiderDisplacement = rs_modified.getString("Displacement");
String
strRiderDistrict = rs_modified.getString("Rider District Number");
String
strRiderLapsCompleted = rs_modified.getString("Laps Completed");
String strRiderDNF =
"False";
if
(rs_modified.getBoolean("Rider DNF")){
strRiderDNF =
"True";
}
if
(rs_modified.getBoolean("Rider Disqualified") == true){
strRiderInfo =
strRiderInfo + " DQ" + " " + retForceStringWidth(strRiderNumber, 6,
InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderFirstName + " " + strRiderLastName, 19,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderBrand
+ " " + strRiderDisplacement, 16, InsertionLocation.inCenter) + " " +
retForceStringWidth(strRiderDistrict, 4, InsertionLocation.inCenter) +
" " + retForceStringWidth(strRiderLapsCompleted, 4,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderDNF,
5, InsertionLocation.inCenter) + " ";
} else{
strRiderInfo =
strRiderInfo + " " +
retForceStringWidth(Integer.toString(intPosition), 3,
InsertionLocation.inLeft) + " " + retForceStringWidth(strRiderNumber,
6, InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderFirstName + " " + strRiderLastName, 19,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderBrand
+ " " + strRiderDisplacement, 16, InsertionLocation.inCenter) + " " +
retForceStringWidth(strRiderDistrict, 4, InsertionLocation.inCenter) +
" " + retForceStringWidth(strRiderLapsCompleted, 4,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderDNF,
5, InsertionLocation.inCenter) + " ";
intPosition =
intPosition + 1;
}
if
(Integer.parseInt(strRiderLapsCompleted) > 0){
long lngTotalTime
= rs_modified.getLong("Lap" + strRiderLapsCompleted);
java.util.Date
dtNow = new java.util.Date();
java.util.Date
dtStartTime = new java.util.Date();
dtStartTime.setTime(dtNow.getTime() - (lngTotalTime * 1000)); //
Subtract TotalTime in milliseconds (lngTotalTime is in Seconds So must
Be Converted)
strRiderInfo =
strRiderInfo + retForceStringWidth(retElapsedTime(dtStartTime, dtNow,
true), 14, InsertionLocation.inCenter) + "\r\n";
} else{
strRiderInfo =
strRiderInfo + retForceStringWidth("---", 14,
InsertionLocation.inCenter) + "\r\n";
}
}
}
}
}
}
txtRiderInfo.setText(strRiderInfo);
} catch (SQLException ex) {
ex.printStackTrace();
}
}
} else if (cmbRaceReport.getSelectedIndex() == 2 ||
cmbRaceReport.getSelectedIndex() == 3){
readAndSort();
String QueryString1 = "Select * FROM [Master Rider
Table] Where [Race ID] = " +
Integer.toString(aryRaceID.get(cmbRaceEvents.getSelectedIndex())) + "
AND [Class ID]" + strClassString + " Order By [Rider Disqualified]
DESC, [Laps Completed] DESC";
String QueryString2 = "Select * FROM [Modified
Rider Records] Where [Race ID] = " +
Integer.toString(aryRaceID.get(cmbRaceEvents.getSelectedIndex())) + "
AND [Class ID]" + strClassString + " Order By [Rider Disqualified]
DESC, [Laps Completed] DESC";
try {
stmt =
cnRaceDatabase.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
stmt_modified =
cnRaceDatabase.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(QueryString1);
rs_modified =
stmt_modified.executeQuery(QueryString2);
int intPosition = 1;
String strRiderInfo = "";
if (cmbRaceReport.getSelectedIndex() == 2){
strRiderInfo =
(String)cmbRaceClass.getSelectedItem() + " Preliminary Race Results
Report.\r\nAll Total Elapsed Times Are Based From The Start Of The
First Heat.\r\n\r\n";
} else{
strRiderInfo =
(String)cmbRaceClass.getSelectedItem() + " Preliminary Race Results
Report.\r\nAll Lap Times Are Based From The Start Of Each Riders Class.
\r\n\r\n";
}
strRiderInfo = strRiderInfo + "|Number|
Rider Name |DIST|LAPS|POS|Disql| DNF |";
int intNumberOfLaps =
this.getNumberOfLaps(aryRaceID.get(cmbRaceEvents.getSelectedIndex()));
for (int intLap = 1; intLap <=
intNumberOfLaps; intLap++){
strRiderInfo = strRiderInfo + " Lap" +
intLap + " Time " + "|";
}
strRiderInfo = strRiderInfo + " Total Time |
\r\n";
strRiderInfo = strRiderInfo + "|______|
___________________|____|____|___|_____|_____|";
for (int intLap = 1; intLap <=
intNumberOfLaps; intLap++){
strRiderInfo = strRiderInfo +
"_____________|";
}
strRiderInfo = strRiderInfo + "______________|
\r\n";
for (int intReportIndex = 1; intReportIndex <=
intRacerCount; intReportIndex++){
if (blnRiderModified[intReportIndex] ==
false){
rs.beforeFirst();
while(rs.next()){
System.out.println(lngRiderIDValue[intReportIndex] + " = " +
rs.getLong("ID"));
if
(lngRiderIDValue[intReportIndex] == rs.getLong("ID")){
if (rs.getBoolean("Rider
Present") == true){
String strRiderNumber =
rs.getString("Rider Number");
String strRiderFirstName =
rs.getString("First Name");
String strRiderLastName =
rs.getString("Last Name");
String strRiderBrand =
rs.getString("Brand");
String
strRiderDisplacement = rs.getString("Displacement");
String strRiderDistrict =
rs.getString("Rider District Number");
String
strRiderLapsCompleted = rs.getString("Laps Completed");
long lngClassOffset =
rs.getLong("Class Offset");
String
strRiderDisqualified = "False";
if (rs.getBoolean("Rider
Disqualified")){
strRiderDisqualified =
"True";
}
String strRiderDNF =
"False";
if (rs.getBoolean("Rider
DNF")){
strRiderDNF = "True";
}
if
(cmbRaceReport.getSelectedIndex() == 2){
if
(rs.getBoolean("Rider Disqualified") == true){
//strRiderInfo =
strRiderInfo + " " + retForceStringWidth(rsReports![Rider Number], 6,
inright) & " " & ForceStringWidth(rsReports!
[First Name] & " " & rsReports![Last Name], 19, InCenter) & " "
& ForceStringWidth(rsReports![Rider District Number], 4,
InCenter) & " " & ForceStringWidth(rsReports![Laps Completed], 4,
InCenter) & " " & ForceStringWidth("DQ", 3, inleft)
& " " & ForceStringWidth(rsReports![Rider
Disqualified], 5, InCenter) & " " &
ForceStringWidth(rsReports![Rider DNF], 5, InCenter) & " "
strRiderInfo =
strRiderInfo + " " + retForceStringWidth(strRiderNumber, 6,
InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderFirstName + " " + strRiderLastName, 19,
InsertionLocation.inCenter) + " " +
retForceStringWidth(strRiderDistrict, 4, InsertionLocation.inCenter) +
" " + retForceStringWidth(strRiderLapsCompleted, 4,
InsertionLocation.inCenter) + " " + retForceStringWidth("DQ", 3,
InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderDisqualified, 5,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderDNF,
5, InsertionLocation.inCenter) + " ";
} else{
// txtRiderInfo.Text =
txtRiderInfo.Text & " " & ForceStringWidth(rsReports![Rider Number],
6, inright) & " " & ForceStringWidth(rsReports!
[First Name] & " " & rsReports![Last Name], 19, InCenter) & " "
& ForceStringWidth(rsReports![Rider District Number], 4,
InCenter) & " " & ForceStringWidth(rsReports![Laps Completed], 4,
InCenter) & " " & ForceStringWidth(CStr(Position), 3,
inleft) & " " &
ForceStringWidth(rsReports![Rider Disqualified], 5, InCenter) & " " &
ForceStringWidth(rsReports![Rider DNF], 5, InCenter) & " "
strRiderInfo =
strRiderInfo + " " + retForceStringWidth(strRiderNumber, 6,
InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderFirstName + " " + strRiderLastName, 19,
InsertionLocation.inCenter) + " " +
retForceStringWidth(strRiderDistrict, 4, InsertionLocation.inCenter) +
" " + retForceStringWidth(strRiderLapsCompleted, 4,
InsertionLocation.inCenter) + " " +
retForceStringWidth(Integer.toString(intPosition), 3,
InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderDisqualified, 5,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderDNF,
5, InsertionLocation.inCenter) + " ";
}
} else{
if
(rs.getBoolean("Rider Disqualified") == true){
// txtRiderInfo.Text =
txtRiderInfo.Text & " " & ForceStringWidth(rsReports![Rider Number],
6, inright) & " " &
ForceStringWidth(rsReports![First Name] & " " & rsReports![Last Name],
19, InCenter) & " " & ForceStringWidth(rsReports![Rider
District Number], 4, InCenter) & " " & ForceStringWidth(rsReports!
[Laps Completed], 4, InCenter) & " " &
ForceStringWidth("DQ", 3, inleft) & " " &
ForceStringWidth(rsReports![Rider Disqualified], 5, InCenter) & " "
& ForceStringWidth(rsReports![Rider DNF], 5, InCenter) & "
"
strRiderInfo =
strRiderInfo + " " + retForceStringWidth(strRiderNumber, 6,
InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderFirstName + " " + strRiderLastName, 19,
InsertionLocation.inCenter) + " " +
retForceStringWidth(strRiderDistrict, 4, InsertionLocation.inCenter) +
" " + retForceStringWidth(strRiderLapsCompleted, 4,
InsertionLocation.inCenter) + " " + retForceStringWidth("DQ", 3,
InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderDisqualified, 5,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderDNF,
5, InsertionLocation.inCenter) + " ";
} else{
// txtRiderInfo.Text =
txtRiderInfo.Text & " " & ForceStringWidth(rsReports![Rider Number],
6, inright) & " " & ForceStringWidth(rsReports![First Name] & " " &
rsReports![Last Name], 19, InCenter) & " " &
ForceStringWidth(rsReports![Rider District Number], 4, InCenter) & " "
& ForceStringWidth(rsReports![Laps Completed], 4, InCenter) & " " &
ForceStringWidth("N/A", 3, inleft) & " " & ForceStringWidth(rsReports!
[Rider Disqualified], 5, InCenter) & " " & ForceStringWidth(rsReports!
[Rider DNF], 5, InCenter) & " "
strRiderInfo =
strRiderInfo + " " + retForceStringWidth(strRiderNumber, 6,
InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderFirstName + " " + strRiderLastName, 19,
InsertionLocation.inCenter) + " " +
retForceStringWidth(strRiderDistrict, 4, InsertionLocation.inCenter) +
" " + retForceStringWidth(strRiderLapsCompleted, 4,
InsertionLocation.inCenter) + " " + retForceStringWidth("N/A", 3,
InsertionLocation.inLeft) + " " +
retForceStringWidth(strRiderDisqualified, 5,
InsertionLocation.inCenter) + " " + retForceStringWidth(strRiderDNF,
5, InsertionLocation.inCenter) + " ";
}
}
long
lngLastCompletedLapTime = 0;
for (int intLap = 1;
intLap <= intNumberOfLaps; intLap++){
long lngTotalTime =
rs.getLong("Lap" + intLap);
if (lngTotalTime > 0){
if
(cmbRaceReport.getSelectedIndex() == 2) {
java.util.Date
dtNow = new java.util.Date();
java.util.Date
dtStartTime = new java.util.Date();
dtStartTime.setTime(dtNow.getTime() - (lngTotalTime * 1000)); //
Subtract TotalTime in milliseconds (lngTotalTime is in Seconds So must
Be Converted)
//
txtRiderInfo.Text = txtRiderInfo.Text &
ForceStringWidth(ElapsedTime(Now, DateAdd("s", rsReports.Fields("Lap"
& Lap).value, Now), True), 13, InCenter) & " "
strRiderInfo =
strRiderInfo + retForceStringWidth(retElapsedTime(dtStartTime, dtNow,
true), 13, InsertionLocation.inCenter) + " ";
} else{
if (intLap ==
1){
java.util.Date dtNow = new java.util.Date();
java.util.Date dtStartTime = new java.util.Date();
dtStartTime.setTime(dtNow.getTime() - ((lngTotalTime - lngClassOffset)
* 1000)); //Subtract TotalTime in milliseconds and the Class Offset
(lngTotalTime is in Seconds So must Be Converted)
//
txtRiderInfo.Text = txtRiderInfo.Text &
ForceStringWidth(ElapsedTime(Now, DateAdd("s", rsReports.Fields("Lap"
& Lap).value - rsReports![Class Offset], Now), True), 13, InCenter) &
" "
strRiderInfo = strRiderInfo +
retForceStringWidth(retElapsedTime(dtStartTime, dtNow, true), 13,
InsertionLocation.inCenter) + " ";
} else{
java.util.Date dtNow = new java.util.Date();
java.util.Date dtLastLapTime = new java.util.Date();
java.util.Date dtCurrentLapTime = new java.util.Date();
dtLastLapTime.setTime(dtNow.getTime() - (lngLastCompletedLapTime *
1000));
dtCurrentLapTime.setTime(dtNow.getTime() - (lngTotalTime * 1000)); //
Subtract TotalTime in milliseconds and the Class Offset (lngTotalTime
is in Seconds So must Be Converted)
// Offset =
rsReports.Fields("lap" & Lap).value - rsReports.Fields("lap" & Lap -
1).value
//
txtRiderInfo.Text = txtRiderInfo.Text &
ForceStringWidth(ElapsedTime(Now, DateAdd("s", Offset, Now), True),
13, InCenter) & " "
strRiderInfo = strRiderInfo +
retForceStringWidth(retElapsedTime(dtCurrentLapTime, dtLastLapTime,
true), 13, InsertionLocation.inCenter) + " ";
}
}
lngLastCompletedLapTime = lngTotalTime;
} else{
// txtRiderInfo.Text =
txtRiderInfo.Text & ForceStringWidth("---", 13, InCenter) & " "
strRiderInfo =
strRiderInfo + retForceStringWidth("---", 13,
InsertionLocation.inCenter) + " ";
}
}
if (rs.getInt("Laps
Completed") > 0){
// txtRiderInfo.Text =
txtRiderInfo.Text & ForceStringWidth(ElapsedTime(DateAdd("s", -
TotalTime, Now), Now, True), 14, InCenter) & vbCrLf
java.util.Date dtNow =
new java.util.Date();
java.util.Date
dtStartTime = new java.util.Date();
dtStartTime.setTime(dtNow.getTime() - (lngLastCompletedLapTime *
1000)); //Subtract TotalTime in milliseconds (lngTotalTime is in
Seconds So must Be Converted)
strRiderInfo =
strRiderInfo + retForceStringWidth(retElapsedTime(dtStartTime, dtNow,
true), 14, InsertionLocation.inCenter) + "\r\n";
} else{
strRiderInfo =
strRiderInfo + retForceStringWidth("---", 14,
InsertionLocation.inCenter) + "\r\n";
// txtRiderInfo.Text =
txtRiderInfo.Text & ForceStringWidth("---", 14, InCenter) & vbCrLf
}
}
break;
}
}
} else{
// rsBackup.MoveFirst
// Do Until rsBackup.BOF = True Or rsBackup.EOF
= True
// If RiderIDValue(ReportIndex) = rsBackup!
[Original ID] Then
// If rsBackup![Rider Present] = "True"
Then
// If cmbReport.ListIndex = 1 Then
// If rsBackup![Rider
Disqualified] = True Then
// txtRiderInfo.Text =
txtRiderInfo.Text & " " & ForceStringWidth(rsBackup![Rider Number], 6,
inright) & " " & ForceStringWidth(rsBackup![First Name] & " " &
rsBackup![Last Name], 19, InCenter) & " " & ForceStringWidth(rsBackup!
[Rider District Number], 4, InCenter) & " " &
ForceStringWidth(rsBackup![Laps Completed], 4, InCenter) & " " &
ForceStringWidth("DQ", 3, inleft) & " " & ForceStringWidth(rsBackup!
[Rider Disqualified], 5, InCenter) & " " & ForceStringWidth(rsBackup!
[Rider DNF], 5, InCenter) & " "
// Else
// txtRiderInfo.Text =
txtRiderInfo.Text & " " & ForceStringWidth(rsBackup![Rider Number], 6,
inright) & " " & ForceStringWidth(rsBackup![First Name] & " " &
rsBackup![Last Name], 19, InCenter) & " " & ForceStringWidth(rsBackup!
[Rider District Number], 4, InCenter) & " " &
ForceStringWidth(rsBackup![Laps Completed], 4, InCenter) & " " &
ForceStringWidth(CStr(Position), 3, inleft) & " " &
ForceStringWidth(rsBackup![Rider Disqualified], 5, InCenter) & " " &
ForceStringWidth(rsBackup![Rider DNF], 5, InCenter) & " "
// End If
// Else
// If rsBackup![Rider
Disqualified] = True Then
// txtRiderInfo.Text =
txtRiderInfo.Text & " " & ForceStringWidth(rsBackup![Rider Number], 6,
inright) & " " & ForceStringWidth(rsBackup![First Name] & " " &
rsBackup![Last Name], 19, InCenter) & " " & ForceStringWidth(rsBackup!
[Rider District Number], 4, InCenter) & " " &
ForceStringWidth(rsBackup![Laps Completed], 4, InCenter) & " " &
ForceStringWidth("DQ", 3, inleft) & " " & ForceStringWidth(rsBackup!
[Rider Disqualified], 5, InCenter) & " " & ForceStringWidth(rsBackup!
[Rider DNF], 5, InCenter) & " "
// Else
// txtRiderInfo.Text =
txtRiderInfo.Text & " " & ForceStringWidth(rsBackup![Rider Number], 6,
inright) & " " & ForceStringWidth(rsBackup![First Name] & " " &
rsBackup![Last Name], 19, InCenter) & " " & ForceStringWidth(rsBackup!
[Rider District Number], 4, InCenter) & " " &
ForceStringWidth(rsBackup![Laps Completed], 4, InCenter) & " " &
ForceStringWidth("N/A", 3, inleft) & " " & ForceStringWidth(rsBackup!
[Rider Disqualified], 5, InCenter) & " " & ForceStringWidth(rsBackup!
[Rider DNF], 5, InCenter) & " "
// End If
// End If
// For Lap = 1 To NumberOfLaps
// If rsBackup.Fields("Lap" &
Lap).value > 0 Then
// If cmbReport.ListIndex =
1 Then
// TotalTime =
rsBackup.Fields("Lap" & Lap).value
// txtRiderInfo.Text =
txtRiderInfo.Text & ForceStringWidth(ElapsedTime(Now, DateAdd("s",
rsBackup.Fields("Lap" & Lap).value, Now), True), 13, InCenter) & " "
// Else
// Debug.Print rsBackup!
[Class Offset]
// TotalTime =
rsBackup.Fields("Lap" & Lap).value - rsBackup![Class Offset]
// If Lap = 1 Then
// Debug.Print
rsBackup![Class Offset]
//
txtRiderInfo.Text = txtRiderInfo.Text &
ForceStringWidth(ElapsedTime(Now, DateAdd("s", rsBackup.Fields("Lap" &
Lap).value - rsBackup![Class Offset], Now), True), 13, InCenter) & " "
// Else
// Offset =
rsBackup.Fields("lap" & Lap).value - rsBackup.Fields("lap" & Lap -
1).value
//
txtRiderInfo.Text = txtRiderInfo.Text &
ForceStringWidth(ElapsedTime(Now, DateAdd("s", Offset, Now), True),
13, InCenter) & " "
// End If
// End If
// Else
// txtRiderInfo.Text =
txtRiderInfo.Text & ForceStringWidth("---", 13, InCenter) & " "
// End If
// Next Lap
// If rsBackup![Laps Completed] > 0
Then
// txtRiderInfo.Text =
txtRiderInfo.Text & ForceStringWidth(ElapsedTime(DateAdd("s", -
TotalTime, Now), Now, True), 14, InCenter) & vbCrLf
// Else
// txtRiderInfo.Text =
txtRiderInfo.Text & ForceStringWidth("---", 14, InCenter) & vbCrLf
// End If
// End If
// Exit Do
// End If
// rsBackup.MoveNext
// Loop
}
intPosition++;
}
txtRiderInfo.setText(strRiderInfo);
} catch (java.sql.SQLException ex) {
ex.printStackTrace();
}
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new frmRaceReport().setVisible(true);
}
});
}
private int getNumberOfLaps(long lngRaceID){
java.sql.Statement stmt;
java.sql.ResultSet rs;
int intNumberOfLaps = 0;
if (openRaceDatabase()){
try {
stmt = cnRaceDatabase.createStatement();
rs = stmt.executeQuery("SELECT [ID], [Laps Completed]
FROM [Master Rider Table] Where [Race ID] = " + lngRaceID + " Order By
[Laps Completed] DESC");
while (rs.next()){
intNumberOfLaps = rs.getInt("Laps Completed");
break;
}
rs.close();
stmt.close();
stmt = cnRaceDatabase.createStatement();
rs = stmt.executeQuery("SELECT [ID], [Laps Completed]
FROM [Modified Rider Records] Where [Race ID] = " + lngRaceID + "
Order By [Laps Completed] DESC");
while (rs.next()){
int intTemp = rs.getInt("Laps Completed");
if (intTemp > intNumberOfLaps){
intNumberOfLaps = intTemp;
}
break;
}
rs.close();
stmt.close();
} catch(java.sql.SQLException ex){
}
}
return intNumberOfLaps;
}
public static String left(String strval, int length){
if (length < 1 || strval.length() < length){
return "";
}
return strval.substring(0,length);
}
private void readAndSort(){
if (openRaceDatabase()){
String strClassString;
if (cmbRaceClass.getSelectedIndex() == 1) { //All
Classes
strClassString = "> 0";
} else {
strClassString = " = " +
Integer.toString(aryClassID.get(cmbRaceClass.getSelectedIndex()));
}
//Build Database Variables
java.sql.Statement stmt;
java.sql.Statement stmt_modified;
java.sql.ResultSet rs;
java.sql.ResultSet rs_modified;
//Build Report Arrays
String QueryString1 = "Select Count (*) FROM [Master Rider
Table] Where [Race ID] = " +
Integer.toString(aryRaceID.get(cmbRaceEvents.getSelectedIndex())) + "
AND [Class ID]" + strClassString;
String QueryString2 = "";
try {
stmt = cnRaceDatabase.createStatement();
rs = stmt.executeQuery(QueryString1);
if (rs.next()){
intRacerCount = (int)rs.getLong(1);
}
rs.close();
stmt.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
if (intRacerCount > 0){
//Do Nothing
} else{
javax.swing.JOptionPane.showMessageDialog(null, "No
Riders Available For This Class.", "Report Not Available",
javax.swing.JOptionPane.OK_OPTION);
//Need To Leave The Method here
}
//Must Add One To Array as Array 0 is Special For Sorting
lngRiderLapTime = new long[intRacerCount + 1];
intRiderLapCount = new int[intRacerCount + 1];
lngRiderIDValue = new long[intRacerCount + 1];
blnRiderModified = new boolean[intRacerCount + 1];
blnRiderDisqualified = new boolean[intRacerCount + 1];
//Sort Riders By Lap Time
QueryString1 = "Select * FROM [Master Rider Table] Where
[Race ID] = " +
Integer.toString(aryRaceID.get(cmbRaceEvents.getSelectedIndex())) + "
AND [Class ID]" + strClassString + " Order By [Rider Disqualified]
DESC, [Laps Completed] DESC";
QueryString2 = "Select * FROM [Modified Rider Records]
Where [Race ID] = " +
Integer.toString(aryRaceID.get(cmbRaceEvents.getSelectedIndex())) + "
AND [Class ID]" + strClassString + " Order By [Rider Disqualified]
DESC, [Laps Completed] DESC";
try {
stmt =
cnRaceDatabase.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
stmt_modified =
cnRaceDatabase.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(QueryString1);
rs_modified =
stmt_modified.executeQuery(QueryString2);
int intReportIndex = 0;
while (rs.next()){
intReportIndex++;
long lngRiderID = rs.getLong("ID");
boolean blnModifiedRecordFound = false;
rs_modified.beforeFirst();
while (rs_modified.next()){
long lngRiderID_modified =
rs_modified.getLong("Original ID");
if (lngRiderID == lngRiderID_modified){
blnModifiedRecordFound = true;
blnRiderModified[intReportIndex] = true;
intRiderLapCount[intReportIndex] =
rs_modified.getInt("Laps Completed");
if (intRiderLapCount[intReportIndex] >
0){
lngRiderLapTime[intReportIndex] =
rs_modified.getLong("Lap" + intRiderLapCount[intReportIndex]);
}
blnRiderDisqualified[intReportIndex] =
rs_modified.getBoolean("Rider Disqualified");
lngRiderIDValue[intReportIndex] =
lngRiderID_modified;
break;
}
}
if (blnModifiedRecordFound == false){
blnRiderModified[intReportIndex] = false;
intRiderLapCount[intReportIndex] =
rs.getInt("Laps Completed");
if (intRiderLapCount[intReportIndex] > 0){
lngRiderLapTime[intReportIndex] =
rs.getLong("Lap" + intRiderLapCount[intReportIndex]);
}
blnRiderDisqualified[intReportIndex] =
rs.getBoolean("Rider Disqualified");
lngRiderIDValue[intReportIndex] = lngRiderID;
} else{
//Do Nothing
}
}
for (int intSortIndex=1; intSortIndex <=
intRacerCount; intSortIndex++){
boolean blnRecordMoved = false;
for (int intHighestValueIndex = intRacerCount;
intHighestValueIndex >= (intSortIndex + 1); intHighestValueIndex--){
if ((intRiderLapCount[intHighestValueIndex] ==
intRiderLapCount[intSortIndex] &&
lngRiderLapTime[intHighestValueIndex] < lngRiderLapTime[intSortIndex])
|| (intRiderLapCount[intHighestValueIndex] >
intRiderLapCount[intSortIndex])){
blnRiderModified[0] =
blnRiderModified[intHighestValueIndex];
intRiderLapCount[0] =
intRiderLapCount[intHighestValueIndex];
lngRiderLapTime[0] =
lngRiderLapTime[intHighestValueIndex];
lngRiderIDValue[0] =
lngRiderIDValue[intHighestValueIndex];
blnRiderDisqualified[0] =
blnRiderDisqualified[intHighestValueIndex];
blnRiderModified[intHighestValueIndex] =
blnRiderModified[intSortIndex];
intRiderLapCount[intHighestValueIndex] =
intRiderLapCount[intSortIndex];
lngRiderLapTime[intHighestValueIndex] =
lngRiderLapTime[intSortIndex];
lngRiderIDValue[intHighestValueIndex] =
lngRiderIDValue[intSortIndex];
blnRiderDisqualified[intHighestValueIndex]
= blnRiderDisqualified[intSortIndex];
blnRiderModified[intSortIndex] =
blnRiderModified[0];
intRiderLapCount[intSortIndex] =
intRiderLapCount[0];
lngRiderLapTime[intSortIndex] =
lngRiderLapTime[0];
lngRiderIDValue[intSortIndex] =
lngRiderIDValue[0];
blnRiderDisqualified[intSortIndex] =
blnRiderDisqualified[0];
blnRecordMoved = true;
}
}
if (blnRecordMoved == true){intSortIndex = 0;}
}
for (int intSortIndex = 1; intSortIndex <=
intRacerCount; intSortIndex++){
boolean blnRecordMoved = false;
for (int intHighestValueIndex = intSortIndex;
intHighestValueIndex >= (intRacerCount - 1); intHighestValueIndex-- ){
if (blnRiderDisqualified[intHighestValueIndex]
== true && blnRiderDisqualified[intHighestValueIndex + 1] == false) {
blnRiderModified[0] =
blnRiderModified[intHighestValueIndex];
intRiderLapCount[0] =
intRiderLapCount[intHighestValueIndex];
lngRiderLapTime[0] =
lngRiderLapTime[intHighestValueIndex];
lngRiderIDValue[0] =
lngRiderIDValue[intHighestValueIndex];
blnRiderDisqualified[0] =
blnRiderDisqualified[intHighestValueIndex];
blnRiderModified[intHighestValueIndex] =
blnRiderModified[intHighestValueIndex + 1];
intRiderLapCount[intHighestValueIndex] =
intRiderLapCount[intHighestValueIndex + 1];
lngRiderLapTime[intHighestValueIndex] =
lngRiderLapTime[intHighestValueIndex + 1];
lngRiderIDValue[intHighestValueIndex] =
lngRiderIDValue[intHighestValueIndex + 1];
blnRiderDisqualified[intHighestValueIndex]
= blnRiderDisqualified[intHighestValueIndex + 1];
blnRiderModified[intHighestValueIndex + 1]
= blnRiderModified[0];
intRiderLapCount[intHighestValueIndex + 1]
= intRiderLapCount[0];
lngRiderLapTime[intHighestValueIndex + 1]
= lngRiderLapTime[0];
lngRiderIDValue[intHighestValueIndex + 1]
= lngRiderIDValue[0];
blnRiderDisqualified[intHighestValueIndex
+ 1] = blnRiderDisqualified[0];
blnRecordMoved = true;
}
}
if (blnRecordMoved == true){intSortIndex = 0;}
}
} catch(java.sql.SQLException ex){
}
}
}
public static long retDateDiffInSeconds(java.util.Date date1,
java.util.Date date2){
long returnvalue = -9999;
returnvalue = ((date1.getTime() - date2.getTime()) / 1000);
return returnvalue;
}
private static String retDateFormat(java.util.Date datetime,
String format){
java.text.Format formatter = new java.text.SimpleDateFormat(format);
String s = formatter.format(datetime);
return s;
}
private static String retElapsedTime(java.util.Date dtStartTime,
java.util.Date dtCurrentTime, boolean blnShortHand ){
float[] fltClockValue = new float[5];
String[] strLabel = new String[5];
strLabel[1] = "Second";
fltClockValue[1] =
java.lang.Math.abs((float)retDateDiffInSeconds(dtStartTime,
dtCurrentTime)); //Make Sure Value Is Positive
strLabel[4] = "Day";
fltClockValue[4] = (int)(fltClockValue[1] / 86400);
strLabel[3] = "Hour";
fltClockValue[3] = (int)((fltClockValue[1] - (fltClockValue[4]
* 86400)) / 3600);
strLabel[2] = "Minute";
fltClockValue[2] = (int)(fltClockValue[1] / 60);
fltClockValue[2] = fltClockValue[2] % 60;
fltClockValue[1] = fltClockValue[1] % 60;
for (int intIndex = 1; intIndex <= 4; intIndex++){
if (fltClockValue[intIndex] != 1.0){strLabel[intIndex] =
strLabel[intIndex] + "s";}
}
String strElapsedTime = "";
if (blnShortHand == false){
if (fltClockValue[4] > 0){
strElapsedTime = fltClockValue[4] + " " + strLabel[4]
+ " " + fltClockValue[3] + " " + strLabel[3] + " " + fltClockValue[2]
+ " " + strLabel[2] + " " + fltClockValue[1] + " " + strLabel[1];
} else{
strElapsedTime = fltClockValue[3] + " " + strLabel[3]
+ " " + fltClockValue[2] + " " + strLabel[2] + " " + fltClockValue[1]
+ " " + strLabel[1];
}
} else{
java.text.NumberFormat formatter = new
java.text.DecimalFormat("00");
if (fltClockValue[4] > 0) {
strElapsedTime = fltClockValue[4] + "D " +
formatter.format(fltClockValue[3]) + "H " +
formatter.format(fltClockValue[2]) + "M " +
formatter.format(fltClockValue[1]) + "S";
} else{
strElapsedTime = formatter.format(fltClockValue[3]) +
"H " + formatter.format(fltClockValue[2]) + "M " +
formatter.format(fltClockValue[1]) + "S";
}
}
return strElapsedTime;
}
private static String retForceStringWidth(String strStringData,
int intStringLength, InsertionLocation InsertionPoint){
String strNameString = "";
if (strStringData.length() > intStringLength) {
strStringData = left(strStringData, intStringLength);
}
String strForceStringWidth = strStringData;
if (strForceStringWidth.length() > intStringLength){
strNameString = left(strForceStringWidth,
intStringLength);
} else{
while (strForceStringWidth.length() < intStringLength){
if (InsertionPoint == InsertionLocation.inRight){
strForceStringWidth = strForceStringWidth + " ";
} else if (InsertionPoint == InsertionLocation.inLeft)
{
strForceStringWidth = " " + strForceStringWidth;
} else if (InsertionPoint ==
InsertionLocation.inCenter){
strForceStringWidth = " " + strForceStringWidth;
if (strForceStringWidth.length() < intStringLength)
{
strForceStringWidth = strForceStringWidth + "
";
}
}
}
}
return strForceStringWidth;
}
public boolean openRaceDatabase(){
boolean dbopen = false;
if (cnRaceDatabase != null){
try {
cnRaceDatabase.getMetaData(); //recommended way to
check connection
dbopen = true;
} catch (java.sql.SQLException ex) {
ex.printStackTrace();
try {
cnRaceDatabase.close();
} catch (java.sql.SQLException ex1) {
ex.printStackTrace();
}
}
}
if (dbopen == false){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cnRaceDatabase =
java.sql.DriverManager.getConnection("jdbcdbcriver={Microsoft
Access Driver
(*.mdb)};DBQ=RaceDatabase.mdb;DriverID=22;READONLY=true");
cnRaceDatabase.getMetaData();
dbopen = true;
}catch (java.sql.SQLException se) {
javax.swing.JOptionPane.showMessageDialog(null, "Error
Opening Database.\r\n" + se.getErrorCode() + ":" + se.getMessage(),
"Database Error", javax.swing.JOptionPane.ERROR_MESSAGE);
System.exit(1); // Note that this is an abnormal
termination of the program.
} catch (ClassNotFoundException cnfe) {
//MainSettings.notifier.logProgramNote("Open Settings
Derby Driver Error:", cnfe.getMessage());
}
}
return dbopen;
}
// Variables declaration - do not modify
private javax.swing.JButton btExit;
private javax.swing.JComboBox cmbRaceClass;
private javax.swing.JComboBox cmbRaceEvents;
private javax.swing.JComboBox cmbRaceReport;
private datechooser.beans.DateChooserCombo dtpDateTime;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JTextArea txtRiderInfo;
// End of variables declaration
private java.sql.Connection cnRaceDatabase;
private boolean blnStartup = true;
private boolean blnBuildingRaceEvents = false;
private boolean blnBuildingRaceClasses = false;
private String strDateTime = "";
private java.util.ArrayList<String> aryMasterRaceClassesAllowed =
new java.util.ArrayList<String>();
private java.util.ArrayList<Integer> aryClassID = new
java.util.ArrayList<Integer>();
private java.util.ArrayList<Integer> aryRaceID = new
java.util.ArrayList<Integer>();
long[] lngRiderLapTime;
int[] intRiderLapCount;
long[] lngRiderIDValue;
boolean[] blnRiderModified;
boolean[] blnRiderDisqualified;
int intRacerCount = 0;
private enum InsertionLocation{
inLeft,
inRight,
inCenter
}
}
*****************************************************************************************
JNLP FILE BELOW
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jnlp PUBLIC "-//Sun Microsystems, Inc.//DTD JNLP 1.5//EN"
"http://www.netbeans.org/jnlp/DTD/jnlp.dtd">
<jnlp codebase="file:///C:/JavaCode/RaceReporter"
href="RaceReporter.jnlp">
<information>
<title>RaceReporter</title>
<vendor>R--Y--E, Inc.</vendor>
<homepage href="homepage.html"/>
<description> </description>
<icon href="default"/>
<offline-allowed/>
<shortcut online="true">
<desktop/>
</shortcut>
</information>
<resources>
<j2se href="http://java.sun.com/products/autodl/j2se"
version="1.4+"/>
</resources>
<resources>
<jar download="eager" href="dist/RaceReporter.jar" main="false"/>
</resources>
<resources locale="" os="">
<jar download="eager" href="DateChooser.jar" main="false"
version=""/>
</resources>
<application-desc main-class="racereporter.frmRaceReport"/>
</jnlp>