private void FileUpdate() { try { if (_DataHasChanged || (Helpers.s_Players != null && Helpers.s_Players.PlayerDataChanged())) { // re-write the whole file. FileAccessor sr = new FileAccessor(Helpers.s_Leagues.GetCurrentLeagueFile(), Helpers.FileType.ForWriting); sr.Dispose(); _DataHasChanged = false; } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), Helpers.Title); } }
private void PopulateLeague(string file) { if (file.Length > 5) { Helpers.s_Players = new Players(); Helpers.s_Rounds = new Rounds(); try { using (FileAccessor sr = new FileAccessor(file, Helpers.FileType.ForReading)) { string line; int PlayerID; String[] lineElements; Player plr; Round rnd; while ((line = sr.DataFile.ReadLine()) != null) { lineElements = line.Split(','); if (lineElements[0].ToString() == "Player") { PlayerID = int.Parse(lineElements[1]); plr = new Player(PlayerID) { Name = lineElements[2], Actual = double.Parse(lineElements[3]), Playing = int.Parse(lineElements[4]), Category = int.Parse(lineElements[5]), Notes = lineElements[6] }; Helpers.s_Players.AddPlayer(plr); } else if (lineElements[0].ToString() == "Round") { rnd = new Round { PlayerID = int.Parse(lineElements[1]), Sequence = int.Parse(lineElements[2]), Date = lineElements[3], Course = lineElements[4], SSI = int.Parse(lineElements[5]), ActualStrokes = int.Parse(lineElements[6]), AdjustedStrokes = int.Parse(lineElements[7]), Score_Gross = int.Parse(lineElements[8]), Score_Net = int.Parse(lineElements[9]), HandicapUsed = int.Parse(lineElements[10]), Notes = lineElements[11] }; Helpers.s_Rounds.AddRound(rnd); } } } foreach (Player plr in Helpers.s_Players.PlayersList) { plr.UpdateRoundsPlayed(Helpers.s_Rounds.RoundsPlayed(plr.PlayerID)); } if (Helpers.s_Players.PlayersList.Count > 1) { Helpers.s_Players.SortPlayers(); } } catch { throw; } } }
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; } }