Exemplo n.º 1
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();
                    }
                }
            }
        }