1672 lines
No EOL
66 KiB
C#
1672 lines
No EOL
66 KiB
C#
/*===========================================================================================================================
|
||
* Instituto Costarricense de Acueductos y Alcantarillados. - 2015
|
||
* Administración de la Seguridad
|
||
* Nombre de la Pantalla: frwUsuario.aspx
|
||
*
|
||
* Explicación de los contenidos del archivo
|
||
*===========================================================================================================================
|
||
* HISTORIAL
|
||
*
|
||
* PERSONA DIA – MES - AÑO DESCRIPCIÓN
|
||
* Esteban Gutierrez Rapso 20 – 04 - 2015 Se inicia con el diseño de la pagina
|
||
* …………………………………………………………
|
||
* …………………………………………………………
|
||
*===========================================================================================================================
|
||
* Derechos Reservados (C) 2015 AyA.
|
||
* ESTE CÓDIGO ES PROVEÍDO “TAL CUAL ES” SIN GARANTÍA ALGUNA
|
||
* DE NINGÚN TIPO, SEA IMPLICITA O EXPLICITA.
|
||
* NO SE PERMITE SU REPRODUCCIÓN PARCIAL O TOTAL, NI SU COMERCIALIZACIÓN
|
||
*===========================================================================================================================
|
||
*/
|
||
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Linq;
|
||
using System.Web;
|
||
using System.Web.UI;
|
||
using System.Web.UI.WebControls;
|
||
using System.Web.UI.HtmlControls;
|
||
|
||
using AyABL;
|
||
|
||
using AyABL.AUT.Autenticacion;
|
||
using AyABL.APL;
|
||
using AyADAL;
|
||
using System.Configuration;
|
||
using AyABL.RCS;
|
||
using AyABL.Usuario;
|
||
using System.IO;
|
||
using System.Text;
|
||
|
||
|
||
|
||
|
||
public partial class Forms_Usuarios_frwUsuario : General
|
||
{
|
||
|
||
#region Inicializar Formulario (R0)
|
||
|
||
override protected void OnInit(EventArgs e) //M0
|
||
{
|
||
try
|
||
{
|
||
base.OnInit(e);
|
||
|
||
InicializarFormulario();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R0M0", ex);
|
||
}
|
||
}
|
||
|
||
private void InicializarFormulario() //M1
|
||
{
|
||
try
|
||
{
|
||
Response.Cache.SetCacheability(HttpCacheability.NoCache);
|
||
|
||
construirGridView();
|
||
construirGridUsuariosAD();
|
||
|
||
Javascript.CheckAllGridViewItems(Page);
|
||
|
||
cuwBusquedaList.Buscar += new _controlesusuario_Estandar_cuwBusquedaList.SearchEvent(Buscar);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R0M1", ex);
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Variables (R1)
|
||
|
||
GridView grvListaDatosUsuariosTemp, grvUsuariosADTemp;
|
||
|
||
UsuarioBL objUsuarioBL;
|
||
AutenticacionBL objAutenticacionBL;
|
||
UsuarioRolBL objUsuarioRolBL;
|
||
|
||
RolBL objRolBL;
|
||
ArrayList arlCondicionesFiltroBusqueda = new ArrayList();
|
||
oficinaayaBL objDependenciaBL;
|
||
|
||
DataSet dsUsuarios;
|
||
#endregion
|
||
|
||
#region Eventos Formulario (R2)
|
||
|
||
protected void Page_Load(object sender, EventArgs e) //M0
|
||
{
|
||
try
|
||
{
|
||
//Este codigo es para obligar al boton a hacer un postback completo y no uno parcial que se da cuando el boton esta dentro del updatepanel
|
||
ScriptManager.GetCurrent(Page).RegisterPostBackControl(btnImprimir);
|
||
|
||
if ((!IsPostBack) && (Session.Count > 0))
|
||
{
|
||
llenarGridView(true);
|
||
mostrarFilaTabla(1);
|
||
llenarDDLRol();
|
||
|
||
llenarDDLtipoInspeccion();
|
||
llenarDDLdependencia();
|
||
ComandosxMenu();
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R2M0", ex);
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Eventos Controles Web (R3)
|
||
|
||
/// <summary>
|
||
/// Metodo que se utiliza para extraer información del registro de la base de datos y ser mostrado en el acordeon de Controles
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
|
||
protected void grvListaDatosUsuarios_RowCommand(object sender, GridViewCommandEventArgs e) //M0
|
||
{
|
||
try
|
||
{
|
||
if (e.CommandName == "editar")
|
||
{
|
||
int i = Convert.ToInt32(e.CommandArgument);
|
||
GridViewRow selectedRow = grvListaDatosUsuarios.Rows[i];
|
||
int intPkUsuario = Convert.ToInt32(selectedRow.Cells[2].Text);
|
||
ViewState["PkUsuario"] = intPkUsuario;
|
||
ViewState["MODO"] = "Modifica";
|
||
|
||
mostrarFilaTabla(3);
|
||
|
||
mostrarDatos(intPkUsuario);
|
||
|
||
llenarGridViewDependencias(selectedRow.Cells[4].Text);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R3M0", ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Metodo que se utiliza para la paginación del Grid en caso de que el usuario desee ver mas registros
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
|
||
protected void grvListaRoles_PageIndexChanging(object sender, GridViewPageEventArgs e) //M1
|
||
{
|
||
try
|
||
{
|
||
// grvListaRoles.PageIndex = e.NewPageIndex;
|
||
llenarGridView(true);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R3M1", ex);
|
||
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Metodo que se utiliza para borrar el rol del listado de roles
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
|
||
protected void grvListaRoles_RowCommand(object sender, GridViewCommandEventArgs e) //M2
|
||
{
|
||
//try
|
||
//{
|
||
// if (e.CommandName == "borrar")
|
||
// {
|
||
// int i = Convert.ToInt32(e.CommandArgument);
|
||
// //GridViewRow selectedRow = grvListaRoles.Rows[i];
|
||
// int intPkRole = Convert.ToInt32(selectedRow.Cells[1].Text);
|
||
// if (removerRole(intPkRole))
|
||
// llenarGridRol(Int32.Parse(ViewState["PkUsuario"].ToString()));
|
||
|
||
// GuardarEventoBitacora(
|
||
// Session["LOGIN"].ToString(),
|
||
// AccionBitacora.INSERT.ToString(),
|
||
// MensajesBitacora.EliminarRegistro + ": Se ha eliminado el rol " + selectedRow.Cells[1].Text,
|
||
// "frwUsuario.aspx",
|
||
// Convert.ToInt32(ConfigurationManager.AppSettings["pkApp"])
|
||
// );
|
||
// }
|
||
//}
|
||
//catch (Exception ex)
|
||
//{
|
||
// MensajeError("Error en R3M2", ex);
|
||
//}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Metodo que se utiliza para la paginación del Grid en caso de que el usuario desee ver mas registros
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
|
||
protected void grvListaDatosUsuarios_PageIndexChanging(object sender, GridViewPageEventArgs e) //M3
|
||
{
|
||
try
|
||
{
|
||
grvListaDatosUsuarios.PageIndex = e.NewPageIndex;
|
||
llenarGridView(true);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R3M3", ex);
|
||
}
|
||
}
|
||
|
||
///<summary>
|
||
///Activar el botón de Refrescar
|
||
///</summary>
|
||
///<param name="sender"></param>
|
||
///<param name="e"></param>
|
||
|
||
protected void btnRefrescar_Click(object sender, System.Web.UI.ImageClickEventArgs e) //M4
|
||
{
|
||
try
|
||
{
|
||
llenarGridView(true);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R3M4" + MensajesAplicacion.RefrescarFallido.ToString(), ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Extrae información del registro de la base de datos y ser mostrado en el acordeon de Controles
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
|
||
protected void grvUsuariosAD_RowCommand(object sender, GridViewCommandEventArgs e) //M5
|
||
{
|
||
try
|
||
{
|
||
if (e.CommandName == "editar")
|
||
{
|
||
//Extrae la fila seleccionada del GridView
|
||
int intIndice = Convert.ToInt32(e.CommandArgument);
|
||
GridViewRow selectedRow = grvUsuariosAD.Rows[intIndice];
|
||
|
||
txtLoginAD.Text = selectedRow.Cells[1].Text;
|
||
txtFuncionario.Text = HttpUtility.HtmlDecode(selectedRow.Cells[2].Text);
|
||
txtCedulaAD.Text = selectedRow.Cells[3].Text;
|
||
txtCorreo.Text = this.txtLoginAD.Text + "@aya.go.cr";
|
||
txtLoginAP.Text = selectedRow.Cells[1].Text;
|
||
|
||
if (selectedRow.Cells[3].Text.Trim().Length > 0)
|
||
{
|
||
//cargar los datos aqui
|
||
condicionesBusqueda();
|
||
|
||
objUsuarioBL = new UsuarioBL();
|
||
if (selectedRow.Cells[3].Text.Length == 10)
|
||
objUsuarioBL.objUsuarioEL.Empleado = selectedRow.Cells[3].Text;
|
||
else
|
||
objUsuarioBL.objUsuarioEL.Empleado = "0" + selectedRow.Cells[3].Text;
|
||
DataSet dsUsuarios = objUsuarioBL.dsPersonal();
|
||
|
||
if (dsUsuarios.Tables[0].Rows.Count != 0)
|
||
{
|
||
txtAplicacion.Text = "SISTEMA DE DISPONIBILIDAD DE SERVICIO DE AGUA Y ALCANTARILLADO SANITARIO";
|
||
//txtDependencia.Text = dsUsuarios.Tables[0].Rows[0]["DEPENDENCIA"].ToString();
|
||
txtEmpleado.Text = dsUsuarios.Tables[0].Rows[0]["NBR_EMPLEADO"].ToString() + " " + dsUsuarios.Tables[0].Rows[0]["APE_1"].ToString() + " " + dsUsuarios.Tables[0].Rows[0]["APE_2"].ToString();
|
||
txtCedula.Text = dsUsuarios.Tables[0].Rows[0]["CEDULA"].ToString();
|
||
if (dsUsuarios.Tables[0].Rows[0]["EDO_EMPLEADO"].ToString() == "A")
|
||
chkActivo.Checked = true;
|
||
else
|
||
chkActivo.Checked = false;
|
||
}
|
||
else
|
||
MensajeAlerta("Este empleado no se encuentra incluido en la base de datos de STARH");
|
||
|
||
objUsuarioBL = new UsuarioBL();
|
||
objUsuarioBL.objUsuarioEL.USUARIO = this.txtLoginAD.Text.Trim();
|
||
//DataSet dsAcceso = objUsuarioBL.dsAccesoUsuario(objUsuarioBL.objUsuarioEL);
|
||
//if (dsAcceso.Tables[0].Rows.Count > 0)
|
||
//{
|
||
|
||
// MensajeAlerta("Este empleado ya se encuentra incluido en esta aplicación.");
|
||
//}
|
||
//else
|
||
DataSet dsAcceso = objUsuarioBL.dsAccesoUsuario(objUsuarioBL.objUsuarioEL);
|
||
if (dsAcceso.Tables[0].Rows.Count > 0)
|
||
{
|
||
//MensajeInformativo("El usuario solicitado no existe en el directorio activo o se encuentra deshabilitado.");
|
||
//ddlRegion.SelectedValue = dsAcceso.Tables[0].Rows[0]["FKDEPENDENCIAUSUARIOXDEPENDENCIA"].ToString();
|
||
ddlDependencia.SelectedValue = dsAcceso.Tables[0].Rows[0]["FKDEPENDENCIA"].ToString();
|
||
|
||
txtTelefonoCubiculo.Text = dsAcceso.Tables[0].Rows[0]["TELEFONOCUBICULOUSUARIOXDEPENDENCIA"].ToString();
|
||
chkDirector.Checked = bool.Parse(dsAcceso.Tables[0].Rows[0]["DIRECTORUSUARIOXDEPENDENCIA"].ToString());
|
||
chkJefatura.Checked = bool.Parse(dsAcceso.Tables[0].Rows[0]["JEFATURAUSUARIOXDEPENDENCIA"].ToString());
|
||
txtObservaciones.Text = dsAcceso.Tables[0].Rows[0]["OBSERVACIONESUSUARIOXDEPENDENCIA"].ToString();
|
||
ddlTipoInspeccion.Text = dsAcceso.Tables[0].Rows[0]["FKTIPOINSPECCION"].ToString();
|
||
lblRegion.Text = lblRegion.Text = "(Región: " + dsAcceso.Tables[0].Rows[0]["DESCRIPCIONREGION"].ToString() + ")";
|
||
}
|
||
{
|
||
|
||
mostrarFilaTabla(3);
|
||
ddlRol.Focus();
|
||
llenarGridRol(-1);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
MensajeAlerta("Este empleado no presenta el número de cedula registrado en el Active Directory del AyA.");
|
||
}
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R3M5", ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Metodo que se utiliza para la paginación del Grid en caso de que el usuario desee ver mas registros
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
|
||
protected void grvUsuariosAD_PageIndexChanging(object sender, GridViewPageEventArgs e) //M6
|
||
{
|
||
try
|
||
{
|
||
grvUsuariosAD.PageIndex = e.NewPageIndex;
|
||
grvUsuariosAD.SelectedIndex = -1;
|
||
llenarGrvUsuariosAD(txtDatos.Text);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R3M6", ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Activa el evento del botón Buscar (binoculares)
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnBuscar_Click(object sender, System.Web.UI.ImageClickEventArgs e) //M7
|
||
{
|
||
try
|
||
{
|
||
llenarGridView(true);
|
||
}
|
||
catch(Exception ex)
|
||
{
|
||
MensajeError("Error en R3M7" + MensajesAplicacion.UsuarioInexistente.ToString(), ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Activa el evento del boton Nuevo
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
|
||
protected void btnNuevo_Click(object sender, EventArgs e) //M8
|
||
{
|
||
try
|
||
{
|
||
limpiarCampos();
|
||
ViewState["MODO"] = "Nuevo";
|
||
mostrarFilaTabla(2);
|
||
//Limpia el grid de Active Directory
|
||
grvUsuariosAD.DataBind();
|
||
txtDatos.Focus();
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R3M8" + MensajesAplicacion.GuardadoFallido.ToString(), ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Metodo que activa el botón de Eliminar
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
|
||
protected void btnActivar_Click(object sender, EventArgs e) //M9
|
||
{
|
||
try
|
||
{
|
||
|
||
foreach (GridViewRow row in grvListaDatosUsuarios.Rows)
|
||
{
|
||
HtmlInputCheckBox chkTemp = (HtmlInputCheckBox)row.Controls[0].Controls[1];
|
||
if (chkTemp != null)
|
||
{
|
||
// si el registro esta marcado
|
||
if (chkTemp.Checked)
|
||
{
|
||
int intPkEliminar = Convert.ToInt32(row.Cells[2].Text);
|
||
ActivarDesactivar(intPkEliminar);
|
||
MensajeInformativo(AyABL.BASESDEDATOS.ADS + "Interfaz: " + MensajesAplicacion.GuardadoExitoso.ToString());
|
||
}
|
||
}
|
||
}
|
||
llenarGridView(true);
|
||
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R3M9", ex);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// Activa el evento del ddlApp para cargar el listado de roles de la aplicación seleccionada
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
|
||
protected void ddlAplicacion_SelectedIndexChanged(object sender, EventArgs e) //M10
|
||
{
|
||
try
|
||
{
|
||
llenarDDLRol();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R3M10", ex);
|
||
}
|
||
|
||
}
|
||
|
||
///<summary>
|
||
///Activa el metodo del boton Anterior, regresa a la primera fila de la tabla
|
||
///</summary>
|
||
///<param name="sender"></param>
|
||
///<param name="e"></param>
|
||
|
||
protected void btnAnterior_Click(object sender, EventArgs e) //M12
|
||
{
|
||
try
|
||
{
|
||
llenarGridView(true);
|
||
divDatosSuperiores.Visible = true;
|
||
divDatosMedios.Visible = false;
|
||
divDatosInferiores.Visible = false;
|
||
limpiarCampos();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R3M12", ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Buscar usuarios en el Active Directory.
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
|
||
protected void btnBuscarAD_Click(object sender, EventArgs e) //M13
|
||
{
|
||
try
|
||
{
|
||
llenarGrvUsuariosAD(txtDatos.Text);
|
||
EjecutarScript("$('#MainContent_grvUsuariosAD > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > input:nth-child(1)').attr('title', 'Nuevo');");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R3M13" + MensajesAplicacion.BusquedaFallido.ToString(), ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Activa el evento del boton guardar.1
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
|
||
protected void btnGuardar_Click(object sender, EventArgs e) //M14
|
||
{
|
||
try
|
||
{
|
||
|
||
{
|
||
string strModo = ViewState["MODO"].ToString();
|
||
if (ddlDependencia.SelectedValue == "-1")
|
||
{
|
||
MensajeAlerta("Debe seleccionar la dependencia del usuario.");
|
||
ddlDependencia.Focus();
|
||
}
|
||
else
|
||
{
|
||
|
||
if (ddlRol.SelectedValue == "-1" )
|
||
{
|
||
MensajeAlerta("Debe seleccionar el Rol del usuario.");
|
||
ddlRol.Focus();
|
||
|
||
}
|
||
else
|
||
{
|
||
int pkRegistro = GuardarDatos();
|
||
llenarGridView(true);
|
||
mostrarFilaTabla(1);
|
||
llenarDDLRol();
|
||
|
||
llenarDDLtipoInspeccion();
|
||
llenarDDLdependencia();
|
||
limpiarCampos();
|
||
MensajeInformativo(AyABL.BASESDEDATOS.ADS + "Interfaz: " + MensajesAplicacion.GuardadoExitoso.ToString());
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R3M14", ex);
|
||
}
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
#region Metodos Personalizados (R4)
|
||
|
||
/// <summary>
|
||
/// Oculta las filas que lo requieran
|
||
/// </summary>
|
||
/// <param name="p_intFila"></param>
|
||
private void mostrarFilaTabla(int p_intFila) //M0
|
||
{
|
||
try
|
||
{
|
||
divDatosSuperiores.Visible = false;
|
||
divDatosMedios.Visible = false;
|
||
divDatosInferiores.Visible = false;
|
||
|
||
switch (p_intFila)
|
||
{
|
||
case 1:
|
||
llenarGridView(true);
|
||
divDatosSuperiores.Visible = true;
|
||
break;
|
||
case 2:
|
||
llenarGridView(true);
|
||
divDatosMedios.Visible = true;
|
||
break;
|
||
case 3:
|
||
llenarGridView(true);
|
||
divDatosInferiores.Visible = true;
|
||
break;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Metodo que se utiliza para contruir el Grid al inicio de la pantalla
|
||
/// </summary>
|
||
private void construirGridView() //M1
|
||
{
|
||
try
|
||
{
|
||
grvListaDatosUsuariosTemp = (GridView)tdLista.FindControl("grvListaDatosUsuarios");
|
||
|
||
GridViewBoundField bdfPkUsuario = new GridViewBoundField("PKUSUARIO", "PK", false, false, false);
|
||
GridViewBoundField bdfFkEmpleado = new GridViewBoundField("FKEMPLEADO", "Cédula", true, false, true);
|
||
GridViewBoundField bdfLoginUsuario = new GridViewBoundField("LOGINUSUARIO", "Login", true, false, true);
|
||
GridViewBoundField bdfNombreCompleto = new GridViewBoundField("NOMBRECOMPLETO", "Nombre", true, false, true);
|
||
//GridViewBoundField bdfNombreDependencia = new GridViewBoundField("DEPENDENCIA", "Dependencia", true, false, true);
|
||
//GridViewBoundField bdfUbicacion = new GridViewBoundField("UBICACION", "Ubicación", true, false, true);
|
||
GridViewBoundField bdfActivoUsuario = new GridViewBoundField("ACTIVOUSUARIO", "Activo", true, "Si", "No", true);
|
||
|
||
grvListaDatosUsuariosTemp.Columns.Add(bdfPkUsuario);
|
||
grvListaDatosUsuariosTemp.Columns.Add(bdfFkEmpleado);
|
||
grvListaDatosUsuariosTemp.Columns.Add(bdfLoginUsuario);
|
||
grvListaDatosUsuariosTemp.Columns.Add(bdfNombreCompleto);
|
||
//grvListaDatosUsuariosTemp.Columns.Add(bdfNombreDependencia);
|
||
//grvListaDatosUsuariosTemp.Columns.Add(bdfUbicacion);
|
||
grvListaDatosUsuariosTemp.Columns.Add(bdfActivoUsuario);
|
||
|
||
grvListaDatosUsuariosTemp.Columns[0].ItemStyle.Width = 25;
|
||
grvListaDatosUsuariosTemp.Columns[0].HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
|
||
grvListaDatosUsuariosTemp.Columns[0].ItemStyle.HorizontalAlign = HorizontalAlign.Center;
|
||
grvListaDatosUsuariosTemp.Columns[1].ItemStyle.Width = 25;
|
||
|
||
//grvListaDatosUsuarios.PageSize = 5;
|
||
cuwBusquedaList.LlenarCHKLBusqueda(grvListaDatosUsuariosTemp);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// Metodo que se encarga de agregar el filtro de busqueda seleccionado por el usuario
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
//private void condicionesBusqueda() //M2
|
||
//{
|
||
// objUsuarioBL = new UsuarioBL();
|
||
// CondicionDAL condicion;
|
||
// DateTime dteFechaInicio = new DateTime();
|
||
// DateTime dteFechaFin = new DateTime();
|
||
// ListItem li = new ListItem();
|
||
// string p_parametros;
|
||
// p_parametros = this.cuwBusquedaList.getValorBusqueda();
|
||
// try
|
||
// {
|
||
// if (p_parametros != "")
|
||
// {
|
||
// //aqui se construye el listItem con los datos que vienen del control en formato {valor : texto , valor : texto}
|
||
// char[] separadorTuplas = { ',' };
|
||
// char[] separadorValores = { ':' };
|
||
// string[] arrayTupla = p_parametros.Split(separadorTuplas);
|
||
|
||
// for (int i = 0; i <= (arrayTupla.Length - 1); i++)
|
||
// {
|
||
// if (arrayTupla[i].ToString() != "")
|
||
// {
|
||
// string[] arrayValores = arrayTupla[i].ToString().Split(separadorValores);
|
||
// li = new ListItem(arrayValores[1], arrayValores[0]);
|
||
|
||
// if (li.Value.Contains("FECHA") && li.Text != string.Empty)
|
||
// {
|
||
|
||
// if (li.Value.Contains("INICIO"))
|
||
// {
|
||
// dteFechaInicio = Convert.ToDateTime(li.Text.ToString());
|
||
// }
|
||
// if (li.Value.Contains("FIN"))
|
||
// {
|
||
// dteFechaFin = Convert.ToDateTime(li.Text.ToString());
|
||
|
||
// if (dteFechaFin != null || dteFechaInicio != null)
|
||
// if (dteFechaInicio < dteFechaFin || dteFechaFin == dteFechaInicio)
|
||
// {
|
||
// objUsuarioBL = new UsuarioBL();
|
||
// arlCondicionesFiltroBusqueda = objUsuarioBL.buscarPorFechas(Tablas.USUARIO, dteFechaInicio, dteFechaFin, operadorLogico.AND);
|
||
// }
|
||
// else
|
||
// MensajeInformativo(AyABL.BASESDEDATOS.ADS + "Interfaz: " + "Verifique que la Fecha de Inicio sea menor que la Fecha Final" + "M2");
|
||
// else
|
||
// MensajeInformativo(AyABL.BASESDEDATOS.ADS + "Interfaz: " + "Verifique que los campos de las fechas no estén vacíos" + "M2");
|
||
// }
|
||
// }
|
||
// else
|
||
// {
|
||
// if (li.Value.Contains("booleano") && li.Text != "2")
|
||
// {
|
||
// condicion = new CondicionDAL();
|
||
// char[] separadorColumna = { '|' };
|
||
// string[] strColumna = li.Value.Split(separadorColumna);
|
||
// condicion.valorIzquierdo = strColumna[1].ToString();
|
||
// condicion.operadorGeneral = operadorGeneral.EQUAL;
|
||
// condicion.operadorLogico = operadorLogico.AND;
|
||
// condicion.valorDerecho = li.Text;
|
||
// arlCondicionesFiltroBusqueda.Add(condicion);
|
||
// }
|
||
// else
|
||
// {
|
||
// if (li.Text != string.Empty && !li.Value.Contains("booleano"))
|
||
// {
|
||
// condicion = new CondicionDAL();
|
||
// condicion.valorIzquierdo = li.Value;
|
||
// condicion.operadorGeneral = operadorGeneral.LIKEALL;
|
||
// condicion.operadorLogico = operadorLogico.AND;
|
||
// condicion.valorDerecho = "%" + li.Text + "%";
|
||
// arlCondicionesFiltroBusqueda.Add(condicion);
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// catch (Exception ex)
|
||
// {
|
||
// throw ex;
|
||
// }
|
||
|
||
//}
|
||
private void condicionesBusqueda() //M2
|
||
{
|
||
objUsuarioBL = new UsuarioBL();
|
||
CondicionDAL condicion;
|
||
DateTime dteFechaInicio = new DateTime();
|
||
DateTime dteFechaFin = new DateTime();
|
||
ListItem li = new ListItem();
|
||
string p_parametros;
|
||
p_parametros = this.cuwBusquedaList.getValorBusqueda();
|
||
try
|
||
{
|
||
if (p_parametros != "")
|
||
{
|
||
//aqui se construye el listItem con los datos que vienen del control en formato {valor : texto , valor : texto}
|
||
char[] separadorTuplas = { ',' };
|
||
char[] separadorValores = { ':' };
|
||
string[] arrayTupla = p_parametros.Split(separadorTuplas);
|
||
|
||
for (int i = 0; i <= (arrayTupla.Length - 1); i++)
|
||
{
|
||
if (arrayTupla[i].ToString() != "")
|
||
{
|
||
string[] arrayValores = arrayTupla[i].ToString().Split(separadorValores);
|
||
li = new ListItem(arrayValores[1], arrayValores[0]);
|
||
|
||
if (li.Value.Contains("FECHA") && li.Text != string.Empty)
|
||
{
|
||
|
||
if (li.Value.Contains("INICIO"))
|
||
{
|
||
dteFechaInicio = Convert.ToDateTime(li.Text.ToString());
|
||
dteFechaFin = DateTime.Now;
|
||
}
|
||
if (li.Value.Contains("FIN"))
|
||
{
|
||
dteFechaFin = Convert.ToDateTime(li.Text.ToString());
|
||
|
||
if (dteFechaFin != null || dteFechaInicio != null)
|
||
if (dteFechaInicio < dteFechaFin || dteFechaFin == dteFechaInicio)
|
||
{
|
||
objUsuarioBL = new UsuarioBL();
|
||
arlCondicionesFiltroBusqueda = objUsuarioBL.buscarPorFechas(Tablas.BITACORA, dteFechaInicio, dteFechaFin, operadorLogico.AND, arlCondicionesFiltroBusqueda);
|
||
}
|
||
else
|
||
MensajeInformativo(AyABL.BASESDEDATOS.ADS + "Interfaz: " + "Verifique que la Fecha de Inicio sea menor que la Fecha Final" + "M2");
|
||
else
|
||
MensajeInformativo(AyABL.BASESDEDATOS.ADS + "Interfaz: " + "Verifique que los campos de las fechas no estén vacíos" + "M2");
|
||
}
|
||
else
|
||
{
|
||
objUsuarioBL = new UsuarioBL();
|
||
arlCondicionesFiltroBusqueda = objUsuarioBL.buscarPorFechas(Tablas.BITACORA, dteFechaInicio, dteFechaFin, operadorLogico.AND, arlCondicionesFiltroBusqueda);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (li.Value.Contains("booleano") && li.Text != "2")
|
||
{
|
||
condicion = new CondicionDAL();
|
||
char[] separadorColumna = { '|' };
|
||
string[] strColumna = li.Value.Split(separadorColumna);
|
||
condicion.valorIzquierdo = strColumna[1].ToString();
|
||
condicion.operadorGeneral = operadorGeneral.EQUAL;
|
||
condicion.operadorLogico = operadorLogico.AND;
|
||
condicion.valorDerecho = li.Text.Trim();
|
||
arlCondicionesFiltroBusqueda.Add(condicion);
|
||
}
|
||
else
|
||
{
|
||
if (li.Text != string.Empty && !li.Value.Contains("booleano"))
|
||
{
|
||
condicion = new CondicionDAL();
|
||
condicion.valorIzquierdo = li.Value;
|
||
condicion.operadorGeneral = operadorGeneral.LIKEALL;
|
||
condicion.operadorLogico = operadorLogico.AND;
|
||
condicion.valorDerecho = "%" + li.Text.Trim() + "%";
|
||
arlCondicionesFiltroBusqueda.Add(condicion);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// Metodo que se utiliza con el buscador de la parte superior de la pantalla, y hace que se despliegue la información de acuerdo
|
||
/// a lo solicitado
|
||
/// </summary>|
|
||
private void Buscar() //M4
|
||
{
|
||
try
|
||
{
|
||
llenarGridView(true);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Constrye el Grid de los usuarios en el active
|
||
/// </summary>
|
||
private void construirGridUsuariosAD() //M5
|
||
{
|
||
try
|
||
{
|
||
grvUsuariosADTemp = (GridView)tdDatosMedios.FindControl("grvUsuariosAD");
|
||
|
||
GridViewBoundField bdfLogin = new GridViewBoundField("Login", "LOGIN", false, false, true);
|
||
GridViewBoundField bdfNombre = new GridViewBoundField("Nombre", "NOMBRE", false, false, true);
|
||
GridViewBoundField bdfCedula = new GridViewBoundField("Cedula", "CEDULA", false, false, true);
|
||
|
||
grvUsuariosADTemp.Columns.Add(bdfLogin);
|
||
grvUsuariosADTemp.Columns.Add(bdfNombre);
|
||
grvUsuariosADTemp.Columns.Add(bdfCedula);
|
||
grvUsuariosADTemp.Columns[0].ItemStyle.Width = 45;
|
||
grvUsuariosADTemp.Columns[1].ItemStyle.Width = 125;
|
||
grvUsuariosADTemp.Columns[2].ItemStyle.Width = 325;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Metodo que se utiliza para el despliegue de los botones
|
||
/// </summary>
|
||
private void ComandosxMenu() //M6
|
||
{
|
||
try
|
||
{
|
||
DataSet dsComandos = getComandos();
|
||
|
||
|
||
|
||
if (dsComandos != null)
|
||
{
|
||
foreach (DataRow drTemp in dsComandos.Tables[0].Rows)
|
||
{
|
||
switch (drTemp["NOMBRECOMANDO"].ToString().ToUpper())
|
||
{
|
||
case "NUEVO":
|
||
|
||
btnNuevo.Visible = true;
|
||
btnBuscarAD.Visible = true;
|
||
btnActivar.Visible = true;
|
||
btnGuardar.Visible = true;
|
||
break;
|
||
|
||
case "MODIFICA":
|
||
//Inicio de variable tipo VIEWSTATE
|
||
ViewState["PUEDEMODIFICAR"] = true;
|
||
btnGuardar.Visible = true;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Metodo que se utiliza para remover el role asignado al usuario
|
||
/// </summary>
|
||
/// <param name="p_intPkRole"></param>
|
||
private bool removerRole(int p_intPkRole) //M7
|
||
{
|
||
bool blnValorRetornado = false;
|
||
try
|
||
{
|
||
objUsuarioRolBL = new UsuarioRolBL();
|
||
objUsuarioRolBL.objUsuarioRolEL.Rol = p_intPkRole;
|
||
objUsuarioRolBL.objUsuarioRolEL.Usuario = Int32.Parse(ViewState["PkUsuario"].ToString());
|
||
objUsuarioRolBL.eliminarUsuarioRol();
|
||
blnValorRetornado = true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
return blnValorRetornado;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Imprime el contendo del gridview
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Imprimir(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
condicionesBusqueda();
|
||
dsUsuarios = objUsuarioBL.dsListaUsuarios(arlCondicionesFiltroBusqueda);
|
||
DataTable dt = dsUsuarios.Tables[0];
|
||
String FileName = "Reporte_Usuarios";
|
||
|
||
if (dt.Rows.Count > 0)
|
||
{
|
||
string filename = FileName + ".xls";
|
||
System.IO.StringWriter tw = new System.IO.StringWriter();
|
||
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
|
||
DataGrid dgGrid = new DataGrid();
|
||
dgGrid.DataSource = dt;
|
||
dgGrid.DataBind();
|
||
|
||
//Get the HTML for the control.
|
||
dgGrid.RenderControl(hw);
|
||
//Write the HTML back to the browser.
|
||
//Response.ContentType = application/vnd.ms-excel;
|
||
Response.ContentType = "application/vnd.ms-excel";
|
||
Response.AppendHeader("Content-Disposition",
|
||
"inline; filename=" + filename + "");
|
||
this.EnableViewState = false;
|
||
Response.Write(tw.ToString());
|
||
Response.End();
|
||
}
|
||
}
|
||
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
#region Metodos Controles a Datos (R5)
|
||
|
||
/// <summary>
|
||
/// guarda y modifica registros en la tabla.
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private int GuardarDatos() //M0
|
||
{
|
||
int nValorRetornado = 0;
|
||
int nValorRetornadoRol = 0;
|
||
|
||
try
|
||
{
|
||
string strModo = ViewState["MODO"].ToString();
|
||
|
||
objUsuarioBL = new UsuarioBL();
|
||
objUsuarioBL.objUsuarioEL.USUARIO = txtLoginAP.Text.Trim();
|
||
objUsuarioBL.objUsuarioEL.Login = txtLoginAP.Text.Trim();
|
||
objUsuarioBL.objUsuarioEL.Activo = chkActivo.Checked;
|
||
objUsuarioBL.objUsuarioEL.Empleado = txtCedula.Text;
|
||
if ( ddlDependencia.SelectedValue != "-1")
|
||
objUsuarioBL.objUsuarioEL.FKDEPENDENCIA = int.Parse(ddlDependencia.SelectedValue);
|
||
|
||
|
||
objUsuarioBL.objUsuarioEL.TELEFONOCUBICULO = txtTelefonoCubiculo.Text;
|
||
objUsuarioBL.objUsuarioEL.DIRECTOR = chkDirector.Checked;
|
||
objUsuarioBL.objUsuarioEL.JEFATURA = chkJefatura.Checked;
|
||
objUsuarioBL.objUsuarioEL.OBSERVACIONES = txtObservaciones.Text;
|
||
//if (ddlTipoInspeccion.SelectedValue != "-1")
|
||
objUsuarioBL.objUsuarioEL.FKTIPOINSPECCION = int.Parse(ddlTipoInspeccion.SelectedValue);
|
||
|
||
objUsuarioRolBL = new UsuarioRolBL();
|
||
if (ddlRol.SelectedValue != "-1")
|
||
{
|
||
|
||
|
||
//ViewState["PkRol"] = Int32.Parse(ddlRol.SelectedValue);
|
||
objUsuarioRolBL.objUsuarioRolEL.Rol = Int32.Parse(ddlRol.SelectedValue);
|
||
}
|
||
//verificamos el numero rol
|
||
if (ViewState["PkUsuario"] == null)
|
||
{
|
||
UsuarioBL objUsuarioConsultaRolBL = new UsuarioBL();
|
||
objUsuarioConsultaRolBL.objUsuarioEL.PK = Int32.Parse(ViewState["PkUsuario"].ToString());
|
||
DataSet dsUsuario = objUsuarioBL.dsListaUsuarios(null);
|
||
|
||
if (dsUsuario.Tables[0].Rows.Count > 0)
|
||
{
|
||
ViewState["PkRol"] = dsUsuario.Tables[0].Rows[0]["PKUSUARIOROL"].ToString();
|
||
|
||
}
|
||
}
|
||
if (strModo == "Nuevo")
|
||
{
|
||
nValorRetornado = objUsuarioBL.insertarUsuario();
|
||
if (int.Parse(ViewState["PkRol"].ToString()) > 0 )
|
||
nValorRetornadoRol = GuardarRol(nValorRetornado);
|
||
else
|
||
GuardarRol(Int32.Parse(ViewState["PkUsuario"].ToString()));
|
||
|
||
if (nValorRetornado != 0 && nValorRetornadoRol != 0)
|
||
GuardarEventoBitacora(
|
||
Session["LOGIN"].ToString(),
|
||
AccionBitacora.INSERT.ToString(),
|
||
MensajesBitacora.IngresarRegistro + ": Se ha ingresado el usuario " + txtLoginAP.Text.Trim(),
|
||
"frwUsuario.aspx",
|
||
Convert.ToInt32(ConfigurationManager.AppSettings["pkApp"])
|
||
);
|
||
else
|
||
MensajeAlerta("Se presento un problema al guardar el registro por favor intente de nuevo.");
|
||
|
||
}
|
||
else if (strModo == "Modifica" && bool.Parse(ViewState["PUEDEMODIFICAR"].ToString()) == true)
|
||
{
|
||
DataSet dsAcceso = objUsuarioBL.dsAccesoUsuario(objUsuarioBL.objUsuarioEL);
|
||
|
||
if (dsAcceso.Tables[0].Rows.Count > 0)
|
||
nValorRetornado = objUsuarioBL.moidificarUsuario();
|
||
else
|
||
nValorRetornado = objUsuarioBL.insertarUsuario();
|
||
|
||
GuardarRol(Int32.Parse(ViewState["PkUsuario"].ToString()));
|
||
|
||
GuardarEventoBitacora(
|
||
Session["LOGIN"].ToString(),
|
||
AccionBitacora.INSERT.ToString(),
|
||
MensajesBitacora.IngresarRegistro + ": Se ha modificado el usuario " + txtLoginAP.Text.Trim(),
|
||
"frwUsuario.aspx",
|
||
Convert.ToInt32(ConfigurationManager.AppSettings["pkApp"])
|
||
);
|
||
}
|
||
}
|
||
|
||
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
return nValorRetornado;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Guarda el rol nuevo del usuario.
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private int GuardarRol(int p_pkUsuario) //M1
|
||
{
|
||
int nValorRetornado = 0;
|
||
try
|
||
{
|
||
string strModo = ViewState["MODO"].ToString();
|
||
|
||
objUsuarioRolBL = new UsuarioRolBL();
|
||
objUsuarioRolBL.objUsuarioRolEL.Rol = Int32.Parse(ddlRol.SelectedValue);
|
||
objUsuarioRolBL.objUsuarioRolEL.Usuario = p_pkUsuario;
|
||
|
||
|
||
if (strModo == "Nuevo" && ViewState["PkRol"] == null)
|
||
{
|
||
nValorRetornado = objUsuarioRolBL.insertarUsuarioRol();
|
||
}
|
||
else if (strModo == "Modifica")
|
||
{
|
||
if (ViewState["PkRol"] != null)
|
||
{
|
||
objUsuarioRolBL.objUsuarioRolEL.PK = int.Parse(ViewState["PkRol"].ToString());
|
||
nValorRetornado = objUsuarioRolBL.actualizarUsuarioRol(objUsuarioRolBL.objUsuarioRolEL);
|
||
}
|
||
else
|
||
nValorRetornado = objUsuarioRolBL.insertarUsuarioRol();
|
||
}
|
||
return nValorRetornado;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// Activa o desactiva el usuario
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
|
||
private bool ActivarDesactivar(int p_intPkEliminar) //M2
|
||
{
|
||
bool blnValorRetornado = false;
|
||
bool blnActivo = false;
|
||
try
|
||
{
|
||
objUsuarioBL = new UsuarioBL();
|
||
objUsuarioBL.objUsuarioEL.PK = p_intPkEliminar;
|
||
DataSet dsUsuarioDS = objUsuarioBL.listarUsuarios(null, false,null);
|
||
|
||
//Verifica que el usuario se encuentre en la BD
|
||
if (dsUsuarioDS.Tables[0].Rows.Count != 0)
|
||
{
|
||
//Si esta activado que lo desactive
|
||
if (Convert.ToBoolean(dsUsuarioDS.Tables[0].Rows[0][Concepto.ACTIVO.ToString() + Tablas.USUARIO.ToString()]))
|
||
blnActivo = false;
|
||
//Si esta desactivado que lo active
|
||
else
|
||
blnActivo = true;
|
||
objUsuarioBL.objUsuarioEL.Login = dsUsuarioDS.Tables[0].Rows[0][t_ads_usuario.LOGIN.ToString() + Tablas.USUARIO.ToString()].ToString();
|
||
objUsuarioBL.objUsuarioEL.Activo = blnActivo;
|
||
objUsuarioBL.objUsuarioEL.Empleado = dsUsuarioDS.Tables[0].Rows[0][Constraints.FK.ToString() + Tablas.EMPLEADO.ToString()].ToString();
|
||
objUsuarioBL.activarInactivarUsuario();
|
||
}
|
||
GuardarEventoBitacora(
|
||
Session["LOGIN"].ToString(),
|
||
AccionBitacora.INSERT.ToString(),
|
||
MensajesBitacora.ModificarRegistro + ": Se ha puesto el registro de la PK=" + p_intPkEliminar + " en " + blnActivo,
|
||
"frwUsuario.aspx",
|
||
Convert.ToInt32(ConfigurationManager.AppSettings["pkApp"])
|
||
);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
return blnValorRetornado;
|
||
}
|
||
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
#region Metodos Datos a Controles (R6)
|
||
/// <summary>
|
||
/// Carga el grid principal
|
||
/// </summary>
|
||
/// <param name="p_Llenar"></param>
|
||
private void llenarGridView(bool p_Llenar) //M0
|
||
{
|
||
try
|
||
{
|
||
if (!IsPostBack || p_Llenar)
|
||
{
|
||
condicionesBusqueda();
|
||
dsUsuarios = objUsuarioBL.dsListaUsuarios(arlCondicionesFiltroBusqueda);
|
||
General.detalleGridView(dsUsuarios, grvListaDatosUsuariosTemp, lblTotalDatos);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Carga el grid de las dependencias asociadas al usuario
|
||
/// </summary>
|
||
/// <param name="p_Llenar"></param>
|
||
private void llenarGridViewDependencias(string strUsuario) //M0
|
||
{
|
||
try
|
||
{
|
||
|
||
|
||
detalledependenciaxusuarioBL objDetalleDependenciaxUsuarioBL = new detalledependenciaxusuarioBL();
|
||
objDetalleDependenciaxUsuarioBL.objDetalledependenciaxusuarioEL.USUARIO = strUsuario;
|
||
DataSet ds = objDetalleDependenciaxUsuarioBL.dsListaDetalledependenciaxusuario();
|
||
General.detalleGridView(ds, grvListaDependencias, lblTotalDatos);
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Muestra los datos del registro
|
||
/// </summary>
|
||
/// <param name="p_intPkConsultar"></param>
|
||
private void mostrarDatos(int p_intPkConsultar) //M1
|
||
{
|
||
try
|
||
{
|
||
|
||
limpiarCampos();
|
||
objUsuarioBL = new UsuarioBL();
|
||
objUsuarioBL.objUsuarioEL.PK = p_intPkConsultar;
|
||
DataSet dsUsuario = objUsuarioBL.dsListaUsuarios(null);
|
||
|
||
objAutenticacionBL = new AutenticacionBL();
|
||
DataSet dsUsuariosAD = objAutenticacionBL.BuscarLoginUsuario(dsUsuario.Tables[0].Rows[0]["LOGINUSUARIO"].ToString(), "", "");
|
||
|
||
|
||
if (dsUsuario.Tables[0].Rows.Count > 0)
|
||
{
|
||
|
||
//Información de Active Directory
|
||
txtLoginAD.Text = dsUsuariosAD.Tables["LoginBLs"].Rows[0]["Login"].ToString();
|
||
txtFuncionario.Text = HttpUtility.HtmlDecode(dsUsuariosAD.Tables["LoginBLs"].Rows[0]["Nombre"].ToString());
|
||
|
||
txtCedulaAD.Text = dsUsuariosAD.Tables["LoginBLs"].Rows[0]["Cedula"].ToString();
|
||
txtCorreo.Text = dsUsuariosAD.Tables["LoginBLs"].Rows[0]["Login"].ToString() + "@aya.go.cr";
|
||
|
||
//Información de Aplicación
|
||
txtLoginAP.Text = dsUsuario.Tables[0].Rows[0]["LOGINUSUARIO"].ToString();
|
||
chkActivo.Checked = bool.Parse(dsUsuario.Tables[0].Rows[0]["ACTIVOUSUARIO"].ToString());
|
||
txtAplicacion.Text = dsUsuario.Tables[0].Rows[0]["NOMBREAPLICACION"].ToString();
|
||
//txtDependencia.Text = dsUsuario.Tables[0].Rows[0]["DEPENDENCIA"].ToString();
|
||
txtEmpleado.Text = dsUsuario.Tables[0].Rows[0]["NOMBRECOMPLETO"].ToString();
|
||
txtCedula.Text = dsUsuario.Tables[0].Rows[0]["FKEMPLEADO"].ToString();
|
||
|
||
llenarGridRol(Int32.Parse(ViewState["PkUsuario"].ToString()));
|
||
ViewState["PkRol"] = dsUsuario.Tables[0].Rows[0]["PKUSUARIOROL"].ToString();
|
||
ddlRol.SelectedValue = dsUsuario.Tables[0].Rows[0]["PKROL"].ToString();
|
||
|
||
objUsuarioBL.objUsuarioEL.USUARIO = dsUsuariosAD.Tables["LoginBLs"].Rows[0]["Login"].ToString();
|
||
DataSet dsAcceso = objUsuarioBL.dsAccesoUsuario(objUsuarioBL.objUsuarioEL);
|
||
if (dsAcceso.Tables[0].Rows.Count > 0)
|
||
{
|
||
//MensajeInformativo("El usuario solicitado no existe en el directorio activo o se encuentra deshabilitado.");
|
||
//ddlRegion.SelectedValue = dsAcceso.Tables[0].Rows[0]["FKDEPENDENCIAUSUARIOXDEPENDENCIA"].ToString();
|
||
ddlDependencia.SelectedValue = dsAcceso.Tables[0].Rows[0]["FKDEPENDENCIA"].ToString();
|
||
|
||
txtTelefonoCubiculo.Text = dsAcceso.Tables[0].Rows[0]["TELEFONOCUBICULOUSUARIOXDEPENDENCIA"].ToString();
|
||
chkDirector.Checked = bool.Parse(dsAcceso.Tables[0].Rows[0]["DIRECTORUSUARIOXDEPENDENCIA"].ToString());
|
||
chkJefatura.Checked = bool.Parse(dsAcceso.Tables[0].Rows[0]["JEFATURAUSUARIOXDEPENDENCIA"].ToString());
|
||
txtObservaciones.Text = dsAcceso.Tables[0].Rows[0]["OBSERVACIONESUSUARIOXDEPENDENCIA"].ToString();
|
||
ddlTipoInspeccion.Text = dsAcceso.Tables[0].Rows[0]["FKTIPOINSPECCION"].ToString();
|
||
lblRegion.Text = lblRegion.Text = "(Región: " + dsAcceso.Tables[0].Rows[0]["DESCRIPCIONREGION"].ToString() + ")";
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
|
||
}
|
||
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Carga el grvUsuariosAD con los datos extraidos del Active Directory
|
||
/// </summary>
|
||
private void llenarGrvUsuariosAD(string p_strUsuario) //M2
|
||
{
|
||
try
|
||
{
|
||
if (txtDatos.Text.Length > 1)
|
||
{
|
||
objAutenticacionBL = new AutenticacionBL();
|
||
DataSet dsUsuariosAD = objAutenticacionBL.BuscarLoginUsuario(p_strUsuario, "", "");
|
||
//objUsuarioBL = new UsuarioBL();
|
||
//objUsuarioBL.objUsuarioEL.USUARIO = txtDatos.Text;
|
||
|
||
//DataSet dsUsuariosAD = objUsuarioBL.dsListaUsuariosStarH(null);
|
||
if (dsUsuariosAD.Tables[0].Rows.Count > 0)
|
||
General.detalleGridView(dsUsuariosAD, grvUsuariosADTemp, lblTotalDatos);
|
||
else
|
||
{
|
||
MensajeInformativo("El usuario solicitado no existe en el directorio activo o se encuentra deshabilitado.");
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Llena el dropdownlist de Roles según la aplicación
|
||
/// </summary>
|
||
private void llenarDDLRol() //M4
|
||
{
|
||
try
|
||
{
|
||
arlCondicionesFiltroBusqueda = new ArrayList();
|
||
//Limpia el control
|
||
ddlRol.Items.Clear();
|
||
//Instancia el bjeto
|
||
objRolBL = new RolBL();
|
||
//Asigna datos al atributo
|
||
objRolBL.objRolEL.Aplicacion = Convert.ToInt32(ConfigurationManager.AppSettings["pkApp"]);
|
||
objRolBL.objRolEL.Rol = 0;
|
||
objRolBL.objRolEL.Usuario = 0;
|
||
//Carga la información en un dataset
|
||
DataSet dsRol = objRolBL.dsListaRoles(arlCondicionesFiltroBusqueda);
|
||
if (dsRol.Tables[0].Rows.Count != 0)
|
||
{
|
||
ddlRol.DataSource = dsRol;
|
||
ddlRol.DataTextField = dsRol.Tables[0].Columns["NOMBREROL"].ColumnName;
|
||
ddlRol.DataValueField = dsRol.Tables[0].Columns["PKROL"].ColumnName;
|
||
|
||
ddlRol.DataBind();
|
||
|
||
ddlRol.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
||
}
|
||
else
|
||
ddlRol.Items.Insert(0, new ListItem("----- App sin Roles -----", "-1"));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// LLena el listado de roles de usuario
|
||
/// </summary>
|
||
private void llenarGridRol(int nUsuario)
|
||
{
|
||
try
|
||
{
|
||
//Instancia el objeto
|
||
objUsuarioRolBL = new UsuarioRolBL();
|
||
//Asigna un valor al atributo de referencia del objeto
|
||
objUsuarioRolBL.objUsuarioRolEL.Usuario = nUsuario;
|
||
//Carga en un dataset la información
|
||
DataSet dsRoles = objUsuarioRolBL.listarRolesxAplicacion();
|
||
// grvListaRoles.DataSource = dsRoles;
|
||
//grvListaRoles.DataBind();
|
||
//General.detalleGridView(dsRoles, grvListaRoles, null);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
///// <summary>
|
||
///// Llena el dropdownlist de Cantonales según la aplicación
|
||
///// </summary>
|
||
//private void llenarDDLregion() //M2
|
||
//{
|
||
// try
|
||
// {
|
||
// //Limpia el control
|
||
// ddlRegion.Items.Clear();
|
||
// //Instancia el bjeto
|
||
// objRegionBL = new regionBL();
|
||
// //Asigna datos al atributo
|
||
|
||
// objRegionBL.objregionEL.PK = 0;
|
||
// objRegionBL.objregionEL.Descripcion = "";
|
||
// //Carga la información en un dataset
|
||
// DataSet dsRegion = objRegionBL.dsListaRegiones(null);
|
||
// if (dsRegion.Tables[0].Rows.Count != 0)
|
||
// {
|
||
// ddlRegion.DataSource = dsRegion;
|
||
// ddlRegion.DataTextField = dsRegion.Tables[0].Columns["DESCRIPCIONREGION"].ColumnName;
|
||
// ddlRegion.DataValueField = dsRegion.Tables[0].Columns["PKREGION"].ColumnName;
|
||
// ddlRegion.DataBind();
|
||
|
||
|
||
// ddlRegion.Items.Insert(0, new ListItem("----- Seleccione una región -----", "-1"));
|
||
// }
|
||
// else
|
||
// ddlRegion.Items.Insert(0, new ListItem("----- No existen regiones -----", "-1"));
|
||
// }
|
||
// catch (Exception ex)
|
||
// {
|
||
// throw ex;
|
||
// }
|
||
//}
|
||
|
||
/// <summary>
|
||
/// Llena el dropdownlist de dependencias
|
||
/// </summary>
|
||
private void llenarDDLdependencia() //M3
|
||
{
|
||
try
|
||
{
|
||
//Limpia el control
|
||
ddlDependencia.Items.Clear();
|
||
//Instancia el bjeto
|
||
objDependenciaBL = new oficinaayaBL();
|
||
|
||
//Carga la información en un dataset
|
||
objDependenciaBL.objoficinaayaEL.PK = 0;
|
||
DataSet dsDependencia = objDependenciaBL.dsListaCantonal(null);
|
||
if (dsDependencia.Tables[0].Rows.Count != 0)
|
||
{
|
||
ddlDependencia.DataSource = dsDependencia;
|
||
ddlDependencia.DataTextField = dsDependencia.Tables[0].Columns["DESCRIPCIONDEPENDENCIASIGDD"].ColumnName;
|
||
ddlDependencia.DataValueField = dsDependencia.Tables[0].Columns["PKDEPENDENCIASIGDD"].ColumnName;
|
||
ddlDependencia.DataBind();
|
||
|
||
ddlDependencia.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
||
ddlDependencia.Items.Insert(0, new ListItem("Todos", "-2"));
|
||
}
|
||
else
|
||
ddlDependencia.Items.Insert(0, new ListItem("----- No existen dependencias -----", "-1"));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// Llena el dropdownlist de grado academico según la aplicación
|
||
/// </summary>
|
||
private void llenarDDLtipoInspeccion() //M6
|
||
{
|
||
try
|
||
{
|
||
//Limpia el control
|
||
ddlTipoInspeccion.Items.Clear();
|
||
//Instancia el bjeto
|
||
objUsuarioBL = new UsuarioBL();
|
||
//Asigna datos al atributo
|
||
|
||
|
||
//Carga la información en un dataset
|
||
DataSet dsTipoInspeccion = objUsuarioBL.dsListaTipoInspeccion(null);
|
||
if (dsTipoInspeccion.Tables[0].Rows.Count != 0)
|
||
{
|
||
ddlTipoInspeccion.DataSource = dsTipoInspeccion;
|
||
ddlTipoInspeccion.DataTextField = dsTipoInspeccion.Tables[0].Columns["DESCRIPCIONTIPOINSPECCION"].ColumnName;
|
||
ddlTipoInspeccion.DataValueField = dsTipoInspeccion.Tables[0].Columns["PKTIPOINSPECCION"].ColumnName;
|
||
ddlTipoInspeccion.DataBind();
|
||
|
||
|
||
ddlTipoInspeccion.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
||
}
|
||
else
|
||
ddlTipoInspeccion.Items.Insert(0, new ListItem("----- No existen opciones -----", "-1"));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
///<summary>
|
||
///Limpia los campos
|
||
///</summary>
|
||
private void limpiarCampos()
|
||
{
|
||
|
||
txtLoginAD.Text = string.Empty;
|
||
txtFuncionario.Text = string.Empty;
|
||
txtCedula.Text = string.Empty;
|
||
txtCorreo.Text = string.Empty;
|
||
txtDatos.Text = string.Empty;
|
||
//Información de Aplicación
|
||
txtLoginAP.Text = string.Empty;
|
||
chkActivo.Checked = false;
|
||
txtAplicacion.Text = string.Empty;
|
||
txtEmpleado.Text = string.Empty;
|
||
ddlRol.SelectedValue= "-1";
|
||
ddlDependencia.SelectedValue = "-1";
|
||
|
||
//Configuración de Aplicacion
|
||
txtObservaciones.Text = string.Empty;
|
||
txtTelefonoCubiculo.Text = string.Empty;
|
||
ddlTipoInspeccion.SelectedValue = "-1";
|
||
chkDirector.Checked = false;
|
||
chkJefatura.Checked = false;
|
||
|
||
}
|
||
#endregion
|
||
|
||
protected void grvListaDatosUsuarios_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
protected void btnAgregarDependencias_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (ddlDependencia.SelectedValue == "-1")
|
||
{
|
||
MensajeAlerta("Debe seleccionar la dependencia del usuario.");
|
||
ddlDependencia.Focus();
|
||
}
|
||
else
|
||
{
|
||
if (ViewState["PkUsuario"] == null)
|
||
{
|
||
objUsuarioBL = new UsuarioBL();
|
||
objUsuarioBL.objUsuarioEL.Login = txtLoginAP.Text.Trim();
|
||
objUsuarioBL.objUsuarioEL.Activo = chkActivo.Checked;
|
||
objUsuarioBL.objUsuarioEL.Empleado = txtCedula.Text;
|
||
if (ddlDependencia.SelectedValue != "-1")
|
||
objUsuarioBL.objUsuarioEL.FKDEPENDENCIA = int.Parse(ddlDependencia.SelectedValue);
|
||
|
||
|
||
objUsuarioBL.objUsuarioEL.TELEFONOCUBICULO = txtTelefonoCubiculo.Text;
|
||
objUsuarioBL.objUsuarioEL.DIRECTOR = chkDirector.Checked;
|
||
objUsuarioBL.objUsuarioEL.JEFATURA = chkJefatura.Checked;
|
||
objUsuarioBL.objUsuarioEL.OBSERVACIONES = txtObservaciones.Text;
|
||
//if (ddlTipoInspeccion.SelectedValue != "-1")
|
||
objUsuarioBL.objUsuarioEL.FKTIPOINSPECCION = int.Parse(ddlTipoInspeccion.SelectedValue);
|
||
ViewState["PkUsuario"] = objUsuarioBL.insertarUsuario();
|
||
ViewState["MODO"] = "Modifica";
|
||
}
|
||
detalledependenciaxusuarioBL objDetalleDependenciaxUsuario = new detalledependenciaxusuarioBL();
|
||
objDetalleDependenciaxUsuario.objDetalledependenciaxusuarioEL.USUARIO = txtLoginAP.Text.Trim();
|
||
int nPkDetalle = 0;
|
||
if (ddlDependencia.SelectedValue == "-2") // todos
|
||
{
|
||
//desasociar todas las dependencias actuales al usuario
|
||
|
||
|
||
|
||
objDetalleDependenciaxUsuario.elminardetalledependenciaxusuario();
|
||
|
||
|
||
|
||
objDependenciaBL = new oficinaayaBL();
|
||
|
||
//Carga la información en un dataset
|
||
objDependenciaBL.objoficinaayaEL.PK = 0;
|
||
DataSet dsDependencia = objDependenciaBL.dsListaCantonal(null);
|
||
if (dsDependencia.Tables[0].Rows.Count != 0)
|
||
{
|
||
foreach (DataRow row in dsDependencia.Tables[0].Rows)
|
||
{
|
||
objDetalleDependenciaxUsuario.objDetalledependenciaxusuarioEL.FKDEPENDENCIA = int.Parse(row["PKDEPENDENCIASIGDD"].ToString());
|
||
nPkDetalle = objDetalleDependenciaxUsuario.insertarDetalleDependenciaxUsuario();
|
||
if (nPkDetalle != 0)
|
||
{
|
||
MensajeInformativo("Se asoció correctamente todas las dependencias al usuario " + txtFuncionario.Text.Trim());
|
||
|
||
GuardarEventoBitacora(
|
||
Session["LOGIN"].ToString(),
|
||
AccionBitacora.INSERT.ToString(),
|
||
MensajesBitacora.IngresarRegistro + ": Se ha asociado la dependencia " + row["DESCRIPCIONDEPENDENCIASIGDD"].ToString() + " al usuario " + txtFuncionario.Text.Trim(),
|
||
"frwUsuario.aspx",
|
||
Convert.ToInt32(ConfigurationManager.AppSettings["pkApp"])
|
||
);
|
||
}
|
||
else
|
||
MensajeAlerta("Se presentó un error al agregar la dependencia.");
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
objDetalleDependenciaxUsuario.objDetalledependenciaxusuarioEL.FKDEPENDENCIA = int.Parse(ddlDependencia.SelectedValue);
|
||
nPkDetalle = objDetalleDependenciaxUsuario.insertarDetalleDependenciaxUsuario();
|
||
if (nPkDetalle != 0)
|
||
{
|
||
MensajeInformativo("Se asoció correctamente la dependencia al usuario");
|
||
|
||
GuardarEventoBitacora(
|
||
Session["LOGIN"].ToString(),
|
||
AccionBitacora.INSERT.ToString(),
|
||
MensajesBitacora.IngresarRegistro + ": Se ha asociado la dependencia " + ddlDependencia.SelectedItem.Text + " al usuario " + txtFuncionario.Text.Trim(),
|
||
"frwUsuario.aspx",
|
||
Convert.ToInt32(ConfigurationManager.AppSettings["pkApp"])
|
||
);
|
||
}
|
||
else
|
||
MensajeAlerta("Se presentó un error al agregar la dependencia.");
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Se presentó un error al agregar la dependencia.", ex);
|
||
}
|
||
finally
|
||
{
|
||
llenarGridViewDependencias(txtLoginAP.Text.Trim());
|
||
}
|
||
|
||
}
|
||
protected void grvListaDependencias_RowCommand(object sender, GridViewCommandEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (e.CommandName == "eliminar")
|
||
{
|
||
int i = Convert.ToInt32(e.CommandArgument);
|
||
GridViewRow selectedRow = grvListaDependencias.Rows[i];
|
||
int intPkDetalle = Convert.ToInt32(selectedRow.Cells[0].Text);
|
||
ViewState["PKDETALLEDEPENDENCIA"] = intPkDetalle;
|
||
|
||
|
||
mostrarFilaTabla(3);
|
||
|
||
eliminarDependencia(intPkDetalle);
|
||
llenarGridViewDependencias(txtLoginAD.Text.Trim());
|
||
|
||
GuardarEventoBitacora(
|
||
Session["LOGIN"].ToString(),
|
||
AccionBitacora.INSERT.ToString(),
|
||
MensajesBitacora.IngresarRegistro + ": Se ha desasociado la dependencia " + ddlDependencia.SelectedItem.Text + " al usuario " + txtFuncionario.Text.Trim(),
|
||
"frwUsuario.aspx",
|
||
Convert.ToInt32(ConfigurationManager.AppSettings["pkApp"])
|
||
);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R3M0 ", ex);
|
||
}
|
||
}
|
||
public void eliminarDependencia(int nPkDependencia)
|
||
{
|
||
try
|
||
{
|
||
detalledependenciaxusuarioBL objDetalleDependenciaxUsuario = new detalledependenciaxusuarioBL();
|
||
|
||
objDetalleDependenciaxUsuario.objDetalledependenciaxusuarioEL.PKDETALLEDEPENDENCIAXUSUARIO = nPkDependencia;
|
||
objDetalleDependenciaxUsuario.elminardetalledependenciaxusuario();
|
||
MensajeInformativo("Se desasoció la dependencia del usuario");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Se presentó un error al intentar eliminar la dependencia", ex);
|
||
}
|
||
|
||
}
|
||
protected void grvListaDependencias_PageIndexChanging(object sender, GridViewPageEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
grvListaDependencias.PageIndex = e.NewPageIndex;
|
||
llenarGridViewDependencias(txtLoginAD.Text.Trim());
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R3M3", ex);
|
||
}
|
||
}
|
||
protected void ddlDependencia_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
dependenciasdaaBL objDependenciaBL = new dependenciasdaaBL();
|
||
objDependenciaBL.objdependenciasdaaEL.PK = int.Parse(ddlDependencia.SelectedValue);
|
||
DataSet ds = objDependenciaBL.listarDependenciaSdaa(null,false);
|
||
if (ds.Tables[0].Rows.Count > 0)
|
||
lblRegion.Text = "(Región: " + ds.Tables[0].Rows[0]["DESCRIPCIONREGION"].ToString() + ")";
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MensajeError("Error en R3M3", ex);
|
||
}
|
||
}
|
||
} |