>using System; >using OakLeaf.MM.Main; > >namespace Apps4u.WinApp.Business.Search >{ > /// <summary> > /// The SearchCritieria Class will contain functions to manipulate and validate the search criteria > /// </summary> > public class SearchCriteria > { > > protected bool SearchValidate_Completed_ErrorFree = false; > > public SearchCriteria() > { > } > > /// <summary> > /// This method will validate the string to ensure it has no invalid characters in it. > /// </summary> > /// <param name="SearchArray">receives an Object Array from the GUI</param> > /// <returns>Returns True or False</returns> > public bool SearchValidateStrings(params object[] SearchArray) > { > > foreach (object ValidDataArray in SearchArray) > { > // TODO : Add a regular expression search here to validate the array elements > // if (string is not valid) > // {this.SearchValidate_Completed_ErrorFree = false; break;} > } > return this.SearchValidate_Completed_ErrorFree; > } > > /// <summary> > /// This method will build a string where clause > /// </summary> > /// <param name="SearchArray"></param> > /// <returns></returns> > public string BuildSearchWhereClause(params object[] SearchArray) > { > if (!this.SearchValidate_Completed_ErrorFree) return ""; > > string sWhereClause, sFieldName1, sFieldName2 = ""; > bool lIsNotEmpty_Object = false; > bool lOnFirstItem = true; > > foreach (object BuildStringArray in SearchArray) > { > // the first object is the field name which should always have a value > // the second object is suppose to be the value from the form. > // so we will test if the second object has a value > if (lOnFirstItem) > { > lOnFirstItem = false; > sFieldName1 = BuildStringArray.ToString(); > } > else > { > lOnFirstItem = true; > sFieldName2 = BuildStringArray.ToString() ; > } > > // test to see if we have a value > if (!mmString.Empty(sFieldName2)) lIsNotEmpty_Object = true; > > if (lIsNotEmpty_Object) > { > if (!mmString.Empty(sWhereClause)) sWhereClause += " AND "; >********************> > if (BuildStringArray.GetType() == System.Int16 || BuildStringArray.GetType() == System.Int32 || BuildStringArray.GetType() == System.Int64 ) > { sWhereClause += sFieldName1 + " = " + sFieldName2 ;} > else if (BuildStringArray.GetType() == System.DateTime) > { sWhereClause += sFieldName1 + " = {" + sFieldName2 + "}";} > else if (BuildStringArray.GetType() == System.String) > { sWhereClause += sFieldName1 + " = '" + sFieldName2 + "'";} > > } > } > return ""; > } > > } >} >