public void ActualizarPelicula(MoviItems items)
 {
     try
     {
         comando = new SqlCommand();
         using (SqlConnection conexion = new SqlConnection(DbContext.StringConeccion))
         {
             comando.Connection  = conexion;
             comando.CommandText = "VerRegistros";
             comando.CommandType = CommandType.StoredProcedure;
             comando.Parameters.AddWithValue("@Tipo", "Update");
             comando.Parameters.AddWithValue("@id", items.Id);
             comando.Parameters.AddWithValue("@Titulo", items.Titulo);
             comando.Parameters.AddWithValue("@Genero", items.Genero);
             comando.Parameters.AddWithValue("@Precio", items.Precio);
             conexion.Open();
             int num = comando.ExecuteNonQuery();
             if (num > 0)
             {
                 string message = "La pelicula " + items.Titulo + " se actualizo con exito";
                 string caption = "Mensaje informativo!";
                 MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
        public void AgregarPelicula(MoviItems items)
        {
            try
            {
                comando = new SqlCommand();
                using (SqlConnection conexion = new SqlConnection(DbContext.StringConeccion))
                {
                    string condicion = string.Empty;
                    comando.Connection  = conexion;
                    comando.CommandText = "VerRegistros";
                    comando.CommandType = CommandType.StoredProcedure;
                    comando.Parameters.AddWithValue("@Tipo", "Insert");
                    comando.Parameters.AddWithValue("@Condicion", condicion);
                    comando.Parameters.AddWithValue("@Titulo", items.Titulo);
                    comando.Parameters.AddWithValue("@Genero", items.Genero);
                    comando.Parameters.AddWithValue("@Precio", items.Precio);
                    comando.Parameters.AddWithValue("@imagen", items.Imagen);
                    conexion.Open();
                    int num = comando.ExecuteNonQuery();

                    if (num > 0)
                    {
                        string message = "La pelicula " + items.Titulo + " se guardo con exito";
                        string caption = "Registra Guardado!";
                        MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#3
0
        //metodo de validación
        private void ValidarFormulario(MoviItems pelicula)
        {
            MoviItems peli = new MoviItems();

            ValidationContext       validationContext = new ValidationContext(pelicula, null, null);
            List <ValidationResult> errors            = new List <ValidationResult>();

            Boolean t = Validator.TryValidateObject(pelicula, validationContext, errors, true);

            if (errors.Count() > 0)
            {
                foreach (var error in errors)
                {
                    string campo = string.Empty;

                    if ("Titulo".Equals(error.MemberNames.FirstOrDefault()))
                    {
                        lbl_Titulo.Text      = error.ErrorMessage;
                        lbl_Titulo.ForeColor = Color.Red;
                    }
                    if ("Genero".Equals(error.MemberNames.FirstOrDefault()))
                    {
                        lbl_Genero.Text      = error.ErrorMessage;
                        lbl_Genero.ForeColor = Color.Red;
                    }
                }
                errors.Clear();
            }
            else
            {
                MessageBox.Show("Entidad Correcta");
            }
        }
示例#4
0
        private void TxtB_Genero_TextChanged(object sender, EventArgs e)
        {
            try
            {
                MoviItems pelicula;

                pelicula = new MoviItems
                {
                    Genero = txtB_Genero.Text
                };

                ValidationContext validationContext = new ValidationContext(pelicula, null, null)
                {
                    MemberName = "Genero"
                };
                List <ValidationResult> errors = new List <ValidationResult>();

                Boolean valor = Validator.TryValidateProperty(pelicula.Genero, validationContext, errors);

                if (errors.Count() > 0)
                {
                    foreach (var error in errors)
                    {
                        string campo = string.Empty;

                        if (valor == false)
                        {
                            lbl_Genero.Text      = error.ErrorMessage;
                            lbl_Genero.ForeColor = Color.Red;
                        }
                    }
                    errors.Clear();
                }
                else
                {
                    lbl_Genero.Text      = "*";
                    lbl_Genero.ForeColor = Color.Black;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#5
0
        private void Btn_Agregar_Click(object sender, EventArgs e)
        {
            MoviItems pelicula = new MoviItems();

            try
            {
                pelicula = new MoviItems
                {
                    Id           = Convert.ToInt16(lbl_Id.Text),
                    Titulo       = txtB_Titulo.Text,
                    FechaEmision = DateTime.Now,
                    Genero       = txtB_Genero.Text,
                    Precio       = Convert.ToInt16(txtB_Precio.Text),
                    Imagen       = ImageToByteArray(pbx_Imagen)
                };

                if (lbl_Id.Text == "0")
                {
                    controllers = new MoviItemsControllers();
                    controllers.AgregarPelicula(pelicula);
                    LimpiarCampos();
                    LlenerDataGrid(string.Empty);
                }
                else
                {
                    controllers = new MoviItemsControllers();
                    controllers.ActualizarPelicula(pelicula);
                    LimpiarCampos();
                    LlenerDataGrid(string.Empty);
                }
            }
            catch (Exception)
            {
                ValidarFormulario(pelicula);
            }
        }