protected override void OnNavigatedTo(NavigationEventArgs e)
        {
           
            navigationHelper.OnNavigatedTo(e);
            vm = e.Parameter as VisitorManager;
           // Debug.WriteLine("Hey, it's ScheduledVisit2. I see you've handed me a visitor '" + vm.firstname + " " + vm.lastname + ", ID: " + vm.ID);
           // Debug.WriteLine("Their bemsid is: " + vm.bemsid);
            thisID = vm.ID;
            if (vm.PreScreenedByInitials != "")
            {
                togPrescreened.IsOn = true;
            }


            if(vm.bemsid != 0){
                togBoeing.IsOn = true;
                lblCompBems.Text = "BEMSID";
                txtCompBems.Text = vm.bemsid.ToString();
            }

            if (vm.companyrepresented != null && vm.companyrepresented != "" && vm.bemsid == 0)
            {
                txtCompBems.Text = vm.companyrepresented;
            }
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            
            navigationHelper.OnNavigatedTo(e);
            vm = e.Parameter as VisitorManager;

            //default to no boeing emp
            RadBoeEmpNo.IsChecked = true;

            if (vm.bemsid != 0)
            {
                //togPrescreened.IsOn = true;
                //txtCompany.Text = vm.bemsid.ToString();
                if (RadBoeEmpYes != null) { RadBoeEmpYes.IsChecked = true; }
               
                txtCompany.Text = vm.bemsid.ToString();
            }
            else
            {
                if (vm.companyrepresented!=null)
                {
                    txtCompany.Text = vm.companyrepresented;
                }
                
            }
        }
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     navigationHelper.OnNavigatedTo(e);
     vm = e.Parameter as VisitorManager;
     if (vm != null)
     {
         vm.prerecorded = true; //?
     }
 }
        private async void btnSave_Click_1(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(txtFirstName.Text) || String.IsNullOrEmpty(txtLastName.Text) || String.IsNullOrEmpty(txtHost.Text))
            {
                MessageDialog msgbox = new MessageDialog("All fields are required.", "Problem...");
                msgbox.Commands.Clear();
                msgbox.Commands.Add(new UICommand { Label = "Ok", Id = 0 });
                var res = await msgbox.ShowAsync();
            }
            else
            {
                VisitorManager vm = new VisitorManager();
                vm.firstname = txtFirstName.Text; vm.lastname = txtLastName.Text;  vm.boeinghostname = txtHost.Text;

                TimeSpan ts = dpTime.Time;
                Debug.WriteLine("the time is " + ts);
                DateTimeOffset dto = dpDate.Date;
                DateTime dt = dto.DateTime;
                DateTime date = new DateTime(dpDate.Date.Year, dpDate.Date.Month, dpDate.Date.Day, dpTime.Time.Hours, dpTime.Time.Minutes, 00);

               // Debug.WriteLine("the date is " + date);

                vm.timein = date;
                vm.EnteredByAdminDate = DateTime.Now;
                vm.EnteredByAdmin = 1;
                vm.prerecorded = true;


                if (!alreadyEntered)
                {
                   // Debug.WriteLine("adding the node");
                    await vm.record("Scheduled Visit");

                }
                else
                {
                    vm.ID = thisID;
                    vm.bemsid = thisBEMS;
                    vm.companyrepresented = company;
                    vm.PreScreenedByInitials = screenedby;
                    Debug.WriteLine("updating bemsid: " + vm.bemsid);
                   // Debug.WriteLine("updating node" + vm.ID);
                    await vm.update("Scheduled Visit");
                }


                this.Frame.Navigate(typeof(ScheduleVisit2), vm);
            }
        }
 private async void btnSave_Click(object sender, RoutedEventArgs e)
 {
     //record the sign out
     VisitorManager vm = new VisitorManager();
     vm.parsePerson(this.person);
     await vm.record("Sign Out");
     this.Frame.Navigate(typeof(VisitorSignOutConfirmation2));
 }
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     navigationHelper.OnNavigatedTo(e);
     vm = e.Parameter as VisitorManager;
    
     if (vm != null)
     {
         txtFirstName.Text = vm.firstname;
         txtLastName.Text = vm.lastname;
         //txtCompany.Text = vm.companyrepresented;
         txtHost.Text = vm.boeinghostname;
         //how about hte date
         dpDate.Date = DateTimeOffset.Parse(vm.timein.ToString());
         dpTime.Time = TimeSpan.Parse(vm.timein.TimeOfDay.ToString());
         alreadyEntered = true;
         thisID = vm.ID;
         thisBEMS = vm.bemsid;
         company = vm.companyrepresented;
         screenedby = vm.PreScreenedByInitials;
         Debug.WriteLine("Hello from " + vm.firstname + " " + vm.lastname + ", ID:" + vm.ID +  " bemsid: "  + vm.bemsid);
     }
 }
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     navigationHelper.OnNavigatedTo(e);
     vm = e.Parameter as VisitorManager;
     if(vm!=null){
     vm.prerecorded = true;
     txtFirstName.Text = vm.firstname;
     txtLastName.Text = vm.lastname;
     //txtCompany.Text = vm.companyrepresented;
     txtHost.Text = vm.boeinghostname;
         }
 }
        private async void btnSave_Click(object sender, RoutedEventArgs e)
        {
            //do form verification
            //save visitor info
            if(String.IsNullOrEmpty(txtFirstName.Text) || String.IsNullOrEmpty(txtLastName.Text) ||  String.IsNullOrEmpty(txtHost.Text) ){
                MessageDialog msgbox = new MessageDialog("All fields are required.", "Problem...");
                msgbox.Commands.Clear();
                msgbox.Commands.Add(new UICommand { Label = "Ok", Id = 0 });
                var res = await msgbox.ShowAsync(); 
            }else
            {
                if (vm == null) {
                    vm = new VisitorManager();
                    vm.firstname = txtFirstName.Text;
                    vm.lastname = txtLastName.Text;
                    //vm.companyrepresented = txtCompany.Text;
                    vm.boeinghostname = txtHost.Text;

                    Debug.WriteLine("send to badge capture screen.");
                }
                else
                {
                    vm.firstname = txtFirstName.Text;
                    vm.lastname = txtLastName.Text;
                    //vm.companyrepresented = txtCompany.Text;
                    vm.boeinghostname = txtHost.Text;
                }
               
                this.Frame.Navigate(typeof(VisitorProcessPage2), vm);
            }
        }
 private void AppBarButton_Click_2(object sender, RoutedEventArgs e)
 {
    
     ScheduledVisitTile thisTile = lvItems.SelectedItem as ScheduledVisitTile;
    if(thisTile!=null){
             VisitorManager vm = new VisitorManager();
             vm.parsePerson(thisTile.person);
             this.Frame.Navigate(typeof(VisitorProcessPage1), vm);
        }
 }
        //private async void txtName_Copy_KeyUp(object sender, KeyRoutedEventArgs e)
        //{
        //    StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync("logdata.xml");

        //    lvItems.Items.Clear();

        //    //   Debug.WriteLine("Attempting to read file  " + file.Path + " into xdocument");
        //    XDocument doc = XDocument.Load(file.Path);
        //    var ps = (
        //        from actions in doc.Root.Elements("Action").Elements("Person")
        //        select actions
        //    );

        //    if (txtName_Copy.Text.Count() > 0)
        //    {

        //        IEnumerable<XElement> persons = (
        //            from actions in doc.Root.Elements("Action")
        //            where (string)actions.Attribute("type") == "Scheduled Visit"
        //            from person in actions.Elements("Person")
        //            where (person.Element("Company-Represented").Value.ToUpper().Contains(txtName_Copy.Text.ToUpper()))
        //            from dates in person.Elements("Date")
        //            orderby DateTime.Parse(person.Element("Time-In").Value) ascending
        //            where Convert.ToDateTime(dates.Value).Date == DateTime.Now.Date
        //            select person
        //        );

        //        foreach (XElement signin in persons)
        //        {
        //            ScheduledVisitTile tile = new ScheduledVisitTile();
        //            tile.person = signin;
        //            tile.txtName.Text = signin.Element("Last-Name").Value.ToString() + ", " + signin.Element("First-Name").Value.ToString();
        //            tile.txtCompany.Text = signin.Element("Company-Represented").Value.ToString();
        //            var formatter = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("shortdate");
        //            var formatterTime = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("shorttime");
        //            DateTime dateToFormat = Convert.ToDateTime(signin.Element("Time-In").Value.ToString());
        //            var thedate = formatter.Format(dateToFormat);
        //            var thetime = formatterTime.Format(dateToFormat);
        //            tile.txtDate.Text = thedate + " " + thetime;
        //            lvItems.Items.Add(tile);


        //        }
        //    }

        //}

        private void AppBarButton_Click_2(object sender, RoutedEventArgs e)
        {

            ScheduledVisitTile thisTile = lvItems.SelectedItem as ScheduledVisitTile;
            if (thisTile != null)
            {
                VisitorManager vm = new VisitorManager();
                vm.parsePerson(thisTile.person);
               // this.Frame.Navigate(typeof(VisitorProcessPage1), vm);
                if (Convert.ToBoolean(App.appman.localSettings.Values["UsePrivacyStatement"]))
                {
                    this.Frame.Navigate(typeof(PrivacyStatement), vm);
                }
                else
                {
                    this.Frame.Navigate(typeof(VisitorProcessPage1), vm);
                }
                
            }
        }