public int InsertarLote(LoteProduccion l) { SqlConnection connection = null; SqlCommand cmd = null; try { connection = GetConnection(); connection.Open(); cmd = connection.CreateCommand(); cmd.CommandText = "INSERT INTO [Produccion].[LotesProduccion] VALUES (@DetalleAsociado)" + Environment.NewLine + "SELECT CAST(SCOPE_IDENTITY() as int)"; cmd.Parameters.AddWithValue("@DetalleAsociado", l.DetalleAsociado.IdDetallePedido); int id = (int)cmd.ExecuteScalar(); l.IdLoteProduccion = id; return(id); } catch (Exception ex) { throw ex; } finally { if (connection != null) { connection.Close(); connection.Dispose(); } } }
private Modelo.Produccion.LoteProduccion GenerarLote() { Modelo.Produccion.LoteProduccion l = new LoteProduccion(); l.IdLoteProduccion = 0; l.DetalleAsociado = new Modelo.Ventas.DetallePedido() { IdDetallePedido = this.IdDetalleAsociado }; return(l); }
public static void Insertar(LoteProduccion lote, List <DetalleProduccion> listaDetalles) { SqlConnection cn = new SqlConnection(); cn.ConnectionString = @"Data Source=FEDE-PC;Initial Catalog=BD_Golosinas;Integrated Security=True"; cn.Open(); SqlTransaction tran = cn.BeginTransaction(); try { SqlCommand cmd = new SqlCommand(); cmd.Connection = cn; cmd.CommandText = @"Insert into Produccion (id_produccion,fecha_y_hora, id_empleado) values(@Id_produccion, @Fecha, @Id_emp)"; cmd.Parameters.AddWithValue(@"Id_produccion", lote.codLote); cmd.Parameters.AddWithValue(@"Fecha", lote.fecha); cmd.Parameters.AddWithValue(@"Id_emp", lote.id_empleado); cmd.Transaction = tran; cmd.ExecuteNonQuery(); foreach (DetalleProduccion detalle in listaDetalles) { detalle.id_produccion = lote.codLote; SqlCommand cmdDet = new SqlCommand(); cmdDet.Connection = cn; cmdDet.CommandText = @"Insert into Detalle_Produccion (id_produccion, id_golosina,cantidad) values (@id_prod,@Id_Gol,@Cant)"; cmdDet.Parameters.AddWithValue(@"id_prod", detalle.id_produccion); cmdDet.Parameters.AddWithValue(@"Id_Gol", detalle.id_golosina); cmdDet.Parameters.AddWithValue(@"Cant", detalle.cantidad); cmdDet.Transaction = tran; cmdDet.ExecuteNonQuery(); ActualizarStock(detalle, tran, cn); } tran.Commit(); } catch (SqlException ex) { tran.Rollback(); throw new ApplicationException("Error al Guardar el Pedido: " + ex.Message); } finally { cn.Close(); } }
public void AgregarEtapa(LoteProduccion l, LoteEtapa.EtapasProduccion e) { SqlConnection connection = null; SqlCommand cmd = null; try { connection = GetConnection(); connection.Open(); cmd = connection.CreateCommand(); cmd.CommandText = "INSERT INTO [Produccion].[LotesEtapas] (OrdenadoPor,FechaOrdenamiento,Lote,Etapa) VALUES (" + Environment.NewLine + "@OrdenadoPor," + Environment.NewLine + "GETDATE()," + Environment.NewLine + "@Lote," + Environment.NewLine + "@Etapa" + Environment.NewLine + ")" + Environment.NewLine + "SELECT CAST(SCOPE_IDENTITY() as int)"; cmd.Parameters.AddWithValue("@OrdenadoPor", Session.UsuarioEnCurso.IdUsuario); cmd.Parameters.AddWithValue("@Lote", l.IdLoteProduccion); cmd.Parameters.AddWithValue("@Etapa", (int)e); int id = (int)cmd.ExecuteScalar(); l.Add(new LoteEtapa() { IdLoteEtapa = id, OrdenadoPor = Session.UsuarioEnCurso, Etapa = e }); } catch (Exception ex) { throw ex; } finally { if (connection != null) { connection.Close(); connection.Dispose(); } } }
protected void btnConfirmar_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } LoteProduccion lote = new LoteProduccion(); lote.codLote = int.Parse(txtNumLote.Text); Empleado emp = (Empleado)Session["Empleado"]; lote.id_empleado = emp.id_empleado.Value; lote.fecha = DateTime.Parse(txtFecha.Text); List <DetalleProduccion> listaDetalles = (List <DetalleProduccion>)Session["ListaDetalles"]; LoteProduccionDao.Insertar(lote, listaDetalles); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Pedido Registrado con Exito!')", true); Limpiar(); }
public void CerrarEtapa(LoteProduccion l, LoteEtapa.EtapasProduccion e) { SqlConnection connection = null; SqlCommand cmd = null; try { connection = GetConnection(); connection.Open(); cmd = connection.CreateCommand(); cmd.CommandText = "UPDATE [Produccion].[LotesEtapas] " + "SET " + "AutorizadoPor = @AutorizadoPor, " + "FechaAutorizacion = GETDATE() " + "WHERE Lote = @Lote AND Etapa = @Etapa"; cmd.Parameters.AddWithValue("@AutorizadoPor", Session.UsuarioEnCurso.IdUsuario); cmd.Parameters.AddWithValue("@Lote", l.IdLoteProduccion); cmd.Parameters.AddWithValue("@Etapa", e); cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { if (connection != null) { connection.Close(); connection.Dispose(); } } }
public void PasarAvance() { if (CurrentLote == null) { CurrentLote = GenerarLote(); ctrlLotes.InsertarLote(CurrentLote); ctrlLotes.AgregarEtapa(CurrentLote, LoteEtapa.EtapasProduccion.Corte); foreach (GastosMaterial g in lst) { ctrlEtapas.AgregarGastoDeMaterial(CurrentLote[0], g); } Limpiar(); } else { ctrlLotes.CerrarEtapa(CurrentLote, CurrentLote[CurrentLote.Count - 1].Etapa); if (CurrentLote[CurrentLote.Count - 1].Etapa != LoteEtapa.EtapasProduccion.Entregado) { ctrlLotes.AgregarEtapa(CurrentLote, (LoteEtapa.EtapasProduccion)CurrentLote.Count + 1); } } }
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(); } } }
private void MostrarAvance(DataRow row) { if (row == null) { return; } if (row.IsNull("Etapa")) { CurrentLote = null; txtIdLoteEtapa.EditValue = 0; txtIdLoteProduccion.EditValue = 0; txtOrdenadoPor.EditValue = Session.UsuarioEnCurso.Nombre + " " + Session.UsuarioEnCurso.ApellidoPaterno; DtpFechaOrdenamiento.EditValue = DateTime.Today; lst = new List <GastosMaterial>(); lst.Add( new GastosMaterial() { Material = ctrlMateriales.GetById((int)row["Base"]), Cantidad = (int)row["Cantidad"], Observacion = "Consumo necesario generado", Tipo = GastosMaterial.TiposGasto.Consumo } ); this.IdDetalleAsociado = (int)row["IdDetalle"]; GcConsumos.DataSource = lst; GcConsumos.RefreshDataSource(); btnAgregar.Text = "Iniciar Produccion"; BtnGuardar.Enabled = false; } else { Modelo.Produccion.LoteProduccion l = ctrlLotes.GetById((int)row["IdLoteProduccion"]); if (l == null) { return; } Modelo.Produccion.LoteEtapa e = l[l.Count - 1]; txtIdLoteEtapa.EditValue = e.IdLoteEtapa; txtIdLoteProduccion.EditValue = l.IdLoteProduccion; txtOrdenadoPor.EditValue = e.OrdenadoPor.Nombre + " " + e.OrdenadoPor.ApellidoPaterno; if (e.AutorizadoPor != null) { txtAutorizadoPor.EditValue = e.AutorizadoPor.Nombre + " " + e.AutorizadoPor.ApellidoPaterno; } DtpFechaOrdenamiento.EditValue = e.FechaOrdemamiento; DtpFechaAutorizacion.EditValue = e.FechaAutorizacion; lst.Clear(); foreach (GastosMaterial g in e.GastosMateriales) { lst.Add(g); } GcConsumos.RefreshDataSource(); btnAgregar.Text = "Terminar Etapa"; CurrentLote = l; BtnGuardar.Enabled = true; } btnAgregar.Enabled = true; }