Example #1
0
        protected void DWPeliculas_Init(object sender, EventArgs e)
        {
            try
            {
                int id;
                int.TryParse(Request.QueryString["id"], out id); //Recuperamos id del actor
                actor              = new actorEN(id, "");        //Cargamos id del actor en el EN
                actor              = actor.mostrarActor();       //Cargamos los datos del actor
                NombreText.Text    = actor.Nombre;
                ApellidosText.Text = actor.Apellidos;
                fechaNac.Text      = actor.FechaNac.Substring(0, 10);
                paisEN p = new paisEN(actor.Pais);
                nombrePais.Text = p.mostrarIdPais().Pais;

                List <peliculaEN> peliculas = actor.mostrarPeliculasActor();
                List <string>     nombres   = new List <string>();
                for (int i = 0; i < peliculas.Count; i++)//Guardamos nombres en la lista desplegable
                {
                    nombres.Add(peliculas[i].NombreP);
                    listaID.Add(peliculas[i].IdP);//Asociamos id a cada nombre de la lista
                }
                DWPeliculas.DataSource = nombres;
                DWPeliculas.DataBind();
                DWPeliculas.Items.Insert(0, new ListItem("[Seleccionar]", "0"));
            }catch (Exception ex)
            {
                Response.Redirect("../Pagina_Error.aspx?err=" + ex.Message);
            }
        }
        public actorEN mostrarActor(int id)
        {
            paisCAD       pais = new paisCAD();
            actorEN       act  = new actorEN();
            SqlConnection cn   = new SqlConnection(ConfigurationManager.ConnectionStrings["bbdd"].ToString());

            cn.Open();
            string comando = "";

            comando = "select * from Actores where Id_Actor = " + id + "Order by Apellidos, Nombre";

            SqlCommand cmd    = new SqlCommand(comando, cn);
            var        reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                act.IdAc      = (int)reader["Id_Actor"];
                act.Nombre    = reader["Nombre"].ToString();
                act.Apellidos = reader["Apellidos"].ToString();
                act.FechaNac  = reader["Fecha_Nac"].ToString();
                act.Pais      = pais.mostrarPais((int)reader["Nacionalidad"]).Pais;
            }
            reader.Close();
            cn.Close();

            return(act);
        }
        public List <actorEN> mostrarListaActores(actorEN actor)
        {
            paisCAD        pais  = new paisCAD();
            List <actorEN> lista = new List <actorEN>();
            SqlConnection  cn    = new SqlConnection(ConfigurationManager.ConnectionStrings["bbdd"].ToString());

            cn.Open();
            string comando = "";

            if (actor.Nombre == "%")
            {
                comando = "select * from Actores Order by Apellidos, Nombre";
            }
            else
            {
                comando = "select distinct * from Actores where Nombre like '%" + actor.Nombre + "%' or Apellidos like '%" + actor.Nombre + "%' Order by Apellidos, Nombre";
            }
            SqlCommand cmd    = new SqlCommand(comando, cn);
            var        reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                actorEN act = new actorEN();
                act.IdAc      = (int)reader["Id_Actor"];
                act.Nombre    = reader["Nombre"].ToString();
                act.Apellidos = reader["Apellidos"].ToString();
                act.FechaNac  = reader["Fecha_Nac"].ToString();
                act.Pais      = pais.mostrarPais((int)reader["Nacionalidad"]).Pais;
                lista.Add(act);
            }
            reader.Close();
            cn.Close();

            return(lista);
        }
        protected void Btn_Modificar_Click(object sender, EventArgs e)
        {
            if (DWActor.Items.Count == 1)
            {
                Btn_Modificar1.Visible = false;
                ErrM.ForeColor         = Color.Red;
                ErrM.Visible           = true;
                ErrM.Text = "No quedan actores";
            }
            else
            {
                if (DWActor.SelectedItem.ToString() != "[Seleccionar]" && DWPais.SelectedItem.ToString() != "[Seleccionar]")
                {
                    if (TextBox1.Text != "" && TextBox2.Text != "")
                    {
                        try
                        {
                            string fecha = DWdia.SelectedItem.ToString() + "-" + DWmes.SelectedItem.ToString() + "-" + DWaño.SelectedItem.ToString();
                            actor = new actorEN(-1, TextBox1.Text, TextBox2.Text, fecha, DWPais.SelectedItem.ToString());
                            bool stop = false;
                            for (int i = 0; i < listaA.Count && !stop; i++)
                            {
                                if (listaA[i].Nombre + " " + listaA[i].Apellidos == DWActor.SelectedItem.ToString())
                                {
                                    actor.IdAc = listaA[i].IdAc;
                                    stop       = true;
                                }
                            }
                            actor.modificarActor();
                            ErrM.ForeColor = Color.Green;
                            ErrM.Visible   = true;
                            ErrM.Text      = "MODIFICADO CORRECTAMENTE";


                            DWActor_Init(sender, e);
                        }
                        catch (Exception ex)
                        {
                            ErrM.ForeColor = Color.Red;
                            ErrM.Visible   = true;
                            ErrM.Text      = ex.Message;
                        }
                    }
                    else
                    {
                        ErrM.ForeColor = Color.Red;
                        ErrM.Visible   = true;
                        ErrM.Text      = "*Quedan campos vacíos";
                    }
                }
            }
        }
        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);
                }
            }
        }
        protected void Button_Actor(object sender, EventArgs e)
        {
            if (ActorBox.Text != "")
            {
                listaID.Clear();
                actorEN       actor        = new actorEN(-1, ActorBox.Text);
                List <string> ListaNombres = new List <string>();
                DWActor.Visible    = true;
                Btn_Actor2.Visible = true;
                List <actorEN> d = actor.listaActores();
                for (int i = 0; i < d.Count; i++)
                {
                    ListaNombres.Add(d[i].Nombre + " " + d[i].Apellidos);
                    listaID.Add(d[i].IdAc);
                }

                DWActor.DataSource = ListaNombres;
                DWActor.DataBind();
                DWActor.Items.Insert(0, new ListItem("[Seleccionar]", "0"));
                if (DWActor.Items.Count == 1)
                {
                    ErrActor.Visible   = true;
                    ErrActor.Text      = "*Búsqueda vacía. Introduzca el carácter '%' para ver todos los actores";
                    DWActor.Visible    = false;
                    Btn_Actor2.Visible = false;
                }
                else
                {
                    ErrActor.Visible = false;
                }
            }
            else
            {
                ErrActor.Visible = true;
                ErrActor.Text    = "*Campo vacío";
            }

            ErrSerie.Visible           = false;
            ErrPelicula.Visible        = false;
            ErrDistribuidora.Visible   = false;
            ErrDirector.Visible        = false;
            DWDistribuidora.Visible    = false;
            DWPeliculas.Visible        = false;
            DWSeries.Visible           = false;
            DWDirector.Visible         = false;
            Btn_Distribuidora2.Visible = false;
            Btn_Pelicula2.Visible      = false;
            Btn_Serie2.Visible         = false;
            Btn_Director2.Visible      = false;
        }
Example #7
0
 protected void Btn_Añadir_Click(object sender, EventArgs e)
 {
     if (TextBox1.Text != "" && TextBox2.Text != "")
     {
         if (DWPais.SelectedItem.ToString() != "[Seleccionar]")
         {
             try
             {
                 string  fecha = DWdia.SelectedItem.ToString() + "-" + DWmes.SelectedItem.ToString() + "-" + DWaño.SelectedItem.ToString();
                 actorEN actor = new actorEN(-1, TextBox1.Text, TextBox2.Text, fecha, DWPais.SelectedItem.ToString());
                 actor.anyadirActor();
                 Err1.Text      = "AÑADIDO CORRECTAMENTE";
                 Err1.Visible   = true;
                 Err1.ForeColor = Color.Green;
             }
             catch (Exception ex)
             {
                 Err1.ForeColor = Color.Red;
                 Err1.Text      = ex.Message;
                 Err1.Visible   = true;
             }
         }
     }
     else if (TextBox1.Text == "" && TextBox2.Text != "")
     {
         Err.Visible   = true;
         Err.ForeColor = Color.Red;
         Err.Text      = "*Campo vacío";
     }
     else if (TextBox1.Text != "" && TextBox2.Text == "")
     {
         Err0.Visible   = true;
         Err0.ForeColor = Color.Red;
         Err0.Text      = "*Campo vacío";
     }
     else
     {
         Err.Visible    = true;
         Err.ForeColor  = Color.Red;
         Err.Text       = "*Campo vacío";
         Err0.Visible   = true;
         Err0.ForeColor = Color.Red;
         Err0.Text      = "*Campo vacío";
     }
 }
        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);
            }
        }
 public bool existe(actorEN actor)
 {
     return(false);
 }