Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="selectedValue"></param>
        /// <returns></returns>
        public static int?GetSelectedId(string selectedValue)
        {
            int?rtnVal = TextUtility.TextToNullableInt(selectedValue);

            // If it is the empty row added from the collection, the return value should be null
            if (rtnVal == 0)
            {
                rtnVal = null;
            }

            return(rtnVal);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="selectedValue"></param>
        /// <returns></returns>
        public static string GetSelectedValue(string selectedValue)
        {
            string rtnVal = TextUtility.PruneText(selectedValue);

            // If it is the empty row added from the collection, the return value should be null
            if (String.IsNullOrEmpty(rtnVal))
            {
                rtnVal = null;
            }

            return(rtnVal);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Attempts to format numbers in string as a zip code - will not cause error and
        /// will still process invalid zips.
        /// </summary>
        /// <param name="ZipCode"></param>
        /// <returns>Null if no digits, or attempted formatting of the digits.</returns>
        static public string FormatZip(string ZipCode)
        {
            string zipCodeNumbers = TextUtility.NumbersOnly(ZipCode);

            if (zipCodeNumbers == null)
            {
                return(null);
            }
            else if (zipCodeNumbers.Length == 5)
            {
                return(zipCodeNumbers);
            }
            else if (zipCodeNumbers.Length > 5) // May be invalid but don't care.
            {
                return(zipCodeNumbers.Substring(0, 5) + "-" + zipCodeNumbers.Substring(5));
            }
            else// Invalid zip code with less than 5 digits.
            {
                return(zipCodeNumbers);
            }
        }
Ejemplo n.º 4
0
        public static DateTime?TextTimeToNullableDate(string strTime, bool roundUp = false)
        {
            DateTime?rtnVal = null;

            strTime = TextUtility.PruneText(strTime);

            if (!String.IsNullOrEmpty(strTime))
            {
                string time      = null;
                string strNumber = null;
                string strText   = null;

                TimeParser(strTime, out strNumber, out strText);

                // Prepend hours if missing a digit
                if (!String.IsNullOrEmpty(strNumber) && (strNumber.Length == 1 || strNumber.Length == 3))
                {
                    strNumber = "0" + strNumber;
                }

                // Append the minutes if missing
                if (!String.IsNullOrEmpty(strNumber) && strNumber.Length < 4)
                {
                    strNumber = strNumber + "00";
                }

                if (!String.IsNullOrEmpty(strNumber))
                {
                    time = strNumber.Substring(0, 2) + ":" + strNumber.Substring(2, 2);
                    int hour = Int32.Parse(strNumber.Substring(0, 2));

                    // Implys 24 format
                    if (hour > 12)
                    {
                        time = String.Format("{0:##}:{1}pm", hour - 12, strNumber.Substring(2, 2));
                    }
                    else
                    {
                        if (!String.IsNullOrEmpty(strText))
                        {
                            if (strText[0] == 'p' || strText[0] == 'P')
                            {
                                time += "pm";
                            }
                            else
                            {
                                time += "am";
                            }
                        }
                        else
                        {
                            time += "am";
                        }
                    }
                }

                DateTime date;

                if (DateTime.TryParse(time, out date))
                {
                    if (roundUp)
                    {
                        rtnVal = RoundTime(date);
                    }
                    else
                    {
                        rtnVal = date;
                    }
                }
            }

            return(rtnVal);
        }