internal void Save()
        {
            AtletaEntity atleta = this.DataContext as AtletaEntity;
            int          result = 0;

            if (CanSave())
            {
                if (atleta.AtletaId == -1)
                {
                    result = new AtletaService().Add(atleta);
                }
                else
                {
                    result = new AtletaService().Update(atleta);
                }

                if (result == 0)
                {
                    MessageBox.Show("Atleta Salvato!");
                }
                else
                {
                    MessageBox.Show("Errore duante il salvataggio!");
                }
            }
        }
        public static bool UpdateAngraficDataByAtleta(AtletaEntity a)
        {
            String commandText = "UPDATE Atleti " +
                                 "SET IdASD = " + a.IdAsd + ", Cognome = '" + a.Cognome + "', Nome = '" + a.Nome + "', Sesso = '" + a.Sesso + "', Email = '" + a.Email + "'" +
                                 "WHERE Id = " + a.IdAtleta;

            SqlConnection c = null;

            try
            {
                c = new SqlConnection(Helper.GetConnectionString());

                c.Open();

                SqlCommand command     = new SqlCommand(commandText, c);
                Int32      rowAffected = command.ExecuteNonQuery();

                if (rowAffected == 1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
            finally
            {
                c.Close();
            }
        }
예제 #3
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            String newName    = textBoxNewName.Text;
            String newSurname = textBoxNewSurname.Text;
            String sesso      = radioButtonMale.Checked ? "M" : "F";

            IdAsd = (int)comboBoxNewAssociation.SelectedValue;

            AtletaEntity a = new AtletaEntity()
            {
                IdAsd    = IdAsd,
                IdAtleta = IdAtleta,
                Nome     = newName,
                Cognome  = newSurname,
                Sesso    = sesso
            };

            if (SqlDal_Fighters.UpdateAngraficDataByAtleta(a))
            {
                MessageBox.Show("Anagrafica aggiornata correttamente", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Search(textBoxName.Text, textBoxSurname.Text);
            }
            else
            {
                MessageBox.Show("Anagrafica non aggiornata", "ERRORE", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public static List <AtletaEntity> GetAtletiTorneoVsDisciplinaAssoluti(int idTorneo, int idDisciplina)
        {
            List <AtletaEntity> atleti = new List <AtletaEntity>();

            AtletaEntity a;

            String sqlText = "select * from AtletiVsTorneoVsDiscipline atd, TorneoVsDiscipline td, atleti a, ASD, Ranking r " +
                             "where atd.IdTorneoVsDiscipline = td.Id " +
                             "and a.Id = atd.IdAtleta " +
                             "and asd.Id = a.IdASD " +
                             "and r.IdAtleta = a.Id " +
                             "and td.IdTorneo = " + idTorneo + " " +
                             "and td.IdDisciplina = " + idDisciplina + " " +
                             "and r.IdDisciplina = " + idDisciplina + " " +
                             "order by r.Punteggio DESC, ASD.Nome_ASD ASC, a.Cognome ASC";

            SqlConnection c = null;

            try
            {
                c = new SqlConnection(Helper.GetConnectionString());

                c.Open();

                SqlCommand    command = new SqlCommand(sqlText, c);
                SqlDataReader reader  = command.ExecuteReader();

                while (reader.Read())
                {
                    a = new AtletaEntity()
                    {
                        IdAsd    = Convert.ToInt32(reader["IdASD"]),
                        Asd      = Convert.ToString(reader["Nome_ASD"]),
                        Nome     = Convert.ToString(reader["Nome"]),
                        Cognome  = Convert.ToString(reader["Cognome"]),
                        IdAtleta = Convert.ToInt32(reader["IdAtleta"]),
                        Ranking  = Convert.ToDouble(reader["Punteggio"])
                    };

                    atleti.Add(a);
                }

                if (atleti.Count > 0)
                {
                    return(atleti);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                return(null);
            }
            finally
            {
                c.Close();
            }
        }
예제 #5
0
        public AtletaEntity getAtletaById(int atletaId)
        {
            AtletaEntity atleta = null;

            using (var db = new AtletiDbEntities())
            {
                atleta = db.Atleta.FirstOrDefault(x => x.AtletaId == atletaId).ToAtletaEntity();
            }

            return(atleta);
        }
예제 #6
0
 public int Delete(AtletaEntity atleta)
 {
     if (atleta != null)
     {
         using (var db = new AtletiDbEntities())
         {
             db.Atleta.Remove(db.Atleta.First(x => x.AtletaId == atleta.AtletaId));
             db.SaveChanges();
         }
         return(0);
     }
     return(-1);
 }
예제 #7
0
 public int Add(AtletaEntity atleta)
 {
     if (atleta != null)
     {
         using (var db = new AtletiDbEntities())
         {
             db.Atleta.Add(atleta.ToDbAtleta());
             db.SaveChanges();
         }
         return(0);
     }
     return(-1);
 }
        public static Int32 InsertNewAtleta(AtletaEntity a)
        {
            String commandText = "INSERT INTO Atleti VALUES (" +
                                 a.IdAsd + ",'" + a.Cognome + "','" + a.Nome + "','" + a.Sesso + "','" + a.Email + "'); " +
                                 "SELECT SCOPE_IDENTITY();";

            SqlConnection c = null;

            try
            {
                c = new SqlConnection(Helper.GetConnectionString());

                c.Open();

                SqlCommand    command = new SqlCommand(commandText, c);
                SqlDataReader reader  = command.ExecuteReader();

                Int32 idInserted = 0;
                reader.Read();

                idInserted = Convert.ToInt32(reader[0]);

                if (idInserted > 0)
                {
                    int rowAffected = InsertNewRanking(idInserted);
                    //insert in ranking storico
                    if (rowAffected >= 1)
                    {
                        return(idInserted);
                    }
                    else
                    {
                        return(-1);
                    }
                }
                else
                {
                    return(-1);
                }
            }
            catch (Exception ex)
            {
                return(-1);
            }
            finally
            {
                c.Close();
            }
        }
예제 #9
0
        public static Atleta ToDbAtleta(this AtletaEntity atletaEntity, Atleta atleta = null)
        {
            if (atleta == null)
            {
                atleta = new Atleta();
            }

            atleta.AtletaId           = atletaEntity.AtletaId;
            atleta.AtletaName         = atletaEntity.Name;
            atleta.AtletaSurname      = atletaEntity.Surname;
            atleta.AtletaBirthday     = atletaEntity.BirthDay;
            atleta.AtletaCFD          = atletaEntity.FiscalCode;
            atleta.AtletaNrCartellino = atletaEntity.NrCartellino;
            atleta.AtletaSex          = atletaEntity.Sex.ToString();

            return(atleta);
        }
예제 #10
0
        public static AtletaEntity GetAtletaById(int idAtleta)
        {
            AtletaEntity atleta = new AtletaEntity();

            String commandText = "select at.*, asd.Nome_ASD from atleti at join ASD asd on at.IdASD = asd.Id where at.Id = " + idAtleta;

            SqlConnection c = null;

            try
            {
                c = new SqlConnection(Helper.GetConnectionString());

                c.Open();

                SqlCommand    command = new SqlCommand(commandText, c);
                SqlDataReader reader  = command.ExecuteReader();

                while (reader.Read())
                {
                    atleta = new AtletaEntity()
                    {
                        IdAtleta = (int)reader["Id"],
                        IdAsd    = (int)reader["IdASD"],
                        Cognome  = Convert.ToString(reader["Cognome"]),
                        Nome     = Convert.ToString(reader["Nome"]),
                        Sesso    = Convert.ToString(reader["Sesso"]),
                        Asd      = Convert.ToString(reader["Nome_ASD"]),
                        Email    = Convert.ToString(reader["Email"])
                    };
                }
                return(atleta);
            }
            catch (Exception e)
            {
                return(null);
            }
            finally
            {
                c.Close();
            }
        }
예제 #11
0
        public int Update(AtletaEntity atleta)
        {
            int result = 0;

            if (atleta != null)
            {
                using (var db = new AtletiDbEntities())
                {
                    Atleta atletaDb = db.Atleta.FirstOrDefault(x => atleta.AtletaId == x.AtletaId);
                    if (atletaDb == null)
                    {
                        result = -1;
                    }
                    else
                    {
                        atletaDb = atleta.ToDbAtleta(atletaDb);
                        db.SaveChanges();
                    }
                }
            }
            return(result);
        }
예제 #12
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            AtletaEntity newAtleta;

            if (comboBoxAssociation.SelectedIndex < 0)
            {
                MessageBox.Show("Selezionare un'ASD", "Attenzione", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (textBoxSurname.Text == "")
            {
                MessageBox.Show("Inserire il Cognome", "Attenzione", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (textBoxName.Text == "")
            {
                MessageBox.Show("Selezionare il Nome", "Attenzione", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                newAtleta = new AtletaEntity()
                {
                    IdAsd   = (int)comboBoxAssociation.SelectedValue,
                    Nome    = textBoxName.Text,
                    Cognome = textBoxSurname.Text,
                    Sesso   = radioButtonMale.Checked ? "M" : "F"
                };
                int idInserted = SqlDal_Fighters.InsertNewAtleta(newAtleta);

                if (idInserted > 0)
                {
                    MessageBox.Show("Atleta inserito correttamente [ID = " + idInserted + "]", "Messaggio", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Atleta NON inserito.", "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private bool CanSave()
        {
            AtletaEntity atleta = this.DataContext as AtletaEntity;

            if (string.IsNullOrEmpty(atleta.FiscalCode))
            {
                MessageBox.Show("Inserisci il Codice Fiscale!");
                return(false);
            }

            if (string.IsNullOrEmpty(atleta.Name))
            {
                MessageBox.Show("Inserisci il Nome!");
                return(false);
            }

            if (string.IsNullOrEmpty(atleta.Surname))
            {
                MessageBox.Show("Inserisci il Cognome!");
                return(false);
            }

            return(true);
        }