Example #1
0
        private void LoadPlayer(Player player)
        {
            labelAge.Text     = player.Age.ToString();
            llbFirstName.Text = player.FirstName;
            llbLastName.Text  = player.LastName;

            labelSchool.Text = player.SchoolId.ToString();
            School school = DataBase.GetSchool(player.SchoolId);

            if (school != null)
            {
                labelSchool.Text = school.Name;
            }


            labelProvince.Text = player.DistrictId.ToString();
            District district = DataBase.GetDistrict(player.DistrictId);

            if (district != null)
            {
                labelProvince.Text = district.Name;
            }


            labelEducationZone.Text = player.EducationZoneId.ToString();
            EducationZone educationZone = DataBase.GetEducationZone(player.EducationZoneId);

            if (educationZone != null)
            {
                labelEducationZone.Text = educationZone.Name;
            }
        }
Example #2
0
        private void LoadPlayerToPLayerTab(Player player)
        {
            tbPlayerNumber.Text = player.Number;
            tbFirstName.Text    = player.FirstName;
            tbLastName.Text     = player.LastName;

            /*School school = DataBase.getSchoolById(player.SchoolId);
             * if (school != null)
             * {
             *  cbxSchool.SelectedText = school.Name;
             * }*/

            numericUpDownAge.Text   = player.Age.ToString();
            cbxGender.SelectedIndex = player.Sex;

            District district = DataBase.GetDistrict(player.DistrictId);

            if (district != null)
            {
                cbxDistrict.SelectedText = district.Name;
            }

            EducationZone zone = DataBase.GetEducationZone(player.EducationZoneId);

            if (zone != null)
            {
                comboBoxEducationZones.SelectedText = zone.Name;
            }
        }
Example #3
0
        public static EducationZone GetEducationZone(String educationZoneName)
        {
            string cache_key = "EDUCATION_ZONES_NAME_MAP";

            ObjectCache   cache        = MemoryCache.Default;
            EducationZone resEducation = null;

            Dictionary <String, EducationZone> educationZonesDictionary = cache[cache_key] as Dictionary <String, EducationZone>;

            if (educationZonesDictionary == null)
            {
                List <EducationZone> educationZoneList = LoadEducationZones();
                educationZonesDictionary = new Dictionary <String, EducationZone>();

                foreach (var zone in educationZoneList)
                {
                    String zoneName = zone.Name;

                    if (zoneName == educationZoneName)
                    {
                        resEducation = zone;
                    }

                    educationZonesDictionary.Add(zoneName, zone);
                }

                cache.Set(cache_key, educationZonesDictionary, DateTimeOffset.MaxValue);
                logger.Debug("Cached set EducationZone by name");
            }
            else
            {
                if (!educationZonesDictionary.TryGetValue(educationZoneName, out resEducation))
                {
                    logger.Debug("EducationZone by name not found in cache");
                }
                else
                {
                    logger.Debug("Cached used EducationZone by name");
                }
            }

            return(resEducation);
        }
Example #4
0
        private void btnPlayerEdit_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(tbPlayerNumber.Text.Trim()))
            {
                MessageBox.Show("Invalid player number", "Invalid number", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            if (!Int32.TryParse(numericUpDownAge.Text, out var age))
            {
                MessageBox.Show("Please enter a valid age", "Invalid Age", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (String.IsNullOrEmpty(tbFirstName.Text.Trim()) || String.IsNullOrEmpty(tbLastName.Text.Trim()))
            {
                MessageBox.Show("Please enter both first name and last name.", "Invalid Name", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (String.IsNullOrEmpty(cbxDistrict.Text.Trim()))
            {
                MessageBox.Show("Please choose a valid district.", "Invalid District", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (String.IsNullOrEmpty(comboBoxEducationZones.Text.Trim()))
            {
                MessageBox.Show("Please choose a valid education zone.", "Invalid Education Zone", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (!Util.ValidHumanSexString(cbxGender.Text.Trim()))
            {
                MessageBox.Show("Please choose a valid gender.", "Invalid Gender", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                long     districtId = 0;
                District district   = DataBase.GetDistrictByName(cbxDistrict.Text);
                if (district != null)
                {
                    districtId = district.Id;
                }

                long   schoolId = 0;
                School school   = DataBase.GetSchool(cbxSchool.Text);
                if (school != null)
                {
                    schoolId = school.Id;
                }

                long          educationZoneId = 0;
                EducationZone zone            = DataBase.GetEducationZone(comboBoxEducationZones.Text);
                if (zone != null)
                {
                    educationZoneId = zone.Id;
                }

                string searchString   = tbPlayerNumber.Text.Trim();
                Player searchMe       = new Player(searchString);
                Player searchByNumber = DataBase.FindPlayerByNumber(searchMe);
                if (searchByNumber != null)
                {
                    Player newPlayer = new Player(searchByNumber.Id, tbPlayerNumber.Text, tbFirstName.Text, tbLastName.Text, age,
                                                  (byte)Util.SexStringToEnum(cbxGender.Text), schoolId, districtId, educationZoneId);

                    if (PlayersTab.SavePlayer(newPlayer))
                    {
                        LoadPlayerList();
                        statusViewer.Update("Player update successful!", Status.SUCCESS);
                    }
                }
            }
        }
Example #5
0
        private void btnAddPlayer_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(tbPlayerNumber.Text.Trim()))
            {
                MessageBox.Show("Invalid player number", "Invalid number", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            if (!Int32.TryParse(numericUpDownAge.Text, out var age))
            {
                MessageBox.Show("Please enter a valid age", "Invalid Age", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (String.IsNullOrEmpty(tbFirstName.Text.Trim()) || String.IsNullOrEmpty(tbLastName.Text.Trim()))
            {
                MessageBox.Show("Please enter both first name and last name.", "Invalid Name", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (String.IsNullOrEmpty(cbxDistrict.Text.Trim()))
            {
                MessageBox.Show("Please choose a valid district.", "Invalid District", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (String.IsNullOrEmpty(comboBoxEducationZones.Text.Trim()))
            {
                MessageBox.Show("Please choose a valid education zone.", "Invalid Education Zone", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (!Util.ValidHumanSexString(cbxGender.Text.Trim()))
            {
                MessageBox.Show("Please choose a valid gender.", "Invalid Gender", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                long     districtId = 0;
                District district   = DataBase.GetDistrictByName(cbxDistrict.Text);
                if (district != null)
                {
                    districtId = district.Id;
                }

                long   schoolId = 0;
                School school   = DataBase.GetSchool(cbxSchool.Text);
                if (school != null)
                {
                    schoolId = school.Id;
                }

                long          educationZoneId = 0;
                EducationZone zone            = DataBase.GetEducationZone(comboBoxEducationZones.Text);
                if (zone != null)
                {
                    educationZoneId = zone.Id;
                }

                Player newPlayer = new Player(0, tbPlayerNumber.Text, tbFirstName.Text, tbLastName.Text, age,
                                              (byte)Util.SexStringToEnum(cbxGender.Text), schoolId, districtId, educationZoneId);

                var result = PlayersTab.AddPlayer(newPlayer);
                if (result.Item1)
                {
                    statusViewer.Update("Player saved sucecssfully...!", Status.INFO);
                    LoadPlayerList();

                    if (checkBoxAddtoanEvent.Checked)
                    {
                        Player existingPlayer = DataBase.FindPlayerByNumber(newPlayer);
                        LoadEventManagementTabPlayer(existingPlayer);
                        CleanupPlayerTabTextBoxes();
                    }
                }
            }
        }
Example #6
0
        private void tbFilterByPlayersNumber_TextChanged(object sender, EventArgs e)
        {
            CleanupFilterByPlayerTabLabels();

            List <Event> el = new List <Event>();

            bindingSourceFilteredEventsOnPlayers.DataSource = el;
            bindingSourceFilteredEventsOnPlayers.ResetBindings(false);
            lblFilterByPlayerNameOutput.Text = "Not found";

            var textbox = sender as TextBox;

            if (textbox != null)
            {
                String searchString = textbox.Text.Trim();

                if (searchString != Resources.DefaultSearchString)
                {
                    var playerList = DataBase.LoadPlayers();
                    var myRegex    = new Regex(@"^" + searchString + ".*$");
                    IEnumerable <Player> searchedPlayers = playerList.Where(player => myRegex.IsMatch(player.Number));

                    List <Player> players = searchedPlayers.ToList();
                    bindingSourcePlayers.DataSource = players;
                    bindingSourcePlayers.ResetBindings(false);

                    Player searchedPlayer = players.FirstOrDefault();

                    if (searchedPlayer != null)
                    {
                        Player searchMe       = new Player(searchString);
                        Player searchByNumber = DataBase.FindPlayerByNumber(searchMe);
                        if (searchByNumber != null)
                        {
                            lblFilterByPlayerNameOutput.Text = searchedPlayer.FullName();

                            District district = DataBase.GetDistrict(searchedPlayer.DistrictId);
                            if (district != null)
                            {
                                lblFilterByPlayerDistrictOutput.Text = district.Name;
                            }
                            else
                            {
                                lblFilterByPlayerDistrictOutput.Text = "UNKNOWN";
                            }

                            EducationZone zone = DataBase.GetEducationZone(searchedPlayer.EducationZoneId);
                            if (zone != null)
                            {
                                labelEducationZoneFBP.Text = zone.Name;
                            }
                            else
                            {
                                labelEducationZoneFBP.Text = "UNKNOWN";
                            }

                            School school = DataBase.GetSchool(searchedPlayer.SchoolId);
                            if (school != null)
                            {
                                lblFilterByPlayerSchoolOutput.Text = school.Name;
                            }
                            else
                            {
                                lblFilterByPlayerSchoolOutput.Text = "UNKNOWN";
                            }

                            PlayerEvent        searchPlayerEvents = new PlayerEvent(0, searchedPlayer.Id);
                            List <PlayerEvent> playerEventList    = DataBase.GetPlayerEventsByPlayer(searchPlayerEvents);
                            List <Event>       eventList          = DataBase.GetEventsForPlayerEvents(playerEventList);
                            bindingSourceFilteredEventsOnPlayers.DataSource = eventList;
                            bindingSourceFilteredEventsOnPlayers.ResetBindings(false);
                        }
                    }
                }
            }
        }