Exemplo n.º 1
0
        /// <summary>
        /// Validate date and returns true/false.
        /// </summary>
        /// <param name="maskValue">MaskValue</param>
        /// <param name="value">date</param>
        /// <returns>true or false</returns>
        public static bool ValidateDate(string maskValue, string value)
        {
            bool RetVal = true;



            //TimePeriod format yyyy.mm
            if (RetVal && maskValue == "0000.00" && value.Length == 7)
            {
                RetVal = (TimePeriodFacade.ValidateMonth(7, value));
            }
            if (RetVal && maskValue == "Q0.0000" && value.Length == 7)
            {
                if (!string.IsNullOrEmpty(value.Substring(1, 1).Trim()) && (Convert.ToInt32(value.Substring(1, 1)) > 0 && Convert.ToInt32(value.Substring(1, 1)) < 5))
                {
                    RetVal = true;
                }
                else
                {
                    RetVal = false;
                }
            }

            //TimePeriod format yyyy.mm-yyyy.mm
            if (RetVal && maskValue == "0000.00-0000.00" && value.Length == 15)
            {
                RetVal = (TimePeriodFacade.ValidateMonth(15, value) && TimePeriodFacade.ValidateMonth(7, value));
            }

            //TimePeriod format yyyy.mm.dd
            if (RetVal && maskValue == "0000.00.00" && value.Length == 10)
            {
                if (TimePeriodFacade.ValidateMonth(7, value))
                {
                    RetVal = TimePeriodFacade.ValidateDay(Convert.ToInt32(value.Substring(0, 4)), Convert.ToInt32(value.Substring(5, 2)), Convert.ToInt32(value.Substring(8, 2)));
                }
                else
                {
                    RetVal = false;
                }
            }
            //TimePeriod format yyyy.mm.dd-yyyy.mm.dd
            if (RetVal && maskValue == "0000.00.00-0000.00.00" && value.Length == 21)
            {
                if (TimePeriodFacade.ValidateMonth(7, value) && TimePeriodFacade.ValidateMonth(18, value))
                {
                    RetVal = (TimePeriodFacade.ValidateDay(Convert.ToInt32(value.Substring(0, 4)), Convert.ToInt32(value.Substring(5, 2)), Convert.ToInt32(value.Substring(8, 2))) && TimePeriodFacade.ValidateDay(Convert.ToInt32(value.Substring(11, 4)), Convert.ToInt32(value.Substring(16, 2)), Convert.ToInt32(value.Substring(19, 2))));
                }
                else
                {
                    RetVal = false;
                }
            }

            return(RetVal);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns mask value only if the timperiod is in DevInfo format.
        /// </summary>
        /// <param name="timeperiod"></param>
        /// <returns></returns>
        public static string GetMaskValue(string timeperiod)
        {
            string RetVal = string.Empty;

            if (!string.IsNullOrEmpty(timeperiod))
            {
                switch (timeperiod.Length)
                {
                case 4:     // "yyyy"

                    RetVal = "0000";
                    break;

                case 7:     // "yyyy.mm"
                    if (timeperiod.StartsWith("Q"))
                    {
                        RetVal = "Q0.0000";
                    }
                    else
                    {
                        RetVal = "0000.00";
                    }
                    break;

                case 10:     // "yyyy.mm.dd"
                case 8:
                    RetVal = "0000.00.00";
                    break;

                case 5:
                    if (timeperiod.Contains("-"))
                    {
                        RetVal = "0000-0000";
                    }
                    else
                    {
                        RetVal = "0000.00";
                    }

                    break;

                case 9:     // "yyyy-yyyy"

                    RetVal = "0000-0000";
                    break;

                case 15:     // "yyyy.mm-yyyy.mm"
                case 13:
                    RetVal = "0000.00-0000.00";
                    break;

                case 21:     //"yyyy.mm.dd-yyyy.mm.dd"
                case 19:
                    RetVal = "0000.00.00-0000.00.00";
                    break;

                default:
                    break;
                }

                if (string.IsNullOrEmpty(RetVal))
                {
                    if (TimePeriodFacade.ValidateDate(RetVal, timeperiod) == false)
                    {
                        RetVal = string.Empty;
                    }
                }
            }



            return(RetVal);
        }