jueves 24 de abril de 2008

Cancelar el uso del botón back



Esto puede colocarse en el evento onLoad del elemento BODY dentro de un documento HTML

document.location.href.replace(this.href)

Método de conexión a SAP desde .net

public int Ejecutar()
{
Destination r3 = _fnDefineConexion();
// Se cargan los parámetros de entrada en una tabla.
Z_PARAM2Table _sapTablaParam = null;
_sapTablaParam = new Z_PARAM2Table ();
Z_PARAM2 Entrada = null;
Entrada = new Z_PARAM ();
Entrada.Valor1 = Valor1;
Entrada.Valor2 = Valor2;
Entrada.Valor3 = Valor3;
_sapTablaParam.Add(Entrada);
Entrada = null;
ReportesSAP rfc = null;
// Se ejecuta el RFC
rfc = new ReportesSAP(r3.ConnectionString);
rfc.Z_Historia(ref _sapTabla,
ref _sapTablaMsgError,
ref _sapTablaParam);
rfc.Connection.Close();
rfc.Dispose();
rfc = null;
r3.Dispose();
r3 = null;
return 0;
}
----------------------
//Función para la definición del string de conexión.
private Destination _fnDefineConexion()
{
Destination r3 = new Destination();
if (ConfigurationSettings.AppSettings["UserName"].Length > 0 )
{
r3.Username = ConfigurationSettings.AppSettings["UserName"];
}
if (ConfigurationSettings.AppSettings["Password"].Length > 0 )
{
r3.Password = ConfigurationSettings.AppSettings["Password"];
}
if (ConfigurationSettings.AppSettings["Client"].Length > 0 )
{
r3.Client =Convert.ToInt16(ConfigurationSettings.AppSettings["Client"].ToString());
}
if (ConfigurationSettings.AppSettings["SystemNumber"].Length > 0 )
{
r3.SystemNumber =Convert.ToInt16(ConfigurationSettings.AppSettings["SystemNumber"].ToString());
}
if (ConfigurationSettings.AppSettings["LogonGroup"].Length > 0 )
{
r3.LogonGroup =ConfigurationSettings.AppSettings["LogonGroup"];
}
if (ConfigurationSettings.AppSettings["SAPSystemName"].Length > 0 )
{
r3.SAPSystemName =ConfigurationSettings.AppSettings["SAPSystemName"];
}
if (ConfigurationSettings.AppSettings["AppServerHost"].Length > 0 )
{
r3.AppServerHost =ConfigurationSettings.AppSettings["AppServerHost"];
}
return r3;
}
--------------------------

Variables de conexión en el web.config

<add key="Username" value=""/>
<add key="Password" value=""/>
<add key="Client" value="100"/> <!-- Ambiente!-->
<add key="SystemNumber" value="00"/> <!-- Número sistema -->
<add key="AppServerHost" value="10.10.10.1"/> <!-- IP Server -->
<add key="MsgServerHost" value=""/>
<add key="LogonGroup" value=""/>
<add key="SAPSystemName" value=""/>

miércoles 23 de abril de 2008

Como validar la existencia de un proceso activo en el sistema.

Ejemplo de como encontrar si existe un proceso activo en la máquina.
Es necesario agregar el namespace para esto:

using System.Diagnostics ;

Este es el código que lo realiza:

Process[] _proceso = Process.GetProcessesByName("firefox");
if (_proceso.Length != 0 )
{
MessageBox.Show("Está activo");
}
else
{
MessageBox.Show("No está activo");
}


Float a string con formato de tipo moneda (JavaScript)

Función para formatear un número float a un string con formato de tipo moneda en JavaScript.

function formatNumber(num,prefix)
{
num = Math.round(parseFloat(num)*Math.pow(10,2))/Math.pow(10,2)
prefix = prefix || '';
num += '';
var splitStr = num.split('.');
var splitLeft = splitStr[0];
var splitRight = splitStr.length > 1 ? '.' + splitStr[1] : '.00';
splitRight = splitRight + '00';
splitRight = splitRight.substr(0,3);
var regx = /(\d+)(\d{3})/;
while (regx.test(splitLeft)) {
splitLeft = splitLeft.replace(regx, '$1' + ',' + '$2');
}
return prefix + splitLeft + splitRight;
}

martes 22 de abril de 2008

ZedGraph. Libreria para generar gráficas.

Existe, entre otras tantas, una librería de clases que puede ser de bastante ayuda al querer representar gráficas. Su nombre es ZedGraph y es una libreria de clases con su código fuente para poder crear gráficas en proyectos .net

Mas información aquí y acá

Enviando correo desde asp.net usando gmail

En este link me encontré con este código, que seguramente pronto me será muy útil


public static bool SendEmail(string siteEmail ,string requesterAddress, string link)
{
try
{
int port = 587;
string userName = “tahir.rauf1@gmail.com”;
string password = “Allahakbar”;

MailMessage mailMsg = new MailMessage();
SmtpClient mailObject = new SmtpClient(”smtp.gmail.com”,port);

mailMsg.From = new MailAddress(siteEmail, “FLVZ”);
mailMsg.To.Add(new MailAddress(requesterAddress));
mailMsg.IsBodyHtml = false;
mailMsg.Body = link;
mailMsg.Subject = “This is the Subject”;

mailObject.Credentials = new System.Net.NetworkCredential(userName, password);
mailObject.Send(mailMsg);
return true;
}
catch
{
return false;
}
}

Búsqueda