93 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace IronIntel.Contractor
{
public class Helper
{
public static readonly DateTime DBMinDateTime = new DateTime(1900, 01, 01);
public static bool IsTrue(string s)
{
const string YES = "Yes";
const string TRUE = "True";
const string ONE = "1";
return (string.Compare(s, YES, true) == 0) || (string.Compare(s, TRUE, true) == 0) || (string.Compare(s, ONE) == 0);
}
public static bool Contains(string text, string val)
{
if (!string.IsNullOrWhiteSpace(text))
{
return text.IndexOf(val, StringComparison.OrdinalIgnoreCase) >= 0;
}
else
{
return false;
}
}
public static void CloneProperty(object objDes, object objSrc)
{
if (objDes == null || objSrc == null)
return;
PropertyInfo[] pisDes = objDes.GetType().GetProperties();
Type tSrc = objSrc.GetType();
foreach (PropertyInfo piDes in pisDes)
{
if (!piDes.CanWrite)
continue;
PropertyInfo piSrc = tSrc.GetProperty(piDes.Name, piDes.PropertyType);
if (piSrc == null || !piSrc.CanRead)
continue;
try
{
piDes.SetValue(objDes, piSrc.GetValue(objSrc, null), null);
}
catch (Exception e)
{
e.ToString();
}
}
}
public static object DateValueToNull(DateTime date)
{
if (date <= DBMinDateTime)
return null;
else
return date;
}
public static object DateValueToNullOrBigHour(DateTime date)
{
if (date <= DBMinDateTime)
return null;
else
return date.AddDays(1).AddSeconds(-1);
}
public static object NumberValueToNull(int value)
{
if (value < 0)
return null;
else
return value;
}
public static object NumberValueToNull(double value)
{
if (value < 0)
return null;
else
return value;
}
}
}