Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (var entorno = new PracticaPistolaEntities())
            {
                entorno.Producto.Add(new Producto()
                {
                    CodBarra = txtCodBarra.Text,
                    Tipo     = txtTipo.Text,
                    Marca    = txtMarca.Text,
                    Precio   = Convert.ToInt32(txtPrecio.Text)
                });

                entorno.SaveChanges();

                if (entorno.SaveChanges() != 1)
                {
                    MessageBox.Show("Producto guardado exitosamente");
                }
                else
                {
                    MessageBox.Show("Error al guardar producto");
                }

                limpiar();
            }
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (PracticaPistolaEntities entorno = new PracticaPistolaEntities())
            {
                materia.Marca  = txtMarca.Text;
                materia.Tipo   = txtTipo.Text;
                materia.Precio = Convert.ToInt32(txtPrecio.Text);

                entorno.Entry(materia).State = System.Data.Entity.EntityState.Modified;
                entorno.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (PracticaPistolaEntities algo = new PracticaPistolaEntities())
            {
                var coso = algo.Producto.Where(x => x.CodBarra == txtCodigo.Text);

                foreach (Producto bar in coso)
                {
                    algo.Producto.Remove(bar);
                }
                algo.SaveChanges();
                eliminar();
                MessageBox.Show("Producto eliminado");
            }
        }
Ejemplo n.º 4
0
        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)
            {
                using (PracticaPistolaEntities entorno = new PracticaPistolaEntities())
                {
                    var cosa = entorno.Producto.Where(x => x.CodBarra == txtCodigo.Text).FirstOrDefault();

                    if (cosa != null)
                    {
                        txtMarca.Text = cosa.Marca;
                        txtTipo.Text  = cosa.Tipo;
                        MessageBox.Show("Producto encontrado");
                    }
                    else
                    {
                        MessageBox.Show("Producto no encontrado");
                        txtCodigo.Clear();
                    }
                }
            }
        }