/// <summary>
        /// Builds a where clause for a specified column/field of a specified type with data as
        /// a condition. Returns "" if data is empty.
        /// </summary>
        /// <param name="colName"></param>
        /// <param name="data"></param>
        /// <param name="dt"></param>
        /// <returns></returns>
        private string BuildWhereSingle(string colName, string data, DataTypes dt, DataObject.SearchTypes st)
        {
            if (data == "")
            {
                return("");
            }
            else
            {
                string safeData = data.Replace("'", "''");
                string toReturn = " AND ";

                if (dt == DataTypes.Text)
                {
                    if (st == DataObject.SearchTypes.Contains)
                    {
                        toReturn += colName + " LIKE '%" + safeData + "%'";
                    }
                    else if (st == DataObject.SearchTypes.BeginsWith)
                    {
                        toReturn += colName + " LIKE '" + safeData + "%'";
                    }
                    else
                    {
                        toReturn += colName + " = '" + safeData + "'";
                    }
                }
                else if (dt == DataTypes.Numeric)
                {
                    toReturn += colName + " = " + safeData;
                }
                else if (dt == DataTypes.Date)
                {
                    // Have to do special processing for the date
                    DateTime compareDate = System.Convert.ToDateTime(safeData);
                    string   dateWhere;
                    if (st == DataObject.SearchTypes.Before)
                    {
                        dateWhere = "'" + CommonFunctions.ToMySQLDateTime(compareDate) + "' > {colname}";
                    }
                    else if (st == DataObject.SearchTypes.After)
                    {
                        dateWhere = "'" + CommonFunctions.ToMySQLDateTime(compareDate) + "' < {colname}";
                    }
                    else
                    {
                        dateWhere = "YEAR({colname}) = '" + compareDate.Year + "' AND MONTH({colname}) = '" +
                                    compareDate.Month + "' AND DAY({colname}) = '" + compareDate.Day + "'";
                    }

                    dateWhere = dateWhere.Replace("{colname}", colName);
                    toReturn += dateWhere;
                }


                return(toReturn);
            }
        }
Exemple #2
0
 /// <summary>
 /// Builds a where clause for a specified column/field of a specified type with data as
 /// a condition. Returns "" if data is empty.
 /// </summary>
 private string BuildWhereSingle(string colName, string data, DataTypes dt, DataObject.SearchTypes st, bool enabled)
 {
     if (enabled)
     {
         return(BuildWhereSingle(colName, data, dt, st));
     }
     else
     {
         return("");
     }
 }