Exemple #1
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                var dt = (DateTime) value;

                Lunar lunar = new Lunar(dt);
                return lunar.GetOBOfDay(dt).LShX2;
            }
            catch (Exception)
            {
                return "";
            }
        }
Exemple #2
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                var dt = (DateTime) value;

                Lunar lunar = new Lunar(dt);
                var a = lunar.GetOBOfDay(dt).LShX2;

                switch (a)
                {
                    case "鼠":
                        return ToUnicodeString("&#xe800");
                    case "牛":
                        return ToUnicodeString("&#xe801");
                    case "虎":
                        return ToUnicodeString("&#xe802");
                    case "兔":
                        return ToUnicodeString("&#xe803");
                    case "龙":
                        return ToUnicodeString("&#xe804");
                    case "蛇":
                        return ToUnicodeString("&#xe805");
                    case "马":
                        return ToUnicodeString("&#xe806");
                    case "羊":
                        return ToUnicodeString("&#xe807");
                    case "猴":
                        return ToUnicodeString("&#xe808");
                    case "鸡":
                        return ToUnicodeString("&#xe809");
                    case "狗":
                        return ToUnicodeString("&#xe80a");
                    case "猪":
                        return ToUnicodeString("&#xe80b");
                }

                return "";
            }
            catch (Exception)
            {
                return "";
            }
        }
Exemple #3
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                var dt = (DateTime) value;

                Lunar lunar = new Lunar(dt);
                var ob = lunar.GetOBOfDay(dt);

                switch (parameter.ToString())
                {
                    case "年":
                        return ob.Lyear3;
                    case "月":
                        return ob.Lmonth2;
                    case "日":
                        return ob.Lday2;
                    case "时":
                        return ob.Ltime2;
                }

                return ob.Lyear3;
            }
            catch (Exception)
            {
                return "";
            }
        }
Exemple #4
0
        private void UpdateDateTimes(DateTime dateTime, WeatherInfo weatherInfo = null)
        {
            CurrentDateInfos = null;

            var tempDateInfos = new List<DateInfo>();

            if (dateTime.Date != DateTime.Now.Date)
            {
                dateTime = new DateTime(dateTime.Year, dateTime.Month, 1);
            }

            Lunar lastMouth= new Lunar(dateTime.AddMonths(-1));
            Lunar currentMouth = new Lunar(dateTime);
            Lunar nextMouth = new Lunar(dateTime.AddMonths(1));

            DateTime firstDayOfMouth = dateTime.AddDays(-dateTime.Day + 1);
            DateTime lastDayOfLastMouth = dateTime.AddDays(-dateTime.Day);

            int startDay = (int)firstDayOfMouth.DayOfWeek;
            int daysOfMounth = (firstDayOfMouth.AddMonths(1) - firstDayOfMouth).Days;

            if (startDay == 0)
                startDay = 7;

            DateTime startDate = firstDayOfMouth.AddDays(1 - startDay);
            DateTime endDate = startDate.AddDays(41);

            for (int i = 0; i < 35; i++)
            {
                var day = startDate.AddDays(i);
                Lunar mouth = null;
                var ob = lastMouth.GetOBOfDay(day);
                if (ob != null)
                    mouth = lastMouth;
                else
                {
                    ob = currentMouth.GetOBOfDay(day);
                    if (ob != null)
                        mouth = currentMouth;
                    else
                    {
                        ob = nextMouth.GetOBOfDay(day);
                        if (ob != null)
                            mouth = nextMouth;
                    }
                }
                var dateInfo = new DateInfo()
                {
                    DateTime = day,
                    CurrentDate = dateTime,
                    OB = ob,
                    Lunar = mouth
                };

                switch ((dateInfo.DateTime.Date - DateTime.Now.Date).Days)
                {
                    case -1:
                        dateInfo.Weather = weatherInfo?.YesterdayWeather;
                        break;
                    case 0:
                        dateInfo.Weather = weatherInfo?.TodayWeather;
                        break;
                    case 1:
                        dateInfo.Weather = weatherInfo?.TomorrowWeather;
                        break;
                    case 2:
                        dateInfo.Weather = weatherInfo?.ThirdDayWeather;
                        break;
                    case 3:
                        dateInfo.Weather = weatherInfo?.FourthDayWeather;
                        break;
                    case 4:
                        dateInfo.Weather = weatherInfo?.FifthDayWeather;
                        break;
                    case 5:
                        dateInfo.Weather = weatherInfo?.SixthDayWeather;
                        break;
                }
                tempDateInfos.Add(dateInfo);
            }

            if (startDate.AddDays(35).Month == dateTime.Month)
            {
                MouthMargin = ExtendMargin;
                for (int i = 0; i < 7; i++)
                {
                    var day = firstDayOfMouth.AddDays(i + 36 - startDay);
                    Lunar mouth = null;
                    var ob = lastMouth.GetOBOfDay(day);
                    if (ob != null)
                        mouth = lastMouth;
                    else
                    {
                        ob = currentMouth.GetOBOfDay(day);
                        if (ob != null)
                            mouth = currentMouth;
                        else
                        {
                            ob = nextMouth.GetOBOfDay(day);
                            if (ob != null)
                                mouth = nextMouth;
                        }
                    }
                    var dateInfo = new DateInfo()
                    {
                        DateTime = day,
                        CurrentDate = dateTime,
                        OB = ob,
                        Lunar = mouth
                    };

                    switch ((dateInfo.DateTime.Date - DateTime.Now.Date).Days)
                    {
                        case -1:
                            dateInfo.Weather = weatherInfo?.YesterdayWeather;
                            break;
                        case 0:
                            dateInfo.Weather = weatherInfo?.TodayWeather;
                            break;
                        case 1:
                            dateInfo.Weather = weatherInfo?.TomorrowWeather;
                            break;
                        case 2:
                            dateInfo.Weather = weatherInfo?.ThirdDayWeather;
                            break;
                        case 3:
                            dateInfo.Weather = weatherInfo?.FourthDayWeather;
                            break;
                        case 4:
                            dateInfo.Weather = weatherInfo?.FifthDayWeather;
                            break;
                        case 5:
                            dateInfo.Weather = weatherInfo?.SixthDayWeather;
                            break;
                    }
                    tempDateInfos.Add(dateInfo);
                    CalendarRows = 6;
                }

                IsExtendedMonth = true;
            }
            else
            {
                MouthMargin = NormalMargin;
                CalendarRows = 5;
                IsExtendedMonth = false;
            }

            CurrentDateInfos = tempDateInfos;
        }