public void CreateYearDays() { try { var curyear = int.Parse(CalendarClass.YearName(CalendarClass.TodayDate())); var curday = 1; var curmonth = 1; var curweekno = 1; var curweekday = CalendarClass.WeekDay(curyear + "/01/01"); var isleapyear = CalendarClass.IsLeapYear(curyear); int yeardays; if (isleapyear) { yeardays = 366; } else { yeardays = 365; } for (int i = 1; i <= yeardays; i++) { AddItem(i, curday, curmonth, CalendarClass.MonthNameByCode(curmonth), curyear, curweekday, CalendarClass.WeekDayName(curweekday), curweekno); curday++; curweekday++; if (curmonth <= 6 && curday > 31) { curmonth++; curday = 1; } if (curmonth > 6 && curday > 30) { curmonth++; curday = 1; } if (curweekday > 6) { curweekday = 0; curweekno++; } ; } } catch (Exception ex) { var er = ex.Message; } }
public CalendarDayView() { if (FixParams.FromOut && FixParams.ActiveDate != "") { _ActiveDate = FixParams.ActiveDate; _ActiveWeekDay = CalendarClass.WeekDay(FixParams.ActiveDate); FixParams.FromOut = false; FixParams.ActiveDate = ""; showbtmbar = false; } else { _ActiveDate = CalendarClass.TodayDate(); _ActiveWeekDay = CalendarClass.WeekDay(CalendarClass.TodayDate()); } MonthName.Text = CalendarClass.MonthName(_ActiveDate) + " ماه " + CalendarClass.YearName(_ActiveDate); DayNumber.Text = CalendarClass.DayNumber(_ActiveDate); DayName.Text = CalendarClass.WeekDayName(CalendarClass.WeekDay(_ActiveDate)); lblNote.Text = CalendarClass.Events(CalendarClass.DateToDateTime(_ActiveDate)); grdWeekDays = CreateWeekGrid(_ActiveDate, _ActiveWeekDay); _layout.Children.Clear(); _layout.Children.Add(DayNumber, Constraint.RelativeToParent((p) => { return(_layout.Width - (65 * FixParams.AspectRate)); }), Constraint.RelativeToParent((p) => { return(5 * FixParams.AspectRate); }), Constraint.RelativeToParent((p) => { return(60 * FixParams.AspectRate); }), Constraint.RelativeToParent((p) => { return(55 * FixParams.AspectRate); }) ); _layout.Children.Add(MonthName, Constraint.RelativeToParent((p) => { return(_layout.Width - (180 * FixParams.AspectRate)); }), Constraint.RelativeToParent((p) => { return(1 * FixParams.AspectRate); }), Constraint.RelativeToParent((p) => { return(120 * FixParams.AspectRate); }), Constraint.RelativeToParent((p) => { return(30 * FixParams.AspectRate); }) ); _layout.Children.Add(DayName, Constraint.RelativeToParent((p) => { return(_layout.Width - (180 * FixParams.AspectRate)); }), Constraint.RelativeToParent((p) => { return(25 * FixParams.AspectRate); }), Constraint.RelativeToParent((p) => { return(120 * FixParams.AspectRate); }), Constraint.RelativeToParent((p) => { return(30 * FixParams.AspectRate); }) ); _layout.Children.Add(grdWeekDays, Constraint.RelativeToParent((p) => { return(10 * FixParams.AspectRate); }), Constraint.RelativeToParent((p) => { return(DayNumber.Height); }), Constraint.RelativeToParent((p) => { return(_layout.Width - (20 * FixParams.AspectRate)); }), Constraint.RelativeToParent((p) => { return(75 * FixParams.AspectRate); }) ); grdPryingTimes = CreatePryingTimeGrid(_ActiveDate); _layout.Children.Add(grdPryingTimes, Constraint.RelativeToParent((p) => { return(10 * FixParams.AspectRate); }), Constraint.RelativeToParent((p) => { return(_layout.Height - (100 * FixParams.AspectRate)); }), Constraint.RelativeToParent((p) => { return(_layout.Width - (20 * FixParams.AspectRate)); }), Constraint.RelativeToParent((p) => { return(50 * FixParams.AspectRate); }) ); _layout.Children.Add(ButtomLayout, Constraint.RelativeToParent((p) => { return(0); }), Constraint.RelativeToParent((p) => { return(_layout.Height - (40 * FixParams.AspectRate)); }), Constraint.RelativeToParent((p) => { return(_layout.Width); }), Constraint.RelativeToParent((p) => { return(40 * FixParams.AspectRate); }) ); Button btnGotoWeekView = new Button() { BackgroundColor = FixParams.PanelColor, Text = "هفته", FontSize = FixParams.StandardSize, TextColor = FixParams.FontColor, HeightRequest = 40 * FixParams.AspectRate, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.StartAndExpand, }; btnGotoWeekView.Clicked += OnWeekClicked; if (showbtmbar) { ButtomLayout.Children.Insert(0, btnGotoWeekView); } CreatePanel(_layout, _ActiveDate); Task.Run(() => { CalendarMenu cm = new CalendarMenu(); cm.CreateYearDays(); App.YearDays = cm.CalendarDataList; cm.CreateWeekLayout(App.YearDays); App.GridOfWeeks = cm.GridList; wv = new CalendarWeekView(); }); Content = _layout; }
public Grid CreateCalendar(int ActiveYear, int ActiveMonth) { var today = CalendarClass.DayNumber(CalendarClass.TodayDate()); var grdCalendar = new Grid(); var fmDay = CalendarClass.WeekDay(ActiveYear.ToString() + "/" + CalendarClass.FullMonthCode(ActiveMonth.ToString()) + "/" + "01"); var is6col = ((fmDay == 5 || fmDay == 6) && ActiveMonth <= 6) || (fmDay == 6 && ActiveMonth > 6); int maxcol = 0; grdCalendar.ColumnSpacing = 2 * FixParams.AspectRate; grdCalendar.RowSpacing = 2 * FixParams.AspectRate; grdCalendar.BackgroundColor = FixParams.PanelColor; grdCalendar.RowDefinitions.Add(new RowDefinition() { Height = 50 * FixParams.AspectRate }); grdCalendar.RowDefinitions.Add(new RowDefinition() { Height = 50 * FixParams.AspectRate }); grdCalendar.RowDefinitions.Add(new RowDefinition() { Height = 50 * FixParams.AspectRate }); grdCalendar.RowDefinitions.Add(new RowDefinition() { Height = 50 * FixParams.AspectRate }); grdCalendar.RowDefinitions.Add(new RowDefinition() { Height = 50 * FixParams.AspectRate }); grdCalendar.RowDefinitions.Add(new RowDefinition() { Height = 50 * FixParams.AspectRate }); grdCalendar.RowDefinitions.Add(new RowDefinition() { Height = 50 * FixParams.AspectRate }); if (is6col) { maxcol = 6; grdCalendar.ColumnDefinitions.Add(new ColumnDefinition()); grdCalendar.ColumnDefinitions.Add(new ColumnDefinition()); grdCalendar.ColumnDefinitions.Add(new ColumnDefinition()); grdCalendar.ColumnDefinitions.Add(new ColumnDefinition()); grdCalendar.ColumnDefinitions.Add(new ColumnDefinition()); grdCalendar.ColumnDefinitions.Add(new ColumnDefinition()); grdCalendar.ColumnDefinitions.Add(new ColumnDefinition { Width = 60 * FixParams.AspectRate }); } else { maxcol = 5; grdCalendar.ColumnDefinitions.Add(new ColumnDefinition()); grdCalendar.ColumnDefinitions.Add(new ColumnDefinition()); grdCalendar.ColumnDefinitions.Add(new ColumnDefinition()); grdCalendar.ColumnDefinitions.Add(new ColumnDefinition()); grdCalendar.ColumnDefinitions.Add(new ColumnDefinition()); grdCalendar.ColumnDefinitions.Add(new ColumnDefinition { Width = 60 * FixParams.AspectRate }); } for (int k = 0; k < 7; k++) { grdCalendar.Children.Add(new Label { Text = "", BackgroundColor = FixParams.SpecFontColor }, 0, k); grdCalendar.Children.Add(new Label { Text = "", BackgroundColor = FixParams.SpecFontColor }, maxcol - 1, k); } for (int j = fmDay; j <= fmDay + 30; j++) { var row = j % 7; int col = 0; if (is6col) { if (j < 7 && j >= 0) { col = 5; } if (j < 14 && j >= 7) { col = 4; } if (j < 21 && j >= 14) { col = 3; } if (j < 28 && j >= 21) { col = 2; } if (j < 35 && j >= 28) { col = 1; } if (j < 42 && j >= 35) { col = 0; } } else { if (j < 7 && j >= 0) { col = 4; } if (j < 14 && j >= 7) { col = 3; } if (j < 21 && j >= 14) { col = 2; } if (j < 28 && j >= 21) { col = 1; } if (j < 35 && j >= 28) { col = 0; } } Color rc = new Color(); if (row < 6) { rc = FixParams.FontColor; } else { rc = FixParams.AlterFontColor; } if (ActiveMonth < 7 && ActiveMonth > 0) { if (j - fmDay <= 30) { Label lblDay = new Label() { XAlign = TextAlignment.Center, YAlign = TextAlignment.Center, TextColor = rc, BackgroundColor = FixParams.BackgroundColor, Text = (j - fmDay + 1).ToString(), FontSize = FixParams.SmallSize }; var DayNumber = lblDay.Text; if (int.Parse(lblDay.Text) < 10) { DayNumber = "0" + DayNumber; } var _Today = ActiveYear.ToString() + "/" + CalendarClass.FullMonthCode(ActiveMonth.ToString()) + "/" + DayNumber; if (CalendarClass.IsHolyDay(CalendarClass.DateToDateTime(_Today))) { lblDay.TextColor = FixParams.AlterFontColor; } lblDay.GestureRecognizers. Add(new TapGestureRecognizer { Command = new Command(async() => { FixParams.FromOut = true; FixParams.ActiveDate = _Today; await Navigation.PushAsync(new CalendarDayView()); }), NumberOfTapsRequired = 1 }); grdCalendar.Children.Add(lblDay, col, row); } } if (ActiveMonth < 12 && ActiveMonth >= 7) { if (j - fmDay <= 29) { Label lblDay = new Label() { XAlign = TextAlignment.Center, YAlign = TextAlignment.Center, TextColor = rc, BackgroundColor = FixParams.BackgroundColor, Text = (j - fmDay + 1).ToString(), FontSize = FixParams.SmallSize }; var DayNumber = lblDay.Text; if (int.Parse(lblDay.Text) < 10) { DayNumber = "0" + DayNumber; } var _Today = ActiveYear.ToString() + "/" + CalendarClass.FullMonthCode(ActiveMonth.ToString()) + "/" + DayNumber; if (CalendarClass.IsHolyDay(CalendarClass.DateToDateTime(_Today))) { lblDay.TextColor = FixParams.AlterFontColor; } lblDay.GestureRecognizers. Add(new TapGestureRecognizer { Command = new Command(async() => { FixParams.FromOut = true; FixParams.ActiveDate = _Today; await Navigation.PushAsync(new CalendarDayView()); }), NumberOfTapsRequired = 1 }); grdCalendar.Children.Add(lblDay, col, row); } } if (ActiveMonth == 12) { if ((j - fmDay <= 29 && CalendarClass.IsLeapYear(ActiveYear)) || (j - fmDay <= 28 && !CalendarClass.IsLeapYear(ActiveYear))) { Label lblDay = new Label() { XAlign = TextAlignment.Center, YAlign = TextAlignment.Center, TextColor = rc, BackgroundColor = FixParams.BackgroundColor, Text = (j - fmDay + 1).ToString(), FontSize = FixParams.SmallSize }; var DayNumber = lblDay.Text; if (int.Parse(lblDay.Text) < 10) { DayNumber = "0" + DayNumber; } var _Today = ActiveYear.ToString() + "/" + CalendarClass.FullMonthCode(ActiveMonth.ToString()) + "/" + DayNumber; if (CalendarClass.IsHolyDay(CalendarClass.DateToDateTime(_Today))) { lblDay.TextColor = FixParams.AlterFontColor; } lblDay.GestureRecognizers. Add(new TapGestureRecognizer { Command = new Command(async() => { FixParams.FromOut = true; FixParams.ActiveDate = _Today; await Navigation.PushAsync(new CalendarDayView()); }), NumberOfTapsRequired = 1 }); grdCalendar.Children.Add(lblDay, col, row); } } } for (int i = 0; i < 7; i++) { grdCalendar.Children.Add(new Label { TextColor = FixParams.AlterFontColor, BackgroundColor = FixParams.PanelColor, Text = " " + CalendarClass.DayNames[i], HeightRequest = 30 * FixParams.AspectRate, FontSize = FixParams.StandardSize, XAlign = TextAlignment.End, YAlign = TextAlignment.Center }, maxcol, i); } return(grdCalendar); }