Botones Faltantes
This commit is contained in:
@@ -175,6 +175,8 @@
|
||||
</div>
|
||||
<asp:Button ID="BtnAgregarProducto" runat="server" Text="Agregar Producto"
|
||||
CssClass="btn btn-primary" ValidationGroup="GrpAgregarProducto" />
|
||||
<asp:Button ID="BtnEliminarProducto" runat="server" Text="Eliminar Producto"
|
||||
CssClass="btn-eliminar" OnClick="BtnEliminarProducto_Click" />
|
||||
</div>
|
||||
|
||||
<!-- GridViews -->
|
||||
@@ -233,6 +235,13 @@
|
||||
</div>
|
||||
</ContentTemplate>
|
||||
</asp:UpdatePanel>
|
||||
|
||||
<!-- Botón para Guardar la OP -->
|
||||
<div class="form-group" style="margin-top: 20px;">
|
||||
<asp:Button ID="BtnGuardarOP" runat="server" Text="Guardar Orden de Producción"
|
||||
CssClass="btn btn-success" OnClick="BtnGuardarOP_Click"
|
||||
ValidationGroup="GrpGuardar" />
|
||||
</div>
|
||||
</div>
|
||||
</ContentTemplate>
|
||||
</asp:UpdatePanel>
|
||||
|
||||
166
OP/OP.aspx.vb
166
OP/OP.aspx.vb
@@ -195,7 +195,7 @@ Partial Class OP_OP
|
||||
rowMP("Tipo") = "MP"
|
||||
rowMP("Clave") = CvePS
|
||||
rowMP("Producto") = drMP("producto").ToString()
|
||||
rowMP("UnidadMedida") = drMP("UnidadMedida").ToString()
|
||||
rowMP("UnidadMedida") = drMP("UnidadMedidaMateriaPrima").ToString()
|
||||
rowMP("Cantidad") = drMP("Cantidad").ToString().ToDecimal()
|
||||
rowMP("Surtido") = 0
|
||||
DtMP.Rows.Add(rowMP)
|
||||
@@ -231,22 +231,172 @@ Partial Class OP_OP
|
||||
ActualizarGrids()
|
||||
End Sub
|
||||
|
||||
Protected Sub BtnEliminarProducto_Click(sender As Object, e As EventArgs)
|
||||
If DdlPS.SelectedValue = "-1" Then
|
||||
Alert("Seleccione un producto del listado.", TipoMensaje.MsgAdvertencia)
|
||||
Return
|
||||
End If
|
||||
|
||||
Dim CveProducto As Integer = DdlPS.SelectedValue.ToEntero()
|
||||
|
||||
Dim filasProducto As DataRow() = DtPS.Select($"Clave = {CveProducto}")
|
||||
If filasProducto.Length > 0 Then
|
||||
DtPS.Rows.Remove(filasProducto(0))
|
||||
End If
|
||||
|
||||
EliminarDatosRelacionados(CveProducto)
|
||||
|
||||
ActualizarGrids()
|
||||
End Sub
|
||||
|
||||
Private Sub EliminarDatosRelacionados(CveProducto As Integer)
|
||||
Dim filasMP As DataRow() = DtMP.Select($"Clave = {CveProducto}")
|
||||
For Each fila As DataRow In filasMP
|
||||
DtMP.Rows.Remove(fila)
|
||||
Next
|
||||
|
||||
Dim filasMO As DataRow() = DtMO.Select($"Clave = {CveProducto}")
|
||||
For Each fila As DataRow In filasMO
|
||||
DtMO.Rows.Remove(fila)
|
||||
Next
|
||||
|
||||
Dim filasCI As DataRow() = DtCI.Select($"Clave = {CveProducto}")
|
||||
For Each fila As DataRow In filasCI
|
||||
DtCI.Rows.Remove(fila)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Protected Sub BtnGuardarOP_Click(sender As Object, e As EventArgs)
|
||||
' Validar campos obligatorios
|
||||
If DdlClientes.SelectedValue = "-1" Then
|
||||
Alert("Seleccione un cliente.", TipoMensaje.MsgAdvertencia)
|
||||
Return
|
||||
End If
|
||||
|
||||
If DtPS.Rows.Count = 0 Then
|
||||
Alert("Agregue al menos un producto.", TipoMensaje.MsgAdvertencia)
|
||||
Return
|
||||
End If
|
||||
|
||||
' Iniciar transacción
|
||||
Dim clsOP As New ClsOP()
|
||||
clsOP.IniciaTransacSQL()
|
||||
|
||||
Try
|
||||
' Insertar/Actualizar cabecera de la OP usando UpdateOP
|
||||
Dim CveOP As Integer = Me.CveOP ' Si es nuevo, CveOP = -1
|
||||
Dim Success As Boolean = clsOP.UpdateOP(
|
||||
CveOP:=CveOP,
|
||||
Descripcion:=TxtDescripcion.Text,
|
||||
CveCliente:=DdlClientes.SelectedValue.ToEntero(),
|
||||
CvePS:=DdlPS.SelectedValue.ToEntero(),
|
||||
CveSubProyecto:=DdlSubProyecto.SelectedValue.ToEntero(),
|
||||
Cantidad:=1, ' Ajustar según lógica de negocio
|
||||
Fecha:=Convert.ToDateTime(Txtfecha.Text),
|
||||
CveEmpresa:=UsuarioActual.CveEmpresa,
|
||||
CveUsuario:=UsuarioActual.CveUsuario
|
||||
)
|
||||
|
||||
If Not Success Then
|
||||
Throw New Exception("Error al guardar la cabecera de la OP.")
|
||||
End If
|
||||
|
||||
' Obtener el CveOP generado (asumiendo que se actualiza en la propiedad)
|
||||
If Me.CveOP = -1 Then
|
||||
' Si es nuevo, recuperar el CveOP de la base de datos
|
||||
' (Requiere que el SP PA_OP_OrdendeProduccionUp devuelva el ID)
|
||||
' Esto depende de la implementación del SP.
|
||||
' Ejemplo hipotético:
|
||||
clsOP.GetOP(-1, DdlClientes.SelectedValue.ToEntero(), DdlSubProyecto.SelectedValue.ToEntero(), -1, -1, -1, MinFecha, MaxFecha, UsuarioActual.CveEmpresa)
|
||||
If clsOP.DtResultados.Rows.Count > 0 Then
|
||||
Me.CveOP = clsOP.DtResultados.Rows(0)("CveOP").ToString.ToEntero()
|
||||
End If
|
||||
End If
|
||||
|
||||
' Insertar detalles de Productos, MP, MO, CI
|
||||
For Each drProducto As DataRow In DtPS.Rows
|
||||
Dim CvePS As Integer = drProducto("Clave").ToString().ToEntero()
|
||||
|
||||
' Insertar Materia Prima relacionada
|
||||
For Each drMP As DataRow In DtMP.Select($"Clave = {CvePS}")
|
||||
clsOP.AddMP(
|
||||
Cantidad:=drMP("Cantidad").ToString().ToDecimal(),
|
||||
CvePS:=CvePS,
|
||||
CvePSMateriaPrima:=drMP("CvePSMateriaPrima").ToString().ToEntero(),
|
||||
CveUM:=drMP("CveUM").ToString().ToEntero(),
|
||||
CveUMMateriaPrima:=drMP("CveUMMateriaPrima").ToString().ToEntero()
|
||||
)
|
||||
Next
|
||||
|
||||
' Insertar Mano de Obra relacionada
|
||||
For Each drMO As DataRow In DtMO.Select($"Clave = {CvePS}")
|
||||
clsOP.AddMO(
|
||||
Cantidad:=drMO("Cantidad").ToString().ToDecimal(),
|
||||
CvePS:=CvePS,
|
||||
CvePuesto:=drMO("CvePuesto").ToString().ToEntero(),
|
||||
CveUM:=drMO("CveUM").ToString().ToEntero()
|
||||
)
|
||||
Next
|
||||
|
||||
' Insertar Costos Indirectos relacionados
|
||||
For Each drCI As DataRow In DtCI.Select($"Clave = {CvePS}")
|
||||
clsOP.AddCI(
|
||||
Cantidad:=drCI("Cantidad").ToString().ToDecimal(),
|
||||
CvePS:=CvePS,
|
||||
CvePSMateriaPrima:=drCI("CvePSMateriaPrima").ToString().ToEntero(),
|
||||
CveUM:=drCI("CveUM").ToString().ToEntero(),
|
||||
CveUMMateriaPrima:=drCI("CveUMMateriaPrima").ToString().ToEntero()
|
||||
)
|
||||
Next
|
||||
Next
|
||||
|
||||
' Commit si todo es exitoso
|
||||
clsOP.Commit()
|
||||
Alert("Orden de Producción guardada correctamente.", TipoMensaje.MsgInformacion)
|
||||
Response.Redirect($"OP.aspx?CveOP={Me.CveOP}") ' Redirigir a la OP guardada
|
||||
|
||||
Catch ex As Exception
|
||||
' Rollback en caso de error
|
||||
clsOP.RollBack()
|
||||
Alert($"Error al guardar: {ex.Message}", TipoMensaje.MsgError)
|
||||
Finally
|
||||
clsOP.Dispose()
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub ActualizarGrids()
|
||||
GvProductos.DataSource = DtPS.Select("Tipo = 'Producto'").CopyToDataTable()
|
||||
Dim dtProductosFiltrados As DataTable = DtPS.Clone() ' Clona la estructura
|
||||
Dim rowsProductos As DataRow() = DtPS.Select("Tipo = 'Producto'")
|
||||
If rowsProductos.Length > 0 Then
|
||||
dtProductosFiltrados = rowsProductos.CopyToDataTable()
|
||||
End If
|
||||
GvProductos.DataSource = dtProductosFiltrados
|
||||
GvProductos.DataBind()
|
||||
|
||||
|
||||
GvMateriaPrima.DataSource = DtMP.Select("Tipo = 'MP'").CopyToDataTable()
|
||||
Dim dtMPFiltrados As DataTable = DtMP.Clone()
|
||||
Dim rowsMP As DataRow() = DtMP.Select("Tipo = 'MP'")
|
||||
If rowsMP.Length > 0 Then
|
||||
dtMPFiltrados = rowsMP.CopyToDataTable()
|
||||
End If
|
||||
GvMateriaPrima.DataSource = dtMPFiltrados
|
||||
GvMateriaPrima.DataBind()
|
||||
|
||||
GvManoObra.DataSource = DtMO.Select("Tipo = 'MO'").CopyToDataTable()
|
||||
Dim dtMOFiltrados As DataTable = DtMO.Clone()
|
||||
Dim rowsMO As DataRow() = DtMO.Select("Tipo = 'MO'")
|
||||
If rowsMO.Length > 0 Then
|
||||
dtMOFiltrados = rowsMO.CopyToDataTable()
|
||||
End If
|
||||
GvManoObra.DataSource = dtMOFiltrados
|
||||
GvManoObra.DataBind()
|
||||
|
||||
|
||||
GvCostosIndirectos.DataSource = DtCI.Select("Tipo = 'CI'").CopyToDataTable()
|
||||
Dim dtCIFiltrados As DataTable = DtCI.Clone()
|
||||
Dim rowsCI As DataRow() = DtCI.Select("Tipo = 'CI'")
|
||||
If rowsCI.Length > 0 Then
|
||||
dtCIFiltrados = rowsCI.CopyToDataTable()
|
||||
End If
|
||||
GvCostosIndirectos.DataSource = dtCIFiltrados
|
||||
GvCostosIndirectos.DataBind()
|
||||
|
||||
|
||||
UpGvDatosOP.Update()
|
||||
End Sub
|
||||
|
||||
|
||||
Reference in New Issue
Block a user