public void RunningOrderForEvent(String inEvent)
 {
     myTourProperties = TourProperties.Instance;
     if (inEvent.Equals( "Slalom" )) {
         mySortCmd = myTourProperties.RunningOrderSortSlalom;
         slalomButton.Checked = true;
     } else if ( inEvent.Equals( "Trick" ) ) {
         mySortCmd = myTourProperties.RunningOrderSortTrick;
         trickButton.Checked = true;
     } else if ( inEvent.Equals( "Jump" ) ) {
         mySortCmd = myTourProperties.RunningOrderSortJump;
         jumpButton.Checked = true;
     }
 }
        public void RunningOrderForEvent(DataRow inTourRow, String inEvent) {
            myTourProperties = TourProperties.Instance;
            myTourRow = inTourRow;
            myEvent = inEvent;
            if (inEvent.Equals("Slalom")) {
                this.Text = myWindowTitle + " - Slalom";
                mySortCmd = myTourProperties.RunningOrderSortSlalom;
            } else if (inEvent.Equals( "Trick" )) {
                this.Text = myWindowTitle + " - Trick";
                mySortCmd = myTourProperties.RunningOrderSortTrick;
            } else if (inEvent.Equals( "Jump" )) {
                this.Text = myWindowTitle + " - Jump";
                mySortCmd = myTourProperties.RunningOrderSortJump;
            }
            myTourRules = (String)myTourRow["Rules"];

            if (myTourRow["SlalomRounds"] == DBNull.Value) {
                myTourRow["SlalomRounds"] = 0;
            }
            if (myTourRow["TrickRounds"] == DBNull.Value) {
                myTourRow["TrickRounds"] = 0;
            }
            if (myTourRow["JumpRounds"] == DBNull.Value) {
                myTourRow["JumpRounds"] = 0;
            }
            if ( myEvent.ToLower().Equals("slalom") ) {
                myRounds = Convert.ToInt16(myTourRow["SlalomRounds"]);
            } else if (myEvent.ToLower().Equals("trick")) {
                myRounds = Convert.ToInt16(myTourRow["TrickRounds"]);
            } else if (myEvent.ToLower().Equals("jump")) {
                myRounds = Convert.ToInt16(myTourRow["JumpRounds"]);
            }

            //Load round selection list based on number of rounds specified for the tournament
            roundActiveSelect.SelectList_LoadHorztl( myRounds.ToString(), roundActiveSelect_Click, false );
            roundActiveSelect.RoundValue = "1";
            mySanctionNum = Properties.Settings.Default.AppSanctionNum;
            //navRefresh_Click(null, null);

        }
        private void ScoreEntry_Load(object sender, EventArgs e)
        {
            if (Properties.Settings.Default.SlalomEntry_Width > 0) {
                this.Width = Properties.Settings.Default.SlalomEntry_Width;
            }
            if (Properties.Settings.Default.SlalomEntry_Height > 0) {
                this.Height = Properties.Settings.Default.SlalomEntry_Height;
            }
            if (Properties.Settings.Default.SlalomEntry_Location.X > 0
                && Properties.Settings.Default.SlalomEntry_Location.Y > 0) {
                this.Location = Properties.Settings.Default.SlalomEntry_Location;
            }
            myTourProperties = TourProperties.Instance;
            mySortCommand = myTourProperties.RunningOrderSortSlalom;
            int curDelim = mySortCommand.IndexOf( "AgeGroup" );
            if (curDelim < 0) {
            } else if (curDelim > 0) {
                mySortCommand = mySortCommand.Substring( 0, curDelim ) + "DivOrder" + mySortCommand.Substring( curDelim + "AgeGroup".Length );
                myTourProperties.RunningOrderSortSlalom = mySortCommand;
            } else {
                mySortCommand = "DivOrder" + mySortCommand.Substring( "AgeGroup".Length );
                myTourProperties.RunningOrderSortSlalom = mySortCommand;
            }

            ResizeNarrow.Visible = false;
            ResizeNarrow.Enabled = false;
            ResizeWide.Visible = true;
            ResizeWide.Enabled = true;
            ResizeNarrow.Location = ResizeWide.Location;

            EventDelayReasonTextBox.Visible = false;
            EventDelayReasonLabel.Visible = false;
            StartTimerButton.Visible = false;
            PauseTimerButton.Visible = true;
            StartTimerButton.Location = PauseTimerButton.Location;

            String[] curList = { "SkierName", "Div", "DivOrder", "EventGroup", "RunOrder", "TeamCode", "EventClass", "RankingScore", "RankingRating", "HCapBase", "HCapScore", "Status" };
            sortDialogForm = new SortDialogForm();
            sortDialogForm.ColumnListArray = curList;

            filterDialogForm = new Common.FilterDialogForm();
            filterDialogForm.ColumnListArray = curList;

            rerideReasonDialogForm = new RerideReason();
            skierDoneReasonDialogForm = new SkierDoneReason();
            OptUpDialogForm = new SlalomOptUp();
            myCheckEventRecord = new CheckEventRecord();

            // Retrieve data from database
            mySanctionNum = Properties.Settings.Default.AppSanctionNum;
            Cursor.Current = Cursors.WaitCursor;

            if (mySanctionNum == null) {
                MessageBox.Show("An active tournament must be selected from the Administration menu Tournament List option");
            } else {
                if (mySanctionNum.Length < 6) {
                    MessageBox.Show("An active tournament must be selected from the Administration menu Tournament List option");
                } else {
                    //Retrieve selected tournament attributes
                    DataTable curTourDataTable = getTourData(mySanctionNum);
                    if (curTourDataTable.Rows.Count > 0) {
                        myTourRow = curTourDataTable.Rows[0];
                        myTourRules = (String)myTourRow["Rules"];
                        if ( myTourRules.ToLower().Equals( "ncwsa" ) ) {
                            TeamCode.Visible = true;
                        } else {
                            TeamCode.Visible = false;
                        }
                        if ( (byte)myTourRow["SlalomRounds"] > 0 ) {
                            mySortCommand = myTourProperties.RunningOrderSortSlalom;

                            EventRunInfoLabel.Text = "   Event Start:\n" + "   Event Delay:\n" + "Skiers, Passes:";
                            EventRunInfoData.Text = "";
                            EventRunPerfLabel.Text = "Event Duration:\n" + "Mins Per Skier:\n" + " Mins Per Pass:"******"";

                            //Load round selection list based on number of rounds specified for the tournament
                            roundSelect.SelectList_Load( myTourRow["SlalomRounds"].ToString(), roundSelect_Click );
                            roundActiveSelect.SelectList_LoadHorztl( myTourRow["SlalomRounds"].ToString(), roundActiveSelect_Click );
                            roundActiveSelect.RoundValue = "1";

                            //Load rope length selection list
                            SlalomLineSelect.SelectList_Load( SlalomLineSelect_Change );

                            //Load slalom speed selection list
                            SlalomSpeedSelect.SelectList_Load( SlalomSpeedSelect_Change );

                            mySkierClassList = new ListSkierClass();
                            mySkierClassList.ListSkierClassLoad();
                            scoreEventClass.DataSource = mySkierClassList.DropdownList;
                            scoreEventClass.DisplayMember = "ItemName";
                            scoreEventClass.ValueMember = "ItemValue";
                            myTourClass = myTourRow["Class"].ToString().ToUpper();
                            myClassCRow = mySkierClassList.SkierClassDataTable.Select("ListCode = 'C'")[0];
                            myClassERow = mySkierClassList.SkierClassDataTable.Select("ListCode = 'E'")[0];

                            //Determine required number of judges for event
                            myNumJudges = 5;
                            StringBuilder curSqlStmt = new StringBuilder( "" );
                            curSqlStmt.Append( "Select ListCode, CodeValue, MaxValue, MinValue FROM CodeValueList " );
                            curSqlStmt.Append( "Where ListName = 'SlalomJudgesNum' And ListCode = '" + myTourClass + "' ORDER BY SortSeq" );
                            DataTable curNumJudgesDataTable = getData( curSqlStmt.ToString() );
                            if (curNumJudgesDataTable.Rows.Count > 0) {
                                setShowByNumJudges( Convert.ToInt16( (Decimal)curNumJudgesDataTable.Rows[0]["MaxValue"] ));
                            } else {
                                setShowByNumJudges ( 1 );
                            }
                            if ( myNumJudges > 3 ) {
                                ClassC5JudgeCB.Visible = false;
                                ClassC5JudgeCB.Enabled = false;
                                ClassR3JudgeCB.Visible = true;
                                ClassR3JudgeCB.Enabled = true;
                                ClassR3JudgeCB.Checked = true;
                            } else {
                                ClassC5JudgeCB.Visible = true;
                                ClassC5JudgeCB.Enabled = true;
                                ClassR3JudgeCB.Visible = false;
                                ClassR3JudgeCB.Enabled = false;
                            }

                            //Retrieve and load boat times
                            curSqlStmt = new StringBuilder( "" );
                            curSqlStmt.Append( "SELECT ListCode, ListCodeNum, SortSeq, CodeValue, MinValue, MaxValue, CodeDesc " );
                            curSqlStmt.Append( "FROM CodeValueList WHERE ListName = 'SlalomBoatTime' ORDER BY SortSeq" );
                            myTimesDataTable = getData( curSqlStmt.ToString() );

                            //Retrieve list of approved tournament boats
                            getApprovedTowboats();
                            listApprovedBoatsDataGridView.Visible = false;
                            BoatSelectInfoLabel.Visible = false;

                            //Retrieve and load tournament event entries
                            loadEventGroupList( Convert.ToByte( roundActiveSelect.RoundValue ) );

                            if (ExportLiveWeb.LiveWebLocation.Length > 1) {
                                LiveWebLabel.Visible = true;
                            } else {
                                LiveWebLabel.Visible = false;
                            }

                        } else {
                            MessageBox.Show( "The slalom event is not defined for the active tournament" );
                        }
                    } else {
                        MessageBox.Show( "The active tournament is not properly defined.  You must select from the Administration menu Tournament List option" );
                    }
                }
            }
            Cursor.Current = Cursors.Default;
        }
        private void SlalomScorebook_Load( object sender, EventArgs e )
        {
            if ( Properties.Settings.Default.SlalomScorebook_Width > 0 ) {
                this.Width = Properties.Settings.Default.SlalomScorebook_Width;
            }
            if ( Properties.Settings.Default.SlalomScorebook_Height > 0 ) {
                this.Height = Properties.Settings.Default.SlalomScorebook_Height;
            }
            if ( Properties.Settings.Default.SlalomScorebook_Location.X > 0
                && Properties.Settings.Default.SlalomScorebook_Location.Y > 0 ) {
                this.Location = Properties.Settings.Default.SlalomScorebook_Location;
            }
            myTourProperties = TourProperties.Instance;
            bestScoreButton.Checked = true;
            if ( myTourProperties.SlalomScorebookDataType.ToLower().Equals( "total" ) ) totalScoreButton.Checked = true;
            if ( myTourProperties.SlalomScorebookDataType.ToLower().Equals( "final" ) ) finalScoreButton.Checked = true;
            if ( myTourProperties.SlalomScorebookDataType.ToLower().Equals( "first" ) ) firstScoreButton.Checked = true;
            nopsPointsButton.Checked = true;
            if ( myTourProperties.SlalomScorebookPointsMethod.ToLower().Equals( "nops" ) ) nopsPointsButton.Checked = true;
            if ( myTourProperties.SlalomScorebookPointsMethod.ToLower().Equals( "plcmt" ) ) plcmtPointsButton.Checked = true;
            if ( myTourProperties.SlalomScorebookPointsMethod.ToLower().Equals( "kbase" ) ) kBasePointsButton.Checked = true;
            if ( myTourProperties.SlalomScorebookPointsMethod.ToLower().Equals( "ratio" ) ) ratioPointsButton.Checked = true;

            plcmtDivButton.Checked = true;
            if ( myTourProperties.SlalomScorebookPlcmtOrg.ToLower().Equals( "div" ) ) plcmtDivButton.Checked = true;
            if ( myTourProperties.SlalomScorebookPlcmtOrg.ToLower().Equals( "divgr" ) ) plcmtDivGrpButton.Checked = true;

            // Retrieve data from database
            mySanctionNum = Properties.Settings.Default.AppSanctionNum;

            if ( mySanctionNum == null ) {
                MessageBox.Show( "An active tournament must be selected from the Administration menu Tournament List option" );
            } else {
                if ( mySanctionNum.Length < 6 ) {
                    MessageBox.Show( "An active tournament must be selected from the Administration menu Tournament List option" );
                } else {
                    //Retrieve selected tournament attributes
                    DataTable curTourDataTable = getTourData( mySanctionNum );
                    if ( curTourDataTable.Rows.Count > 0 ) {
                        myTourRow = curTourDataTable.Rows[0];
                        myTourRules = (String)myTourRow["Rules"];

                        if ( myTourRules.ToLower().Equals( "iwwf" ) ) {
                            kBasePointsButton.Checked = true;
                        } else if ( myTourRules.ToLower().Equals( "ncwsa" ) ) {
                            plcmtPointsButton.Checked = true;
                        }
                        loadEventGroupList();
                    }
                }
            }
        }
        private void SlalomSummary_Load(object sender, EventArgs e)
        {
            if (Properties.Settings.Default.SlalomScoreSummary_Width > 0) {
                this.Width = Properties.Settings.Default.SlalomScoreSummary_Width;
            }
            if (Properties.Settings.Default.SlalomScoreSummary_Height > 0) {
                this.Height = Properties.Settings.Default.SlalomScoreSummary_Height;
            }
            if (Properties.Settings.Default.SlalomScoreSummary_Location.X > 0
                && Properties.Settings.Default.SlalomScoreSummary_Location.Y > 0) {
                this.Location = Properties.Settings.Default.SlalomScoreSummary_Location;
            }
            myTourProperties = TourProperties.Instance;

            bestScoreButton.Checked = true;
            if (myTourProperties.SlalomSummaryDataType.ToLower().Equals( "best" )) bestScoreButton.Checked = true;
            if ( myTourProperties.SlalomSummaryDataType.ToLower().Equals( "total" ) ) totalScoreButton.Checked = true;
            if ( myTourProperties.SlalomSummaryDataType.ToLower().Equals( "final" ) ) finalScoreButton.Checked = true;
            if ( myTourProperties.SlalomSummaryDataType.ToLower().Equals( "first" ) ) firstScoreButton.Checked = true;
            if ( myTourProperties.SlalomSummaryDataType.ToLower().Equals( "round" ) ) roundScoreButton.Checked = true;
            if (myTourProperties.SlalomSummaryDataType.ToLower().Equals( "h2h" )) h2hScoreButton.Checked = true;

            rawScoreButton.Checked = true;
            if ( myTourProperties.SlalomSummaryPlcmtMethod.ToLower().Equals( "points" ) ) pointsScoreButton.Checked = true;
            groupPlcmtButton.Checked = true;
            if ( myTourProperties.SlalomSummaryPlcmtOrg.ToLower().Equals( "tour" ) ) plcmtTourButton.Checked = true;
            if ( myTourProperties.SlalomSummaryPlcmtOrg.ToLower().Equals( "div" ) ) plcmtDivButton.Checked = true;
            if ( myTourProperties.SlalomSummaryPlcmtOrg.ToLower().Equals( "divgr" ) ) plcmtDivGrpButton.Checked = true;
            nopsPointsButton.Checked = true;
            if ( myTourProperties.SlalomSummaryPointsMethod.ToLower().Equals( "nops" ) ) nopsPointsButton.Checked = true;
            if ( myTourProperties.SlalomSummaryPointsMethod.ToLower().Equals( "plcmt" ) ) plcmtPointsButton.Checked = true;
            if ( myTourProperties.SlalomSummaryPointsMethod.ToLower().Equals( "kbase" ) ) kBasePointsButton.Checked = true;
            if ( myTourProperties.SlalomSummaryPointsMethod.ToLower().Equals( "hcap" ) ) handicapPointsButton.Checked = true;
            if ( myTourProperties.SlalomSummaryPointsMethod.ToLower().Equals( "ratio" ) ) ratioPointsButton.Checked = true;
            numPrelimTextBox.Text = myTourProperties.SlalomSummaryNumPrelim;

            String[] curList = { "MemberId", "SkierName", "City", "State", "SkiYearAge", "AgeGroup", "Event"
                    , "EventClassSlalom", "PlcmtSlalom", "TeamSlalom", "HCapBaseSlalom"
                    , "RoundSlalom", "ScoreSlalom", "PointsSlalom"
                    , "FinalPassNum", "FinalSpeedMph", "FinalSpeedKph", "FinalLen", "FinalLenOff", "FinalPassScore" };
            sortDialogForm = new SortDialogForm();
            sortDialogForm.ColumnListArray = curList;

            filterDialogForm = new Common.FilterDialogForm();
            filterDialogForm.ColumnListArray = curList;

            // Retrieve data from database
            mySanctionNum = Properties.Settings.Default.AppSanctionNum;

            if (mySanctionNum == null) {
                MessageBox.Show("An active tournament must be selected from the Administration menu Tournament List option");
            } else {
                if (mySanctionNum.Length < 6) {
                    MessageBox.Show("An active tournament must be selected from the Administration menu Tournament List option");
                } else {
                    //Retrieve selected tournament attributes
                    DataTable curTourDataTable = getTourData();
                    if (curTourDataTable.Rows.Count > 0) {
                        myTourRow = curTourDataTable.Rows[0];
                        myTourRules = (String)myTourRow["Rules"];

                        if ( myTourProperties.SlalomScoreSummary_Sort.Length > 0 ) {
                            mySortCommand = myTourProperties.SlalomScoreSummary_Sort;
                        } else {
                            mySortCommand = "";
                        }
                        if (myTourRules.ToLower().Equals( "ncwsa" )) {
                            Round.Visible = false;
                            EventClass.Visible = false;
                            TeamCodeNcwsa.Visible = true;
                            TeamCode.Visible = false;
                        } else {
                            TeamCodeNcwsa.Visible = false;
                            TeamCode.Visible = true;
                        }

                        loadGroupList();
                    }
                }
            }
        }
        private void TrickSummaryTeam_Load( object sender, EventArgs e )
        {
            if ( Properties.Settings.Default.TrickTeamSummary_Width > 0 ) {
                this.Width = Properties.Settings.Default.TrickTeamSummary_Width;
            }
            if ( Properties.Settings.Default.TrickTeamSummary_Height > 0 ) {
                this.Height = Properties.Settings.Default.TrickTeamSummary_Height;
            }
            if ( Properties.Settings.Default.TrickTeamSummary_Location.X > 0
                && Properties.Settings.Default.TrickTeamSummary_Location.Y > 0 ) {
                this.Location = Properties.Settings.Default.TrickTeamSummary_Location;
            }
            myTourProperties = TourProperties.Instance;

            bestScoreButton.Checked = true;
            if (myTourProperties.TrickTeamSummaryDataType.ToLower().Equals( "best" )) bestScoreButton.Checked = true;
            if (myTourProperties.TrickTeamSummaryDataType.ToLower().Equals( "total" )) totalScoreButton.Checked = true;
            if ( myTourProperties.TrickTeamSummaryDataType.ToLower().Equals( "final" ) ) finalScoreButton.Checked = true;
            rawScoreButton.Checked = true;
            if (myTourProperties.TrickTeamSummaryPlcmtMethod.ToLower().Equals( "score" )) rawScoreButton.Checked = true;
            if (myTourProperties.TrickTeamSummaryPlcmtMethod.ToLower().Equals( "points" )) pointsScoreButton.Checked = true;
            plcmtTourButton.Checked = true;
            if (myTourProperties.TrickTeamSummaryPlcmtOrg.ToLower().Equals( "tour" )) plcmtTourButton.Checked = true;
            if (myTourProperties.TrickTeamSummaryPlcmtOrg.ToLower().Equals( "div" )) divPlcmtButton.Checked = true;
            if (myTourProperties.SlalomTeamSummaryPlcmtOrg.ToLower().Equals( "group" )) groupPlcmtButton.Checked = true;
            plcmtPointsButton.Checked = true;
            if ( myTourProperties.TrickTeamSummaryPointsMethod.ToLower().Equals( "nops" ) ) nopsPointsButton.Checked = true;
            if ( myTourProperties.TrickTeamSummaryPointsMethod.ToLower().Equals( "plcmt" ) ) plcmtPointsButton.Checked = true;
            if ( myTourProperties.TrickTeamSummaryPointsMethod.ToLower().Equals( "kbase" ) ) kBasePointsButton.Checked = true;
            if ( myTourProperties.TrickTeamSummaryPointsMethod.ToLower().Equals( "hcap" ) ) handicapPointsButton.Checked = true;
            if ( myTourProperties.TrickTeamSummaryPointsMethod.ToLower().Equals( "ratio" ) ) ratioPointsButton.Checked = true;

            // Retrieve data from database
            mySanctionNum = Properties.Settings.Default.AppSanctionNum;

            if ( mySanctionNum == null ) {
                MessageBox.Show( "An active tournament must be selected from the Administration menu Tournament List option" );
            } else {
                if ( mySanctionNum.Length < 6 ) {
                    MessageBox.Show( "An active tournament must be selected from the Administration menu Tournament List option" );
                } else {
                    myNumPerTeam = Convert.ToInt16( myTourProperties.TrickTeamSummary_NumPerTeam);
                    NumPerTeamTextBox.Text = myNumPerTeam.ToString();

                    //Retrieve selected tournament attributes
                    DataTable curTourDataTable = getTourData();
                    if (curTourDataTable.Rows.Count > 0) {
                        myTourRow = curTourDataTable.Rows[0];
                        myTourRules = (String)myTourRow["Rules"];
                        if (myTourRules.ToLower().Equals( "ncwsa" )) {
                            Round.Visible = false;
                            EventClass.Visible = false;
                        }
                        loadGroupList();
                    }
                }
            }
        }
        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;
        }
        private void TourList_Load(object sender, EventArgs e)
        {
            if (Properties.Settings.Default.TourList_Width > 0) {
                this.Width = Properties.Settings.Default.TourList_Width;
            }
            if (Properties.Settings.Default.TourList_Height > 0) {
                this.Height = Properties.Settings.Default.TourList_Height;
            }
            if (Properties.Settings.Default.TourList_Location.X > 0
                && Properties.Settings.Default.TourList_Location.Y > 0) {
                this.Location = Properties.Settings.Default.TourList_Location;
            }
            myTourProperties = TourProperties.Instance;
            mySortCommand = "SanctionId ASC";

            sortDialogForm = new SortDialogForm();
            sortDialogForm.ColumnList = dataGridView.Columns;

            filterDialogForm = new Common.FilterDialogForm();
            filterDialogForm.ColumnList = dataGridView.Columns;

            //Retrieve tournament list and set current position to active tournament
            navRefresh_Click( null, null );
        }
        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;
        }
        private void MasterSummaryOverallUS_Load( object sender, EventArgs e )
        {
            if ( Properties.Settings.Default.MasterSummaryOverallUS_Width > 0 ) {
                this.Width = Properties.Settings.Default.MasterSummaryOverallUS_Width;
            }
            if ( Properties.Settings.Default.MasterSummaryOverallUS_Height > 0 ) {
                this.Height = Properties.Settings.Default.MasterSummaryOverallUS_Height;
            }
            if ( Properties.Settings.Default.MasterSummaryOverallUS_Location.X > 0
                && Properties.Settings.Default.MasterSummaryOverallUS_Location.Y > 0 ) {
                this.Location = Properties.Settings.Default.MasterSummaryOverallUS_Location;
            }
            myTourProperties = TourProperties.Instance;

            bestScoreButton.Checked = true;
            if (myTourProperties.MasterSummaryOverallDataType.ToLower().Equals( "best" )) bestScoreButton.Checked = true;
            if (myTourProperties.MasterSummaryOverallDataType.ToLower().Equals( "round" )) roundScoreButton.Checked = true;
            if (myTourProperties.MasterSummaryOverallDataType.ToLower().Equals( "final" )) finalScoreButton.Checked = true;

            pointsScoreButton.Checked = true;
            if (myTourProperties.MasterSummaryOverallPlcmtMethod.ToLower().Equals( "points" )) pointsScoreButton.Checked = true;
            if (myTourProperties.MasterSummaryOverallPlcmtMethod.ToLower().Equals( "hcap" )) handicapScoreButton.Checked = true;
            if (myTourProperties.MasterSummaryOverallPlcmtMethod.ToLower().Equals( "ratio" )) ratioScoreButton.Checked = true;

            plcmtDivButton.Checked = true;
            if (myTourProperties.MasterSummaryOverallPlcmtOrg.ToLower().Equals( "div" )) plcmtDivButton.Checked = true;
            if (myTourProperties.MasterSummaryOverallPlcmtOrg.ToLower().Equals( "divgr" )) plcmtDivGrpButton.Checked = true;
            if (myTourProperties.MasterSummaryOverallPlcmtOrg.ToLower().Equals( "tour" )) plcmtTourButton.Checked = true;
            if (myTourProperties.MasterSummaryOverallPlcmtOrg.ToLower().Equals( "group" )) groupPlcmtButton.Checked = true;

            nopsPointsButton.Checked = true;
            if (myTourProperties.MasterSummaryOverallPointsMethod.ToLower().Equals( "nops" )) nopsPointsButton.Checked = true;
            if (myTourProperties.MasterSummaryOverallPointsMethod.ToLower().Equals( "plcmt" )) plcmtPointsButton.Checked = true;
            if (myTourProperties.MasterSummaryOverallPointsMethod.ToLower().Equals( "kbase" )) kBasePointsButton.Checked = true;
            if (myTourProperties.MasterSummaryOverallPointsMethod.ToLower().Equals( "ratio" )) ratioPointsButton.Checked = true;

            showAllButton.Checked = true;
            if (myTourProperties.MasterSummaryOverallFilter.ToLower().Equals( "all" )) showAllButton.Checked = true;
            if (myTourProperties.MasterSummaryOverallFilter.ToLower().Equals( "qualifed" )) showQlfyButton.Checked = true;
            if (myTourProperties.MasterSummaryOverallFilter.ToLower().Equals( "eligible" )) showEligButton.Checked = true;

            // Retrieve data from database
            mySanctionNum = Properties.Settings.Default.AppSanctionNum;

            if ( mySanctionNum == null ) {
                MessageBox.Show( "An active tournament must be selected from the Administration menu Tournament List option" );
            } else {
                if ( mySanctionNum.Length < 6 ) {
                    MessageBox.Show( "An active tournament must be selected from the Administration menu Tournament List option" );
                } else {
                    //Retrieve selected tournament attributes
                    DataTable curTourDataTable = getTourData();
                    if (curTourDataTable.Rows.Count > 0) {
                        myTourRow = curTourDataTable.Rows[0];
                        myTourRules = (String)myTourRow["Rules"];

                        if (myTourRules.ToLower().Equals( "ncwsa" )) {
                            RoundOverall.Visible = false;
                            RoundSlalom.Visible = false;
                            RoundTrick.Visible = false;
                            RoundJump.Visible = false;
                            EventClassSlalom.Visible = false;
                            EventClassTrick.Visible = false;
                            EventClassJump.Visible = false;
                            TeamCodeNcwsa.Visible = true;
                        } else {
                            RoundOverall.Visible = true;
                            RoundSlalom.Visible = true;
                            RoundTrick.Visible = true;
                            RoundJump.Visible = true;
                            EventClassSlalom.Visible = true;
                            EventClassTrick.Visible = true;
                            EventClassJump.Visible = true;
                            TeamCodeNcwsa.Visible = false;
                        }

                        loadEventGroupList();
                    }
                }
            }
        }
        private void ScoreEntry_Load(object sender, EventArgs e)
        {
            if (Properties.Settings.Default.JumpEntry_Width > 0) {
                this.Width = Properties.Settings.Default.JumpEntry_Width;
            }
            if (Properties.Settings.Default.JumpEntry_Height > 0) {
                this.Height = Properties.Settings.Default.JumpEntry_Height;
            }
            if (Properties.Settings.Default.JumpEntry_Location.X > 0
                && Properties.Settings.Default.JumpEntry_Location.Y > 0) {
                this.Location = Properties.Settings.Default.JumpEntry_Location;
            }
            myTourProperties = TourProperties.Instance;
            mySortCommand = myTourProperties.RunningOrderSortJump;
            int curDelim = mySortCommand.IndexOf( "AgeGroup" );
            if (curDelim < 0) {
            } else if (curDelim > 0) {
                mySortCommand = mySortCommand.Substring( 0, curDelim ) + "DivOrder" + mySortCommand.Substring( curDelim + "AgeGroup".Length );
                myTourProperties.RunningOrderSortJump = mySortCommand;
            } else {
                mySortCommand = "DivOrder" + mySortCommand.Substring( "AgeGroup".Length );
                myTourProperties.RunningOrderSortJump = mySortCommand;
            }

            ResizeNarrow.Visible = false;
            ResizeNarrow.Enabled = false;
            ResizeWide.Visible = true;
            ResizeWide.Enabled = true;
            ResizeNarrow.Location = ResizeWide.Location;

            EventRunInfoLabel.Text = "   Event Start:\n" + "   Event Delay:\n" + "Skiers, Passes:";
            EventRunInfoData.Text = "";
            EventRunPerfLabel.Text = "Event Duration:\n" + "Mins Per Skier:\n" + " Mins Per Pass:"******"";
            EventDelayReasonTextBox.Visible = false;
            EventDelayReasonLabel.Visible = false;
            StartTimerButton.Visible = false;
            PauseTimerButton.Visible = true;
            StartTimerButton.Location = PauseTimerButton.Location;

            String[] curList = { "SkierName", "Div", "DivOrder", "EventGroup", "RunOrder", "TeamCode", "EventClass", "RankingScore", "RankingRating", "HCapBase", "HCapScore", "Status" };
            sortDialogForm = new SortDialogForm();
            sortDialogForm.ColumnListArray = curList;

            filterDialogForm = new Common.FilterDialogForm();
            filterDialogForm.ColumnListArray = curList;

            eventGroupSelect = new EventGroupSelect();
            rerideReasonDialogForm = new RerideReason();
            skierDoneReasonDialogForm = new SkierDoneReason();

            // Retrieve data from database
            mySanctionNum = Properties.Settings.Default.AppSanctionNum;
            Cursor.Current = Cursors.WaitCursor;

            if (mySanctionNum == null) {
                MessageBox.Show("An active tournament must be selected from the Administration menu Tournament List option");
            } else {
                if (mySanctionNum.Length < 6) {
                    MessageBox.Show("An active tournament must be selected from the Administration menu Tournament List option");
                } else {
                    //Retrieve selected tournament attributes
                    DataTable curTourDataTable = getTourData(mySanctionNum);
                    if (curTourDataTable.Rows.Count > 0) {
                        myTourRow = curTourDataTable.Rows[0];
                        myTourRules = (String)myTourRow["Rules"];
                        if ( myTourRules.ToLower().Equals( "ncwsa" ) ) {
                            TeamCode.Visible = true;
                        } else {
                            TeamCode.Visible = false;
                        }

                        if ( (byte)myTourRow["JumpRounds"] > 0 ) {
                            mySanctionYear = Convert.ToInt16( mySanctionNum.Substring( 0, 2 ) );

                            //Load round selection list based on number of rounds specified for the tournament
                            roundSelect.SelectList_Load( myTourRow["JumpRounds"].ToString(), roundSelect_Click );
                            roundActiveSelect.SelectList_LoadHorztl( myTourRow["JumpRounds"].ToString(), roundActiveSelect_Click );
                            roundActiveSelect.RoundValue = "1";
                            roundSelect.RoundValue = "1";

                            //Load jump speed selection list
                            JumpSpeedSelect.SelectList_Load( JumpSpeedSelect_Change );

                            //Load ramp height selection list
                            RampHeightSelect.SelectList_Load( RampHeightSelect_Change );

                            mySkierClassList = new ListSkierClass();
                            mySkierClassList.ListSkierClassLoad();
                            scoreEventClass.DataSource = mySkierClassList.DropdownList;
                            scoreEventClass.DisplayMember = "ItemName";
                            scoreEventClass.ValueMember = "ItemValue";

                            myRuleType = ((String)myTourRow["Rules"]).ToUpper();
                            myTourClass = myTourRow["Class"].ToString().ToUpper();
                            myClassCRow = mySkierClassList.SkierClassDataTable.Select("ListCode = 'C'")[0];
                            myClassERow = mySkierClassList.SkierClassDataTable.Select("ListCode = 'E'")[0];
                            myAgeDivList = new AgeGroupDropdownList( myTourRow );

                            //Setup for meter input if using meters to calculate distances
                            NumJudges = Convert.ToInt16( myTourProperties.JumpEntryNumJudges);
                            if ( NumJudges > 0 ) {
                                JumpCalcMetersCB.Checked = true;
                                JumpCalcVideoCB.Checked = false;
                            } else {
                                JumpCalcMetersCB.Checked = false;
                                JumpCalcVideoCB.Checked = true;
                            }

                            //Retrieve boat times
                            StringBuilder curSqlStmt = new StringBuilder( "" );
                            curSqlStmt.Append( "SELECT ListCode, CodeValue, MinValue, MaxValue, CodeDesc FROM CodeValueList WHERE ListName = 'JumpBoatTime3Seg' ORDER BY SortSeq" );
                            myTimesDataTable = getData( curSqlStmt.ToString() );

                            //Retrieve maximum speeds by age group
                            getMaxSpeedData();

                            //Retrieve minimum speeds by class
                            getMinSpeedData();

                            //Retrieve maximum ramp heights by age group
                            getMaxRampData();

                            //Retrieve list of divisions and scores that require 3 segment validation for L and R tournaments
                            try {
                                DataTable curTourClassDataTable = mySkierClassList.getTourClassList();
                                myClassRow = curTourClassDataTable.Select( "ListCode = '" + myTourClass + "'" )[0];
                                if ((Decimal)myClassRow["ListCodeNum"] > (Decimal)myClassERow["ListCodeNum"]) {
                                    getJump3TimesDivData();
                                } else {
                                    myJump3TimesDivDataTable = null;
                                }
                            } catch {
                                myJump3TimesDivDataTable = null;
                            }

                            //Get list of approved tow boats
                            getApprovedTowboats();
                            BoatSelectInfoLabel.Visible = false;
                            listApprovedBoatsDataGridView.Visible = false;

                            //Retrieve and load tournament event entries
                            loadEventGroupList( Convert.ToByte( roundActiveSelect.RoundValue ) );

                            if (ExportLiveWeb.LiveWebLocation.Length > 1) {
                                LiveWebLabel.Visible = true;
                            } else {
                                LiveWebLabel.Visible = false;
                            }
                        } else {
                            MessageBox.Show( "The jump event is not defined for the active tournament" );
                        }
                    } else {
                        MessageBox.Show( "The active tournament is not properly defined.  You must select from the Administration menu Tournament List option" );
                    }
                }
            }
            Cursor.Current = Cursors.Default;
        }
        public bool ExportData()
        {
            DataTable curDataTable, curDetailDataTable, curScoresDataTable;
            try {
                //Retrieve selected tournament attributes
                DataTable curTourDataTable = getTourData();
                myTourRow = curTourDataTable.Rows[0];
                myTourRules = (String)myTourRow["Rules"];

                myTourProperties = TourProperties.Instance;

                if (myTourRow["SlalomRounds"] == DBNull.Value) { myTourRow["SlalomRounds"] = 0; }
                if ( myTourRow["TrickRounds"] == DBNull.Value ) { myTourRow["TrickRounds"] = 0; }
                if ( myTourRow["JumpRounds"] == DBNull.Value ) { myTourRow["JumpRounds"] = 0; }
                Int16 curEventRounds = 0;
                try {
                    curEventRounds = Convert.ToInt16( myTourRow["SlalomRounds"] );
                    if ( curEventRounds > 0 ) {
                        isSlalomActive = true;
                    } else {
                        isSlalomActive = false;
                    }
                } catch {
                    isSlalomActive = false;
                }
                try {
                    curEventRounds = Convert.ToInt16( myTourRow["TrickRounds"] );
                    if ( curEventRounds > 0 ) {
                        isTrickActive = true;
                    } else {
                        isTrickActive = false;
                    }
                } catch {
                    isTrickActive = false;
                }
                try {
                    curEventRounds = Convert.ToInt16( myTourRow["JumpRounds"] );
                    if ( curEventRounds > 0 ) {
                        isJumpActive = true;
                    } else {
                        isJumpActive = false;
                    }
                } catch {
                    isJumpActive = false;
                }

                StringBuilder outLine = new StringBuilder( "" );
                String curFilename = mySanctionNum.Trim() + "TS.prn";
                myOutBuffer = getExportFile( curFilename );
                if ( myOutBuffer != null ) {
                    Log.WriteFile( "Export tournament summary: " + curFilename );

                    writeHeader();
                    OfficialWorkUpdate curWorkRecordUpdate = new OfficialWorkUpdate();
                    curWorkRecordUpdate.updateOfficialWorkRecord();

                    readExportTourSkierCounts();
                    readExportEventSkierCounts();
                    readExportEventSkierGroupCounts();

                    curDataTable = getOfficialWorkAsgmt();
                    readExportOfficialAsgmt(curDataTable);

                    if ( isSlalomActive ) {
                        curScoresDataTable = getSlalomScores();
                        curDetailDataTable = getSlalomDetail();
                        readExportSlalomData( curScoresDataTable, curDetailDataTable );
                    }
                    if ( isTrickActive ) {
                        curScoresDataTable = getTrickScores();
                        curDetailDataTable = getTrickDetail();
                        readExportTrickData( curScoresDataTable, curDetailDataTable );
                    }
                    if ( isJumpActive ) {
                        curScoresDataTable = getJumpScores();
                        curDetailDataTable = getJumpDetail();
                        readExportJumpData( curScoresDataTable, curDetailDataTable );
                    }

                    DataTable curTeamDataTable = getTeamList();
                    if ( curTeamDataTable.Rows.Count > 0 ) {
                        readExportTeamData();
                    }

                    writeFooter();

                    Log.WriteFile( "Export tournament summary complete: " + curFilename );

                    myOutBuffer.Close();
                    return true;
                } else {
                    return false;
                }

            } catch ( Exception ex ) {
                MessageBox.Show( "Exception encountered in ExportTourSummary processing"
                    + "\n\nException: " + ex.Message
                );
                return false;
            }
        }
        public Boolean exportScoreBookData()
        {
            String curMethodName = "ExportScoreBookHtmlIwwf";
            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;
            myTourProperties = TourProperties.Instance;

            ExportScorebookTypeDialogForm curDialogForm = new ExportScorebookTypeDialogForm();
            curDialogForm.ShowDialog();
            if (curDialogForm.DialogResult == DialogResult.OK) {
                String curReportFormat = curDialogForm.ReportFormat;
                if (curReportFormat.Equals( "Magazine" )) {
                    MessageBox.Show( "This feature is not currently supported for IWWF tournaments" );
                } else {
                    try {
                        curMsg = "Exporting Scorebook Html";
                        Log.WriteFile( curMethodName + ":begin: " + curMsg );

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

                        if (outBuffer == null) {
                            curMsg = "Output file not available";
                        } else {
                            String curPlcmtMethod = "score", curPlcmtOrg = "div", curPointsMethod = "kbase";
                            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";
                            }

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

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

                            DataTable mySummaryDataTable = curCalcSummary.CalcIwwfEventPlcmts( myTourRow, mySanctionNum, "Scorebook", myTourRules, 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( mySanctionNum, myTourRow, myMemberData, mySummaryDataTable, mySlalomDetail, myTrickDetail, myJumpDetail );
                            mySummaryDataTable = newSummaryDataTable;
                            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, mySummaryDataTable );
                            }
                            //Build master summary header
                            writeMasterSummaryHeader( outBuffer, curPlcmtOrg, curReportFormat );
                            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();

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

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

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

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

                                writeSkierTrickScore( curRow, curPlcmtOrg, outBuffer );

                                writeSkierJumpScore( curRow, curPlcmtOrg, outBuffer );

                                writeSkierOverallScore( curRow, curReportFormat, 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() );

                                DataTable mySlalomDataTable = curCalcSummary.CalcIwwfEventPlcmts( myTourRow, mySanctionNum, "Slalom", myTourRules, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                                writeIndexSlalomResults( curPlcmtOrg, mySlalomDataTable, outBuffer );

                                DataTable myTrickDataTable = curCalcSummary.CalcIwwfEventPlcmts( myTourRow, mySanctionNum, "Trick", myTourRules, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                                writeIndexTrickResults( curPlcmtOrg, myTrickDataTable, outBuffer );

                                DataTable myJumpDataTable = curCalcSummary.CalcIwwfEventPlcmts( myTourRow, mySanctionNum, "Jump", myTourRules, curDataType, curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                                writeIndexJumpResults( curPlcmtOrg, myJumpDataTable, outBuffer );

                                DataTable myOverallDataTable = curCalcSummary.CalcIwwfEventPlcmts( myTourRow, mySanctionNum, "Overall", myTourRules, "best", curPlcmtMethod, curPlcmtOrg, curPointsMethod, null, null );
                                writeIndexOverallResults( curPlcmtOrg, myOverallDataTable, outBuffer );

                                if (isTeamAvailable()) {
                                    //Write team summary
                                    Int16 myNumPerTeam = Convert.ToInt16( myTourProperties.TeamSummary_NumPerTeam);
                                    String curTeamPlcmtOrg = myTourProperties.TeamSummaryPlcmtOrg;
                                    //Int16 myNumPerTeam = Properties.Settings.Default.TeamSummary_NumPerTeam;
                                    //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";
                                    }

                                    String curSortCmd = "";
                                    if (curTeamPlcmtOrg.ToLower().Equals( "div" )) {
                                        curSortCmd = "AgeGroup ASC, PointsSlalom DESC, SkierName ASC";
                                    } else {
                                        curSortCmd = "PointsSlalom DESC, SkierName ASC";
                                    }
                                    mySlalomDataTable.DefaultView.Sort = curSortCmd;
                                    mySlalomDataTable = mySlalomDataTable.DefaultView.ToTable();
                                    DataTable myTeamDataTable = curCalcSummary.getSlalomSummaryTeam( mySlalomDataTable, myTourRow, myNumPerTeam, curTeamDataType, curTeamPlcmtMethod, curTeamPlcmtOrg, curTeamPointsMethod );

                                    if (curTeamPlcmtOrg.ToLower().Equals( "div" )) {
                                        curSortCmd = "AgeGroup ASC, PointsTrick DESC, SkierName ASC";
                                    } else {
                                        curSortCmd = "PointsTrick DESC, SkierName ASC";
                                    }
                                    myTrickDataTable.DefaultView.Sort = curSortCmd;
                                    myTrickDataTable = myTrickDataTable.DefaultView.ToTable();
                                    myTeamDataTable = curCalcSummary.getTrickSummaryTeam( myTeamDataTable, myTrickDataTable, myTourRow, myNumPerTeam, curTeamDataType, curTeamPlcmtMethod, curTeamPlcmtOrg, curTeamPointsMethod );

                                    if (curTeamPlcmtOrg.ToLower().Equals( "div" )) {
                                        curSortCmd = "AgeGroup ASC, PointsJump DESC, SkierName ASC";
                                    } else {
                                        curSortCmd = "PointsJump DESC, SkierName ASC";
                                    }
                                    myJumpDataTable.DefaultView.Sort = curSortCmd;
                                    myJumpDataTable = myJumpDataTable.DefaultView.ToTable();
                                    myTeamDataTable = curCalcSummary.getJumpSummaryTeam( myTeamDataTable, myJumpDataTable, myTourRow, myNumPerTeam, curTeamDataType, curTeamPlcmtMethod, curTeamPlcmtOrg, curTeamPointsMethod );

                                    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;
        }
        private void RunningOrderRound_Load(object sender, EventArgs e) {
            if (Properties.Settings.Default.RunningOrderRound_Width > 0) {
                this.Width = Properties.Settings.Default.RunningOrderRound_Width;
            }
            if (Properties.Settings.Default.RunningOrderRound_Height > 0) {
                this.Height = Properties.Settings.Default.RunningOrderRound_Height;
            }
            if (Properties.Settings.Default.RunningOrder_Location.X > 0
                && Properties.Settings.Default.RunningOrderRound_Location.Y > 0) {
                    this.Location = Properties.Settings.Default.RunningOrderRound_Location;
            }

            myTourProperties = TourProperties.Instance;

            myRunOrderCopyDialog = new RunOrderCopyDialogForm();
            myRunOrderElimDialog = new RunOrderElimDialogForm();
            myCalcSummary = new CalcScoreSummary();

            mySanctionNum = Properties.Settings.Default.AppSanctionNum;
            loadGroupList();
            isDataModified = false;
        }
        private void RunningOrderTour_Load(object sender, EventArgs e)
        {
            if (Properties.Settings.Default.RunningOrder_Width > 0) {
                this.Width = Properties.Settings.Default.RunningOrder_Width;
            }
            if (Properties.Settings.Default.RunningOrder_Height > 0) {
                this.Height = Properties.Settings.Default.RunningOrder_Height;
            }
            if (Properties.Settings.Default.RunningOrder_Location.X > 0
                && Properties.Settings.Default.RunningOrder_Location.Y > 0) {
                this.Location = Properties.Settings.Default.RunningOrder_Location;
            }
            isLoadInProg = true;
            myTourProperties = TourProperties.Instance;

            String[] curList = { "SkierName", "EventGroup", "Div", "DivOrder", "RunOrder", "TeamCode", "EventClass", "RankingScore", "RankingRating", "JumpHeight", "HCapBase", "HCapScore" };
            sortDialogForm = new SortDialogForm();
            sortDialogForm.ColumnListArray = curList;

            filterDialogForm = new Common.FilterDialogForm();
            filterDialogForm.ColumnListArray = curList;

            // Retrieve data from database
            mySanctionNum = Properties.Settings.Default.AppSanctionNum;

            if (mySanctionNum == null) {
                MessageBox.Show("An active tournament must be selected from the Administration menu Tournament List option");
                //this.Close();
            } else {
                if (mySanctionNum.Length < 6) {
                    MessageBox.Show("An active tournament must be selected from the Administration menu Tournament List option");
                    //this.Close();
                } else {
                    //Retrieve selected tournament attributes
                    DataTable curTourDataTable = getTourData( mySanctionNum );
                    if ( curTourDataTable.Rows.Count > 0 ) {
                        myTourRow = curTourDataTable.Rows[0];
                        myTourRules = (String)myTourRow["Rules"];
                        myTourEventClass = (String)myTourRow["EventClass"];
                        myTourClass = (String)myTourRow["Class"];

                        mySkierClassList = new ListSkierClass();
                        mySkierClassList.ListSkierClassLoad();
                        EventClass.DataSource = mySkierClassList.DropdownList;
                        EventClass.DisplayMember = "ItemName";
                        EventClass.ValueMember = "ItemValue";

                        if ( myTourRow["SlalomRounds"] == DBNull.Value ) { myTourRow["SlalomRounds"] = 0; }
                        if ( myTourRow["TrickRounds"] == DBNull.Value ) { myTourRow["TrickRounds"] = 0; }
                        if ( myTourRow["JumpRounds"] == DBNull.Value ) { myTourRow["JumpRounds"] = 0; }
                        if ( Convert.ToInt16( myTourRow["SlalomRounds"] ) == 0 ) {
                            slalomButton.Visible = false;
                        }
                        if ( Convert.ToInt16( myTourRow["TrickRounds"] ) == 0 ) {
                            trickButton.Visible = false;
                        }
                        if ( Convert.ToInt16( myTourRow["JumpRounds"] ) == 0 ) {
                            jumpButton.Visible = false;
                        }

                        myFilterCmd = "";
                        if (slalomButton.Checked) {
                            mySortCmd = myTourProperties.RunningOrderSortSlalom;
                        } else if (trickButton.Checked) {
                            mySortCmd = myTourProperties.RunningOrderSortTrick;
                        } else if (jumpButton.Checked) {
                            mySortCmd = myTourProperties.RunningOrderSortJump;
                        }

                        if (ExportLiveWeb.LiveWebLocation.Length > 1) {
                            LiveWebLabel.Visible = true;
                        } else {
                            LiveWebLabel.Visible = false;
                        }
                    } else {
                        MessageBox.Show( "An active tournament must be selected from the Administration menu Tournament List option" );
                    }
                }
            }
            isDataModified = false;
            isLoadInProg = false;
        }