Esempio n. 1
0
        async void importClicked(object sender, System.EventArgs e)
        {
            JObject data = MatchParameters.initializeEventsObject();

            try {
                JObject importJSON = (JObject)JsonConvert.DeserializeObject(importData.Text);
                if (importJSON.ContainsKey("Matches") || importJSON.ContainsKey("PitNotes"))
                {
                    if (importJSON.ContainsKey("Matches"))
                    {
                        if (!data.ContainsKey("Matches"))
                        {
                            data.Add(new JProperty("Matches", new JArray()));
                        }
                        await addMatchItemsChecker(data, importJSON);
                    }
                    if (importJSON.ContainsKey("PitNotes"))
                    {
                        if (!data.ContainsKey("PitNotes"))
                        {
                            data.Add(new JProperty("PitNotes", new JArray()));
                        }
                        await addPitItemsChecker(data, importJSON);
                    }
                    Preferences.Set("matchEventsString", JsonConvert.SerializeObject(data));
                    await PopupNavigation.Instance.PopAsync(true);
                }
                else
                {
                    await DisplayAlert("Alert", "Error in Data", "OK");
                }
            } catch (JsonReaderException) {
                await DisplayAlert("Alert", "Error in Data", "OK");
            }
        }
        async void importClicked(object sender, System.EventArgs e)
        {
            JObject data = MatchParameters.initializeEventsObject();

            if (data.ContainsKey(""))
            {
                data.Remove("");
            }
            if (importData.Text.ToLower().Contains("https://pastebin.com/raw/"))
            {
                try
                {
                    String response = new WebClient().DownloadString(importData.Text);
                    importData.Text = response;
                }
                catch {
                    await DisplayAlert("Error", "No Internet!", "OK");

                    return;
                }
            }
            try {
                JObject import = (JObject)JsonConvert.DeserializeObject(importData.Text);
                foreach (JProperty temp in import.Properties())
                {
                    Debug.WriteLine(temp);
                    JObject importJSON = new JObject();
                    //importJSON = importJSON;
                    try
                    {
                        importJSON = temp.Value.ToObject <JObject>();
                        if (importJSON.ContainsKey("Matches") || importJSON.ContainsKey("PitNotes"))
                        {
                            if (importJSON.ContainsKey("Matches"))
                            {
                                await addMatchItemsChecker(data, importJSON, (String)temp.Name); //TODO
                            }
                            if (importJSON.ContainsKey("PitNotes"))
                            {
                                await addPitItemsChecker(data, importJSON, (String)temp.Name); //TODO
                            }
                            Debug.WriteLine("final" + data);
                            Preferences.Set(ConstantVars.APP_DATA_STORAGE, JsonConvert.SerializeObject(data));
                            PopupNavigation.Instance.PopAsync();
                        }
                        else
                        {
                            await DisplayAlert("Alert", "Error in Data", "OK");
                        }
                    }
                    catch
                    {
                    }
                }
            } catch (JsonReaderException ex) {
                Debug.WriteLine(ex);
                await DisplayAlert("Alert", "Error in Data", "OK");
            }
        }
Esempio n. 3
0
        async void backClicked(object sender, System.EventArgs e)
        {
            var text = await DisplayAlert("Alert", "Do you want to discard progress?", "Yes", "No");

            if (text)
            {
                NewMatchStart.isTimerRunning = false;
                s.setEventButtons(true);
                s.setSlider(0);
                MatchParameters.clearMatchItems();
                Children.Remove(s);
                Navigation.PopAsync();
            }
        }
Esempio n. 4
0
        void saveClicked(object sender, System.EventArgs e)
        {
            //Disables save button so app doesn't crash when user taps many times
            saveButton.IsEnabled  = false;
            vals[vals.Length - 1] = newName.ToString();
            Dictionary <String, object> s = new Dictionary <String, object> ();

            for (int i = 0; i < vals.Length - 1; i++)
            {
                s.Add("q" + i, vals[i]);
            }
            s.Add("team", newName);
            JObject notes = JObject.FromObject(s);

            if (isAllEmpty(notes))
            {
                try {
                    Navigation.PopAsync(true);
                } catch (InvalidOperationException) { }
                clearMatchItems();
            }
            else
            {
                //Adds or creates new JObject to start all data in app cache
                JObject dataMain = MatchParameters.initializeEventsObject();
                JObject data     = (JObject)dataMain[Preferences.Get(ConstantVars.CURRENT_EVENT_NAME, "")];
                if (!data.ContainsKey("PitNotes"))
                {
                    data.Add(new JProperty("PitNotes", new JArray()));
                    pushBackToHome(dataMain, data, new JArray(), notes);
                }
                else
                {
                    JArray temp = (JArray)data["PitNotes"];
                    if (temp.ToList().Exists(x => x["team"].Equals(notes["team"])))
                    {
                        var item = temp.ToList().Find(x => (int)x["team"] == (int)notes["team"]);
                        temp.Remove(item);
                        for (int i = 0; i < ConstantVars.QUESTIONS.Length; i++)
                        {
                            try {
                                item["q" + (i)] = giveNewString(item["q" + i].ToString(), notes["q" + (i)].ToString());
                            } catch { }
                        }
                    }
                    pushBackToHome(dataMain, data, temp, notes);
                }
            }
        }
        void saveClicked(object sender, System.EventArgs e)
        {
            //Disables save button so app doesn't crash when user taps many times
            saveButton.IsEnabled = false;

            vals.team = Preferences.Get("teamStart", "oof");
            JObject notes = JObject.FromObject(vals);

            if (isAllEmpty(notes))
            {
                try {
                    if (Matches.appRestore == false)
                    {
                        Navigation.PopToRootAsync(true);
                    }
                    else if (Matches.appRestore == true)
                    {
                        Matches.appRestore = false;
                        Navigation.PopAsync(true);
                    }
                } catch (System.InvalidOperationException) { }
                clearMatchItems();
            }
            else
            {
                //Adds or creates new JObject to start all data in app cache
                JObject data = MatchParameters.initializeEventsObject();
                if (!data.ContainsKey("PitNotes"))
                {
                    data.Add(new JProperty("PitNotes", new JArray()));
                    pushBackToHome(data, new JArray(), notes);
                }
                else
                {
                    JArray temp = (JArray)data["PitNotes"];
                    if (temp.ToList().Exists(x => x["team"].Equals(notes["team"])))
                    {
                        var item = temp.ToList().Find(x => x["team"].Equals(notes["team"]));
                        temp.Remove(item);
                        for (int i = 0; i < ConstantVars.QUESTIONS.Length; i++)
                        {
                            item["q" + (i)] = giveNewString(item["q" + (i)].ToString(), notes["q" + (i)].ToString());
                        }
                    }
                    pushBackToHome(data, temp, notes);
                }
            }
        }
        async void importClicked(object sender, System.EventArgs e)
        {
            JObject data = MatchParameters.initializeEventsObject();

            if (importData.Text.ToLower().Contains("https://pastebin.com/raw/"))
            {
                try
                {
                    String response = new WebClient().DownloadString(importData.Text);
                    importData.Text = response;
                }
                catch {
                    await DisplayAlert("Error", "No Internet!", "OK");

                    return;
                }
            }
            try {
                JObject importJSON = (JObject)JsonConvert.DeserializeObject(importData.Text);
                if (importJSON.ContainsKey("Matches") || importJSON.ContainsKey("PitNotes"))
                {
                    if (importJSON.ContainsKey("Matches"))
                    {
                        if (!data.ContainsKey("Matches"))
                        {
                            data.Add(new JProperty("Matches", new JArray()));
                        }
                        await addMatchItemsChecker(data, importJSON);
                    }
                    if (importJSON.ContainsKey("PitNotes"))
                    {
                        if (!data.ContainsKey("PitNotes"))
                        {
                            data.Add(new JProperty("PitNotes", new JArray()));
                        }
                        await addPitItemsChecker(data, importJSON);
                    }
                    Preferences.Set("matchEventsString", JsonConvert.SerializeObject(data));
                    await PopupNavigation.Instance.PopAsync(true);
                }
                else
                {
                    await DisplayAlert("Alert", "Error in Data", "OK");
                }
            } catch (JsonReaderException) {
                await DisplayAlert("Alert", "Error in Data", "OK");
            }
        }
        async void backClicked(object sender, System.EventArgs e)
        {
            var text = await DisplayAlert("Alert", "Do you want to discard progress?", "Yes", "No");

            if (text)
            {
                MatchParameters.clearMatchItems();
                if (Matches.appRestore == false)
                {
                    Matches.appRestore = false;
                    Navigation.PopToRootAsync(true);
                }
                else if (Matches.appRestore == true)
                {
                    Matches.appRestore = false;
                    Navigation.PopAsync(true);
                }
            }
        }