public static int ActiveWeekOfYear(string ActiveDate) { CultureInfo CI = new CultureInfo("fa-Ir"); var Cal = CI.Calendar; CalendarWeekRule CWR = CI.DateTimeFormat.CalendarWeekRule; DayOfWeek FirstDOW = CI.DateTimeFormat.FirstDayOfWeek; int FirstWeek = Cal.GetWeekOfYear(DateToDateTime(CalendarClass.YearName(ActiveDate) + "/01/01"), CWR, FirstDOW); int week = Cal.GetWeekOfYear(DateToDateTime(ActiveDate), CWR, FirstDOW); return(week - FirstWeek); }
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 Grid CreateWeekGrid(string ActiveDate, int ActiveWeekDay) { int ActiveDay = int.Parse(CalendarClass.DayNumber(ActiveDate)); var grdTemp = new Grid(); grdTemp.RowDefinitions.Add(new RowDefinition { Height = 30 * FixParams.AspectRate }); grdTemp.RowDefinitions.Add(new RowDefinition { Height = 40 * FixParams.AspectRate }); grdTemp.RowSpacing = 0; grdTemp.ColumnSpacing = 2 * FixParams.AspectRate; grdTemp.Padding = 2 * FixParams.AspectRate; grdTemp.BackgroundColor = FixParams.PanelColor; for (int i = 0; i < 7; i++) { grdTemp.Children.Add(new Label { TextColor = FixParams.AlterFontColor, BackgroundColor = FixParams.PanelColor, Text = " " + CalendarClass.ShortDayNames[6 - i], XAlign = TextAlignment.Center, YAlign = TextAlignment.Center, FontSize = FixParams.StandardSize }, i, 0); var clr = new Color(); if (ActiveWeekDay == i) { clr = FixParams.SpecFontColor; } else { clr = FixParams.FontColor; } var lblDayNum = new MyLabel { TextColor = clr, BackgroundColor = FixParams.BackgroundColor, Text = " " + CalendarClass.DayNumber(CalendarClass.AddDayToDate(ActiveDate, i - ActiveWeekDay).ToString()), XAlign = TextAlignment.Center, YAlign = TextAlignment.Center, FontSize = FixParams.MediumSize, Property1 = i.ToString(), Property2 = CalendarClass.AddDayToDate(ActiveDate, i - ActiveWeekDay).ToString() }; if (CalendarClass.IsHolyDay(CalendarClass.DateToDateTime(lblDayNum.Property2))) { lblDayNum.TextColor = FixParams.AlterFontColor; } if (i == 6) { lblDayNum.TextColor = FixParams.AlterFontColor; } lblDayNum.GestureRecognizers.Add(new TapGestureRecognizer { Command = new Command(() => { _ActiveDate = lblDayNum.Property2; _ActiveWeekDay = int.Parse(lblDayNum.Property1); DayNumber.Text = lblDayNum.Text; DayName.Text = CalendarClass.WeekDayName(_ActiveWeekDay); MonthName.Text = CalendarClass.MonthName(_ActiveDate) + " ماه " + CalendarClass.YearName(_ActiveDate); grdWeekDays = CreateWeekGrid(_ActiveDate, _ActiveWeekDay); Animateview(_pnlDayNote, 400); _layout.Children.Remove(DayNumber); _layout.Children.Remove(DayName); _layout.Children.Remove(MonthName); _layout.Children.Remove(grdWeekDays); _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); }) ); for (int j = 11; j >= 6; j--) { grdPryingTimes.Children.RemoveAt(j); } prayer _prayer = new prayer(); _prayer.UpdatePryTimes(_ActiveDate); grdPryingTimes.Children.Add(new Label { FontSize = FixParams.SmallSize, Text = prayer._MP, XAlign = TextAlignment.Center, YAlign = TextAlignment.Center, TextColor = FixParams.FontColor, BackgroundColor = FixParams.BackgroundColor }, 5, 1); grdPryingTimes.Children.Add(new Label { FontSize = FixParams.SmallSize, Text = prayer._SR, XAlign = TextAlignment.Center, YAlign = TextAlignment.Center, TextColor = FixParams.FontColor, BackgroundColor = FixParams.BackgroundColor }, 4, 1); grdPryingTimes.Children.Add(new Label { FontSize = FixParams.SmallSize, Text = prayer._MD, XAlign = TextAlignment.Center, YAlign = TextAlignment.Center, TextColor = FixParams.FontColor, BackgroundColor = FixParams.BackgroundColor }, 3, 1); grdPryingTimes.Children.Add(new Label { FontSize = FixParams.SmallSize, Text = prayer._SS, XAlign = TextAlignment.Center, YAlign = TextAlignment.Center, TextColor = FixParams.FontColor, BackgroundColor = FixParams.BackgroundColor }, 2, 1); grdPryingTimes.Children.Add(new Label { FontSize = FixParams.SmallSize, Text = prayer._NP, XAlign = TextAlignment.Center, YAlign = TextAlignment.Center, TextColor = FixParams.FontColor, BackgroundColor = FixParams.BackgroundColor }, 1, 1); grdPryingTimes.Children.Add(new Label { FontSize = FixParams.SmallSize, Text = prayer._MN, XAlign = TextAlignment.Center, YAlign = TextAlignment.Center, TextColor = FixParams.FontColor, BackgroundColor = FixParams.BackgroundColor }, 0, 1); _pnlDayNote.Children.Clear(); lblNote.Text = CalendarClass.Events(CalendarClass.DateToDateTime(_ActiveDate)); if (CalendarClass.IsHolyDay(CalendarClass.DateToDateTime(_ActiveDate))) { lblNote.TextColor = FixParams.AlterFontColor; } _pnlDayNote.Children.Add(lblNote); }), NumberOfTapsRequired = 1 }); grdTemp.Children.Add(lblDayNum, 6 - i, 1); } return(grdTemp); }
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; }
protected override ContentPage CreateDefault(object item) { var currentInt = (int)item; Label MonthName = new Label { TextColor = FixParams.FontColor, Text = CalendarClass.MonthNameByCode(currentInt) + " ماه " + CalendarClass.YearName("1394/01/01"), XAlign = TextAlignment.Center, YAlign = TextAlignment.Center, FontSize = FixParams.MediumSize }; Grid grdCalendar = new Grid(); StackLayout layout = new StackLayout() { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, BackgroundColor = FixParams.PanelColor, Padding = 2 * FixParams.AspectRate }; grdCalendar = CreateCalendar(1394, currentInt); layout.Children.Add(MonthName); layout.Children.Add(grdCalendar); _ActiveDate = "1394/" + CalendarClass.FullMonthCode((currentInt - 1).ToString()) + "/05"; Button btnGotoWeekView = new Button() { BackgroundColor = FixParams.PanelColor, Text = "هفته", FontSize = FixParams.StandardSize, TextColor = FixParams.FontColor, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.StartAndExpand, }; Button btnGotoYearView = new Button() { BackgroundColor = FixParams.PanelColor, Text = "سال", FontSize = FixParams.StandardSize, TextColor = FixParams.FontColor, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.EndAndExpand, }; btnGotoWeekView.Clicked += OnWeekClicked; StackLayout ButtomLayout = new StackLayout { Children = { btnGotoWeekView, btnGotoYearView }, Orientation = StackOrientation.Horizontal, BackgroundColor = FixParams.PanelColor, VerticalOptions = LayoutOptions.EndAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, }; Entry PerisianDate = new Entry { Text = _ActiveDate, TextColor = FixParams.FontColor, BackgroundColor = FixParams.BackgroundColor }; Image btnCalendar = new Image { Source = ImageSource.FromFile("Calendar.png"), HeightRequest = 40, WidthRequest = 40, }; Label lblPersianDate = new Label { Text = "تاریخ جلالی", FontSize = FixParams.SmallSize, TextColor = FixParams.FontColor }; var grdPersianDate = new Grid(); grdPersianDate.RowDefinitions.Add(new RowDefinition()); grdPersianDate.ColumnDefinitions.Add(new ColumnDefinition { Width = 40 }); grdPersianDate.ColumnDefinitions.Add(new ColumnDefinition()); grdPersianDate.ColumnDefinitions.Add(new ColumnDefinition() { Width = 50 }); grdPersianDate.Children.Add(lblPersianDate, 2, 0); grdPersianDate.Children.Add(PerisianDate, 1, 0); grdPersianDate.Children.Add(btnCalendar, 0, 0); StackLayout ConvertLayout = new StackLayout { Children = { new StackLayout { Children = { new BoxView() { Color = FixParams.AlterFontColor, HeightRequest = 1 }, grdPersianDate, new BoxView() { Color = FixParams.AlterFontColor, HeightRequest = 1 }, }, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, }, }, Orientation = StackOrientation.Horizontal, BackgroundColor = FixParams.PanelColor, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, }; layout.Children.Add(ButtomLayout); return(new ContentPage { Content = layout }); }