public void navRefresh_Click( object sender, EventArgs e )
        {
            // Retrieve data from database
            if ( mySanctionNum != null && myEvent != null ) {
                String curDataType = "all", curPlcmtMethod = "score";
                String curPlcmtOrg, curPointsMethod;
                Int16 curNumPrelimRounds = 0;
                CalcScoreSummary curCalcSummary = new CalcScoreSummary();

                // Retrieve data from database depending on selection criteria
                String curMsg = "Tournament scores retrieved ";

                if ( bestScoreButton.Checked ) {
                    curDataType = "best";
                    winStatusMsg.Text = curMsg + "- best scores ";
                } else if ( totalScoreButton.Checked ) {
                    curDataType = "total";
                    winStatusMsg.Text = curMsg + "- total scores";
                } else if ( finalScoreButton.Checked ) {
                    curDataType = "final";
                    winStatusMsg.Text = curMsg + "- final scores";
                } else if ( firstScoreButton.Checked ) {
                    curDataType = "first";
                    winStatusMsg.Text = curMsg + "- first scores";
                } else if ( roundScoreButton.Checked ) {
                    curDataType = "round";
                    winStatusMsg.Text = curMsg + "- all scores";
                } else if (h2hScoreButton.Checked) {
                    curDataType = "h2h";
                    winStatusMsg.Text = curMsg + "- head to head";
                } else {
                    curDataType = "best";
                    winStatusMsg.Text = curMsg + "- best scores ";
                }
                myTourProperties.SlalomSummaryDataType = curDataType;

                if ( rawScoreButton.Checked ) {
                    curPlcmtMethod = "score";
                } else if ( pointsScoreButton.Checked ) {
                    curPlcmtMethod = "points";
                } else {
                    curPlcmtMethod = "score";
                }
                myTourProperties.SlalomSummaryPlcmtMethod = curPlcmtMethod;

                if ( groupPlcmtButton.Checked ) {
                    curPlcmtOrg = "group";
                    EventGroup.Visible = true;
                } else if ( plcmtTourButton.Checked ) {
                    curPlcmtOrg = "tour";
                    EventGroup.Visible = false;
                } else if (plcmtDivButton.Checked) {
                    curPlcmtOrg = "div";
                    EventGroup.Visible = false;
                } else if (plcmtDivGrpButton.Checked) {
                    curPlcmtOrg = "divgr";
                    EventGroup.Visible = true;
                } else {
                    curPlcmtOrg = "tour";
                    EventGroup.Visible = false;
                }
                myTourProperties.SlalomSummaryPlcmtOrg = curPlcmtOrg;

                HCapBase.Visible = false;
                HCapScore.Visible = false;
                if ( nopsPointsButton.Checked ) {
                    curPointsMethod = "nops";
                } else if ( plcmtPointsButton.Checked ) {
                    curPointsMethod = "plcmt";
                } else if ( kBasePointsButton.Checked ) {
                    curPointsMethod = "kbase";
                } else if ( handicapPointsButton.Checked ) {
                    curPointsMethod = "hcap";
                    HCapBase.Visible = true;
                    HCapScore.Visible = true;
                } else if ( ratioPointsButton.Checked ) {
                    curPointsMethod = "ratio";
                    HCapBase.Visible = true;
                    HCapScore.Visible = true;
                } else {
                    curPointsMethod = "nops";
                }
                myTourProperties.SlalomSummaryPointsMethod = curPointsMethod;

                if (myTourRules.ToLower().Equals( "iwwf" ) && kBasePointsButton.Checked) {
                    HCapBase.Visible = false;
                    HCapScore.Visible = false;
                }

                if ( myTourRules.ToLower().Equals( "ncwsa" )
                    && plcmtPointsButton.Checked
                    && pointsScoreButton.Checked
                    ) {
                    rawScoreButton.Checked = true;
                    curPlcmtMethod = "score";
                    myTourProperties.SlalomSummaryPlcmtMethod = curPlcmtMethod;
                }

                if (h2hScoreButton.Checked) {
                    EventGroup.Visible = true;
                    if (plcmtTourButton.Checked) {
                        curPlcmtOrg = "tour";
                    } else {
                        curPlcmtOrg = "div";
                    }
                }
                if ( h2hScoreButton.Checked || finalScoreButton.Checked ) {
                    if ( numPrelimTextBox.Text.Length == 0 ) {
                        MessageBox.Show( "Number of preliminary rounds is required for Head to Head reporting" );
                        return;
                    } else {
                        curNumPrelimRounds = Convert.ToInt16( numPrelimTextBox.Text );
                    }
                }

                String curGroupValue = "";
                try {
                    curGroupValue = EventGroupList.SelectedItem.ToString();
                    if (!( curGroupValue.ToLower().Equals( "all" ) )) {
                        if (myTourRules.ToLower().Equals( "ncwsa" )) {
                            if (curGroupValue.ToUpper().Equals( "MEN A" )) {
                                curGroupValue = "CM";
                            } else if (curGroupValue.ToUpper().Equals( "WOMEN A" )) {
                                curGroupValue = "CW";
                            } else if (curGroupValue.ToUpper().Equals( "MEN B" )) {
                                curGroupValue = "BM";
                            } else if (curGroupValue.ToUpper().Equals( "WOMEN B" )) {
                                curGroupValue = "BW";
                            } else {
                                curGroupValue = "All";
                            }
                        }
                    }
                } catch {
                    curGroupValue = "All";
                }

                this.Cursor = Cursors.WaitCursor;
                if (curGroupValue.ToLower().Equals( "all" )) {
                    if ( myTourRules.ToLower().Equals( "iwwf" ) ) {
                        curPointsMethod = "kbase";
                        mySummaryDataTable = curCalcSummary.CalcIwwfEventPlcmts( myTourRow, mySanctionNum, "Slalom", myTourRules, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                    } else if ( h2hScoreButton.Checked || ( finalScoreButton.Checked && curNumPrelimRounds > 0 ) ) {
                        mySummaryDataTable = curCalcSummary.getSlalomSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, curNumPrelimRounds );
                    } else {
                        mySummaryDataTable = curCalcSummary.getSlalomSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );
                    }
                } else {
                    if (myTourRules.ToLower().Equals( "iwwf" )) {
                        curPointsMethod = "kbase";
                        mySummaryDataTable = curCalcSummary.CalcIwwfEventPlcmts( myTourRow, mySanctionNum, "Slalom", myTourRules, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, "All", curGroupValue );
                    } else if ( h2hScoreButton.Checked || ( finalScoreButton.Checked && curNumPrelimRounds > 0 ) ) {
                        mySummaryDataTable = curCalcSummary.getSlalomSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, "All", curGroupValue, curNumPrelimRounds );
                    } else {
                        if (myTourRules.ToLower().Equals( "ncwsa" )) {
                            mySummaryDataTable = curCalcSummary.getSlalomSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, "All", curGroupValue );
                        } else {
                            mySummaryDataTable = curCalcSummary.getSlalomSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, "All", curGroupValue );
                        }
                    }
                }

                if (mySummaryDataTable.Rows.Count > 0) {
                    if (h2hScoreButton.Checked || ( finalScoreButton.Checked && curNumPrelimRounds > 0) ) {
                        mySummaryDataTable = curCalcSummary.buildHeadToHeadSummary( mySummaryDataTable, myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, curNumPrelimRounds, "Slalom" );
                    } else {
                        if (mySortCommand.Length > 1) {
                            if (myTourRules.ToLower().Equals( "iwwf" ) && curPointsMethod.ToLower().Equals( "kbase" )) {
                            } else {
                                mySummaryDataTable.DefaultView.Sort = mySortCommand;
                                mySummaryDataTable = mySummaryDataTable.DefaultView.ToTable();
                            }
                        }
                    }
                    loadDataGrid( mySummaryDataTable );
                } else {
                    scoreSummaryDataGridView.Rows.Clear();
                    MessageBox.Show( "No data available for report" );
                }
            }
            this.Cursor = Cursors.Default;
        }
        public void navRefresh_Click( object sender, EventArgs e )
        {
            // Retrieve data from database
            if ( mySanctionNum != null && myTourRow != null ) {
                String curDataType = "best", curPlcmtMethod = "score", curPointsMethod = "";
                String curPlcmtOrg = "", curPlcmtOverallOrg = "";
                //String curPlcmtOrg = "div";

                CalcScoreSummary curCalcSummary = new CalcScoreSummary();

                // Retrieve data from database depending on selection criteria
                String curMsg = "Tournament scores retrieved ";

                if ( bestScoreButton.Checked ) {
                    curDataType = "best";
                    winStatusMsg.Text = curMsg + "- best scores ";
                } else if ( totalScoreButton.Checked ) {
                    curDataType = "total";
                    winStatusMsg.Text = curMsg + "- total scores";
                } else if ( finalScoreButton.Checked ) {
                    curDataType = "final";
                    winStatusMsg.Text = curMsg + "- final scores";
                } else if ( firstScoreButton.Checked ) {
                    curDataType = "first";
                    winStatusMsg.Text = curMsg + "- first scores";
                }
                myTourProperties.SlalomScorebookDataType = curDataType;
                if ( nopsPointsButton.Checked ) {
                    curPointsMethod = "nops";
                } else if ( plcmtPointsButton.Checked ) {
                    curPointsMethod = "plcmt";
                } else if ( kBasePointsButton.Checked ) {
                    curPointsMethod = "kbase";
                } else if ( ratioPointsButton.Checked ) {
                    curPointsMethod = "ratio";
                } else {
                    curPointsMethod = "nops";
                }
                myTourProperties.SlalomScorebookPointsMethod = curPointsMethod;

                if ( plcmtDivButton.Checked ) {
                    curPlcmtOrg = "div";
                    curPlcmtOverallOrg = "agegroup";
                    EventGroup.Visible = false;
                } else if ( plcmtDivGrpButton.Checked ) {
                    curPlcmtOrg = "divgr";
                    curPlcmtOverallOrg = "agegroupgroup";
                    EventGroup.Visible = true;
                } else {
                    curPlcmtOrg = "div";
                    curPlcmtOverallOrg = "agegroup";
                    EventGroup.Visible = false;
                }
                myTourProperties.SlalomScorebookPlcmtOrg = curPlcmtOrg;

                Cursor.Current = Cursors.WaitCursor;
                scoreSummaryDataGridView.BeginInvoke( (MethodInvoker)delegate() {
                    Application.DoEvents();
                    winStatusMsg.Text = "Tournament entries retrieved";
                } );

                String curGroupValue = "";
                try {
                    curGroupValue = EventGroupList.SelectedItem.ToString();
                    if (!( curGroupValue.ToLower().Equals( "all" ) )) {
                        if (myTourRules.ToLower().Equals( "ncwsa" )) {
                            if (curGroupValue.ToUpper().Equals( "MEN A" )) {
                                curGroupValue = "CM";
                            } else if (curGroupValue.ToUpper().Equals( "WOMEN A" )) {
                                curGroupValue = "CW";
                            } else if (curGroupValue.ToUpper().Equals( "MEN B" )) {
                                curGroupValue = "BM";
                            } else if (curGroupValue.ToUpper().Equals( "WOMEN B" )) {
                                curGroupValue = "BW";
                            } else {
                                curGroupValue = "All";
                            }
                        }
                    }
                } catch {
                    curGroupValue = "All";
                }

                if ( curGroupValue.ToLower().Equals( "all" ) ) {
                    if ( myTourRules.ToLower().Equals( "iwwf" ) && curPointsMethod.ToLower().Equals( "kbase" ) ) {
                        mySummaryDataTable = curCalcSummary.CalcIwwfEventPlcmts( myTourRow, mySanctionNum, "Scorebook", myTourRules, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                    } else {
                        mySummaryDataTable = curCalcSummary.getSlalomSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );

                        myMemberData = curCalcSummary.getMemberData( mySanctionNum );
                        mySlalomDetail = curCalcSummary.getSlalomScoreDetail( myTourRow, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                        mySummaryDataTable = curCalcSummary.buildTourScorebook( mySanctionNum, myTourRow, myMemberData, mySummaryDataTable, mySlalomDetail, null, null );
                    }
                } else {
                    if ( myTourRules.ToLower().Equals( "iwwf" ) && curPointsMethod.ToLower().Equals( "kbase" ) ) {
                        mySummaryDataTable = curCalcSummary.CalcIwwfEventPlcmts( myTourRow, mySanctionNum, "Scorebook", myTourRules, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, "All", curGroupValue );
                    } else {
                        mySummaryDataTable = curCalcSummary.getSlalomSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, "All", curGroupValue );

                        myMemberData = curCalcSummary.getMemberData( mySanctionNum, curGroupValue );
                        mySlalomDetail = curCalcSummary.getSlalomScoreDetail( myTourRow, curPlcmtMethod, curPlcmtOrg, curPointsMethod, "All", curGroupValue );
                        mySummaryDataTable = curCalcSummary.buildTourScorebook( mySanctionNum, myTourRow, myMemberData, mySummaryDataTable, mySlalomDetail, null, null );
                    }
                }

                loadSummaryDataGrid();
                Cursor.Current = Cursors.Default;
            }
        }
        public Boolean exportTourPerfData( String inSanctionId )
        {
            Boolean returnStatus = false;
            String curMemberId = "", curReadyToSki = "", curAgeGroup = "";
            StringBuilder outLine = new StringBuilder( "" );
            StreamWriter outBuffer = null;
            String curFilename = "", curRules = "";
            myTourProperties = TourProperties.Instance;

            DataTable curTourDataTable = getTourData( inSanctionId );
            if ( curTourDataTable != null ) {
                if ( curTourDataTable.Rows.Count > 0 ) {
                    myTourRow = curTourDataTable.Rows[0];
                    curRules = (String)myTourRow["Rules"];

                    curFilename = inSanctionId.Trim() + myTourRow["Class"].ToString().Trim() + ".wsp";
                    outBuffer = getExportFile( curFilename );
                    if ( outBuffer != null ) {
                        Log.WriteFile( "Export performance data file begin: " + curFilename );

                        //Build file header line and write to file
                        outLine.Append( writeHeader( inSanctionId ) );
                        outBuffer.WriteLine( outLine.ToString() );

                        //Initialize output buffer
                        outLine = new StringBuilder( "" );
                    }
                }
            }
            if ( outBuffer != null ) {
                myProgressInfo = new ProgressWindow();
                myProgressInfo.setProgessMsg( "Processing Skier Performance Data File" );
                myProgressInfo.Show();
                myProgressInfo.Refresh();
                myProgressInfo.setProgressMax( 10 );

                DataTable curMemberDataTable = getMemberData( inSanctionId );
                if ( curMemberDataTable != null ) {
                    DataRow[] curScoreRows, curScoreSlalomRows, curScoreTrickRows, curScoreJumpRows;
                    String curPlcmtMethod = "score", curPlcmtOverallOrg = "agegroup";
                    String curDataType = myTourProperties.MasterSummaryDataType;
                    //String curDataType = Properties.Settings.Default.MasterSummaryV2DataType;
                    if ( curDataType.ToLower().Equals( "total" )
                        || curDataType.ToLower().Equals( "best" )
                        || curDataType.ToLower().Equals( "final" )
                        || curDataType.ToLower().Equals( "first" ) ) {
                    } else {
                        curDataType = "best";
                    }
                    String curPointsMethod = myTourProperties.MasterSummaryPointsMethod;
                    //String curPointsMethod = Properties.Settings.Default.MasterSummaryV2PointsMethod;
                    if ( curPointsMethod.ToLower().Equals( "nops" )
                        || curPointsMethod.ToLower().Equals( "plcmt" )
                        || curPointsMethod.ToLower().Equals( "kbase" )
                        || curPointsMethod.ToLower().Equals( "ratio" ) ) {
                    } else {
                        curPointsMethod = "nops";
                    }
                    String curPlcmtOrg = myTourProperties.MasterSummaryPlcmtOrg;
                    //String curPlcmtOrg = Properties.Settings.Default.MasterSummaryV2PlcmtOrg;
                    if ( curPlcmtOrg.ToLower().Equals("div") ) {
                        curPlcmtOverallOrg = "agegroup";
                    } else if ( curPlcmtOrg.ToLower().Equals( "divgr" ) ) {
                        curPlcmtOverallOrg = "agegroupgroup";
                    } else {
                        curPlcmtOverallOrg = "agegroup";
                        curPlcmtOrg = "div";
                    }

                    CalcScoreSummary curCalcSummary = new CalcScoreSummary();
                    DataTable mySummaryDataTable = null;

                    DataTable myMemberData = curCalcSummary.getMemberData( inSanctionId );
                    myProgressInfo.setProgressValue( 1 );
                    myProgressInfo.Refresh();

                    if (curRules.ToLower().Equals( "iwwf" ) && curPointsMethod.ToLower().Equals( "kbase" )) {
                        mySummaryDataTable = curCalcSummary.CalcIwwfEventPlcmts( myTourRow, inSanctionId, "Scorebook", curRules, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                        myProgressInfo.setProgressValue( 5 );
                        myProgressInfo.Refresh();

                        DataTable mySlalomDetail = curCalcSummary.getSlalomScoreDetail( myTourRow, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                        myProgressInfo.setProgressValue( 6 );
                        myProgressInfo.Refresh();
                        DataTable myTrickDetail = curCalcSummary.getTrickScoreDetail( myTourRow, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                        myProgressInfo.setProgressValue( 7 );
                        myProgressInfo.Refresh();
                        DataTable myJumpDetail = curCalcSummary.getJumpScoreDetail( myTourRow, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                        myProgressInfo.setProgressValue( 8 );
                        myProgressInfo.Refresh();
                        DataTable newSummaryDataTable = curCalcSummary.buildTourScorebook( inSanctionId, myTourRow, myMemberData, mySummaryDataTable, mySlalomDetail, myTrickDetail, myJumpDetail );
                        mySummaryDataTable = newSummaryDataTable;
                        myProgressInfo.setProgressValue( 9 );
                        myProgressInfo.Refresh();

                    } else {
                        DataTable mySlalomDataTable = curCalcSummary.getSlalomSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );
                        myProgressInfo.setProgressValue( 2 );
                        myProgressInfo.Refresh();
                        DataTable myTrickDataTable = curCalcSummary.getTrickSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );
                        myProgressInfo.setProgressValue( 3 );
                        myProgressInfo.Refresh();
                        DataTable myJumpDataTable = curCalcSummary.getJumpSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );
                        myProgressInfo.setProgressValue( 4 );
                        myProgressInfo.Refresh();
                        mySummaryDataTable = curCalcSummary.buildOverallSummary( myTourRow, mySlalomDataTable, myTrickDataTable, myJumpDataTable, curDataType, curPlcmtOverallOrg );
                        myProgressInfo.setProgressValue( 5 );
                        myProgressInfo.Refresh();

                        DataTable mySlalomDetail = curCalcSummary.getSlalomScoreDetail( myTourRow, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                        myProgressInfo.setProgressValue( 6 );
                        myProgressInfo.Refresh();
                        DataTable myTrickDetail = curCalcSummary.getTrickScoreDetail( myTourRow, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                        myProgressInfo.setProgressValue( 7 );
                        myProgressInfo.Refresh();
                        DataTable myJumpDetail = curCalcSummary.getJumpScoreDetail( myTourRow, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                        myProgressInfo.setProgressValue( 8 );
                        myProgressInfo.Refresh();
                        DataTable newSummaryDataTable = curCalcSummary.buildTourScorebook( inSanctionId, myTourRow, myMemberData, mySummaryDataTable, mySlalomDetail, myTrickDetail, myJumpDetail );
                        mySummaryDataTable = newSummaryDataTable;
                        myProgressInfo.setProgressValue( 9 );
                        myProgressInfo.Refresh();

                    }
                    mySkierClassList = new ListSkierClass();
                    mySkierClassList.ListSkierClassLoad();

                    int curRowCount = 0;
                    myProgressInfo.setProgressMax( curMemberDataTable.Rows.Count );
                    foreach ( DataRow curMemberRow in curMemberDataTable.Rows ) {
                        curRowCount++;
                        myProgressInfo.setProgressValue( curRowCount );
                        myProgressInfo.Refresh();

                        curMemberId = curMemberRow["MemberId"].ToString();
                        curAgeGroup = curMemberRow["AgeGroup"].ToString();
                        curReadyToSki = curMemberRow["ReadyToSki"].ToString();
                        curScoreRows = mySummaryDataTable.Select( "MemberId = '" + curMemberId + "' AND AgeGroup = '" + curAgeGroup + "'" );
                        //curScoreSlalomRows = mySlalomDataTable.Select( "MemberId = '" + curMemberId + "' AND AgeGroup = '" + curAgeGroup + "'" );
                        //curScoreTrickRows = myTrickDataTable.Select( "MemberId = '" + curMemberId + "' AND AgeGroup = '" + curAgeGroup + "'" );
                        //curScoreJumpRows = myJumpDataTable.Select( "MemberId = '" + curMemberId + "' AND AgeGroup = '" + curAgeGroup + "'" );

                        if ( curReadyToSki.Equals( "Y" ) ) {
                            if ( curScoreRows.Length > 0 ) {
                                //Write skier identification information
                                outLine.Append( writeSkierInfo( curMemberRow, inSanctionId, curRules, curAgeGroup ) );

                                //Write skier performance summary information
                                //outLine.Append( writeSkierPerfSmry( curMemberId, curAgeGroup, curDataType, curMemberRow, curScoreRows, curScoreSlalomRows, curScoreTrickRows, curScoreJumpRows ) );
                                outLine.Append( writeSkierPerfSmry( curMemberId, curAgeGroup, curDataType, curMemberRow, curScoreRows, curScoreRows, curScoreRows, curScoreRows ) );

                                //Write skier performance summary information
                                outLine.Append( writeSkierPerfData( curMemberId, curAgeGroup, curRules, curMemberRow, curScoreRows ) );

                                //Write output line to file
                                outBuffer.WriteLine( outLine.ToString() );
                            }
                        }

                        //Initialize output buffer
                        outLine = new StringBuilder( "" );
                    }
                    returnStatus = true;
                    outBuffer.Close();

                    myProgressInfo.Close();
                    if ( curMemberDataTable.Rows.Count > 0 ) {
                        MessageBox.Show( curMemberDataTable.Rows.Count + " rows found and written" );
                    } else {
                        MessageBox.Show( "No rows found" );
                    }
                    Log.WriteFile( "Export performance data file complete: " + curFilename );
                }
            }

            return returnStatus;
        }
        public void navRefresh_Click( object sender, EventArgs e )
        {
            this.Cursor = Cursors.WaitCursor;

            // Retrieve data from database
            if ( mySanctionNum != null && myEvent != null ) {
                String curDataType = "all", curPlcmtMethod = "score";
                String curPlcmtOrg, curPointsMethod;
                CalcScoreSummary curCalcSummary = new CalcScoreSummary();

                // Retrieve data from database depending on selection criteria
                String curMsg = "Tournament scores retrieved ";

                if ( bestScoreButton.Checked ) {
                    curDataType = "best";
                    winStatusMsg.Text = curMsg + "- best scores ";
                } else if ( totalScoreButton.Checked ) {
                    curDataType = "total";
                    winStatusMsg.Text = curMsg + "- total scores";
                } else if ( finalScoreButton.Checked ) {
                    curDataType = "final";
                    winStatusMsg.Text = curMsg + "- final scores";
                }
                myTourProperties.SlalomTeamSummaryDataType = curDataType;

                if ( rawScoreButton.Checked ) {
                    curPlcmtMethod = "score";
                } else if ( pointsScoreButton.Checked ) {
                    curPlcmtMethod = "points";
                } else {
                    curPlcmtMethod = "score";
                }
                myTourProperties.SlalomTeamSummaryPlcmtMethod = curPlcmtMethod;

                if ( divPlcmtButton.Checked ) {
                    curPlcmtOrg = "div";
                } else if (groupPlcmtButton.Checked) {
                    curPlcmtOrg = "group";
                } else if ( plcmtTourButton.Checked ) {
                    curPlcmtOrg = "tour";
                } else {
                    curPlcmtOrg = "tour";
                }

                myTourProperties.SlalomTeamSummaryPlcmtOrg = curPlcmtOrg;

                HCapBase.Visible = false;
                HCapScore.Visible = false;
                if ( nopsPointsButton.Checked ) {
                    curPointsMethod = "nops";
                } else if ( plcmtPointsButton.Checked ) {
                    curPointsMethod = "plcmt";
                    curPlcmtMethod = "score";
                } else if ( kBasePointsButton.Checked ) {
                    curPointsMethod = "kbase";
                } else if ( handicapPointsButton.Checked ) {
                    curPointsMethod = "hcap";
                    HCapBase.Visible = true;
                    HCapScore.Visible = true;
                } else if ( ratioPointsButton.Checked ) {
                    curPointsMethod = "ratio";
                    HCapBase.Visible = true;
                    HCapScore.Visible = true;
                } else {
                    curPointsMethod = "nops";
                }
                myTourProperties.SlalomTeamSummaryPointsMethod = curPointsMethod;

                String curGroupValue = "";
                try {
                    curGroupValue = EventGroupList.SelectedItem.ToString();
                    if (!( curGroupValue.ToLower().Equals( "all" ) )) {
                        if (myTourRules.ToLower().Equals( "ncwsa" )) {
                            if (curGroupValue.ToUpper().Equals( "MEN A" )) {
                                curGroupValue = "CM";
                            } else if (curGroupValue.ToUpper().Equals( "WOMEN A" )) {
                                curGroupValue = "CW";
                            } else if (curGroupValue.ToUpper().Equals( "MEN B" )) {
                                curGroupValue = "BM";
                            } else if (curGroupValue.ToUpper().Equals( "WOMEN B" )) {
                                curGroupValue = "BW";
                            } else {
                                curGroupValue = "All";
                            }
                        }
                    }
                } catch {
                    curGroupValue = "All";
                }

                if (myTourRules.ToLower().Equals( "iwwf" )) {
                    curPointsMethod = "kbase";
                    myScoreDataTable = curCalcSummary.CalcIwwfEventPlcmts( myTourRow, mySanctionNum, "Slalom", myTourRules, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, "Team", curGroupValue );
                    loadScoreDataGrid( myScoreDataTable );
                    myTeamDataTable = curCalcSummary.getSlalomSummaryTeam( myScoreDataTable, myTourRow, myNumPerTeam, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );
                    if (plcmtTourButton.Checked) {
                        myTeamDataTable = curCalcSummary.CalcTeamCombinedSummary( myTourRow, myScoreDataTable, null, null, myNumPerTeam );
                    }
                } else if (myTourRules.ToLower().Equals( "ncwsa" )) {
                    if (plcmtTourButton.Checked) {
                        curPlcmtOrg = "div";
                    }
                    myScoreDataTable = curCalcSummary.getSlalomSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, "Team", curGroupValue );
                    loadScoreDataGrid( myScoreDataTable );
                    myTeamDataTable = curCalcSummary.getSlalomSummaryTeam( myScoreDataTable, myTourRow, myNumPerTeam, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );
                    if (plcmtTourButton.Checked) {
                        myTeamDataTable = curCalcSummary.CalcTeamEventCombinedNcwsaSummary( myTeamDataTable, mySanctionNum );
                    }
                } else {
                    myScoreDataTable = curCalcSummary.getSlalomSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, "Team", curGroupValue );
                    loadScoreDataGrid( myScoreDataTable );
                    myTeamDataTable = curCalcSummary.getSlalomSummaryTeam( myScoreDataTable, myTourRow, myNumPerTeam, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );
                    if (plcmtTourButton.Checked) {
                        myTeamDataTable = curCalcSummary.CalcTeamCombinedSummary( myTourRow, myScoreDataTable, null, null, myNumPerTeam );
                    }
                }

                String curSortCmd = "";
                if (TeamDiv.Visible) {
                    curSortCmd = "DivOrder ASC, Div ASC, TeamScoreTotal DESC";
                } else {
                    curSortCmd = "TeamScoreTotal DESC";
                }
                myTeamDataTable.DefaultView.Sort = curSortCmd;
                myTeamDataTable = myTeamDataTable.DefaultView.ToTable();
                loadTeamDataGrid( myTeamDataTable );
            }
            this.Cursor = Cursors.Default;
        }
        public Boolean exportScoreBookData()
        {
            String curMethodName = "exportScoreBookData";
            Boolean returnStatus = false;
            StringBuilder outLine = new StringBuilder( "" );
            String curMsg = "", curMemberId = "", curAgeGroup = "", prevMemberId = "", prevAgeGroup = "", curReadyToSki = "";
            String curFileFilter = "SBK files (*.sbk)|*.sbk|All files (*.*)|*.*";
            Int16 curRound = 0;
            DataRow prevRow = null;
            DataRow[] curScoreRows = null;
            myTourProperties = TourProperties.Instance;

            try {
                curMsg = "Exporting Scorebook";
                Log.WriteFile( curMethodName + ":begin: " + curMsg );
                String curFilename = mySanctionNum.Trim() + myTourClass + ".sbk";
                StreamWriter outBuffer = getExportFile( curFileFilter, curFilename );

                if (outBuffer == null) {
                    curMsg = "Output file not available";
                } else {
                    String curPlcmtMethod = "score", curPlcmtOverallOrg = "agegroup";
                    String curDataType = myTourProperties.MasterSummaryDataType;
                    //String curDataType = Properties.Settings.Default.MasterSummaryV2DataType;
                    if ( curDataType.ToLower().Equals( "total" )
                        || curDataType.ToLower().Equals( "best" )
                        || curDataType.ToLower().Equals( "final" )
                        || curDataType.ToLower().Equals( "first" ) ) {
                    } else {
                        curDataType = "best";
                    }
                    String curPointsMethod = myTourProperties.MasterSummaryPointsMethod;
                    //String curPointsMethod = Properties.Settings.Default.MasterSummaryV2PointsMethod;
                    if ( curPointsMethod.ToLower().Equals( "nops" )
                        || curPointsMethod.ToLower().Equals( "plcmt" )
                        || curPointsMethod.ToLower().Equals( "kbase" )
                        || curPointsMethod.ToLower().Equals( "ratio" ) ) {
                    } else {
                        curPointsMethod = "nops";
                    }
                    String curPlcmtOrg = myTourProperties.MasterSummaryPlcmtOrg;
                    //String curPlcmtOrg = Properties.Settings.Default.MasterSummaryV2PlcmtOrg;
                    if ( curPlcmtOrg.ToLower().Equals( "div" ) ) {
                        curPlcmtOverallOrg = "agegroup";
                    } else if ( curPlcmtOrg.ToLower().Equals( "divgr" ) ) {
                        curPlcmtOverallOrg = "agegroupgroup";
                    } else {
                        curPlcmtOverallOrg = "agegroup";
                        curPlcmtOrg = "div";
                    }

                    myProgressInfo = new ProgressWindow();
                    myProgressInfo.setProgessMsg( "Processing Scorebook" );
                    myProgressInfo.Show();
                    myProgressInfo.Refresh();
                    myProgressInfo.setProgressMax( 10 );

                    CalcScoreSummary curCalcSummary = new CalcScoreSummary();
                    mySummaryDataTable = null;

                    DataTable myMemberData = curCalcSummary.getMemberData( mySanctionNum );
                    myProgressInfo.setProgressValue( 1 );
                    myProgressInfo.Refresh();

                    if (myTourRules.ToLower().Equals( "iwwf" )) {
                        mySummaryDataTable = curCalcSummary.CalcIwwfEventPlcmts( myTourRow, mySanctionNum, "Scorebook", myTourRules, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                        myProgressInfo.setProgressValue( 2 );
                        myProgressInfo.Refresh();

                        DataTable mySlalomDetail = curCalcSummary.getSlalomScoreDetail( myTourRow, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                        myProgressInfo.setProgressValue( 6 );
                        myProgressInfo.Refresh();
                        DataTable myTrickDetail = curCalcSummary.getTrickScoreDetail( myTourRow, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                        myProgressInfo.setProgressValue( 7 );
                        myProgressInfo.Refresh();
                        DataTable myJumpDetail = curCalcSummary.getJumpScoreDetail( myTourRow, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                        myProgressInfo.setProgressValue( 8 );
                        myProgressInfo.Refresh();
                        DataTable newSummaryDataTable = curCalcSummary.buildTourScorebook( mySanctionNum, myTourRow, myMemberData, mySummaryDataTable, mySlalomDetail, myTrickDetail, myJumpDetail );
                        mySummaryDataTable = newSummaryDataTable;
                        myProgressInfo.setProgressValue( 9 );
                        myProgressInfo.Refresh();

                    } else {
                        DataTable mySlalomDataTable = curCalcSummary.getSlalomSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );
                        myProgressInfo.setProgressValue( 1 );
                        myProgressInfo.Refresh();
                        DataTable myTrickDataTable = curCalcSummary.getTrickSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );
                        myProgressInfo.setProgressValue( 2 );
                        myProgressInfo.Refresh();
                        DataTable myJumpDataTable = curCalcSummary.getJumpSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );
                        myProgressInfo.setProgressValue( 3 );
                        myProgressInfo.Refresh();
                        mySummaryDataTable = curCalcSummary.buildOverallSummary( myTourRow, mySlalomDataTable, myTrickDataTable, myJumpDataTable, curDataType, curPlcmtOverallOrg );
                        myProgressInfo.setProgressValue( 4 );
                        myProgressInfo.Refresh();

                        DataTable mySlalomDetail = curCalcSummary.getSlalomScoreDetail( myTourRow, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                        myProgressInfo.setProgressValue( 6 );
                        myProgressInfo.Refresh();
                        DataTable myTrickDetail = curCalcSummary.getTrickScoreDetail( myTourRow, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                        myProgressInfo.setProgressValue( 7 );
                        myProgressInfo.Refresh();
                        DataTable myJumpDetail = curCalcSummary.getJumpScoreDetail( myTourRow, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                        myProgressInfo.setProgressValue( 8 );
                        myProgressInfo.Refresh();

                        mySummaryDataTable = curCalcSummary.buildTourScorebook( mySanctionNum, myTourRow, myMemberData, mySummaryDataTable, mySlalomDetail, myTrickDetail, myJumpDetail );
                        myProgressInfo.setProgressValue( 9 );
                        myProgressInfo.Refresh();
                    }

                    myProgressInfo.setProgressMax( mySummaryDataTable.Rows.Count );
                    myProgressInfo.Refresh();

                    //Build file header line and write to file
                    writeHeader( outBuffer );

                    int curRowCount = 0;
                    foreach ( DataRow curRow in mySummaryDataTable.Rows ) {
                        curRowCount++;
                        myProgressInfo.setProgressValue( curRowCount );
                        myProgressInfo.Refresh();

                        curMemberId = curRow["MemberId"].ToString();
                        curAgeGroup = curRow["AgeGroup"].ToString();
                        curReadyToSki = curRow["ReadyToSki"].ToString();
                        if ( curMemberId != prevMemberId || curAgeGroup != prevAgeGroup ) {
                            outLine = new StringBuilder( "" );
                            outBuffer.WriteLine( outLine.ToString() );
                            curScoreRows = mySummaryDataTable.Select( "MemberId = '" + curMemberId + "' AND AgeGroup = '" + curAgeGroup + "'" );
                        }

                        //Initialize control fields
                        prevMemberId = curMemberId;
                        prevAgeGroup = curAgeGroup;
                        curRound = (Int16)curRow["RoundOverall"];

                        //Initialize output buffer
                        outLine = new StringBuilder( "" );

                        //Write skier identification information
                        outLine.Append( writeSkierInfo( curRow, curRound ) );

                        //Write skier performance summary information
                        outLine.Append( writeSkierSlalomScore( curRow, curScoreRows ) );

                        outLine.Append( writeSkierTrickScore( curRow, curScoreRows ) );

                        outLine.Append( writeSkierJumpScore( curRow, curScoreRows ) );

                        outLine.Append( writeSkierOverallScore( curRow ) );
                        //Write output line to file
                        outBuffer.WriteLine( outLine.ToString() );
                    }

                    //Build file footer and write to file
                    outLine = new StringBuilder( "" );
                    outBuffer.WriteLine( outLine.ToString() );
                    outLine.Append( writeFooter() );
                    outBuffer.WriteLine( outLine.ToString() );

                    returnStatus = true;
                    outBuffer.Close();

                    myProgressInfo.Close();
                    if ( mySummaryDataTable.Rows.Count > 0 ) {
                        curMsg = mySummaryDataTable.Rows.Count + " skiers found and written";
                    } else {
                        curMsg = "No rows found";
                    }
                }
                MessageBox.Show( curMsg );
                Log.WriteFile( curMethodName + ":complete: " + curMsg );
            } catch ( Exception ex ) {
                MessageBox.Show( "Error:" + curMethodName + " Could not write file from DataGridView\n\nError: " + ex.Message );
                curMsg = curMethodName + ":Exception=" + ex.Message;
                Log.WriteFile( curMsg );
                returnStatus = false;
            }

            return returnStatus;
        }
        public Boolean exportScoreBookData()
        {
            String curMethodName = "exportScoreBookHtml";
            Boolean returnStatus = false;
            StringBuilder outLine = new StringBuilder( "" );
            String curMsg = "", curMemberId = "", curAgeGroup = "", prevMemberId = "", prevAgeGroup = "", curReadyToSki = "";
            String curFileFilter = "HTML files (*.htm)|*.htm|All files (*.*)|*.*";
            Int16 curRound = 0;
            DataRow prevRow = null;
            DataRow[] curScoreSlalomRows = null, curScoreTrickRows = null, curScoreJumpRows = null;
            myTourProperties = TourProperties.Instance;

            ExportScorebookTypeDialogForm curDialogForm = new ExportScorebookTypeDialogForm();
            curDialogForm.ShowDialog();
            if ( curDialogForm.DialogResult == DialogResult.OK ) {
                String curReportFormat = curDialogForm.ReportFormat;
                if ( curReportFormat.Equals( "Magazine" ) ) {
                    Tools.ExportScorebookPublishFmt myExportDataReport = new ExportScorebookPublishFmt();
                    myExportDataReport.ExportScorebookPublishFmtData();
                    returnStatus = true;
                } else {
                    try {
                        curMsg = "Exporting Scorebook Html";
                        Log.WriteFile( curMethodName + ":begin: " + curMsg );

                        mySkierClassList = new ListSkierClass();
                        mySkierClassList.ListSkierClassLoad();

                        String curFilename = mySanctionNum.Trim() + "CS.HTM";
                        StreamWriter outBuffer = getExportFile( curFileFilter, curFilename );

                        if ( outBuffer == null ) {
                            curMsg = "Output file not available";
                        } else {
                            String curPlcmtMethod = "score", curPlcmtOverallOrg = "agegroup";
                            String curDataType = myTourProperties.MasterSummaryDataType;
                            //String curDataType = Properties.Settings.Default.MasterSummaryV2DataType;
                            if ( curDataType.ToLower().Equals( "total" )
                                || curDataType.ToLower().Equals( "best" )
                                || curDataType.ToLower().Equals( "final" )
                                || curDataType.ToLower().Equals( "first" ) ) {
                            } else {
                                curDataType = "best";
                            }
                            String curPointsMethod = myTourProperties.MasterSummaryPointsMethod;
                            //String curPointsMethod = Properties.Settings.Default.MasterSummaryV2PointsMethod;
                            if (curPointsMethod.ToLower().Equals( "nops" )
                                || curPointsMethod.ToLower().Equals( "plcmt" )
                                || curPointsMethod.ToLower().Equals( "kbase" )
                                || curPointsMethod.ToLower().Equals( "ratio" )) {
                            } else {
                                curPointsMethod = "nops";
                            }

                            String curPlcmtOrg = myTourProperties.MasterSummaryPlcmtOrg;
                            //String curPlcmtOrg = Properties.Settings.Default.MasterSummaryV2PlcmtOrg;
                            if ( curPlcmtOrg.ToLower().Equals( "div" ) ) {
                                curPlcmtOverallOrg = "agegroup";
                            } else if ( curPlcmtOrg.ToLower().Equals( "divgr" ) ) {
                                curPlcmtOverallOrg = "agegroupgroup";
                            } else {
                                curPlcmtOverallOrg = "agegroup";
                                curPlcmtOrg = "div";
                            }

                            myProgressInfo = new ProgressWindow();
                            myProgressInfo.setProgessMsg( "Processing Scorebook HTML" );
                            myProgressInfo.Show();
                            myProgressInfo.Refresh();
                            myProgressInfo.setProgressMax( 10 );
                            CalcScoreSummary curCalcSummary = new CalcScoreSummary();

                            DataTable mySlalomDataTable = curCalcSummary.getSlalomSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );
                            myProgressInfo.setProgressValue( 1 );
                            myProgressInfo.Refresh();
                            DataTable myTrickDataTable = curCalcSummary.getTrickSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );
                            myProgressInfo.setProgressValue( 2 );
                            myProgressInfo.Refresh();
                            DataTable myJumpDataTable = curCalcSummary.getJumpSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );
                            myProgressInfo.setProgressValue( 3 );
                            myProgressInfo.Refresh();
                            DataTable myOverallDataTable = curCalcSummary.buildOverallSummary( myTourRow, mySlalomDataTable, myTrickDataTable, myJumpDataTable, curDataType, curPlcmtOverallOrg );
                            myProgressInfo.setProgressValue( 4 );
                            myProgressInfo.Refresh();

                            DataTable myMemberData = curCalcSummary.getMemberData( mySanctionNum );
                            myProgressInfo.setProgressValue( 5 );
                            myProgressInfo.Refresh();

                            DataTable mySlalomDetail = curCalcSummary.getSlalomScoreDetail( myTourRow, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                            myProgressInfo.setProgressValue( 6 );
                            myProgressInfo.Refresh();
                            DataTable myTrickDetail = curCalcSummary.getTrickScoreDetail( myTourRow, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                            myProgressInfo.setProgressValue( 7 );
                            myProgressInfo.Refresh();
                            DataTable myJumpDetail = curCalcSummary.getJumpScoreDetail( myTourRow, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                            myProgressInfo.setProgressValue( 8 );
                            myProgressInfo.Refresh();

                            DataTable mySummaryDataTable = curCalcSummary.buildTourScorebook( mySanctionNum, myTourRow, myMemberData, myOverallDataTable, mySlalomDetail, myTrickDetail, myJumpDetail );
                            myProgressInfo.setProgressValue( 9 );
                            myProgressInfo.Refresh();

                            myProgressInfo.setProgressMax( mySummaryDataTable.Rows.Count );
                            myProgressInfo.Refresh();

                            //Build file header line and write to file
                            writeHeader( outBuffer, curPlcmtOrg );

                            if ( curReportFormat.Equals( "Index" ) ) {
                                //Build index header
                                writeIndexHeader( outBuffer, curPlcmtOrg, mySlalomDataTable, myTrickDataTable, myJumpDataTable, myOverallDataTable );
                            }
                            //Build master summary header
                            writeMasterSummaryHeader( outBuffer, curPlcmtOrg );
                            int curRowCount = 0;
                            foreach ( DataRow curRow in mySummaryDataTable.Rows ) {
                                curRowCount++;
                                myProgressInfo.setProgressValue( curRowCount );
                                myProgressInfo.Refresh();

                                curMemberId = curRow["MemberId"].ToString();
                                curAgeGroup = curRow["AgeGroup"].ToString();
                                curReadyToSki = curRow["ReadyToSki"].ToString();
                                if ( curMemberId != prevMemberId || curAgeGroup != prevAgeGroup ) {
                                    curScoreSlalomRows = mySlalomDataTable.Select( "MemberId = '" + curMemberId + "' AND AgeGroup = '" + curAgeGroup + "'" );
                                    curScoreTrickRows = myTrickDataTable.Select( "MemberId = '" + curMemberId + "' AND AgeGroup = '" + curAgeGroup + "'" );
                                    curScoreJumpRows = myJumpDataTable.Select( "MemberId = '" + curMemberId + "' AND AgeGroup = '" + curAgeGroup + "'" );
                                }

                                //Initialize control fields
                                prevMemberId = curMemberId;
                                prevAgeGroup = curAgeGroup;
                                curRound = (Int16)curRow["Round"];

                                //Initialize output buffer
                                outLine = new StringBuilder( "<tr>" );

                                //Write skier identification information
                                writeSkierInfo( curRow, curRound, outBuffer );

                                //Write skier performance summary information
                                writeSkierSlalomScore( curRow, curScoreSlalomRows, curPlcmtOrg, outBuffer );

                                writeSkierTrickScore( curRow, curScoreTrickRows, curPlcmtOrg, outBuffer );

                                writeSkierJumpScore( curRow, curScoreJumpRows, curPlcmtOrg, outBuffer );

                                writeSkierOverallScore( curRow, outBuffer );

                                //Write output line to file
                                outLine = new StringBuilder( "</tr>" );
                                outBuffer.WriteLine( outLine.ToString() );
                            }
                            outLine = new StringBuilder( "</table>" );
                            outBuffer.WriteLine( outLine.ToString() );

                            if ( curReportFormat.Equals( "Index" ) ) {
                                outLine = new StringBuilder( "<br/><br/><a href=#PageTop>Return to Index</a><br/></div>" );
                                outBuffer.WriteLine( outLine.ToString() );

                                writeIndexSlalomResults( curPlcmtOrg, mySlalomDataTable, outBuffer );
                                writeIndexTrickResults( curPlcmtOrg, myTrickDataTable, outBuffer );
                                writeIndexJumpResults( curPlcmtOrg, myJumpDataTable, outBuffer );
                                writeIndexOverallResults( curPlcmtOrg, myOverallDataTable, outBuffer );

                                Boolean curTeamsAvailble = isTeamAvailable();
                                //if ( this.myTourClass.Equals("B") || this.myTourClass.Equals("A") ) {
                                //    curTeamsAvailble = false;
                                //}

                                if ( curTeamsAvailble ) {
                                    Int16 myNumPerTeam = Convert.ToInt16( myTourProperties.TeamSummary_NumPerTeam);
                                    String curTeamPlcmtOrg = myTourProperties.TeamSummaryPlcmtOrg;
                                    //String curTeamPlcmtOrg = Properties.Settings.Default.TeamSummaryPlcmtOrg;
                                    if (curTeamPlcmtOrg.ToLower().Equals( "tour" )
                                        || curTeamPlcmtOrg.ToLower().Equals( "div" )) {
                                    } else {
                                        curTeamPlcmtOrg = "tour";
                                    }
                                    String curTeamPlcmtMethod = "points";
                                    String curTeamDataType = myTourProperties.TeamSummaryDataType;
                                    //String curTeamDataType = Properties.Settings.Default.TeamSummaryDataType;
                                    if (curTeamDataType.ToLower().Equals( "total" )
                                        || curTeamDataType.ToLower().Equals( "best" )
                                        || curTeamDataType.ToLower().Equals( "final" )
                                        || curTeamDataType.ToLower().Equals( "first" )) {
                                    } else {
                                        curTeamDataType = "best";
                                    }
                                    String curTeamPointsMethod = myTourProperties.TeamSummaryPointsMethod;
                                    //String curTeamPointsMethod = Properties.Settings.Default.MasterSummaryV2PointsMethod;
                                    if (curTeamPointsMethod.ToLower().Equals( "nops" )
                                        || curTeamPointsMethod.ToLower().Equals( "plcmt" )
                                        || curTeamPointsMethod.ToLower().Equals( "kbase" )
                                        || curTeamPointsMethod.ToLower().Equals( "ratio" )) {
                                    } else {
                                        curTeamPointsMethod = "nops";
                                    }

                                    if ( this.myTourClass.Equals("B") || this.myTourClass.Equals("A") ) {
                                        curTeamPointsMethod = "nops";
                                        curTeamDataType = "best";
                                        curTeamPlcmtOrg = "awsa";
                                        curTeamPlcmtMethod = "points";
                                        myNumPerTeam = 4;
                                    }

                                    String curGroupValue = "all";
                                    mySlalomDataTable = curCalcSummary.getSlalomSummary(myTourRow, curTeamDataType, curTeamPlcmtMethod, curTeamPlcmtOrg, curTeamPointsMethod, "Team", curGroupValue);
                                    myTrickDataTable = curCalcSummary.getTrickSummary(myTourRow, curTeamDataType, curTeamPlcmtMethod, curTeamPlcmtOrg, curTeamPointsMethod, "Team", curGroupValue);
                                    myJumpDataTable = curCalcSummary.getJumpSummary(myTourRow, curTeamDataType, curTeamPlcmtMethod, curTeamPlcmtOrg, curTeamPointsMethod, "Team", curGroupValue);

                                    DataTable myTeamDataTable = null;
                                    myTeamDataTable = curCalcSummary.getSlalomSummaryTeam(mySlalomDataTable, myTourRow, myNumPerTeam, curTeamDataType, curTeamPlcmtMethod, curTeamPlcmtOrg, curTeamPointsMethod);
                                    myTeamDataTable = curCalcSummary.getTrickSummaryTeam(myTeamDataTable, myTrickDataTable, myTourRow, myNumPerTeam, curTeamDataType, curTeamPlcmtMethod, curTeamPlcmtOrg, curTeamPointsMethod);
                                    myTeamDataTable = curCalcSummary.getJumpSummaryTeam(myTeamDataTable, myJumpDataTable, myTourRow, myNumPerTeam, curTeamDataType, curTeamPlcmtMethod, curTeamPlcmtOrg, curTeamPointsMethod);
                                    if ( curTeamPlcmtOrg.ToLower().Equals("tour") ) {
                                        myTeamDataTable = curCalcSummary.CalcTeamCombinedSummary(myTourRow, mySlalomDataTable, myTrickDataTable, myJumpDataTable, myNumPerTeam);
                                    }

                                    if ( myTourClass.Equals("B") || myTourClass.Equals("A") ) {
                                        mySlalomDataTable = curCalcSummary.CalcTeamAwsaEventPoints(mySlalomDataTable, "Slalom");
                                        myTrickDataTable = curCalcSummary.CalcTeamAwsaEventPoints(myTrickDataTable, "Trick");
                                        myJumpDataTable = curCalcSummary.CalcTeamAwsaEventPoints(myJumpDataTable, "Jump");
                                        myTeamDataTable = curCalcSummary.CalcTeamAwsaCombinedSummary(myTourRow, mySlalomDataTable, myTrickDataTable, myJumpDataTable, myNumPerTeam);
                                        writeIndexTeamResults(myTeamDataTable, myNumPerTeam, curTeamPlcmtOrg, outBuffer);
                                        writeIndexTeamDetailResults(mySlalomDataTable, myTrickDataTable, myJumpDataTable, myNumPerTeam, curTeamPlcmtOrg, outBuffer);
                                    } else {
                                        writeIndexTeamResults(myTeamDataTable, myNumPerTeam, curTeamPlcmtOrg, outBuffer);
                                    }
                                }
                            } else {
                                outLine = new StringBuilder( "</div>" );
                                outBuffer.WriteLine( outLine.ToString() );
                            }

                            //Build file footer and write to file
                            writeFooter( outBuffer );
                            outLine = new StringBuilder( "" );
                            outBuffer.WriteLine( outLine.ToString() );

                            returnStatus = true;
                            outBuffer.Close();

                            myProgressInfo.Close();
                            if ( mySummaryDataTable.Rows.Count > 0 ) {
                                curMsg = mySummaryDataTable.Rows.Count + " skiers found and written";
                            } else {
                                curMsg = "No rows found";
                            }
                        }
                        MessageBox.Show( curMsg );
                        Log.WriteFile( curMethodName + ":conplete: " + curMsg );
                    } catch ( Exception ex ) {
                        MessageBox.Show( "Error:" + curMethodName + " Error writing scorebook html file\n\nError: " + ex.Message );
                        curMsg = curMethodName + ":Exception=" + ex.Message;
                        Log.WriteFile( curMsg );
                        returnStatus = false;
                    }
                }
            } else {
                returnStatus = false;
            }

            return returnStatus;
        }
        public void navRefresh_Click( object sender, EventArgs e )
        {
            this.Cursor = Cursors.WaitCursor;

            // Retrieve data from database
            if ( mySanctionNum != null && myTourRow != null ) {
                String curDataType = "all", curPlcmtMethod = "score";
                String curPlcmtOrg, curPointsMethod;
                CalcScoreSummary curCalcSummary = new CalcScoreSummary();

                // Retrieve data from database depending on selection criteria
                String curMsg = "Tournament scores retrieved ";

                if ( bestScoreButton.Checked ) {
                    curDataType = "best";
                    winStatusMsg.Text = curMsg + "- best scores ";
                } else if ( roundScoreButton.Checked ) {
                    curDataType = "round";
                    winStatusMsg.Text = curMsg + "- total scores";
                } else if ( finalScoreButton.Checked ) {
                    curDataType = "final";
                    winStatusMsg.Text = curMsg + "- final scores";
                }
                myTourProperties.MasterSummaryOverallDataType = curDataType;

                if ( pointsScoreButton.Checked ) {
                    curPlcmtMethod = "points";
                } else if ( handicapScoreButton.Checked ) {
                    curPlcmtMethod = "hcap";
                } else if ( ratioScoreButton.Checked ) {
                    curPlcmtMethod = "ratio";
                } else {
                    curPlcmtMethod = "points";
                }
                myTourProperties.MasterSummaryOverallPlcmtMethod = curPlcmtMethod;

                EventGroup.Visible = false;
                if ( groupPlcmtButton.Checked ) {
                    curPlcmtOrg = "group";
                    EventGroup.Visible = true;
                } else if ( plcmtTourButton.Checked ) {
                    curPlcmtOrg = "tour";
                } else if ( plcmtDivButton.Checked ) {
                    curPlcmtOrg = "div";
                } else if ( plcmtDivGrpButton.Checked ) {
                    curPlcmtOrg = "divgr";
                    EventGroup.Visible = true;
                } else {
                    curPlcmtOrg = "tour";
                }
                myTourProperties.MasterSummaryOverallPlcmtOrg = curPlcmtOrg;

                if ( nopsPointsButton.Checked ) {
                    curPointsMethod = "nops";
                } else if ( plcmtPointsButton.Checked ) {
                    curPointsMethod = "plcmt";
                } else if ( kBasePointsButton.Checked ) {
                    curPointsMethod = "kbase";
                } else if ( ratioPointsButton.Checked ) {
                    curPointsMethod = "ratio";
                } else {
                    curPointsMethod = "nops";
                }
                myTourProperties.MasterSummaryOverallPointsMethod = curPointsMethod;

                String curFilterSetting = "All";
                if ( showAllButton.Checked ) {
                    curFilterSetting = "All";
                } else if ( showQlfyButton.Checked ) {
                    curFilterSetting = "Qualifed";
                } else {
                    curFilterSetting = "All";
                }
                myTourProperties.MasterSummaryOverallFilter = curFilterSetting;

                /*
                if ( EventGroup.Visible ) {
                    SlalomLabel.Location = new Point( 208, SlalomLabel.Location.Y );
                    TrickLabel.Location = new Point( 573, SlalomLabel.Location.Y );
                    JumpLabel.Location = new Point( 830, SlalomLabel.Location.Y );
                    OverallLabel.Location = new Point( 1062, SlalomLabel.Location.Y );
                } else {
                    SlalomLabel.Location = new Point( 168, SlalomLabel.Location.Y );
                    TrickLabel.Location = new Point( 533, SlalomLabel.Location.Y );
                    JumpLabel.Location = new Point( 790, SlalomLabel.Location.Y );
                    OverallLabel.Location = new Point( 1022, SlalomLabel.Location.Y );
                }
                 */

                String curGroupValue = "";
                try {
                    curGroupValue = EventGroupList.SelectedItem.ToString();
                    if (!( curGroupValue.ToLower().Equals( "all" ) )) {
                        if (myTourRules.ToLower().Equals( "ncwsa" )) {
                            if (curGroupValue.ToUpper().Equals( "MEN A" )) {
                                curGroupValue = "CM";
                            } else if (curGroupValue.ToUpper().Equals( "WOMEN A" )) {
                                curGroupValue = "CW";
                            } else if (curGroupValue.ToUpper().Equals( "MEN B" )) {
                                curGroupValue = "BM";
                            } else if (curGroupValue.ToUpper().Equals( "WOMEN B" )) {
                                curGroupValue = "BW";
                            } else {
                                curGroupValue = "All";
                            }
                        }
                    }
                } catch {
                    curGroupValue = "All";
                }

                if ( curGroupValue.ToLower().Equals( "all" ) ) {
                    if ( myTourRules.ToLower().Equals( "iwwf" ) && curPointsMethod.ToLower().Equals( "kbase" ) ) {
                        mySummaryDataTable = curCalcSummary.CalcIwwfEventPlcmts( myTourRow, mySanctionNum, "Overall", myTourRules, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                    } else {
                        mySlalomDataTable = curCalcSummary.getSlalomSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );
                        myTrickDataTable = curCalcSummary.getTrickSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );
                        myJumpDataTable = curCalcSummary.getJumpSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );
                        mySummaryDataTable = curCalcSummary.buildOverallSummary( myTourRow, mySlalomDataTable, myTrickDataTable, myJumpDataTable, curDataType, curPlcmtOrg );
                    }
                } else {
                    if ( myTourRules.ToLower().Equals( "iwwf" ) && curPointsMethod.ToLower().Equals( "kbase" ) ) {
                        mySummaryDataTable = curCalcSummary.CalcIwwfEventPlcmts( myTourRow, mySanctionNum, "Overall", myTourRules, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, "All", curGroupValue );
                    } else {
                        mySlalomDataTable = curCalcSummary.getSlalomSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, "All", curGroupValue );
                        myTrickDataTable = curCalcSummary.getTrickSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, "All", curGroupValue );
                        myJumpDataTable = curCalcSummary.getJumpSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, "All", curGroupValue );
                        mySummaryDataTable = curCalcSummary.buildOverallSummary( myTourRow, mySlalomDataTable, myTrickDataTable, myJumpDataTable, curDataType, curPlcmtOrg );
                    }
                }
                loadSummaryDataGrid();
            }
            this.Cursor = Cursors.Default;
        }
        private bool readExportTeamData()
        {
            StringBuilder outLine = new StringBuilder( "" );
            bool returnStatus = false;

            Int16 curNumPerTeam = Convert.ToInt16( myTourProperties.TeamSummary_NumPerTeam);
            String curDataType = "best";
            String curPointsMethod = "nops";
            String curPlcmtMethod = "points";
            String curPlcmtOrg = "div";
            CalcScoreSummary curCalcSummary = new CalcScoreSummary();

            if ( myTourRules.ToLower().Equals( "iwwf" ) ) {
                curPointsMethod = "kbase";
            } else if ( myTourRules.ToLower().Equals( "ncwsa" ) ) {
                curPointsMethod = "plcmt";
            }
            DataTable curSlalomDataTable = curCalcSummary.getSlalomSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, "Team" );
            DataTable curTrickDataTable = curCalcSummary.getTrickSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, "Team" );
            DataTable curJumpDataTable = curCalcSummary.getJumpSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, "Team" );

            DataTable curTeamDataTable = curCalcSummary.getSlalomSummaryTeam( curSlalomDataTable, myTourRow, curNumPerTeam, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );
            curTeamDataTable = curCalcSummary.getTrickSummaryTeam( curTeamDataTable, curTrickDataTable, myTourRow, curNumPerTeam, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );
            curTeamDataTable = curCalcSummary.getJumpSummaryTeam( curTeamDataTable, curJumpDataTable, myTourRow, curNumPerTeam, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );

            curTeamDataTable.DefaultView.Sort = "Div ASC, TeamScoreTotal DESC";
            curTeamDataTable = curTeamDataTable.DefaultView.ToTable();

            outLine = new StringBuilder( "" );
            myOutBuffer.WriteLine( outLine.ToString() );
            myOutBuffer.WriteLine( outLine.ToString() );
            outLine.Append( "Team Scores" );
            myOutBuffer.WriteLine( outLine.ToString() );
            outLine = new StringBuilder( "" );
            outLine.Append( "Div" );
            outLine.Append( " | Team" );
            outLine.Append( " | Slalom" );
            outLine.Append( " | Trick" );
            outLine.Append( " | Jump" );
            outLine.Append( " | Total" );
            myOutBuffer.WriteLine( outLine.ToString() );

            foreach ( DataRow curRow in curTeamDataTable.Rows ) {
                outLine = new StringBuilder( "" );
                try {
                    try {
                        outLine.Append( curRow["Div"].ToString() );
                    } catch {
                        outLine.Append( " " );
                    }
                    try {
                        outLine.Append( " | " + (String)curRow["TeamCode"]);
                    } catch {
                        outLine.Append( " " );
                    }
                    try {
                        outLine.Append( "-" + (String)curRow["Name"] );
                    } catch {
                        outLine.Append( " " );
                    }
                    try {
                        outLine.Append( " | " + ((Decimal)curRow["TeamScoreSlalom"] ).ToString( "##,##0.00" ) );
                    } catch {
                        outLine.Append( " | " );
                    }
                    try {
                        outLine.Append( " | " + ( (Decimal)curRow["TeamScoreTrick"] ).ToString( "##,##0.00" ) );
                    } catch {
                        outLine.Append( " | " );
                    }
                    try {
                        outLine.Append( " | " + ( (Decimal)curRow["TeamScoreJump"] ).ToString( "##,##0.00" ) );
                    } catch {
                        outLine.Append( " | " );
                    }
                    try {
                        outLine.Append( " | " + ( (Decimal)curRow["TeamScoreTotal"] ).ToString( "##,##0.00" ) );
                    } catch {
                        outLine.Append( " | " );
                    }
                } catch ( Exception ex ) {
                    outLine.Append( "Exception encountered: " + ex.Message );
                }
                myOutBuffer.WriteLine( outLine.ToString() );
                returnStatus = true;
            }

            return returnStatus;
        }
        public Boolean ExportScorebookPublishFmtData()
        {
            String curMethodName = "ExportScorebookPublishFmtData";
            Boolean returnStatus = false;
            StringBuilder outLine = new StringBuilder( "" );
            String curMsg = "", curMemberId = "", curAgeGroup = "", prevAgeGroup = "";
            String curFileFilter = "TXT files (*.txt)|*.txt|All files (*.*)|*.*";
            Int16 curRound = 0, curOverallPlcmt = 0;
            DataRow prevRow = null;
            DataRow[] curScoreSlalomRows = null, curScoreTrickRows = null, curScoreJumpRows = null;

            try {
                curMsg = "Exporting Scorebook Publish Data";
                Log.WriteFile( curMethodName + ":begin: " + curMsg );
                String curFilename = mySanctionNum.Trim() + "-publish.txt";
                StreamWriter outBuffer = getExportFile( curFileFilter, curFilename );

                if ( outBuffer == null ) {
                    curMsg = "Output file not available";
                } else {
                    String curPlcmtMethod = "score"
                        , curPlcmtOverallOrg = "agegroup"
                        , curDataType = "best"
                        , curPointsMethod = "nops"
                        , curPlcmtOrg = "div";

                    myProgressInfo = new ProgressWindow();
                    myProgressInfo.setProgessMsg( "Processing Scorebook Publish Data" );
                    myProgressInfo.Show();
                    myProgressInfo.Refresh();
                    myProgressInfo.setProgressMax( 10 );

                    CalcScoreSummary curCalcSummary = new CalcScoreSummary();
                    DataTable mySlalomDataTable = curCalcSummary.getSlalomSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );
                    myProgressInfo.setProgressValue( 1 );
                    myProgressInfo.Refresh();
                    DataTable myTrickDataTable = curCalcSummary.getTrickSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );
                    myProgressInfo.setProgressValue( 2 );
                    myProgressInfo.Refresh();
                    DataTable myJumpDataTable = curCalcSummary.getJumpSummary( myTourRow, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod );
                    myProgressInfo.setProgressValue( 3 );
                    myProgressInfo.Refresh();
                    DataTable mySummaryDataTable = curCalcSummary.buildOverallSummary( myTourRow, mySlalomDataTable, myTrickDataTable, myJumpDataTable, curDataType, curPlcmtOverallOrg );
                    foreach ( DataRow curRow in mySummaryDataTable.Rows ) {
                        if ( ( (String)curRow["QualifyOverall"] ).ToUpper().Equals( "YES" ) ) {
                        } else {
                            curRow["ScoreOverall"] = 0;
                        }
                    }
                    myProgressInfo.setProgressValue( 4 );
                    myProgressInfo.Refresh();

                    mySummaryDataTable.DefaultView.Sort = "AgeGroup ASC, QualifyOverall Desc, ScoreOverall Desc, SkierName ASC";
                    DataTable curSummaryDataTable = mySummaryDataTable.DefaultView.ToTable();

                    myProgressInfo.setProgressMax( mySummaryDataTable.Rows.Count );
                    myProgressInfo.Refresh();

                    //Build file header line and write to file
                    writeHeader( outBuffer );

                    int curRowCount = 0;
                    foreach ( DataRow curRow in curSummaryDataTable.Rows ) {
                        curRowCount++;
                        myProgressInfo.setProgressValue( curRowCount );
                        myProgressInfo.Refresh();

                        curMemberId = curRow["MemberId"].ToString();
                        curAgeGroup = curRow["AgeGroup"].ToString();
                        if ( curAgeGroup != prevAgeGroup ) {
                            if ( prevAgeGroup.Length > 0 ) {
                                outBuffer.WriteLine( "" );
                                curOverallPlcmt = 0;
                            }

                            //Write skier identification information
                            outLine = new StringBuilder( "" );
                            outLine.Append( writeDivisionHeader( outBuffer, curAgeGroup ) );
                        }

                        curScoreSlalomRows = mySlalomDataTable.Select( "MemberId = '" + curMemberId + "' AND AgeGroup = '" + curAgeGroup + "'" );
                        curScoreTrickRows = myTrickDataTable.Select( "MemberId = '" + curMemberId + "' AND AgeGroup = '" + curAgeGroup + "'" );
                        curScoreJumpRows = myJumpDataTable.Select( "MemberId = '" + curMemberId + "' AND AgeGroup = '" + curAgeGroup + "'" );

                        //Initialize control fields
                        prevAgeGroup = curAgeGroup;

                        //Initialize output buffer
                        outLine = new StringBuilder( "" );

                        //Write skier identification information
                        outLine.Append( writeSkierInfo( curRow, curRound ) );

                        //Write skier performance summary information
                        outLine.Append( writeSkierSlalomScore( curRow, curScoreSlalomRows ) );

                        outLine.Append( writeSkierTrickScore( curRow, curScoreTrickRows ) );

                        outLine.Append( writeSkierJumpScore( curRow, curScoreJumpRows ) );

                        curOverallPlcmt++;
                        outLine.Append( writeSkierOverallScore( curRow, curOverallPlcmt ) );
                        //Write output line to file
                        outBuffer.WriteLine( outLine.ToString() );
                    }

                    //Build file footer and write to file
                    outLine = new StringBuilder( "" );
                    outBuffer.WriteLine( outLine.ToString() );

                    returnStatus = true;
                    outBuffer.Close();

                    myProgressInfo.Close();
                    if ( mySummaryDataTable.Rows.Count > 0 ) {
                        curMsg = mySummaryDataTable.Rows.Count + " skiers found and written";
                    } else {
                        curMsg = "No rows found";
                    }
                }
                MessageBox.Show( curMsg );
                Log.WriteFile( curMethodName + ":conplete: " + curMsg );
            } catch ( Exception ex ) {
                MessageBox.Show( "Error:" + curMethodName + " Could not write file from data input\n\nError: " + ex.Message );
                curMsg = curMethodName + ":Exception=" + ex.Message;
                Log.WriteFile( curMsg );
                returnStatus = false;
            }

            return returnStatus;
        }