private void initView() { mainPanel.MouseDown += dragger_MouseDown; closeApp.Click += stopApp; TODAY = DateTime.Today; selectedGridItem = new CalndarGridItem(); previouslySelected = selectedGridItem.getTextView(); selectedGridItem.setText(TODAY.Day + ""); selectedGridItem.setDateTime(TODAY); nextMonthBtn.RotateLeft(); prevMonthBtn.RotateRight(); prevMonthBtn.addOnButtonClickHandler(new EventHandler(prevMonthBtn_onClick)); nextMonthBtn.addOnButtonClickHandler(new EventHandler(nextMonthBtn_onClick)); createGrid(0); String currenDayOfMonthString = (int)DateTime.Today.Day + ""; currentDayOfMonth.Text = (currenDayOfMonthString.Length < 2 ? "0" + currenDayOfMonthString : currenDayOfMonthString); currentDayOfWeek.Text = TODAY.DayOfWeek + ""; setWeatherCondition(); }
private void onGridItemClickListener(CalndarGridItem sender) { // 更新选中效果 selectedGridItem.ClearSelectedEffect(); if (!sender.daysAreEqual(TODAY)) { sender.SetSelectedEffect(); } selectedGridItem = sender; // 更新任务事件列表 refreshEventList(); }
/** * 创建一个7x7的日期网格 */ private void createCalenderGrid() { //创建一个7×7的网格 for (int i = 0; i < 49; i++) { CalndarGridItem item = new CalndarGridItem(); // 第一行为星期页签 if (i < 7) { item.setWeekDay(g_weeklabels[i]); item.setTextColor(Color.FromArgb(50, 63, 86)); } else { // 注册点击事件 item.setOnGridItemClickListener(new CalndarGridItemClickHandler(onGridItemClickListener)); } gridView.Controls.Add(item); mCalenderItemList.Add(item); } }
/** * 创建日期格子,包括星期页签 */ private void refreshCalenderGrid(int offsetMonth) { // 重置当前月 currentMonthCounter = offsetMonth; if (selectedGridItem != null) { selectedGridItem.ClearSelectedEffect(); } // 计算当前选择的月 以及上一个月 下一个月 DateTime today = DateTime.Today; // 如果不是本月 if (offsetMonth != 0) { today = today.AddMonths(offsetMonth); } // 下个月 DateTime nextMonth = today.AddMonths(1); // 上个月 DateTime prevMonth = today.AddMonths(-1); // 本月的第一天 DateTime temp = new DateTime(today.Year, today.Month, 1); int dayOfWeek = (int)temp.DayOfWeek; int list_index = 7; // 显示上个月剩余的天数 int dayOfPrevMonth = System.DateTime.DaysInMonth(prevMonth.Year, prevMonth.Month); for (int i = dayOfWeek - 1; i >= 0; i--) { CalndarGridItem item = mCalenderItemList[list_index++]; item.ResetItem(); //item.setDayText((dayOfPrevMonth - i) + ""); item.setDateTime(new DateTime(prevMonth.Year, prevMonth.Month, (dayOfPrevMonth - i))); item.setTextColor(Color.FromArgb(50, 63, 86)); } // 显示本月的天数 int daysOfCurrentMonth = System.DateTime.DaysInMonth(today.Year, today.Month); for (int i = 1; i <= daysOfCurrentMonth && list_index < mCalenderItemList.Count; i++) { string day = i.ToString(); // 创建日期格子 CalndarGridItem item = mCalenderItemList[list_index++]; item.ResetItem(); item.setDateTime(new DateTime(today.Year, today.Month, i)); item.setTextColor(Color.FromArgb(255, 255, 255)); // 今天 if (offsetMonth == 0 && i == DateTime.Today.Day) { item.makeToDay(); //首次启动没有选择item,就选中今天 if (selectedGridItem == null) { selectedGridItem = item; } } String key = Utils.GetDateString(today, day); if (mEventData.ContainsKey(key.GetHashCode())) { if (offsetMonth <= 0 && i < TODAY.Day) { item.hadNote(); } else { item.hasNote(); } } } // 显示下一个月的前几天 int daysOfNextMonth = dayOfWeek - 1 + daysOfCurrentMonth; for (int i = 1; i < 42 - daysOfNextMonth; i++) { CalndarGridItem item = mCalenderItemList[list_index++]; item.ResetItem(); item.setDateTime(new DateTime(nextMonth.Year, nextMonth.Month, i)); item.setTextColor(Color.FromArgb(50, 63, 86)); } // 设置界面年月 currentMonth.Text = today.ToString("MMMM"); currentYear.Text = today.Year + ""; // 设置选择 if (!selectedGridItem.daysAreEqual(TODAY)) { selectedGridItem.SetSelectedEffect(); } refreshEventList(); }
private void createGrid(int addMonth) { if (File.Exists(eventFileName)) { SaveXML <Dictionary <int, List <Event> > > saver = new SaveXML <Dictionary <int, List <Event> > >(); mEvents = saver.GetData(mEvents, eventFileName); } gridView.Controls.Clear(); String[] months = { "su", "mo", "tu", "we", "th", "fr", "sa" }; for (int i = 0; i < 7; i++) { CalndarGridItem item = new CalndarGridItem(); item.setText(months[i]); item.setTextColor(Color.FromArgb(50, 63, 86)); gridView.Controls.Add(item); } DateTime temp; DateTime today = DateTime.Today; if (addMonth != 0) { today = today.AddMonths(addMonth); } DateTime nextMonth = today.AddMonths(1); DateTime prevMonth = today.AddMonths(-1); temp = new DateTime(today.Year, today.Month, 1); int dayOfWeek = (int)temp.DayOfWeek; int dayOfPrevMonth = System.DateTime.DaysInMonth(prevMonth.Year, prevMonth.Month); for (int i = dayOfWeek - 1; i >= 0; i--) { CalndarGridItem item = new CalndarGridItem(); item.setText((dayOfPrevMonth - i) + ""); item.setTextColor(Color.FromArgb(50, 63, 86)); gridView.Controls.Add(item); } int daysOfCurrentMonth = System.DateTime.DaysInMonth(today.Year, today.Month); for (int i = 1; i <= daysOfCurrentMonth; i++) { CalndarGridItem item = new CalndarGridItem(); item.setText(i + ""); if (addMonth == 0 && i == (int)DateTime.Today.Day) { item.makeToDay(); } item.setDateTime(today); item.getTextView().Cursor = Cursors.Hand; item.setOnGridItemClickListener(new EventHandler(onGridItemClickListener)); String key = i + " " + today.ToString("MMMM").Substring(0, 3) + " " + today.Year; if (mEvents.ContainsKey(key.GetHashCode())) { if (addMonth <= 0 && i < TODAY.Day) { item.hadNote(); } else { item.hasNote(); } } gridView.Controls.Add(item); } int daysOfNextMonth = dayOfWeek - 1 + daysOfCurrentMonth; for (int i = 1; i < 35 - daysOfNextMonth; i++) { CalndarGridItem item = new CalndarGridItem(); item.setText(i + ""); item.setTextColor(Color.FromArgb(50, 63, 86)); gridView.Controls.Add(item); } currentMonth.Text = today.ToString("MMMM"); currentYear.Text = today.Year + ""; }