CNSA-216-FP/FWA_MAIN/Val.cs

150 lines
3.1 KiB
C#

using System;
using System.Data;
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 string PatID(TextBox box)
{
string word = box.Text.Trim();
while (word.Length < 8)
{
word = "0" + word;
}
DataSet ds = PharmacyDataTier.PatientInfoSearch(word);
if (ds.Tables[0].Rows.Count > 0)
{
return word;
}
else
{
return "00000000";
}
}
public static string MedID(TextBox box)
{
string word = box.Text.Trim();
while (word.Length < 7)
{
word = "0" + word;
}
DataSet ds = PharmacyDataTier.MedicationInfoSearch(word);
if (ds.Tables[0].Rows.Count > 0)
{
return word;
}
else
{
return "0000000";
}
}
public static string PhyID(TextBox box)
{
string word = box.Text.Trim();
while (word.Length < 8)
{
word = "0" + word;
}
DataSet ds = PharmacyDataTier.PhysicianInfoSearch(word);
if (ds.Tables[0].Rows.Count > 0)
{
return word;
}
else
{
return "00000000";
}
}
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);
}
}
}
}