}//fin mostrar //metodo buscar public DataTable Buscar(DProducto Producto) {//inicio buscar DataTable DtResultado = new DataTable("producto"); SqlConnection SqlCon = new SqlConnection(); try { SqlCon.ConnectionString = Conexion.Cn; SqlCommand SqlCmd = new SqlCommand(); SqlCmd.Connection = SqlCon; SqlCmd.CommandType = CommandType.StoredProcedure; SqlCmd.CommandText = "spbuscar_producto"; SqlParameter ParTextoBuscar = new SqlParameter(); ParTextoBuscar.ParameterName = "@textobuscar"; ParTextoBuscar.SqlDbType = SqlDbType.VarChar; ParTextoBuscar.Size = 255; ParTextoBuscar.Value = Producto.Textobuscar; SqlCmd.Parameters.Add(ParTextoBuscar); SqlDataAdapter SqlDat = new SqlDataAdapter(SqlCmd); SqlDat.Fill(DtResultado); } catch (Exception) { return(null); } return(DtResultado); }//fin metodo buscar
public void editar(DProducto producto) { try { con.ConnectionString = Conexion.cn; con.Open(); MySqlCommand cmd = con.CreateCommand(); cmd.CommandText = "UPDATE producto set nombre = @param1, concentracion = @param2, presentacion = @param3, fechavenc = @param4, lote = @param5, reg_invima = @param6, forma = @param7, idlaboratorio = @param8, idcategoria =@param10 where cod_producto = @param9"; cmd.Parameters.AddWithValue("@param1", producto.Nombre); cmd.Parameters.AddWithValue("@param2", producto.Concetracion); cmd.Parameters.AddWithValue("@param3", producto._Presentacion); cmd.Parameters.AddWithValue("@param4", producto._fechav); cmd.Parameters.AddWithValue("@param5", producto.Lote); cmd.Parameters.AddWithValue("@param6", producto.Invima); cmd.Parameters.AddWithValue("@param7", producto.forma); cmd.Parameters.AddWithValue("@param8", producto.idlab); cmd.Parameters.AddWithValue("@param9", producto._Idproducto); cmd.Parameters.AddWithValue("@param10", producto.idcat); cmd.ExecuteNonQuery(); } catch (Exception ex) { Console.Write(ex.ToString()); } }
}//fin editar //metodo eliminar public string Eliminar(DProducto Producto) {//inicio eliminar string rpta = ""; SqlConnection SqlCon = new SqlConnection(); try { //conexion SqlCon.ConnectionString = Conexion.Cn; SqlCon.Open(); //establecer el comando SqlCommand SqlCmd = new SqlCommand(); SqlCmd.Connection = SqlCon; SqlCmd.CommandText = "speliminar_producto"; SqlCmd.CommandType = CommandType.StoredProcedure; //parametros SqlParameter ParId_Producto = new SqlParameter(); ParId_Producto.ParameterName = "@id_producto"; ParId_Producto.SqlDbType = SqlDbType.Int; ParId_Producto.Value = Producto.Id_producto; SqlCmd.Parameters.Add(ParId_Producto); rpta = SqlCmd.ExecuteNonQuery() == 1 ? "OK" : "NO SE HA ELIMINADO EL REGISTRO"; } catch (Exception ex) { rpta = ex.Message + ex.StackTrace; } finally { if (SqlCon.State == ConnectionState.Open) { SqlCon.Close(); } } return(rpta); }//fin eliminar
}//fin insertar //metodo editar public string Editar(DProducto Producto) {//inicio editar string rpta = ""; SqlConnection SqlCon = new SqlConnection(); try { //conexion SqlCon.ConnectionString = Conexion.Cn; SqlCon.Open(); //establecer el comando SqlCommand SqlCmd = new SqlCommand(); SqlCmd.Connection = SqlCon; SqlCmd.CommandText = "speditar_producto"; SqlCmd.CommandType = CommandType.StoredProcedure; //parametros SqlParameter ParId_Producto = new SqlParameter(); ParId_Producto.ParameterName = "@id_producto"; ParId_Producto.SqlDbType = SqlDbType.Int; ParId_Producto.Value = Producto.Id_producto; SqlCmd.Parameters.Add(ParId_Producto); SqlParameter ParCodigo_Barra = new SqlParameter(); ParCodigo_Barra.ParameterName = "@codigo_barra"; ParCodigo_Barra.SqlDbType = SqlDbType.Int; ParCodigo_Barra.Value = Producto.Codigo_barra; SqlCmd.Parameters.Add(ParCodigo_Barra); SqlParameter ParDescripcion = new SqlParameter(); ParDescripcion.ParameterName = "@descripcion"; ParDescripcion.SqlDbType = SqlDbType.VarChar; ParDescripcion.Size = (255); ParDescripcion.Value = Producto.Descripcion; SqlCmd.Parameters.Add(ParDescripcion); SqlParameter ParPrecio_Venta = new SqlParameter(); ParPrecio_Venta.ParameterName = "@precio_venta"; ParPrecio_Venta.SqlDbType = SqlDbType.Decimal; ParPrecio_Venta.Value = Producto.Precio_venta; SqlCmd.Parameters.Add(ParPrecio_Venta); SqlParameter ParStock = new SqlParameter(); ParStock.ParameterName = "@stock"; ParStock.SqlDbType = SqlDbType.Int; ParStock.Value = Producto.Stock; SqlCmd.Parameters.Add(ParStock); SqlParameter ParStock_Minimo = new SqlParameter(); ParStock_Minimo.ParameterName = "@stock_minimo"; ParStock_Minimo.SqlDbType = SqlDbType.Int; ParStock_Minimo.Value = Producto.Stock_minimo; SqlCmd.Parameters.Add(ParStock_Minimo); SqlParameter ParVencimiento = new SqlParameter(); ParVencimiento.ParameterName = "@vencimiento"; ParVencimiento.SqlDbType = SqlDbType.DateTime; ParVencimiento.Value = Producto.Vencimiento; SqlCmd.Parameters.Add(ParVencimiento); SqlParameter ParId_Taller = new SqlParameter(); ParId_Taller.ParameterName = "@id_taller"; ParId_Taller.SqlDbType = SqlDbType.Int; ParId_Taller.Value = Producto.Id_taller; SqlCmd.Parameters.Add(ParId_Taller); SqlParameter ParId_Materia_Prima = new SqlParameter(); ParId_Materia_Prima.ParameterName = "@id_materia_prima"; ParId_Materia_Prima.SqlDbType = SqlDbType.Int; ParId_Materia_Prima.Value = Producto.Id_materia_prima; SqlCmd.Parameters.Add(ParId_Materia_Prima); //ejecutar el codigo rpta = SqlCmd.ExecuteNonQuery() == 1 ? "OK" : "HA FALLADO LA EDICION DEL REGISTRO"; } catch (Exception ex) { rpta = ex.Message + ex.StackTrace; } finally { if (SqlCon.State == ConnectionState.Open) { SqlCon.Close(); } } return(rpta); }//fin editar
public string Insertar(DProducto Producto) { string Rpta = ""; try { SqlCon.ConnectionString = Conexion.Cn; SqlCon.Open(); SqlCmd.Connection = SqlCon; SqlCmd.CommandText = "SPInsertar_Producto"; SqlCmd.CommandType = CommandType.StoredProcedure; SqlParameter parIdProducto = new SqlParameter(); parIdProducto.ParameterName = "@Id_Producto"; parIdProducto.SqlDbType = SqlDbType.Int; parIdProducto.Direction = ParameterDirection.Output; SqlCmd.Parameters.Add(parIdProducto); SqlParameter parNombre = new SqlParameter(); parNombre.ParameterName = "@Nombre"; parNombre.SqlDbType = SqlDbType.VarChar; parNombre.Size = 50; parNombre.Value = Producto.Nombre; SqlCmd.Parameters.Add(parNombre); SqlParameter parMarca = new SqlParameter(); parMarca.ParameterName = "@Marca"; parMarca.SqlDbType = SqlDbType.VarChar; parMarca.Size = 50; parMarca.Value = Producto.Marca; SqlCmd.Parameters.Add(parMarca); SqlParameter parIdCategoria = new SqlParameter(); parIdCategoria.ParameterName = "@Id_Categoria"; parIdCategoria.SqlDbType = SqlDbType.Int; parIdCategoria.Value = Producto.Id_Categoria; SqlCmd.Parameters.Add(parIdCategoria); SqlParameter parIdPresentacion = new SqlParameter(); parIdPresentacion.ParameterName = "@Id_Presentacion"; parIdPresentacion.SqlDbType = SqlDbType.Int; parIdPresentacion.Value = Producto.Id_Presentacion; SqlCmd.Parameters.Add(parIdPresentacion); SqlParameter parMedida = new SqlParameter(); parMedida.ParameterName = "@Medida"; parMedida.SqlDbType = SqlDbType.Int; parMedida.Value = Producto.Medida; SqlCmd.Parameters.Add(parMedida); Rpta = SqlCmd.ExecuteNonQuery() == 1 ? "Ok" : "No se guardo"; } catch (Exception ex) { Rpta = ex.Message; } finally { if (SqlCon.State == ConnectionState.Open) { SqlCon.Close(); } } return(Rpta); }
public string InsertarDetalle_Compuesto(DDetalleVenta DetalleVenta, ref SqlConnection sqlCon, ref SqlTransaction sqlTran, DProducto Producto) { string rpta = ""; try { //Comandos SqlCommand sqlCmd = new SqlCommand(); sqlCmd.Connection = sqlCon; sqlCmd.Transaction = sqlTran; sqlCmd.CommandText = "sp_insertarDetalleVenta"; sqlCmd.CommandType = CommandType.StoredProcedure; SqlParameter ParIdDetalleVenta = new SqlParameter(); ParIdDetalleVenta.ParameterName = "@idDetalleVenta"; ParIdDetalleVenta.SqlDbType = SqlDbType.Int; ParIdDetalleVenta.Direction = ParameterDirection.Output; sqlCmd.Parameters.Add(ParIdDetalleVenta); SqlParameter ParIdVenta = new SqlParameter(); ParIdVenta.ParameterName = "@idVenta"; ParIdVenta.SqlDbType = SqlDbType.Int; ParIdVenta.Value = DetalleVenta.IdVenta; sqlCmd.Parameters.Add(ParIdVenta); SqlParameter ParidProducto = new SqlParameter(); ParidProducto.ParameterName = "@idProducto"; ParidProducto.SqlDbType = SqlDbType.Int; ParidProducto.Value = DetalleVenta.IdProducto; sqlCmd.Parameters.Add(ParidProducto); SqlParameter ParCantidad = new SqlParameter(); ParCantidad.ParameterName = "@cantidad"; ParCantidad.SqlDbType = SqlDbType.Int; ParCantidad.Value = DetalleVenta.Cantidad; sqlCmd.Parameters.Add(ParCantidad); SqlParameter ParPrecioVenta = new SqlParameter(); ParPrecioVenta.ParameterName = "@precioVenta"; ParPrecioVenta.SqlDbType = SqlDbType.Decimal; ParPrecioVenta.Precision = 8; ParPrecioVenta.Scale = 2; ParPrecioVenta.Value = DetalleVenta.PrecioVenta; sqlCmd.Parameters.Add(ParPrecioVenta); SqlParameter ParDescuento = new SqlParameter(); ParDescuento.ParameterName = "@descuento"; ParDescuento.SqlDbType = SqlDbType.Decimal; ParDescuento.Precision = 8; ParDescuento.Scale = 2; ParDescuento.Value = DetalleVenta.Descuento; sqlCmd.Parameters.Add(ParDescuento); SqlParameter ParNota = new SqlParameter(); ParNota.ParameterName = "@nota"; ParNota.SqlDbType = SqlDbType.VarChar; ParNota.Size = 250; ParNota.Value = DetalleVenta.Nota; sqlCmd.Parameters.Add(ParNota); SqlParameter ParTipo = new SqlParameter(); ParTipo.ParameterName = "@tipo"; ParTipo.SqlDbType = SqlDbType.Char; ParCantidad.Value = "C"; sqlCmd.Parameters.Add(ParTipo); SqlParameter ParEstado = new SqlParameter(); ParEstado.ParameterName = "@estado"; ParEstado.SqlDbType = SqlDbType.VarChar; ParEstado.Size = 20; ParEstado.Value = DetalleVenta.Estado; sqlCmd.Parameters.Add(ParEstado); rpta = sqlCmd.ExecuteNonQuery() >= 1 ? "OK" : "No se ingresó el Registro"; if (rpta == "OK") { rpta = Producto.EditarStock(Producto); } if (rpta.Equals("OK")) { sqlTran.Commit(); } else { sqlTran.Rollback(); } //sqlCmd.ExecuteScalar(); } catch (Exception ex) { rpta = ex.Message; } return(rpta); }