Пример #1
0
        private void EditorView_TouchUpInside(object sender, EventArgs e)
        {
            scheduleEditor.Editor.Hidden = false;
            schedule.Hidden   = true;
            headerView.Hidden = true;
            tableView.Hidden  = true;

            NSDate     today    = new NSDate();
            NSCalendar calendar = NSCalendar.CurrentCalendar;
            // Get the year, month, day from the date
            NSDateComponents components = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);
            NSDate startDate = calendar.DateFromComponents(components);

            scheduleEditor.label_subject.Text  = "Subject";
            scheduleEditor.label_location.Text = "Location";
            String _sDate = DateTime.Parse((startDate.ToString())).ToString();

            scheduleEditor.picker_startDate.SetDate(startDate, true);
            scheduleEditor.button_startDate.SetTitle(_sDate, UIControlState.Normal);
            String _eDate = DateTime.Parse((startDate.AddSeconds(3600).ToString())).ToString();

            scheduleEditor.picker_endDate.SetDate(startDate.AddSeconds(3600), true);
            scheduleEditor.button_endDate.SetTitle(_eDate, UIControlState.Normal);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            commonHelper = new CommonHelper();
            this.NavigationItem.Title = "Last Worn Date";

            // create next button
            nextButton = new UIBarButtonItem("Other Details", UIBarButtonItemStyle.Plain, NextButtonClickAction);
            NavigationItem.SetRightBarButtonItem(nextButton, true);

            // create previous button
            prevButton = new UIBarButtonItem("ItemType", UIBarButtonItemStyle.Plain, PrevButtonClickAction);
            NavigationItem.SetLeftBarButtonItem(prevButton, true);


            var calendar    = new NSCalendar(NSCalendarType.Gregorian);
            var currentDate = NSDate.Now;
            var components  = new NSDateComponents();

            components.Year = -60;

            NSDate minDate = calendar.DateByAddingComponents(components, NSDate.Now, NSCalendarOptions.None);

            Console.WriteLine("ViewDidLoad, before AddScreenLayout wardrobeObj" + wardrobeObj.ItemType);



            AddScreenLayout();
        }
Пример #3
0
        public static int _getDayOfWeekWithDate(NSDate date)
        {
            var gregorian         = new NSCalendar(NSCalendarType.Gregorian);
            var weekDayComponents = gregorian.Components(NSCalendarUnit.Weekday, date);

            return((int)weekDayComponents.Weekday);
        }
Пример #4
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            NSCalendar calendar = new NSCalendar(NSCalendarType.Gregorian);

            calendar.FirstWeekDay = 2;
            NSDate           date       = NSDate.Now;
            NSDateComponents components = new NSDateComponents();

            components.Year = -10;
            NSDate minDate = calendar.DateByAddingComponents(components, date, (NSCalendarOptions)0);

            components.Year = 10;
            NSDate maxDate = calendar.DateByAddingComponents(components, date, (NSCalendarOptions)0);

            this.CalendarView = new TKCalendar(this.View.Bounds);
            this.CalendarView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            this.View.AddSubview(this.CalendarView);

            this.CalendarView.Delegate = new CalendarDelegate(this);
            this.CalendarView.ViewMode = TKCalendarViewMode.Year;
            this.CalendarView.Calendar = calendar;
            this.CalendarView.MinDate  = minDate;
            this.CalendarView.MaxDate  = maxDate;
            this.CalendarView.NavigateToDate(date, false);
        }
Пример #5
0
        public override void ViewDidLoad()
        {
            this.AddOption ("Year", SelectYear);
            this.AddOption ("Month", SelectMonth);
            this.AddOption ("Month Names", SelectMonthNames);
            this.AddOption ("Year Numbers", SelectYearNumbers);
            this.AddOption ("Flow", SelectFlow);
            this.AddOption ("Week view", SelectWeekView);

            base.ViewDidLoad ();

            NSCalendar calendar = new NSCalendar (NSCalendarType.Gregorian);
            calendar.FirstWeekDay = 2;
            NSDate date = NSDate.Now;
            NSDateComponents components = new NSDateComponents ();
            components.Year = -10;
            NSDate minDate = calendar.DateByAddingComponents (components, date, (NSCalendarOptions)0);
            components.Year = 10;
            NSDate maxDate = calendar.DateByAddingComponents (components, date, (NSCalendarOptions)0);

            this.CalendarView = new TKCalendar (this.View.Bounds);
            this.CalendarView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            this.View.AddSubview (this.CalendarView);

            this.calendarDelegate = new CalendarDelegate(this);

            this.CalendarView.Delegate = calendarDelegate;
            this.CalendarView.ViewMode = TKCalendarViewMode.Year;
            this.CalendarView.Calendar = calendar;
            this.CalendarView.MinDate = minDate;
            this.CalendarView.MaxDate = maxDate;
            this.CalendarView.NavigateToDate (date, false);
        }
Пример #6
0
        static void Main(string[] args)
        {
            NSApplication.Init();

            NSDate           now            = NSDate.Now;
            DateTime         cNow           = DateTime.UtcNow;
            NSCalendar       cal            = NSCalendar.CurrentCalendar;
            NSDateComponents weekComponents = new NSDateComponents();

            List <LotteryEntry> entries = new List <LotteryEntry>();

            for (int i = 0; i < 10; i++)
            {
                weekComponents.Week = i;
                NSDate iWeeksFromNow = cal.DateByAddingComponents(weekComponents, now, NSCalendarOptions.None);

                DateTime cWeeksFromNow = cNow.AddDays(i * 7);

                LotteryEntry newEntry = new LotteryEntry(iWeeksFromNow, cWeeksFromNow);
                entries.Add(newEntry);
            }

            foreach (LotteryEntry entry in entries)
            {
                Debug.WriteLine("{0}", entry);
            }

            NSApplication.Main(args);
        }
Пример #7
0
        public void GetAllCalendarIdentifiers()
        {
            RequiresIos8();

            foreach (NSCalendarType t in Enum.GetValues(typeof(NSCalendarType)))
            {
                switch (t)
                {
                case NSCalendarType.IslamicTabular:
                case NSCalendarType.IslamicUmmAlQura:
#if __MACOS__
                    if (!TestRuntime.CheckSystemVersion(PlatformName.MacOSX, 10, 10))
                    {
                        continue;
                    }
#else
                    if (!TestRuntime.CheckXcodeVersion(6, 0))
                    {
                        continue;
                    }
#endif
                    break;
                }
                NSCalendar c = new NSCalendar(t);
                Assert.IsNotNull(c.Identifier, "Can't find identifier: " + t.ToString());
            }
        }
        public CalendarBlackoutDates()
        {
            //Calendar
            calendar1              = new SFCalendar();
            calendar1.ViewMode     = SFCalendarViewMode.SFCalendarViewModeMonth;
            calendar1.HeaderHeight = 40;
            this.AddSubview(calendar1);

            //Setting BlackOutDates
            NSDate     today    = new NSDate();
            NSCalendar calendar = NSCalendar.CurrentCalendar;
            // Get the year, month, day from the date
            NSDateComponents components = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second

            calendar1.BlackoutDates = new NSMutableArray();

            for (int i = 0; i < 5; i++)
            {
                NSDate startDate = calendar.DateFromComponents(components);
                components.Day += 1;
                calendar1.BlackoutDates.Add(startDate);
            }

            appView = new UITableView();
            appView.RegisterClassForCellReuse(typeof(UITableViewCell), "Cell");
            if ((UIDevice.CurrentDevice).UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
            {
                calendarView.AddSubview(calendar1);
                this.AddSubview(calendarView);
            }
            this.AddSubview(appView);
        }
Пример #9
0
        private void CalendarDrawMonthCell(object sender, DrawMonthCellEventArgs e)
        {
            NSCalendar date  = NSCalendar.CurrentCalendar;
            NSDate     today = new NSDate();

            NSDateComponents monthCellDateComponents = date.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, e.MonthCell.Date);
            NSDateComponents todayDateComponents = date.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            UIButton button = new UIButton();

            button.SetTitle(monthCellDateComponents.Day.ToString(), UIControlState.Normal);
            button.SetTitleColor(UIColor.Black, UIControlState.Normal);

            if (e.MonthCell.IsCurrentMonth)
            {
                if (monthCellDateComponents.Day == todayDateComponents.Day && monthCellDateComponents.Month == todayDateComponents.Month && monthCellDateComponents.Year == todayDateComponents.Year)
                {
                    //// customized paricular date by setting differernt background color
                    button.BackgroundColor = UIColor.Red;
                }
                else
                {
                    button.BackgroundColor = UIColor.LightGray;
                }

                e.MonthCell.View = button;
            }
        }
Пример #10
0
        private void UpdatMinMaxYears()
        {
            if (_picker == null)
            {
                return;
            }

            var calendar = new NSCalendar(NSCalendarType.Gregorian);
            var maximumDateComponents = new NSDateComponents
            {
                Day   = MaxYear.Day,
                Month = MaxYear.Month,
                Year  = MaxYear.Year
            };

            _picker.MaximumDate = calendar.DateFromComponents(maximumDateComponents);

            var minimumDateComponents = new NSDateComponents
            {
                Day   = MinYear.Day,
                Month = MinYear.Month,
                Year  = MinYear.Year
            };

            _picker.MinimumDate = calendar.DateFromComponents(minimumDateComponents);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            this.CurrentFrame = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Size.Width, UIScreen.MainScreen.Bounds.Size.Height);
            this.AddButton();
            //Creating an instance for SfSchedule control
            SFSchedule schedule = new SFSchedule();

            schedule.Frame        = new CGRect(0, removeExceptionAppointment.Frame.Bottom, this.CurrentFrame.Size.Width, this.CurrentFrame.Size.Height - removeExceptionAppointment.Frame.Bottom);
            schedule.ScheduleView = SFScheduleView.SFScheduleViewWeek;

            NSCalendar calendar = new NSCalendar(NSCalendarType.Gregorian);
            NSDate     today    = NSDate.Now;
            // Get the year, month, day from the date
            NSDateComponents startDateComponents = calendar.Components(NSCalendarUnit.Year |
                                                                       NSCalendarUnit.Month |
                                                                       NSCalendarUnit.Day, today);

            // Set the year, month, day, hour, minute, second
            startDateComponents.Year   = 2017;
            startDateComponents.Month  = 09;
            startDateComponents.Day    = 03;
            startDateComponents.Hour   = 10;
            startDateComponents.Minute = 0;
            startDateComponents.Second = 0;

            //setting start time for the event
            NSDate startDate = calendar.DateFromComponents(startDateComponents);

            //setting end time for the event
            NSDate endDate = startDate.AddSeconds(2 * 60 * 60);

            // set moveto date to schedule
            schedule.MoveToDate(startDate);

            // Set the exception dates.
            var exceptionDate1 = startDate;
            var exceptionDate2 = startDate.AddSeconds(2 * 24 * 60 * 60);

            exceptionDate3 = startDate.AddSeconds(4 * 24 * 60 * 60);

            // Add Schedule appointment
            ScheduleAppointment recurrenceAppointment = new ScheduleAppointment();

            recurrenceAppointment.Id                       = 1;
            recurrenceAppointment.StartTime                = startDate;
            recurrenceAppointment.EndTime                  = endDate;
            recurrenceAppointment.Subject                  = (NSString)"Occurs Daily";
            recurrenceAppointment.AppointmentBackground    = UIColor.Blue;
            recurrenceAppointment.RecurrenceRule           = (NSString)"FREQ=DAILY;COUNT=20";
            recurrenceAppointment.RecurrenceExceptionDates = new System.Collections.ObjectModel.ObservableCollection <NSDate> {
                exceptionDate1,
                exceptionDate2,
                exceptionDate3
            };

            scheduleAppointmentCollection.Add(recurrenceAppointment);
            schedule.ItemsSource = scheduleAppointmentCollection;
            this.View.AddSubview(schedule);
        }
Пример #12
0
        public static DateTime NSDateToDateTime(NSDate date)
        {
            var calendar   = new NSCalendar(NSCalendarType.Gregorian);
            var components = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day | NSCalendarUnit.Hour | NSCalendarUnit.Minute | NSCalendarUnit.Second, date);

            return(new DateTime((int)components.Year, (int)components.Month, (int)components.Day, (int)components.Hour, (int)components.Minute, (int)components.Second));
        }
Пример #13
0
        private void EditorView_TouchUpInside(object sender, EventArgs e)
        {
            ScheduleEditor.Editor.Hidden = false;
            Schedule.Hidden   = true;
            HeaderView.Hidden = true;
            TableView.Hidden  = true;

            NSDate     today    = new NSDate();
            NSCalendar calendar = NSCalendar.CurrentCalendar;

            // Get the year, month, day from the date
            NSDateComponents components = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);
            NSDate startDate = calendar.DateFromComponents(components);

            ScheduleEditor.LabelSubject.Text  = "Subject";
            ScheduleEditor.LabelLocation.Text = "Location";
            String startDate1 = DateTime.Parse(startDate.ToString()).ToString();

            ScheduleEditor.PickerStartDate.SetDate(startDate, true);
            ScheduleEditor.ButtonStartDate.SetTitle(startDate1, UIControlState.Normal);
            String endDate = DateTime.Parse(startDate.AddSeconds(3600).ToString()).ToString();

            ScheduleEditor.PickerEndDate.SetDate(startDate.AddSeconds(3600), true);
            ScheduleEditor.ButtonEndDate.SetTitle(endDate, UIControlState.Normal);
        }
Пример #14
0
        private void SetMonthSettings()
        {
            monthSettings = new MonthViewSettings();

            NSDate     today    = new NSDate();
            NSCalendar calendar = NSCalendar.CurrentCalendar;

            // Get the year, month, day from the date
            NSDateComponents components = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            schedule.MonthViewSettings  = monthSettings;
            monthSettings.BlackoutDates = new NSMutableArray();
            if (switchBlackOutDates != null && switchBlackOutDates.On)
            {
                components.Day -= 3;
                for (int i = 0; i < 3; i++)
                {
                    NSDate startDate = calendar.DateFromComponents(components);
                    components.Day += 1;
                    schedule.MonthViewSettings.BlackoutDates.Add(startDate);
                }
            }

            if (switchWeekNumber != null && switchWeekNumber.On)
            {
                schedule.MonthViewSettings.ShowWeekNumber = true;
            }
            else
            {
                schedule.MonthViewSettings.ShowWeekNumber = false;
            }
        }
Пример #15
0
		List<WeatherModel> addPopulationData()
		{
			List<WeatherModel> array = new List<WeatherModel>();

			NSDate now = NSDate.Now;


			string[] imagesArray = new string[] { "Cloudy.png", "Humid.png", "Rainy.png", "Warm.png", "Windy.png", "Cloudy.png", "Humid.png" };
			for (int i = 0; i < 7; i++)
			{
				int daysToAdd = i;
				NSDateComponents components = new NSDateComponents();
				components.Day = daysToAdd;

				NSCalendar gregorian =  NSCalendar.CurrentCalendar;

				NSDate newDate2 = gregorian.DateByAddingComponents(components, now, NSCalendarOptions.None);
				NSDateFormatter dateFormatter = new NSDateFormatter();
				dateFormatter.DateFormat = "EEEE, MMMM dd";

				NSDateFormatter dateFormatter1 = new NSDateFormatter();
				dateFormatter1.DateFormat = "EEEE";
				array.Add(new WeatherModel((NSString)dateFormatter.StringFor(newDate2), (NSString)imagesArray[i], (NSString)new Random().Next(10, 40).ToString(), (NSString)dateFormatter1.StringFor(newDate2)));
			}

			return array;
		}
Пример #16
0
        private ObservableCollection <ScheduleAppointment> CreateAppointments()
        {
            NSDate     today    = new NSDate();
            NSCalendar calendar = NSCalendar.CurrentCalendar;

            // Get the year, month, day from the date
            NSDateComponents components = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            components.Hour   = 10;
            components.Minute = 0;
            components.Second = 0;
            NSDate startDate = calendar.DateFromComponents(components);

            // Get the year, month, day from the date
            NSDateComponents endDateComponents = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            endDateComponents.Hour   = 12;
            endDateComponents.Minute = 0;
            endDateComponents.Second = 0;
            NSDate endDate = calendar.DateFromComponents(endDateComponents);
            ScheduleAppointment appointment = new ScheduleAppointment();

            appointment.StartTime             = startDate;
            appointment.EndTime               = endDate;
            appointment.Subject               = new NSString("Jeni's B'Day Celebration");
            appointment.AppointmentBackground = UIColor.FromRGB(0xA2, 0xC1, 0x39);
            NSDateComponents components1 = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            components1.Hour   = 11;
            components1.Minute = 0;
            components1.Second = 0;
            components1.Day    = components1.Day + 1;
            NSDate startDate1 = calendar.DateFromComponents(components1);

            // Get the year, month, day from the date
            NSDateComponents endDateComponents1 = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            endDateComponents1.Hour   = 13;
            endDateComponents1.Minute = 30;
            endDateComponents1.Second = 0;
            endDateComponents1.Day    = endDateComponents1.Day + 1;
            NSDate endDate1 = calendar.DateFromComponents(endDateComponents1);
            ScheduleAppointment appointment1 = new ScheduleAppointment();

            appointment1.StartTime             = startDate1;
            appointment1.EndTime               = endDate1;
            appointment1.Subject               = new NSString("Checkup");
            appointment1.AppointmentBackground = UIColor.FromRGB(0xD8, 0x00, 0x73);
            ObservableCollection <ScheduleAppointment> appCollection = new ObservableCollection <ScheduleAppointment>();

            appCollection.Add(appointment);
            appCollection.Add(appointment1);
            return(appCollection);
        }
Пример #17
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
// >> getting-started-calendar-cs
            TKCalendar calendarView = new TKCalendar(this.View.Bounds);

            calendarView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            this.View.AddSubview(calendarView);
// << getting-started-calendar-cs

            calendarDelegate = new CalendarDelegate();

// >> getting-started-assigndatasource-cs
            calendarView.DataSource = new CalendarDataSource(this);
// << getting-started-assigndatasource-cs

// >> getting-started-event-cs
            events = new List <TKCalendarEvent> ();
            NSCalendar calendar = new NSCalendar(NSCalendarType.Gregorian);
            NSDate     date     = NSDate.Now;

            Random r = new Random();

            for (int i = 0; i < 3; i++)
            {
                TKCalendarEvent ev = new TKCalendarEvent();
                ev.Title = "Sample event";
                NSDateComponents components = calendar.Components(NSCalendarUnit.Day | NSCalendarUnit.Month | NSCalendarUnit.Year, date);
                components.Day = r.Next() % 20;
                ev.StartDate   = calendar.DateFromComponents(components);
                ev.EndDate     = calendar.DateFromComponents(components);
                ev.EventColor  = UIColor.Red;
                events.Add(ev);
            }
// << getting-started-event-cs

// >> getting-started-minmaxdate-cs
            calendarView.MinDate = TKCalendar.DateWithYear(2010, 1, 1, calendar);
            calendarView.MaxDate = TKCalendar.DateWithYear(2016, 12, 31, calendar);
// << getting-started-minmaxdate-cs

//			calendarDelegate.events = this.events;
            calendarView.Delegate = calendarDelegate;

// >> getting-started-navigatetodate-cs
            NSDateComponents newComponents = new NSDateComponents();

            newComponents.Year  = 2015;
            newComponents.Month = 5;
            newComponents.Day   = 1;
            NSDate newDate = calendarView.Calendar.DateFromComponents(newComponents);

// >> navigation-navigate-cs
            calendarView.NavigateToDate(newDate, true);
// << navigation-navigate-cs
// << getting-started-navigatetodate-cs

            calendarView.ReloadData();
        }
Пример #18
0
        public void TestMaximumRange(int location, int length, NSCalendarUnit unit)
        {
            var cal   = new NSCalendar(NSCalendarType.Gregorian);
            var range = cal.MaximumRange(unit);

            Assert.AreEqual(length, range.Length);
            Assert.AreEqual(location, range.Location);
        }
Пример #19
0
        private int GetStartDateHour(NSDate startTimeDate)
        {
            NSCalendar       calendar           = NSCalendar.CurrentCalendar;
            NSDateComponents startDateCompoents = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day | NSCalendarUnit.Hour | NSCalendarUnit.Minute | NSCalendarUnit.Second, startTimeDate);

            return((int)startDateCompoents.Hour);
        }
Пример #20
0
        private int GetEndDateHour(NSDate endTimeDate)
        {
            NSCalendar       calendar          = NSCalendar.CurrentCalendar;
            NSDateComponents endDateComponents = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day | NSCalendarUnit.Hour | NSCalendarUnit.Minute | NSCalendarUnit.Second, endTimeDate);

            return((int)endDateComponents.Hour);
        }
Пример #21
0
        public void TestOrdinality(int year, int month, int day, NSCalendarUnit smaller, NSCalendarUnit larger, int expected)
        {
            var cal        = new NSCalendar(NSCalendarType.Gregorian);
            var date       = new DateTime(year, month, day, 0, 0, 0, DateTimeKind.Local);
            var ordinality = cal.Ordinality(smaller, larger, (NSDate)date);

            Assert.AreEqual(ordinality, expected);
        }
Пример #22
0
        public static DateTime ToDateTimeUTC(this NSDate nsdate)
        {
            NSCalendar calendar = NSCalendar.CurrentCalendar;
            var        date     = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day | NSCalendarUnit.Hour | NSCalendarUnit.Minute | NSCalendarUnit.Second, nsdate);

            date.TimeZone = NSTimeZone.FromName(@"UTC");
            return(new DateTime((int)date.Year, (int)date.Month, (int)date.Day, (int)date.Hour, (int)date.Minute, (int)date.Second, DateTimeKind.Utc));
        }
Пример #23
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            this.tableViewDataSource = new TableViewDataSource(this);

            this.TableView = new UITableView(new RectangleF());
            this.TableView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleTopMargin;
            this.TableView.RegisterClassForCellReuse(typeof(UITableViewCell), new NSString("cell"));
            this.TableView.DataSource = this.tableViewDataSource;
            this.View.AddSubview(this.TableView);

            NSCalendar calendar = new NSCalendar(NSCalendarType.Gregorian);

            calendar.FirstWeekDay = 2;

            NSDateComponents components = new NSDateComponents();

            components.Year = -10;
            NSDate minDate = calendar.DateByAddingComponents(components, NSDate.Now, (NSCalendarOptions)0);

            components.Year = 10;
            NSDate maxDate = calendar.DateByAddingComponents(components, NSDate.Now, (NSCalendarOptions)0);

            this.calendarDelegate   = new CalendarDelegate(this);
            this.calendarDataSource = new CalendarDataSource(this);

            this.CalendarView = new TKCalendar(new RectangleF());
            this.CalendarView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            this.CalendarView.Calendar         = calendar;
            this.CalendarView.Delegate         = calendarDelegate;
            this.CalendarView.DataSource       = calendarDataSource;
            // >> navigation-minmaxdate-cs
            this.CalendarView.MinDate = minDate;
            this.CalendarView.MaxDate = maxDate;
            // << navigation-minmaxdate-cs
            this.CalendarView.AllowPinchZoom = true;

            TKCalendarMonthPresenter presenter = (TKCalendarMonthPresenter)this.CalendarView.Presenter;

            presenter.Style.TitleCellHeight = 40;
            presenter.HeaderIsSticky        = true;

            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
            {
                presenter.WeekNumbersHidden = true;
                // >> customizations-ipad-cs
                this.CalendarView.Theme = new TKCalendarIPadTheme();
                // << customizations-ipad-cs
                presenter.Update(true);
            }
            else
            {
                presenter.WeekNumbersHidden = false;
            }

            this.View.AddSubview(this.CalendarView);
        }
Пример #24
0
        /// <summary>
        /// Gets the appointment collection
        /// </summary>
        /// <returns>Appointment collection</returns>
        internal ObservableCollection <Meeting> GetAppointments()
        {
            NSDate     today    = new NSDate();
            NSCalendar calendar = NSCalendar.CurrentCalendar;

            appointmentCollection = new ObservableCollection <Meeting>();
            SetEventCollection();
            RandomNumbers();
            SetFromCollection();
            SetToCollection();
            SetColorCollection();

            for (int i = 0; i < 15; i++)
            {
                meeting           = new Meeting();
                meeting.Color     = colorCollection[i];
                meeting.EventName = (NSString)eventCollection[i];
                meeting.From      = fromCollection[i];

                // To create all day appointments
                if (i % 6 == 0 && i != 0)
                {
                    meeting.IsAllDay = true;
                }

                // To create two days span appointment
                if (i % 5 == 0 && i != 0)
                {
                    toCollection[i] = fromCollection[i];
                    var dateComponent = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day | NSCalendarUnit.Hour | NSCalendarUnit.Minute | NSCalendarUnit.Second, toCollection[i]);
                    dateComponent.Day = dateComponent.Day + 2;
                    toCollection[i]   = calendar.DateFromComponents(dateComponent);
                }

                // To create 24 hour span appointments
                if (i % 7 == 0)
                {
                    toCollection[i] = fromCollection[i];
                    var dateComponent = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day | NSCalendarUnit.Hour | NSCalendarUnit.Minute | NSCalendarUnit.Second, toCollection[i]);
                    dateComponent.Hour   = dateComponent.Hour + 23;
                    dateComponent.Minute = dateComponent.Minute + 59;
                    toCollection[i]      = calendar.DateFromComponents(dateComponent);
                }

                // To create minimum height appointments
                if (eventCollection[i].Contains("alert"))
                {
                    toCollection[i]       = fromCollection[i];
                    meeting.MinimumHeight = 20;
                }

                meeting.To = toCollection[i];
                appointmentCollection.Add(meeting);
            }

            return(appointmentCollection);
        }
Пример #25
0
        private void PrevMonthBtnClicked(object sender, EventArgs args)
        {
            NSCalendar       cal   = NSCalendar.CurrentCalendar;
            NSDateComponents comps = cal.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, _calendar.CurrentDate);

            comps.Month          -= 1;
            _calendar.CurrentDate = cal.DateFromComponents(comps);
            UpdateMonthTitle();
        }
Пример #26
0
        public NSDate DateWithOffset(int days, int hours)
        {
            NSCalendar       calendar   = NSCalendar.CurrentCalendar;
            NSDateComponents components = new NSDateComponents();

            components.Day  = days;
            components.Hour = hours;
            return(calendar.DateByAddingComponents(components, NSDate.Now, (NSCalendarOptions)0));
        }
Пример #27
0
        private int GetDayOfWeek(NSDate visibleDate)
        {
            NSCalendar       calendar             = NSCalendar.CurrentCalendar;
            NSDate           today1               = new NSDate();
            NSDateComponents visibleDateCompoents = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day | NSCalendarUnit.Weekday, visibleDate);

            return((int)visibleDateCompoents.Weekday);
        }
Пример #28
0
 public NSDate DateWithYear(int year, int month, int day)
 {
     NSCalendar calendar = new NSCalendar (NSCalendarType.Gregorian);
     NSDateComponents components = new NSDateComponents ();
     components.Year = year;
     components.Month = month;
     components.Day = day;
     return calendar.DateFromComponents (components);
 }
Пример #29
0
        public void TestOrdinality(int year, int month, int day, NSCalendarUnit smaller, NSCalendarUnit larger, int expected)
        {
            var cal  = new NSCalendar(NSCalendarType.Gregorian);
            var date = new DateTime(year, month, day, 0, 0, 0, DateTimeKind.Utc);
            var dt   = (NSDate)date;

            cal.TimeZone = NSTimeZone.FromName("Europe/Madrid");
            Assert.AreEqual((nuint)expected, cal.Ordinality(smaller, larger, dt), $"Ordinality");
        }
        private void GetDataFromQuery(DateTime start, DateTime end, HKQuantityType quentityType, HKUnit unit, Action <IEnumerable <double> > act)
        {
            NSCalendar       calendar = NSCalendar.CurrentCalendar;
            NSDateComponents interval = new NSDateComponents {
                Day = 1
            };
            NSDate startDate  = start.ToNsDate();
            NSDate anchorDate = end.ToNsDate();

            HKStatisticsCollectionQuery query = new HKStatisticsCollectionQuery(
                quentityType,
                null,
                HKStatisticsOptions.CumulativeSum,
                anchorDate,
                interval
                )
            {
                InitialResultsHandler = (localQuery, result, error) =>
                {
                    if (error != null)
                    {
                        OnError?.Invoke(error.Description);
                        return;
                    }
                    int      daysCount = (end - start).Days + 1;
                    double[] st        = new double[daysCount];

                    result.EnumerateStatistics(startDate, anchorDate, (statistics, stop) =>
                    {
                        HKQuantity quantity = statistics?.SumQuantity();

                        int index = (statistics.StartDate.ToDateTime() - start).Days;

                        if (index < 0 || index > st.Length)
                        {
                            return;
                        }

                        double value = quantity?.GetDoubleValue(unit) ?? 0;

                        st[index] = value;
                    });

                    act(st.AsEnumerable());
                }
            };

            try
            {
                _healthStore.ExecuteQuery(query);
            }
            catch (Exception e)
            {
                OnError?.Invoke(e.Message);
            }
        }
Пример #31
0
        public NSDate DateWithYear(int year, int month, int day)
        {
            NSCalendar       calendar   = new NSCalendar(NSCalendarType.Gregorian);
            NSDateComponents components = new NSDateComponents();

            components.Year  = year;
            components.Month = month;
            components.Day   = day;
            return(calendar.DateFromComponents(components));
        }
Пример #32
0
        public void GetAllCalendarIdentifiers()
        {
            RequiresIos8();

            foreach (NSCalendarType t in Enum.GetValues(typeof(NSCalendarType)))
            {
                NSCalendar c = new NSCalendar(t);
                Assert.IsNotNull(c.Identifier, "Can't find identifier: " + t.ToString());
            }
        }
Пример #33
0
        public void ButtonTouched()
        {
            this.Title = "Back";

            NSCalendar calendar = new NSCalendar (NSCalendarType.Gregorian);
            TKCalendarYearViewController controller = new TKCalendarYearViewController ();
            controller.ContentView.MinDate = TKCalendar.DateWithYear (2012, 1, 1, calendar);
            controller.ContentView.MaxDate = TKCalendar.DateWithYear (2018, 12, 31, calendar);
            controller.ContentView.NavigateToDate (NSDate.Now, false);
            this.NavigationController.PushViewController (controller, true);
        }
Пример #34
0
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			this.tableViewDataSource = new TableViewDataSource (this);

			this.TableView = new UITableView (new RectangleF ());
			this.TableView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleTopMargin;
			this.TableView.RegisterClassForCellReuse (typeof(UITableViewCell), new NSString("cell"));
			this.TableView.DataSource = this.tableViewDataSource;
			this.View.AddSubview (this.TableView);

			NSCalendar calendar = new NSCalendar (NSCalendarType.Gregorian);
			calendar.FirstWeekDay = 2;

			NSDateComponents components = new NSDateComponents ();
			components.Year = -10;
			NSDate minDate = calendar.DateByAddingComponents (components, NSDate.Now, (NSCalendarOptions)0);
			components.Year = 10;
			NSDate maxDate = calendar.DateByAddingComponents (components, NSDate.Now, (NSCalendarOptions)0);

			this.calendarDelegate = new CalendarDelegate (this);
			this.calendarDataSource = new CalendarDataSource (this);

			this.CalendarView = new TKCalendar (new RectangleF());
			this.CalendarView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
			this.CalendarView.Calendar = calendar;
			this.CalendarView.Delegate = calendarDelegate;
			this.CalendarView.DataSource = calendarDataSource;
			this.CalendarView.MinDate = minDate;
			this.CalendarView.MaxDate = maxDate;
			this.CalendarView.AllowPinchZoom = true;

			TKCalendarMonthPresenter presenter = (TKCalendarMonthPresenter)this.CalendarView.Presenter;
			presenter.Style.TitleCellHeight = 40;
			presenter.HeaderIsSticky = true;

			if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) {
				presenter.WeekNumbersHidden = true;
				this.CalendarView.Theme = new TKCalendarIPadTheme ();
				presenter.Update (true);
			} else {
				presenter.WeekNumbersHidden = false;
			}

			this.View.AddSubview (this.CalendarView);
		}
        void TurnOnNotifications()
        {
            // create notification for every day at specified time
            var notification = new UILocalNotification ();

            notification.RepeatInterval = NSCalendarUnit.Day;

            //set time
            var time = new NSDateComponents ();
            time.Hour = (nint)slider.Value;
            time.Minute = 00;
            time.Second = 0;

            //choose calendar
            var calendar = new NSCalendar (NSCalendarType.Gregorian);

            //create fire date
            var date = calendar.DateFromComponents (time);

            // set the fire date (the date time in which it will fire)
            notification.FireDate = date;
            notification.TimeZone = NSTimeZone.DefaultTimeZone;

            // configure the alert stuff
            notification.AlertTitle = "The APOD is ready!";
            //			notification.AlertAction = "Open the app";
            notification.AlertBody = "Open the app and check it out!";

            notification.UserInfo = NSDictionary.FromObjectAndKey (new NSString ("UserInfo for notification"), new NSString ("Notification"));

            // modify the badge - has no effect on the Watch
            notification.ApplicationIconBadgeNumber = 1;

            // set the sound to be the default sound
            notification.SoundName = UILocalNotification.DefaultSoundName;

            // schedule it
            UIApplication.SharedApplication.ScheduleLocalNotification (notification);
        }
Пример #36
0
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			TKChart chart = new TKChart (this.View.Bounds);
			chart.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
			this.View.AddSubview (chart);

			NSCalendar calendar = new NSCalendar (NSCalendarType.Gregorian);
			NSDateComponents dateTimeComponents = new NSDateComponents ();
			dateTimeComponents.Year = 2013;
			dateTimeComponents.Day = 1;

			Random r = new Random ();
			List<TKChartDataPoint> list = new List<TKChartDataPoint> ();
			for (int i = 1; i <= 6; i++) {
				dateTimeComponents.Month = i;
				list.Add(new TKChartDataPoint(calendar.DateFromComponents(dateTimeComponents), new NSNumber(r.Next() % 100)));
			}

			TKChartSplineAreaSeries series = new TKChartSplineAreaSeries (list.ToArray());
			series.SelectionMode = TKChartSeriesSelectionMode.Series;

			dateTimeComponents.Month = 1;
			NSDate minDate = new NSDate ();
			NSDate maxDate = new NSDate ();
			minDate = calendar.DateFromComponents (dateTimeComponents);
			dateTimeComponents.Month = 6;
			maxDate = calendar.DateFromComponents (dateTimeComponents);

			TKChartDateTimeAxis xAxis = new TKChartDateTimeAxis (minDate, maxDate);
			xAxis.MajorTickIntervalUnit = TKChartDateTimeAxisIntervalUnit.Months;
			xAxis.MajorTickInterval = 1;
			chart.XAxis = xAxis;

			chart.AddSeries (series);
		}
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            //scrollView = stackView.Superview as UIScrollView;
            //scrollView.KeyboardDismissMode = UIScrollViewKeyboardDismissMode.OnDrag;
            //scrollView.ScrollEnabled = true;
            // Set up Navigation Bar
            var saveButton = new UIBarButtonItem (UIBarButtonSystemItem.Save, save);
            var cancelButton = new UIBarButtonItem (UIBarButtonSystemItem.Cancel, cancel);
            NavigationItem.Title = "New Medication:";
            NavigationItem.RightBarButtonItem = saveButton;
            NavigationItem.HidesBackButton = true;
            NavigationItem.LeftBarButtonItem = cancelButton;

            //NSNotificationCenter.DefaultCenter.AddObserver (this, new ObjCRuntime.Selector("keyboardDidAppear:"), UIKeyboard.DidShowNotification, null);
            //NSNotificationCenter.DefaultCenter.AddObserver (this, new ObjCRuntime.Selector ("keyboardWillDissapear:"), UIKeyboard.WillHideNotification, null);

            // Set up the date formatter
            dateFormat = new NSDateFormatter();
            dateFormat.DateStyle = NSDateFormatterStyle.None;
            dateFormat.TimeStyle = NSDateFormatterStyle.Short;

            // Set up new pet form
            nameField = new UITextField();
            nameField.Text = "Medication Name";
            nameField.BorderStyle = UITextBorderStyle.RoundedRect;
            nameField.ReturnKeyType = UIReturnKeyType.Done;

            medTypeLabel = new UILabel ();
            medTypeLabel.Text = "Type of Medication";
            medTypeButton = new UIButton (UIButtonType.RoundedRect);
            medTypeButton.AddTarget (editMedType, UIControlEvent.TouchUpInside);
            medTypeButton.SetTitle ("Pill", UIControlState.Normal);
            medTypeButton.TitleLabel.Font = medTypeButton.TitleLabel.Font.WithSize (medTypeLabel.Font.PointSize);
            medTypePicker = new UIPickerView ();
            medTypePicker.Delegate = new MedTypePickerDelegate (this);
            medTypePicker.DataSource = new MedTypePickerDataSource ();

            freqLabel = new UILabel ();
            freqLabel.Text = "Frequency";
            freqTextField = new UITextField ();
            freqTextField.Text = "1";
            freqTextField.KeyboardType = UIKeyboardType.NumberPad;
            freqTextField.BorderStyle = UITextBorderStyle.RoundedRect;
            freqTextField.Enabled = false;
            freqTextField.AddTarget (freqTextFieldChanged, UIControlEvent.EditingDidEnd | UIControlEvent.EditingDidEndOnExit);
            freqStepper = new UIStepper ();
            freqStepper.Value = 1;
            freqStepper.MinimumValue = 1;
            freqStepper.Enabled = false;
            freqStepper.AddTarget (freqStepperIncremented, UIControlEvent.ValueChanged);
            UIStackView freqStackView = new UIStackView (new UIView[] { freqTextField, freqStepper });
            freqStackView.Spacing = 8;
            freqStackView.Axis = UILayoutConstraintAxis.Horizontal;
            freqButton = new UIButton (UIButtonType.RoundedRect);
            freqButton.SetTitle ("Daily", UIControlState.Normal);
            freqButton.TitleLabel.Font = freqButton.TitleLabel.Font.WithSize (medTypeLabel.Font.PointSize);
            freqButton.AddTarget (editFrequency, UIControlEvent.TouchUpInside);
            freqPicker = new UIPickerView ();
            freqPicker.Delegate = new MedFreqPickerDelegate (this);
            freqPicker.DataSource = new MedFreqPickerDataSource ();

            timePicker = new UIDatePicker ();
            gregorian = new NSCalendar (NSCalendarType.Gregorian);
            timePicker.Date = gregorian.DateBySettingsHour (9, 0, 0, NSDate.Now, NSCalendarOptions.MatchNextTime);
            timePicker.Mode = UIDatePickerMode.Time;
            timePicker.AddTarget (timePickerChanged, UIControlEvent.AllEvents);

            UILabel timeLabel = new UILabel ();
            timeLabel.Text = "Time";
            timeButtons = new UIButton[1];
            timeDates = new NSDate[1];
            timeDates [0] = gregorian.DateBySettingsHour (9, 0, 0, NSDate.Now, NSCalendarOptions.MatchNextTime);
            timeButtons [0] = new UIButton (UIButtonType.RoundedRect);
            timeButtons [0].SetTitle ("9:00 AM", UIControlState.Normal);
            timeButtons [0].AddTarget (openTimePicker, UIControlEvent.TouchUpInside);
            timeStack = new UIStackView ();
            timeStack.Alignment = UIStackViewAlignment.Leading;
            timeStack.Distribution = UIStackViewDistribution.FillProportionally;
            timeStack.Spacing = 5;
            timeStack.Axis = UILayoutConstraintAxis.Vertical;
            timeStack.AddArrangedSubview (timeLabel);
            foreach (var button in timeButtons) {
                timeStack.AddArrangedSubview (button);
            }
            timeStack.AddArrangedSubview (timePicker);
            timePicker.Hidden = true;

            dayLabel = new UILabel ();
            dayLabel.Text = "Day";
            dayLabel.Hidden = true;
            dayButton = new UIButton (UIButtonType.RoundedRect);
            var day = gregorian.GetComponentFromDate (NSCalendarUnit.Weekday, NSDate.Now);
            dayButton.SetTitle (gregorian.WeekdaySymbols[day], UIControlState.Normal);
            dayButton.AddTarget (openDayPicker, UIControlEvent.TouchUpInside);
            dayButton.Hidden = true;
            dayPicker = new UIDatePicker ();
            dayPicker.Mode = UIDatePickerMode.Date;
            dayPicker.MinimumDate = NSDate.Now;
            dayPicker.MaximumDate = NSDate.Now.AddSeconds (604800);
            dayPicker.AddTarget (dayPickerChanged, UIControlEvent.AllEvents);
            dayPicker.Hidden = true;

            prescriptionLengthLabel = new UILabel ();
            prescriptionLengthLabel.Text = "Prescription Length";
            prescriptionLengthTextField = new UITextField ();
            prescriptionLengthTextField.Text = "20";
            prescriptionLengthTextField.AddTarget (prescriptionTextFieldChanged, UIControlEvent.EditingDidEnd | UIControlEvent.EditingDidEndOnExit);
            prescriptionLengthTextField.KeyboardType = UIKeyboardType.NumberPad;
            prescriptionLengthTextField.BorderStyle = UITextBorderStyle.RoundedRect;
            prescriptionLengthStepper = new UIStepper ();
            prescriptionLengthStepper.Value = 20;
            prescriptionLengthStepper.MinimumValue = 1;
            prescriptionLengthStepper.AddTarget (prescriptionStepperIncremented, UIControlEvent.ValueChanged);
            prescriptionDayLabel = new UILabel ();
            prescriptionDayLabel.Text = "Days";
            UIStackView prescriptionStackView = new UIStackView (new UIView[] {
                prescriptionLengthTextField,
                prescriptionLengthStepper,
                prescriptionDayLabel
            });
            prescriptionStackView.Axis = UILayoutConstraintAxis.Horizontal;
            prescriptionStackView.Alignment = UIStackViewAlignment.Leading;
            prescriptionStackView.Distribution = UIStackViewDistribution.FillProportionally;
            prescriptionStackView.Spacing = 5;

            refillsLabel = new UILabel ();
            refillsLabel.Text = "Refills Remaining";
            refillsTextField = new UITextField ();
            refillsTextField.Text = "0";
            refillsTextField.KeyboardType = UIKeyboardType.NumberPad;
            refillsTextField.BorderStyle = UITextBorderStyle.RoundedRect;
            refillsTextField.AddTarget (refillsTextFieldChanged, UIControlEvent.EditingDidEnd | UIControlEvent.EditingDidEndOnExit);
            refillsStepper = new UIStepper ();
            refillsStepper.Value = 0;
            refillsStepper.MinimumValue = 0;
            refillsStepper.AddTarget (refillsStepperIncremented, UIControlEvent.ValueChanged);
            UIStackView refillsStackView = new UIStackView (new UIView[] { refillsTextField, refillsStepper });
            refillsStackView.Spacing = 5;
            refillsStackView.Alignment = UIStackViewAlignment.Leading;
            refillsStackView.Distribution = UIStackViewDistribution.FillProportionally;
            refillsStackView.Axis = UILayoutConstraintAxis.Horizontal;

            pharmacyTextView = new UITextView ();
            pharmacyTextView.Text = "Pharmacy Address";
            pharmacyTextView.ScrollEnabled = false;
            pharmacyTextView.BackgroundColor = UIColor.LightGray;
            pharmacyTextField = new UITextField ();
            pharmacyTextField.Text = "Pharmacy Address";
            pharmacyTextField.BorderStyle = UITextBorderStyle.RoundedRect;

            // Sets up the stackview
            stackView.Spacing = 5;
            stackView.Alignment = UIStackViewAlignment.Leading;
            stackView.Distribution = UIStackViewDistribution.EqualSpacing;
            stackView.AddArrangedSubview (nameField);
            UIView spaceView = new UIView (CoreGraphics.CGRect.FromLTRB (0, 0, 50, SECTION_SPACER));
            spaceView.AddConstraint (NSLayoutConstraint.Create (spaceView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, SECTION_SPACER));
            stackView.AddArrangedSubview (spaceView);
            stackView.AddArrangedSubview (medTypeLabel);
            stackView.AddArrangedSubview (medTypeButton);
            stackView.AddArrangedSubview (medTypePicker);
            medTypePicker.Hidden = true;
            UIView spaceView2 = new UIView (CoreGraphics.CGRect.FromLTRB (0, 0, 50, SECTION_SPACER));
            spaceView2.AddConstraint (NSLayoutConstraint.Create (spaceView2, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, SECTION_SPACER));
            stackView.AddArrangedSubview (spaceView2);
            stackView.AddArrangedSubview (freqLabel);
            stackView.AddArrangedSubview (freqStackView);
            stackView.AddArrangedSubview (freqButton);
            stackView.AddArrangedSubview (freqPicker);
            freqPicker.Hidden = true;
            UIView spaceView3 = new UIView (CoreGraphics.CGRect.FromLTRB (0, 0, 50, SECTION_SPACER));
            spaceView3.AddConstraint (NSLayoutConstraint.Create (spaceView3, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, SECTION_SPACER));
            stackView.AddArrangedSubview (spaceView3);
            stackView.AddArrangedSubview (timeStack);
            stackView.AddArrangedSubview (dayLabel);
            stackView.AddArrangedSubview (dayButton);
            stackView.AddArrangedSubview (dayPicker);
            UIView spaceView4 = new UIView (CoreGraphics.CGRect.FromLTRB (0, 0, 50, SECTION_SPACER));
            spaceView4.AddConstraint (NSLayoutConstraint.Create (spaceView4, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, SECTION_SPACER));
            stackView.AddArrangedSubview (spaceView4);
            stackView.AddArrangedSubview (prescriptionLengthLabel);
            stackView.AddArrangedSubview (prescriptionStackView);
            UIView spaceView5 = new UIView (CoreGraphics.CGRect.FromLTRB (0, 0, 50, SECTION_SPACER));
            spaceView5.AddConstraint (NSLayoutConstraint.Create (spaceView5, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, SECTION_SPACER));
            stackView.AddArrangedSubview (spaceView5);
            stackView.AddArrangedSubview (refillsLabel);
            stackView.AddArrangedSubview (refillsStackView);
            UIView spaceView6 = new UIView (CoreGraphics.CGRect.FromLTRB (0, 0, 50, SECTION_SPACER));
            spaceView6.AddConstraint (NSLayoutConstraint.Create (spaceView6, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, SECTION_SPACER));
            stackView.AddArrangedSubview (spaceView6);
            stackView.AddArrangedSubview (pharmacyTextField);
            UIView spaceView7 = new UIView (CoreGraphics.CGRect.FromLTRB (0, 0, 50, SECTION_SPACER));
            spaceView7.AddConstraint (NSLayoutConstraint.Create (spaceView7, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, SECTION_SPACER));
            stackView.AddArrangedSubview (spaceView7);
        }
Пример #38
0
		void AddEarthquakesToList (List<Earthquake> earthquakes)
		{
			var entity = NSEntityDescription.EntityForName ("Earthquake", managedObjectContext);
			var fetchRequest = new NSFetchRequest ();
			fetchRequest.Entity = entity;

			var date = (NSPropertyDescription)entity.PropertiesByName.ValueForKey (new NSString ("date"));
			var location = (NSPropertyDescription)entity.PropertiesByName.ValueForKey (new NSString ("location"));

			fetchRequest.PropertiesToFetch = new NSPropertyDescription[] { date, location };
			fetchRequest.ResultType = NSFetchRequestResultType.DictionaryResultType;

			NSError error;

			foreach (var earthquake in earthquakes) {
				var arguments = new NSObject[] { earthquake.Location, earthquake.Date };
				fetchRequest.Predicate = NSPredicate.FromFormat ("location = %@ AND date = %@", arguments);
				var fetchedItems = NSArray.FromNSObjects (managedObjectContext.ExecuteFetchRequest (fetchRequest, out error));

				if (fetchedItems.Count == 0) {

					if (string.IsNullOrEmpty (entity.Description))
						continue;

					var managedEarthquake = new ManagedEarthquake (entity, managedObjectContext) {
						Magnitude = earthquake.Magnitude,
						Location = earthquake.Location,
						Date = earthquake.Date,
						USGSWebLink = earthquake.USGSWebLink,
						Latitude = earthquake.Latitude,
						Longitude = earthquake.Longitude
					};

					managedObjectContext.InsertObject (managedEarthquake);
				}

				var gregorian = new NSCalendar (NSCalendarType.Gregorian);
				var offsetComponents = new NSDateComponents ();
				offsetComponents.Day = -14;// 14 days back from today
				NSDate twoWeeksAgo = gregorian.DateByAddingComponents (offsetComponents, NSDate.Now, NSCalendarOptions.None);

				// use the same fetchrequest instance but switch back to NSManagedObjectResultType
				fetchRequest.ResultType = NSFetchRequestResultType.ManagedObject;
				fetchRequest.Predicate = NSPredicate.FromFormat ("date < %@", new NSObject[] { twoWeeksAgo });

				var olderEarthquakes = NSArray.FromObjects (managedObjectContext.ExecuteFetchRequest (fetchRequest, out error));

				for (nuint i = 0; i < olderEarthquakes.Count; i++)
					managedObjectContext.DeleteObject (olderEarthquakes.GetItem<ManagedEarthquake> (i));

				if (managedObjectContext.HasChanges) {
					if (!managedObjectContext.Save (out error))
						Console.WriteLine (string.Format ("Unresolved error {0}", error.LocalizedDescription));
				}
			}
		}