public TestPage()
        {
            var       test = new AppSettings();
            String    output;
            LineEntry input = new LineEntry("Input Setting");

            Button save = new Button()
            {
                Text = "Save"
            };

            save.Clicked += (sender, e) =>
            {
                AppSettings.SaveSettings("Test", input.data);
            };

            Button recall = new Button()
            {
                Text = "Recall"
            };

            recall.Clicked += (sender, e) =>
            {
                output = AppSettings.RetrieveSettings("Test");
                DisplayAlert("Output", output, "OK");
            };

            Content = new StackLayout()
            {
                Children =
                {
                    input,
                    save,
                    recall
                }
            };
        }
Example #2
0
        public PreMatchScoutingPage(string scouterName)
        {
            //Page Title
            Title = "Match Scouting";

            if (!string.IsNullOrEmpty(scouts.scouterName))
            {
                scouts.lineEntry.Text            = scouterName;
                matchNoLineEntry.inputEntry.Text = "";
                matchNumber = "";
            }

            var checkBoxLayout = new StackLayout()
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Orientation       = StackOrientation.Horizontal
            };

            for (int i = 0; i < matchPhaseCheckboxes.Length; i++)
            {
                matchPhaseCheckboxes[i] = new CheckBox()
                {
                    DefaultText = matchPhase[i],
                    FontSize    = GlobalVariables.sizeSmall
                }
            }
            ;

            foreach (var box in matchPhaseCheckboxes)
            {
                box.CheckedChanged += (sender, e) => {
                    if (!semaphore)
                    {
                        checkBoxChanged(box);
                    }
                };
                checkBoxLayout.Children.Add(box);
            }
            getDefaultMatchType();

            setNoLbl = new Label {
                Text           = "Set Number:",
                FontSize       = GlobalVariables.sizeSmall,
                FontAttributes = FontAttributes.Bold,
            };

            setNoPicker.Title = "[Select Set No.]";
            setNoPicker.SelectedIndexChanged += (sender, e) => {
                try {
                    setNumber = Convert.ToInt32(setNoPicker.Items[setNoPicker.SelectedIndex]);
                }
                catch (Exception ex) {
                    Console.WriteLine("Error: " + ex.Message);
                }
                setMatchNumber();
            };

            matchNoLineEntry = new LineEntry("Match Number:");
            matchNoLineEntry.inputEntry.Keyboard     = Keyboard.Numeric;
            matchNoLineEntry.inputEntry.TextChanged += (sender, e) => {
                setMatchNumber();
            };

            matchNoLayout = new StackLayout()
            {
                Orientation = StackOrientation.Horizontal,
                Spacing     = 10,

                Children =
                {
                    new StackLayout()
                    {
                        Children =
                        {
                            setNoLbl,
                            setNoPicker
                        }
                    },
                    matchNoLineEntry
                }
            };

            matchNoView = new ContentView()
            {
                Content = matchNoLineEntry
            };

            Label allianceLabel = new Label {
                Text           = "Alliance:",
                FontSize       = GlobalVariables.sizeSmall,
                FontAttributes = FontAttributes.Bold
            };

            alliancePicker       = new Picker();
            alliancePicker.Title = "[Choose an Option]";
            foreach (var i in alliances)
            {
                alliancePicker.Items.Add(i);
            }
            alliancePicker.SelectedIndexChanged += (sender, e) => {
                setMatchNumber();
            };

            var teamNoLbl = new Label {
                Text           = "Team Number:",
                FontSize       = GlobalVariables.sizeSmall,
                FontAttributes = FontAttributes.Bold
            };

            teamNoPicker       = new Picker();
            teamNoPicker.Title = "[Select Match No. and Alliance first]";

            teamNoPicker.SelectedIndexChanged += (sender, e) => {
                try {
                    teamNumber = Convert.ToInt32(teamNoPicker.Items[teamNoPicker.SelectedIndex]);
                }
                catch (Exception ex) {
                    Console.WriteLine("Error: " + ex.Message);
                }
            };

            teamNoPickerLayout = new StackLayout()
            {
                Children =
                {
                    teamNoLbl,
                    teamNoPicker
                }
            };

            teamNoView = new ContentView()
            {
                Content = teamNoPickerLayout
            };

            teamNoLineEntry = new LineEntry("Team Number:");
            teamNoLineEntry.inputEntry.Placeholder  = "[Enter Team Number]";
            teamNoLineEntry.inputEntry.Keyboard     = Keyboard.Numeric;
            teamNoLineEntry.inputEntry.TextChanged += (sender, e) => {
                try {
                    teamNumber = Convert.ToInt32(teamNoLineEntry.data);
                }
                catch {
                    teamNumber = 0;
                }
            };

            Label positionLabel = new Label {
                Text           = "Starting Position:",
                FontSize       = GlobalVariables.sizeSmall,
                FontAttributes = FontAttributes.Bold
            };

            positionPicker       = new Picker();
            positionPicker.Title = "Choose an Option";
            foreach (var i in startPos)
            {
                positionPicker.Items.Add(i);
            }

            positionPicker.SelectedIndexChanged += (sender, e) => {
                positionPicker.Title = positionPicker.Items[positionPicker.SelectedIndex];
            };

            var beginMatchBtn = new Button()
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Text            = "Begin Match",
                TextColor       = Color.Green,
                BackgroundColor = Color.Black,
                FontSize        = GlobalVariables.sizeMedium
            };

            beginMatchBtn.Clicked += (sender, e) => {
                bool inputFlag = false;
                if (string.IsNullOrEmpty(scouts.lineEntry.Text))
                {
                    inputFlag = true;
                }
                if (string.IsNullOrEmpty(matchNoLineEntry.inputEntry.Text))
                {
                    inputFlag = true;
                }
                if ((teamNoPicker.SelectedIndex == -1 && (competitionPhase == "F" || competitionPhase == "QM")) ||
                    (teamNoPicker.SelectedIndex == -1 && setNoPicker.SelectedIndex == -1 && (competitionPhase == "QF" || competitionPhase == "SF")) ||
                    (string.IsNullOrEmpty(teamNoLineEntry.inputEntry.Text) && competitionPhase == "P"))
                {
                    inputFlag = true;
                }

                if (positionPicker.SelectedIndex == -1 || alliancePicker.SelectedIndex == -1 || inputFlag)
                {
                    DisplayAlert("Error", "Fill out all inputs", "OK");
                }
                else
                {
                    initializeTeamData();
                }
            };

            var navigationBtns = new NavigationButtons(false, new Button[] { beginMatchBtn });

            navigationBtns.backBtn.Clicked += (sender, e) => {
                Navigation.PopModalAsync();
            };

            var pageLayout = new StackLayout()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,

                Children =
                {
                    busyIcon,
                    scouts,
                    checkBoxLayout,
                    matchNoView,
                    allianceLabel,
                    alliancePicker,
                    teamNoView,
                    positionLabel,
                    positionPicker
                }
            };

            var dataScroll = new ScrollView()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,

                Content = pageLayout
            };

            var grid = new Grid()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,

                RowDefinitions =
                {
                    new RowDefinition {
                        Height = GridLength.Star
                    },
                    new RowDefinition {
                        Height = GridLength.Auto
                    }
                }
            };

            grid.Children.Add(dataScroll, 0, 0);
            grid.Children.Add(navigationBtns, 0, 1);

            Content = grid;
        }

        async Task getDefaultMatchType()
        {
            if (CheckInternetConnectivity.InternetStatus())
            {
                var db = new FirebaseClient(GlobalVariables.firebaseURL);

                var phaseGet = await db
                               .Child(GlobalVariables.regionalPointer)
                               .Child("competitionPhase")
                               .OnceSingleAsync <string>();

                int i = 0;
                foreach (var phase in matchPhase)
                {
                    if (phase == phaseGet)
                    {
                        break;
                    }
                    i++;
                }
                checkBoxChanged(matchPhaseCheckboxes[i]);
            }
        }

        void checkBoxChanged(CheckBox c)
        {
            semaphore = true;
            for (int i = 0; i < matchPhaseCheckboxes.Length; i++)
            {
                if (matchPhaseCheckboxes[i] != c)
                {
                    matchPhaseCheckboxes[i].Checked = false;
                }
                else
                {
                    matchPhaseCheckboxes[i].Checked = true;
                    competitionPhase = matchPhase[i];
                }
            }
            setMatchTeamNumberLayout();

            if (competitionPhase != "QF" || competitionPhase != "SF")
            {
                teamNoPicker.Items.Clear();
                teamNoPicker.SelectedIndex = -1;
                teamNoPicker.Title         = "[Select A Team]";
            }
            else
            {
                setMatchNumber();
            }

            semaphore = false;
        }

        void setMatchTeamNumberLayout()
        {
            if (competitionPhase == "P")
            {
                teamNoView.Content = teamNoLineEntry;
                matchNoLayout.Children.Remove(matchNoLineEntry);
            }
            else
            {
                teamNoView.Content = teamNoPickerLayout;

                if (competitionPhase == "QM" || competitionPhase == "F")
                {
                    matchNoView.Content = matchNoLineEntry;
                    matchNoLayout.Children.Remove(matchNoLineEntry);
                }
                else
                {
                    matchNoView.Content = matchNoLayout;
                    matchNoLayout.Children.Add(matchNoLineEntry);
                    setNoPicker.Items.Clear();

                    int items = 0;
                    if (competitionPhase == "QF")
                    {
                        items = 4;
                    }
                    else
                    {
                        items = 2;
                    }

                    for (int i = 1; i <= items; i++)
                    {
                        setNoPicker.Items.Add(i.ToString());
                    }
                }
            }
        }

        async Task setMatchNumber()
        {
            if (competitionPhase == "QF" || competitionPhase == "SF")
            {
                matchNumber = competitionPhase + (setNoPicker.SelectedIndex + 1) + "M" + matchNoLineEntry.inputEntry.Text;
            }
            else if (competitionPhase == "F")
            {
                matchNumber = competitionPhase + matchNoLineEntry.inputEntry.Text;
            }
            else
            {
                matchNumber = competitionPhase + (Convert.ToInt64(matchNoLineEntry.inputEntry.Text) < 10 ? "0" + matchNoLineEntry.inputEntry.Text : matchNoLineEntry.inputEntry.Text);
            }

            if (!matchPhaseCheckboxes[0].Checked)
            {
                await getTeamNoPickerOptions();
            }
        }

        async Task getTeamNoPickerOptions()
        {
            if (CheckInternetConnectivity.InternetStatus())
            {
                try {
                    busyIcon.IsVisible = true;
                    busyIcon.IsRunning = true;

                    var            db       = new FirebaseClient(GlobalVariables.firebaseURL);
                    EventMatchData matchGet = new EventMatchData();

                    matchGet = await db
                               .Child(GlobalVariables.regionalPointer)
                               .Child("matchList")
                               .Child(matchNumber.ToString())
                               .OnceSingleAsync <EventMatchData>();

                    Console.WriteLine("Match: " + matchNoLineEntry.inputEntry.Text + " , Alliance: " + alliancePicker.Items[alliancePicker.SelectedIndex]);

                    teamNoPicker.Items.Clear();
                    if (string.IsNullOrEmpty(matchGet.matchNumber))
                    {
                        teamNoPicker.Title = "[Select Match No. and Alliance first]";
                    }
                    else
                    {
                        teamNoPicker.Title = "[Select A Team]";

                        if (alliancePicker.SelectedIndex == 0)
                        {
                            foreach (var item in matchGet.Red)
                            {
                                teamNoPicker.Items.Add(item.ToString());
                            }
                        }
                        else if (alliancePicker.SelectedIndex == 1)
                        {
                            foreach (var item in matchGet.Blue)
                            {
                                teamNoPicker.Items.Add(item.ToString());
                            }
                        }
                    }

                    busyIcon.IsVisible = false;
                    busyIcon.IsRunning = false;
                }  catch (Exception e) {
                    Console.WriteLine("Error: " + e.Message);
                }
            }
        }

        async Task initializeTeamData()
        {
            busyIcon.IsVisible = true;
            busyIcon.IsRunning = true;
            int matchType = 0;

            matchData.scouterName = scouts.lineEntry.Text;;
            matchData.matchNumber = matchNumber;
            matchData.teamNumber  = teamNumber;
            matchData.matchID     = teamNumber + "-" + matchNumber;
            matchData.alliance    = alliancePicker.Items[alliancePicker.SelectedIndex];
            matchData.startPos    = positionPicker.Items[positionPicker.SelectedIndex];

            if (CheckInternetConnectivity.InternetStatus())
            {
                bool   test = true;
                var    db   = new FirebaseClient(GlobalVariables.firebaseURL);
                string path = "NULL";


                if (competitionPhase != "P")
                {
                    path      = "matchData/" + matchData.matchID;
                    matchType = 0;
                }
                else
                {
                    path      = "practiceMatchData/" + matchData.matchID;
                    matchType = -1;
                }

                if (await FirebaseAccess.checkExistingMatchData(db, path))
                {
                    if (!await DisplayAlert("Error", "Match Data already exists for this team-match. Do you want to overwrite it?", "OK", "Cancel"))
                    {
                        test = false;
                    }
                }

                if (test)
                {
                    FirebaseAccess.saveData(db, path, matchData);

                    await Navigation.PushModalAsync(new AutoMatchScoutingPage(matchData, matchType));
                }

                /*
                 * if (checkValue == 1) {
                 *
                 *      var dataCheck = await db
                 *                                      .Child(GlobalVariables.regionalPointer)
                 *                                      .Child("teamMatchData")
                 *                                      .Child(matchData.teamNumber.ToString())
                 *                                      .Child(matchData.matchNumber)
                 *                                      .OnceSingleAsync<TeamMatchData>();
                 *
                 *      if (dataCheck != null)
                 *              if (!await DisplayAlert("Error", "Match Data already exists for this team. Do you want to overwrite it?", "OK", "Cancel"))
                 *                      test = false;
                 *
                 *      if(test){
                 *              var send = db
                 *                              .Child(GlobalVariables.regionalPointer)
                 *                              .Child("teamMatchData")
                 *                              .Child(matchData.teamNumber.ToString())
                 *                              .Child(matchData.matchNumber)
                 *                              .PutAsync(matchData);
                 *
                 *              matchType = 0;
                 *
                 *              await Navigation.PushAsync(new AutoMatchScoutingPage(matchData, matchType));
                 *      }
                 * } else {
                 *      var dataCheck = await db
                 *                                      .Child(GlobalVariables.regionalPointer)
                 *                                      .Child("PracticeMatches")
                 *                                      .Child(matchData.teamNumber.ToString())
                 *                                      .Child(matchData.matchNumber)
                 *                                      .OnceSingleAsync<TeamMatchData>();
                 *
                 *      if (dataCheck != null)
                 *              if (!await DisplayAlert("Error", "Match Data already exists for this team. Do you want to overwrite it?", "OK", "Cancel"))
                 *                      test = false;
                 *
                 *      if(test) {
                 *              var send = db
                 *                              .Child(GlobalVariables.regionalPointer)
                 *                              .Child("PracticeMatches")
                 *                              .Child(matchData.teamNumber.ToString())
                 *                              .Child(matchData.matchNumber)
                 *                              .PutAsync(matchData);
                 *
                 *              matchType = -1;
                 *
                 *              await Navigation.PushAsync(new AutoMatchScoutingPage(matchData, matchType));
                 *      }
                 *
                 * }
                 */
            }
            busyIcon.IsVisible = false;
            busyIcon.IsRunning = false;
        }
    }
        public AdminLoginPopup()
        {
            Title = "Admin Page";

            var pageGrid = new Grid()
            {
                RowDefinitions =
                {
                    new RowDefinition()
                    {
                        Height = GridLength.Auto
                    },
                    new RowDefinition()
                    {
                        Height = GridLength.Auto
                    },
                    new RowDefinition()
                    {
                        Height = GridLength.Auto
                    }
                }
            };

            var pw = new LineEntry("Enter Password:"******"Remember Login"
            };
            var loginBtn = new Button()
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Text            = "Login",
                TextColor       = Color.Green,
                BackgroundColor = Color.Black,
                FontSize        = GlobalVariables.sizeMedium
            };

            loginBtn.Clicked += (sender, e) => {
                if (pw.inputEntry.Text == "DaV1nc1")
                {
                    if (checkBox.Checked)
                    {
                        AppSettings.SaveSettings("AdminLogin", "true");
                    }

                    pw.inputEntry.Text = null;
                    Navigation.PopPopupAsync();
                    Navigation.PushModalAsync(new AdminPage());
                }
                else
                {
                    DisplayAlert("Error", "Incorrect password", "OK");
                }
            };

            Button[] btnArray       = { loginBtn };
            var      navigationBtns = new PopupNavigationButtons(false, btnArray);


            pageGrid.Children.Add(pw, 0, 0);
            pageGrid.Children.Add(checkBox, 0, 1);
            pageGrid.Children.Add(navigationBtns, 0, 2);

            Content = new Frame()
            {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                Margin            = GlobalVariables.popupMargin,
                Padding           = new Thickness(5),

                BackgroundColor = Color.Gray,
                HasShadow       = true,

                Content = pageGrid
            };
        }
        public AdminPage()
        {
            Title = "Admin Page";

            var updateMatchListBtn = new Button()
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Text            = "Update Match List",
                TextColor       = Color.Green,
                BackgroundColor = Color.Black,
                FontSize        = GlobalVariables.sizeMedium
            };

            updateMatchListBtn.Clicked += (sender, e) => {
                UpdateMatchList();
            };

            var updateTeamListBtn = new Button()
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Text            = "Update Team List",
                TextColor       = Color.Green,
                BackgroundColor = Color.Black,
                FontSize        = GlobalVariables.sizeMedium
            };

            updateTeamListBtn.Clicked += (sender, e) => {
                UpdateTeamList();
            };

            var eventStatTestBtn = new Button()
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Text            = "Test OPR Grab",
                TextColor       = Color.Green,
                BackgroundColor = Color.Black,
                FontSize        = GlobalVariables.sizeMedium
            };

            eventStatTestBtn.Clicked += (sender, e) => {
                //getEventStats();
            };

            var updateTeamStats = new LineEntry("Update Single Team Stats");

            updateTeamStats.inputEntry.Placeholder = "Enter Team No.";
            updateTeamStats.inputEntry.Keyboard    = Keyboard.Numeric;
            var singleTeamStatUpdateBtn = new Button()
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Text            = "Update",
                TextColor       = Color.Green,
                BackgroundColor = Color.Black,
                FontSize        = GlobalVariables.sizeMedium
            };

            singleTeamStatUpdateBtn.Clicked += (sender, e) => {
                //updateAvgTeamData(Convert.ToInt32(updateTeamStats.data), true);
            };

            var singleTeamStatUpdateView = new StackLayout()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Orientation       = StackOrientation.Horizontal,
                Spacing           = 1,
                Children          =
                {
                    updateTeamStats,
                    singleTeamStatUpdateBtn
                }
            };

            var allTeamStatUpdateBtn = new Button()
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Text            = "Update All Team Stats",
                TextColor       = Color.Green,
                BackgroundColor = Color.Black,
                FontSize        = GlobalVariables.sizeMedium
            };

            allTeamStatUpdateBtn.Clicked += (sender, e) => {
                //allTeamsStatsUpdateGrab();
            };

            var addMatchBtn = new Button()
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Text            = "Add Match",
                TextColor       = Color.Green,
                BackgroundColor = Color.Black,
                FontSize        = GlobalVariables.sizeMedium
            };

            addMatchBtn.Clicked += (sender, e) => {
                Navigation.PushPopupAsync(new AddMatchPopupPage());
            };

            var updateTeamOPRS = new Button()
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Text            = "Update OPRS",
                TextColor       = Color.Green,
                BackgroundColor = Color.Black,
                FontSize        = GlobalVariables.sizeMedium
            };

            updateTeamOPRS.Clicked += (sender, e) => {
                getEventOprs();
            };

            var logoutBtn = new Button()
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Text            = "Logout",
                TextColor       = Color.Green,
                BackgroundColor = Color.Black,
                FontSize        = GlobalVariables.sizeMedium
            };

            logoutBtn.Clicked += (sender, e) => {
                logout();
            };
            Button[] btnArray       = { logoutBtn };
            var      navigationBtns = new NavigationButtons(false, btnArray);

            Content = new StackLayout()
            {
                Children =
                {
                    busyIcon,
                    new ScrollView()
                    {
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        VerticalOptions   = LayoutOptions.FillAndExpand,

                        Content = new StackLayout()
                        {
                            HorizontalOptions = LayoutOptions.FillAndExpand,
                            VerticalOptions   = LayoutOptions.FillAndExpand,

                            Children =
                            {
                                updateTeamListBtn,
                                updateMatchListBtn,
                                //ingleTeamStatUpdateView,
                                //allTeamStatUpdateBtn,
                                addMatchBtn,
                                updateTeamOPRS
                                //eventStatTestBtn,
                            }
                        }
                    },
                    navigationBtns
                }
            };
        }