Exemplo n.º 1
0
        public static void RunAdmin(Admin admin)
        {
            var choice = AdminMenu();
            switch (choice)
            {
                case 1: //Create new competition
                    CreateCompetition();
                    AddReferees();
                    AddDiversToCompetition(TempCompetition.Rounds);
                    TempCompetition.SortDiveOrder();
                    admin.AddCompetition(TempCompetition);
                    break;

                case 2: // Add new diver to database
                    var diver = CreateDiver();
                    admin.AddDiver(diver);
                    break;

                case 3: // Add new referee to database
                    var referee = CreateReferee();
                    admin.AddReferee(referee);
                    break;

                case 4: // Show all competitions, choose one to start
                    DisplayCompetitions();
                    var id = ChooseCompetition();
                    if (id > 0)
                    {
                        admin.StartCompetition(id);
                        WriteLine($"Competition {id} has started!");
                    }
                    Thread.Sleep(1000);
                    Clear();
                    break;

                case 5:
                    WriteLine("Testsend");
                    ReadLine();
                    ClientNetworkHandler.SendToServer("SendJudge");
                    ReadLine();
                    break;

                case 0: // Logout user
                    ClientNetworkHandler.SendAndReceive("Logout");
                    LoginHandler.userState = LoginHandler.UserState.None;
                    // LoginHandler.LoginMenu();
                    break;

                default:
                    WriteLine("Try again!");
                    break;
            }
        }
Exemplo n.º 2
0
 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();
 }
Exemplo n.º 3
0
        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!");
                }
            }
        }
Exemplo n.º 4
0
        public void OnAddDiverToDatabase(object source, EventArgs args)
        {
            if (IsNullOrEmpty(AddDiver.nameBox.Text) ||
                IsNullOrEmpty(AddDiver.CountryBox.Text) ||
                IsNullOrEmpty(AddDiver.AgeBox.Text) ||
                IsNullOrEmpty(AddDiver.diverIDBox.Text))
            {
                ErrorMessageBox("Fyll i samtliga fält", "Vänligen fyll i alla fält");
                return;
            }
            var admin = new Admin();
            var genderChoice = "";
            if (AddDiver.radioMan.Checked)
                genderChoice = "M";
            else if (AddDiver.radioWoman.Checked)
                genderChoice = "F";

            var diver = new Diver(
                AddDiver.nameBox.Text, AddDiver.CountryBox.Text,
                int.Parse(AddDiver.AgeBox.Text), genderChoice,
                int.Parse(AddDiver.diverIDBox.Text));
            admin.AddDiver(diver);
            MessageBox.Show(
                "Hoppare tillagd till databasen!",
                "Hoppare tillagd", MessageBoxButtons.OK);
            AddDiver.Close();
        }
Exemplo n.º 5
0
        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);
            }
        }