Indicate that a record already exists in the database

0

I would like to know how I do to indicate within the code, that the product already exists in the database.

I explain: The form asks to enter an existing code, it is searched in BD, it is obtained and it shows the user a message that indicates the existing record.

Now what I want to know is: How to do the opposite of the previous instruction, that is, when the user writes a code that does not exist inside the BD, This send me a message indicating that the registration does not exist and that you can enter a new record.

This is what I have done and what works as I want:

But in the end it is where I want to place the instruction where it indicates that the code does not exist and that it can enter a new one.

 private void btn_buscarProducto_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(textBox8.Text))
        {
            MessageBox.Show("Ingrese Código de barra.", "¡Advertencia!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            return;
        }

        using (ProductosEF _bdVentas = new ProductosEF())
        {
            Producto _Producto = new Producto();
            var BuscarProducto = _bdVentas.BusquedaProductos(textBox8.Text.Trim()).ToList();

            if (BuscarProducto.Count() > 0)
            {
                MessageBox.Show("Este producto ya existe en la base de datos.", "¡ATENCIÓN!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
                txtcodei.Text = BuscarProducto.FirstOrDefault().codigo_interno;
                txtcodebar.Text = BuscarProducto.FirstOrDefault().codigo_barra;
                txtdescripcion.Text = BuscarProducto.FirstOrDefault().descripcion;
                txtmarca.Text = BuscarProducto.FirstOrDefault().marca;
                txttamaño.Text = BuscarProducto.FirstOrDefault().tamaño;
                txtcosto.Text = BuscarProducto.FirstOrDefault().costo.ToString();
                txtprecio.Text = BuscarProducto.FirstOrDefault().precio.ToString();
           }

        }
    
asked by Dave 20.02.2018 в 14:56
source

1 answer

1

Fixed: Add the line of Else , and the matter is fixed.

     else {  
MessageBox.Show("Este codigo no existe en la base de datos. ¿Desea ingresar uno nuevo?", "¡ATENCIÓN!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
          }
    
answered by 20.02.2018 / 15:31
source