CNSA-216-FP/FWA_MAIN/Val.cs
EggMan20339 fe80a41d5c idk
2024-03-28 19:23:49 -04:00

86 lines
1.8 KiB
C#

using System;
using System.Web.UI.WebControls;
namespace FWA_MAIN
{
public class Val
{
public static string varchar(TextBox box, int length)
{
if (box.Text.Length <= length)
{
return box.Text.Trim();
}
else
{
return "";
}
}
public static int IntType(TextBox box)
{
try
{
return int.Parse(box.Text.Trim());
}
catch (Exception e)
{
return 0;
}
}
public static short SmallIntType(TextBox box)
{
try
{
if (box.Text.Length > 0)
{
if (double.Parse(box.Text) < 65535 && double.Parse(box.Text) >= 0)
{
return short.Parse(box.Text.Trim());
}
else
{
return 0;
}
}
else
{
return 0;
}
}
catch (Exception e)
{
return 0;
}
}
public static DateTime Date(TextBox box)
{
try
{
DateTime date = DateTime.Parse(box.Text.Trim());
if (date < new DateTime(1753,1,1) || date > new DateTime(9999,12,31))
{
throw new Exception();
}
return date;
}
catch (Exception e)
{
return new DateTime(3000, 1, 1);
}
}
}
}