private async void btn_Clicked(object sender, EventArgs e)
        {
            Facolta fac            = listFacolta.Where(x => x.Nome == pickerFacoltà.Items[pickerFacoltà.SelectedIndex]).First();
            int     facolta        = fac.IdFacolta;
            string  db             = fac.DB;
            int     laureaId       = dictionaryLauree.Where(x => x.Key == pickerLaurea.Items[pickerLaurea.SelectedIndex]).First().Value;
            string  laurea         = dictionaryLauree.Where(x => x.Key == pickerLaurea.Items[pickerLaurea.SelectedIndex]).First().Key;
            int     anno           = pickerAnno.SelectedIndex;
            string  annoString     = anni[anno];
            string  semestre       = sem.Where(x => x.Key == pickerSemestre.Items[pickerSemestre.SelectedIndex]).First().Value;
            string  semestreString = sem.Where(x => x.Key == pickerSemestre.Items[pickerSemestre.SelectedIndex]).First().Key;
            bool    group          = pickerRaggruppa.SelectedIndex == 0 ? false : true;

            activityIndicator.IsVisible = true;

            //Settings.FacoltaIndex = pickerFacoltà.SelectedIndex;
            //Settings.LaureaIndex = pickerLaurea.SelectedIndex;
            //Settings.AnnoIndex = anno;
            Settings.Raggruppa = pickerRaggruppa.SelectedIndex;

            if (!CrossConnectivity.Current.IsConnected)               //non connesso a internet
            {
                activityIndicator.IsVisible = false;
                lblError.IsVisible          = true;
                var toast = DependencyService.Get <IToastNotificator>();
                await toast.Notify(ToastNotificationType.Error, "Errore", "Nessun accesso a internet", TimeSpan.FromSeconds(3));

                return;
            }

            string s = await Web.GetOrarioCompleto(semestre, db, facolta, laureaId, anno);

            if (s == string.Empty)
            {
                activityIndicator.IsVisible = false;
                lblError.IsVisible          = true;
                return;
            }

            List <CorsoCompleto> lista = Web.GetSingleOrarioCompleto(s);

            activityIndicator.IsVisible = false;

            if (lista.Count > 0)
            {
                var completoViewModel = new OrariCompletoViewModel()
                {
                    Facolta = fac, LaureaString = laurea, Anno = annoString, Semestre = semestreString, ListOrari = lista, Group = group
                };
                var nav = new OrarioCompleto();
                nav.BindingContext = completoViewModel;
                await this.Navigation.PushAsync(nav);

                //                await this.Navigation.PushAsync(new OrarioCompletoGroup(lista, fac.Nome, laurea, annoString, semestreString, group));
            }
            else
            {
                lblError.IsVisible = true;
                return;
            }
        }
        public SelectCompleto()
        {
            Title         = "Completo";
            Icon          = null;
            listFacolta   = Facolta.facolta;
            pickerFacoltà = new Picker()
            {
                Title = "Facoltà"
            };
            pickerLaurea = new Picker()
            {
                Title = "Corso di Laurea"
            };

            int index = 0;

            foreach (var f in listFacolta)
            {
                pickerFacoltà.Items.Add(f.Nome);
                if (f.IdFacolta == Settings.FacoltaId && f.DB == Settings.FacoltaDB)
                {
                    _facoltàIndex = index;
                }

                index++;
            }

            //pickerFacoltà.SelectedIndex = facoltàIndex;

            pickerFacoltà.SelectedIndexChanged += (sender, args) =>
            {
                var     s       = pickerFacoltà.Items[pickerFacoltà.SelectedIndex];
                Facolta facolta = listFacolta.Where(x => x.Nome == s).First();
                //dictionaryLauree = LaureeDictionary.getLauree(facolta).Where(x => x.Value != 0).ToDictionary(x => x.Key, x => x.Value);
                dictionaryLauree = LaureeDictionary.getLauree(facolta).Where(x => x.Value != 0).ToDictionary(x => x.Key, x => x.Value);
                pickerLaurea.Items.Clear();

                if (dictionaryLauree.Count == 0)
                {
                    return;
                }

                index = 0;
                foreach (var item in dictionaryLauree)
                {
                    pickerLaurea.Items.Add(item.Key);
                    if (item.Value == Settings.LaureaId)
                    {
                        _laureaIndex = index;
                    }

                    index++;
                }


                pickerLaurea.SelectedIndex = 0;
            };

            anni = new String[] { "TUTTI gli anni", "1° Anno", "2° Anno", "3° Anno", "4° Anno", "5° Anno" };

            pickerLaurea.SelectedIndexChanged += (sender, args) =>
            {
                int i = 0;
                pickerAnno.IsEnabled = true;

                if (pickerLaurea.Items.Count > 0)
                {
                    if (pickerLaurea.Items[pickerLaurea.SelectedIndex].Contains("Magistrale"))
                    {
                        limit = 5;
                    }
                    else if (pickerLaurea.Items[pickerLaurea.SelectedIndex].Contains("LM"))
                    {
                        limit = 2;
                    }
                    else
                    {
                        limit = 3;
                    }

                    pickerAnno.Items.Clear();
                    foreach (var x in anni)
                    {
                        if (i > limit)
                        {
                            break;
                        }
                        pickerAnno.Items.Add(x);
                        i++;
                    }
                    pickerAnno.SelectedIndex = 0;
                }
            };

            pickerAnno = new Picker()
            {
                Title = "Ordina per..",
            };

            pickerSemestre = new Picker()
            {
                Title = "Semestre"
            };
            sem = new Dictionary <string, string>()
            {
                { "Primo", "completo" }, { "Secondo", "secondo" }
            };

            pickerRaggruppa = new Picker()
            {
                Title = "Raggruppa per.."
            };
            ragg = new String[] { "Corso", "Giorno" };

            foreach (var x in anni)
            {
                pickerAnno.Items.Add(x);
            }

            foreach (var s in sem)
            {
                pickerSemestre.Items.Add(s.Key);
            }

            foreach (var g in ragg)
            {
                pickerRaggruppa.Items.Add(g);
            }

            //pickerFacoltà.SelectedIndex = Settings.FacoltaIndex;
            pickerFacoltà.SelectedIndex = _facoltàIndex;

            //if (Settings.LaureaIndex == 0)
            //    pickerLaurea.SelectedIndex = 0;
            //else
            pickerLaurea.SelectedIndex = _laureaIndex;
            //pickerLaurea.SelectedIndex = Settings.LaureaIndex;

            //pickerAnno.SelectedIndex = int.Parse(Settings.Anno) + 1;
            pickerAnno.SelectedIndex = (int)Settings.AnnoIndex;

            //Se siamo a Marzo, secondo semsestre
            pickerSemestre.SelectedIndex = DateTime.Today.Month >= new DateTime(2016, 03, 01).Month&& DateTime.Today.Month <= new DateTime(2016, 06, 01).Month ? 1 : 0;

            pickerRaggruppa.SelectedIndex = Settings.Raggruppa;

            lblError = new Label()
            {
                Text              = "ORARIO NON DISPONIBILE O IN CORSO DI DEFINIZIONE",
                TextColor         = ColorHelper.Red500,
                FontSize          = Device.GetNamedSize(NamedSize.Small, this),
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                IsVisible         = false,
            };
            activityIndicator = new ActivityIndicator()
            {
                IsVisible         = false,
                IsRunning         = true,
                HorizontalOptions = LayoutOptions.Fill
            };

            var btn = new Button()
            {
                VerticalOptions = LayoutOptions.EndAndExpand,
                Text            = "Ricerca",
                BackgroundColor = ColorHelper.Blue700,
                TextColor       = ColorHelper.White,
                BorderColor     = ColorHelper.White,
            };

            btn.Clicked += btn_Clicked;

            var layout = new StackLayout()
            {
                BackgroundColor   = ColorHelper.White,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Padding           = new Thickness(10, 10, 10, 10),
                Orientation       = StackOrientation.Vertical,
                Children          = { pickerFacoltà, pickerLaurea, pickerAnno, pickerSemestre, pickerRaggruppa, lblError, activityIndicator, btn }
            };

            Content = layout;
        }
        private StackLayout initLayout1_settings()
        {
            //TODO Picker numero di corsi e peso difficoltà
            listFacolta    = Facolta.facolta;
            _pickerFacoltà = new Picker()
            {
                Title = "Facoltà"
            };
            _pickerLaurea = new Picker()
            {
                Title = "Corso di Laurea"
            };

            int index = 0;

            foreach (var f in listFacolta)
            {
                _pickerFacoltà.Items.Add(f.Nome);
                if (f.IdFacolta == Settings.FacoltaId && f.DB == Settings.FacoltaDB)
                {
                    _facoltàIndex = index;
                }

                index++;
            }

            //pickerFacoltà.SelectedIndex = facoltàIndex;

            _pickerFacoltà.SelectedIndexChanged += (sender, args) =>
            {
                var     s       = _pickerFacoltà.Items[_pickerFacoltà.SelectedIndex];
                Facolta facolta = listFacolta.Where(x => x.Nome == s).First();
                //dictionaryLauree = LaureeDictionary.getLauree(facolta).Where(x => x.Value != 0).ToDictionary(x => x.Key, x => x.Value);
                dictionaryLauree = LaureeDictionary.getLauree(facolta).Where(x => x.Value != 0).ToDictionary(x => x.Key, x => x.Value);
                _pickerLaurea.Items.Clear();

                if (dictionaryLauree.Count == 0)
                {
                    return;
                }

                index = 0;
                foreach (var item in dictionaryLauree)
                {
                    _pickerLaurea.Items.Add(item.Key);
                    if (item.Value == Settings.LaureaId)
                    {
                        _laureaIndex = index;
                    }

                    index++;
                }


                _pickerLaurea.SelectedIndex = 0;
            };

            anni = new String[] { "TUTTI gli anni", "1° Anno", "2° Anno", "3° Anno", "4° Anno", "5° Anno" };

            _pickerLaurea.SelectedIndexChanged += (sender, args) =>
            {
                int i = 0;
                _pickerAnno.IsEnabled = true;

                if (_pickerLaurea.Items.Count > 0)
                {
                    if (_pickerLaurea.Items[_pickerLaurea.SelectedIndex].Contains("Magistrale"))
                    {
                        limit = 5;
                    }
                    else if (_pickerLaurea.Items[_pickerLaurea.SelectedIndex].Contains("LM"))
                    {
                        limit = 2;
                    }
                    else
                    {
                        limit = 3;
                    }

                    _pickerAnno.Items.Clear();
                    foreach (var x in anni)
                    {
                        if (i > limit)
                        {
                            break;
                        }
                        _pickerAnno.Items.Add(x);
                        i++;
                    }
                    _pickerAnno.SelectedIndex = 0;
                }
            };

            _pickerAnno = new Picker()
            {
                Title = "Ordina per..",
            };

            _pickerSemestre = new Picker()
            {
                Title = "Semestre"
            };
            sem = new Dictionary <string, string>()
            {
                { "Primo", "completo" }, { "Secondo", "secondo" }
            };

            foreach (var x in anni)
            {
                _pickerAnno.Items.Add(x);
            }

            foreach (var s in sem)
            {
                _pickerSemestre.Items.Add(s.Key);
            }

            //pickerFacoltà.SelectedIndex = Settings.FacoltaIndex;
            _pickerFacoltà.SelectedIndex = _facoltàIndex;

            //if (Settings.LaureaIndex == 0)
            //    pickerLaurea.SelectedIndex = 0;
            //else
            _pickerLaurea.SelectedIndex = _laureaIndex;
            //pickerLaurea.SelectedIndex = Settings.LaureaIndex;

            //pickerAnno.SelectedIndex = int.Parse(Settings.Anno) + 1;
            _pickerAnno.SelectedIndex = (int)Settings.AnnoIndex;

            //Se siamo a Marzo, secondo semsestre
            _pickerSemestre.SelectedIndex = DateTime.Today.Month >= new DateTime(2016, 03, 01).Month&& DateTime.Today.Month <= new DateTime(2016, 06, 01).Month ? 1 : 0;

            _pickerNumCorsi = new Picker()
            {
                Title = "Numero corsi"
            };
            for (int i = 1; i < 11; i++)
            {
                _pickerNumCorsi.Items.Add(i.ToString());
            }

            _pickerPesi = new Picker()
            {
                Title = "Ti pesa andare un giorno in più?"
            };
            _pickerPesi.Items.Add("Non è un problema!");
            _pickerPesi.Items.Add("Molto! Preferirei evitare");

            lblError = new Label()
            {
                Text              = "ORARIO NON DISPONIBILE O IN CORSO DI DEFINIZIONE",
                TextColor         = ColorHelper.Red500,
                FontSize          = Device.GetNamedSize(NamedSize.Small, this),
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                IsVisible         = false,
            };
            activityIndicator = new ActivityIndicator()
            {
                IsVisible         = false,
                IsRunning         = true,
                HorizontalOptions = LayoutOptions.Fill
            };

            var btn = new Button()
            {
                VerticalOptions = LayoutOptions.EndAndExpand,
                Text            = "Avanti",
                BackgroundColor = ColorHelper.Blue700,
                TextColor       = ColorHelper.White,
                BorderColor     = ColorHelper.White,
            };

            btn.Clicked += btnSettings_Clicked;

            var layout = new StackLayout()
            {
                BackgroundColor   = ColorHelper.White,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Padding           = new Thickness(15, 10, 15, 10),
                Orientation       = StackOrientation.Vertical,
                Children          = { _pickerFacoltà, _pickerLaurea, _pickerAnno, _pickerSemestre, _pickerNumCorsi, _pickerPesi, lblError, activityIndicator, btn }
            };

            return(layout);
        }
        private async void btnSettings_Clicked(object sender, EventArgs e)
        {
            lblError.IsVisible = false;

            _fac = listFacolta.Where(x => x.Nome == _pickerFacoltà.Items[_pickerFacoltà.SelectedIndex]).First();
            int    facolta  = _fac.IdFacolta;
            string db       = _fac.DB;
            int    laureaId = dictionaryLauree.Where(x => x.Key == _pickerLaurea.Items[_pickerLaurea.SelectedIndex]).First().Value;

            _laurea = dictionaryLauree.Where(x => x.Key == _pickerLaurea.Items[_pickerLaurea.SelectedIndex]).First().Key;
            int anno = _pickerAnno.SelectedIndex;

            _annoString = anni[anno];
            string semestre = sem.Where(x => x.Key == _pickerSemestre.Items[_pickerSemestre.SelectedIndex]).First().Value;

            _semestreString = sem.Where(x => x.Key == _pickerSemestre.Items[_pickerSemestre.SelectedIndex]).First().Key;

            NUM_CORSI = _pickerNumCorsi.SelectedIndex + 1;

            int peso = _pickerPesi.SelectedIndex;

            if (peso == 0)
            {
                PESO_GIORNO          = 1;
                PESO_SOVRAPPOSIZIONE = 5;
            }
            else
            {
                PESO_GIORNO          = 10;
                PESO_SOVRAPPOSIZIONE = 1;
            }

            if (!CrossConnectivity.Current.IsConnected)
            { //non connesso a internet
                //activityIndicator.IsVisible = false;
                lblError.IsVisible = true;
                var toast = DependencyService.Get <IToastNotificator>();
                await toast.Notify(ToastNotificationType.Error, "Errore", "Nessun accesso a internet", TimeSpan.FromSeconds(3));

                return;
            }

            if (_pickerNumCorsi.SelectedIndex == -1 || _pickerPesi.SelectedIndex == -1)
            {
                var toast = DependencyService.Get <IToastNotificator>();
                await toast.Notify(ToastNotificationType.Warning, "Attenzione", "Devi completare tutti i campi", TimeSpan.FromSeconds(3));

                //activityIndicator.IsVisible = false;
                return;
            }

            activityIndicator.IsVisible = true;

            string s = await Web.GetOrarioCompleto(semestre, db, facolta, laureaId, anno);

            if (s == string.Empty)
            {
                activityIndicator.IsVisible = false;
                lblError.IsVisible          = true;
                return;
            }

            _listSource = Web.GetSingleOrarioCompleto(s);

            if (_listSource.Count() == 0)
            {
                activityIndicator.IsVisible = false;
                lblError.IsVisible          = true;
                return;
            }

            _listaGroup = _listSource.GroupBy(x => x.Semestre);

            var _listaGroupObb = _listaGroup;

            _listViewObbligatori.ItemsSource = _listaGroupObb;

            var _listaGroupSce = _listSource.GroupBy(x => x.Semestre);

            _listViewScelta.ItemsSource = _listaGroupSce;

            activityIndicator.IsVisible = false;

            _viewModel = new OrariCompletoViewModel()
            {
                Facolta = _fac, LaureaString = _laurea, Anno = _annoString, Semestre = _semestreString, Group = false
            };

            //_index++;
            //this.CurrentPage = this.Children[_index];

            _index           = this.Children.IndexOf(page2_obbligatori);
            this.CurrentPage = this.Children[_index];

            //List<CorsoCompleto> lista = Web.GetSingleOrarioCompleto(s);
            //activityIndicator.IsVisible = false;
        }
Example #5
0
        private View getView()
        {
            listFacolta   = Facolta.facolta;
            pickerFacoltà = new Picker()
            {
                Title = "Facoltà"
            };
            pickerLaurea = new Picker()
            {
                Title = "Corso di Laurea"
            };

            var index = 0;

            foreach (var f in listFacolta)
            {
                pickerFacoltà.Items.Add(f.Nome);
                if (f.IdFacolta == Settings.FacoltaId && f.DB == Settings.FacoltaDB)
                {
                    _facoltàIndex = index;
                }

                index++;
            }

            pickerFacoltà.SelectedIndexChanged += (sender, args) =>
            {
                var     s       = pickerFacoltà.Items[pickerFacoltà.SelectedIndex];
                Facolta facolta = listFacolta.Where(x => x.Nome == s).First();
                dictionaryLauree = LaureeDictionary.getLauree(facolta);
                pickerLaurea.Items.Clear();

                index = 0;
                foreach (var item in dictionaryLauree)
                {
                    pickerLaurea.Items.Add(item.Key);
                    if (item.Value == Settings.LaureaId)
                    {
                        _laureaIndex = index;
                    }

                    index++;
                }

                pickerLaurea.SelectedIndex = 0;
            };

            pickData = new DatePicker()
            {
                Format = "D"
            };

            pickerOrder = new Picker()
            {
                Title = "Ordina per..",
            };
            String[] ordina = new String[] { "Alfabetico", "Orario" };

            foreach (var x in ordina)
            {
                pickerOrder.Items.Add(x);
            }

            pickerFacoltà.SelectedIndex = _facoltàIndex;
            pickerLaurea.SelectedIndex  = _laureaIndex; //devo tenere conto di GENERALE
            pickerOrder.SelectedIndex   = Settings.Order;

            var btn = new Button()
            {
                VerticalOptions = LayoutOptions.EndAndExpand,
                Text            = "Ricerca",
                BackgroundColor = ColorHelper.Blue700,
                TextColor       = ColorHelper.White,
                BorderColor     = ColorHelper.White,
            };

            activityIndicator = new ActivityIndicator()
            {
                IsVisible         = false,
                IsRunning         = true,
                HorizontalOptions = LayoutOptions.Fill
            };

            lblError = new Label()
            {
                Text              = "ORARIO NON DISPONIBILE O IN CORSO DI DEFINIZIONE",
                TextColor         = ColorHelper.Red500,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                FontSize          = Device.GetNamedSize(NamedSize.Small, this),
                IsVisible         = false,
            };

            btn.Clicked += btn_Clicked;
            var layout = new StackLayout()
            {
                BackgroundColor   = ColorHelper.White,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Padding           = new Thickness(10, 10, 10, 10),
                Orientation       = StackOrientation.Vertical,
                Children          = { pickerFacoltà, pickerLaurea, pickData, pickerOrder, lblError, activityIndicator, btn, }
            };

            return(layout);
        }
        private View getView()
        {
            var lblWelcome = new Label()
            {
                Text = string.Format("Welcome {0}", Settings.Name), HorizontalOptions = LayoutOptions.CenterAndExpand
            };

            listFacolta = Facolta.facolta;

            _imgAvatar = new CircleImage
            {
                BorderColor       = Color.White,
                BorderThickness   = 1,
                HeightRequest     = 150,
                WidthRequest      = 150,
                Aspect            = Aspect.AspectFill,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.StartAndExpand,
            };

            if (Settings.Picture != string.Empty)
            {
                _imgAvatar.Source = Settings.Picture;
            }
            //else //immagine predefinita o possibilità di caricare una propria foto????

            _entryNome = new Entry()
            {
                Placeholder = "Nome",
                //Text = "Lorenzo",
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Keyboard          = Keyboard.Text,
                Text = Settings.GivenName
            };
            _entryCognome = new Entry()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                //Text = "Giudici",
                Placeholder = "Cognome",
                Keyboard    = Keyboard.Text,
                Text        = Settings.Surname
            };

            _entryCognome.TextChanged += _entryCognome_TextChanged;
            _entryMail = new Entry()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Text = Settings.Username,
                //Placeholder = "n.cognome2"
            };
            _entryMatricola = new Entry()
            {
                Placeholder = "Matr.",
                //Text = "1020589",
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };

            _pickFacolta = new Picker()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Title             = "Facoltà"
            };
            _pickLaurea = new Picker()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Title             = "Laurea",
                IsEnabled         = false,
            };
            _pickAnno = new Picker()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Title             = "Anno",
                IsEnabled         = false
            };

            foreach (var f in listFacolta)
            {
                _pickFacolta.Items.Add(f.Nome);
            }

            _pickFacolta.SelectedIndexChanged += (sender, args) =>
            {
                var     s       = _pickFacolta.Items[_pickFacolta.SelectedIndex];
                Facolta facolta = listFacolta.Where(x => x.Nome == s).First();
                dictionaryLauree = LaureeDictionary.getLauree(facolta).Where(x => x.Value != 0).ToDictionary(x => x.Key, x => x.Value);
                _pickLaurea.Items.Clear();

                foreach (var item in dictionaryLauree)
                {
                    _pickLaurea.Items.Add(item.Key);
                }

                _pickLaurea.SelectedIndex = 0;
                _pickLaurea.IsEnabled     = true;
            };

            String[] anni = new String[] { "1° Anno", "2° Anno", "3° Anno", "4° Anno", "5° Anno" };
            _pickLaurea.SelectedIndexChanged += (sender, args) =>
            {
                int i = 1;
                _pickAnno.IsEnabled = true;

                if (_pickLaurea.Items.Count > 0)
                {
                    if (_pickLaurea.Items[_pickLaurea.SelectedIndex].Contains("Magistrale"))
                    {
                        limit = 5;
                    }
                    else if (_pickLaurea.Items[_pickLaurea.SelectedIndex].Contains("LM"))
                    {
                        limit = 2;
                    }
                    else
                    {
                        limit = 3;
                    }

                    _pickAnno.Items.Clear();
                    foreach (var x in anni)
                    {
                        if (i > limit)
                        {
                            break;
                        }
                        _pickAnno.Items.Add(x);
                        i++;
                    }
                    _pickAnno.SelectedIndex = 0;
                }
            };

            _lblNotific = new Label()
            {
                HorizontalOptions = LayoutOptions.StartAndExpand,
                Text = "Notifiche variazioni lezioni"
            };
            _switchSync = new Switch()
            {
                IsToggled = true
            };

            _lblSync = new Label()
            {
                HorizontalOptions = LayoutOptions.StartAndExpand,
                Text = "Aggiornamento in bakgruound"
            };
            _switchNotific = new Switch()
            {
                IsToggled = true
            };

            _activityIndicator = new ActivityIndicator()
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                IsRunning         = true,
                IsVisible         = false,
            };

            var grid = new Grid()
            {
                Padding           = new Thickness(15, 5, 15, 5),
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                RowSpacing        = 8,
                ColumnSpacing     = 8,
                RowDefinitions    =
                {
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                },
                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(0.6, GridUnitType.Star)
                    },
                }
            };

            //DA AGGIUNGERE ROW CON LABEL WELCOM NOME
            grid.Children.Add(_imgAvatar, 0, 2, 0, 1);
            grid.Children.Add(_entryNome, 0, 2, 1, 2);
            grid.Children.Add(_entryCognome, 0, 2, 2, 3);
            grid.Children.Add(_entryMail, 0, 1, 3, 4);
            grid.Children.Add(_entryMatricola, 1, 2, 3, 4);
            grid.Children.Add(_pickFacolta, 0, 2, 4, 5);
            grid.Children.Add(_pickLaurea, 0, 1, 5, 6);
            grid.Children.Add(_pickAnno, 1, 2, 5, 6);
            grid.Children.Add(_lblSync, 0, 1, 6, 7);
            grid.Children.Add(_switchSync, 1, 2, 6, 7);
            grid.Children.Add(_lblNotific, 0, 1, 7, 8);
            grid.Children.Add(_switchNotific, 1, 2, 7, 8);
            grid.Children.Add(_activityIndicator, 0, 2, 8, 9);

//            tbiNext = new ToolbarItem("Avanti", "ic_next.png", toolbarItem_next, 0, 0);
//            //if (Device.OS == TargetPlatform.Android)
//            //{ // BUG: Android doesn't support the icon being null
//            //    tbiNext = new ToolbarItem("Avanti", "ic_menu.png", () =>
//            //    {
//            //        Navigation.PushAsync(new MasterDetailView());
//            //    }, 0, 0);
//            //}
//            //if (Device.OS == TargetPlatform.WinPhone)
//            //{
//            //    tbi = new ToolbarItem("Avanti", "ic_menu.png", () =>
//            //    {
//            //        Navigation.PushAsync(new MasterDetailView());
//            //    }, 0, 0);
//            //}
//            ToolbarItems.Add(tbiNext);
            return(grid);
        }
        private async void toolbarItem_next()
        {
            if (_entryNome.Text == string.Empty || _entryCognome.Text == string.Empty || _entryMatricola.Text == string.Empty || _pickFacolta.SelectedIndex < 0)
            {
                await DisplayAlert("ATTENZIONE", "Occorre compilare tutti i campi correttmente prima di procedere.", "OK");

                return;
            }

            CheckNetwork();

            ToolbarItems.Remove(tbiNext);
            _activityIndicator.IsVisible = true;

            Facolta fac          = listFacolta.Where(x => x.Nome == _pickFacolta.Items[_pickFacolta.SelectedIndex]).First();
            int     facoltaId    = fac.IdFacolta;
            int     facoltaIndex = _pickFacolta.SelectedIndex;
            string  facolta      = fac.Nome;
            string  db           = fac.DB;
            int     laureaId     = dictionaryLauree.Where(x => x.Key == _pickLaurea.Items[_pickLaurea.SelectedIndex]).First().Value;
            int     laureaIndex  = _pickLaurea.SelectedIndex;
            string  laurea       = _pickLaurea.Items[_pickLaurea.SelectedIndex];
            int     annoIndex    = _pickAnno.SelectedIndex + 1;
            string  anno         = _pickAnno.Items[annoIndex - 1];

            Settings.Name      = _entryNome.Text.TrimEnd();
            Settings.GivenName = _entryCognome.Text.TrimEnd();
            Settings.Email     = _entryMail.Text.Trim() + "@studenti.unibg.it";


            Settings.Facolta        = facolta;
            Settings.FacoltaDB      = db;
            Settings.Laurea         = laurea;
            Settings.Anno           = anno;
            Settings.BackgroundSync = _switchSync.IsToggled;
            Settings.Notify         = _switchNotific.IsToggled;

            Settings.Matricola    = _entryMatricola.Text;
            Settings.FacoltaId    = facoltaId;
            Settings.LaureaId     = laureaId;
            Settings.LaureaIndex  = laureaIndex;
            Settings.FacoltaIndex = facoltaIndex;
            Settings.AnnoIndex    = annoIndex;

            Settings.CreatedAtString = _service.User.CreatedAt.Date.ToString("d");
            Settings.UpdatedAtString = _service.User.CreatedAt.Date.ToString("d");

            _service.User.BackgroundSync = Settings.BackgroundSync;

            //aggiornamento User
            _service.User.Matricola = _entryMatricola.Text;
            _service.User.FacoltaDB = db;
            _service.User.FacoltaId = facoltaId;
            _service.User.LaureaId  = laureaId;
            _service.User.AnnoIndex = annoIndex;

            await _service.UpdateUser();

            if (!CrossConnectivity.Current.IsConnected)   //non connesso a internet
            {
                var toast = DependencyService.Get <IToastNotificator> ();
                await toast.Notify(ToastNotificationType.Error, "Errore", "Nessun accesso a internet", TimeSpan.FromSeconds(3));

                ToolbarItems.Add(tbiNext);
                return;
            }

            string completo = await Web.GetOrarioCompleto("completo", db, facoltaId, laureaId, annoIndex);

            string secondo = await Web.GetOrarioCompleto("secondo", db, facoltaId, laureaId, annoIndex);

            List <CorsoCompleto> lista_completo = Web.GetSingleOrarioCompleto(completo);
            List <CorsoCompleto> lista_secondo  = Web.GetSingleOrarioCompleto(secondo);

            if (lista_completo.Count() != 0 && lista_completo.FirstOrDefault().Semestre == 1)
            {
                lista_completo.AddRange(lista_secondo);
            }

//            _activityIndicator.IsVisible = false;

            Settings.PrimoAvvio   = false;
            Settings.SuccessLogin = true;

            //var nav = new NavigationPage (new ListaCorsi(lista_completo) { Service = _service}) {
            //	BarBackgroundColor = ColorHelper.Blue700,
            //	BarTextColor = ColorHelper.White
            //};

            await Navigation.PushAsync(new ListaCorsi(lista_completo) { Service = _service });
        }