// List<WorkHours> whList = new List<WorkHours>(); public void fillWeeklyCalendar() { Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Wait, 2); myGrid.Opacity = 0.5; LeftMonth = String.Empty; LeftYear = String.Empty; RightMonth = String.Empty; RightYear = String.Empty; // whList = (await WorkHours.ReadListAsync()).Where(w => w.EmployeeId == Connection.User.UserId).ToList(); Windows.Globalization.Calendar calendar = new Windows.Globalization.Calendar(); List<NameValueItem3> dList = new List<NameValueItem3>(); List<WeekDay> weekList = new List<WeekDay>(7); if (flip2 == 0) { if (String.IsNullOrEmpty(SelectedMonth)) SelectedMonth = calendar.MonthAsSoloString(); if (String.IsNullOrEmpty(SelectedYear)) SelectedYear = calendar.Year.ToString(); SelectedWeek = 1; } if (flip2 == -1) { if (SelectedWeek == 1) { SelectedWeek = 4; if ((DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month) == 1) { SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(12); SelectedYear = ((Convert.ToInt32(SelectedYear)) - 1).ToString(); } else { SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1); } } else { SelectedWeek--; } } if (flip2 == 1) { if (SelectedWeek == 4) { SelectedWeek = 1; if ((DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month) == 12) { SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(1); SelectedYear = ((Convert.ToInt32(SelectedYear)) + 1).ToString(); } else { SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month + 1); } } else { SelectedWeek++; } } int noOfDaysInTheSelectedMonth = 0; int shift = 0; string firstDay = String.Empty; if (SelectedWeek == 1) { //int noOfDaysInTheSelectedMonth = 0; //int shift = 0; //string firstDay = String.Empty; noOfDaysInTheSelectedMonth = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month); firstDay = new DateTime(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month, 1).ToString("dddd"); switch (firstDay) { case "Sunday": shift = 0; break; case "Monday": shift = 1; break; case "Tuesday": shift = 2; break; case "Wednesday": shift = 3; break; case "Thursday": shift = 4; break; case "Friday": shift = 5; break; case "Saturday": shift = 6; break; } int NumberOfPreviousMonthDays; string previuosMonth; string previousMonthYear; if (shift != 0) { if (DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month != 1) { NumberOfPreviousMonthDays = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1); previuosMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);// previousMonthYear = SelectedYear; } else { NumberOfPreviousMonthDays = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear) - 1, 12); previuosMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(12);// CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);// previousMonthYear = (Convert.ToInt32(SelectedYear) - 1).ToString(); } for (int i = shift - 1; i >= 0; i--) { weekList.Add(new WeekDay { Year = previousMonthYear, Month = previuosMonth, Day = NumberOfPreviousMonthDays - i }); } for (int i = 1; i <= 7 - shift; i++) { weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i }); if (i == 7 - shift) { ReachedDayInWeeklyCalendar = weekList.Last(); StartDayInWeeklyCalendar = weekList.First(); } } LeftMonth = previuosMonth; LeftYear = previousMonthYear; RightMonth = SelectedMonth; // MonthNameTextBlock3.Text =SelectedMonth ; RightYear = selectedYear; } if (shift == 0) { for (int i = 1; i <= 7; i++) { weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i }); if (i == 7) { ReachedDayInWeeklyCalendar = weekList.Last(); StartDayInWeeklyCalendar = weekList.First(); } } LeftMonth = SelectedMonth; LeftYear = SelectedYear; RightMonth = String.Empty; RightYear = String.Empty; } //fill dList // weekList.Clear(); } else if (SelectedWeek == 2 || SelectedWeek == 3 || SelectedWeek == 4) { if (!backward) { for (int i = ReachedDayInWeeklyCalendar.Day + 1; i <= (ReachedDayInWeeklyCalendar.Day + 7); i++) { weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i }); if (i == ReachedDayInWeeklyCalendar.Day + 7) { ReachedDayInWeeklyCalendar = weekList.Last(); StartDayInWeeklyCalendar = weekList.First(); break; } } } else //backward true { if (StartDayInWeeklyCalendar.Day - 1 != 0) { for (int i = StartDayInWeeklyCalendar.Day - 7; i <= (StartDayInWeeklyCalendar.Day - 1); i++) { weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i }); if (i == StartDayInWeeklyCalendar.Day - 1) { ReachedDayInWeeklyCalendar = weekList.Last(); StartDayInWeeklyCalendar = weekList.First(); break; } } } else { if (DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month != 1) { noOfDaysInTheSelectedMonth = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month); //SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);// //SelectedYear = SelectedYear; } else { noOfDaysInTheSelectedMonth = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear) - 1, 12); //SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(12);// CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);// //SelectedYear = (Convert.ToInt32(SelectedYear) - 1).ToString(); } for (int i = noOfDaysInTheSelectedMonth - 6; i <= (noOfDaysInTheSelectedMonth - 0); i++) { weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i }); if (i == (noOfDaysInTheSelectedMonth - 0)) { ReachedDayInWeeklyCalendar = weekList.Last(); StartDayInWeeklyCalendar = weekList.First(); break; } } } } LeftMonth = SelectedMonth; LeftYear = SelectedYear; RightMonth = String.Empty; RightYear = String.Empty; } for (int i = 0; i < 192; i++) { OutLookEvent[] myOEvent2 = null; OutLookEvent myOEvent = null; WorkHours wh = null; if (i % 8 == 0) { dList.Add(new NameValueItem3() { timeItem = true, time = new TimeSpan(i / 8, 0, 0), Width = 1, timeStr = (new TimeSpan(i / 8, 0, 0)).ToString(), Color1 = "#BFB5DF", Width1 = 120 }); //( new TimeSpan(i / 8, 0, 0)).ToString() } else { DateTime loopDate = new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year), DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month, weekList.ElementAt((i % 8) - 1).Day); try { // myOEvent = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy"))).ToArray().First(); // myOEvent = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy")) && (e.start_time.TimeOfDay.Equals(new TimeSpan(i / 8, 0, 0)) || e.end_time.TimeOfDay >= (new TimeSpan(i / 8, 0, 0)))).ToArray().First(); // myOEvent = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy")) && (new TimeSpan(e.end_time.TimeOfDay.Hours,0,0) >= (new TimeSpan(i / 8, 0, 0)) || e.isAllDay == true)).ToArray().First(); // myOEvent = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy")) && (((new TimeSpan(e.end_time.TimeOfDay.Hours, 0, 0) > (new TimeSpan(i / 8, 0, 0))) && (new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) <= (new TimeSpan(i / 8, 0, 0)))) || e.isAllDay == true || ((new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) <= (new TimeSpan(i / 8, 0, 0)))&&(TimeSpan)(e.end_time - e.start_time) <= new TimeSpan(1, 0, 0)))).ToArray().First(); myOEvent = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy")) && (((new TimeSpan(e.end_time.TimeOfDay.Hours, 0, 0) > (new TimeSpan(i / 8, 0, 0))) && (new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) <= (new TimeSpan(i / 8, 0, 0)))) || e.isAllDay == true || ((new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) == (new TimeSpan(i / 8, 0, 0))) && ((TimeSpan)(e.end_time - e.start_time)).Hours <= 1))).ToArray().First(); myOEvent2 = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy")) && (((new TimeSpan(e.end_time.TimeOfDay.Hours, 0, 0) > (new TimeSpan(i / 8, 0, 0))) && (new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) <= (new TimeSpan(i / 8, 0, 0)))) || e.isAllDay == true || ((new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) == (new TimeSpan(i / 8, 0, 0))) && ((TimeSpan)(e.end_time - e.start_time)).Hours <= 1))).ToArray(); } catch { } try { wh = whList.Where(w =>(( w.From.ToString("MMMM dd, yyyy").Equals(loopDate.ToString("MMMM dd, yyyy")) && w.From.TimeOfDay.Hours<=(i / 8) && w.To.ToString("MMMM dd, yyyy").Equals(loopDate.ToString("MMMM dd, yyyy")) && w.To.TimeOfDay.Hours>=(i / 8)) || ( w.From.ToString("MMMM dd, yyyy").Equals(loopDate.ToString("MMMM dd, yyyy")) && w.From.TimeOfDay.Hours<=i / 8 && w.To.Date.Equals(loopDate.AddDays(1))) || (w.From.Date.Equals(loopDate.AddDays(-1).Date) && w.To.Date.Equals(loopDate.Date) && w.To.TimeOfDay.Hours >= (i/8)) || (w.TimeOffFrom.Date.Equals(loopDate.Date) && w.TimeOffFrom.TimeOfDay.Hours<=(i/8) && w.TimeOffTo.TimeOfDay.Hours>=(i/8) ) ) ).ToArray().First(); } catch { } dList.Add(new NameValueItem3() { timeItem = false, time = new TimeSpan(i / 8, 0, 0), Width = 3, weekDay = weekList.ElementAt((i % 8) - 1), Color1 = (myOEvent != null ? "Wheat" : "#BFB5DF"), myOutLookEvent = myOEvent, myOutLookEvent2 = myOEvent2, workHours = wh, Border = (myOEvent != null || wh != null ? new Thickness(1) : new Thickness(0)), Color2 = (wh == null ? "#BFB5DF" : (wh.From.TimeOfDay.Hours == 7 ? "#99FF99" : (wh.From.TimeOfDay.Hours == 15 ? "#99CCFF" : (wh.From.TimeOfDay.Hours == 23 ? "Wheat" : "#BFB5DF")))), Width1 = (myOEvent == null && wh != null ? 0 : (myOEvent != null && wh != null) ? 60 : 120), Width2 = (wh != null && myOEvent == null ? 120 : (wh != null && myOEvent != null) ? 60 : 0), }); if (i > 0 || i < 8) { // if(myOEvent.isAllDay) switch (i) { case 1: Sunday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year), DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month, weekList.ElementAt((i % 8) - 1).Day) ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day; try { Sunday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null); } catch { Sunday2.Text = String.Empty; } break; case 2: Monday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year), DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month, weekList.ElementAt((i % 8) - 1).Day) ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day; try { Monday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null); } catch { Monday2.Text = String.Empty; } break; case 3: Tuesday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year), DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month, weekList.ElementAt((i % 8) - 1).Day) ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day; try { Tuesday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null); } catch { Tuesday2.Text = String.Empty; } break; case 4: Wednesday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year), DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month, weekList.ElementAt((i % 8) - 1).Day) ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day; try { Wednesday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null); } catch { Wednesday2.Text = String.Empty; } break; case 5: Thursday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year), DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month, weekList.ElementAt((i % 8) - 1).Day) ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day; try { Thursday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null); } catch { Thursday2.Text = String.Empty; } break; case 6: Friday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year), DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month, weekList.ElementAt((i % 8) - 1).Day) ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day; try { Friday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null); } catch { Friday2.Text = String.Empty; } break; case 7: Saturday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year), DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month, weekList.ElementAt((i % 8) - 1).Day) ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day; try { Saturday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null); } catch { Saturday2.Text = String.Empty; } break; } // weekList.ElementAt((i-1)%8) } } } flip2 = 0; backward = false; WeekGridView.ItemsSource = dList; weekList.Clear(); Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { WeekGridView.ScrollIntoView(dList.ElementAt(147)); }); myGrid.Opacity = 1; Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 2); }
public async void fillWeeklyCalendar() { Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Wait, 2); myGrid.Opacity = 0.5; appIncrease++; //if (flip2 == 0) //{ whList = (await WorkHours.ReadListAsync()).Where(w => w.EmployeeId == SelectedDoctor.UserId).ToList(); appList = (await Appointment.ReadAppointmentsList()).Where(a => a.UserID == SelectedDoctor.UserId).ToList(); invList = (await Invitation.ReadInvitationsList()).Where(i => i.ToUserId == SelectedDoctor.UserId).ToList(); //} if (SelectedWeek != 0 && flip2 == 0) { stay = true; } if (!stay) { LeftMonth = String.Empty; LeftYear = String.Empty; RightMonth = String.Empty; RightYear = String.Empty; } // whList = (await WorkHours.ReadListAsync()).Where(w => w.EmployeeId == Connection.User.UserId).ToList(); calendar = new Windows.Globalization.Calendar(); //ObservableCollection List<NameValueItem3> dList = new List<NameValueItem3>(); //dList.Clear(); // List<WeekDay> weekList = new List<WeekDay>(7); if (flip2 == 0) { if (String.IsNullOrEmpty(SelectedMonth)) SelectedMonth = calendar.MonthAsSoloString(); if (String.IsNullOrEmpty(SelectedYear)) SelectedYear = calendar.Year.ToString(); if (!stay) SelectedWeek = 1; } if (flip2 == -1) { if (SelectedWeek == 1) { SelectedWeek = 4; if ((DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month) == 1) { SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(12); SelectedYear = ((Convert.ToInt32(SelectedYear)) - 1).ToString(); } else { SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1); } } else { SelectedWeek--; } } if (flip2 == 1) { if (SelectedWeek == 4) { SelectedWeek = 1; if ((DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month) == 12) { SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(1); SelectedYear = ((Convert.ToInt32(SelectedYear)) + 1).ToString(); } else { SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month + 1); } } else { SelectedWeek++; } } int noOfDaysInTheSelectedMonth = 0; int shift = 0; string firstDay = String.Empty; if (!stay) weekList.Clear(); if (SelectedWeek == 1) { //int noOfDaysInTheSelectedMonth = 0; //int shift = 0; //string firstDay = String.Empty; if (!stay) { noOfDaysInTheSelectedMonth = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month); firstDay = new DateTime(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month, 1).ToString("dddd"); switch (firstDay) { case "Sunday": shift = 0; break; case "Monday": shift = 1; break; case "Tuesday": shift = 2; break; case "Wednesday": shift = 3; break; case "Thursday": shift = 4; break; case "Friday": shift = 5; break; case "Saturday": shift = 6; break; } int NumberOfPreviousMonthDays; string previuosMonth; string previousMonthYear; if (shift != 0) { if (DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month != 1) { NumberOfPreviousMonthDays = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1); previuosMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);// previousMonthYear = SelectedYear; } else { NumberOfPreviousMonthDays = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear) - 1, 12); previuosMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(12);// CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);// previousMonthYear = (Convert.ToInt32(SelectedYear) - 1).ToString(); } for (int i = shift - 1; i >= 0; i--) { weekList.Add(new WeekDay { Year = previousMonthYear, Month = previuosMonth, Day = NumberOfPreviousMonthDays - i }); } for (int i = 1; i <= 7 - shift; i++) { weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i }); if (i == 7 - shift) { ReachedDayInWeeklyCalendar = weekList.Last(); StartDayInWeeklyCalendar = weekList.First(); } } LeftMonth = previuosMonth; LeftYear = previousMonthYear; RightMonth = SelectedMonth; // MonthNameTextBlock3.Text =SelectedMonth ; RightYear = selectedYear; } if (shift == 0) { for (int i = 1; i <= 7; i++) { weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i }); if (i == 7) { ReachedDayInWeeklyCalendar = weekList.Last(); StartDayInWeeklyCalendar = weekList.First(); } } LeftMonth = SelectedMonth; LeftYear = SelectedYear; RightMonth = String.Empty; RightYear = String.Empty; } } } else if (SelectedWeek == 2 || SelectedWeek == 3 || SelectedWeek == 4) { if (!stay) { if (!backward) { for (int i = ReachedDayInWeeklyCalendar.Day + 1; i <= (ReachedDayInWeeklyCalendar.Day + 7); i++) { weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i }); if (i == ReachedDayInWeeklyCalendar.Day + 7) { ReachedDayInWeeklyCalendar = weekList.Last(); StartDayInWeeklyCalendar = weekList.First(); break; } } } else //backward true { if (StartDayInWeeklyCalendar.Day - 1 != 0) { for (int i = StartDayInWeeklyCalendar.Day - 7; i <= (StartDayInWeeklyCalendar.Day - 1); i++) { weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i }); if (i == StartDayInWeeklyCalendar.Day - 1) { ReachedDayInWeeklyCalendar = weekList.Last(); StartDayInWeeklyCalendar = weekList.First(); break; } } } else { if (DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month != 1) { noOfDaysInTheSelectedMonth = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear), DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month); //SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);// //SelectedYear = SelectedYear; } else { noOfDaysInTheSelectedMonth = DateTime.DaysInMonth(Convert.ToInt32(SelectedYear) - 1, 12); //SelectedMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(12);// CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.ParseExact(SelectedMonth, "MMMM", CultureInfo.CurrentCulture).Month - 1);// //SelectedYear = (Convert.ToInt32(SelectedYear) - 1).ToString(); } for (int i = noOfDaysInTheSelectedMonth - 6; i <= (noOfDaysInTheSelectedMonth - 0); i++) { weekList.Add(new WeekDay { Year = SelectedYear, Month = SelectedMonth, Day = i }); if (i == (noOfDaysInTheSelectedMonth - 0)) { ReachedDayInWeeklyCalendar = weekList.Last(); StartDayInWeeklyCalendar = weekList.First(); break; } } } } LeftMonth = SelectedMonth; LeftYear = SelectedYear; RightMonth = String.Empty; RightYear = String.Empty; } } for (int i = 0; i < 192; i++) { OutLookEvent[] myOEvent2 = null; OutLookEvent myOEvent = null; WorkHours wh = null; Appointment app1 = null; Appointment app2 = null; Appointment app3 = null; Appointment app4 = null; Invitation inv1 = null; Invitation inv2 = null; Invitation inv3 = null; Invitation inv4 = null; if (i % 8 == 0) { dList.Add(new NameValueItem3() { timeItem = true, time = new TimeSpan(i / 8, 0, 0), Width = 1, timeStr = (new TimeSpan(i / 8, 0, 0)).ToString().Substring(0, (new TimeSpan(i / 8, 0, 0)).ToString().LastIndexOf(":")) + "_", Color1 = "#BFB5DF", Width1 = 45 }); //( new TimeSpan(i / 8, 0, 0)).ToString() } else { DateTime loopDate = new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year), DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month, weekList.ElementAt((i % 8) - 1).Day); //try //{ // // myOEvent = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy"))).ToArray().First(); // // myOEvent = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy")) && (e.start_time.TimeOfDay.Equals(new TimeSpan(i / 8, 0, 0)) || e.end_time.TimeOfDay >= (new TimeSpan(i / 8, 0, 0)))).ToArray().First(); // // myOEvent = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy")) && (new TimeSpan(e.end_time.TimeOfDay.Hours,0,0) >= (new TimeSpan(i / 8, 0, 0)) || e.isAllDay == true)).ToArray().First(); // // myOEvent = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy")) && (((new TimeSpan(e.end_time.TimeOfDay.Hours, 0, 0) > (new TimeSpan(i / 8, 0, 0))) && (new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) <= (new TimeSpan(i / 8, 0, 0)))) || e.isAllDay == true || ((new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) <= (new TimeSpan(i / 8, 0, 0)))&&(TimeSpan)(e.end_time - e.start_time) <= new TimeSpan(1, 0, 0)))).ToArray().First(); // myOEvent = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy")) && (((new TimeSpan(e.end_time.TimeOfDay.Hours, 0, 0) > (new TimeSpan(i / 8, 0, 0))) && (new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) <= (new TimeSpan(i / 8, 0, 0)))) || e.isAllDay == true || ((new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) == (new TimeSpan(i / 8, 0, 0))) && ((TimeSpan)(e.end_time - e.start_time)).Hours <= 1))).ToArray().First(); // myOEvent2 = eventList.Where(e => (e.start_time.ToString("MMMM dd, yyyy")).Equals(loopDate.ToString("MMMM dd, yyyy")) && (((new TimeSpan(e.end_time.TimeOfDay.Hours, 0, 0) > (new TimeSpan(i / 8, 0, 0))) && (new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) <= (new TimeSpan(i / 8, 0, 0)))) || e.isAllDay == true || ((new TimeSpan(e.start_time.TimeOfDay.Hours, 0, 0) == (new TimeSpan(i / 8, 0, 0))) && ((TimeSpan)(e.end_time - e.start_time)).Hours <= 1))).ToArray(); //} //catch //{ //} try { wh = whList.Where(w => ((w.From.ToString("MMMM dd, yyyy").Equals(loopDate.ToString("MMMM dd, yyyy")) && w.From.TimeOfDay.Hours <= (i / 8) && w.To.ToString("MMMM dd, yyyy").Equals(loopDate.ToString("MMMM dd, yyyy")) && w.To.TimeOfDay.Hours >= (i / 8)) || (w.From.ToString("MMMM dd, yyyy").Equals(loopDate.ToString("MMMM dd, yyyy")) && w.From.TimeOfDay.Hours <= i / 8 && w.To.Date.Equals(loopDate.AddDays(1))) || (w.From.Date.Equals(loopDate.AddDays(-1).Date) && w.To.Date.Equals(loopDate.Date) && w.To.TimeOfDay.Hours >= (i / 8)) || (w.TimeOffFrom.Date.Equals(loopDate.Date) && w.TimeOffFrom.TimeOfDay.Hours <= (i / 8) && w.TimeOffTo.TimeOfDay.Hours >= (i / 8)))).ToArray().First(); if (!String.IsNullOrEmpty(wh.TimeOffReason)) wh = null; } catch { } try { app1 = appList.Where(a => (a.Date.Date.Equals(loopDate.Date) && (a.TimeFrom.Hours == (i / 8)) && (a.TimeFrom.Minutes == 0) && (a.TimeTo.Minutes == 15))).ToList().First(); } catch { app1 = new Appointment(); // app1.Complaint = "hiii2"; } try { app2 = appList.Where(a => (a.Date.Date.Equals(loopDate.Date) && (a.TimeFrom.Hours == (i / 8)) && (a.TimeFrom.Minutes == 15) && (a.TimeTo.Minutes == 30))).ToList().First(); } catch { app2 = new Appointment(); } try { app3 = appList.Where(a => (a.Date.Date.Equals(loopDate.Date) && (a.TimeFrom.Hours == (i / 8)) && (a.TimeFrom.Minutes == 30) && (a.TimeTo.Minutes == 45))).ToList().First(); } catch { app3 = new Appointment(); } try { app4 = appList.Where(a => (a.Date.Date.Equals(loopDate.Date) && (a.TimeFrom.Hours == (i / 8)) && (a.TimeFrom.Minutes == 45) && (a.TimeTo.Minutes == 0))).ToList().First(); } catch { app4 = new Appointment(); } try { inv1 = invList.Where(a => (a.Date.Date.Equals(loopDate.Date) && (a.TimeFrom.Hours == (i / 8)) && (a.TimeFrom.Minutes == 0) && (a.TimeTo.Minutes == 15))).ToList().First(); } catch { inv1 = new Invitation(); } try { inv2 = invList.Where(a => (a.Date.Date.Equals(loopDate.Date) && (a.TimeFrom.Hours == (i / 8)) && (a.TimeFrom.Minutes == 15) && (a.TimeTo.Minutes == 30))).ToList().First(); } catch { inv2 = new Invitation(); } try { inv3 = invList.Where(a => (a.Date.Date.Equals(loopDate.Date) && (a.TimeFrom.Hours == (i / 8)) && (a.TimeFrom.Minutes == 30) && (a.TimeTo.Minutes == 45))).ToList().First(); } catch { inv3 = new Invitation(); } try { inv4 = invList.Where(a => (a.Date.Date.Equals(loopDate.Date) && (a.TimeFrom.Hours == (i / 8)) && (a.TimeFrom.Minutes == 45) && (a.TimeTo.Minutes == 0))).ToList().First(); } catch { inv4 = new Invitation(); } dList.Add(new NameValueItem3() { timeItem = false, time = new TimeSpan(i / 8, 0, 0), timeStr = null, Width = 3, weekDay = weekList.ElementAt((i % 8) - 1), Color1 = (myOEvent != null ? "Wheat" : "#BFB5DF"), myOutLookEvent = myOEvent, myOutLookEvent2 = myOEvent2, workHours = wh, Border = (myOEvent != null || wh != null ? new Thickness(1) : new Thickness(0)), //Color2 = (wh == null ? "AliceBlue" : (wh.From.TimeOfDay.Hours == 7 ? "#99FF99" : (wh.From.TimeOfDay.Hours == 15 ? "#99CCFF" : (wh.From.TimeOfDay.Hours == 23 ? "Wheat" : "AliceBlue")))), Color2 = (wh == null ? "#BFB5DF" : (wh.From.TimeOfDay.Hours == 7 ? "#A3F1A7" : (wh.From.TimeOfDay.Hours == 15 ? "#A3F1A7" : (wh.From.TimeOfDay.Hours == 23 ? "#A3F1A7" : "#BFB5DF")))), Width1 = (myOEvent == null && wh != null ? 0 : (myOEvent != null && wh != null) ? 67 : 135), Width2 = (wh != null && myOEvent == null ? 135 : (wh != null && myOEvent != null) ? 67 : 0), Appointment1 = app1, Appointment2 = app2, Appointment3 = app3, Appointment4 = app4, Invitation1 = inv1, Invitation2 = inv2, Invitation3 = inv3, Invitation4 = inv4, EnableTextBlockes = Visibility.Visible, EnableTextBlockes2 = Visibility.Visible, EnableTextBlockes3 = Visibility.Visible, EnableTextBlockes4 = Visibility.Visible, EnableTextBoxes = Visibility.Collapsed, EnableTextBoxes2 = Visibility.Collapsed, EnableTextBoxes3 = Visibility.Collapsed, EnableTextBoxes4 = Visibility.Collapsed, EnableButton = Visibility.Collapsed, EnableButton2 = Visibility.Collapsed, EnableButton3 = Visibility.Collapsed, EnableButton4 = Visibility.Collapsed, EnableDelButton = Visibility.Collapsed, EnableDelButton2 = Visibility.Collapsed, EnableDelButton3 = Visibility.Collapsed, EnableDelButton4 = Visibility.Collapsed, }); if (i > 0 || i < 8) { // if(myOEvent.isAllDay) switch (i) { case 1: Sunday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year), DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month, weekList.ElementAt((i % 8) - 1).Day) ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day; //try //{ // Sunday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null); //} //catch //{ // Sunday2.Text = String.Empty; //} break; case 2: Monday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year), DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month, weekList.ElementAt((i % 8) - 1).Day) ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day; //try //{ // Monday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null); //} //catch //{ // Monday2.Text = String.Empty; //} break; case 3: Tuesday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year), DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month, weekList.ElementAt((i % 8) - 1).Day) ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day; //try //{ // Tuesday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null); //} //catch //{ // Tuesday2.Text = String.Empty; //} break; case 4: Wednesday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year), DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month, weekList.ElementAt((i % 8) - 1).Day) ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day; //try //{ // Wednesday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null); //} //catch //{ // Wednesday2.Text = String.Empty; //} break; case 5: Thursday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year), DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month, weekList.ElementAt((i % 8) - 1).Day) ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day; //try //{ // Thursday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null); //} //catch //{ // Thursday2.Text = String.Empty; //} break; case 6: Friday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year), DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month, weekList.ElementAt((i % 8) - 1).Day) ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day; //try //{ // Friday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null); //} //catch //{ // Friday2.Text = String.Empty; //} break; case 7: Saturday.Text = (new DateTime(Convert.ToInt32(weekList.ElementAt((i % 8) - 1).Year), DateTime.ParseExact(weekList.ElementAt((i % 8) - 1).Month, "MMMM", CultureInfo.CurrentCulture).Month, weekList.ElementAt((i % 8) - 1).Day) ).DayOfWeek.ToString() + " " + weekList.ElementAt((i % 8) - 1).Day; //try //{ // Saturday2.Text = (myOEvent.isAllDay ? myOEvent.Name : null); //} //catch //{ // Saturday2.Text = String.Empty; //} break; } // weekList.ElementAt((i-1)%8) } } } flip2 = 0; backward = false; WeekGridView.ItemsSource = dList; //weekList.Clear(); stay = false; //Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => //{ // WeekGridView.ScrollIntoView(dList.ElementAt(147)); //}); myGrid.Opacity = 1; Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 2); }