public List <MovimientoDetalleBe> Listar(int empresaId, int movimientoId, SqlConnection cn) { List <MovimientoDetalleBe> lista = null; using (SqlCommand cmd = new SqlCommand("web.usp_movimientodetalle_listar", cn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@empresaId", empresaId.GetNullable()); cmd.Parameters.AddWithValue("@movimientoId", movimientoId.GetNullable()); using (SqlDataReader dr = cmd.ExecuteReader()) { if (dr.HasRows) { lista = new List <MovimientoDetalleBe>(); while (dr.Read()) { MovimientoDetalleBe item = new MovimientoDetalleBe(); item.Fila = dr.GetData <int>("Fila"); item.EmpresaId = dr.GetData <int>("EmpresaId"); item.MovimientoId = dr.GetData <int>("MovimientoId"); item.MovimientoDetalleId = dr.GetData <int>("MovimientoDetalleId"); item.ProductoId = dr.GetData <int>("ProductoId"); item.Descripcion = dr.GetData <string>("Descripcion"); item.Cantidad = dr.GetData <decimal>("Cantidad"); item.PrecioUnitario = dr.GetData <decimal>("PrecioUnitario"); item.TotalImporte = dr.GetData <decimal>("TotalImporte"); lista.Add(item); } } } } return(lista); }
public bool Guardar(MovimientoDetalleBe registro, SqlConnection cn) { bool seGuardo = false; try { using (SqlCommand cmd = new SqlCommand("web.usp_movimientodetalle_guardar", cn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@EmpresaId", registro.EmpresaId.GetNullable()); cmd.Parameters.AddWithValue("@MovimientoId", registro.MovimientoId.GetNullable()); cmd.Parameters.AddWithValue("@MovimientoDetalleId", registro.MovimientoDetalleId.GetNullable()); cmd.Parameters.AddWithValue("@ProductoId", registro.ProductoId.GetNullable()); cmd.Parameters.AddWithValue("@Descripcion", registro.Descripcion.GetNullable()); cmd.Parameters.AddWithValue("@Cantidad", registro.Cantidad.GetNullable()); cmd.Parameters.AddWithValue("@PrecioUnitario", registro.PrecioUnitario.GetNullable()); cmd.Parameters.AddWithValue("@TotalImporte", registro.TotalImporte.GetNullable()); cmd.Parameters.AddWithValue("@FlagFechaVencimiento", registro.FlagFechaVencimiento.GetNullable()); cmd.Parameters.AddWithValue("@FechaVencimiento", registro.FechaVencimiento.GetNullable()); cmd.Parameters.AddWithValue("@usuario", registro.Usuario.GetNullable()); int filasAfectadas = cmd.ExecuteNonQuery(); seGuardo = filasAfectadas > 0; } } catch (Exception ex) { seGuardo = false; } return(seGuardo); }
public bool Eliminar(MovimientoDetalleBe registro, SqlConnection cn) { bool seGuardo = false; try { using (SqlCommand cmd = new SqlCommand("dbo.usp_movimientodetalle_eliminar", cn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@EmpresaId", registro.EmpresaId.GetNullable()); cmd.Parameters.AddWithValue("@MovimientoId", registro.MovimientoId.GetNullable()); cmd.Parameters.AddWithValue("@MovimientoDetalleId", registro.MovimientoDetalleId.GetNullable()); cmd.Parameters.AddWithValue("@usuario", registro.Usuario.GetNullable()); int filasAfectadas = cmd.ExecuteNonQuery(); seGuardo = filasAfectadas > 0; } } catch (Exception ex) { seGuardo = false; } return(seGuardo); }
public bool Guardar(MovimientoBe registro) { int? movimientoId = null; bool seGuardo = false; { try { using (TransactionScope scope = new TransactionScope()) { cn.Open(); seGuardo = movimientoDa.Guardar(registro, cn, out movimientoId); // Si seGuardo es True entonces if (seGuardo) { if (registro.ListaMovimientoDetalleEliminados != null) { foreach (int movimientoDetalleId in registro.ListaMovimientoDetalleEliminados) { MovimientoDetalleBe registroDetalleEliminar = new MovimientoDetalleBe(); registroDetalleEliminar.EmpresaId = registro.EmpresaId; registroDetalleEliminar.MovimientoId = (int)movimientoId; registroDetalleEliminar.MovimientoDetalleId = movimientoDetalleId; registroDetalleEliminar.Usuario = registro.Usuario; seGuardo = movimientoDetalleDa.Eliminar(registroDetalleEliminar, cn); if (!seGuardo) { break; } } } // Si la Lista de Detalle es diferente de Null if (registro.ListaMovimientoDetalle != null) { //Entonces recorro la misma Lista de detalle con el Item foreach (var item in registro.ListaMovimientoDetalle) { item.MovimientoId = (int)movimientoId; item.EmpresaId = registro.EmpresaId; item.Usuario = registro.Usuario; seGuardo = movimientoDetalleDa.Guardar(item, cn); //seGuardo = new if (!seGuardo) { break; } ProductoAlmacenBe paBe = new ProductoAlmacenBe(); paBe.EmpresaId = registro.EmpresaId; paBe.AlmacenId = registro.SedeAlmacenId; paBe.ProductoId = item.ProductoId; paBe.Monto = item.Cantidad; paBe.TipoMovimientoId = registro.TipoMovimientoId; paBe.Usuario = registro.Usuario; seGuardo = productoAlmacenDa.Guardar(paBe, cn); if (!seGuardo) { break; } } } } if (seGuardo) { scope.Complete(); } cn.Close(); } } catch (Exception ex) { seGuardo = false; } finally { if (cn.State == ConnectionState.Open) { cn.Close(); } } } return(seGuardo); }