355 lines
15 KiB
VB.net
355 lines
15 KiB
VB.net
Option Explicit On
|
|
Option Strict On
|
|
|
|
Imports System.Data
|
|
Imports System.Linq
|
|
Imports Extensiones
|
|
|
|
Partial Class OS_PopUpMateriales
|
|
Inherits ClsPaginas
|
|
|
|
Private Property CveOSDetalle As Integer
|
|
Get
|
|
Return ViewState("CveOSDetalle").ToString.ToEntero
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CveOSDetalle") = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property Consecutivo As Integer
|
|
Get
|
|
Return ViewState("Consecutivo").ToString.ToEntero
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("Consecutivo") = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property DTPS As DataTable
|
|
Get
|
|
Return CType(ViewState("DTPS"), DataTable)
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DTPS") = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property TmpDT As DataTable
|
|
Get
|
|
Return CType(ViewState("TmpDT"), DataTable)
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("TmpDT") = value
|
|
End Set
|
|
End Property
|
|
|
|
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
|
|
If Not IsPostBack Then
|
|
CType(Me.Master, BaseMasterPage).EsPopup = True
|
|
CType(Me.Master, BaseMasterPage).PopupWidth = 500
|
|
RegistraScript("$get('tdContenido').style.height='350px'")
|
|
|
|
CargaPS(-1, DdlPS)
|
|
CargaClasificaciones()
|
|
|
|
CveOSDetalle = Request("CveOSDetalle").ToEntero
|
|
ViewState("Consecutivo") = Request("Consecutivo").ToEntero
|
|
ViewState("Orden") = ""
|
|
|
|
If CveOSDetalle = 0 Then
|
|
UpTitulos.Visible = False
|
|
Else
|
|
CreaDT()
|
|
CargaMateriales()
|
|
End If
|
|
|
|
If Not Request("EsThickbox") Is Nothing Then
|
|
hdnEsThickbox.Value = Request("EsThickbox")
|
|
Else
|
|
hdnEsThickbox.Value = "N"
|
|
End If
|
|
|
|
If UsuarioActual.TienePermisoProceso(74) = False Then GvPS.Columns(3).Visible = False
|
|
'If Not Request("ClientIDLink") Is Nothing Then
|
|
' hdnClientIDLink.Value = Request("ClientIDLink")
|
|
'Else
|
|
' hdnClientIDLink.Value = "NoDefinido"
|
|
'End If
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub CreaDT()
|
|
TmpDT = New DataTable
|
|
TmpDT.Columns.Add("Consecutivo", GetType(Integer))
|
|
TmpDT.Columns.Add("CveMaterialUtilizado", GetType(Integer))
|
|
TmpDT.Columns.Add("CveOSDetalle", GetType(Integer))
|
|
TmpDT.Columns.Add("Cantidad", GetType(Decimal))
|
|
TmpDT.Columns.Add("CveUnidadMedida", GetType(Integer))
|
|
TmpDT.Columns.Add("UM", GetType(String))
|
|
TmpDT.Columns.Add("CvePS", GetType(Integer))
|
|
TmpDT.Columns.Add("PS", GetType(String))
|
|
TmpDT.Columns.Add("CveClasificacion", GetType(Integer))
|
|
TmpDT.Columns.Add("Clasificacion", GetType(String))
|
|
TmpDT.Columns.Add("SeFacturara", GetType(String))
|
|
TmpDT.Columns.Add("SeFacturaraTexto", GetType(String))
|
|
End Sub
|
|
|
|
Private Sub CargaClasificaciones()
|
|
DdlClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa)
|
|
DdlClasificacion.DataBind()
|
|
End Sub
|
|
|
|
Private Sub CargaPS(CveClasificacion As Integer, Objeto As DropDownList)
|
|
Dim ObjPS As New ClsProductosServicios()
|
|
If ObjPS.GetPS(-1, CveClasificacion, UsuarioActual.CveEmpresa) Then
|
|
ViewState("DTPS") = ObjPS.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa & " AND Estado = 'Activo'", "PS")
|
|
Objeto.Items.Clear()
|
|
Objeto.DataSource = ViewState("DTPS")
|
|
Objeto.DataBind()
|
|
Objeto.Items.Insert(0, New ListItem("*** Actualizar listado de Productos o Servicios ***", "-2"))
|
|
Objeto.Items.Insert(0, New ListItem("Seleccione el Producto", "-1"))
|
|
End If
|
|
ObjPS.Dispose()
|
|
End Sub
|
|
|
|
Protected Sub DdlClasificacion_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DdlClasificacion.SelectedIndexChanged
|
|
CargaPS(DdlClasificacion.SelectedValue.ToEntero, DdlPS)
|
|
UpTitulos.Update()
|
|
End Sub
|
|
|
|
Private Sub CargaMateriales()
|
|
Try
|
|
Dim objOS As New ClsOS
|
|
|
|
If objOS.GetDetalleMateriales(CveOSDetalle, -1) Then
|
|
For Each Material As DataRow In objOS.DtResultados.Rows
|
|
Dim RowPS As DataRow = DTPS.FiltraParametros("CvePS = " & Material("CvePS").ToString).Rows(0)
|
|
Dim PS As String = RowPS("PS").ToString
|
|
Dim CveUnidadMedida As Integer = RowPS("CveUnidadMedida").ToString.ToEntero
|
|
Dim UM = GlobalDTUnidadesMedida.FiltraParametros("CveUnidadMedida = " & CveUnidadMedida).Rows(0)("UnidadMedida").ToString
|
|
Dim CveClasificacion As Integer = RowPS("CveClasificacion").ToString.ToEntero
|
|
Dim Clasificacion As String = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltraParametros("CveClasificacion = " & CveClasificacion).Rows(0)("Clasificacion").ToString
|
|
|
|
AddPS(Material("CveMaterialUtilizado").ToString.ToEntero, CveOSDetalle, Material("Cantidad").ToString.ToDecimal, CveUnidadMedida, UM, Material("CvePS").ToString.ToEntero, PS, CveClasificacion, Clasificacion, Material("SeFacturara").ToString)
|
|
Next
|
|
End If
|
|
objOS.Dispose()
|
|
|
|
If ViewState("Orden").ToString() <> String.Empty Then
|
|
CargaGrid(ViewState("Orden").ToString())
|
|
Else
|
|
CargaGrid("")
|
|
End If
|
|
Catch ex As Exception
|
|
Alert("Error al cargar los Materiales", TipoMensaje.MsgError)
|
|
End Try
|
|
End Sub
|
|
|
|
#Region "G V D A T O S"
|
|
Protected Sub GvPS_RowCancelingEdit(sender As Object, e As GridViewCancelEditEventArgs) Handles GvPS.RowCancelingEdit
|
|
GvPS.EditIndex = -1
|
|
If ViewState("Orden").ToString() <> String.Empty Then
|
|
CargaGrid(ViewState("Orden").ToString())
|
|
Else
|
|
CargaGrid("")
|
|
End If
|
|
End Sub
|
|
|
|
Protected Sub GvPS_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvPS.RowDataBound
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
e.Row.Cells(0).Width = Unit.Pixel(50)
|
|
e.Row.Cells(1).Width = Unit.Pixel(60)
|
|
e.Row.Cells(2).Width = Unit.Pixel(230)
|
|
|
|
If e.Row.Cells(3).Visible = True Then
|
|
e.Row.Cells(3).Width = Unit.Pixel(80)
|
|
e.Row.Cells(4).Width = Unit.Pixel(100)
|
|
Else
|
|
e.Row.Cells(4).Width = Unit.Pixel(180)
|
|
End If
|
|
|
|
'e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Left
|
|
|
|
If e.Row.RowState = DataControlRowState.Edit OrElse e.Row.RowState = 5 Then
|
|
e.Row.FCDropDownList("DdlPS").DataSource = DTPS
|
|
e.Row.FCDropDownList("DdlPS").DataBind()
|
|
e.Row.FCDropDownList("DdlPS").SelectedValue = e.Row.DBCampo("CvePS")
|
|
|
|
e.Row.FCDropDownList("DdlClasificacion").DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa)
|
|
e.Row.FCDropDownList("DdlClasificacion").DataBind()
|
|
e.Row.FCDropDownList("DdlClasificacion").SelectedValue = e.Row.DBCampo("CveClasificacion")
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
Protected Sub GvPS_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles GvPS.RowEditing
|
|
GvPS.EditIndex = e.NewEditIndex
|
|
If ViewState("Orden").ToString() <> String.Empty Then
|
|
CargaGrid(ViewState("Orden").ToString())
|
|
Else
|
|
CargaGrid("")
|
|
End If
|
|
End Sub
|
|
|
|
Protected Sub GvPS_RowDeleting(sender As Object, e As GridViewDeleteEventArgs) Handles GvPS.RowDeleting
|
|
Dim CveMaterialUtilizado As Integer = GvPS.DataKeys(e.RowIndex).Value.ToString.ToEntero
|
|
|
|
If CveMaterialUtilizado > 0 Then
|
|
Dim objMateriales As New ClsOS
|
|
If objMateriales.RemoveDetalleMateriales(CveMaterialUtilizado, CveOSDetalle) Then
|
|
|
|
End If
|
|
End If
|
|
Dim i As Integer = TmpDT.Rows.IndexOf(TmpDT.Rows(e.RowIndex))
|
|
|
|
TmpDT.Rows.RemoveAt(i)
|
|
|
|
UpTitulos.Update()
|
|
|
|
If ViewState("Orden").ToString() <> String.Empty Then
|
|
CargaGrid(ViewState("Orden").ToString())
|
|
Else
|
|
CargaGrid("")
|
|
End If
|
|
End Sub
|
|
#End Region
|
|
|
|
#Region "O R D E N A M I E N T O"
|
|
Protected Sub LbOrden_Click(ByVal sender As Object, ByVal e As EventArgs)
|
|
Dim Orden As String = ""
|
|
Dim Campo As String = ""
|
|
Dim Literal As Literal = Nothing
|
|
Const OrdenInicial As String = ""
|
|
Dim Arg(2) As String
|
|
|
|
Arg = CType(sender, LinkButton).CommandArgument().ToString.Split(";"c)
|
|
Campo = Arg(0)
|
|
Literal = CType(CType(sender, LinkButton).NamingContainer.FindControl("Img" & Campo.Replace(",", "_")), Literal)
|
|
|
|
If ViewState(String.Format("O{0}", Campo)) IsNot Nothing AndAlso ViewState(String.Format("O{0}", Campo)).ToString = String.Format("{0} DESC", Campo) Then
|
|
ViewState(String.Format("O{0}", Campo)) = String.Format("{0} ASC", Campo)
|
|
Literal.Text = String.Format("<i class='fa fa-sort-asc' style='color:#999' ></i>")
|
|
Else
|
|
ViewState(String.Format("O{0}", Campo)) = String.Format("{0} DESC", Campo)
|
|
Literal.Text = String.Format("<i class='fa fa-sort-desc' style='color:#999' ></i>")
|
|
End If
|
|
Orden = OrdenInicial & ViewState(String.Format("O{0}", Campo)).ToString
|
|
ViewState("Orden") = Orden
|
|
CargaGrid(Orden)
|
|
End Sub
|
|
|
|
Private Sub CargaGrid(Orden As String)
|
|
If Orden <> String.Empty Then
|
|
GvPS.DataSource = TmpDT.FiltraParametros("", Orden)
|
|
Else
|
|
GvPS.DataSource = TmpDT
|
|
End If
|
|
GvPS.DataBind()
|
|
UpDatos.Update()
|
|
End Sub
|
|
#End Region
|
|
|
|
Protected Sub LbAgregar_Click(sender As Object, e As EventArgs) Handles LbAgregar.Click
|
|
If TmpDT.FiltraParametros("CvePS = " + DdlPS.SelectedValue.ToString).Rows.Count = 0 Then
|
|
AddPS(-(TmpDT.Rows.Count + 1), CveOSDetalle, TxtCantidad.Text.ToDecimal, HdnUnidadMedida.Value.ToEntero, LblUnidadMedida.Text, DdlPS.SelectedValue.ToEntero, DdlPS.SelectedItem.Text, DdlClasificacion.SelectedValue.ToEntero, DdlClasificacion.SelectedItem.Text, "Sí")
|
|
UpTitulos.Update()
|
|
End If
|
|
DdlClasificacion.SelectedIndex = 0
|
|
DdlPS.SelectedIndex = 0
|
|
TxtCantidad.Text = ""
|
|
End Sub
|
|
|
|
Private Sub AddPS(CveMaterialUtilizado As Integer, CveOSDetalle As Integer, Cantidad As Decimal, CveUnidadMedida As Integer, UM As String, CvePS As Integer, PS As String, CveClasificacion As Integer, Clasificacion As String, SeFacturara As String)
|
|
Dim Row As DataRow = Nothing
|
|
Row = TmpDT.NewRow()
|
|
|
|
Row("Consecutivo") = Consecutivo
|
|
Row("CveMaterialUtilizado") = CveMaterialUtilizado
|
|
Row("CveOSDetalle") = CveOSDetalle
|
|
Row("Cantidad") = Cantidad
|
|
Row("CveUnidadMedida") = CveUnidadMedida
|
|
Row("UM") = UM
|
|
Row("CvePS") = CvePS
|
|
Row("PS") = PS
|
|
Row("CveClasificacion") = CveClasificacion
|
|
Row("Clasificacion") = Clasificacion
|
|
Row("SeFacturara") = SeFacturara
|
|
Row("SeFacturaraTexto") = If(SeFacturara = "1", "Si", "No")
|
|
|
|
TmpDT.Rows.Add(Row)
|
|
GvPS.DataSource = TmpDT
|
|
GvPS.DataBind()
|
|
|
|
UpDatos.Update()
|
|
End Sub
|
|
|
|
Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs) Handles BtnGuardar.Click
|
|
'Guardar los materiales directo a la base de datos
|
|
Dim objMateriales As New ClsOS
|
|
|
|
For Each R As DataRow In TmpDT.Rows
|
|
If R("CveMaterialUtilizado").ToString.ToEntero < 0 Then
|
|
objMateriales.AddDetalleMateriales(R("CveOsDetalle").ToString.ToEntero, R("Cantidad").ToString.ToDecimal, R("CveUnidadMedida").ToString.ToEntero, R("CvePS").ToString.ToEntero, If(R("SeFacturara").ToString = "1", True, False))
|
|
Else
|
|
objMateriales.UpdateDetalleMateriales(R("CveMaterialUtilizado").ToString.ToEntero, R("CveOsDetalle").ToString.ToEntero, R("Cantidad").ToString.ToDecimal, R("CveUnidadMedida").ToString.ToEntero, R("CvePS").ToString.ToEntero, If(R("SeFacturara").ToString = "1", True, False))
|
|
End If
|
|
Next
|
|
objMateriales.Dispose()
|
|
'RegistraScript(String.Format("CargaEspecificaciones('{0}', '{1}');", Especificaciones, EspecificacionesS))
|
|
RegistraScript(String.Format("CargaMateriales('{0}', '{1}');", "", Consecutivo))
|
|
End Sub
|
|
|
|
Protected Sub DdlClasificacion_SelectedIndexChanged1(sender As Object, e As EventArgs)
|
|
Dim ddl As DropDownList = DirectCast(sender, DropDownList)
|
|
Dim DdlGVPS As DropDownList = Nothing
|
|
|
|
Dim gvr As GridViewRow = DirectCast(ddl.NamingContainer, GridViewRow)
|
|
|
|
DdlGVPS = GvPS.Rows(gvr.RowIndex).FCDropDownList("DdlPS")
|
|
If DdlGVPS IsNot Nothing Then CargaPS(DirectCast(sender, DropDownList).SelectedValue.ToEntero, DdlGVPS)
|
|
End Sub
|
|
|
|
Protected Sub DdlPS_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlPS.SelectedIndexChanged
|
|
If DdlPS.SelectedIndex > 1 Then
|
|
Dim PS As DataTable = DTPS.FiltraParametros("CvePS = " & DdlPS.SelectedValue)
|
|
If PS.Rows.Count > 0 Then
|
|
HdnUnidadMedida.Value = PS.Rows(0)("CveUnidadMedida").ToString
|
|
LblUnidadMedida.Text = PS.Rows(0)("UnidadMedida").ToString
|
|
DdlClasificacion.SelectedValue = PS.Rows(0)("CveClasificacion").ToString
|
|
End If
|
|
'RegistraScript("Recalcula();")
|
|
PS.Dispose()
|
|
UpTitulos.Update()
|
|
ElseIf DdlPS.SelectedValue = "-2" Then
|
|
CargaPS(-1, DdlPS)
|
|
End If
|
|
End Sub
|
|
|
|
Protected Sub BtnCancelar_Click(sender As Object, e As EventArgs) Handles BtnCancelar.Click
|
|
RegistraScript("Cancelar();")
|
|
End Sub
|
|
|
|
Protected Sub GvPS_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles GvPS.RowUpdating
|
|
Dim Cantidad As Decimal = GvPS.Rows(e.RowIndex).FCTextBox("txtCantidad").Text.ToDecimal
|
|
Dim CveClasificacion As Integer = GvPS.Rows(e.RowIndex).FCDropDownList("DdlClasificacion").SelectedValue.ToEntero
|
|
Dim Clasificacion As String = GvPS.Rows(e.RowIndex).FCDropDownList("DdlClasificacion").SelectedItem.Text
|
|
Dim CvePS As Integer = GvPS.Rows(e.RowIndex).FCDropDownList("DdlPS").SelectedValue.ToEntero
|
|
Dim PS As String = GvPS.Rows(e.RowIndex).FCDropDownList("DdlPS").SelectedItem.Text
|
|
Dim SeFacturara As String = If(GvPS.Rows(e.RowIndex).FCCheckBox("ChkSeFacturara").Checked, "1", "0")
|
|
|
|
TmpDT.Rows(e.RowIndex)("Cantidad") = Cantidad
|
|
TmpDT.Rows(e.RowIndex)("CveClasificacion") = CveClasificacion
|
|
TmpDT.Rows(e.RowIndex)("Clasificacion") = Clasificacion
|
|
TmpDT.Rows(e.RowIndex)("CvePS") = CvePS
|
|
TmpDT.Rows(e.RowIndex)("PS") = PS
|
|
TmpDT.Rows(e.RowIndex)("SeFacturara") = SeFacturara
|
|
TmpDT.Rows(e.RowIndex)("SeFacturaraTexto") = If(SeFacturara = "1", "Si", "No")
|
|
|
|
GvPS.EditIndex = -1
|
|
GvPS.DataSource = TmpDT
|
|
GvPS.DataBind()
|
|
|
|
End Sub
|
|
End Class
|