Beispiel #1
0
        /// <summary>
        /// Permite editar los datos de un elemento
        /// </summary>
        private void buttonEditar_Click(object sender, EventArgs e)
        {
            Button             buttonClicked = sender as Button;
            FormEditarElemento form          = new FormEditarElemento(connection);

            command = new MySqlCommand("Select nombre, descripcion, imagen from elementos where nombre=@nombre and nombre_col = @nombre_col and nombre_user = @nombre_user", connection);
            command.Parameters.AddWithValue("@nombre", buttonClicked.Name);
            command.Parameters.AddWithValue("@nombre_col", ColeccionActiva);
            command.Parameters.AddWithValue("@nombre_user", UsuarioActivo);

            connection.Open();

            reader = command.ExecuteReader();
            reader.Read();

            form.Nombre      = buttonClicked.Name;
            form.Descripcion = reader["descripcion"].ToString();

            if (reader["imagen"] != DBNull.Value)
            {
                form.ImgBytes = (byte[])reader["imagen"];
            }
            else
            {
                form.ImgBytes = null;
            }


            ControlElemento.Elemento elemento = (ControlElemento.Elemento)flowLayoutPanelElementos.Controls.Find(buttonClicked.Name, false).First();

            connection.Close();

            form.ShowDialog();

            if (form.DialogResult == DialogResult.OK && form.ImgBytes != null)
            {
                MemoryStream ms    = new MemoryStream(form.ImgBytes);
                Image        fondo = Image.FromStream(ms);

                elemento.BackgroundImage       = fondo;
                elemento.BackgroundImageLayout = ImageLayout.Zoom;
            }
        }
        /// <summary>
        /// Permite modificar el elemento mostrado
        /// </summary>
        private void buttonModificar_Click(object sender, EventArgs e)
        {
            FormEditarElemento form = new FormEditarElemento(connection);

            form.Nombre      = Text;
            form.Descripcion = richTextBoxDescripcion.Text;
            form.ImgBytes    = ImgBytes;

            form.ShowDialog();

            if (form.DialogResult == DialogResult.OK)
            {
                richTextBoxDescripcion.Text = form.Descripcion;
                if (form.ImgBytes != null)
                {
                    MemoryStream ms = new MemoryStream(form.ImgBytes);
                    pictureBoxCaratula.Image = Image.FromStream(ms);
                }
            }
        }