public int authenticateAlias(ProductoEnt producto)
 {
     SqlConnection sqlConnection = new SqlConnection(ConexionDal.connectionString);
     SqlCommand sqlCommand = sqlConnection.CreateCommand();
     sqlCommand.CommandType = CommandType.Text;
     sqlCommand.CommandText = "Select Count(Id) From Producto Where Estado = 1 And Alias = @Alias And Id <> @Id";
     sqlCommand.Parameters.AddWithValue("@Alias", producto.ALIAS);
     sqlCommand.Parameters.AddWithValue("@Id", producto.ID);
     sqlConnection.Open();
     int exists = Convert.ToInt32(sqlCommand.ExecuteScalar());
     sqlConnection.Close();
     return exists;
 }
 public int authenticate(ProductoEnt producto)
 {
     SqlConnection sqlConnection = new SqlConnection(ConexionDal.connectionString);
     SqlCommand sqlCommand = sqlConnection.CreateCommand();
     sqlCommand.CommandType = CommandType.Text;
     sqlCommand.CommandText = "Select Count(Id) From Producto Where Estado = 1 And Nombre_Generico = @Nombre_Generico "
         + "And Marca = @Marca And Presentacion = @Presentacion And ISNULL(Sabor_U_Olor, '') = @Sabor_U_Olor "
         + "And Id <> @Id";
     sqlCommand.Parameters.AddWithValue("@Nombre_Generico", producto.NOMBRE_GENERICO);
     sqlCommand.Parameters.AddWithValue("@Marca", producto.MARCA);
     sqlCommand.Parameters.AddWithValue("@Presentacion", producto.PRESENTACION);
     sqlCommand.Parameters.AddWithValue("@Sabor_U_Olor", producto.SABOR_U_OLOR);
     sqlCommand.Parameters.AddWithValue("@Id", producto.ID);
     sqlConnection.Open();
     int exists = Convert.ToInt32(sqlCommand.ExecuteScalar());
     sqlConnection.Close();
     return exists;
 }
 public int add(ProductoEnt producto)
 {
     SqlConnection sqlConnection = new SqlConnection(ConexionDal.connectionString);
     SqlCommand sqlCommand = sqlConnection.CreateCommand();
     sqlCommand.CommandType = CommandType.StoredProcedure;
     sqlCommand.CommandText = "insertarProducto";
     sqlCommand.Parameters.AddWithValue("@Id_Proveedor", producto.ID_PROVEEDOR);
     sqlCommand.Parameters.AddWithValue("@Id_Grupo", producto.ID_GRUPO);
     sqlCommand.Parameters.AddWithValue("@Tipo_De_Codigo_De_Barras", producto.TIPO_DE_CODIGO_DE_BARRAS);
     sqlCommand.Parameters.AddWithValue("@Codigo_De_Barras", producto.CODIGO_DE_BARRAS);
     sqlCommand.Parameters.AddWithValue("@Nombre_Generico", producto.NOMBRE_GENERICO);
     sqlCommand.Parameters.AddWithValue("@Marca", producto.MARCA);
     sqlCommand.Parameters.AddWithValue("@Presentacion", producto.PRESENTACION);
     if (producto.SABOR_U_OLOR != "")
     {
         sqlCommand.Parameters.AddWithValue("@Sabor_U_Olor", producto.SABOR_U_OLOR);
     }
     else
     {
         sqlCommand.Parameters.AddWithValue("@Sabor_U_Olor", DBNull.Value);
     }
     sqlCommand.Parameters.AddWithValue("@Tipo", producto.TIPO);
     if (producto.CANTIDAD_MINIMA > 0)
     {
         sqlCommand.Parameters.AddWithValue("@Cantidad_Minima", producto.CANTIDAD_MINIMA);
     }
     else
     {
         sqlCommand.Parameters.AddWithValue("@Cantidad_Minima", DBNull.Value);
     }
     sqlCommand.Parameters.AddWithValue("@Precio_De_Compra", producto.PRECIO_DE_COMPRA);
     sqlCommand.Parameters.AddWithValue("@Precio_De_Venta", producto.PRECIO_DE_VENTA);
     sqlCommand.Parameters.AddWithValue("@Alias", producto.ALIAS);
     sqlConnection.Open();
     int id = Convert.ToInt32(sqlCommand.ExecuteScalar());
     sqlConnection.Close();
     return id;
 }
 public int getNumber(ProductoEnt producto)
 {
     SqlConnection sqlConnection = new SqlConnection(ConexionDal.connectionString);
     SqlCommand sqlCommand = sqlConnection.CreateCommand();
     sqlCommand.CommandType = CommandType.Text;
     sqlCommand.CommandText = "Select COUNT(Id) From Producto Where Estado = 1 "
         + "And Tipo_De_Codigo_De_Barras = @Tipo_De_Codigo_De_Barras";
     sqlCommand.Parameters.AddWithValue("@Tipo_De_Codigo_De_Barras", producto.TIPO_DE_CODIGO_DE_BARRAS);
     sqlConnection.Open();
     int number = Convert.ToInt32(sqlCommand.ExecuteScalar());
     sqlConnection.Close();
     return number;
 }
 public DataTable getByBarCode(ProductoEnt producto)
 {
     SqlConnection sqlConnection = new SqlConnection(ConexionDal.connectionString);
     SqlCommand sqlCommand = sqlConnection.CreateCommand();
     sqlCommand.CommandType = CommandType.Text;
     sqlCommand.CommandText = "Select Id, Alias, Tipo, Precio_De_Venta From buscarProductos() "
         + "Where Codigo_De_Barras = @Codigo_De_Barras";
     sqlCommand.Parameters.AddWithValue("@Codigo_De_Barras", producto.CODIGO_DE_BARRAS);
     SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
     DataTable dataTable = new DataTable("Producto");
     sqlDataAdapter.SelectCommand = sqlCommand;
     sqlDataAdapter.Fill(dataTable);
     return dataTable;
 }
 public int authenticateAlias(ProductoEnt producto)
 {
     return objetoProducto.authenticateAlias(producto);
 }
 private void searchProduct()
 {
     producto.CODIGO_DE_BARRAS = textBoxCodigoDeBarras.Text.Trim().ToUpper();
     DataTable dataTableProducto = objetoProducto.select(producto);
     if (dataTableProducto.Rows.Count > 0)
     {
         addProducto(dataTableProducto);
     }
     else
     {
         Producto.Nuevo formularioNuevoProducto = new Producto.Nuevo(2, producto.CODIGO_DE_BARRAS);
         formularioNuevoProducto.ShowDialog();
         producto = formularioNuevoProducto.producto;
         if (producto.ID != 0)
         {
             dataTableProducto = objetoProducto.select(producto);
             addProducto(dataTableProducto);
         }
     }
 }
 public void update(ProductoEnt producto)
 {
     SqlConnection sqlConnection = new SqlConnection(ConexionDal.connectionString);
     SqlCommand sqlCommand = sqlConnection.CreateCommand();
     sqlCommand.CommandType = CommandType.Text;
     sqlCommand.CommandText = "Update Producto Set Id_Proveedor = @Id_Proveedor, Id_Grupo = @Id_Grupo, "
         + "Tipo_De_Codigo_De_Barras = @Tipo_De_Codigo_De_Barras, Codigo_De_Barras = @Codigo_De_Barras, "
         + "Nombre_Generico = @Nombre_Generico, Marca = @Marca, Sabor_U_Olor = @Sabor_U_Olor, Tipo = @Tipo, "
         + "Cantidad_Minima = @Cantidad_Minima, Precio_De_Compra = @Precio_De_Compra, Precio_De_Venta = @Precio_De_Venta, "
         + "Alias = @Alias Where Id = @Id";
     sqlCommand.Parameters.AddWithValue("@Id_Proveedor", producto.ID_PROVEEDOR);
     sqlCommand.Parameters.AddWithValue("@Id_Grupo", producto.ID_GRUPO);
     sqlCommand.Parameters.AddWithValue("@Tipo_De_Codigo_De_Barras", producto.TIPO_DE_CODIGO_DE_BARRAS);
     sqlCommand.Parameters.AddWithValue("@Codigo_De_Barras", producto.CODIGO_DE_BARRAS);
     sqlCommand.Parameters.AddWithValue("@Nombre_Generico", producto.NOMBRE_GENERICO);
     sqlCommand.Parameters.AddWithValue("@Marca", producto.MARCA);
     sqlCommand.Parameters.AddWithValue("@Presentacion", producto.PRESENTACION);
     if (producto.SABOR_U_OLOR != "")
     {
         sqlCommand.Parameters.AddWithValue("@Sabor_U_Olor", producto.SABOR_U_OLOR);
     }
     else
     {
         sqlCommand.Parameters.AddWithValue("@Sabor_U_Olor", DBNull.Value);
     }
     sqlCommand.Parameters.AddWithValue("@Tipo", producto.TIPO);
     if (producto.CANTIDAD_MINIMA > 0)
     {
         sqlCommand.Parameters.AddWithValue("@Cantidad_Minima", producto.CANTIDAD_MINIMA);
     }
     else
     {
         sqlCommand.Parameters.AddWithValue("@Cantidad_Minima", DBNull.Value);
     }
     sqlCommand.Parameters.AddWithValue("@Precio_De_Compra", producto.PRECIO_DE_COMPRA);
     sqlCommand.Parameters.AddWithValue("@Precio_De_Venta", producto.PRECIO_DE_VENTA);
     sqlCommand.Parameters.AddWithValue("@Alias", producto.ALIAS);
     sqlCommand.Parameters.AddWithValue("@Id", producto.ID);
     sqlConnection.Open();
     sqlCommand.ExecuteNonQuery();
     sqlConnection.Close();
 }
 public DataTable select(ProductoEnt producto)
 {
     return objetoProducto.select(producto);
 }
 public DataTable search(ProductoEnt producto)
 {
     return objetoProducto.search(producto);
 }
 public int insert(ProductoEnt producto)
 {
     return objetoProducto.add(producto);
 }
 public int getNumber(ProductoEnt producto)
 {
     return objetoProducto.getNumber(producto);
 }
 public DataTable getByBarCode(ProductoEnt producto)
 {
     return objetoProducto.getByBarCode(producto);
 }
 public void delete(ProductoEnt producto)
 {
     objetoProducto.delete(producto);
 }
 public int authenticateCodigoDeBarras(ProductoEnt producto)
 {
     return objetoProducto.authenticateCodigoDeBarras(producto);
 }
 public DataTable search(ProductoEnt producto)
 {
     SqlConnection sqlConnection = new SqlConnection(ConexionDal.connectionString);
     SqlCommand sqlCommand = sqlConnection.CreateCommand();
     sqlCommand.CommandType = CommandType.Text;
     sqlCommand.CommandText = "Select Id_Proveedor, Id_Grupo, Tipo_De_Codigo_De_Barras, Codigo_De_Barras, Nombre_Generico, Marca, "
         + "Presentacion, Sabor_U_Olor, Tipo, Cantidad_Minima, Precio_De_Compra, Precio_De_Venta, Alias From Producto Where Estado = 1 "
         + "And Id = @Id";
     sqlCommand.Parameters.AddWithValue("@Id", producto.ID);
     SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
     DataTable dataTable = new DataTable("Producto");
     sqlDataAdapter.SelectCommand = sqlCommand;
     sqlDataAdapter.Fill(dataTable);
     return dataTable;
 }
 public DataTable select(ProductoEnt producto)
 {
     SqlConnection sqlConnection = new SqlConnection(ConexionDal.connectionString);
     SqlCommand sqlCommand = sqlConnection.CreateCommand();
     sqlCommand.CommandType = CommandType.Text;
     sqlCommand.CommandText = "Select Id, Codigo_De_Barras, Nombre_Generico, Marca, Presentacion, Sabor_U_Olor, "
         + "Precio_De_Compra, Precio_De_Venta From buscarProductos() Where Codigo_De_Barras = @Codigo_De_Barras";
     sqlCommand.Parameters.AddWithValue("@Codigo_De_Barras", producto.CODIGO_DE_BARRAS);
     SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
     DataTable dataTable = new DataTable("Producto");
     sqlDataAdapter.SelectCommand = sqlCommand;
     sqlDataAdapter.Fill(dataTable);
     return dataTable;
 }
 public void update(ProductoEnt producto)
 {
     objetoProducto.update(producto);
 }
 public void updatePrecios(ProductoEnt producto)
 {
     SqlConnection sqlConnection = new SqlConnection(ConexionDal.connectionString);
     SqlCommand sqlCommand = sqlConnection.CreateCommand();
     sqlCommand.CommandType = CommandType.Text;
     sqlCommand.CommandText = "Update Producto Set Precio_De_Compra = @Precio_De_Compra, Precio_De_Venta = @Precio_De_Venta "
         + "Where Id = @Id";
     sqlCommand.Parameters.AddWithValue("@Precio_De_Compra", producto.PRECIO_DE_COMPRA);
     sqlCommand.Parameters.AddWithValue("@Precio_De_Venta", producto.PRECIO_DE_VENTA);
     sqlCommand.Parameters.AddWithValue("@Id", producto.ID);
     sqlConnection.Open();
     sqlCommand.ExecuteNonQuery();
     sqlConnection.Close();
 }
 public DataTable search(ProveedorEnt proveedor, IngresoEnt ingreso, ProductoEnt producto)
 {
     return objetoIngreso.search(proveedor, ingreso, producto);
 }
 public DataTable search(ProveedorEnt proveedor, IngresoEnt ingreso, ProductoEnt producto)
 {
     string where = "";
     if (proveedor.NIT != "")
     {
         where = where + " And P.Nit Like '%" + proveedor.NIT + "%'";
     }
     if (proveedor.NOMBRE != "")
     {
         where = where + " And P.Nombre Like '%" + proveedor.NOMBRE + "%'";
     }
     if (ingreso.FECHA != "")
     {
         where = where + " And I.Fecha = '" + ingreso.FECHA + "'";
     }
     if (ingreso.NUMERO_DE_REGISTRO != 0)
     {
         where = where + " And I.Numero_De_Registro = '" + ingreso.NUMERO_DE_REGISTRO + "'";
     }
     if (ingreso.NUMERO_DE_NOTA_DE_ENTREGA != "")
     {
         where = where + " And I.Numero_De_Nota_De_Entrega Like '%" + ingreso.NUMERO_DE_NOTA_DE_ENTREGA + "%'";
     }
     if (ingreso.ESTADO != "")
     {
         where = where + " And I.Estado Like '%" + ingreso.ESTADO + "%'";
     }
     if (producto.CODIGO_DE_BARRAS != "")
     {
         where = where + " And Pr.Codigo_De_Barras = '" + producto.CODIGO_DE_BARRAS + "'";
     }
     SqlConnection sqlConnection = new SqlConnection(ConexionDal.connectionString);
     SqlCommand sqlCommand = sqlConnection.CreateCommand();
     sqlCommand.CommandType = CommandType.Text;
     sqlCommand.CommandText = "Select I.Id, P.Nit, P.Nombre As Proveedor, I.Fecha, I.Numero_De_Registro, I.Numero_De_Nota_De_Entrega, "
         + "I.Monto, I.Observaciones, I.Estado "
         + "From Proveedor P, Ingreso I, Producto Pr, Detalle_De_Ingreso DdI "
         + "Where P.Id = I.Id_Proveedor And P.Estado = 1 And I.Id = DdI.Id_Ingreso And I.Tipo = 'COMPRA' And Pr.Id = DdI.Id_Producto "
         + "And Pr.Estado = 1 And DdI.Estado in ('VIGENTE', 'ANULADO')" + where;
     SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
     sqlDataAdapter.SelectCommand = sqlCommand;
     DataTable dataTable = new DataTable("Ingreso");
     sqlDataAdapter.Fill(dataTable);
     return dataTable;
 }
 public void delete(ProductoEnt producto)
 {
     SqlConnection sqlConnection = new SqlConnection(ConexionDal.connectionString);
     SqlCommand sqlCommand = sqlConnection.CreateCommand();
     sqlCommand.CommandType = CommandType.Text;
     sqlCommand.CommandText = "Update Producto Set Estado = 0 Where Id = @Id";
     sqlCommand.Parameters.AddWithValue("@Id", producto.ID);
     sqlConnection.Open();
     sqlCommand.ExecuteNonQuery();
     sqlConnection.Close();
 }
 private void buttonGuardar_Click(object sender, EventArgs e)
 {
     if (validate())
     {
         ingreso.ID_PROVEEDOR = proveedor.ID;
         ingreso.NUMERO_DE_NOTA_DE_ENTREGA = textBoxNumeroDeNotaDeEntrega.Text.Trim().ToUpper();
         ingreso.MONTO = Convert.ToDecimal(calculateMonto());
         ingreso.OBSERVACIONES = textBoxObservaciones.Text.Trim().ToUpper();
         objetoIngreso.update(ingreso);
         foreach (DetalleDeIngresoEnt purchaseDetail in detalleDeIngresolist)
         {
             objetoDetalleDeIngreso.delete(purchaseDetail);
         }
         for (int rowIndex = 0; rowIndex < dataGridViewDetalleDeIngreso.Rows.Count; rowIndex++)
         {
             detalleDeIngreso = new DetalleDeIngresoEnt();
             detalleDeIngreso.ID = Convert.ToInt32(dataGridViewDetalleDeIngreso["Id", rowIndex].Value);
             detalleDeIngreso.ID_INGRESO = ingreso.ID;
             detalleDeIngreso.ID_PRODUCTO = Convert.ToInt32(dataGridViewDetalleDeIngreso["Id_Producto", rowIndex].Value);
             detalleDeIngreso.CANTIDAD = Convert.ToDecimal(dataGridViewDetalleDeIngreso["Cantidad", rowIndex].Value);
             detalleDeIngreso.PRECIO_DE_COMPRA = Convert.ToDecimal(dataGridViewDetalleDeIngreso["Precio_De_Compra", rowIndex].Value);
             detalleDeIngreso.MONTO_TOTAL = Convert.ToDecimal(dataGridViewDetalleDeIngreso["Monto_Total", rowIndex].Value);
             detalleDeIngreso.PORCENTAJE_DE_UTILIDAD =
                 Convert.ToDecimal(dataGridViewDetalleDeIngreso["Porcentaje_De_Utilidad", rowIndex].Value);
             detalleDeIngreso.PRECIO_DE_VENTA = Convert.ToDecimal(dataGridViewDetalleDeIngreso["Precio_De_Venta", rowIndex].Value);
             if (detalleDeIngreso.ID != 0)
             {
                 objetoDetalleDeIngreso.update(detalleDeIngreso);
             }
             else
             {
                 detalleDeIngreso.ID = objetoDetalleDeIngreso.add(detalleDeIngreso);
             }
             producto = new ProductoEnt();
             producto.ID = detalleDeIngreso.ID_PRODUCTO;
             producto.PRECIO_DE_COMPRA = detalleDeIngreso.PRECIO_DE_COMPRA;
             producto.PRECIO_DE_VENTA = detalleDeIngreso.PRECIO_DE_VENTA;
             objetoProducto.updatePrecios(producto);
         }
         MessageBox.Show("Los datos fueron guardados correctamente", "OperaciĆ³n Exitosa", MessageBoxButtons.OK,
             MessageBoxIcon.Information);
         this.Close();
     }
 }
 public void updatePrecios(ProductoEnt producto)
 {
     objetoProducto.updatePrecios(producto);
 }