Option Explicit On Option Strict On Imports Extensiones Partial Class Ventas_CatPreciosLista Inherits ClsPaginas #Region "Propiedades" Public Property CvePrecioLista As Integer Get Return ViewState("CveCompuesto").ToString.ToEntero End Get Set(value As Integer) ViewState("CveCompuesto") = value End Set End Property Public Property EsEditar As Integer Get Return ViewState("EsEditar").ToString.ToEntero End Get Set(value As Integer) ViewState("EsEditar") = 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 CvePrecioLista = -1 EsEditar = 0 If UsuarioActual.Empresa.Funcionalidad(382) = "1" Then divPermiso.Visible = True End If dvEstatus.Visible = False CargaDatos() End If End Sub Private Sub CargaDatos() Dim ObjVta As New ClsVentas If ObjVta.GetPrecioListas(CveEmpresa:=UsuarioActual.CveEmpresa) Then GvDatos.DataSource = ObjVta.DtResultados GvDatos.DataBind() Else GvDatos.DataSource = Nothing End If ObjVta.Dispose() GvDatos.DataBind() End Sub Protected Sub imgE_Click(sender As Object, e As EventArgs) Dim Boton As LinkButton = CType(sender, LinkButton) CvePrecioLista = Boton.CommandArgument.ToEntero Dim GvRow As GridViewRow = DirectCast(Boton.NamingContainer, GridViewRow) TxtPrecioLista.Text = GvRow.DataKey("PrecioLista").ToString ChkPredeterminada.Checked = GvRow.DataKey("Predeterminada") = "True" chkEstatus.Checked = CBool(GvRow.DataKey("Estatus")) ChkRestringida.Checked = CBool(GvRow.DataKey("Restringuida")) EsEditar = 1 BtnAgregarCatalogo.Text = "Actualizar" dvEstatus.Visible = True Using ObjVenta As New ClsVentas If ObjVenta.GetPreciosListasSubProyecto(CvePrecioLista, UsuarioActual.CveEmpresa) Then GvSubProyectos.DataSource = ObjVenta.DtResultados.Copy() End If End Using GvSubProyectos.DataBind() UpBodyCo.Update() UpFooter.Update() RegistraScript("$('#divAgregar').modal()") End Sub Protected Sub BtnAgregarCatalogo_Click(sender As Object, e As EventArgs) Handles BtnAgregarCatalogo.Click Dim ActualizarFranquicias As Boolean = False If UsuarioActual.Empresa.Funcionalidad(563) <> "" AndAlso UsuarioActual.Empresa.Funcionalidad(109) = "1" Then ActualizarFranquicias = True End If Dim ObjVta As New ClsVentas ObjVta.IniciaTransacSQL() Dim TieneError As Boolean = False Try If EsEditar = 0 Then Dim CvePrecioLista As Integer = ObjVta.AddPrecioLista(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, TxtPrecioLista.Text, ChkPredeterminada.Checked, ChkRestringida.Checked, 0, UpdateFranquicia:=ActualizarFranquicias) If Not CvePrecioLista > 0 Then TieneError = True End If If Not TieneError Then If UsuarioActual.Empresa.Funcionalidad(382) = "1" Then For Each GvRow As GridViewRow In GvSubProyectos.Rows If GvRow.RowType = DataControlRowType.DataRow Then Dim Permitir As Boolean = GvRow.FCCheckBox("ChkPermitir").Checked Dim CveSubProyecto As Integer = GvRow.DataKey("CveSubProyecto").ToEntero() If Not ObjVta.UpdatePreciosListasSubProyecto(CvePrecioLista, CveSubProyecto, Permitir, UsuarioActual.CveEmpresa) Then TieneError = False Exit For End If End If Next End If End If ElseIf EsEditar = 1 Then If Not ObjVta.UpdatePrecioLista(TxtPrecioLista.Text, chkEstatus.Checked, UsuarioActual.CveUsuario, 0, ChkPredeterminada.Checked, ChkRestringida.Checked, CvePrecioLista, UpdateFranquicia:=ActualizarFranquicias) Then TieneError = True End If If Not TieneError Then If UsuarioActual.Empresa.Funcionalidad(382) = "1" Then For Each GvRow As GridViewRow In GvSubProyectos.Rows If GvRow.RowType = DataControlRowType.DataRow Then Dim Permitir As Boolean = GvRow.FCCheckBox("ChkPermitir").Checked Dim CveSubProyecto As Integer = GvRow.DataKey("CveSubProyecto").ToEntero() If Not ObjVta.UpdatePreciosListasSubProyecto(Me.CvePrecioLista, CveSubProyecto, Permitir, UsuarioActual.CveEmpresa) Then TieneError = False Exit For End If End If Next End If End If EsEditar = 0 dvEstatus.Visible = False BtnAgregarCatalogo.Text = "Agregar" End If Catch ex As Exception TieneError = True GuardaLog(ex.ToString()) End Try If TieneError Then ObjVta.RollBack() Alert("Ocurrió un error al guardar el precio de lista", TipoMensaje.MsgError) Else ObjVta.Commit() Alert("El precio de lista se guardo correctamente", TipoMensaje.MsgInformacion) End If RegistraScript("$('#divAgregar').modal('hide')") ObjVta.Dispose() TxtPrecioLista.Text = "" CargaDatos() UpDatos.Update() UpBodyCo.Update() RecargaGlobal() End Sub Protected Sub GvDatos_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvDatos.RowDeleting Dim ObjPrecioLista As New ClsVentas Dim CvePrecioLista As Integer = GvDatos.Rows(e.RowIndex).DataKey("CvePrecioLista").ToEntero If ObjPrecioLista.RemovePrecioLista(CvePrecioLista) Then Alert("El Precio de lista se eliminó correctamente", TipoMensaje.MsgInformacion) End If ObjPrecioLista.Dispose() CargaDatos() UpDatos.Update() RecargaGlobal() End Sub 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.VerticalAlign = VerticalAlign.Middle e.Row.FCLinkButton("ImgE").CommandArgument = e.Row.DataKey("CvePrecioLista").ToString If CBool(e.Row.DBCampo("Estatus")) = True Then e.Row.FCLabel("LblEstatus").Text = "Activo" e.Row.FCLabel("LblEstatus").ForeColor = Drawing.Color.Green Else e.Row.FCLabel("LblEstatus").Text = "Inactivo" e.Row.FCLabel("LblEstatus").ForeColor = Drawing.Color.Red End If End If End Sub Protected Sub btnCancelar_Click(sender As Object, e As EventArgs) Handles BtnOpenDiv.Click EsEditar = 0 RegistraScript("$('#divAgregar').modal()") BtnAgregarCatalogo.Text = "Agregar" TxtPrecioLista.Text = "" dvEstatus.Visible = False UpBodyCo.Update() UpFooter.Update() End Sub Private Sub RecargaGlobal() GlobalDTPrecioListas(UsuarioActual.CveEmpresa) = Nothing End Sub #Region "VIEJO" ' 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 ' CargaDatos() ' 'Permiso Registro ' If UsuarioActual.TienePermisoProceso(132) Then LbAgregar.Enabled = True Else LbAgregar.Enabled = False ' 'Permiso Eliminar ' If UsuarioActual.TienePermisoProceso(134) Then GvDatos.Columns(5).Visible = True Else GvDatos.Columns(6).Visible = False ' End If ' End Sub ' Private Sub CargaDatos() ' Dim ObjListas As New ClsVentas ' If ObjListas.GetPrecioListas(CveEmpresa:=UsuarioActual.CveEmpresa) Then ' GvDatos.DataSource = ObjListas.DtResultados ' GvDatos.DataBind() ' Else ' Me.GvDatos.DataSource = Nothing ' End If ' If ObjListas.GetPrecioListas(-1) Then ' GlobalDTPrecioListas(-1) = ObjListas.DtResultados ' End If ' ObjListas.Dispose() ' OrdenaDatos() ' End Sub ' Protected Sub LbAgregar_Click(sender As Object, e As System.EventArgs) Handles LbAgregar.Click ' Dim ObjListas As New ClsVentas ' If HdnModalidad.Value = "I" Then ' If ObjListas.AddPrecioLista(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, TxtPrecioLista.Text.Trim, TxtPorcentaje.Text.Trim.ToDouble) Then ' TxtPrecioLista.Text = "" ' TxtPorcentaje.Text = "" ' Alert("La nueva Lista se guardó correctamente.", TipoMensaje.MsgInformacion) ' UpTitulos.Update() ' CargaDatos() ' UpDatos.Update() ' OcultaDiv() ' End If ' ObjListas.Dispose() ' Else ' If HdnID.Value.ToEntero <> -1 Then ' If ObjListas.UpdatePrecioLista(TxtPrecioLista.Text.Trim, True, UsuarioActual.CveUsuario, TxtPorcentaje.Text.Trim.ToDouble, HdnID.Value.ToEntero) Then ' TxtPrecioLista.Text = "" ' TxtPorcentaje.Text = "" ' Alert("La lista se actualizó correctamente.", TipoMensaje.MsgInformacion) ' UpTitulos.Update() ' CargaDatos() ' UpDatos.Update() ' OcultaDiv() ' End If ' End If ' End If ' 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 ' Dim URL As String = String.Format("javascript:CleanObjects();SetValue('HdnModalidad', 'U');SetValue('HdnID', '{0}'); SetObjects('{1}','{2}');ShowDivRegistro();return false;", e.Row.DBCampo("CvePrecioLista").ToEntero, e.Row.DBCampo("PrecioLista"), e.Row.DBCampo("Porcentaje")) ' 'GeneroLigas ' Dim Liga As String = String.Format("", URL) ' e.Row.VerticalAlign = VerticalAlign.Middle ' e.Row.FCLinkButton("ImgE").OnClientClick = URL ' End If ' End Sub ' Protected Sub GvDatos_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvDatos.RowDeleting ' Dim ObjListas As New ClsVentas ' If ObjListas.RemovePrecioLista(GvDatos.DataKeys(e.RowIndex).Value.ToString.ToEntero) Then ' GvDatos.EditIndex = -1 ' ViewState("DTPrecioListas") = ObjListas.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) ' Alert("La Lista se eliminó correctamente.", TipoMensaje.MsgInformacion) ' End If ' If ObjListas.GetPrecioListas(-1) Then ' GlobalDTPrecioListas(-1) = ObjListas.DtResultados ' End If ' ObjListas.Dispose() ' CargaDatos() ' UpDatos.Update() ' End Sub ' Protected Sub GvDatos_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GvDatos.RowUpdating ' Dim ObjListas As New ClsVentas ' Dim PrecioLista As String = DirectCast(GvDatos.Rows(e.RowIndex).FindControl("TxtPrecioLista"), TextBox).Text.Trim ' Dim Porcentaje As Double = DirectCast(GvDatos.Rows(e.RowIndex).FindControl("TxtPorcentaje"), TextBox).Text.Trim.ToDouble ' Dim Estatus As Boolean = GvDatos.Rows(e.RowIndex).FCCheckBox("ChkEstatus").Checked ' Dim CvePrecioLista As Integer = GvDatos.DataKeys(e.RowIndex).Value.ToString.ToEntero ' If ObjListas.UpdatePrecioLista(PrecioLista, Estatus, UsuarioActual.CveUsuario, Porcentaje, CvePrecioLista) Then ' GvDatos.EditIndex = -1 ' ViewState("DTPrecioListas") = ObjListas.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) ' Alert("Los cambios se guardaron correctamente.", TipoMensaje.MsgInformacion) ' End If ' If ObjListas.GetPrecioListas(-1) Then ' GlobalDTPrecioListas(-1) = ObjListas.DtResultados ' End If ' ObjListas.Dispose() ' OrdenaDatos() ' End Sub '#End Region '#Region " O R D E N A M I E N T O JAVASCRIPT" ' Private Sub OrdenaDatos() ' If (GvDatos.Rows.Count > 0) Then ' GvDatos.UseAccessibleHeader = True ' GvDatos.HeaderRow.TableSection = TableRowSection.TableHeader ' RegistraScript("OrdenarGV();") ' End If ' End Sub '#End Region ' Private Sub OcultaDiv() ' ScriptManager.RegisterStartupScript(Me, Me.GetType, "Llave", "HideDivRegistro();", True) ' End Sub #End Region End Class