public static void RunReferee(Referee referee) { var choice = RefereeMenu(); switch (choice) { case 1: // Show all competitions, choose one to start DisplayAvailableCompetitions(referee); var id = ChooseCompetition(); Thread.Sleep(1000); Clear(); break; case 2: // Test receive dive referee.ReceiveDive(); break; case 0: // Logout user ClientNetworkHandler.SendAndReceive("Logout"); LoginHandler.userState = LoginHandler.UserState.None; //LoginHandler.LoginMenu(); break; default: WriteLine("Try again!"); break; } }
public Assessment(int id, Score score, Dive dive, Referee referee) : base(id) { Point = score; DiveId = dive.Id; RefereeId = referee.Id; }
public void TestGetCompetition() { var competition = DbHandler.GetCompetition(49); Assert.AreEqual("Flydiving Cup", competition.Name); Assert.AreEqual("Moskva", competition.Location); Assert.AreEqual(4, competition.Rounds); var diver = DbHandler.GetDiver(3); var dive = DbHandler.GetDive(113); var referees = DbHandler.GetAssignedRefereesByCompetition(49); foreach (var tDiver in competition.ListDiver) { if (diver == tDiver) { Assert.AreEqual(diver.Name, tDiver.Name); Assert.AreEqual(diver.ListDive, tDiver.ListDive); } foreach (var tDive in tDiver.ListDive.Where(tDive => dive == tDive)) { Assert.AreEqual(dive.Type.Code, tDive.Type.Code); Assert.AreNotEqual(34, tDive.DiverId); } } var referee1 = new Referee(4, "Katja", "Ryssland"); var referee2 = new Referee(10, "Kalle", "Finland"); foreach (var judge in referees) { if (judge != referee1 && judge != referee2) continue; Assert.AreEqual(judge.Name, referee1.Name); Assert.AreEqual(judge.Country, referee2.Country); } }
public static void AddReferees() { DisplayReferees(); for (var i = 1; i <= 5; i++) { try { var tempReferee = new Referee(); var choice = ChooseReferee(i); foreach (var referee in AllReferees) { if (referee.Id == choice) { tempReferee = referee; } } if (tempReferee.Id == -1 || tempReferee.Id == 0) { i--; throw new ListObjectNotFoundException("Referee not found!"); } if (!TempCompetition.ListReferee.Contains(tempReferee)) TempCompetition.ListReferee.Add(tempReferee); else { i--; throw new ListObjectAlreadyExistsException("Referee already added!"); } } catch (ListObjectNotFoundException listObjectNotFoundException) { WriteLine(listObjectNotFoundException.Message); } catch (ListObjectAlreadyExistsException e) { WriteLine(e.Message); } } }
public static object LoginCheck(string userName, string password) { Logger.Trace($"Entering method {MethodBase.GetCurrentMethod().Name}"); Logger.Info($"Validating user with username {userName} and password {password}"); var sql = $"SELECT * FROM User WHERE loginName = '{userName}'"; using (var sqlConnection = ConnectToDatabase()) { var localPassword = ""; var localAccountType = ""; var localId = 0; var localName = ""; var localCountry = ""; using (var sqlQuery = new MySqlCommand(sql, sqlConnection)) { Logger.Info("Running Query: \"{0}\"", sql); var tableReader = sqlQuery.ExecuteReader(); while (tableReader.Read()) { localPassword = tableReader.GetString("password"); localAccountType = tableReader.GetString("accounttype"); localId = tableReader.GetInt32("ID"); localName = tableReader.GetString("name"); localCountry = tableReader.GetString("country"); } } if (localAccountType == "admin" && localPassword == password) { var admin = new Admin(localId, localName, localCountry, localAccountType); Logger.Info("User successfully validated as {0}", admin); Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}"); return admin; } if (localAccountType == "referee" && localPassword == password) { var referee = new Referee(localId, localName, localCountry, localAccountType); Logger.Info("User successfully validated as {0}", referee); Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}"); return referee; } Logger.Info("Unable to validate user."); Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}"); return "WI"; } }
public static void InsertReferee(Referee referee) { Logger.Trace($"Entering method {MethodBase.GetCurrentMethod().Name}"); const string sql = "INSERT INTO User (Name, Country, Loginname, password, Accounttype) " + "VALUES (@Name, @Country, @Loginname, @password, @Accounttype)"; using (var sqlConnection = ConnectToDatabase()) { using (var sqlQuery = new MySqlCommand(sql, sqlConnection)) { Logger.Info("Running Query: \"{0}\"", sql); sqlQuery.Parameters.AddWithValue("@Name", referee.Name); sqlQuery.Parameters.AddWithValue("@Country", referee.Country); sqlQuery.Parameters.AddWithValue("@Loginname", referee.Username); sqlQuery.Parameters.AddWithValue("@password", referee.Password); sqlQuery.Parameters.AddWithValue("@Accounttype", "referee"); var result = sqlQuery.ExecuteNonQuery(); Logger.Info("{0} rows affected", result); } } Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}"); }
public static void InsertAssignment(Competition competition, Referee referee) { Logger.Trace($"Entering method {MethodBase.GetCurrentMethod().Name}"); const string sql = "INSERT INTO Assignment (Competition, Referee) " + "VALUES (@competitionId, @refereeId)"; using (var sqlConnection = ConnectToDatabase()) { using (var sqlQuery = new MySqlCommand(sql, sqlConnection)) { Logger.Info("Running Query: \"{0}\"", sql); sqlQuery.Parameters.AddWithValue("@competitionId", competition.Id); sqlQuery.Parameters.AddWithValue("@refereeId", referee.Id); var result = sqlQuery.ExecuteNonQuery(); Logger.Info("{0} rows affected", result); } } Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}"); }
private static void LoginValidationGui(object userInfo) { ClientNetworkHandler.Connect(); var obj = ClientNetworkHandler.SendAndReceive($"LI;{userInfo}"); // Checks which user through received object var tAdmin = obj as Admin; if (tAdmin != null) { UserAdmin = tAdmin; userState = UserState.Admin; } var tReferee = obj as Referee; if (tReferee != null) { UserReferee = tReferee; userState = UserState.Referee; } else if (obj is string) { MessageBox.Show((string)obj, "Wrong Input!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void TestLogin() { var admin = new Admin(19, "Kjellbo", "Danmark"); var obj = DbHandler.LoginCheck("user_Kjellbo1", "0815"); var tAdmin = obj as Admin; if (tAdmin != null) { Assert.AreEqual(admin.Name, tAdmin.Name); Assert.AreEqual(admin.Country, tAdmin.Country); } var referee = new Referee(17, "Kjell", "Sverige"); obj = DbHandler.LoginCheck("user_Kjell1", "0815"); var tReferee = obj as Referee; if (tReferee == null) return; Assert.AreEqual(referee.Name, tReferee.Name); Assert.AreEqual(referee.Country, tReferee.Country); }
public void AddReferee(Referee referee) { referee.Password = Hasher.GenerateHash(referee.Password); SendToServer(referee); }
public Assessment(Score score, Dive dive, Referee referee) { this.Point = score; this.DiveId = dive.Id; this.RefereeId = referee.Id; }
public void OnAddNewRefereeToDatabase(object source, EventArgs args) { var admin = new Admin(); foreach (var box in RefereeFormTextBoxes) { if (!IsNullOrEmpty(box.Text)) continue; ErrorMessageBox("Tomt Fält", "Det finns 1 eller flera tomma fält"); return; } if (NewReferee.PasswordBox.Text != NewReferee.CheckPasswordBox.Text) { ErrorMessageBox("Fel lösenord", "Lösenorden stämmer inte överrens!"); return; } var referee = new Referee(NewReferee.FirstnameBox.Text, NewReferee.CountryBox.Text, NewReferee.PasswordBox.Text, NewReferee.UsernameBox.Text); admin.AddReferee(referee); MessageBox.Show( "Domare tillagd till databasen!", "Domare tillagd", MessageBoxButtons.OK); NewReferee.Close(); }
public void OnLoginButton(object source, MyEventArgs args) { try { ClientNetworkHandler.Connect(); var loginString = "LI;" + args.MyObject; var obj = ClientNetworkHandler.SendAndReceive(loginString); if (obj is Admin) { //var adminThread = new Thread(AdminForm.LoadForm); //adminThread.Start(); Login.Hide(); AdminForm.LoadForm(); } else if (obj is Referee) { //var refereeThread = new Thread(RefereeMenu.LoadForm); //refereeThread.Start(); LoggedInUser = (Referee)obj; Login.Hide(); RefereeMenu.LoadForm(); } else if (obj is string) { throw new FormatException((string)obj); } Login.Close(); } catch (FormatException formatException) { ErrorMessageBox("Inloggningsfel", formatException.Message); } }
private static void LoginValidationConsole() { while (true) { try { Console.Write("Login Name: "); var name = Console.ReadLine(); Console.Write("Password: "******"LI;{name};{password}"); // Checks which user through received object var tAdmin = obj as Admin; if (tAdmin != null) { UserAdmin = tAdmin; userState = UserState.Admin; Console.Clear(); Console.WriteLine("Welcome {0}! (Admin)", tAdmin.Name); return; } var tReferee = obj as Referee; if (tReferee != null) { UserReferee = tReferee; userState = UserState.Referee; Console.Clear(); Console.WriteLine("Welcome {0}! (Referee)", tReferee.Name); return; } if ((string)obj == "") { Console.WriteLine("Wrong usernamn or password!"); } } catch (SocketException socketException) { Console.WriteLine(socketException.Message); } catch (FormatException formatException) { Console.WriteLine(formatException.Message); } catch (NullReferenceException nullReference) { Console.WriteLine(nullReference.Message); Console.WriteLine("Wrong username or password!"); } } }
public static Referee CreateReferee() { Clear(); WriteLine("Enter referee details:"); var referee = new Referee(); Write("Name: "); referee.Name = ReadLine(); Write("Country: "); referee.Country = ReadLine(); Write("Username: "******"Password: "******"\n"); return referee; }
private static void DisplayAvailableCompetitions(Referee referee) { Clear(); WriteLine("---Available competitions---"); WriteLine("ID | Name | Location | Date | Type | Rounds "); AllCompetitions = (List<Competition>)ClientNetworkHandler.SendAndReceive($"GAC;{referee.Id}"); foreach (var competition in AllCompetitions) { WriteLine(competition.ToString()); }; }
public static List<Referee> GetAssignedRefereesByCompetition(int id) { Logger.Trace($"Entering method {MethodBase.GetCurrentMethod().Name}"); var sql = "SELECT * FROM referee WHERE id IN " + $"(SELECT referee FROM assignment WHERE Competition = {id})"; using (var sqlConnection = ConnectToDatabase()) { var tReferees = new List<Referee>(); using (var sqlQuery = new MySqlCommand(sql, sqlConnection)) { Logger.Info("Running Query: \"{0}\"", sql); var tableReader = sqlQuery.ExecuteReader(); while (tableReader.Read()) { var tReferee = new Referee( tableReader.GetInt32("ID"), tableReader.GetString("Name"), tableReader.GetString("Country")); tReferees.Add(tReferee); } } Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}"); return tReferees; } }
public static List<Referee> GetReferees() { Logger.Trace($"Entering method {MethodBase.GetCurrentMethod().Name}"); const string sql = "SELECT * FROM referee"; using (var sqlConnection = ConnectToDatabase()) { var refereeList = new List<Referee>(); using (var sqlQuery = new MySqlCommand(sql, sqlConnection)) { Logger.Info("Running Query: \"{0}\"", sql); var tableReader = sqlQuery.ExecuteReader(); while (tableReader.Read()) { var referee = new Referee( tableReader.GetInt32("Id"), tableReader.GetString("Name"), tableReader.GetString("Country"), tableReader.GetString("AccountType")); refereeList.Add(referee); } } Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}"); return refereeList; } }
public void AddReferee(Referee referee) { ListReferee.Add(referee); }