Example #1
0
        public void CreatePopupList()
        {
            if (DateRule == "")            //如果是空白,默认选中今天,啥也不限制
            {
                AyCalendar ac = new AyCalendar();
                ac.BorderBrush           = Brushes.Transparent;
                ac.MinDateReferToElement = this.MinDateReferToElement;
                ac.MaxDateReferToElement = this.MaxDateReferToElement;
                ac.DateBoxInput          = this;
                //ac.DisabledDatesStrings = this.DisabledDatesStrings;
                ac.HorizontalAlignment = HorizontalAlignment.Center;
                ac.VerticalAlignment   = VerticalAlignment.Center;
                ac.SelectMode          = AyDatePickerSelectMode.OnlySelectDate;
                if (!this.Text.IsNullAndTrimAndEmpty())
                {
                    DateTime?date = ReverseDateTimeFromText(ac);
                    if (date.HasValue)
                    {
                        ac.SelectedDateTime = date;
                    }
                }
                RootGrid.Children.Add(ac);
            }
            else
            {
                if (DateRuleObjects.IsNotNull())
                {
                    _fmt = AyCalendarService.GetAyCalendarFMT(DateRuleObjects.dateFmt);
                    switch (_fmt)
                    {
                    case AyCalendarFMT.None:
                        break;

                    default:
                        AyCalendar ac = CreateAyCalendar();
                        RootGrid.Children.Add(ac);
                        break;
                    }
                }
            }
        }
        public static AyCalendarFMT GetAyCalendarFMT(string dateFmt)
        {
            bool          yy = dateFmt.IndexOf("y") > -1;
            bool          MM = dateFmt.IndexOf("M") > -1;
            bool          dd = dateFmt.IndexOf("d") > -1;
            bool          hh = dateFmt.IndexOf("H") > -1;
            bool          mm = dateFmt.IndexOf("m") > -1;
            bool          ss = dateFmt.IndexOf("s") > -1;
            AyCalendarFMT df = AyCalendarFMT.None;

            if (yy && MM && !dd && !hh && !mm && !ss)
            {
                df = AyCalendarFMT.YearMonth;
            }
            else if (yy && MM && dd && !hh && !mm && !ss)
            {
                df = AyCalendarFMT.YearMonthDay;
            }
            else if (yy && MM && dd && hh && !mm && !ss)
            {
                df = AyCalendarFMT.YearMonthDayH;
            }
            else if (yy && MM && dd && hh && mm && !ss)
            {
                df = AyCalendarFMT.YearMonthDayHM;
            }
            else if (yy && MM && dd && hh && mm && ss)
            {
                df = AyCalendarFMT.YearMonthDayHMS;
            }
            else if (!yy && !MM && !dd && hh && mm && ss)
            {
                df = AyCalendarFMT.HMS;
            }
            else if (!yy && !MM && !dd && hh && mm && !ss)
            {
                df = AyCalendarFMT.HM;
            }
            return(df);
        }