/* ____________________________________________________________ M Y V A L I D A T O R C L A S S Created 4/21/07 Ron Kessler ____________________________________________________________ * This class is used to validate textbox entries to be sure they are not empty * * Methods: * IsNotEmpty is a static member which accepts a textbox as an argument and * checks to see that the text property of that object is zero-length */ using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; //be sure to add this so it can recognize controls namespace Access_DB_Part1_Step_3 { public class myValidator { const string MYMSG = "Validation Error"; //---local member to hold ControlText property value private static string m_ControlText; /// /// Public Static property which passes the name of the textbox being evaluated /// /// public static string ControlText { get { return m_ControlText; } set { m_ControlText = value; } } /*---by making this method static, you don't have to instantiate the class to use it I pass in the textbox to be evaluated and test its length. The property called ControlText just lets me show the user which control needs attention. This can also be passed using the TAG property of the control. */ public static bool IsLegal(TextBox textbox) { if (textbox.Text.Trim().Length == 0) { MessageBox.Show(m_ControlText + " is required.", MYMSG, MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } else return true; } } }