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