TFS_ANTIGUO/AYA.FROPI/Intranet/App_Code/General.cs
Administrador 50700fd78b Solución FROPI
git-tfs-id: [http://192.168.1.10:8080/tfs/AyA]$/SINORT;C491
2019-05-27 14:46:35 +00:00

274 lines
No EOL
9.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using AyABL.SEG;
using AyAEM.ExceptionManagement.Exceptions;
using System.Diagnostics;
/// <summary>
/// Descripción breve de General
/// </summary>
public partial class General : System.Web.UI.Page
{
#region Variables
BitacoraBL objBitacora;
RolMenuComandoBL objRolMenuComandoBL;
MenuBL objMenuBL;
#endregion
#region Metodos
/// <summary>
/// Carga el rol de acceso de la pagina
/// </summary>
/// <returns></returns>
public DataSet getComandos()
{
DataSet dsComandosMenu = new DataSet();
string strURL = string.Empty;
objMenuBL = new MenuBL();
objRolMenuComandoBL = new RolMenuComandoBL();
ViewState["PUEDEMODIFICAR"] = false;
if (Session["PKROL"] != null)
{
//strURL = Request.Url.AbsoluteUri.Replace("http://" + Request.Url.Authority + Request.ApplicationPath.ToString(), "~/").ToString().Replace("//", "/");
strURL = "~" + Request.Url.AbsolutePath;
//objMenuBL.objMenuEL.URL = strURL; //.Substring(0, strURL.Length - 54) + ".aspx";
dsComandosMenu = objRolMenuComandoBL.cargarComandosxRol(Convert.ToInt32(Session["PKROL"].ToString()), strURL);
if (dsComandosMenu.Tables[0].Rows.Count != 0 || dsComandosMenu.Tables[0] != null)
{
ViewState["PkMenu"] = dsComandosMenu.Tables[0].Rows[0]["PKMENU"];
}
}
return dsComandosMenu;
}
/// <summary>
/// Registrar el evento en bitacora
/// </summary>
/// <param name="intComando"></param>
/// <param name="intOpcionMenu"></param>
/// <param name="strDetalle"></param>
public void GuardarEventoBitacora(string p_strLogin, string p_strAccion,string p_strRegistro, string p_strNombrePagina)
{
objBitacora = new BitacoraBL();
objBitacora.objBitacoraEL.Login = p_strLogin;
objBitacora.objBitacoraEL.Fecha = DateTime.Now;
objBitacora.objBitacoraEL.Accion = p_strAccion;
objBitacora.objBitacoraEL.Registro = p_strRegistro;
objBitacora.objBitacoraEL.Pagina = p_strNombrePagina;
objBitacora.insertarBitacora();
}
/// <summary>
/// Muestra la cantidad de datos que tiene el gridview asi como cuales son los datos que estoy visualizando en este. Ej: 11 al 20 de 20 datos
/// </summary>
/// <param name="p_dsDatos"></param>
/// <param name="p_grvGridView"></param>
/// <param name="p_Label"></param>
public static void detalleGridView(DataSet p_dsDatos, GridView p_grvGridView, object p_objLabel)
{
try
{
p_grvGridView.ShowHeader = true;
p_grvGridView.DataSource = p_dsDatos;
p_grvGridView.DataBind();
string mensaje = "0 Registros encontrados";
if (p_dsDatos != null)
{
if (p_dsDatos.Tables[0].Rows.Count > 0)
{
mensaje = "Viendo datos del " + ((p_grvGridView.PageIndex * p_grvGridView.PageSize) + 1) + " al " + (p_grvGridView.Rows.Count +
(p_grvGridView.PageIndex * p_grvGridView.PageSize)) + " de " + p_dsDatos.Tables[0].Rows.Count;
}
}
if (p_objLabel != null)
{
Label label = (Label)p_objLabel;
label.Text = mensaje;
}
}
catch (Exception ex)
{
throw ex;
}
}
public static void detalleGRVDatos(DataSet p_dsDatos, GridView p_grvGridView)
{
try
{
p_grvGridView.ShowHeader = true;
p_grvGridView.DataSource = p_dsDatos;
p_grvGridView.DataBind();
}
catch (Exception ex)
{
throw ex;
}
}
public static void ddlListaProyectos(DataSet p_dsDatos, DropDownList p_ddlListado)
{
try
{
p_ddlListado.DataSource = p_dsDatos;
p_ddlListado.DataTextField = p_dsDatos.Tables[0].Columns["NOMBREPROYECTO2"].ColumnName;
p_ddlListado.DataValueField = p_dsDatos.Tables[0].Columns["PKPROYECTO"].ColumnName;
p_ddlListado.DataBind();
p_ddlListado.Items.Insert(0, new ListItem("Seleccione un Proyecto", "-1"));
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// muestra un mensaje de error en la ventana y en caso de que se presente un error
/// guardar el mismo en el archivo de ErrorLog.txt
/// </summary>
/// <param name="p_strMensaje"></param>
/// <param name="ex"></param>
public void MensajeError(string p_strMensaje,Exception ex)
{
try
{
if (ex != null)
{
AyAException.Publish(ex, p_strMensaje);
}
//ClientScript.RegisterStartupScript(this.GetType(), "alert", "MostrarMensaje();", true);
System.Web.UI.ScriptManager.RegisterStartupScript(
this,
typeof(General),
ClientID,
"toastr.error('" + p_strMensaje + "<br /><br /><button type=button class=btn clear>Aceptar</button>', 'Error', toastr.options ={timeOut: 0, extendedTimeOut: 0,closeButton: false})",
true);
}
catch (Exception exm)
{
throw exm;
}
}
/// <summary>
/// muestra un mensaje de informacion en la ventana y en caso de que se desee mostrar un mensaje del sistema
/// guardar el mismo en el archivo de ErrorLog.txt
/// </summary>
/// <param name="p_strMensaje"></param>
public void MensajeInformativo(string p_strMensaje)
{
try
{
System.Web.UI.ScriptManager.RegisterStartupScript(
this,
typeof(General),
ClientID,
"toastr.success('" + p_strMensaje + "<br /><br /><button type=button class=btn clear>Aceptar</button>', 'Información',toastr.options ={timeOut: 0, extendedTimeOut: 0,closeButton: true})",
true);
}
catch (Exception ex)
{
throw ex;
}
}
public void MensajeAdvertencia(string p_strMensaje)
{
try
{
System.Web.UI.ScriptManager.RegisterStartupScript(
this,
typeof(General),
ClientID,
"toastr.warning('" + p_strMensaje + "<br /><br /><button type=button class=btn clear>Aceptar</button>', 'Información',toastr.options ={timeOut: 0, extendedTimeOut: 0,closeButton: true})",
true);
}
catch (Exception ex)
{
throw ex;
}
}
public static void ReportarError(Exception ex, string p_strUsuario)
{
System.Security.Principal.WindowsIdentity Usuario = System.Security.Principal.WindowsIdentity.GetCurrent();
string strFecha = string.Empty, strMaquina = string.Empty, strIP = string.Empty, strUsuario = string.Empty,
strError = string.Empty, strPagina = string.Empty, strLinea = string.Empty, strLineaFinal = string.Empty;
//Dedinicion de las variables
strFecha = DateTime.Now.ToLongDateString() + " a las " + DateTime.Now.ToString("HH:mm:ss");
//para capturar la ip
var host = Dns.GetHostEntry(Dns.GetHostName());
foreach (var ip in host.AddressList)
{
if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
strIP = ip.ToString();
}
}
strMaquina = System.Net.Dns.GetHostEntry(strIP).HostName;
strUsuario = HttpContext.Current.User.Identity.Name;
strPagina = HttpContext.Current.Request.CurrentExecutionFilePath;
strError = ex.Message;
strLineaFinal = "--------------------------------------------- Fin Error ------------------------------------------------------------------";
//fijamos donde vamos a crear el archivo y se arma el despliegue del error.
//using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"R:\Documentos\Proyectos\FOPI\App\FOPI\Errorlog.txt", true))
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"D:\Aplicaciones\FOPI(6010)\Raiz\Errorlog.txt", true))
{
file.WriteLine(strLinea);
file.WriteLine(strLinea);
file.WriteLine("Error");
file.WriteLine(strLinea);
file.WriteLine("Fecha: " + strFecha);
file.WriteLine("Equipo: " + strMaquina.Replace(".intranet.aya.go.cr", ""));
file.WriteLine("Usuario: " + p_strUsuario);
file.WriteLine("Pagina: " + strPagina.Substring(15, strPagina.Length - 15));
file.WriteLine("IP: " + strIP);
file.WriteLine("Error: " + strError);
file.WriteLine(strLinea);
file.WriteLine(strLinea);
file.WriteLine(strLineaFinal);
}
}
#endregion
}