Пример #1
0
        public double ReCalcHandicap(int NetScore, int thisRound)
        {
            double         newHandicap     = 0.0;
            BufferCategory CurrentCategory = new BufferCategory();

            CurrentCategory = Helpers.s_Buffers.GetCategory(_Category);

            if (thisRound == 3)
            {
                int tmp = NetScore;
                foreach (Round rnd in Helpers.s_Rounds.RoundsCompleted(_ID))
                {
                    tmp += rnd.Score_Net;
                }

                // New handicap as derived over 3 games.
                _Actual = FormatHandicap(tmp / 3);

                // Re-adjust Net Score as if using this handicap and later we
                // adjust as if this last game was played using this handicap.
                NetScore = (NetScore - Convert.ToInt32(_Actual));
            }

            if (NetScore > CurrentCategory.BufferValue)
            {
                //If Net Score > Buffer then Increase
                newHandicap = FormatHandicap(_Actual + CurrentCategory.Increase);
                _Notes      = string.Concat("Handicap Increased from ", _Actual.ToString("#0.0"), " to ", newHandicap.ToString("#0.0"), " (", DateTime.Now.ToLongDateString(), ")");
            }
            else
            {
                if (NetScore < 0)
                {
                    //Net Score < zero so reduction
                    newHandicap = FormatHandicap(_Actual - (Math.Abs(NetScore) * CurrentCategory.Reduction));
                    _Notes      = string.Concat("Handicap Reduced from ", _Actual.ToString("#0.0"), " to ", newHandicap.ToString("#0.0"), " (", DateTime.Now.ToLongDateString(), ")");
                }
                else
                {
                    //Net Score is within buffer so no Change to handicap.
                    newHandicap = _Actual;
                    _Notes      = "Net Score within Buffer so no change";
                }
            }

            if (thisRound == 3)
            {
                _Notes = string.Concat("First Handicap Initially set as ", newHandicap.ToString("#0.0"), " (", DateTime.Now.ToLongDateString(), ")");
            }

            _Actual      = newHandicap;
            _Playing     = Convert.ToInt32(newHandicap);
            _Category    = CheckCategory(_Actual, CurrentCategory);
            _DataIsDirty = true;
            return(_Actual);
        }
Пример #2
0
        public double CreateAdjustment(int Adjustment)
        {
            try
            {
                double         newHandicap     = 0.0;
                double         oldHandicap     = _Actual;
                Round          adjustmentRound = new Round();
                BufferCategory CurrentCategory = new BufferCategory();

                CurrentCategory = Helpers.s_Buffers.GetCategory(_Category);
                newHandicap     = _Actual - Adjustment;
                _Notes          = string.Concat("Handicap Adjustment of ", Adjustment.ToString("#0.0"), " applied (", DateTime.Now.ToLongDateString(), ")");
                newHandicap     = Math.Min(newHandicap, 28.0);
                _Playing        = Convert.ToInt32(newHandicap);
                _Actual         = Math.Round(newHandicap, 1);
                _Category       = CheckCategory(_Actual, CurrentCategory);

                adjustmentRound.ActualStrokes   = 0;
                adjustmentRound.AdjustedStrokes = Adjustment;
                adjustmentRound.Course          = "Adjustment";
                adjustmentRound.Date            = DateTime.Now.ToLongDateString();
                adjustmentRound.HandicapUsed    = Convert.ToInt32(oldHandicap);
                adjustmentRound.PlayerID        = _ID;
                adjustmentRound.Sequence        = _Rounds + 1;
                adjustmentRound.SSI             = 0;
                adjustmentRound.Score_Gross     = 0;
                adjustmentRound.Score_Net       = 0;
                adjustmentRound.Notes           = _Notes;

                Helpers.s_Rounds.AddRound(adjustmentRound);
            }
            catch (Exception ex)
            {
                Helpers.Log(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, ErrorLogger.LogLevel.ERROR);
                throw;
            }

            _DataIsDirty = true;
            return(_Actual);
        }
Пример #3
0
        private static int CheckCategory(double newHandicap, BufferCategory CurrentCategory)
        {
            if (newHandicap < CurrentCategory.Minimum)
            {
                // If newHandicap is less than the minimum for the current Category then move down a Category
                // unless already in the minimum Category.
                return((CurrentCategory.Category == Helpers.s_Buffers.MinimumCategoryID()) ? CurrentCategory.Category : CurrentCategory.Category - 1);
            }

            else if (newHandicap > CurrentCategory.Maximum)
            {
                // If new is more than the maximum for the current Category then move up a Category
                // unless already in the maximum Category.
                return((CurrentCategory.Category == Helpers.s_Buffers.MaximumCategoryID()) ? CurrentCategory.Category : CurrentCategory.Category + 1);
            }

            else
            {
                // If still in the same Category then thats the one to return.
                return(CurrentCategory.Category);
            }
        }
Пример #4
0
        private string ExtractPlayerDetails(bool adjustmentLetter)
        {
            try {
                string path = Helpers.OpenFile(Helpers.FileType.ForExtracting);
                if (path != string.Empty)
                {
                    using (FileAccessor fl = new FileAccessor(path, Helpers.FileType.ForExtracting))
                    {
                        StringBuilder str = new StringBuilder();

                        str.Append("Player Name:".PadRight(20)).Append(_CurrentPlayer.Name).AppendLine();
                        str.Append("Extract Date:".PadRight(20)).Append(DateTime.Now.ToString("dd MMM yyyy")).AppendLine();
                        str.Append("Rounds Played:".PadRight(20)).Append(_CurrentPlayer.RoundsPlayed.ToString()).AppendLine();
                        str.Append("Playing Handicap:".PadRight(20)).Append(_CurrentPlayer.Playing.ToString("#0")).AppendLine();
                        str.Append("Actual Handicap:".PadRight(20)).Append(_CurrentPlayer.Actual.ToString("#0.0")).AppendLine();
                        str.Append("Category:".PadRight(20)).Append(_CurrentPlayer.Category.ToString()).AppendLine();
                        fl.WriteEntry(str.ToString());
                        str.Clear();

                        if (adjustmentLetter)
                        {
                            fl.WriteEntry("");
                            fl.WriteEntry("*".PadLeft(50, '*'));
                            fl.WriteEntry("ADJUSTMENT");
                            fl.WriteEntry("*".PadLeft(50, '*'));

                            if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + AppDomain.CurrentDomain.RelativeSearchPath + "Info\\"))
                            {
                                string info = AppDomain.CurrentDomain.BaseDirectory + AppDomain.CurrentDomain.RelativeSearchPath + "Info\\Clause23.txt";
                                if (File.Exists(info))
                                {
                                    using (FileAccessor file = new FileAccessor(info, Helpers.FileType.ForReading))
                                    {
                                        str.Append(file.DataFile.ReadToEnd());
                                    }
                                }
                                else
                                {
                                    str.Append("Cannot find information File");
                                }
                            }
                            else
                            {
                                str.Append("Cannot find information Folder");
                            }

                            fl.WriteEntry(str.ToString());
                            str.Clear();
                            fl.WriteEntry("");
                        }

                        str.Append("Date".PadRight(20));
                        str.Append("Course".PadRight(12));
                        str.Append("SSI".PadRight(5));
                        str.Append("Score".PadRight(7));
                        str.Append("Adjusted".PadRight(10));
                        str.Append("Previous".PadRight(10));
                        str.Append("Net".PadRight(12));
                        str.Append("Notes");
                        fl.WriteEntry(str.AppendLine().ToString());

                        foreach (DataGridViewRow rw in this.dgvHistory.Rows)
                        {
                            str.Clear();
                            str.Append(rw.Cells[2].Value.ToString().PadRight(20));

                            // Chop Course to 12 characters.
                            if (rw.Cells[3].Value.ToString().Length > 12)
                            {
                                str.Append(rw.Cells[3].Value.ToString().Substring(0, 12));
                            }
                            else
                            {
                                str.Append(rw.Cells[3].Value.ToString().PadRight(12));
                            }

                            str.Append(rw.Cells[4].Value.ToString().PadRight(5));
                            str.Append(rw.Cells[5].Value.ToString().PadRight(7));
                            str.Append(rw.Cells[6].Value.ToString().PadRight(10));
                            str.Append(rw.Cells[9].Value.ToString().PadRight(10));

                            str.Append(((Convert.ToInt32(rw.Cells[6].Value) - Convert.ToInt32(rw.Cells[4].Value)).ToString()));
                            str.Append(" (").Append(rw.Cells[6].Value.ToString()).Append("-").Append(rw.Cells[4].Value.ToString()).Append(")  ");

                            str.Append(rw.Cells[10].Value.ToString());

                            fl.WriteEntry(str.ToString());
                        }

                        // Extract current Players Category details.
                        BufferCategory CurrentCategory = new BufferCategory();
                        CurrentCategory = Helpers.s_Buffers.GetCategory(_CurrentPlayer.Category);

                        str.Clear();
                        fl.WriteEntry(str.AppendLine().ToString());
                        str.Append(string.Concat(Enumerable.Repeat("*", 50)));
                        fl.WriteEntry(str.ToString());

                        str.Clear();
                        str.Append("Current Category is ").Append(CurrentCategory.Category.ToString());
                        fl.WriteEntry(str.ToString());

                        str.Clear();
                        str.Append("Minimum Handicap in this Category: ").Append(CurrentCategory.Minimum.ToString());
                        fl.WriteEntry(str.ToString());

                        str.Clear();
                        str.Append("Maximum Handicap in this Category: ").Append(CurrentCategory.Maximum.ToString());
                        fl.WriteEntry(str.ToString());

                        str.Clear();
                        str.Append("Adjustment Range is ").Append(CurrentCategory.Reduction.ToString()).Append(" Reduction and ").Append(CurrentCategory.Increase.ToString()).Append(" Increase");
                        fl.WriteEntry(str.ToString());

                        str.Clear();
                        str.Append("Buffer is ").Append(CurrentCategory.BufferValue.ToString());
                        fl.WriteEntry(str.ToString());

                        str.Clear();
                        str.Append("The Buffer is used where the Net Score is below or above Handicap to decide if an Adjustment is to be made. ").AppendLine();
                        str.Append("    If Net Score is greater than buffer then Adjustment is an Increase. ").AppendLine();
                        str.Append("    If Net Score is within buffer then no Adjustment. ").AppendLine();
                        str.Append("    If Net Score is less than Handicap then Adjustment is a Reduction. ");
                        fl.WriteEntry(str.ToString());

                        str.Clear();
                        str.Append(string.Concat(Enumerable.Repeat("*", 50)));
                        fl.WriteEntry(str.ToString());

                        str = null;
                    }
                }

                return(path);
            }
            catch (Exception ex)
            {
                Helpers.Log(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, ErrorLogger.LogLevel.ERROR);
                throw;
            }
        }