예제 #1
0
        /// <summary>
        /// Finds and stores the servers public ip-address.
        /// </summary>
        /// <returns>IPAddress</returns>
        private IPAddress GetPublicIP()
        {
            IPAddress ip = IPAddress.Parse("127.0.0.1");

            using (WebClient webClient = new WebClient())
            {
                try
                {
                    string text = webClient.DownloadString("http://checki.dyndns.org");

                    text = text.Substring(text.LastIndexOfAny(": ".ToCharArray()) + 1);

                    string ipAddr = text.Substring(0, text.IndexOf('<'));

                    ip = IPAddress.Parse(ipAddr);
                }
                catch (WebException)
                {
                    if (MessageBox.Show("Kan inte hitta din publika IP-adress. Tryck Ok för att skriva in den manuellt.") == DialogResult.OK)
                    {
                        string input = InputDialog.OpenDialog("Fyll i ditt ip");
                        if (input != "" && CheckDataInput.IpAddressCheckFormat(input))
                        {
                            ip = IPAddress.Parse(input);
                        }
                    }
                }
            }

            return(ip);
        }
        private void buttonConnectToIP_Click(object sender, EventArgs e)
        {
            string input = InputDialog.OpenDialog("Skriv in det ip du vill ansluta till");

            if (input != "" && CheckDataInput.IpAddressCheckFormat(input))
            {
                ConnectToIp(input);
            }

            else
            {
                MessageBox.Show("Inte en korrekt ip-adress!");
            }
        }
        /// <summary>
        /// Validates the input data about the new dive
        /// </summary>
        /// <returns></returns>
        private bool ValidateData()
        {
            bool isCodeValid = CheckDataInput.StringCheckFormat(View.TextBoxDiveCode.Text);

            bool isMultiplierValid = double.TryParse(View.TextBoxDiveMultiplier.Text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out double multiplier);


            if (!isCodeValid)
            {
                View.TextBoxDiveCode.BackColor = System.Drawing.Color.Red;
            }
            if (!isMultiplierValid)
            {
                View.TextBoxDiveMultiplier.BackColor = System.Drawing.Color.Red;
            }

            return(isCodeValid && isMultiplierValid);
        }
        /// <summary>
        /// Add a new subcontest to the contest
        /// </summary>
        private void AddSubContest()
        {
            bool isDataValid = false;

            if (CheckDataInput.StringCheckFormat(View.TextBoxName.Text))
            {
                if (SubContestContestants.Count != 0)
                {
                    isDataValid = true;
                }
                else
                {
                    MessageBox.Show("En deltävling behöver minst en deltagare.");
                }
            }
            else
            {
                MessageBox.Show("Tävlingsnamn ej korrekt. Får ej innehålla specialtecken, förutom _ och -");
            }

            if (isDataValid)
            {
                // Make a copy of the gathered SubContestants
                List <Contestant> list           = SubContestContestants.ToList();
                ContestantList    contestantList = new ContestantList();
                foreach (var c in list)
                {
                    contestantList.Add(c);
                }

                // Create the subcontest
                SubContestBranch subContestBranch = new SubContestBranch(View.TextBoxName.Text, CurrentContest, contestantList);

                SubContests.Add(subContestBranch);
                View.ListViewSubContests.Items.Add(subContestBranch.Name);

                // clear the inputs
                SubContestContestants.Clear();
                ClearInputs();
            }
        }
예제 #5
0
 /// <summary>
 /// Try to login
 /// </summary>
 private void Login()
 {
     if (CheckDataInput.EmailCheckFormat(this.tbUserName.Text))
     {
         if (TryCredentials())
         {
             DialogResult = DialogResult.OK;
             Close();
         }
         else
         {
             if (MessageBox.Show("Inlogg misslyckades, vill du försöka igen?", "", MessageBoxButtons.YesNo) != DialogResult.Yes)
             {
                 DialogResult = DialogResult.Cancel;
                 Close();
             }
         }
     }
     else
     {
         tbUserName.BackColor = Color.Red;
     }
 }
예제 #6
0
        public void GoToCreateSubContest()
        {
            // Kolla så att data är korrekt formatterat
            bool stringAreValid = false;

            if (CheckDataInput.StringCheckFormat(View.TextBoxName.Text))
            {
                if (CheckDataInput.StringCheckFormat(View.TextBoxCity.Text))
                {
                    if (CheckDataInput.StringCheckFormat(View.TextBoxArena.Text))
                    {
                        stringAreValid = true;
                    }
                    else
                    {
                        MessageBox.Show("Simhallsnamn är ej giltigt.");
                    }
                }
                else
                {
                    MessageBox.Show("Stadsnamn är ej giltigt.");
                }
            }
            else
            {
                MessageBox.Show("Tävlingsnamn är ej giltigt.");
            }

            bool areDatesSet = false;

            // The dates have DateTime.MinValue if they have not been set manually
            if (StartDate != DateTime.MinValue)
            {
                if (EndDate != DateTime.MinValue)
                {
                    areDatesSet = true;
                }
                else
                {
                    MessageBox.Show("Välj slutdatum.");
                }
            }
            else
            {
                MessageBox.Show("Välj startdatum.");
            }


            // check if any judges or contestans have been added to the contest
            bool areListsFilled = false;

            if (ContestJudgeList.Count > 2)
            {
                if (ContestContestantList.Count > 1)
                {
                    areListsFilled = true;
                }
                else
                {
                    MessageBox.Show("Måste minst vara 2 deltagare på en tävling.");
                }
            }
            else
            {
                MessageBox.Show("Måste minst vara 3 domare på en tävling.");
            }


            // if everything is okay, create the contest and move to subcontestview
            if (stringAreValid && areDatesSet && areListsFilled)
            {
                ContestInfo contestInfo = new ContestInfo(View.TextBoxName.Text, View.TextBoxCity.Text, StartDate, EndDate, View.TextBoxArena.Text);

                // Listorna byggs upp med hjälp av listboxarna.

                Contest contest = new Contest(contestInfo, ContestJudgeList, ContestContestantList);

                CreateSubContestView createSubContestView = new CreateSubContestView();

                CreateSubContestPresenter createSubContestPresenter = new CreateSubContestPresenter(createSubContestView, window, contest);

                window.ChangePanel(createSubContestView, View);
            }
        }