Imports System.Data Imports System.Drawing Imports DocumentFormat.OpenXml.Drawing.Diagrams Imports System.IO Imports Extensiones Imports Microsoft.Reporting.WebForms Partial Class Sistemas_RolesDetalle Inherits ClsPaginas #Region "Propiedades" Private Property CveRol As Integer Get CveRol = ViewState("CveRol").ToString.ToEntero End Get Set(value As Integer) ViewState("CveRol") = value End Set End Property #End Region Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load If Not IsPostBack Then CveRol = If(Request("CveRol") <> "", Request("CveRol").ToString.ToEntero, "-1".ToEntero) CargaDatos() End If End Sub Private Sub CargaDatos() CargaGridIndicadores() CargaGridPermisos() CargaGridProcesos() CargaUsuarios() DdlModulo.DataSource = GlobalDTModulos().FiltraParametros("", Orderby:="Modulo") DdlModulo.DataBind() If CveRol <> -1 Then Dim DTRoles As New DataTable Dim Objeto As New ClsSisRoles If Objeto.GetRoles(CveRol, UsuarioActual.CveEmpresa) Then DTRoles = Objeto.DtResultados If DTRoles.Rows.Count > 0 Then LblRol.Text = DTRoles.FiltroPrimeroValor("Rol") TxtRol.Text = DTRoles.FiltroPrimeroValor("Rol") TxtFecha.Text = DTRoles.FiltroPrimeroValor("FechaIng").ToDate.ToShortDateString TxtUsuarioAlta.Text = DTRoles.FiltroPrimeroValor("Nombre") DdlModulo.SelectedValueExist(DTRoles.FiltroPrimeroValor("CveModulo").ToEntero) If UsuarioActual.Empresa.Funcionalidad(382) = "1" OrElse UsuarioActual.CveRol = 1 Then CargaAdjunto(DTRoles.FiltroPrimeroValor("Adjunto")) End If Else Dim Liga As String = $"document.location.href=""/Sistemas/CatRoles.aspx"";" Alert("El Rol solicitado no existe.", TipoMensaje.MsgAdvertencia, Liga) End If Objeto.Dispose() End If Else LblFechaAlta.Visible = False LblUsuarioAlta.Visible = False End If End Sub Private Sub CargaAdjunto(Adjunto As String) DivManual.Visible = True If Adjunto <> "" Then BtnArchivoAdjunto.Text = Adjunto BtnArchivoAdjunto.Visible = True BtnAdjuntar.Visible = False BtnReemplazarAdjunto.Visible = True Else BtnAdjuntar.Visible = True End If End Sub Private Sub CargaUsuarios() If CveRol > 0 Then Dim ObjUsuarios As New ClsSisUsuarios() If ObjUsuarios.GetUsuarios(-1, CveRol) Then GvUsurios.DataSource = ObjUsuarios.DtResultados.FiltraParametros("", "", {"CveUsuario", "Usuario", "Nombre"}) Else GvUsurios.DataSource = Nothing End If ObjUsuarios.Dispose() End If GvUsurios.DataBind() End Sub #Region "I N D I C A D O R E S" Private Sub CargaGridIndicadores() Dim Objeto As New ClsIndicadores If Objeto.GetRolesIndicadores(CveRol) Then GvIndicadores.DataSource = Objeto.DtResultados End If GvIndicadores.DataBind() UpDatos.Update() Objeto.Dispose() End Sub Private Sub GvIndicadores_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvIndicadores.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.DBCampo("CveRol").ToString.ToEntero = CveRol Then e.Row.FCCheckBox("chkIndicador").Checked = True End If End If End Sub #End Region #Region "P E R M I S O S" Protected Sub GvPermisos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvPermisos.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If (e.Row.DBCampo("CveModuloAcceso")) <> "" Then e.Row.FCCheckBox("ChkP").Checked = True End If End Sub Private Sub CargaGridPermisos() Dim ObjPermisos As New ClsSisRoles() If ObjPermisos.GetRolesModulos(CveRol, -1, -1, UsuarioActual.CveEmpresa) Then GvPermisos.DataSource = ObjPermisos.DtResultados.FiltraParametros(" CvePlataforma IN (1,4) AND AGRUPACION ='N'") Else GvPermisos.DataSource = Nothing End If ObjPermisos.Dispose() GvPermisos.DataBind() End Sub #End Region #Region "P R O C E S O S" Private Sub CargaGridProcesos() Dim ObjPermisos As New ClsSisRoles() If ObjPermisos.GetRolesProcesos(CveRol, -1) Then GvProcesos.DataSource = ObjPermisos.DtResultados Else GvProcesos.DataSource = Nothing End If ObjPermisos.Dispose() GvProcesos.DataBind() End Sub Protected Sub GvProcesos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvProcesos.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If (e.Row.DBCampo("CveModuloAcceso")) <> "" Then e.Row.Cells(0).CssClass = "bg-yellow" End If If (e.Row.DBCampo("CveProcesoAcceso")) <> "" Then e.Row.FCCheckBox("ChkP").Checked = True End If End Sub #End Region Private Sub BtnGuardar_Click(sender As Object, e As EventArgs) Handles BtnGuardar.Click Dim ObjEmpresa As New ClsSisEmpresas Dim ObjIndicador As New ClsIndicadores(ObjEmpresa.IniciaTransacSQL()) Dim Roles As New ClsSisRoles(ObjEmpresa.IniciaTransacSQL()) Dim TieneError As Boolean = False If CveRol <> -1 Then If Not Roles.UpdateRol(DdlModulo.SelectedValue.ToEntero, TxtRol.Text, UsuarioActual.CveUsuario, CveRol) Then TieneError = True Exit Sub End If 'Agregar Indicadores For Each Row As GridViewRow In GvIndicadores.Rows If Row.DataKey("CveIndicador") <> "" AndAlso Row.DataKey("CveRol") <> "" And Row.FCCheckBox("chkIndicador").Checked = False Then If Not ObjIndicador.RemoveIndicadoresRoles(Row.DataKey("CveIndicador").ToEntero, CveRol) Then TieneError = True Exit For End If End If If Row.DataKey("CveIndicador") <> "" AndAlso Row.DataKey("CveRol") = "" Then If Row.FCCheckBox("chkIndicador").Checked Then If Not ObjIndicador.AddIndicadoresRoles(Row.DataKey("CveIndicador").ToEntero, CveRol) Then TieneError = True Exit For End If End If End If Next For Each Row As GridViewRow In GvPermisos.Rows If Not Roles.UpdateRolesModulos(Row.DataKey("CveRol").ToEntero, Row.DataKey("CveModulo").ToEntero, If(Row.FCCheckBox("ChkP").Checked, 1, 0), UsuarioActual.CveUsuario) Then TieneError = True Exit For End If Next For Each Row As GridViewRow In GvProcesos.Rows If Not Roles.UpdateRolesProcesos(Row.DataKey("CveRol").ToEntero, Row.DataKey("CveProceso").ToEntero, If(Row.FCCheckBox("ChkP").Checked, 1, 0), UsuarioActual.CveUsuario) Then TieneError = True Exit For End If Next ElseIf CveRol = -1 Then If Not Roles.AddRol(DdlModulo.SelectedValue.ToEntero, TxtRol.Text, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then TieneError = True End If CveRol = Roles.CveRol For Each Row As GridViewRow In GvIndicadores.Rows If Row.DataKey("CveIndicador") <> "" AndAlso Row.DataKey("CveRol") = "" Then If Row.FCCheckBox("chkIndicador").Checked Then If Not ObjIndicador.AddIndicadoresRoles(Row.DataKey("CveIndicador").ToEntero, CveRol) Then TieneError = True Exit For End If End If End If Next For Each Row As GridViewRow In GvPermisos.Rows If Not Roles.UpdateRolesModulos(CveRol, Row.DataKey("CveModulo").ToEntero, If(Row.FCCheckBox("ChkP").Checked, 1, 0), UsuarioActual.CveUsuario) Then TieneError = True Exit For End If Next For Each Row As GridViewRow In GvProcesos.Rows If Not Roles.UpdateRolesProcesos(CveRol, Row.DataKey("CveProceso").ToEntero, If(Row.FCCheckBox("ChkP").Checked, 1, 0), UsuarioActual.CveUsuario) Then TieneError = True Exit For End If Next End If If TieneError = False Then Dim Liga As String = $"document.location.href=""/Sistemas/CatRoles.aspx"";" Alert("Se han guardado los cambios correctamente.", TipoMensaje.MsgInformacion, Liga) ObjEmpresa.Commit() Else Alert("Ha ocurrido un problema, no se han guardado los cambios.", TipoMensaje.MsgError) ObjEmpresa.RollBack() End If ObjEmpresa.Dispose() RecargaGlobal() End Sub Private Sub RecargaGlobal() GlobalDTRoles(UsuarioActual.CveEmpresa) = Nothing End Sub Private Sub GuardarArchivoAdjunto() If Not txtAdjuntar.getfiles().Archivos.Count > 0 Then Alert("Tiene que cargar un archivo.", TipoMensaje.MsgAdvertencia) Exit Sub End If Dim FileExtension As String = "-1" Dim Filesgral As List(Of Archivo) = txtAdjuntar.getfiles().Archivos Dim Filename As String = "" Dim fileItem As Archivo = Filesgral(0) Try FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "") Dim Adjunto = String.Format("{0}.{1}", Me.CveRol, FileExtension) Dim Path As String Path = String.Format("{0}Roles", UsuarioActual.Empresa.Ruta) If Not Directory.Exists(Path) Then Directory.CreateDirectory(Path) End If Path += $"/{Adjunto}" If File.Exists(Path) Then File.Delete(Path) End If My.Computer.FileSystem.MoveFile(fileItem.FileUrl, Path) If File.Exists(Path) Then If Me.CveRol > 0 Then Using ObjRol As New ClsSisRoles If ObjRol.UpdateRolAdjunto(Me.CveRol, Adjunto, UsuarioActual.CveEmpresa) Then Alert("Documento cargado", TipoMensaje.MsgInformacion) End If End Using Else Alert("Documento cargado", TipoMensaje.MsgInformacion) End If End If BtnAdjuntar.Visible = False BtnArchivoAdjunto.Text = Adjunto BtnArchivoAdjunto.Visible = True BtnReemplazarAdjunto.Visible = True Catch ex As Exception OnError("Error al cargar archivo", ex) End Try End Sub Protected Sub btnGuardarAdjunto_Click(sender As Object, e As EventArgs) GuardarArchivoAdjunto() End Sub End Class