Option Explicit On Option Strict On Imports System.Data Imports System.Linq Imports Extensiones Partial Class Ventas_CatClasificaciones2 Inherits ClsPaginas Public 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("Orden1") = "" ViewState("Orden2") = "" DdlCategoriaS.DataSource = GlobalDTGralCategorias2(UsuarioActual.CveEmpresa) 'GlobalDTGralCategorias(UsuarioActual.CveEmpresa) DdlCategoriaS.DataBind() If UsuarioActual.Empresa.UsaContabilidad Then 'Dim Cuenta As New ClsContPAQi(UsuarioActual.Empresa) 'If Cuenta.GetCuentas(-1, "-1", 1, 20000) Then ' DtCuentas = Cuenta.DtResultados 'End If 'Cuenta.Dispose() 'DdlCuentaGastoS.DataSource = DtCuentas : DdlCuentaGastoS.DataBind() 'DdlCuentaAnticipoS.DataSource = DtCuentas : DdlCuentaAnticipoS.DataBind() 'DdlCuentaInventarioS.DataSource = DtCuentas : DdlCuentaInventarioS.DataBind() Else 'SubFamilia GvDatosS.Columns(1).Visible = False GvDatosS.Columns(2).Visible = False GvDatosS.Columns(3).Visible = False TbHeaderS.Rows(0).Cells(1).Visible = False TbHeaderS.Rows(0).Cells(2).Visible = False TbHeaderS.Rows(0).Cells(3).Visible = False TbHeaderS.Rows(1).Cells(1).Visible = False TbHeaderS.Rows(1).Cells(2).Visible = False TbHeaderS.Rows(1).Cells(3).Visible = False End If CargaDatos() CargaDatosS() End If End Sub Public Sub CargaDatos() Dim ObjCategorias As New ClsGenerales If ObjCategorias.GetCategorias(UsuarioActual.CveEmpresa, 4) Then ViewState("DTCategorias2") = ObjCategorias.DtResultados Else GvDatos.DataSource = Nothing End If ObjCategorias.Dispose() 'ViewState("DTFamilias") = GlobalDTGralCategorias2 If ViewState("Orden1").ToString() <> String.Empty Then CargaGrid(ViewState("Orden1").ToString()) Else CargaGrid("") End If End Sub Public Sub CargaDatosS() Dim ObjClasificaciones As New ClsClasificaciones If ObjClasificaciones.GetClasificaciones(-1, 4) Then GlobalDTClasificaciones2 = ObjClasificaciones.DtResultados ViewState("DTClasificacion2") = GlobalDTClasificaciones2(UsuarioActual.CveEmpresa) Else GvDatosS.DataSource = Nothing End If ObjClasificaciones.Dispose() If ViewState("Orden2").ToString() <> String.Empty Then CargaGridS(ViewState("Orden2").ToString()) Else CargaGridS("") End If End Sub 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("Orden1") = Orden CargaGrid(Orden) End Sub Protected Sub LbOrdenS_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(",", "_") & "S"), 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("Orden1") = Orden CargaGridS(Orden) End Sub Private Sub CargaGrid(Orden As String) If Orden <> String.Empty Then Dim DV As New DataView(CType(ViewState("DTCategorias2"), DataTable), "", Orden, DataViewRowState.CurrentRows) GvDatos.DataSource = DV.ToTable() DV.Dispose() Else GvDatos.DataSource = CType(ViewState("DTCategorias2"), DataTable) End If GvDatos.DataBind() UpDatosF.Update() End Sub Private Sub CargaGridS(Orden As String) If Orden <> String.Empty Then Dim DV As New DataView(CType(ViewState("DTClasificacion2"), DataTable), "", Orden, DataViewRowState.CurrentRows) GvDatosS.DataSource = DV.ToTable().FiltraParametros("1=1") 'SubFamilia--------------------------------------------------------------- DV.Dispose() Else GvDatosS.DataSource = CType(ViewState("DTClasificacion2"), DataTable).FiltraParametros("1=1") 'SubFamilia---------------------------- End If GvDatosS.DataBind() UpDatosS.Update() End Sub Protected Sub LbAgregar_Click(sender As Object, e As EventArgs) Handles LbAgregar.Click Dim ObjCategorias As New ClsGenerales If ObjCategorias.AddCategorias(TxtCategoria.Text.Trim, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 4) Then TxtCategoria.Text = "" Alert("La nueva Categoria 2 se guardó correctamente.", TipoMensaje.MsgInformacion) UpTitulosF.Update() 'ViewState("DTFamilias") = ObjCategorias.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) 'GlobalDTGralCategorias2(UsuarioActual.CveEmpresa) = ObjCategorias.DtResultados If ObjCategorias.GetCategorias(-1, 4) Then ViewState("DTCategorias2") = ObjCategorias.DtResultados.FiltraParametros(String.Format("CveEmpresa = {0}", UsuarioActual.CveEmpresa)) GlobalDTGralCategorias2(UsuarioActual.CveEmpresa) = ObjCategorias.DtResultados CargaDdlCat() End If If ViewState("Orden1").ToString() <> String.Empty Then CargaGrid(ViewState("Orden1").ToString()) Else CargaGrid("") End If End If ObjCategorias.Dispose() End Sub Protected Sub LbAgregarS_Click(sender As Object, e As EventArgs) Handles LbAgregarS.Click Dim ObjClasificaciones As New ClsClasificaciones If ObjClasificaciones.AddClasificaciones(TxtClasificacionS.Text.Trim, "", -1, "", -1, "", -1, "", DdlCategoriaS.SelectedValue.ToEntero, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, RequiereAFCompra:=False, RequiereAFInsumo:=False, RequierePersonal:=False) Then 'DdlCuentaGastoS.SelectedValue.ToEntero, DdlCuentaGastoS.SelectedItem.Text, 'DdlCuentaAnticipoS.SelectedValue.ToEntero, DdlCuentaAnticipoS.SelectedItem.Text, 'DdlCuentaInventarioS.SelectedValue.ToEntero, DdlCuentaInventarioS.SelectedItem.Text, TxtClasificacionS.Text = "" Alert("La nueva Clasificación se guardó correctamente.", TipoMensaje.MsgInformacion) UpTitulosS.Update() If ObjClasificaciones.GetClasificaciones(-1, 4) Then ViewState("DTClasificacion2") = ObjClasificaciones.DtResultados.FiltraParametros(String.Format("CveEmpresa = {0}", UsuarioActual.CveEmpresa)) GlobalDTClasificaciones2 = ObjClasificaciones.DtResultados End If 'DdlCuentaGastoS.SelectedValue = "-1" 'DdlCuentaAnticipoS.SelectedValue = "-1" 'DdlCuentaInventarioS.SelectedValue = "-1" If ViewState("Orden2").ToString() <> String.Empty Then CargaGridS(ViewState("Orden2").ToString()) Else CargaGridS("") End If End If ObjClasificaciones.Dispose() End Sub Protected Sub GvDatos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDatos.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.RowIndex = 0 Then e.Row.Cells(0).Width = Unit.Pixel(350) e.Row.Cells(1).Width = Unit.Pixel(100) e.Row.Cells(2).Width = Unit.Pixel(100) e.Row.Cells(3).Width = Unit.Pixel(100) e.Row.Cells(4).Width = Unit.Pixel(100) e.Row.Cells(5).Width = Unit.Pixel(65) End If e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Center e.Row.Cells(2).HorizontalAlign = HorizontalAlign.Center e.Row.Cells(3).HorizontalAlign = HorizontalAlign.Center e.Row.Cells(4).HorizontalAlign = HorizontalAlign.Center e.Row.Cells(5).HorizontalAlign = HorizontalAlign.Center End If End Sub Protected Sub GvDatosS_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDatosS.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.RowIndex = 0 Then e.Row.Cells(0).Width = Unit.Pixel(350) e.Row.Cells(1).Width = Unit.Pixel(150) e.Row.Cells(2).Width = Unit.Pixel(100) e.Row.Cells(3).Width = Unit.Pixel(100) e.Row.Cells(4).Width = Unit.Pixel(100) e.Row.Cells(5).Width = Unit.Pixel(100) e.Row.Cells(6).Width = Unit.Pixel(100) End If If e.Row.RowState = DataControlRowState.Edit OrElse e.Row.RowState = 5 Then 'e.Row.FCDropDownList("DdlCategoria").DataSource = GlobalDTGralCategorias(UsuarioActual.CveEmpresa) e.Row.FCDropDownList("DdlCategoria").DataSource = GlobalDTGralCategorias2(UsuarioActual.CveEmpresa) e.Row.FCDropDownList("DdlCategoria").DataBind() e.Row.FCDropDownList("DdlCategoria").SelectedValue = e.Row.DBCampo("CveCategoria") Else If UsuarioActual.Empresa.UsaContabilidad Then e.Row.FCLabel("LtlClasificacion").Text = String.Format("{1}", e.Row.DBCampo("CveClasificacion"), e.Row.DBCampo("Clasificacion")) End If End If e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left End If End Sub Protected Sub GvDatos_RowDeleting(sender As Object, e As GridViewDeleteEventArgs) Handles GvDatos.RowDeleting Dim ObjCategorias As New ClsGenerales If ObjCategorias.RemoveCategorias(GvDatos.DataKeys(e.RowIndex).Value.ToString.ToEntero) Then GvDatos.EditIndex = -1 If ObjCategorias.GetCategorias(-1, 4) Then ViewState("DTCategorias2") = ObjCategorias.DtResultados.FiltraParametros(String.Format("CveEmpresa = {0}", UsuarioActual.CveEmpresa)) GlobalDTGralCategorias2(UsuarioActual.CveEmpresa) = ObjCategorias.DtResultados CargaDdlCat() End If Alert("La categoria se eliminó correctamente.", TipoMensaje.MsgInformacion) End If ObjCategorias.Dispose() If ViewState("Orden1").ToString() <> String.Empty Then CargaGrid(ViewState("Orden1").ToString()) Else CargaGrid("") End If End Sub Protected Sub GvDatosS_RowDeleting(sender As Object, e As GridViewDeleteEventArgs) Handles GvDatosS.RowDeleting Dim ObjClasificaciones As New ClsClasificaciones If ObjClasificaciones.RemoveClasificacion(GvDatosS.DataKeys(e.RowIndex).Value.ToString.ToEntero) Then GvDatosS.EditIndex = -1 If ObjClasificaciones.GetClasificaciones(-1, 4) Then ViewState("DTClasificacion2") = ObjClasificaciones.DtResultados.FiltraParametros(String.Format("CveEmpresa = {0}", UsuarioActual.CveEmpresa)) GlobalDTClasificaciones2 = ObjClasificaciones.DtResultados End If Alert("La Clasificacion se eliminó correctamente.", TipoMensaje.MsgInformacion) End If ObjClasificaciones.Dispose() If ViewState("Orden2").ToString() <> String.Empty Then CargaGridS(ViewState("Orden2").ToString()) Else CargaGridS("") End If End Sub Protected Sub GvDatos_RowCancelingEdit(sender As Object, e As GridViewCancelEditEventArgs) Handles GvDatos.RowCancelingEdit GvDatos.EditIndex = -1 If ViewState("Orden1").ToString() <> String.Empty Then CargaGrid(ViewState("Orden1").ToString()) Else CargaGrid("") End If End Sub Protected Sub GvDatosS_RowCancelingEdit(sender As Object, e As GridViewCancelEditEventArgs) Handles GvDatosS.RowCancelingEdit GvDatosS.EditIndex = -1 If ViewState("Orden2").ToString() <> String.Empty Then CargaGridS(ViewState("Orden2").ToString()) Else CargaGridS("") End If End Sub Protected Sub GvDatos_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles GvDatos.RowUpdating Dim ObjCategorias As New ClsGenerales Dim Categoria As String = DirectCast(GvDatos.Rows(e.RowIndex).FindControl("TxtCategoria"), TextBox).Text.Trim Dim Estatus As Boolean = GvDatos.Rows(e.RowIndex).FCCheckBox("ChkEstatus").Checked Dim CveCategoria As Integer = GvDatos.DataKeys(e.RowIndex).Value.ToString.ToEntero If ObjCategorias.UpdateCategoria(Categoria, Estatus, CveCategoria) Then GvDatos.EditIndex = -1 If ObjCategorias.GetCategorias(-1, 4) Then ViewState("DTCategorias2") = ObjCategorias.DtResultados.FiltraParametros(String.Format("CveEmpresa = {0}", UsuarioActual.CveEmpresa)) GlobalDTGralCategorias2(UsuarioActual.CveEmpresa) = ObjCategorias.DtResultados CargaDdlCat() End If Alert("Los cambios se guardaron correctamente.", TipoMensaje.MsgInformacion) End If ObjCategorias.Dispose() If ViewState("Orden1").ToString() <> String.Empty Then CargaGrid(ViewState("Orden1").ToString()) Else CargaGrid("") End If End Sub Protected Sub GvDatosS_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles GvDatosS.RowUpdating Dim ObjClasificaciones As New ClsClasificaciones Dim Clasificacion As String = DirectCast(GvDatosS.Rows(e.RowIndex).FindControl("TxtClasificacion"), TextBox).Text.Trim Dim Estatus As Boolean = GvDatosS.Rows(e.RowIndex).FCCheckBox("ChkEstado").Checked Dim CveClasificacion As Integer = GvDatosS.DataKeys(e.RowIndex).Value.ToString.ToEntero 'Dim DdlGasto As DropDownList = GvDatosS.Rows(e.RowIndex).FCDropDownList("DdlCuentaGasto") 'Dim DdlAnticipo As DropDownList = GvDatosS.Rows(e.RowIndex).FCDropDownList("DdlCuentaAnticipo") 'Dim DdlInventario As DropDownList = GvDatosS.Rows(e.RowIndex).FCDropDownList("DdlCuentaInventario") Dim DdlCategoria As DropDownList = GvDatosS.Rows(e.RowIndex).FCDropDownList("DdlCategoria") 'Dim IDCuentaGasto As Integer = GvDatosS.Rows(e.RowIndex).FCDropDownList("DdlCuentaGasto").SelectedValue.ToEntero If ObjClasificaciones.UpdateClasificacion(Clasificacion, "", -1, "", -1, "", -1, "", Estatus, False, DdlCategoria.SelectedValue.ToEntero, UsuarioActual.CveUsuario, CveClasificacion) Then 'DdlGasto.SelectedValue.ToEntero, DdlGasto.SelectedItem.Text, 'DdlAnticipo.SelectedValue.ToEntero, DdlAnticipo.SelectedItem.Text, 'DdlInventario.SelectedValue.ToEntero, DdlInventario.SelectedItem.Text, GvDatosS.EditIndex = -1 If ObjClasificaciones.GetClasificaciones(-1, 4) Then ViewState("DTClasificacion2") = ObjClasificaciones.DtResultados.FiltraParametros(String.Format("CveEmpresa = {0}", UsuarioActual.CveEmpresa)) End If Alert("Los cambios se guardaron correctamente.", TipoMensaje.MsgInformacion) End If ObjClasificaciones.Dispose() If ViewState("Orden2").ToString() <> String.Empty Then CargaGridS(ViewState("Orden2").ToString()) Else CargaGridS("") End If End Sub Protected Sub GvDatos_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles GvDatos.RowEditing GvDatos.EditIndex = e.NewEditIndex If ViewState("Orden1").ToString() <> String.Empty Then CargaGrid(ViewState("Orden1").ToString()) Else CargaGrid("") End If End Sub Protected Sub GvDatosS_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles GvDatosS.RowEditing GvDatosS.EditIndex = e.NewEditIndex If ViewState("Orden2").ToString() <> String.Empty Then CargaGridS(ViewState("Orden2").ToString()) Else CargaGridS("") End If End Sub Private Sub CargaDdlCat() DdlCategoriaS.DataSource = ViewState("DTCategorias2") DdlCategoriaS.DataBind() UpTitulosS.Update() End Sub End Class