Option Strict On Imports Extensiones Imports System.Data Partial Class General_CatCompuestos Inherits ClsPaginas #Region "Propiedades" Public Property CveCompuesto 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 CveCompuesto = -1 EsEditar = 0 dvEstatus.Visible = False CargaDatos(-1) End If End Sub Private Sub CargaDatos(CveConductor As Integer) Dim PS As New ClsProductosServicios If PS.GetCompuestosActivos(UsuarioActual.CveEmpresa) Then GvDatos.DataSource = PS.DtResultados Else GvDatos.DataSource = Nothing End If PS.Dispose() GvDatos.DataBind() End Sub Protected Sub imgE_Click(sender As Object, e As EventArgs) Dim Boton = CType(sender, LinkButton) CveCompuesto = Boton.CommandArgument.ToEntero Dim GvRow As GridViewRow = DirectCast(Boton.NamingContainer, GridViewRow) TxtCompuesto.Text = GvRow.DataKey("Compuesto").ToString chkEstatus.Checked = CBool(GvRow.DataKey("Estatus")) EsEditar = 1 BtnAgregarCatalogo.Text = "Actualizar" dvEstatus.Visible = True UpBodyCompuesto.Update() UpFooter.Update() RegistraScript("$('#divAgregar').modal()") End Sub Protected Sub BtnAgregarCatalogo_Click(sender As Object, e As EventArgs) Handles BtnAgregarCatalogo.Click Dim PS As New ClsProductosServicios If EsEditar = 0 Then If PS.AddCompuestoActivo(TxtCompuesto.Text, True, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then Alert("El compuesto se agregó correctamente", TipoMensaje.MsgInformacion) Else Alert("Ocurrió un error al agregar el compuesto", TipoMensaje.MsgError) End If ElseIf EsEditar = 1 Then If PS.UpdateCompuestoActivo(TxtCompuesto.Text, CveCompuesto, chkEstatus.Checked) Then Alert("El compuesto se editó correctamente", TipoMensaje.MsgInformacion) Else Alert("Ocurrió un error al editar al compuesto", TipoMensaje.MsgError) End If EsEditar = 0 dvEstatus.Visible = False BtnAgregarCatalogo.Text = "Agregar" End If RegistraScript("$('#divAgregar').modal('hide')") PS.Dispose() TxtCompuesto.Text = "" CargaDatos(-1) UpDatos.Update() UpBodyCompuesto.Update() End Sub Protected Sub GvDatos_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvDatos.RowDeleting Dim PS As New ClsProductosServicios Dim CveCompuesto As Integer = GvDatos.Rows(e.RowIndex).DataKey("CveCompuesto").ToEntero If PS.RemoveCompuestoActivo(CveCompuesto) Then Alert("El Compuesto se eliminó correctamente", TipoMensaje.MsgInformacion) End If PS.Dispose() CargaDatos(-1) UpDatos.Update() 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("CveCompuesto").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" TxtCompuesto.Text = "" dvEstatus.Visible = False UpBodyCompuesto.Update() UpFooter.Update() End Sub End Class