public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            PageHeaderLabel.BackgroundColor = UIColor.Gray;

            SizeF size = new SizeF(320, UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? 600 : 800);

            ProfileScrollView.ContentSize = size;


            MapCCodeList         = new List <Location>();
            LocationList         = new List <Location>();
            provinceList         = new List <Location>();
            stateList            = new List <Location>();
            FilteredLocationList = new List <Location>();
            SelectedMapCCode     = new Location();
            SelectedLocation     = new Location();


            FirstNameTextField.AttributedPlaceholder = new NSAttributedString(
                "FIRST NAME",
                font: FirstNameTextField.Font,
                foregroundColor: UIColor.White
                );

            LastNameTextField.AttributedPlaceholder = new NSAttributedString(

                "LAST NAME",
                font: LastNameTextField.Font,
                foregroundColor: UIColor.White
                );

            MobilePhoneTextField.AttributedPlaceholder = new NSAttributedString(
                "MOBILE PHONE",
                font: MobilePhoneTextField.Font,
                foregroundColor: UIColor.White
                );



            CompanyTextField.AttributedPlaceholder = new NSAttributedString(
                "COMPANY",
                font: CompanyTextField.Font,
                foregroundColor: UIColor.White
                );


            FirstNameTextField.Text   = Settings.FirstName;
            MobilePhoneTextField.Text = Settings.Phone;
            LastNameTextField.Text    = Settings.LastName;
            //Task.Run(async () => {
            //	try
            //	{
            //		AuthResponse response1 = await AuthResponse.GetAuthResponseAsync(Settings.AppID, Settings.Username, Settings.Password);

            //		APIManager manager = new APIManager();

            //		var reponseProfile = await manager.getUserProfile(Settings.AppID, Settings.Username, response1.AuthToken, Settings.Password);


            //		InvokeOnMainThread(() =>
            //				{

            //					//CompanyTextField.Text = reponseProfile.Company;
            //				});

            //	}
            //	catch (Exception e) {

            //	}

            //});

            //ContainerViewWidthConstraint.Constant = View.Bounds.Width - 40;
            ContainerView.BackgroundColor = UIColor.Clear;
            ContainerView.Alpha           = .8f;

            //CGSize contentSize = new CGSize(View.Bounds.Width - 40, ContainerView.Bounds.Height);
            //ProfileScrollView.ContentSize = contentSize;
            //LocationResponseList = new List<LocationResponse>();


            MapCCodePickerView.Model = new MapCCodeModel(this);


            Task.Run(async() =>
            {
                try
                {
                    LocationResponse location = new LocationResponse();
                    if (Reachability.IsHostReachable(Settings._baseDomain))
                    {
                        location = await LocationResponse.GetLocations();
                        if (location.Equals(null))
                        {
                            return;
                        }
                        if (location.Status != "Success")
                        {
                            InvokeOnMainThread(() =>
                            {
                                var alert = UIAlertController.Create("There was a problem loading location data", "Please try again.", UIAlertControllerStyle.Alert);

                                alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Cancel, (obj) =>
                                {
                                    this.DismissViewController(true, null);
                                }));

                                PresentViewController(alert, animated: true, completionHandler: () =>
                                {
                                });
                            });
                        }
                        else
                        {
                            //Save to settings file to use object during the rest of the registration process
                            Settings.LocationResponse = location;

                            var distinctMapCodes = location.Locations.Select(row => row.MapCCode).Distinct().ToList();
                            List <Location> filteredLocationListByFirstMapCode = new List <Location>();



                            foreach (var mapCode in distinctMapCodes)
                            {
                                Location loc = location.Locations.FirstOrDefault(row => row.MapCCode == mapCode);

                                if (loc != null)
                                {
                                    if (loc.MapCCode == "WO")
                                    {
                                        Location placeholderLocation     = new Location();
                                        placeholderLocation.LocationId   = loc.LocationId;
                                        placeholderLocation.LocName      = "World";
                                        placeholderLocation.Abbreviation = loc.Abbreviation;
                                        placeholderLocation.MapCCode     = loc.MapCCode;
                                        placeholderLocation.DisplayOrder = loc.DisplayOrder + 1;
                                        filteredLocationListByFirstMapCode.Add(placeholderLocation);
                                    }
                                    else
                                    {
                                        filteredLocationListByFirstMapCode.Add(loc);
                                    }
                                }
                            }
                            MapCCodeList             = filteredLocationListByFirstMapCode.OrderByDescending(row => row.DisplayOrder).ToList();
                            Location sleLocation     = new Location();
                            sleLocation.LocationId   = 0;
                            sleLocation.LocName      = "Select";
                            sleLocation.Abbreviation = "Select";
                            sleLocation.MapCCode     = "SE";
                            sleLocation.DisplayOrder = 0;
                            MapCCodeList.Insert(0, sleLocation);

                            LocationList         = location.Locations.OrderBy(row => row.DisplayOrder).ToList();
                            FilteredLocationList = LocationList;
                            provinceList         = location.ProvinceLst.OrderBy(row => row.DisplayOrder).ToList();
                            stateList            = location.StatesLst.OrderBy(row => row.DisplayOrder).ToList();

                            if (MapCCodeList.Count > 1 && Settings.LocationPickerSelectedId == 0)
                            {
                                //Assign value to registration objec
                                Settings.LocationPickerSelectedId = MapCCodeList[0].LocationId;
                            }

                            InvokeOnMainThread(() =>
                            {
                                MapCCodePickerView.Model = new MapCCodeModel(this);
                                LocationsPicker.Model    = new LocationsModel(this);

                                if (Settings.IsRegistered)
                                {
                                    var previouslSelectedLocation = MapCCodeList.FirstOrDefault(row => row.LocationId == Settings.LocationPickerSelectedId);

                                    if (previouslSelectedLocation != null)
                                    {
                                        int currentIndex = MapCCodeList.IndexOf(MapCCodeList.FirstOrDefault(row => row.LocationId == Settings.LocationPickerSelectedId));;
                                        MapCCodePickerView.Select(currentIndex, 0, true);
                                    }
                                    else
                                    {
                                        if (Settings.LocationPickerSelectedId != 0)
                                        {
                                            int locationId = Settings.LocationPickerSelectedId;
                                            int mapCIndex  = MapCCodeList.IndexOf(MapCCodeList.FirstOrDefault(row => row.LocationId == 0));
                                            MapCCodePickerView.Select(mapCIndex, 0, true);
                                            MapCCodePickerView.Model.Selected(MapCCodePickerView, mapCIndex, 0);

                                            int locationCInddex = FilteredLocationList.IndexOf(FilteredLocationList.FirstOrDefault(row => row.LocationId == locationId));
                                            LocationsPicker.Select(locationCInddex, 0, true);
                                            LocationsPicker.Model.Selected(LocationsPicker, locationCInddex, 0);
                                            //LocationPicker.Alpha = 1f;
                                        }
                                    }
                                }
                                else
                                {
                                    //MapCCodePicker.Model.Selected(MapCCodePicker, 0, 0);
                                    MapCCodePickerView.Select(0, 0, true);
                                }
                            });
                        }
                    }
                    else
                    {
                        InvokeOnMainThread(() =>
                        {
                            var alert = UIAlertController.Create("Please connect to the internet", "Internet access is required.", UIAlertControllerStyle.Alert);

                            alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Cancel, (obj) =>
                            {
                                RegistrationViewController registrationVC = (RegistrationViewController)((MultiStepProcessHorizontalViewController)this.ParentViewController).ContainerViewController;
                                //var firstStep = registrationVC.Steps.FirstOrDefault();
                                //registrationVC._pageViewController.SetViewControllers(new[] { firstStep as UIViewController }, UIPageViewControllerNavigationDirection.Reverse, true, (finished) =>
                                //{
                                //	if (finished)
                                //	{
                                //		//finalStep.StepActivated(this, new MultiStepProcessStepEventArgs());

                                //	}
                                //});
                                registrationVC.DismissViewController(true, null);
                            }));

                            PresentViewController(alert, animated: true, completionHandler: () =>
                            {
                            });
                        });
                    }
                }
                catch (Exception exe) {
                }
            }
                     );
        }
示例#2
0
        void ReleaseDesignerOutlets()
        {
            if (CompanyTextField != null)
            {
                CompanyTextField.Dispose();
                CompanyTextField = null;
            }

            if (ContainerView != null)
            {
                ContainerView.Dispose();
                ContainerView = null;
            }

            if (dismissButton != null)
            {
                dismissButton.Dispose();
                dismissButton = null;
            }

            if (finishButton != null)
            {
                finishButton.Dispose();
                finishButton = null;
            }

            if (FirstNameTextField != null)
            {
                FirstNameTextField.Dispose();
                FirstNameTextField = null;
            }

            if (LastNameTextField != null)
            {
                LastNameTextField.Dispose();
                LastNameTextField = null;
            }

            if (LocationsPicker != null)
            {
                LocationsPicker.Dispose();
                LocationsPicker = null;
            }

            if (MapCCodePickerView != null)
            {
                MapCCodePickerView.Dispose();
                MapCCodePickerView = null;
            }

            if (MobilePhoneTextField != null)
            {
                MobilePhoneTextField.Dispose();
                MobilePhoneTextField = null;
            }

            if (PageHeaderLabel != null)
            {
                PageHeaderLabel.Dispose();
                PageHeaderLabel = null;
            }

            if (PilotSegmentControl != null)
            {
                PilotSegmentControl.Dispose();
                PilotSegmentControl = null;
            }

            if (ProfileScrollView != null)
            {
                ProfileScrollView.Dispose();
                ProfileScrollView = null;
            }
        }