public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            picker = new ScanditSDK.SIBarcodePicker (appKey);
            picker.OverlayController.DidScanBarcode += (object sender, SIOverlayControllerDidScanEventArgs e) => {
                picker.StopScanning ();
                ProcessBarcode (convertToNumber(e.Barcode ["barcode"].ToString ().ToUpper()));
            };
            picker.OverlayController.DidManualSearch += (object sender, SIOverlayControllerDidManualSearchEventArgs e) => {
                ProcessBarcode (convertToNumber(e.Text.ToUpper()));
            };
            picker.OverlayController.ShowSearchBar (true);
            picker.OverlayController.SetSearchBarKeyboardType (UIKeyboardType.ASCIICapable);
            picker.OverlayController.setSearchBarActionButtonCaption ("Search");
            View.AddSubview (picker.View);

            Shared.Database db = new Shared.Database();
            db.Initialize();
            int campusID = db.getCampusID();

            classPicker = new UIPickerView ();
            List<Area> Classes = dl.getSecureAreas (campusID).ToList();
            classPicker.Model = new Shared.ClassPickerViewModel (Classes);
            View.AddSubview (classPicker);

            eventPicker = new UIPickerView ();
            List<Event> Events = dl.getUpcomingEvents (campusID).ToList ();
            eventPicker.Model = new Shared.EventPickerViewModel (Events);
            View.AddSubview (eventPicker);

            checkInOut = new UISegmentedControl ();
            checkInOut.InsertSegment ("Check IN", 0, true);
            checkInOut.InsertSegment ("Check OUT", 1, true);
            checkInOut.SelectedSegment = 0;
            View.AddSubview (checkInOut);

            note = new UILabel ();
            note.Text = "Select the class and event you are checking kids INTO or OUT of:";
            View.AddSubview (note);

            picker.StartScanning ();
            ConfigureSizing ();
        }
        void loadHouseholds()
        {
            Database db = new Database ();
            DataLayer dl = new DataLayer ();
            LoadingOverlay loadingOverlay = new LoadingOverlay (View.Bounds);
            db.Initialize ();
            dl.Sync ();
            int campusID = db.getCampusID ();
            households = dl.getHouseholds(campusID);

            searchBar.Text = "";
            tblHouseholds.Source = new HouseholdTableSource(households,"", this);
            tblHouseholds.ReloadData();
        }
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear (animated);

            Shared.Database db = new Shared.Database();
            db.Initialize();
            int campusID = db.getCampusID();

            Events = dl.getUpcomingEvents (campusID);
            int x = 0;
            foreach (Event myevent in Events) {
                if (x > segEvent.NumberOfSegments - 1) {
                    segEvent.InsertSegment("",x, true);
                }
                segEvent.SetTitle (myevent.ID.ToString() + ": " + myevent.StartDate.ToString ("HH:mm"), x);
                x += 1;

            }
            loadKids ();
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            Shared.Database db = new Shared.Database();
            db.Initialize();
            int campusID = db.getCampusID();

            Events = dl.getUpcomingEvents (campusID);
            int x = 0;
            foreach (Event myevent in Events) {
                if (x > segEvent.NumberOfSegments - 1) {
                    segEvent.InsertSegment("",x, true);
                }
                segEvent.SetTitle (myevent.ID.ToString() + ": " + myevent.StartDate.ToString ("HH:mm"), x);
                x += 1;

            }

            loadKids ();

            segStatus.ValueChanged += (object sender, EventArgs e) => {
                loadKids();
            };

            segEvent.ValueChanged += (object sender, EventArgs e) => {
                loadKids();
            };

            //			btnSync.TouchUpInside += (object sender, EventArgs e) => {
            //				dl.loadingOverlay = new LoadingOverlay(View.Bounds);
            //				View.AddSubview(dl.loadingOverlay);
            //				dl.Sync();
            //			};
        }
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear (animated);

            Shared.Database db = new Shared.Database();
            db.Initialize();
            int campusID = db.getCampusID();

            List<Area> Classes = dl.getSecureAreas (campusID).ToList();
            classPicker.Model = new Shared.ClassPickerViewModel (Classes);

            List<Event> Events = dl.getUpcomingEvents (campusID).ToList ();
            eventPicker.Model = new Shared.EventPickerViewModel (Events);

            ConfigureSizing ();
            if (picker.IsScanning == false) {
                picker.StartScanning ();
            }
        }
        private void ProcessBarcode(string text)
        {
            try
            {
                Shared.Database db = new Shared.Database();
                db.Initialize();

                int campusID = db.getCampusID();
                List<Area> classes = dl.getSecureAreas(campusID).ToList();
                List<Event> events = dl.getUpcomingEvents(campusID).ToList();

                int row = classPicker.SelectedRowInComponent (0);
                int rowEvent = eventPicker.SelectedRowInComponent(0);
                int InOUT = checkInOut.SelectedSegment;

                if (text.Length == 6) {
                    Person parent = dl.getPerson(Convert.ToInt32(text.Substring(1)));
                    List<Person> children = dl.getChildren(parent.ID).ToList();
                    string message = "";
                    UIActionSheet action = new UIActionSheet("Which child would you like to check in/out");
                    foreach (Person child in children)
                    {
                        action.AddButton(child.ID.ToString() + ":" + child.FirstName);
                    }
                    action.AddButton("Cancel");
                    action.CancelButtonIndex = action.ButtonCount - 1;
                    action.Clicked += (object sender, UIButtonEventArgs e) => {
                        string val = action.ButtonTitle(e.ButtonIndex);
                        if (val.IndexOf(":") > 0)
                        {
                            int personid = Convert.ToInt32(val.Substring(0, val.IndexOf(":")));
                            Person child = dl.getPerson (personid);
                            dl.checkinToSecureArea(personid, classes [row].ID, events[rowEvent].ID, InOUT);
                            bool boVal = (InOUT == 0 ? true : false);
                            UIAlertView alert = new UIAlertView ("Checkin", child.LastName + ", " + child.FirstName + " has been checked " + (boVal ? "INTO " + classes [row].Description : "OUT"), null, "OK", null);
                            alert.Clicked += (object senderAlert, UIButtonEventArgs eAlert) => {
                                picker.StartScanning();
                            };
                            alert.Canceled += (object senderCancelled, EventArgs eCancelled) => {
                                picker.StartScanning();
                            };
                            alert.Show ();
                        }
                        else
                        {
                            picker.StartScanning();
                        }
                    };
                    action.Canceled += (object sender, EventArgs e) => {
                        picker.StartScanning();
                    };
                    action.ShowInView(View);
                } else {
                    Person child = dl.getPerson (Convert.ToInt32 (text));
                    dl.checkinToSecureArea(child.ID, classes [row].ID, events[rowEvent].ID, InOUT);
                    dl.loadingOverlay = new LoadingOverlay(View.Bounds);
                    View.AddSubview(dl.loadingOverlay);
                    dl.Sync();
                    bool val = (InOUT == 0 ? true : false);
                    UIAlertView alert = new UIAlertView ("Checkin", child.LastName + ", " + child.FirstName + " has been checked " + (val ? "INTO " + classes [row].Description : "OUT"), null, "OK", null);
                    alert.Clicked += (object sender, UIButtonEventArgs e) => {
                        picker.StartScanning();
                    };
                    alert.Canceled += (object sender, EventArgs e) => {
                        picker.StartScanning();
                    };
                    alert.Show ();
                }
            }
            catch {
                UIAlertView alert = new UIAlertView ("Error", "Unrecognizable barcode", null, "OK", null);
                alert.Show ();
                picker.StartScanning ();
            }
        }