From c48651e2a37e8af5f1eafff10119eedefa4f96e7 Mon Sep 17 00:00:00 2001 From: ​ Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: customer maintenance --- .../CustomerMaintenance/Validator.cs | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 customer_maintenance/CustomerMaintenance/Validator.cs (limited to 'customer_maintenance/CustomerMaintenance/Validator.cs') diff --git a/customer_maintenance/CustomerMaintenance/Validator.cs b/customer_maintenance/CustomerMaintenance/Validator.cs new file mode 100644 index 0000000..ddc01b6 --- /dev/null +++ b/customer_maintenance/CustomerMaintenance/Validator.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CustomerMaintenance +{ + public static class Validator + { + private static string lineEnd = "\n"; + + public static string LineEnd + { + get + { + return lineEnd; + } + set + { + lineEnd = value; + } + } + + public static string IsPresent(string value, string name) + { + string msg = ""; + if (value == "") + { + msg += name + " is a required field." + LineEnd; + } + return msg; + } + + public static string IsDecimal(string value, string name) + { + string msg = ""; + if (!Decimal.TryParse(value, out _)) + { + msg += name + " must be a valid decimal value." + LineEnd; + } + return msg; + } + + public static string IsInt32(string value, string name) + { + string msg = ""; + if (!Int32.TryParse(value, out _)) + { + msg += name + " must be a valid integer value." + LineEnd; + } + return msg; + } + + public static string IsWithinRange(string value, string name, decimal min, + decimal max) + { + string msg = ""; + if (Decimal.TryParse(value, out decimal number)) + { + if (number < min || number > max) + { + msg += name + " must be between " + min + " and " + max + "." + LineEnd; + } + } + return msg; + } + + public static string IsValidEmail(string value, string name) + { + string msg = ""; + if (value.IndexOf("@") == -1 || + value.IndexOf(".") == -1) + { + msg += name + " must be a valid email address." + LineEnd; + } + return msg; + } + } +} -- cgit 1.4.1