Option Explicit On Option Strict On Imports System.Data Imports System.Linq Imports Extensiones Partial Class OS_PopUpOS_PS_Especificaciones Inherits ClsPaginas Private Property CvePS As Integer Get Return ViewState("CvePS").ToString.ToEntero End Get Set(value As Integer) ViewState("CvePS") = 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 = 601 RegistraScript("$get('tdContenido').style.height='400px'") ViewState("Orden") = "" CvePS = Request("CvePS").ToEntero If CvePS = 0 Then UpTitulos.Visible = False Else CreaDT() CargaPS() If Not Request("Especificaciones") Is Nothing AndAlso Request("Especificaciones") <> "" Then CargaEspecificiones(Request("Especificaciones")) End If CargaPSCaracteristicas() CargaPSCaracteristicasOpciones() End If If Not Request("EsThickbox") Is Nothing Then hdnEsThickbox.Value = Request("EsThickbox") Else hdnEsThickbox.Value = "N" End If 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("CveValor", GetType(Integer)) TmpDT.Columns.Add("CvePSCaracteristica", GetType(Integer)) TmpDT.Columns.Add("Caracteristica", GetType(String)) TmpDT.Columns.Add("EsOpcion", GetType(String)) TmpDT.Columns.Add("CveOpcion", GetType(Integer)) TmpDT.Columns.Add("Opcion", GetType(String)) TmpDT.Columns.Add("CvePS", GetType(Integer)) TmpDT.Columns.Add("PS", GetType(String)) TmpDT.Columns.Add("Valor", GetType(String)) End Sub Private Sub CargaPS() Dim ObjPS As New ClsProductosServicios() If ObjPS.GetPS(CvePS, -1, UsuarioActual.CveEmpresa) Then If ObjPS.DtResultados.Rows.Count = 1 Then LtlClasificacion.Text = ObjPS.DtResultados.Rows(0)("Clasificacion").ToString LtlProductoServicio.Text = ObjPS.DtResultados.Rows(0)("PS").ToString LtlUM.Text = ObjPS.DtResultados.Rows(0)("UnidadMedida").ToString LtlCodigo.Text = ObjPS.DtResultados.Rows(0)("Codigo").ToString End If End If ObjPS.Dispose() End Sub Private Sub CargaEspecificiones(Especificaciones As String) Try Dim LEspecificaciones As String() LEspecificaciones = Especificaciones.Split(CChar(",")) For Each S As String In LEspecificaciones Dim Esp As String() = S.Split(CChar(":")) AddEspecificacion(0, Esp(0).ToEntero, Esp(1), Esp(2), Esp(3).ToEntero, Esp(4), Esp(5), CvePS, LtlProductoServicio.Text) Next If ViewState("Orden").ToString() <> String.Empty Then CargaGrid(ViewState("Orden").ToString()) Else CargaGrid("") End If Catch ex As Exception Alert("Error al cargar las Especificaciones", TipoMensaje.MsgError) End Try End Sub #Region "G V D A T O S" Protected Sub GvValoresCaracteristicas_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvValoresCaracteristicas.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then ' e.Row.Cells(0).Width = Unit.Pixel(150) e.Row.Cells(1).Width = Unit.Pixel(150) e.Row.Cells(2).Width = Unit.Pixel(160) e.Row.Cells(3).Width = Unit.Pixel(160) e.Row.Cells(4).Width = Unit.Pixel(155) 'e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Left If e.Row.RowState = DataControlRowState.Edit OrElse e.Row.RowState = 5 Then e.Row.FCDropDownList("DdlCaracteristica").DataSource = GlobalDTProductosServiciosCaracteristicas(UsuarioActual.CveEmpresa).FiltraParametros("CvePS = " + CvePS.ToString) e.Row.FCDropDownList("DdlCaracteristica").DataBind() e.Row.FCDropDownList("DdlCaracteristica").SelectedValue = e.Row.DBCampo("CvePSCaracteristica") 'Verificar si es Opcion If e.Row.DBCampo("EsOpcion") = "Sí" Then e.Row.FCTextBox("TxtValor").Visible = False e.Row.FCDropDownList("DdlOpcion").Visible = True e.Row.FCDropDownList("DdlOpcion").DataSource = GlobalDTProductosServiciosCaracteristicasOpciones(UsuarioActual.CveEmpresa).FiltraParametros("CvePSCaracteristica = " & e.Row.DBCampo("CvePSCaracteristica").ToString) e.Row.FCDropDownList("DdlOpcion").DataBind() e.Row.FCDropDownList("DdlOpcion").SelectedValue = e.Row.DBCampo("CveOpcion") Else e.Row.FCTextBox("TxtValor").Visible = True e.Row.FCDropDownList("DdlOpcion").Visible = False e.Row.FCTextBox("TxtValor").Text = e.Row.DBCampo("Valor").ToString End If End If End If End Sub Protected Sub GvValoresCaracteristicas_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles GvValoresCaracteristicas.RowEditing GvValoresCaracteristicas.EditIndex = e.NewEditIndex If ViewState("Orden").ToString() <> String.Empty Then CargaGrid(ViewState("Orden").ToString()) Else CargaGrid("") End If End Sub Protected Sub GvValoresCaracteristicas_RowDeleting(sender As Object, e As GridViewDeleteEventArgs) Handles GvValoresCaracteristicas.RowDeleting Dim CvePSCaracteristica As Integer = GvValoresCaracteristicas.DataKeys(e.RowIndex).Value.ToString.ToEntero Dim i As Integer = TmpDT.Rows.IndexOf(TmpDT.Rows(e.RowIndex)) TmpDT.Rows.RemoveAt(i) CargaPSCaracteristicas() CargaPSCaracteristicasOpciones() 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("") 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 GvValoresCaracteristicas.DataSource = TmpDT.FiltraParametros("", Orden) Else GvValoresCaracteristicas.DataSource = TmpDT End If GvValoresCaracteristicas.DataBind() UpDatos.Update() End Sub #End Region Protected Sub GvValoresCaracteristicas_RowCancelingEdit(sender As Object, e As GridViewCancelEditEventArgs) Handles GvValoresCaracteristicas.RowCancelingEdit GvValoresCaracteristicas.EditIndex = -1 If ViewState("Orden").ToString() <> String.Empty Then CargaGrid(ViewState("Orden").ToString()) Else CargaGrid("") End If End Sub Private Sub CargaPSCaracteristicas() If TmpDT.Rows.Count = 0 Then DdlCaracteristica.Items.Clear() DdlCaracteristica.DataSource = GlobalDTProductosServiciosCaracteristicas(UsuarioActual.CveEmpresa).FiltraParametros("CvePS = " + CvePS.ToString) DdlCaracteristica.DataBind() Else Dim CvePSCaracteristicasAgregadas As String = "" For Each R As DataRow In TmpDT.Rows If CvePSCaracteristicasAgregadas <> "" Then CvePSCaracteristicasAgregadas = CvePSCaracteristicasAgregadas + "," End If CvePSCaracteristicasAgregadas = CvePSCaracteristicasAgregadas + R("CvePSCaracteristica").ToString Next DdlCaracteristica.Items.Clear() DdlCaracteristica.DataSource = GlobalDTProductosServiciosCaracteristicas(UsuarioActual.CveEmpresa).FiltraParametros(String.Format("CvePS = {0} and CvePSCaracteristica Not In ({1})", CvePS.ToString, CvePSCaracteristicasAgregadas)) DdlCaracteristica.DataBind() End If DdlCaracteristica_SelectedIndexChanged(New Object, New EventArgs) End Sub Private Sub CargaPSCaracteristicasOpciones() DdlOpcion.Items.Clear() If DdlCaracteristica.SelectedValue.ToString <> "" Then DdlOpcion.DataSource = GlobalDTProductosServiciosCaracteristicasOpciones(UsuarioActual.CveEmpresa).FiltraParametros("CvePSCaracteristica = " + DdlCaracteristica.SelectedValue.ToString) DdlOpcion.DataBind() End If End Sub Protected Sub DdlCaracteristica_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlCaracteristica.SelectedIndexChanged If DdlCaracteristica.SelectedValue <> "" Then Dim DV As New DataView(GlobalDTProductosServiciosCaracteristicas(UsuarioActual.CveEmpresa).FiltraParametros("CvePSCaracteristica = " + DdlCaracteristica.SelectedValue.ToString)) If DV(0)("EsOpcion").ToString = "Sí" Then DdlOpcion.Visible = True CargaPSCaracteristicasOpciones() txtValor.Visible = False Else DdlOpcion.Visible = False txtValor.Visible = True End If Else DdlOpcion.ClearSelection() DdlOpcion.DataSource = "" DdlOpcion.DataBind() End If End Sub Protected Sub LbAgregar_Click(sender As Object, e As EventArgs) Handles LbAgregar.Click If DdlCaracteristica.SelectedValue <> "" Then If TmpDT.FiltraParametros("CvePSCaracteristica = " + DdlCaracteristica.SelectedValue.ToString).Rows.Count = 0 Then Dim EsOpcion As String Dim CveOpcion As Integer Dim Opcion As String Dim Valor As String If DdlOpcion.Visible = True Then EsOpcion = "Sí" CveOpcion = DdlOpcion.SelectedValue.ToEntero Opcion = DdlOpcion.SelectedItem.Text Valor = "-1" Else EsOpcion = "No" CveOpcion = -1 Opcion = "-1" Valor = txtValor.Text End If AddEspecificacion(0, DdlCaracteristica.SelectedValue.ToEntero, DdlCaracteristica.SelectedItem.Text, EsOpcion, CveOpcion, Opcion, Valor, CvePS, LtlProductoServicio.Text) CargaPSCaracteristicas() CargaPSCaracteristicasOpciones() UpTitulos.Update() End If End If End Sub Private Sub AddEspecificacion(CveValor As Integer, CvePSCaracteristica As Integer, Caracteristica As String, EsOpcion As String, CveOpcion As Integer, Opcion As String, Valor As String, CvePS As Integer, PS As String) Dim Row As DataRow = Nothing Row = TmpDT.NewRow() Row("CveValor") = CveValor Row("CvePSCaracteristica") = CvePSCaracteristica Row("Caracteristica") = Caracteristica Row("EsOpcion") = EsOpcion Row("CveOpcion") = CveOpcion Row("Opcion") = Opcion If EsOpcion = "Sí" Then Row("Valor") = Opcion Else Row("Valor") = Valor End If Row("CvePS") = CvePS Row("PS") = PS TmpDT.Rows.Add(Row) GvValoresCaracteristicas.DataSource = TmpDT GvValoresCaracteristicas.DataBind() UpDatos.Update() End Sub Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs) Handles BtnGuardar.Click Dim Especificaciones As String = "-1" For Each R As DataRow In TmpDT.Rows If Especificaciones = "-1" Then Especificaciones = "" Else Especificaciones = Especificaciones + "," Especificaciones = Especificaciones + String.Format("{0}:{1}:{2}:{3}:{4}:{5}", R("CvePSCaracteristica").ToString, R("Caracteristica").ToString, R("EsOpcion"), R("CveOpcion").ToString, R("Opcion").ToString, R("Valor").ToString) Next RegistraScript(String.Format("CargaEspecificaciones('{0}');", Especificaciones)) End Sub Protected Sub DdlCaracteristicaEdit_SelectedIndexChanged(sender As Object, e As EventArgs) Dim ddl As DropDownList = DirectCast(sender, DropDownList) Dim gvr As GridViewRow = DirectCast(ddl.NamingContainer, GridViewRow) Dim DV As New DataView(GlobalDTProductosServiciosCaracteristicas(UsuarioActual.CveEmpresa).FiltraParametros("CvePSCaracteristica = " + ddl.SelectedValue.ToString)) If DV(0)("EsOpcion").ToString = "Sí" Then With GvValoresCaracteristicas.Rows(gvr.RowIndex).FCDropDownList("DdlOpcionEdit") .Visible = True .DataSource = GlobalDTProductosServiciosCaracteristicasOpciones(UsuarioActual.CveEmpresa).FiltraParametros("CvePSCaracteristica = " & ddl.SelectedValue.ToString) .DataBind() ' .SelectedValue = GvValoresCaracteristicas.Rows(gvr.RowIndex).DBCampo("CveOpcion") End With GvValoresCaracteristicas.Rows(gvr.RowIndex).FCTextBox("txtValor").Visible = False Else GvValoresCaracteristicas.Rows(gvr.RowIndex).FCDropDownList("DdlOpcionEdit").Visible = False GvValoresCaracteristicas.Rows(gvr.RowIndex).FCTextBox("txtValor").Visible = True End If End Sub Protected Sub BtnCancelar_Click(sender As Object, e As EventArgs) Handles BtnCancelar.Click RegistraScript("Cancelar();") End Sub End Class