public Retorno SelecionarLoteOfertado(int loteId) { if (Identificacao.Tipo != (int)ETipoUsuario.Frigorifico) { return(Falha(ETipoFalha.NaoPermitido)); } var lote = _contexto.Lotes.FirstOrDefault(x => x.Id == loteId); if (lote == null) { return(Falha(ETipoFalha.RegistroNaoEncontrado)); } if (lote.Status != (int)EStatusLote.Ofertado) { return(Falha("Este lote não pode ser selecionado.")); } lote.Status = (int)EStatusLote.SelecionadoParaCompra; var loteEtapa = new LoteEtapa() { LoteId = lote.Id, Status = (int)EStatusLote.SelecionadoParaCompra, UsuarioId = Identificacao.Id, DataHora = DateTime.Now }; this.Update <Lote>(lote); this.Insert <LoteEtapa>(loteEtapa); this.Save(); return(new Sucesso("Lote selecionado com sucesso.")); }
private void BtnGuardar_Click(object sender, EventArgs e) { LoteEtapa etapa = CurrentLote[CurrentLote.Count - 1]; foreach (GastosMaterial g in lst) { if (g.IdGastoMaterial == 0) { ctrlEtapas.AgregarGastoDeMaterial(etapa, g); } } Limpiar(); }
public List <GastosMaterial> CargarGastosMaterial(LoteEtapa e) { SqlCommand cmd = null; SqlConnection connection = null; SqlDataReader reader = null; try { connection = GetConnection(); connection.Open(); cmd = connection.CreateCommand(); cmd.CommandText = "SELECT * FROM [Produccion].[GastosMaterial] WHERE LoteEtapa = @LoteEtapa"; cmd.Parameters.AddWithValue("@LoteEtapa", e.IdLoteEtapa); reader = cmd.ExecuteReader(); while (reader.Read()) { GastosMaterial g = new GastosMaterial(); g.Cantidad = (double)(decimal)reader["Cantidad"]; g.IdGastoMaterial = (int)reader["IdGastoMaterial"]; g.Material = new Controlador.Produccion.ControladorMaterial().GetById((int)reader["Material"]); g.Observacion = (string)reader["Observacion"]; g.Tipo = (GastosMaterial.TiposGasto)reader["Tipo"]; e.GastosMateriales.Add(g); } return(e.GastosMateriales); } catch (Exception ex) { throw; } finally { if (connection != null) { connection.Close(); connection.Dispose(); } } }
public void AgregarGastoDeMaterial(LoteEtapa e, GastosMaterial g) { SqlConnection connection = null; SqlCommand cmd = null; try { connection = GetConnection(); connection.Open(); cmd = connection.CreateCommand(); cmd.CommandText = "UPDATE [Produccion].[Materiales] SET Existencia = Existencia - @Cantidad WHERE IdMaterial = @Material" + "" + Environment.NewLine + "INSERT INTO [Produccion].[GastosMaterial] VALUES (" + "@Material," + "@LoteEtapa," + "@Cantidad," + "@Tipo," + "@Observacion" + ")" + Environment.NewLine + "SELECT CAST(SCOPE_IDENTITY() as int)"; cmd.Parameters.AddWithValue("@Material", g.Material.IdMaterial); cmd.Parameters.AddWithValue("@LoteEtapa", e.IdLoteEtapa); cmd.Parameters.AddWithValue("@Cantidad", g.Cantidad); cmd.Parameters.AddWithValue("@Tipo", g.Tipo); cmd.Parameters.AddWithValue("@Observacion", g.Observacion); int id = (int)cmd.ExecuteScalar(); g.IdGastoMaterial = id; } catch (Exception ex) { throw ex; } finally { if (connection != null) { connection.Close(); connection.Dispose(); } } }
public LoteProduccion GetById(int id) { SqlConnection connection = null; SqlCommand cmd = null; SqlDataReader reader = null; LoteProduccion l = null; try { connection = GetConnection(); connection.Open(); cmd = connection.CreateCommand(); cmd.CommandText = "SELECT * FROM [Produccion].[LotesProduccion] WHERE idLoteProduccion = @idLote"; cmd.Parameters.AddWithValue("@idLote", id); reader = cmd.ExecuteReader(); if (reader.Read()) { l = new LoteProduccion() { IdLoteProduccion = (int)reader["IdLoteProduccion"] }; int idDetalle = (int)reader["DetalleAsociado"]; l.DetalleAsociado = new Ventas.ControladorDetallePedido().GetById(idDetalle); } else { return(null); } reader.Close(); cmd.CommandText = "SELECT * FROM [Produccion].[LotesEtapas] WHERE Lote = @idLote"; reader = cmd.ExecuteReader(); while (reader.Read()) { Modelo.Produccion.LoteEtapa e = new LoteEtapa(); e.IdLoteEtapa = (int)reader["IdLoteEtapa"]; e.AutorizadoPor = reader["AutorizadoPor"] == DBNull.Value ? null : new Controlador.Usuarios.ControladorUsuario().GetById((int)reader["AutorizadoPor"]); e.OrdenadoPor = reader["OrdenadoPor"] == DBNull.Value ? null : new Controlador.Usuarios.ControladorUsuario().GetById((int)reader["OrdenadoPor"]); e.FechaAutorizacion = reader["FechaAutorizacion"] == DBNull.Value ? DateTime.Today : (DateTime)reader["FechaAutorizacion"]; e.FechaOrdemamiento = (DateTime)reader["FechaOrdenamiento"]; e.Etapa = (LoteEtapa.EtapasProduccion)reader["Etapa"]; e.GastosMateriales = new Controlador.Produccion.ControladorLoteEtapa().CargarGastosMaterial(e); l.Add(e); } return(l); } catch (Exception ex) { throw ex; } finally { if (connection != null) { connection.Close(); connection.Dispose(); } } }