예제 #1
0
        public void anyadirActor(actorEN actor)
        {
            DateTime fecha = DateTime.Parse(actor.FechaNac);

            try
            {
                paisCAD       p      = new paisCAD();
                int           nextId = 1;
                SqlConnection cn     = new SqlConnection(ConfigurationManager.ConnectionStrings["bbdd"].ToString());
                cn.Open();
                string     comando = "";
                SqlCommand cmd;
                comando  = "insert into Actores values (" + nextId + ", '";
                comando += actor.Nombre + "', '" + actor.Apellidos + "', '";
                comando += fecha + "', ";
                comando += p.mostrarIdPais(actor.Pais).IdPais + ")";
                cmd      = new SqlCommand(comando, cn);
                cmd.ExecuteNonQuery();

                cn.Close();
            }
            catch (Exception)
            {
                try
                {
                    paisCAD       p      = new paisCAD();
                    int           nextId = 1;
                    SqlConnection cn     = new SqlConnection(ConfigurationManager.ConnectionStrings["bbdd"].ToString());
                    cn.Open();
                    string     comando = "select max(Id_Actor) max from Actores";
                    SqlCommand cmd     = new SqlCommand(comando, cn);
                    var        reader  = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        nextId = (int)reader["max"] + 1;
                    }
                    reader.Close();
                    comando  = "insert into Actores values (" + nextId + ", '";
                    comando += actor.Nombre + "', '" + actor.Apellidos + "', '";
                    comando += fecha + "', ";
                    comando += p.mostrarIdPais(actor.Pais).IdPais + ")";
                    cmd      = new SqlCommand(comando, cn);
                    cmd.ExecuteNonQuery();

                    cn.Close();
                }catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
        }
        public void anyadirDirector(directorEN director)
        {
            try
            {
                paisCAD       p      = new paisCAD();
                int           nextId = 1;
                SqlConnection cn     = new SqlConnection(ConfigurationManager.ConnectionStrings["bbdd"].ToString());
                cn.Open();
                string     comando = "";
                SqlCommand cmd;
                comando  = "insert into Director values (" + nextId + ", '";
                comando += director.Nombre + "', '" + director.Apellidos + "', ";
                comando += p.mostrarIdPais(director.Nacionalidad).IdPais + ")";
                cmd      = new SqlCommand(comando, cn);
                cmd.ExecuteNonQuery();

                cn.Close();
            }
            catch (Exception)
            {
                try
                {
                    paisCAD       p      = new paisCAD();
                    int           nextId = 1;
                    SqlConnection cn     = new SqlConnection(ConfigurationManager.ConnectionStrings["bbdd"].ToString());
                    cn.Open();
                    string     comando = "select max(Id_Director) max from Director";
                    SqlCommand cmd     = new SqlCommand(comando, cn);
                    var        reader  = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        nextId = (int)reader["max"] + 1;
                    }
                    reader.Close();
                    comando  = "insert into Director values (" + nextId + ", '";
                    comando += director.Nombre + "', '" + director.Apellidos + "', ";
                    comando += p.mostrarIdPais(director.Nacionalidad).IdPais + ")";
                    cmd      = new SqlCommand(comando, cn);
                    cmd.ExecuteNonQuery();

                    cn.Close();
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
        }
 public void modificarDirector(directorEN director)
 {
     try
     {
         paisCAD       p  = new paisCAD();
         SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["bbdd"].ToString());
         cn.Open();
         string comando = "update Director set Nombre = '" + director.Nombre + "', ";
         comando += "Apellidos = '" + director.Apellidos + "', ";
         comando += "Nacionalidad= " + p.mostrarIdPais(director.Nacionalidad).IdPais + " where Id_Director = " + director.IdD;
         SqlCommand cmd = new SqlCommand(comando, cn);
         cmd = new SqlCommand(comando, cn);
         cmd.ExecuteNonQuery();
         cn.Close();
     }catch (Exception ex) {
         throw new Exception(ex.Message);
     }
 }
예제 #4
0
        public void modificarActor(actorEN actor)
        {
            paisCAD  p     = new paisCAD();
            DateTime fecha = DateTime.Parse(actor.FechaNac);

            try
            {
                SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["bbdd"].ToString());
                cn.Open();
                string comando = "update Actores set Nombre = '" + actor.Nombre + "', ";
                comando += "Apellidos = '" + actor.Apellidos + "', Fecha_Nac = '" + fecha + "', ";
                comando += "Nacionalidad= " + p.mostrarIdPais(actor.Pais).IdPais + " where Id_Actor = " + actor.IdAc;
                SqlCommand cmd = new SqlCommand(comando, cn);
                cmd = new SqlCommand(comando, cn);
                cmd.ExecuteNonQuery();
                cn.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }