protected void _dgvLog_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Alterar")
        {
            int         index      = int.Parse(e.CommandArgument.ToString());
            Guid        log_id     = new Guid(_dgvLog.DataKeys[index].Value.ToString());
            LOG_Sistema logSistema = new LOG_Sistema {
                log_id = log_id
            };
            LOG_SistemaBO.GetEntity(logSistema);

            txtID.Text           = logSistema.log_id.ToString();
            txtDataHora.Text     = logSistema.log_dataHora.ToString();
            txtEnderecoIP.Text   = logSistema.log_ip;
            txtNomeMaquina.Text  = logSistema.log_machineName;
            txtSistema.Text      = logSistema.sis_nome ?? string.Empty;
            txtModulo.Text       = logSistema.mod_nome ?? string.Empty;
            txtUsuarioID.Text    = logSistema.usu_id.ToString();
            txtUsuarioLogin.Text = logSistema.usu_login ?? string.Empty;
            txtGrupoID.Text      = logSistema.gru_id != Guid.Empty ? logSistema.gru_id.ToString() : string.Empty;
            txtGrupoNome.Text    = logSistema.gru_nome ?? string.Empty;

            if (logSistema.log_grupoUA != null && logSistema.log_grupoUA != "[]")
            {
                txtGrupoUA.Text = logSistema.log_grupoUA;
            }
            else
            {
                txtGrupoUA.Text = string.Empty;
            }

            txtAcao.Text     = logSistema.log_acao;
            txtDecricao.Text = logSistema.log_descricao;

            txtID.Enabled           = false;
            txtDataHora.Enabled     = false;
            txtEnderecoIP.Enabled   = false;
            txtNomeMaquina.Enabled  = false;
            txtSistema.Enabled      = false;
            txtModulo.Enabled       = false;
            txtUsuarioID.Enabled    = false;
            txtUsuarioLogin.Enabled = false;
            txtGrupoID.Enabled      = false;
            txtGrupoNome.Enabled    = false;
            txtGrupoUA.Enabled      = false;
            txtAcao.Enabled         = false;
            txtDecricao.Enabled     = false;

            ScriptManager.RegisterClientScriptBlock(this, GetType(), "Log", "$('#divLog').dialog('open');", true);
        }
    }
示例#2
0
 /// <summary>
 /// Grava log de sistema no banco de dados.
 /// </summary>
 /// <param name="acao">Ação executada pelo usuário</param>
 /// <param name="descricao">Descrição do log</param>
 /// <param name="usu_login">Login do usuário que tentou realizar a operação (utilizado para operações de login sem sucesso)</param>
 /// <returns>Informa se o log de sistema foi salvo com sucesso.</returns>
 public static Guid _GravaLogSistema(LOG_SistemaTipo acao, string descricao)
 {
     try
     {
         LOG_Sistema entity = new LOG_Sistema();
         entity.log_acao      = Enum.GetName(typeof(LOG_SistemaTipo), acao);
         entity.log_dataHora  = DateTime.Now;
         entity.log_descricao = descricao;
         if (HttpContext.Current != null)
         {
             //Preenche dados do host do site
             LOG_SistemaBO.GenerateLogID();
             entity.log_id          = new Guid(HttpContext.Current.Session[LOG_Sistema.SessionName].ToString());
             entity.log_ip          = HttpContext.Current.Request.UserHostAddress;
             entity.log_machineName = HttpContext.Current.Server.MachineName;
             if (HttpContext.Current.Session != null)
             {
                 SessionWEB session = (SessionWEB)HttpContext.Current.Session[SessSessionWEB];
                 if (session != null)
                 {
                     //Preenche dados referente ao usuário
                     if (session.__UsuarioWEB != null && session.__UsuarioWEB.Usuario != null)
                     {
                         entity.usu_id    = session.__UsuarioWEB.Usuario.usu_id;
                         entity.usu_login = session.__UsuarioWEB.Usuario.usu_login;
                     }
                     //Preenche dados referente ao grupo do usuário
                     if (session.__UsuarioWEB != null && session.__UsuarioWEB.Grupo != null)
                     {
                         //Preenche os dados do grupo
                         entity.gru_id   = session.__UsuarioWEB.Grupo.gru_id;
                         entity.gru_nome = session.__UsuarioWEB.Grupo.gru_nome;
                         //Preenche os dados do sistema
                         SYS_Sistema sistema = new SYS_Sistema
                         {
                             sis_id = session.__UsuarioWEB.Grupo.sis_id
                         };
                         SYS_SistemaBO.GetEntity(sistema);
                         entity.sis_id   = sistema.sis_id;
                         entity.sis_nome = sistema.sis_nome;
                         //Preenche os dados do módulo
                         if (HttpContext.Current.Session[SYS_Modulo.SessionName] != null)
                         {
                             SYS_Modulo modulo = (SYS_Modulo)HttpContext.Current.Session[SYS_Modulo.SessionName];
                             entity.mod_id   = modulo.mod_id;
                             entity.mod_nome = modulo.mod_nome;
                         }
                         else
                         {
                             entity.mod_id   = 0;
                             entity.mod_nome = string.Empty;
                         }
                         //Preenche as entidades e unidades administrativa do grupo
                         if (session.__UsuarioWEB.GrupoUA != null)
                         {
                             //Formata a entidade no padrão JSON
                             JavaScriptSerializer oSerializer = new JavaScriptSerializer();
                             entity.log_grupoUA = oSerializer.Serialize(session.__UsuarioWEB.GrupoUA);
                         }
                     }
                 }
             }
         }
         if (!LOG_SistemaBO.Save(entity))
         {
             throw new Exception("Não foi possível salvar o log do sistema.");
         }
         if (HttpContext.Current != null)
         {
             HttpContext.Current.Session[LOG_Sistema.SessionName] = null;
         }
         return(entity.log_id);
     }
     catch (Exception)
     {
         throw;
     }
 }