Imports System.Data
Imports Extensiones
Partial Class Nomina_CatConceptos
Inherits ClsPaginas
Private Property DTCuentas As DataTable
Get
Return CType(ViewState("DTCuentas"), DataTable)
End Get
Set(value As DataTable)
ViewState("DTCuentas") = value
End Set
End Property
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
ViewState("Orden") = ""
CargaDdls()
CargaDatos()
CargaPadres()
End If
End Sub
Public Sub CargaDatos()
Dim ObjNomina As New ClsNominas
If ObjNomina.GetConceptos(UsuarioActual.CveEmpresa) Then
ViewState("DTNomConceptos") = ObjNomina.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa)
GlobalDTNomConceptos(-1) = ObjNomina.DtResultados
Else
Me.GvDatos.DataSource = Nothing
End If
ObjNomina.Dispose()
If ViewState("Orden").ToString() <> String.Empty Then
CargaGrid(ViewState("Orden").ToString())
Else
CargaGrid("")
End If
End Sub
Private Sub CargaDdls()
Dim ObjConta As New ClsContPAQi(UsuarioActual.Empresa)
If ObjConta.GetCuentas(-1, "-1", 1) Then
DTCuentas = ObjConta.DtResultados
End If
DdlContaConceptos.DataSource = GlobalDTContaConceptosContables(-1)
DdlContaConceptos.DataBind()
DdlContaConceptos.Items.Add(New ListItem("Sin Asignar", "-1"))
DdlContaConceptos.SelectedValue = "-1"
DdlClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa)
DdlClasificacion.DataBind()
DdlClasificacion.Items.Add(New ListItem("Sin Asignar", "-1"))
DdlClasificacion.SelectedValue = "-1"
DdlCtaContable.Items.Add(New ListItem("Sin Asignar", "-1"))
End Sub
Public Sub CargaPadres()
DdlPadre.DataSource = CType(ViewState("DTNomConceptos"), DataTable)
DdlPadre.DataBind()
DdlPadre.Items.Insert(0, New ListItem("", "-1"))
UpDatos.Update()
End Sub
Protected Sub LbAgregar_Click(sender As Object, e As EventArgs) Handles LbAgregar.Click
Dim ObjNomina As New ClsNominas
If ObjNomina.AddConcepto(TxtCodigo.Text.Trim, TxtConcepto.Text.Trim, DdlTipo.SelectedValue, TxtFormula.Text.Trim, ChkSistema.Checked, If(DdlTipoCalculo.SelectedValue.ToString = "0", False, True), True, DdlPadre.SelectedValue.ToEntero, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, DdlContaConceptos.SelectedValue, ChkRetencion.Checked, DdlClasificacion.SelectedValue.ToEntero, DdlCtaContable.SelectedValue.ToEntero) Then
TxtCodigo.Text = ""
TxtConcepto.Text = ""
DdlTipo.SelectedValue = "-1"
TxtFormula.Text = ""
Alert("El nuevo Concepto de Nómina se guardó correctamente.", TipoMensaje.MsgInformacion)
'UpTitulos.Update()
ViewState("DTNomConceptos") = ObjNomina.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa)
GlobalDTNomConceptos(-1) = ObjNomina.DtResultados
If ViewState("Orden").ToString() <> String.Empty Then
CargaGrid(ViewState("Orden").ToString())
Else
CargaGrid("")
End If
UpDatos.Update()
End If
ObjNomina.Dispose()
End Sub
Private Function ValidaFormula(Formula As String) As String
Dim Retorno As String = "Error en Fórmula"
Try
'tengo que cargar la definición de las variables, vienen del globaldt
Dim exp As FormulaEvaluator.Expression
For Each dr As DataRow In GlobalDTNomConceptosFunciones.Rows
exp = New FormulaEvaluator.Expression(String.Format("{0}:=1", dr("Funcion")))
exp.Eval()
Next
'Dim expr As String = Script.ToString
exp = New FormulaEvaluator.Expression(Formula)
If (exp.Errors.Count > 0) Then
Retorno = exp.Errors(0).Message
End If
Dim val As Object = exp.Eval()
If (exp.Errors.Count = 0) Then
Retorno = ""
Else
Retorno = exp.Errors(0).Message
End If
Catch ex As Exception
End Try
Return Retorno
End Function
Protected Sub BtnFormula_Click(sender As Object, e As EventArgs) Handles BtnFormula.Click
Alert(ValidaFormula(TxtFormula.Text), TipoMensaje.MsgInformacion)
End Sub
Protected Sub btnIngresarPredeterminados_Click(sender As Object, e As EventArgs) Handles btnIngresarPredeterminados.Click
Dim ObjNomina As New ClsNominas
If ObjNomina.GetConceptos(UsuarioActual.CveEmpresa) Then
For Each Row As DataRow In ObjNomina.DtResultados.FiltraParametros("CveEmpresa is null").Rows
Dim Codigo As String = Row("Codigo").ToString
Dim Concepto As String = Row("Concepto").ToString
Dim Tipo As String = Row("Tipo").ToString
Dim Formula As String = Row("Formula").ToString
Dim CveConceptoPadre As Integer = If(Not Row("Formula") Is Nothing, Row("CveConceptoPadre").ToString.ToEntero, -1)
Dim Sistema As Boolean = CType(Row("Sistema").ToString, Boolean)
Dim TipoCalculo As Boolean = CType(Row("TipoCalculo").ToString, Boolean)
ObjNomina.AddConcepto(Codigo, Concepto, Tipo, Formula, Sistema, TipoCalculo, True, CveConceptoPadre, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, False, -1, -1)
Next
End If
ObjNomina.Dispose()
CargaDatos()
End Sub
#Region "G V D A T O S"
Protected Sub GvDatos_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvDatos.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Cells(0).Width = Unit.Pixel(80)
e.Row.Cells(1).Width = Unit.Pixel(80)
e.Row.Cells(2).Width = Unit.Pixel(181)
e.Row.Cells(3).Width = Unit.Pixel(120)
e.Row.Cells(4).Width = Unit.Pixel(100)
e.Row.Cells(5).Width = Unit.Pixel(85)
e.Row.Cells(6).Width = Unit.Pixel(100)
e.Row.Cells(7).Width = Unit.Pixel(100)
e.Row.Cells(8).Width = Unit.Pixel(100)
e.Row.Cells(9).Width = Unit.Pixel(59)
e.Row.Cells(10).Width = Unit.Pixel(111)
e.Row.Cells(11).Width = Unit.Pixel(80)
e.Row.Cells(12).Width = Unit.Pixel(81)
e.Row.Cells(13).Width = Unit.Pixel(81)
e.Row.Cells(14).Width = Unit.Pixel(89)
e.Row.Cells(15).Width = Unit.Pixel(61)
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Center
e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Center
e.Row.Cells(2).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(3).HorizontalAlign = HorizontalAlign.Center
e.Row.Cells(4).HorizontalAlign = HorizontalAlign.Center
e.Row.Cells(5).HorizontalAlign = HorizontalAlign.Center
e.Row.Cells(6).HorizontalAlign = HorizontalAlign.Center
e.Row.Cells(7).HorizontalAlign = HorizontalAlign.Center
e.Row.Cells(8).HorizontalAlign = HorizontalAlign.Center
e.Row.Cells(9).HorizontalAlign = HorizontalAlign.Center
e.Row.Cells(10).HorizontalAlign = HorizontalAlign.Center
e.Row.Cells(11).HorizontalAlign = HorizontalAlign.Center
e.Row.Cells(12).HorizontalAlign = HorizontalAlign.Center
e.Row.Cells(13).HorizontalAlign = HorizontalAlign.Center
e.Row.Cells(14).HorizontalAlign = HorizontalAlign.Center
e.Row.Cells(15).HorizontalAlign = HorizontalAlign.Center
If IsNumeric(e.Row.DBCampo("CveConceptoPadre")) Then
e.Row.BackColor = Drawing.Color.Silver
End If
If e.Row.RowState = DataControlRowState.Edit OrElse e.Row.RowState = 5 Then
e.Row.FCDropDownList("DdlPadreGV").DataSource = CType(ViewState("DTNomConceptos"), DataTable)
e.Row.FCDropDownList("DdlPadreGV").DataBind()
e.Row.FCDropDownList("DdlPadreGV").Items.Insert(0, New ListItem("", "-1"))
e.Row.FCDropDownList("DdlPadreGV").SelectedValue = e.Row.DBCampo("CveConceptoPadre")
e.Row.FCDropDownList("DdlTipoGV").SelectedValue = e.Row.DBCampo("Tipo")
e.Row.FCDropDownList("DdlTipoCalculoGV").SelectedValue = e.Row.DBCampo("TipoCalculo")
e.Row.FCDropDownList("DdlClasificacion").DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa)
e.Row.FCDropDownList("DdlClasificacion").DataBind()
e.Row.FCDropDownList("DdlClasificacion").Items.Add(New ListItem("Sin Asignar", "-1"))
e.Row.FCDropDownList("DdlClasificacion").SelectedValue = If(e.Row.DataKey("CveClasificacion") = "", "-1", e.Row.DataKey("CveClasificacion"))
e.Row.FCDropDownList("DdlConceptoContable").DataSource = GlobalDTContaConceptosContables(-1)
e.Row.FCDropDownList("DdlConceptoContable").DataBind()
e.Row.FCDropDownList("DdlConceptoContable").Items.Add(New ListItem("Sin Asignar", "-1"))
e.Row.FCDropDownList("DdlConceptoContable").SelectedValue = If(e.Row.DataKey("CveConceptoContable") = "", "-1", e.Row.DataKey("CveConceptoContable"))
e.Row.FCCheckBox("ChkRetencion").Checked = e.Row.DataKey("EsRetencion")
If e.Row.FCCheckBox("ChkRetencion").Checked Then
e.Row.FCDropDownList("DdlClasificacion").Enabled = False
e.Row.FCDropDownList("DdlCtaContable").Enabled = True
e.Row.FCDropDownList("DdlCtaContable").DataSource = DTCuentas
e.Row.FCDropDownList("DdlCtaContable").DataBind()
e.Row.FCDropDownList("DdlCtaContable").Items.Add(New ListItem("Sin Asignar", "-1"))
e.Row.FCDropDownList("DdlCtaContable").SelectedValue = If(e.Row.DataKey("IdCtaContable") = "", "-1", e.Row.DataKey("IdCtaContable"))
Else
e.Row.FCDropDownList("DdlClasificacion").Enabled = True
e.Row.FCDropDownList("DdlCtaContable").Enabled = False
e.Row.FCDropDownList("DdlCtaContable").Items.Clear()
e.Row.FCDropDownList("DdlCtaContable").Items.Add(New ListItem("Sin Asignar", "-1"))
End If
Else
e.Row.FCLiteral("LtlCuentaContable").Text = If(e.Row.DataKey("IdCtaContable") = "", "Sin Asignar", DTCuentas.FiltroPrimeroValor("CtaCodigo", $"Id={e.Row.DataKey("IdCtaContable")}"))
End If
End If
End Sub
Protected Sub GvDatos_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvDatos.RowDeleting
Dim ObjNomina As New ClsNominas
If ObjNomina.RemoveConcepto(GvDatos.DataKeys(e.RowIndex).Value.ToString.ToEntero, UsuarioActual.CveEmpresa) Then
GvDatos.EditIndex = -1
ViewState("DTNomConceptos") = ObjNomina.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa)
GlobalDTNomConceptos(-1) = ObjNomina.DtResultados
Alert("El Concepto de Nómina se eliminó correctamente.", TipoMensaje.MsgInformacion)
If ViewState("Orden").ToString() <> String.Empty Then
CargaGrid(ViewState("Orden").ToString())
Else
CargaGrid("")
End If
UpDatos.Update()
End If
ObjNomina.Dispose()
End Sub
Protected Sub GvDatos_RowCancelingEdit(sender As Object, e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GvDatos.RowCancelingEdit
GvDatos.EditIndex = -1
If ViewState("Orden").ToString() <> String.Empty Then
CargaGrid(ViewState("Orden").ToString())
Else
CargaGrid("")
End If
End Sub
Protected Sub GvDatos_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GvDatos.RowUpdating
Dim ObjNomina As New ClsNominas
Dim Codigo As String = DirectCast(GvDatos.Rows(e.RowIndex).FindControl("TxtCodigoGV"), TextBox).Text.Trim
Dim Concepto As String = DirectCast(GvDatos.Rows(e.RowIndex).FindControl("TxtConceptoGV"), TextBox).Text.Trim
Dim Tipo As String = DirectCast(GvDatos.Rows(e.RowIndex).FindControl("DdlTipoGV"), DropDownList).SelectedValue
Dim Formula As String = DirectCast(GvDatos.Rows(e.RowIndex).FindControl("TxtFormulaGV"), TextBox).Text.Trim
Dim Sistema As Boolean = GvDatos.Rows(e.RowIndex).FCCheckBox("ChkSistemaGV").Checked
Dim TipoCalculo As Boolean = If(DirectCast(GvDatos.Rows(e.RowIndex).FindControl("DdlTipoCalculoGV"), DropDownList).SelectedValue = "0", False, True)
Dim Estado As Boolean = GvDatos.Rows(e.RowIndex).FCCheckBox("ChkEstadoGV").Checked
Dim CveConceptoPadre As Integer = DirectCast(GvDatos.Rows(e.RowIndex).FindControl("DdlPadreGV"), DropDownList).SelectedValue.ToEntero
Dim CveConcepto As Integer = GvDatos.Rows(e.RowIndex).DataKey("CveConcepto").ToEntero
Dim CveConceptoContable As Integer = DirectCast(GvDatos.Rows(e.RowIndex).FindControl("DdlConceptoContable"), DropDownList).SelectedValue
Dim EsRetencion As Boolean = DirectCast(GvDatos.Rows(e.RowIndex).FindControl("ChkRetencion"), CheckBox).Checked
Dim CveClasificacion As Integer = DirectCast(GvDatos.Rows(e.RowIndex).FindControl("DdlClasificacion"), DropDownList).SelectedValue
Dim IdCtaContable As Integer = DirectCast(GvDatos.Rows(e.RowIndex).FindControl("DdlCtaContable"), DropDownList).SelectedValue
If ObjNomina.UpdateConcepto(Codigo, Concepto, Tipo, Formula, Sistema, TipoCalculo, Estado, CveConceptoPadre, CveConcepto, UsuarioActual.CveEmpresa, CveConceptoContable, EsRetencion, CveClasificacion, IdCtaContable) Then
GvDatos.EditIndex = -1
ViewState("DTNomConceptos") = ObjNomina.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa)
GlobalDTNomConceptos(-1) = ObjNomina.DtResultados
Alert("Los cambios se guardaron correctamente.", TipoMensaje.MsgInformacion)
If ViewState("Orden").ToString() <> String.Empty Then
CargaGrid(ViewState("Orden").ToString())
Else
CargaGrid("")
End If
UpDatos.Update()
End If
ObjNomina.Dispose()
End Sub
Protected Sub GvDatos_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GvDatos.RowEditing
GvDatos.EditIndex = e.NewEditIndex
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("")
Else
ViewState(String.Format("O{0}", Campo)) = String.Format("{0} DESC", Campo)
Literal.Text = String.Format("")
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
Dim DV As New DataView(CType(ViewState("DTNomConceptos"), DataTable), "", Orden, DataViewRowState.CurrentRows)
GvDatos.DataSource = DV.ToTable()
DV.Dispose()
Else
GvDatos.DataSource = CType(ViewState("DTNomConceptos"), DataTable)
End If
GvDatos.DataBind()
UpDatos.Update()
End Sub
Private Sub ChkRetencion_CheckedChanged(sender As Object, e As EventArgs) Handles ChkRetencion.CheckedChanged
If ChkRetencion.Checked Then
DdlClasificacion.SelectedValue = "-1"
DdlClasificacion.Enabled = False
DdlCtaContable.Enabled = True
DdlCtaContable.DataSource = DTCuentas
DdlCtaContable.DataBind()
DdlCtaContable.Items.Add(New ListItem("Sin Asignar", "-1"))
Else
DdlClasificacion.Enabled = True
DdlCtaContable.Enabled = False
DdlCtaContable.Items.Clear()
DdlCtaContable.Items.Add(New ListItem("Sin Asignar", "-1"))
End If
UpTitulos.Update()
End Sub
Protected Sub ChkRetencion_CheckedChanged1(sender As Object, e As EventArgs)
Dim chk As CheckBox = DirectCast(sender, CheckBox)
Dim gr As GridViewRow = DirectCast(chk.Parent.Parent, GridViewRow)
If chk.Checked Then
gr.FCDropDownList("DdlClasificacion").SelectedValue = "-1"
gr.FCDropDownList("DdlClasificacion").Enabled = False
gr.FCDropDownList("DdlCtaContable").Enabled = True
gr.FCDropDownList("DdlCtaContable").DataSource = DTCuentas
gr.FCDropDownList("DdlCtaContable").DataBind()
gr.FCDropDownList("DdlCtaContable").Items.Add(New ListItem("Sin Asignar", "-1"))
Else
gr.FCDropDownList("DdlClasificacion").Enabled = True
gr.FCDropDownList("DdlCtaContable").Enabled = False
gr.FCDropDownList("DdlCtaContable").Items.Clear()
gr.FCDropDownList("DdlCtaContable").Items.Add(New ListItem("Sin Asignar", "-1"))
End If
UpTitulos.Update()
End Sub
End Class
#End Region