Option Explicit On Option Strict On Imports System.Data Imports System.Linq Imports Extensiones Partial Class GRAL_CatCaracteristicasProductosServicios Inherits ClsPaginas Public Property PuedeEditar As Boolean Get Return CBool(ViewState("PuedeEditar")) End Get Set(value As Boolean) ViewState("PuedeEditar") = value End Set End Property Public Property PuedeEliminar As Boolean Get Return CBool(ViewState("PuedeEditar")) End Get Set(value As Boolean) ViewState("PuedeEditar") = 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") = "" CargaProductosServicios() CargaDatos() ViewState("OrdenO") = "" CargaProductosServiciosCaracteristicas() CargaDatosO() End If End Sub Public Sub CargaDatos() Dim ObjCaracteristicas As New ClsGralProductosServiciosCaracteristicas If ObjCaracteristicas.GetProductosServiciosCaracteristicas() Then ViewState("DTProductosServiciosCaracteristicas") = ObjCaracteristicas.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) GlobalDTProductosServiciosCaracteristicas(UsuarioActual.CveEmpresa) = ObjCaracteristicas.DtResultados Else Me.GvDatosCaracteristicas.DataSource = Nothing End If If ViewState("Orden").ToString() <> String.Empty Then CargaGrid(ViewState("Orden").ToString(), 0) Else CargaGrid("", 0) End If End Sub Public Sub CargaDatosO() Dim ObjOpciones As New ClsGralProductosServiciosCaracteristicas If ObjOpciones.GetProductosServiciosCaracteristicasOpciones() Then ViewState("DTProductosServiciosCaracteristicasOpciones") = ObjOpciones.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) GlobalDTProductosServiciosCaracteristicasOpciones(UsuarioActual.CveEmpresa) = ObjOpciones.DtResultados Else GvDatosOpciones.DataSource = Nothing End If If ViewState("OrdenO").ToString() <> String.Empty Then CargaGrid(ViewState("OrdenO").ToString(), 1) Else CargaGrid("", 1) End If End Sub #Region "C A R G A S" Private Sub CargaProductosServicios() Dim ObjPS As New ClsProductosServicios() If ObjPS.GetPS(-1, -1, UsuarioActual.CveEmpresa) Then ViewState("DTPS") = ObjPS.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa & " AND Estado = 'Activo'", "PS") DdlPS.Items.Clear() DdlPS.DataSource = ViewState("DTPS") DdlPS.DataBind() DdlPSO.Items.Clear() DdlPSO.DataSource = ViewState("DTPS") DdlPSO.DataBind() End If ObjPS.Dispose() End Sub Private Sub CargaProductosServiciosCaracteristicas() DdlCaracteristica.Items.Clear() DdlCaracteristica.DataSource = GlobalDTProductosServiciosCaracteristicas(UsuarioActual.CveEmpresa).FiltraParametros("EsOpcion = 'Sí' AND CvePS = " + DdlPSO.SelectedItem.Value.ToString) DdlCaracteristica.DataBind() End Sub Protected Sub DdlPS_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlPS.SelectedIndexChanged If ViewState("Orden").ToString() <> String.Empty Then CargaGrid(ViewState("Orden").ToString(), 0) Else CargaGrid("", 0) End If End Sub Protected Sub DdlCaracteristica_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlCaracteristica.SelectedIndexChanged If ViewState("OrdenO").ToString() <> String.Empty Then CargaGrid(ViewState("OrdenO").ToString(), 1) Else CargaGrid("", 1) End If End Sub Protected Sub DdlPSO_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlPSO.SelectedIndexChanged CargaProductosServiciosCaracteristicas() If ViewState("OrdenO").ToString() <> String.Empty Then CargaGrid(ViewState("OrdenO").ToString(), 1) Else CargaGrid("", 1) End If End Sub Protected Sub CambioProductosServiciosCaracteristicas() CargaProductosServiciosCaracteristicas() UpTitulosC.Update() CargaDatos() CambioProductosServiciosCaracteristicasOpciones() End Sub Protected Sub CambioProductosServiciosCaracteristicasOpciones() UpTitulosO.Update() CargaDatosO() End Sub #End Region Protected Sub LbAgregarC_Click(sender As Object, e As System.EventArgs) Handles LbAgregarC.Click Dim ObjCaracteristicas As New ClsGralProductosServiciosCaracteristicas If ObjCaracteristicas.AddProductosServiciosCaracteristicas(TxtCaracteristica.Text.Trim, DdlPS.SelectedValue.ToEntero, ChkEsOpcion.Checked, UsuarioActual.CveUsuario) Then TxtCaracteristica.Text = "" Alert("La nueva Característica de Producto o Servicio se guardó correctamente.", TipoMensaje.MsgInformacion) ViewState("DTProductosServiciosCaracteristicas") = ObjCaracteristicas.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) GlobalDTProductosServiciosCaracteristicas(UsuarioActual.CveEmpresa) = ObjCaracteristicas.DtResultados CambioProductosServiciosCaracteristicas() End If ObjCaracteristicas.Dispose() End Sub Protected Sub LbAgregarO_Click(sender As Object, e As System.EventArgs) Handles LbAgregarO.Click Dim ObjOpciones As New ClsGralProductosServiciosCaracteristicas If ObjOpciones.AddProductosServiciosCaracteristicasOpciones(TxtOpcion.Text.Trim, DdlCaracteristica.SelectedValue.ToEntero, UsuarioActual.CveUsuario) Then TxtOpcion.Text = "" Alert("La nueva Opción para Característica de Producto o Servicio se guardó correctamente.", TipoMensaje.MsgInformacion) ViewState("DTProductosServiciosCaracteristicasOpciones") = ObjOpciones.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) GlobalDTProductosServiciosCaracteristicasOpciones(UsuarioActual.CveEmpresa) = ObjOpciones.DtResultados CambioProductosServiciosCaracteristicasOpciones() End If ObjOpciones.Dispose() End Sub #Region "G V - C A R A C T E R I S T I C A S" Protected Sub GvDatosCaracteristicas_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvDatosCaracteristicas.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.RowIndex = 0 Then e.Row.Cells(0).Width = Unit.Pixel(200) e.Row.Cells(1).Width = Unit.Pixel(200) 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(65) End If e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Left If e.Row.RowState = DataControlRowState.Edit OrElse e.Row.RowState = 5 Then e.Row.FCDropDownList("DdlPSEdit").DataSource = ViewState("DTPS") e.Row.FCDropDownList("DdlPSEdit").DataBind() e.Row.FCDropDownList("DdlPSEdit").SelectedValue = e.Row.DBCampo("CvePS") End If End If End Sub Protected Sub GvDatosCaracteristicas_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvDatosCaracteristicas.RowDeleting Dim ObjCaracteristicas As New ClsGralProductosServiciosCaracteristicas If ObjCaracteristicas.RemoveProductosServiciosCaracteristica(GvDatosCaracteristicas.DataKeys(e.RowIndex).Value.ToString.ToEntero) Then GvDatosCaracteristicas.EditIndex = -1 ViewState("DTProductosServiciosCaracteristicas") = ObjCaracteristicas.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) GlobalDTProductosServiciosCaracteristicas(UsuarioActual.CveEmpresa) = ObjCaracteristicas.DtResultados Alert("La Característica del Producto o Servicio se eliminó correctamente.", TipoMensaje.MsgInformacion) CambioProductosServiciosCaracteristicas() End If ObjCaracteristicas.Dispose() End Sub Protected Sub GvDatosCaracteristicas_RowCancelingEdit(sender As Object, e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GvDatosCaracteristicas.RowCancelingEdit GvDatosCaracteristicas.EditIndex = -1 If ViewState("Orden").ToString() <> String.Empty Then CargaGrid(ViewState("Orden").ToString(), 0) Else CargaGrid("", 0) End If End Sub Protected Sub GvDatosCaracteristicas_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GvDatosCaracteristicas.RowEditing GvDatosCaracteristicas.EditIndex = e.NewEditIndex If ViewState("Orden").ToString() <> String.Empty Then CargaGrid(ViewState("Orden").ToString(), 0) Else CargaGrid("", 0) End If End Sub Protected Sub GvDatosCaracteristicas_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GvDatosCaracteristicas.RowUpdating Dim ObjCaracteristicas As New ClsGralProductosServiciosCaracteristicas Dim CvePS As Integer = DirectCast(GvDatosCaracteristicas.Rows(e.RowIndex).FindControl("DdlPSEdit"), DropDownList).SelectedValue.ToEntero Dim CveCaracteristica As Integer = GvDatosCaracteristicas.DataKeys(e.RowIndex).Value.ToString.ToEntero Dim Caracteristica As String = DirectCast(GvDatosCaracteristicas.Rows(e.RowIndex).FindControl("TxtCaracteristica"), TextBox).Text.Trim Dim EsOpcion As Boolean = GvDatosCaracteristicas.Rows(e.RowIndex).FCCheckBox("ChkEsOpcion").Checked If ObjCaracteristicas.UpdateProductosServiciosCaracteristica(Caracteristica, CvePS, EsOpcion, CveCaracteristica) Then GvDatosCaracteristicas.EditIndex = -1 ViewState("DTProductosServiciosCaracteristicas") = ObjCaracteristicas.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) GlobalDTProductosServiciosCaracteristicas(UsuarioActual.CveEmpresa) = ObjCaracteristicas.DtResultados Alert("Los cambios se guardaron correctamente.", TipoMensaje.MsgInformacion) CambioProductosServiciosCaracteristicas() End If ObjCaracteristicas.Dispose() End Sub #End Region #Region "G V - C A R A C T E R I S T I C A S O P C I O N E S" Protected Sub GvDatosOpciones_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvDatosOpciones.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.RowIndex = 0 Then e.Row.Cells(0).Width = Unit.Pixel(200) e.Row.Cells(1).Width = Unit.Pixel(200) e.Row.Cells(2).Width = Unit.Pixel(200) 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(65) End If e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Left If e.Row.RowState = DataControlRowState.Edit OrElse e.Row.RowState = 5 Then e.Row.FCDropDownList("DdlCaracteristicaEdit").DataSource = GlobalDTProductosServiciosCaracteristicas(UsuarioActual.CveEmpresa) e.Row.FCDropDownList("DdlCaracteristicaEdit").DataBind() e.Row.FCDropDownList("DdlCaracteristicaEdit").SelectedValue = e.Row.DBCampo("CvePS") End If End If End Sub Protected Sub GvDatosOpciones_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvDatosOpciones.RowDeleting Dim ObjOpciones As New ClsGralProductosServiciosCaracteristicas If ObjOpciones.RemoveProductosServiciosCaracteristicasOpciones(GvDatosOpciones.DataKeys(e.RowIndex).Value.ToString.ToEntero) Then GvDatosOpciones.EditIndex = -1 ViewState("DTProductosServiciosCaracteristicasOpciones") = ObjOpciones.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) GlobalDTProductosServiciosCaracteristicasOpciones(UsuarioActual.CveEmpresa) = ObjOpciones.DtResultados Alert("La Opción para Característica del Producto o Servicio se eliminó correctamente.", TipoMensaje.MsgInformacion) CambioProductosServiciosCaracteristicasOpciones() End If ObjOpciones.Dispose() End Sub Protected Sub GvDatosOpciones_RowCancelingEdit(sender As Object, e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GvDatosOpciones.RowCancelingEdit GvDatosOpciones.EditIndex = -1 If ViewState("OrdenO").ToString() <> String.Empty Then CargaGrid(ViewState("OrdenO").ToString(), 1) Else CargaGrid("", 1) End If End Sub Protected Sub GvDatosOpciones_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GvDatosOpciones.RowUpdating Dim ObjOpciones As New ClsGralProductosServiciosCaracteristicas Dim CveCaracteristica As Integer = DirectCast(GvDatosOpciones.Rows(e.RowIndex).FindControl("DdlCaracteristicaEdit"), DropDownList).SelectedValue.ToEntero Dim CveOpcion As Integer = GvDatosOpciones.DataKeys(e.RowIndex).Value.ToString.ToEntero Dim Opcion As String = DirectCast(GvDatosOpciones.Rows(e.RowIndex).FindControl("TxtOpcion"), TextBox).Text.Trim If ObjOpciones.UpdateProductosServiciosCaracteristicasOpciones(Opcion, CveCaracteristica, CveOpcion) Then GvDatosOpciones.EditIndex = -1 ViewState("DTProductosServiciosCaracteristicasOpciones") = ObjOpciones.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) GlobalDTProductosServiciosCaracteristicasOpciones(UsuarioActual.CveEmpresa) = ObjOpciones.DtResultados Alert("Los cambios se guardaron correctamente.", TipoMensaje.MsgInformacion) CambioProductosServiciosCaracteristicasOpciones() End If ObjOpciones.Dispose() End Sub Protected Sub GvDatosOpciones_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GvDatosOpciones.RowEditing GvDatosOpciones.EditIndex = e.NewEditIndex If ViewState("OrdenO").ToString() <> String.Empty Then CargaGrid(ViewState("OrdenO").ToString(), 1) Else CargaGrid("", 1) 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 gvi As Integer = 0 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) gvi = Arg(1).ToEntero Literal = CType(CType(sender, LinkButton).NamingContainer.FindControl("Img" & Campo.Replace(",", "_")), Literal) Campo = Campo.Substring(0, Campo.Length - 1) If ViewState(String.Format("O{0}", Campo, gvi)) IsNot Nothing AndAlso ViewState(String.Format("O{0}", Campo, gvi)).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, gvi)) = String.Format("{0} DESC", Campo) Literal.Text = String.Format("") End If Orden = OrdenInicial & ViewState(String.Format("O{0}", Campo, gvi)).ToString ViewState("Orden") = Orden CargaGrid(Orden, gvi) End Sub Private Sub CargaGrid(Orden As String, gvi As Integer) Dim Filtro As String = "" If gvi = 0 Then Filtro = "CvePS = " + DdlPS.SelectedItem.Value.ToString If Orden <> String.Empty Then Dim DV As New DataView(CType(ViewState("DTProductosServiciosCaracteristicas"), DataTable), Filtro, Orden, DataViewRowState.CurrentRows) GvDatosCaracteristicas.DataSource = DV.ToTable() DV.Dispose() Else GvDatosCaracteristicas.DataSource = New DataView(GlobalDTProductosServiciosCaracteristicas(UsuarioActual.CveEmpresa), Filtro, "", DataViewRowState.CurrentRows) End If GvDatosCaracteristicas.DataBind() UpDatosC.Update() ElseIf gvi = 1 Then If Not DdlCaracteristica.SelectedItem Is Nothing Then Filtro = "CvePSCaracteristica = " + DdlCaracteristica.SelectedItem.Value.ToString Else Filtro = "1 = 2" End If If Orden <> String.Empty Then Dim DV As New DataView(CType(ViewState("DTProductosServiciosCaracteristicasOpciones"), DataTable), Filtro, Orden, DataViewRowState.CurrentRows) GvDatosOpciones.DataSource = DV.ToTable() DV.Dispose() Else GvDatosOpciones.DataSource = New DataView(GlobalDTProductosServiciosCaracteristicasOpciones(UsuarioActual.CveEmpresa), Filtro, "", DataViewRowState.CurrentRows) End If GvDatosOpciones.DataBind() UpDatosO.Update() End If End Sub #End Region End Class