66 lines
1.9 KiB
C#
66 lines
1.9 KiB
C#
using System;
|
|
|
|
namespace Net.CrossCotting
|
|
{
|
|
public class Utils
|
|
{
|
|
public static DateTime DateTimeEmpty()
|
|
{
|
|
return new DateTime(1, 1, 1, 0, 0, 0);
|
|
}
|
|
|
|
public static DateTime GetFechaHoraInicioActual(DateTime? fecha)
|
|
{
|
|
DateTime? data;
|
|
|
|
data = fecha;
|
|
|
|
if (fecha == null || fecha.Equals(DateTimeEmpty()))
|
|
{
|
|
data = new DateTime(DateTime.Now.Year, 1, DateTime.Now.Day, 0, 0, 0);
|
|
}
|
|
else
|
|
{
|
|
data = new DateTime(((DateTime)fecha).Year, ((DateTime)fecha).Month, ((DateTime)fecha).Day, 0, 0, 0);
|
|
}
|
|
|
|
return (DateTime)data;
|
|
}
|
|
|
|
public static DateTime GetFechaHoraFinActual(DateTime? fecha)
|
|
{
|
|
DateTime? data;
|
|
|
|
data = fecha;
|
|
|
|
if (fecha == null || fecha.Equals(DateTimeEmpty()))
|
|
{
|
|
data = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59);
|
|
}
|
|
else
|
|
{
|
|
data = new DateTime(((DateTime)fecha).Year, ((DateTime)fecha).Month, ((DateTime)fecha).Day, 23, 59, 59);
|
|
}
|
|
|
|
return (DateTime)data;
|
|
}
|
|
|
|
public static string GenerarCodigoAleatorio()
|
|
{
|
|
Random obj = new Random();
|
|
string sCadena = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
|
|
int longitud = sCadena.Length;
|
|
char cletra;
|
|
int nlongitud = 30;
|
|
string sNuevacadena = string.Empty;
|
|
|
|
for (int i = 0; i < nlongitud; i++)
|
|
{
|
|
cletra = sCadena[obj.Next(nlongitud)];
|
|
sNuevacadena += cletra.ToString();
|
|
}
|
|
return sNuevacadena;
|
|
}
|
|
}
|
|
}
|