예제 #1
0
        private Brush GetCellBrush(int weekday, UltraCalendar uc)
        {
            Brush brush = Brushes.White;

            if (weekday == 0)
            {
                brush = Brushes.DarkRed;
            }
            if (weekday == 6)
            {
                brush = Brushes.DarkGreen;
            }
            if (uc != null && uc.SolarDate.Date == DateTime.Now.Date)
            {
                brush = Brushes.DarkOrange;
            }
            if (uc != null && !string.IsNullOrEmpty(uc.SolarTerm))
            {
                brush = Brushes.Cyan;
            }
            if (uc != null && uc.IsFestival)
            {
                brush = Brushes.Red;
            }

            return(brush);
        }
예제 #2
0
        private void ShowStatus(DateTime dt)
        {
            string        strTmp, strFullHolidayDesc;
            UltraCalendar uc = new UltraCalendar(dt);

            this.text7.Text     = GetSolarDateDesc(dt);
            strTmp              = uc.SolarHoliday;
            txtHolidayTips.Text = strFullHolidayDesc = strTmp;
            strTmp              = uc.WeekHoliday;
            if (txtHolidayTips.Text == "")
            {
                txtHolidayTips.Text = strFullHolidayDesc = strTmp;
            }
            else
            {
                strFullHolidayDesc += (strTmp == "" ? "" : "\n" + strTmp);
            }
            strTmp = uc.LunarHoliday;
            if (txtHolidayTips.Text == "")
            {
                txtHolidayTips.Text = strFullHolidayDesc = strTmp;
            }
            else
            {
                strFullHolidayDesc += (strTmp == "" ? "" : "\n" + strTmp);
            }
            txtHolidayTips.Foreground = Brushes.Red;
            txtHolidayTips.ToolTip    = string.IsNullOrWhiteSpace(strFullHolidayDesc) ? null : strFullHolidayDesc;

            if (txtHolidayTips.Text == "")
            {
                txtHolidayTips.Foreground = Brushes.White;
                txtHolidayTips.Text       = GetLunarDateDesc(dt);
            }

            _changedByCode     = true;
            txtYear.Text       = _year.ToString();
            scrBar.Value       = _year;
            txtAnimalYear.Text = uc.AnimalYear + "年";
            txtHoroscope.Text  = uc.Horoscope + "座";
            _changedByCode     = false;
        }
예제 #3
0
        private string GetFullDateDesc(DateTime dt, bool hasWeekday)
        {
            UltraCalendar uc = new UltraCalendar(dt);

            return(uc.SolarYear + "年" + uc.SolarMonth + "月" + uc.SolarDay + "日" + " " + uc.CLunarYear + "年" + uc.CLunarMonth + "月" + uc.CLunarDay + " " + uc.CKanChih + "日" + (hasWeekday ? " " + uc.CWeekday : string.Empty));
        }
예제 #4
0
        private string GetLunarDateDesc(DateTime dt)
        {
            UltraCalendar uc = new UltraCalendar(dt);

            return(uc.CLunarYear + "年" + uc.CLunarMonth + "月" + uc.CLunarDay + " " + uc.CKanChih + "日");
        }
예제 #5
0
        private string GetSolarDateDesc(DateTime dt)
        {
            UltraCalendar uc = new UltraCalendar(dt);

            return(uc.SolarYear + "年" + uc.SolarMonth + "月" + uc.SolarDay + "日 " + uc.CWeekday);
        }
예제 #6
0
 private static bool IsWeekEndOrFestival(UltraCalendar uc)
 {
     return(uc.Weekday == 6 || uc.Weekday == 0 || uc.IsFestival);
 }
예제 #7
0
        public void DisplayCalendar(int year, int month)
        {
            string[] lunarTerms = new string[2] {
                "", ""
            };
            int dayNum = DateTime.DaysInMonth(year, month);

            CalendarListBox.BeginInit();
            CalendarListBox.Items.Clear();

            _calendarDisplayUniformGrid = GetCalendarUniformGrid(CalendarListBox);
            DateTime dt = new DateTime(year, month, 1);

            _calendarDisplayUniformGrid.FirstColumn = (int)(dt.DayOfWeek);

            string sql = $"SELECT * FROM Diary WHERE RecordDate >= '{dt:yyyy-MM-dd}' AND RecordDate < '{dt.AddMonths(1):yyyy-MM-dd}'";

            _diaries = new ObservableCollection <Diary>(new DiaryDAL().GetDiaries(sql));
            for (int i = 0; i < dayNum; i++)
            {
                TextBlock mainDateLabel = new TextBlock
                {
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Background          = Brushes.Black,
                    Padding             = new Thickness(0, 0, 0, 0),
                    Margin = new Thickness(0, 0, 0, 0)
                };

                //This label is used to hold the holiday string.
                Label hiddenLabel = new Label
                {
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    VerticalAlignment   = VerticalAlignment.Stretch,
                    Visibility          = Visibility.Collapsed
                };

                //If the application is not running in zh-CN env,
                //it can display the date number bigger.
                mainDateLabel.FontSize = (_localCultureInfo.ToString() == "zh-CN") ? 20 : 25;

                //计算西历转换农历
                UltraCalendar uc         = new UltraCalendar(dt);
                string        sLunarDate = uc.CLunarDay;
                if (uc.LunarDay == 1)
                {
                    sLunarDate = uc.CLunarMonth + "月";
                }

                //判断该日期是否为农历节气,是则显示该节气
                string sTmp = uc.SolarTerm;
                if (sTmp != string.Empty)
                {
                    sLunarDate = sTmp;  //如为节气则农历日显示节气
                    sTmp       = "【" + sTmp + "】" + (uc.SolarDay > 10 ? "" : " ") + uc.SolarDay.ToString() + "日";
                    if (lunarTerms[0] == string.Empty)
                    {
                        lunarTerms[0] = sTmp;
                    }
                    else
                    {
                        lunarTerms[1] = sTmp;
                    }
                }

                //Weekend should be dispaly in red color.
                hiddenLabel.Content = uc.IsFestival ? uc.FestivalName : string.Empty;

                mainDateLabel.Foreground = GetCellBrush(uc.Weekday, uc);
                mainDateLabel.Text       = dt.Day.ToString(NumberFormatInfo.CurrentInfo);

                //If the application is running in a non zh-CN locale, display no lunar calendar.
                Label subsidiary = null;
                if (_localCultureInfo.ToString() == "zh-CN")
                {
                    subsidiary = new Label
                    {
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Center,
                        Background          = Brushes.Black,
                        Padding             = new Thickness(0, 0, 0, 0),
                        FontSize            = 13,

                        //Control the festival date to be red.
                        Foreground = GetCellBrush(uc.Weekday, uc),
                        Content    = sLunarDate
                    };
                }

                //Compose the final displaying unit.
                StackPanel stackPanel = new StackPanel
                {
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    VerticalAlignment   = VerticalAlignment.Stretch
                };

                stackPanel.Children.Add(hiddenLabel);
                stackPanel.Children.Add(mainDateLabel);
                if (subsidiary != null)
                {
                    stackPanel.Children.Add(subsidiary);
                }

                Diary diary = _diaries.FirstOrDefault(a => a.RecordDate >= dt.Date && a.RecordDate < dt.Date.AddDays(1));
                if (diary != null)    //See if having a diary or note
                {
                    mainDateLabel.TextDecorations = GetUnderlineDecoration();

                    stackPanel.ToolTip = new ToolTip();
                    ToolTip tt = (ToolTip)ToolTipService.GetToolTip(stackPanel);
                    tt.HasDropShadow   = false;
                    tt.BorderThickness = new Thickness(0);
                    tt.Background      = Brushes.Transparent;
                    FancyToolTip toolTip = new FancyToolTip
                    {
                        Title    = diary.Title,
                        InfoText = diary.Content,
                        Footer   = string.Format("{0:yyyy-MM-dd HH:mm}", diary.RowVersion)
                    };
                    tt.Content = toolTip;
                }

                Border border = new Border
                {
                    Margin = new Thickness(1.5),
                    Child  = stackPanel
                };
                CalendarListBox.Items.Add(border);

                //Display the current day in another color
                if (dt.Date == DateTime.Now.Date)
                {
                    border.BorderThickness = new Thickness(1);
                    border.BorderBrush     = Brushes.Orange;
                }
                else if (uc.IsFestival)
                {
                    border.BorderThickness = new Thickness(1);
                    border.CornerRadius    = new CornerRadius(2);
                    border.BorderBrush     = Brushes.DarkGray;
                }

                dt = dt.AddDays(1);
            }

            CalendarListBox.EndInit();
            this.text8.Text = string.Format("{0}\n{1}", lunarTerms[0], lunarTerms[1]);
        }