Option Explicit On Option Strict On Imports System.Data Imports System.Linq Imports Extensiones Partial Class CatClasificacionesDetalle Inherits ClsPaginas #Region " PROPIEDADES " Private Property CveClasificacion As Integer Get Return CType(ViewState("CveClasificacion"), Integer) End Get Set(value As Integer) ViewState("CveClasificacion") = value End Set End Property Public Property DtCuentas As DataTable Get Return CType((ViewState("DtCuentas")), DataTable) End Get Set(value As DataTable) ViewState("DtCuentas") = value End Set End Property #End Region Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then ViewState("Orden") = "" CveClasificacion = IfNull(Request("Cveclasificacion"), "-1").ToString.ToEntero If CveClasificacion > 0 Then If CargaDatos() Then DdlCategoria.DataSource = GlobalDTGralCategorias(UsuarioActual.CveEmpresa) DdlCategoria.DataBind() If UsuarioActual.Empresa.UsaContabilidad Then Dim Cuenta As New ClsContPAQi(UsuarioActual.Empresa) If Cuenta.GetCuentas(-1, "-1", -1) Then DtCuentas = Cuenta.DtResultados End If Cuenta.Dispose() Try DdlCuentaGasto.DataSource = DtCuentas : DdlCuentaGasto.DataBind() Catch ex As Exception End Try Try DdlCuentaCostos.DataSource = DtCuentas : DdlCuentaCostos.DataBind() Catch ex As Exception End Try Try DdlCuentaIngresos.DataSource = DtCuentas : DdlCuentaIngresos.DataBind() Catch ex As Exception End Try End If DdlCuentaGasto.Items.Insert(0, New ListItem("-", "-1")) DdlCuentaCostos.Items.Insert(0, New ListItem("-", "-1")) DdlCuentaIngresos.Items.Insert(0, New ListItem("-", "-1")) End If End If End If End Sub Private Sub CargaGlobal() Dim ObjClasificaciones As New ClsClasificaciones If ObjClasificaciones.GetClasificaciones() Then GlobalDTClasificaciones = ObjClasificaciones.DtResultados Else Alert("Ocurrió un error al cargar las clasificaciones generales. Por favor avisar a Sistemas.", TipoMensaje.MsgError) End If If ObjClasificaciones.GetClasificacionesSubProyecto(CveClasificacion, UsuarioActual.CveEmpresa) Then ViewState("DTClasificaciones") = ObjClasificaciones.DtResultados End If ObjClasificaciones.Dispose() End Sub Public Function CargaDatos() As Boolean Dim Retorno As Boolean = False Dim ObjClasificaciones As New ClsClasificaciones If ObjClasificaciones.GetClasificaciones() Then Dim dr As DataRow = ObjClasificaciones.DtResultados.FiltraParametros(String.Format("CveClasificacion = {0} AND CveEmpresa = {1}", CveClasificacion, UsuarioActual.CveEmpresa)).FiltroPrimero("") If dr IsNot Nothing Then TxtClasificacion.Text = dr("Clasificacion").ToString LblClasificacion.Text = dr("Clasificacion").ToString DdlCuentaGasto.SelectedValue = dr("IdCuentaGasto").ToString DdlCuentaCostos.SelectedValue = dr("IdCuentaCostos").ToString DdlCuentaIngresos.SelectedValue = dr("IdCuentaIngresos").ToString DdlCategoria.SelectedValue = dr("CveCategoria").ToString ChkEstado.Checked = dr("Estatus").ToString = "Activo" Retorno = True BtnGuardar.Visible = True If ObjClasificaciones.GetClasificacionesSubProyecto(CveClasificacion, UsuarioActual.CveEmpresa) Then ViewState("DTClasificaciones") = ObjClasificaciones.DtResultados Else Me.GvDatos.DataSource = Nothing End If End If End If ObjClasificaciones.Dispose() If ViewState("Orden").ToString() <> String.Empty Then CargaGrid(ViewState("Orden").ToString()) Else CargaGrid("") End If Return Retorno End Function Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs) Handles BtnGuardar.Click Dim ObjClasificaciones As New ClsClasificaciones If ObjClasificaciones.UpdateClasificacion(TxtClasificacion.Text, "", DdlCuentaGasto.SelectedValue.ToEntero, DdlCuentaGasto.SelectedItem.Text, DdlCuentaCostos.SelectedValue.ToEntero, DdlCuentaCostos.SelectedItem.Text, DdlCuentaIngresos.SelectedValue.ToEntero, DdlCuentaIngresos.SelectedItem.Text, ChkEstado.Checked, False, DdlCategoria.SelectedValue.ToEntero, UsuarioActual.CveUsuario, CveClasificacion) Then GvDatos.EditIndex = -1 ViewState("DTClasificaciones") = ObjClasificaciones.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) Alert("Los cambios se guardaron correctamente.", TipoMensaje.MsgInformacion) Else Alert("Ocurrió un error al guardar los cambios. Por favor vuelva a intentar.", TipoMensaje.MsgError) End If ObjClasificaciones.Dispose() CargaGlobal() 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 If e.Row.RowIndex = 0 Then e.Row.Cells(0).Width = Unit.Pixel(150) e.Row.Cells(1).Width = Unit.Pixel(150) e.Row.Cells(2).Width = Unit.Pixel(220) e.Row.Cells(3).Width = Unit.Pixel(220) e.Row.Cells(4).Width = Unit.Pixel(60) e.Row.Cells(5).Width = Unit.Pixel(61) 'e.Row.Cells(7).Width = Unit.Pixel(50) 'e.Row.Cells(8).Width = Unit.Pixel(50) End If If e.Row.RowState = DataControlRowState.Edit OrElse e.Row.RowState = 5 Then e.Row.FCDropDownList("DdlCuentaGasto").DataSource = DtCuentas e.Row.FCDropDownList("DdlCuentaGasto").DataBind() e.Row.FCDropDownList("DdlCuentaGasto").Items.Insert(0, New ListItem("-", "-1")) e.Row.FCDropDownList("DdlCuentaGasto").SelectedValue = e.Row.DBCampo("IdCuentaGasto") e.Row.FCDropDownList("DdlCuentaCostos").DataSource = DtCuentas e.Row.FCDropDownList("DdlCuentaCostos").DataBind() e.Row.FCDropDownList("DdlCuentaCostos").Items.Insert(0, New ListItem("-", "-1")) e.Row.FCDropDownList("DdlCuentaCostos").SelectedValue = e.Row.DBCampo("IdCuentaCostos") e.Row.FCDropDownList("DdlCuentaIngresos").DataSource = DtCuentas e.Row.FCDropDownList("DdlCuentaIngresos").DataBind() e.Row.FCDropDownList("DdlCuentaIngresos").Items.Insert(0, New ListItem("-", "-1")) e.Row.FCDropDownList("DdlCuentaIngresos").SelectedValue = e.Row.DBCampo("IdCuentaIngresos") 'e.Row.FCDropDownList("DdlCuentaInventario").DataSource = DtCuentas 'e.Row.FCDropDownList("DdlCuentaInventario").DataBind() ' e.Row.FCDropDownList("DdlCuentaInventario").Items.Insert(0, New ListItem("-", "-1")) ' e.Row.FCDropDownList("DdlCuentaInventario").SelectedValue = e.Row.DBCampo("IdCuentaInventario") End If 'If e.Row.DBCampo("IdCuentaContable").ToEntero > 0 Then ' Dim Dr As DataRow = DtCuentas.FiltroPrimero(String.Format("Id= {0}", e.Row.DBCampo("IdCuentaContable"))) ' If GvDatos.EditIndex <> e.Row.RowIndex Then ' If Dr IsNot Nothing Then ' e.Row.Cells(1).Text = Dr("Nombre").ToString ' End If ' End If 'End If e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left End If End Sub Protected Sub GvDatos_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvDatos.RowDeleting Dim ObjClasificaciones As New ClsClasificaciones If ObjClasificaciones.RemoveClasificacion(GvDatos.DataKeys(e.RowIndex).Value.ToString.ToEntero) Then GvDatos.EditIndex = -1 ViewState("DTClasificaciones") = ObjClasificaciones.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) Alert("La Clasificación se eliminó correctamente.", TipoMensaje.MsgInformacion) Else Alert("Ocurrió un error al eliminar la clasificación. Por favor vuelva a intentar.", TipoMensaje.MsgError) End If CargaGlobal() ObjClasificaciones.Dispose() If ViewState("Orden").ToString() <> String.Empty Then CargaGrid(ViewState("Orden").ToString()) Else CargaGrid("") End If 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 ObjClasificaciones As New ClsClasificaciones Dim CveSubProyecto As Integer = e.Keys("CveSubProyecto").ToString.ToEntero Dim tCveClasificacion As Integer = e.Keys("CveClasificacion").ToString.ToEntero Dim DdlGasto As DropDownList = GvDatos.Rows(e.RowIndex).FCDropDownList("DdlCuentaGasto") Dim DdlCostos As DropDownList = GvDatos.Rows(e.RowIndex).FCDropDownList("DdlCuentaCostos") Dim DdlIngresos As DropDownList = GvDatos.Rows(e.RowIndex).FCDropDownList("DdlCuentaIngresos") If ObjClasificaciones.UpdateClasificacionSubProyecto(tCveClasificacion, CveSubProyecto, DdlGasto.SelectedValue.ToEntero, DdlGasto.SelectedItem.Text, DdlCostos.SelectedValue.ToEntero, DdlCostos.SelectedItem.Text, DdlIngresos.SelectedValue.ToEntero, DdlIngresos.SelectedItem.Text) Then GvDatos.EditIndex = -1 ViewState("DTClasificaciones") = ObjClasificaciones.DtResultados Alert("Los cambios se guardaron correctamente.", TipoMensaje.MsgInformacion) Else Alert("Ocurrió un error al actualizar la clasificación. Por favor vuelva a intentar.", TipoMensaje.MsgError) End If ObjClasificaciones.Dispose() If ViewState("Orden").ToString() <> String.Empty Then CargaGrid(ViewState("Orden").ToString()) Else CargaGrid("") End If 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 CargaGlobal() 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("DTClasificaciones"), DataTable), "", Orden, DataViewRowState.CurrentRows) GvDatos.DataSource = DV.ToTable() DV.Dispose() Else GvDatos.DataSource = CType(ViewState("DTClasificaciones"), DataTable) End If GvDatos.DataBind() UpDatos.Update() End Sub #End Region End Class