示例#1
0
        /// <summary>
        /// add a contestant from the DB to the contest
        /// </summary>
        public void AddContestantToContest()
        {
            try
            {
                var contestantFirstName = View.ListViewGlobalContestants.SelectedItems[0].SubItems[0].Text;
                var contestantLastName  = View.ListViewGlobalContestants.SelectedItems[0].SubItems[1].Text;

                bool isAdded = false;

                foreach (var c in ContestContestantList)
                {
                    if (String.Equals(c.FirstName, contestantFirstName) && String.Equals(c.LastName, contestantLastName))
                    {
                        isAdded = true;
                        MessageBox.Show("Deltagare är redan tillagd!");
                        break;
                    }
                }

                Contestant contestantToBeAdded = null;

                if (!isAdded)
                {
                    foreach (var c in GlobalContestantList)
                    {
                        if (String.Equals(c.FirstName, contestantFirstName) && String.Equals(c.LastName, contestantLastName))
                        {
                            contestantToBeAdded = c;
                        }
                    }

                    if (contestantToBeAdded != null)
                    {
                        ContestContestantList.Add(contestantToBeAdded);
                    }
                }
                UpdateListViews();
            }
            catch (ArgumentOutOfRangeException)
            {
                MessageBox.Show("Välj en deltagare!");
            }
        }
示例#2
0
        /// <summary>
        /// Updates a existing dive with new information
        /// </summary>
        private void ModifyDive()
        {
            SubContestBranch subContestBranch = GetSelectedSubContest();

            Contestant contestant = GetSelectedContestant();

            Dive dive = GetSelectedDive();

            AddDiveView modifyView = new AddDiveView();

            AddDivePresenter presenter = new AddDivePresenter(modifyView, window, subContestBranch, contestant, dive);

            if (subContestBranch != null && contestant != null && dive != null)
            {
                if (modifyView.ShowDialog() == DialogResult.OK)
                {
                    subContestBranch.RemoveExistingDive(contestant, dive);

                    UpdateDivesListView();
                }
            }
        }
示例#3
0
        /// <summary>
        /// Get the selected Dive in ListViewDives
        /// </summary>
        /// <returns>Dive object or null if nothing is chosen</returns>
        private Dive GetSelectedDive()
        {
            if (View.ListViewDives.SelectedIndices.Count != 0)
            {
                var selectedDiveIndex = View.ListViewDives.SelectedIndices[0];

                int i = 0;

                Contestant contestant = GetSelectedContestant();

                if (contestant != null)
                {
                    foreach (var diveList in contestant.DiveLists)
                    {
                        SubContestBranch subContest = GetSelectedSubContest();

                        if (subContest != null)
                        {
                            if (diveList.SubContestBranch == subContest)
                            {
                                foreach (var dive in diveList)
                                {
                                    if (i++ == selectedDiveIndex)
                                    {
                                        return(dive);
                                    }
                                }
                            }
                        }
                    }
                }
            }


            return(null);
        }
        public ContestantList FetchContestants()
        {
            DataTable contestantDataTable = FetchSpecifiedRole("contestant");

            // Iterate through data table and add too person list
            ContestantList contestantList = new ContestantList();

            foreach (DataRow row in contestantDataTable.Rows)
            {
                Contestant contestant = new Contestant
                {
                    ID        = Int32.Parse(row["id"].ToString()),
                    FirstName = row["firstName"].ToString(),
                    LastName  = row["lastName"].ToString(),
                    Age       = Int32.Parse(row["age"].ToString()),
                    Gender    = row["gender"].ToString(),
                    Email     = row["email"].ToString()
                };

                contestantList.Add(contestant);
            }

            return(contestantList);
        }
        public AddDivePresenter(AddDiveView view, ProjectMainWindow window, SubContestBranch subContest, Contestant contestant, Dive dive = null)
        {
            this.View         = view;
            this.window       = window;
            this.SubContest   = subContest;
            CurrentContestant = contestant;

            if (dive != null)
            {
                View.TextBoxDiveCode.Text       = dive.Code.Code;
                View.TextBoxDiveMultiplier.Text = dive.Code.Multiplier.ToString();
            }

            View.EventAddDive += AddDiveToContestant;
        }