Commit inicial Ventas Productivo
This commit is contained in:
289
Inventarios/Equivalencia.aspx.vb
Normal file
289
Inventarios/Equivalencia.aspx.vb
Normal file
@@ -0,0 +1,289 @@
|
||||
Imports System.Data
|
||||
Imports Extensiones
|
||||
|
||||
Partial Class Inventarios_Equivalencia
|
||||
Inherits ClsPaginas
|
||||
|
||||
|
||||
#Region "Propiedades"
|
||||
|
||||
Public Property DtEquivalencias() As DataTable
|
||||
Get
|
||||
Return CType(ViewState("dtEquivalencias"), DataTable)
|
||||
End Get
|
||||
Set(value As DataTable)
|
||||
ViewState("dtEquivalencias") = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
#End Region
|
||||
|
||||
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
|
||||
If Not IsPostBack Then
|
||||
inicializarTabla()
|
||||
btAgregar.Enabled = False
|
||||
InicializarListas()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub InicializarListas()
|
||||
'Llenar el dropdownlist de unidad de medida
|
||||
|
||||
ddlUnidad.DataSource = GlobalDTUnidadesMedida()
|
||||
ddlUnidad.DataBind()
|
||||
|
||||
|
||||
'Llenar el dropdownlist de Productosy servicios
|
||||
Dim productos As New ClsProductosServicios
|
||||
Dim resProductos As New DataTable
|
||||
|
||||
If productos.GetAllPS(UsuarioActual.CveEmpresa) Then
|
||||
resProductos = productos.DtResultados
|
||||
ddlProducto.DataSource = resProductos
|
||||
ddlProducto.DataTextField = "PS"
|
||||
ddlProducto.DataValueField = "CvePS"
|
||||
ddlProducto.DataBind()
|
||||
End If
|
||||
|
||||
productos.Dispose()
|
||||
|
||||
ddlProducto.Items.Insert(0, New ListItem("----", "0"))
|
||||
|
||||
End Sub
|
||||
|
||||
Protected Sub btAgregar_Click(sender As Object, e As EventArgs) Handles btAgregar.Click
|
||||
Dim Precio As Double = txtPrecio.Text.ToDouble
|
||||
Dim CveUnidadMedida As Integer = ddlUnidad.SelectedValue.ToEntero
|
||||
Dim Cantidad As Double = txtCantidad.Text.ToDouble
|
||||
Dim UnidadBase As Boolean = cbUnidadBase.Checked
|
||||
Dim psEquivalencias As New ClsProductosServicios
|
||||
|
||||
Dim Mensaje As String = ""
|
||||
|
||||
Dim dt As New DataTable
|
||||
dt = CType(Me.ViewState("dtEquivalencias"), DataTable)
|
||||
|
||||
If dt.Rows.Count = 0 Then
|
||||
UnidadBase = True
|
||||
End If
|
||||
|
||||
If cbUnidadBase.Checked Then
|
||||
reAsignarBase(dt, dt.Rows.Count - 1)
|
||||
End If
|
||||
|
||||
|
||||
If psEquivalencias.AddPSEquivalencias(ddlProducto.SelectedValue.ToEntero, CveUnidadMedida, Cantidad, UnidadBase, Precio, 1) Then
|
||||
|
||||
gvEquivalencias.DataSource = psEquivalencias.DtResultados
|
||||
|
||||
ViewState("dtEquivalencias") = psEquivalencias.DtResultados
|
||||
|
||||
|
||||
|
||||
txtCantidad.Text = ""
|
||||
txtPrecio.Text = ""
|
||||
ddlUnidad.SelectedIndex = -1
|
||||
cbUnidadBase.Checked = False
|
||||
|
||||
End If
|
||||
|
||||
psEquivalencias.Dispose()
|
||||
gvEquivalencias.DataBind()
|
||||
|
||||
End Sub
|
||||
|
||||
Private Function reordenarNum(dt As DataTable) As DataTable
|
||||
If dt.Rows.Count > 0 Then
|
||||
For i As Integer = 0 To (dt.Rows.Count - 1)
|
||||
dt.Rows(i).Item(0) = (i + 1)
|
||||
Next i
|
||||
End If
|
||||
Return dt
|
||||
End Function
|
||||
|
||||
Private Function existeUM(um As Integer) As Boolean
|
||||
Dim res As Boolean = False
|
||||
Dim dt As DataTable = CType(Me.ViewState("dtEquivalencias"), DataTable)
|
||||
For i As Integer = 0 To (dt.Rows.Count - 1)
|
||||
If dt.Rows(i).Item("CveUnidadMedida").ToString = um.ToString Then
|
||||
Return True
|
||||
End If
|
||||
Next i
|
||||
Return res
|
||||
End Function
|
||||
|
||||
Private Function existeUB(dt As DataTable) As Boolean
|
||||
Dim res As Boolean = False
|
||||
Dim count As Integer = 0
|
||||
' Dim dt As DataTable = Me.ViewState("dtEquivalencias")
|
||||
For i As Integer = 0 To (dt.Rows.Count - 1)
|
||||
If CType(dt.Rows(i).Item("Base"), Boolean) Then
|
||||
count = count + 1
|
||||
End If
|
||||
Next
|
||||
If count = 1 Then
|
||||
res = True
|
||||
End If
|
||||
|
||||
Return res
|
||||
End Function
|
||||
|
||||
Private Function reAsignarBase(dt As DataTable, num As Integer) As DataTable
|
||||
|
||||
For i As Integer = 0 To (dt.Rows.Count - 1)
|
||||
If i = num Then
|
||||
dt.Rows(i).Item("Base") = True
|
||||
Else
|
||||
|
||||
If dt.Rows(i).Item("Base").ToString = "True" Then
|
||||
Dim psEquivalencias As New ClsProductosServicios
|
||||
If Not psEquivalencias.UpdatePSEquivalencias(ddlProducto.SelectedValue.ToEntero, dt.Rows(i).Item("CveUnidadMedida").ToString.ToEntero, dt.Rows(i).Item("Cantidad").ToString.ToDouble, False, dt.Rows(i).Item("Precio").ToString.ToDouble, 1) Then
|
||||
Alert("Error al actualizar registro.", TipoMensaje.MsgError)
|
||||
Return dt
|
||||
End If
|
||||
psEquivalencias.Dispose()
|
||||
End If
|
||||
dt.Rows(i).Item("Base") = False
|
||||
End If
|
||||
Next i
|
||||
Return dt
|
||||
End Function
|
||||
|
||||
Protected Sub inicializarTabla()
|
||||
Dim dt As New DataTable
|
||||
|
||||
dt.Columns.Add("No")
|
||||
dt.Columns.Add("Cantidad")
|
||||
dt.Columns.Add("CveUnidadMedida", Type.GetType("System.Int32"))
|
||||
dt.Columns.Add("Unidad")
|
||||
dt.Columns.Add("Precio")
|
||||
dt.Columns.Add("Base")
|
||||
|
||||
Me.gvEquivalencias.DataSource = dt
|
||||
Me.gvEquivalencias.DataBind()
|
||||
Me.ViewState("dtEquivalencias") = dt
|
||||
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Protected Sub ddlProducto_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlProducto.SelectedIndexChanged
|
||||
gvEquivalencias.EditIndex = -1
|
||||
Dim equivalencias As New ClsProductosServicios
|
||||
|
||||
|
||||
If ddlProducto.SelectedValue = "0" Then
|
||||
btAgregar.Enabled = False
|
||||
Else
|
||||
btAgregar.Enabled = True
|
||||
End If
|
||||
|
||||
If btAgregar.Text = "Editar" Then
|
||||
btAgregar.Text = "Agregar"
|
||||
btCancelar.Visible = False
|
||||
End If
|
||||
|
||||
If equivalencias.GetPSEquivalencias(ddlProducto.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then
|
||||
Dim dt As New DataTable
|
||||
dt.Columns.Add("No")
|
||||
dt.Columns.Add("Cantidad")
|
||||
dt.Columns.Add("CveUnidadMedida", Type.GetType("System.Int32"))
|
||||
dt.Columns.Add("Unidad")
|
||||
dt.Columns.Add("Precio")
|
||||
dt.Columns.Add("Base", Type.GetType("System.String"))
|
||||
dt = equivalencias.DtResultados
|
||||
ViewState("dtEquivalencias") = reordenarNum(dt)
|
||||
gvEquivalencias.DataSource = Me.ViewState("dtEquivalencias")
|
||||
gvEquivalencias.DataBind()
|
||||
|
||||
End If
|
||||
|
||||
equivalencias.Dispose()
|
||||
|
||||
End Sub
|
||||
|
||||
Protected Sub gvEquivalencias_RowDeleting(sender As Object, e As GridViewDeleteEventArgs) Handles gvEquivalencias.RowDeleting
|
||||
|
||||
Dim CveUnidadMedida As Integer = gvEquivalencias.DataKeys(e.RowIndex)("CveUM").ToString().ToEntero ' dt.Rows(e.RowIndex).Item("CveUnidadMedida")
|
||||
Dim UnidadBase As Boolean = CType(gvEquivalencias.DataKeys(e.RowIndex)("UnidadBase"), Boolean)
|
||||
|
||||
|
||||
If UnidadBase Then
|
||||
Alert("No puede eliminar una equivalencia que es Base.", TipoMensaje.MsgError)
|
||||
Return
|
||||
End If
|
||||
|
||||
Dim psEquivalencias As New ClsProductosServicios
|
||||
|
||||
If psEquivalencias.RemovePSEquivalencias(ddlProducto.SelectedValue.ToEntero, CveUnidadMedida) Then
|
||||
gvEquivalencias.DataSource = psEquivalencias.DtResultados
|
||||
ViewState("dtEquivalencias") = psEquivalencias.DtResultados
|
||||
gvEquivalencias.DataBind()
|
||||
End If
|
||||
|
||||
|
||||
psEquivalencias.Dispose()
|
||||
|
||||
End Sub
|
||||
|
||||
Protected Sub EditRow(ByVal sender As Object, ByVal e As GridViewEditEventArgs) Handles gvEquivalencias.RowEditing
|
||||
Dim dt As DataTable = CType(Me.ViewState("dtEquivalencias"), DataTable)
|
||||
|
||||
gvEquivalencias.EditIndex = e.NewEditIndex
|
||||
|
||||
gvEquivalencias.DataSource = dt
|
||||
gvEquivalencias.DataBind()
|
||||
End Sub
|
||||
|
||||
Protected Sub CancelEdit(ByVal sender As Object, ByVal e As GridViewCancelEditEventArgs)
|
||||
gvEquivalencias.EditIndex = -1
|
||||
gvEquivalencias.DataSource = Me.ViewState("dtEquivalencias")
|
||||
gvEquivalencias.DataBind()
|
||||
|
||||
End Sub
|
||||
|
||||
Protected Sub gvEquivalencias_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles gvEquivalencias.RowDataBound
|
||||
|
||||
If e.Row.RowState = DataControlRowState.Edit OrElse e.Row.RowState = 5 Then
|
||||
e.Row.FCDropDownList("ddlEUnidad").DataSource = GlobalDTUnidadesMedida()
|
||||
e.Row.FCDropDownList("ddlEUnidad").SelectedValue = e.Row.DBCampo("CveUnidadMedida")
|
||||
e.Row.FCDropDownList("ddlEUnidad").DataBind()
|
||||
End If
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Protected Sub gvEquivalencias_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles gvEquivalencias.RowUpdating
|
||||
|
||||
Dim psEquivalencias As New ClsProductosServicios
|
||||
|
||||
Dim Mensaje As String = ""
|
||||
Dim dt As DataTable
|
||||
|
||||
Dim cantidad As Double = DirectCast(gvEquivalencias.Rows(e.RowIndex).FindControl("txtECantidad"), TextBox).Text.ToDouble
|
||||
|
||||
Dim precio As Double = DirectCast(gvEquivalencias.Rows(e.RowIndex).FindControl("txtEPrecio"), TextBox).Text.ToDouble
|
||||
Dim base As Boolean = DirectCast(gvEquivalencias.Rows(e.RowIndex).FindControl("cbEBase"), CheckBox).Checked
|
||||
Dim CveUnidadMedida As Integer = DirectCast(gvEquivalencias.Rows(e.RowIndex).FindControl("ddlEUnidad"), DropDownList).SelectedValue.ToEntero
|
||||
|
||||
If psEquivalencias.UpdatePSEquivalencias(ddlProducto.SelectedValue.ToEntero, CveUnidadMedida, cantidad, base, precio, UsuarioActual.CveUsuario) Then
|
||||
dt = psEquivalencias.DtResultados
|
||||
|
||||
If base Then
|
||||
|
||||
reAsignarBase(dt, e.RowIndex)
|
||||
|
||||
End If
|
||||
|
||||
|
||||
ViewState("dtEquivalencias") = dt
|
||||
|
||||
gvEquivalencias.EditIndex = -1
|
||||
gvEquivalencias.DataSource = dt
|
||||
gvEquivalencias.DataBind()
|
||||
End If
|
||||
psEquivalencias.Dispose()
|
||||
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user