Commit inicial Ventas Productivo
This commit is contained in:
289
Contratos/ModificarPresupuesto.aspx.vb
Normal file
289
Contratos/ModificarPresupuesto.aspx.vb
Normal file
@@ -0,0 +1,289 @@
|
||||
Option Explicit On
|
||||
Option Strict On
|
||||
|
||||
Imports System.Data
|
||||
Imports Extensiones
|
||||
|
||||
Partial Class Contratos_ModificarPresupuesto
|
||||
Inherits ClsPaginas
|
||||
Enum TipoModificacion
|
||||
Ampliacion
|
||||
Reduccion
|
||||
Transferencia
|
||||
End Enum
|
||||
#Region "P R O P I E D A D E S"
|
||||
Public ReadOnly Property EstatusFinal() As Integer
|
||||
Get
|
||||
Return 2
|
||||
End Get
|
||||
End Property
|
||||
Public Property CvePresupuesto() As Integer
|
||||
Get
|
||||
Return ViewState("CvePresupuesto").ToString.ToEntero
|
||||
End Get
|
||||
Set(ByVal value As Integer)
|
||||
ViewState("CvePresupuesto") = value
|
||||
End Set
|
||||
End Property
|
||||
Public Property Tipo() As TipoModificacion
|
||||
Get
|
||||
Return DirectCast(ViewState("Tipo"), TipoModificacion)
|
||||
End Get
|
||||
Set(ByVal value As TipoModificacion)
|
||||
ViewState("Tipo") = value
|
||||
End Set
|
||||
End Property
|
||||
Public Property DtPresupuestos() As DataTable
|
||||
Get
|
||||
Return DirectCast(ViewState("DtPresupuestos"), DataTable)
|
||||
End Get
|
||||
Set(ByVal value As DataTable)
|
||||
ViewState("DtPresupuestos") = value
|
||||
End Set
|
||||
End Property
|
||||
Public Property DtClasificaciones() As DataTable
|
||||
Get
|
||||
Return DirectCast(ViewState("DtClasificaciones"), DataTable)
|
||||
End Get
|
||||
Set(ByVal value As DataTable)
|
||||
ViewState("DtClasificaciones") = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
#End Region
|
||||
|
||||
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
|
||||
If Not IsPostBack Then
|
||||
Me.CvePresupuesto = IfNull(Request("CvePresupuesto"), -1).ToString.ToEntero
|
||||
InicializaValores()
|
||||
CargaDatos()
|
||||
|
||||
UpDatosG.Update()
|
||||
UpGvClasificaciones.Update()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
#Region "I N I C I A L I Z A - V A L O R E S"
|
||||
Private Sub InicializaValores()
|
||||
Dim ObjContrato As New ClsContratos()
|
||||
'Dim CvePresupuesto = -1
|
||||
Dim Nombre = "-1"
|
||||
Dim CveSubProyecto = -1
|
||||
Dim CveUsuario = -1
|
||||
If ObjContrato.GetPresupuestos(-1, Nombre, CveSubProyecto, EstatusFinal, CveUsuario, UsuarioActual.CveEmpresa) Then
|
||||
DtPresupuestos = ObjContrato.DtResultados.Copy
|
||||
End If
|
||||
ObjContrato.Dispose()
|
||||
If DtPresupuestos IsNot Nothing Then
|
||||
DdlPresupuesto.DataSource = DtPresupuestos
|
||||
|
||||
DdlPresupuesto.DataBind()
|
||||
DdlPresupuesto.Items.Insert(0, New ListItem("Seleccione un presupuesto", "-1"))
|
||||
DdlPresupuesto.SelectedValueExist(CvePresupuesto)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
|
||||
#End Region
|
||||
|
||||
#Region "C A R G A - D A T O S"
|
||||
Private Sub CargaDatos()
|
||||
Dim CvePresupuesto = DdlPresupuesto.SelectedValue.ToEntero
|
||||
Dim Nombre = "-1"
|
||||
Dim CveSubProyecto = -1
|
||||
Dim CveUsuario = -1
|
||||
Dim Agrupador = 1 'CLASIFICACION
|
||||
If CvePresupuesto > 0 Then
|
||||
TxtFecha.Text = Now.ToString("dd/MM/yyyy")
|
||||
Dim DrPresupuesto = DtPresupuestos.FiltroPrimero($"CvePresupuesto = {CvePresupuesto}")
|
||||
'Dim DrPresupuesto = DtPresupuestos.AsEnumerable.Where(Function(a) a("CvePresupuesto").ToString.ToEntero = CvePresupuesto).FirstOrDefault
|
||||
|
||||
Dim FechaI As Date = DrPresupuesto("FechaInicio").ToString.ToDate
|
||||
Dim FechaF As Date = DrPresupuesto("FechaFin").ToString.ToDate
|
||||
|
||||
Dim ObjContrato As New ClsContratos()
|
||||
If ObjContrato.GetPresupuestosModificacionesDetalle(CvePresupuesto, FechaI, FechaF, UsuarioActual.CveEmpresa) Then
|
||||
DtClasificaciones = ObjContrato.DtResultados.FiltraParametros("CveClasificacion > 0")
|
||||
End If
|
||||
ObjContrato.Dispose()
|
||||
|
||||
If DtClasificaciones IsNot Nothing Then
|
||||
GvPresupuestos.DataSource = DtClasificaciones
|
||||
GvPresupuestos.DataBind()
|
||||
End If
|
||||
|
||||
Dim StrTipo = DdlTipo.SelectedValue
|
||||
|
||||
Select Case StrTipo
|
||||
'A M P L I A C I O N
|
||||
Case "1"
|
||||
Me.Tipo = TipoModificacion.Ampliacion
|
||||
GvPresupuestos.Columns(3).Visible = True
|
||||
GvPresupuestos.Columns(4).Visible = False
|
||||
'R E D U C C I O N
|
||||
Case "2"
|
||||
Me.Tipo = TipoModificacion.Reduccion
|
||||
GvPresupuestos.Columns(3).Visible = False
|
||||
GvPresupuestos.Columns(4).Visible = True
|
||||
'T R A N S F E R E N C I A'
|
||||
Case "1,2"
|
||||
Me.Tipo = TipoModificacion.Transferencia
|
||||
GvPresupuestos.Columns(3).Visible = True
|
||||
GvPresupuestos.Columns(4).Visible = True
|
||||
End Select
|
||||
|
||||
|
||||
End If
|
||||
End Sub
|
||||
Protected Sub GvPresupuestos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvPresupuestos.RowDataBound
|
||||
If e.Row.RowType = DataControlRowType.DataRow Then
|
||||
Dim StrTipo = DdlTipo.SelectedValue
|
||||
Dim Index = e.Row.RowIndex
|
||||
Select Case StrTipo
|
||||
'A M P L I A C I O N
|
||||
Case "1"
|
||||
e.Row.FCTextBox("TxtAmpliacion").Attributes.Add("onKeyUp ", $"Ampliacion({Index});")
|
||||
'R E D U C C I O N
|
||||
Case "2"
|
||||
Dim Saldo As Decimal = e.Row.FCLabel("LtlSaldo").Text.Replace("$", "").ToDecimal
|
||||
e.Row.FCTextBox("TxtReduccion").Attributes.Add("onKeyUp ", $"this.value = minmax(this.value, 0, {Saldo});Reduccion({Index});")
|
||||
'T R A N S F E R E N C I A'
|
||||
Case "1,2"
|
||||
Dim Saldo As Decimal = e.Row.FCLabel("LtlSaldo").Text.Replace("$", "").ToDecimal
|
||||
e.Row.FCTextBox("TxtAmpliacion").Attributes.Add("onKeyUp ", $"Transferencia({Index},'A');")
|
||||
e.Row.FCTextBox("TxtReduccion").Attributes.Add("onKeyUp ", $"this.value = minmax(this.value, 0, {Saldo});Transferencia({Index},'R');")
|
||||
End Select
|
||||
End If
|
||||
If e.Row.RowType = DataControlRowType.Footer Then
|
||||
e.Row.FCLabel("LblTotalSaldo").Text = String.Format("{0:C}", DtClasificaciones.SUM("PorEjercer"))
|
||||
e.Row.FCLabel("LblTotalImporte").Text = String.Format("{0:C}", DtClasificaciones.SUM("Autorizado"))
|
||||
End If
|
||||
End Sub
|
||||
Protected Sub DdlPresupuesto_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlPresupuesto.SelectedIndexChanged
|
||||
CargaDatos()
|
||||
UpDatosG.Update()
|
||||
UpGvClasificaciones.Update()
|
||||
End Sub
|
||||
Protected Sub DdlTipo_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlTipo.SelectedIndexChanged
|
||||
Dim Tipo = DdlTipo.SelectedValue
|
||||
|
||||
Select Case Tipo
|
||||
'A M P L I A C I O N
|
||||
Case "1"
|
||||
GvPresupuestos.Columns(3).Visible = True
|
||||
GvPresupuestos.Columns(4).Visible = False
|
||||
'R E D U C C I O N
|
||||
Case "2"
|
||||
GvPresupuestos.Columns(3).Visible = False
|
||||
GvPresupuestos.Columns(4).Visible = True
|
||||
'T R A N S F E R E N C I A'
|
||||
Case "1,2"
|
||||
GvPresupuestos.Columns(3).Visible = True
|
||||
GvPresupuestos.Columns(4).Visible = True
|
||||
End Select
|
||||
|
||||
For Each GvRow As GridViewRow In GvPresupuestos.Rows
|
||||
If GvRow.RowType = DataControlRowType.DataRow Then
|
||||
Dim Index = GvRow.RowIndex
|
||||
Select Case Tipo
|
||||
'A M P L I A C I O N
|
||||
Case "1"
|
||||
GvRow.FCTextBox("TxtAmpliacion").Attributes.Add("onKeyUp ", $"Ampliacion({Index});")
|
||||
'R E D U C C I O N
|
||||
Case "2"
|
||||
Dim Saldo As Decimal = GvRow.FCLabel("LtlSaldo").Text.Replace("$", "").ToDecimal
|
||||
GvRow.FCTextBox("TxtReduccion").Attributes.Add("onKeyUp ", $"this.value = minmax(this.value, 0, {Saldo});Reduccion({Index});")
|
||||
'T R A N S F E R E N C I A'
|
||||
Case "1,2"
|
||||
Dim Saldo As Decimal = GvRow.FCLabel("LtlSaldo").Text.Replace("$", "").ToDecimal
|
||||
GvRow.FCTextBox("TxtAmpliacion").Attributes.Add("onKeyUp ", $"Transferencia({Index},'A');")
|
||||
GvRow.FCTextBox("TxtReduccion").Attributes.Add("onKeyUp ", $"this.value = minmax(this.value, 0, {Saldo});Transferencia({Index},'R');")
|
||||
End Select
|
||||
End If
|
||||
Next
|
||||
UpGvClasificaciones.Update()
|
||||
End Sub
|
||||
#End Region
|
||||
|
||||
Private Function ValidaDatos() As Boolean
|
||||
Dim CvePresupuesto = DdlPresupuesto.SelectedValue.ToEntero
|
||||
If CvePresupuesto <= 0 Then
|
||||
Alert("Seleccione un Presupuesto.", TipoMensaje.MsgAdvertencia)
|
||||
Return False
|
||||
End If
|
||||
If String.IsNullOrEmpty(TxtJustificion.Text) Then
|
||||
Alert("El campo 'Justificación' no puede estar vacío.", TipoMensaje.MsgAdvertencia)
|
||||
Return False
|
||||
End If
|
||||
If String.IsNullOrEmpty(TxtFecha.Text) Then
|
||||
Alert("El campo 'Fecha' no puede estar vacío.", TipoMensaje.MsgAdvertencia)
|
||||
Return False
|
||||
End If
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs)
|
||||
If ValidaDatos() Then
|
||||
Dim CvePresupuesto = DdlPresupuesto.SelectedValue.ToEntero
|
||||
Dim Tipo = DdlTipo.SelectedValue
|
||||
Dim Justificacion = TxtJustificion.Text
|
||||
Dim Fecha = TxtFecha.Text.ToDate
|
||||
|
||||
Dim TieneError = False
|
||||
Dim ObjPresu As New ClsContratos
|
||||
ObjPresu.IniciaTransacSQL()
|
||||
|
||||
For Each GvRow As GridViewRow In GvPresupuestos.Rows
|
||||
If GvRow.RowType = DataControlRowType.DataRow Then
|
||||
Dim CvePresupuestoDetalle = GvRow.DataKey("CvePresupuestoDetalle").ToEntero
|
||||
Dim CveCompra = -1
|
||||
If CvePresupuestoDetalle > 0 Then
|
||||
|
||||
Select Case Tipo
|
||||
'A M P L I A C I O N
|
||||
Case "1"
|
||||
Dim Ampliacion = GvRow.FCTextBox("TxtAmpliacion").Text.ToDecimal
|
||||
If Ampliacion > 0 Then
|
||||
TieneError = Not ObjPresu.AddPresupuestoMovimiento(CvePresupuestoDetalle, CveCompra, 1, Ampliacion, Fecha, Justificacion)
|
||||
End If
|
||||
'R E D U C C I O N
|
||||
Case "2"
|
||||
Dim Reduccion = GvRow.FCTextBox("TxtReduccion").Text.ToDecimal
|
||||
If Reduccion > 0 Then
|
||||
TieneError = Not ObjPresu.AddPresupuestoMovimiento(CvePresupuestoDetalle, CveCompra, 2, Reduccion, Fecha, Justificacion)
|
||||
End If
|
||||
'T R A N S F E R E N C I A'
|
||||
Case "1,2"
|
||||
Dim Ampliacion = GvRow.FCTextBox("TxtAmpliacion").Text.ToDecimal
|
||||
If Ampliacion > 0 Then
|
||||
TieneError = Not ObjPresu.AddPresupuestoMovimiento(CvePresupuestoDetalle, CveCompra, 1, Ampliacion, Fecha, Justificacion)
|
||||
End If
|
||||
|
||||
If Not TieneError Then
|
||||
Dim Reduccion = GvRow.FCTextBox("TxtReduccion").Text.ToDecimal
|
||||
If Reduccion > 0 Then
|
||||
TieneError = Not ObjPresu.AddPresupuestoMovimiento(CvePresupuestoDetalle, CveCompra, 2, Reduccion, Fecha, Justificacion)
|
||||
End If
|
||||
End If
|
||||
|
||||
End Select
|
||||
|
||||
End If
|
||||
If TieneError Then
|
||||
Exit For
|
||||
End If
|
||||
|
||||
End If
|
||||
Next
|
||||
If TieneError Then
|
||||
ObjPresu.RollBack()
|
||||
Alert("Ocurrió un error al guardar los datos.", TipoMensaje.MsgError)
|
||||
Else
|
||||
ObjPresu.Commit()
|
||||
Alert("Se guardaron los datos correctamente.")
|
||||
End If
|
||||
ObjPresu.Dispose()
|
||||
|
||||
End If
|
||||
End Sub
|
||||
End Class
|
||||
Reference in New Issue
Block a user