private void ComboBoxDropDownClosed_Lunar(object sender, object e) { int lunarYear = comboBoxLunarYears.SelectedIndex + 1970; int lunarMonth = comboBoxLunarMonths.SelectedIndex + 1; int lunarDay = comboBoxLunarDays.SelectedIndex + 1; bool isLeap = LunarToSolar.IsLunarLeapYear(lunarYear); Lunar_t lunar_T = new Lunar_t(lunarYear, lunarMonth, lunarDay, isLeap); int solarYear = 0; int solarMonth = 0; int solarDay = 0; if (LunarToSolar.ToSolar(lunar_T, ref solarYear, ref solarMonth, ref solarDay)) { int daysOfSolarMonth = DaysOfSolarMonth(solarYear, solarMonth); switch (daysOfSolarMonth) { case 28: comboBoxDays.ItemsSource = datas28Days; break; case 29: comboBoxDays.ItemsSource = datas29Days; break; case 30: comboBoxDays.ItemsSource = datas30Days; break; case 31: comboBoxDays.ItemsSource = datas31Days; break; default: break; } comboBoxYears.SelectedIndex = solarYear - 1970; comboBoxMonths.SelectedIndex = solarMonth - 1; comboBoxDays.SelectedIndex = solarDay - 1; int lunarMonthDays = LunarCalendar.DaysOfLunarMonth(solarYear, solarMonth); if (lunarMonthDays == 29) { comboBoxLunarDays.ItemsSource = datas29LunarDays; }//if else { comboBoxLunarDays.ItemsSource = datas30LunarDays; }//else if (lunarDay > lunarMonthDays) { comboBoxLunarDays.SelectedIndex = lunarMonthDays - 1; }//if else { comboBoxLunarDays.SelectedIndex = lunarDay - 1; }//else DateTime dateTime = new DateTime(solarYear, solarMonth, solarDay); Refresh(dateTime); TextBlock_loaded(); } }
private void ComboBoxDropDownClosed_Solar(object sender, object e) { int solarYear = comboBoxYears.SelectedIndex + 1970; int solarMonth = comboBoxMonths.SelectedIndex + 1; int solarDay = comboBoxDays.SelectedIndex + 1; DateTime dateTime = new DateTime(solarYear, solarMonth, solarDay); Refresh(dateTime); int lunarMonthDays = LunarCalendar.DaysOfLunarMonth(solarYear, solarMonth); if (lunarMonthDays == 29) { comboBoxLunarDays.ItemsSource = datas29LunarDays; }//if else { comboBoxLunarDays.ItemsSource = datas30LunarDays; }//else int daysOfSolarMonth = DaysOfSolarMonth(solarYear, solarMonth); switch (daysOfSolarMonth) { case 28: comboBoxDays.ItemsSource = datas28Days; break; case 29: comboBoxDays.ItemsSource = datas29Days; break; case 30: comboBoxDays.ItemsSource = datas30Days; break; case 31: comboBoxDays.ItemsSource = datas31Days; break; default: break; } comboBoxDays.SelectedIndex = solarDay - 1; int lunarYear = LunarCalendar.GetLunarYear(solarYear, solarMonth, solarDay); string lunarMonth = LunarCalendar.GetStringLunarMonth(solarYear, solarMonth, solarDay); int lunarDay = LunarCalendar.GetIntLunarDay(solarYear, solarMonth, solarDay); comboBoxLunarYears.SelectedItem = $"{lunarYear}年"; comboBoxLunarMonths.SelectedItem = lunarMonth; comboBoxLunarDays.SelectedIndex = lunarDay - 1; TextBlock_loaded(); }
public void Combobox_loaded(DateTime currentTime) { comboBoxYears.ItemsSource = datas100Years; int year = currentTime.Year; comboBoxYears.SelectedItem = $"{year}年"; comboBoxMonths.SelectedItem = $"{currentTime.Month}月"; int daysOfSolarMonth = DaysOfSolarMonth(currentTime.Year, currentTime.Month); switch (daysOfSolarMonth) { case 28: comboBoxDays.ItemsSource = datas28Days; break; case 29: comboBoxDays.ItemsSource = datas29Days; break; case 30: comboBoxDays.ItemsSource = datas30Days; break; case 31: comboBoxDays.ItemsSource = datas31Days; break; default: break; } comboBoxDays.SelectedIndex = currentTime.Day - 1; comboBoxLunarYears.ItemsSource = datas100Years; comboBoxLunarYears.SelectedItem = LunarCalendar.GetLunarYear(currentTime.Year, currentTime.Month, currentTime.Day) + "年"; string LunarDay = LunarCalendar.GetLunarDay(currentTime.Year, currentTime.Month, currentTime.Day, false); comboBoxLunarMonths.SelectedItem = LunarCalendar.GetStringLunarMonth(currentTime.Year, currentTime.Month, currentTime.Day); int lunarMonthDays = LunarCalendar.GetIntLunarMonth(currentTime.Year, currentTime.Month, currentTime.Day)[1]; if (lunarMonthDays == 29) { comboBoxLunarDays.ItemsSource = datas29LunarDays; } else { comboBoxLunarDays.ItemsSource = datas30LunarDays; } comboBoxLunarDays.SelectedItem = LunarCalendar.GetLunarDay(currentTime.Year, currentTime.Month, currentTime.Day, true); }
private void Button_Click(object sender, RoutedEventArgs e) { Button b = (Button)sender; if (priClickButton != null) { priClickButton.BorderBrush = brushTransparent; } b.BorderBrush = brushBrown; priClickButton = b; int i = b.Name[b.Name.Length - 2] - '0'; int j = b.Name[b.Name.Length - 1] - '0'; int d = dayInButton[i, j];//该按钮显示的天数 //更新显示的日期 comboBoxDays.SelectedIndex = d - 1; int solarYear = comboBoxYears.SelectedIndex + 1970; int solarMonth = comboBoxMonths.SelectedIndex + 1; int solarDay = comboBoxDays.SelectedIndex + 1; DateTime dateTime = new DateTime(solarYear, solarMonth, solarDay); int lunarMonthDays = LunarCalendar.DaysOfLunarMonth(solarYear, solarMonth); if (lunarMonthDays == 29) { comboBoxLunarDays.ItemsSource = datas29LunarDays; }//if else { comboBoxLunarDays.ItemsSource = datas30LunarDays; }//else int lunarYear = LunarCalendar.GetLunarYear(solarYear, solarMonth, solarDay); string lunarMonth = LunarCalendar.GetStringLunarMonth(solarYear, solarMonth, solarDay); int lunarDay = LunarCalendar.GetIntLunarDay(solarYear, solarMonth, solarDay); comboBoxLunarYears.SelectedItem = $"{lunarYear}年"; comboBoxLunarMonths.SelectedItem = lunarMonth; comboBoxLunarDays.SelectedIndex = lunarDay - 1; TextBlock_loaded(); }
//刷新页面函数 public void Refresh(DateTime dateTime) { foreach (Button button in list) { button.IsEnabled = true; //使按钮能点击 } list.Clear(); //清空链表 for (int i = 0; i < 7; i++) { buttonArray[0, i].Content = ""; buttonArray[4, i].Content = ""; buttonArray[5, i].Content = ""; } ButtonTodayTemp.Background = brushWheat; ButtonTodayTemp.Foreground = brushBlack; if (priClickButton != null) { priClickButton.BorderBrush = brushTransparent; } //星期六、日的字体颜色为brown for (int i = 0; i < 6; i++) { buttonArray[i, 6].Foreground = brushBrown; //星期六 buttonArray[i, 0].Foreground = brushBrown; //星期日 } DateTime date = new DateTime(dateTime.Year, dateTime.Month, 1); int weekday = (int)date.DayOfWeek; int number = 0; int maxDay = DateTime.DaysInMonth(dateTime.Year, dateTime.Month); for (int i = 0; i < 6; i++) { for (int j = 0; j < 7; j++) { number = i * 7 + j + 1 - weekday; if (number > 0 && number <= maxDay) { if (number == dateTime.Day) { priClickButton = buttonArray[i, j]; } string lunarDate = LunarCalendar.GetLunarDay(dateTime.Year, dateTime.Month, number, false); string Blank2 = GetBlank(lunarDate.Length); if (number < 10) { buttonArray[i, j].Content = Blank2 + $" {number}\n" + lunarDate; } else { buttonArray[i, j].Content = Blank2 + $"{number}\n" + lunarDate; } dayInButton[i, j] = number; number++; } else { buttonArray[i, j].IsEnabled = false;//使按钮失效 list.Add(buttonArray[i, j]); dayInButton[i, j] = 0; } } } priClickButton.BorderBrush = brushBrown; DateTime Today = DateTime.Now; if (dateTime.Year == Today.Year && dateTime.Month == Today.Month) { ButtonTodayTemp.Background = brushBrown; ButtonTodayTemp.Foreground = brushWheat; } }
private void MainPage_Loaded(object sender, RoutedEventArgs e) { DateTime currentTime = DateTime.Now; Combobox_loaded(currentTime); TextBlock_loaded(); //星期六、日的字体颜色为brown for (int i = 0; i < 6; i++) { buttonArray[i, 6].Foreground = brushBrown; //星期六 buttonArray[i, 0].Foreground = brushBrown; //星期日 } DateTime dateTime = new DateTime(currentTime.Year, currentTime.Month, 1); int weekday = (int)dateTime.DayOfWeek; int number = 0; dayInButton = new int[6, 7]; /* * while (weekday < 7) * { * if (number == currentTime.Day) * ButtonTodayTemp = buttonArray[0, weekday]; * string lunarDate = LunarCalendar.GetLunarDay(currentTime.Year, currentTime.Month, number, false); * string Blank1 = GetBlank(lunarDate.Length); * buttonArray[0, weekday].Content = Blank1 + $" {number}\n" + lunarDate; * dayInButton[0, weekday] = number; * weekday++; * number++; * } */ int maxDay = DateTime.DaysInMonth(currentTime.Year, currentTime.Month); list = new List <Button>(); for (int i = 0; i < 6; i++) { for (int j = 0; j < 7; j++) { number = i * 7 + j + 1 - weekday; if (number > 0 && number <= maxDay) { if (number == currentTime.Day) { ButtonTodayTemp = buttonArray[i, j]; } string lunarDate = LunarCalendar.GetLunarDay(currentTime.Year, currentTime.Month, number, false); string Blank2 = GetBlank(lunarDate.Length); if (number < 10) { buttonArray[i, j].Content = Blank2 + $" {number}\n" + lunarDate; } else { buttonArray[i, j].Content = Blank2 + $"{number}\n" + lunarDate; } dayInButton[i, j] = number; } else { buttonArray[i, j].IsEnabled = false;//使按钮失效 list.Add(buttonArray[i, j]); dayInButton[i, j] = 0; } } } if (ButtonTodayTemp != null) { ButtonTodayTemp.Background = brushBrown; ButtonTodayTemp.Foreground = brushWheat; } }