示例#1
0
        public static DateLimits GetDateFilter(string dateFilter, string fromDate, string toDate)
        {
            var fromToDate = new DateLimits();

            if (CheckEmpty.Numeric(dateFilter) != (long)Enumerations.DateLimit.Open)
            {
                fromToDate = CalculateDate((Enumerations.DateLimit)Convert.ToInt16(dateFilter), DateTime.Now.Date);
                //if (IsDate(fromToDate.ToDate.ToString(CultureInfo.InvariantCulture))) fromToDate.ToDate = fromToDate.ToDate.AddDays(1);
                return(fromToDate);
            }

            if (CheckEmpty.Numeric(dateFilter) == (long)Enumerations.DateLimit.Open)
            {
                var from = ReadDateFromDisplay(fromDate);
                var to   = ReadDateFromDisplay(toDate);

                fromToDate.FromDate = new DateTime(from.Year, from.Month, from.Day);
                fromToDate.ToDate   = new DateTime(to.Year, to.Month, to.Day);
                if (IsDate(fromToDate.ToDate.ToString(CultureInfo.InvariantCulture)))
                {
                    fromToDate.ToDate = fromToDate.ToDate.GetMaxTimeOfDate();
                }
                return(fromToDate);
            }

            fromToDate.FromDate = DateTime.MinValue;
            fromToDate.ToDate   = DateTime.MaxValue;
            return(fromToDate);
        }
示例#2
0
        public static string FormatDateForDisplay(object val, bool withTime = false)
        {
            var tmpVal = CheckEmpty.Date(val);

            if (tmpVal == DateTime.MinValue)
            {
                return("N/A");
            }

            var toRet = tmpVal.ToString(withTime ? "dd-MM-yyyy hh:mm tt" : "dd-MM-yyyy");

            return(toRet);
        }
        //public static string Entry(long entryPosition, string list, string delimiter = ",")
        //{
        //    string functionReturnValue;
        //    var returnEntry = "";

        //    if (entryPosition == 0) return "";

        //    var numEntries = CountEntries(list, delimiter);
        //    if (numEntries == 1)
        //    {
        //        functionReturnValue = list.Replace(delimiter, "");
        //        if (functionReturnValue == null)
        //            functionReturnValue = "";
        //        return functionReturnValue;
        //    }
        //    long lengthList = list.Length;
        //    numEntries = 1;
        //    long counter = 0;
        //    for (counter = 1; counter <= lengthList; counter++)
        //    {
        //        returnEntry = returnEntry + Strings.Mid(list, counter, 1);
        //        if (Strings.Mid(list, counter, 1) == delimiter | counter == lengthList)
        //        {
        //            if (counter != lengthList)
        //            {
        //                numEntries = numEntries + 1;
        //            }
        //            else
        //            {
        //                if (numEntries + 1 == entryPosition + 1)
        //                {
        //                    functionReturnValue = returnEntry.Replace(delimiter, "");
        //                    if ((functionReturnValue == null))
        //                        functionReturnValue = "";
        //                    return functionReturnValue;
        //                }

        //            }
        //            if (numEntries == entryPosition + 1)
        //            {
        //                functionReturnValue = returnEntry.Replace(delimiter, "");
        //                if ((functionReturnValue == null))
        //                    functionReturnValue = "";
        //                return functionReturnValue;
        //            }
        //            else
        //            {
        //                returnEntry = "";
        //            }
        //        }
        //    }
        //    return "";

        //    return functionReturnValue;
        //}

        //public static string SetEntry(string value, string listValues, string defaultValue, string delimiter)
        //{
        //    int li1;
        //    var lcEq = "=";
        //    var lcComa = ",";

        //    if ((delimiter.Trim().Length == 2))
        //    {
        //        lcEq = delimiter.Substring(0, 1);
        //        lcComa = delimiter.Substring(1, 1);
        //    }

        //    var li2 = CountEntries(listValues, lcComa);
        //    var llFound = false;

        //    for (li1 = 1; li1 <= li2; li1++)
        //    {
        //        var lcEntry = Entry(li1, listValues, lcComa).Trim();
        //        if ((lcEntry.StartsWith(value + " " + lcEq)) | (lcEntry.StartsWith(value + lcEq)))
        //        {
        //            SpecialSetEntry(2, ref lcEntry, defaultValue, lcEq);
        //            SpecialSetEntry(li1, ref listValues, lcEntry, lcComa);
        //            llFound = true;
        //            break; // TODO: might not be correct. Was : Exit For
        //        }
        //    }

        //    if (!llFound)
        //    { listValues = value + lcEq + defaultValue + lcComa + listValues; }

        //    return listValues;

        //}

        //public static void SpecialSetEntry(long tokenNumber, ref string str, object value, string delimiter = ",")
        //{
        //    int i;
        //    //Was empty before instead of nothing
        //    if (tokenNumber <= 0 || str.Length == 0) return;

        //    string[] laStr = str.Split(delimiter, -1, Constants.vbTextCompare);
        //    if (laStr.Length + 1 < tokenNumber) return;

        //    laStr[tokenNumber - 1] = value;
        //    var lcWork = "";
        //    for (i = 0; i <= laStr.Length; i++)
        //    { lcWork = lcWork + delimiter + laStr[i]; }

        //    lcWork = Strings.Mid(lcWork, delimiter.Length + 1);
        //    if (lcWork.Length > 0)
        //    { str = lcWork; }
        //}

        public static string Quotify(string list)
        {
            if (CheckEmpty.String(list) == "")
            {
                return("''");
            }
            var listArray = new List <string>(list.Split(','));

            for (var i = 0; i <= listArray.Count - 1; i++)
            {
                listArray[i] = "'" + listArray[i] + "'";
            }
            return(string.Join(",", listArray));
        }
示例#4
0
        private static Expression <Func <Log, bool> > CreateFilter(string search)
        {
            var serializer = new JavaScriptSerializer();
            var dict       = serializer.Deserialize <Dictionary <string, object> >(search);

            var predicate = PredicateBuilder.True <Log>();

            if (CheckEmpty.String(ref dict, "Module") != "")
            {
                predicate = predicate.And(p => p.Module.Id == dict["Module"].ToString());
            }

            if (CheckEmpty.String(ref dict, "Action") != "")
            {
                predicate = predicate.And(p => p.Action.Contains(dict["Action"].ToString()));
            }

            if (CheckEmpty.String(ref dict, "Text") != "")
            {
                predicate = predicate.And(p => p.Text.Contains(dict["Text"].ToString()));
            }

            if (CheckEmpty.String(ref dict, "UserId") != "")
            {
                predicate = predicate.And(p => p.UserId == Convert.ToInt64(dict["UserId"]));
            }

            if (CheckEmpty.String(ref dict, "BranchId") != "")
            {
                predicate = predicate.And(p => p.BranchId == Convert.ToInt64(dict["BranchId"]));
            }

            if (CheckEmpty.String(ref dict, "DateFilter") != "")
            {
                var dtLimits = DateUtilities.GetDateFilter(dict["DateFilter"].ToString(), dict["FromDate"].ToString(), dict["ToDate"].ToString());
                predicate = predicate.And(p => p.EntryDate >= dtLimits.FromDate);
                predicate = predicate.And(p => p.EntryDate <= dtLimits.ToDate);
            }

            return(predicate);
        }