public void ReadUsersFromFile() { try { using (BinaryReader b = new BinaryReader( File.Open("UserData.txt", FileMode.Open))) { int pos = 0; int length = (int)b.BaseStream.Length; while (pos < length) { Dictionary <DateTime, BettingsEvents> betsPlacedUser = new Dictionary <DateTime, BettingsEvents>(); string email = b.ReadString(); int age = b.ReadInt32(); string name = b.ReadString(); string surname = b.ReadString(); string login = b.ReadString(); string password = b.ReadString(); string country = b.ReadString(); string phoneNumber = b.ReadString(); decimal balance = b.ReadDecimal(); string valute = b.ReadString(); int betsPlaced = b.ReadInt32(); for (int i = 0; i < betsPlaced; i++) { string eventStartStr = b.ReadString(); DateTime eventStart = DateTime.Parse(eventStartStr); TypeOfEvent typeOfEvent = (TypeOfEvent)b.ReadInt32(); string teamOne = b.ReadString(); double teamOneCoefitient = b.ReadDouble(); decimal teamOneMonetPlaced = b.ReadDecimal(); string teamTwo = b.ReadString(); double teamTwoCoefitient = b.ReadDouble(); decimal teamTwoMoneyPlaced = b.ReadDecimal(); string eventEndStr = b.ReadString(); DateTime eventEnd = DateTime.Parse(eventEndStr); BettingsEvents bettings = new BettingsEvents { TeamOne = teamOne, TeamOneMonetPlaced = teamOneMonetPlaced, TeamOneCoefitient = teamOneCoefitient, TeamTwo = teamTwo, TeamTwoCoefitient = teamTwoCoefitient, TeamTwoMoneyPlaced = teamTwoMoneyPlaced, EventStart = eventStart, EventEnd = eventEnd, }; betsPlacedUser.Add(eventStart, bettings); pos += eventStartStr.Length * 2 + eventEndStr.Length * 2 + sizeof(int) + teamOne.Length * 2 + sizeof(double) * 2 + sizeof(decimal) * 2 + teamTwo.Length * 2; } User user = new User(name, surname, country, login, password, email, phoneNumber, age, balance, valute, betsPlacedUser); betsPlacedUser.Clear(); users.Add(user.Email, user); pos += sizeof(int) + email.Length * 2 + name.Length * 2 + surname.Length * 2 + login.Length * 2 + password.Length * 2 + country.Length * 2 + phoneNumber.Length * 2 + sizeof(decimal) + valute.Length * 2; } } } catch (IOException e) { Console.WriteLine(e.Message + " Cant open file"); } }
public void ReadFromFile() { try { using (BinaryReader b = new BinaryReader( File.Open("BetEvents.txt", FileMode.Open))) { int pos = 0; int length = (int)b.BaseStream.Length; while (pos < length) { List <BettingsEvents> bettings = new List <BettingsEvents>(); pos += sizeof(int); TypeOfEvent typeOfEvent = (TypeOfEvent)b.ReadInt32(); int eventsCount = b.ReadInt32(); pos += sizeof(int); for (int i = 0; i < eventsCount; i++) { string teamOne = b.ReadString(); double teamOneCoefitient = b.ReadDouble(); decimal teamOneMoneyPlaced = b.ReadDecimal(); string teamTwo = b.ReadString(); double teamTwoCoefitient = b.ReadDouble(); decimal teamTwoMoneyPlaced = b.ReadDecimal(); string startStr = b.ReadString(); string endStr = b.ReadString(); DateTime eventStart = DateTime.Parse(startStr); DateTime eventEnd = DateTime.Parse(endStr); BettingsEvents bet = new BettingsEvents { TeamOne = teamOne, TeamTwo = teamTwo, TeamOneCoefitient = teamOneCoefitient, TeamTwoCoefitient = teamTwoCoefitient, TeamOneMonetPlaced = teamOneMoneyPlaced, TeamTwoMoneyPlaced = teamTwoMoneyPlaced, EventStart = eventStart, EventEnd = eventEnd, BettingEvents = typeOfEvent }; bettings.Add(bet); pos += teamOne.Length * 2 + sizeof(double) + sizeof(decimal) + teamTwo.Length * 2 + sizeof(double) + sizeof(decimal) + startStr.Length * 2 + endStr.Length * 2; } bettingEvents.Add(typeOfEvent, bettings); } } } catch (IOException e) { Console.WriteLine(e.Message + " Cant open file"); } }
public void AddBettingEvents() { if (manage.LoggedAdmin != null) { char choice = 'y'; while (choice == 'y' || choice == 'Y') { BettingsEvents bettings = new BettingsEvents(); Console.WriteLine("Chose a discipline of the bet:"); Console.Write(" 1.eSports\n 2.Football\n 3.Basketball\n 4.Cricket\n 5.Valleyball\n 6.MMA\n 7.Box\n 8.Marathon\n 9.Tennis\n 10.Hokey\n"); switch (Int32.Parse(Console.ReadLine())) { case 1: bettings.BettingEvents = TypeOfEvent.eSports; break; case 2: bettings.BettingEvents = TypeOfEvent.Football; break; case 3: bettings.BettingEvents = TypeOfEvent.Basketball; break; case 4: bettings.BettingEvents = TypeOfEvent.Cricket; break; case 5: bettings.BettingEvents = TypeOfEvent.Valleyball; break; case 6: bettings.BettingEvents = TypeOfEvent.MMA; break; case 7: bettings.BettingEvents = TypeOfEvent.Box; break; case 8: bettings.BettingEvents = TypeOfEvent.Marathon; break; case 9: bettings.BettingEvents = TypeOfEvent.Tennis; break; case 10: bettings.BettingEvents = TypeOfEvent.Hokey; break; } Console.Write("Team one name:"); bettings.TeamOne = Console.ReadLine(); Console.Write("Team two name:"); bettings.TeamTwo = Console.ReadLine(); bettings.EventStart = DateTime.Now; Console.Write("Enter length of event in minutes:"); bettings.EventEnd = bettings.EventStart.AddSeconds(Int32.Parse(Console.ReadLine())); bettings.SetTeamOneCoefitient(0); bettings.SetTeamTwoCoefitient(0); if (bettingEvents.ContainsKey(bettings.BettingEvents)) { foreach (var item in bettingEvents) { if (item.Key == bettings.BettingEvents) { item.Value.Add(bettings); } break; } } else { List <BettingsEvents> betEvents = new List <BettingsEvents>(); betEvents.Add(bettings); bettingEvents.Add(bettings.BettingEvents, betEvents); } Console.WriteLine("Want to continue adding events? (y/n)"); choice = Char.Parse(Console.ReadLine()); } } else { Console.WriteLine("You`re not allowed to manage bets"); } }