Exemple #1
0
        public async void AddNewTree()
        {
            if (pickPlot.SelectedIndex > -1)
            {
                Application.Current.Properties["Counter"] = pickPlot.SelectedIndex;
                MessagingCenter.Unsubscribe <AddTreePop>(this, "Add");

                MessagingCenter.Subscribe <AddTreePop>(this, "Add", async(sender) =>
                {
                    int hold = pickPlot.SelectedIndex;
                    pickPlot.SelectedIndex = -1;
                    pickPlot.SelectedIndex = hold;
                    Titlename.Text         = AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("ManagePlots") + ": saving";
                    SaveAll.GetInstance().SaveTrees2();
                    Titlename.Text = AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("ManagePlots") + ": saved";
                    await Task.Delay(5000);
                    Titlename.Text = AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("ManagePlots");
                });
                await PopupNavigation.Instance.PushAsync(AddTreePop.GetInstance());
            }
        }
Exemple #2
0
        public async void Done()
        {
            if (PlotName.Text != null && int.TryParse(PlotYear.Text, out int yearout) && yearout <= DateTime.Now.Year)
            {
                double[] geo;
                if (Latent.Text == null)
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        DisplayAlert(AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("InputInv"), AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("WrongCoord"), "OK");
                    });
                    return;
                }
                string[] splitter = Latent.Text.Split(',');

                if (splitter.Count() != 2)
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        DisplayAlert(AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("InputInv"), AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("WrongCoord"), "OK");
                    });
                    return;
                }
                if (double.TryParse(splitter.ElementAt(0), out double latout) && double.TryParse(splitter.ElementAt(1), out double lonout))
                {
                    if (latout > 90 || latout < -90 || lonout > 180 || lonout <= -180)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            DisplayAlert(AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("InputInv"), AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("OORCoord"), "OK");
                        });
                        return;
                    }
                    geo = new double[] { latout, lonout };
                }
                //   else if (Application.Current.Properties["ThisLocation"] != null)
                //   {
                //       geo = (double[])Application.Current.Properties["ThisLocation"];
                // }
                else
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        DisplayAlert(AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("InputInv"), AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("OORCoord"), "OK");
                    });
                    return;
                }
                NextPlot = new Plot(PlotName.Text);
                NextPlot.SetTag(geo);
                NextPlot.Describe    = Comments.Text;
                NextPlot.NearestTown = Location.Text;
                NextPlot.Owner       = Owner.Text;
                if (Application.Current.Properties["Bounds"] != null && ((List <TK.CustomMap.Position>)Application.Current.Properties["Bounds"]).Count > 1)
                {
                    NextPlot.AddPolygon(((List <TK.CustomMap.Position>)Application.Current.Properties["Bounds"]));
                    Application.Current.Properties["Bounds"] = new List <TK.CustomMap.Position>();
                }
                if (int.Parse(PlotYear.Text) != 0)
                {
                    NextPlot.YearPlanted = yearout;
                }
                for (int i = 0; i < ((List <Plot>)Application.Current.Properties["Plots"]).Count; i++)
                {
                    if (((List <Plot>)Application.Current.Properties["Plots"]).ElementAt(i).GetName() == PlotName.Text)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            DisplayAlert(AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("InputInv"), AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("EnterName"), "OK");
                        });
                        return;
                    }
                }
                ((List <Plot>)Application.Current.Properties["Plots"]).Add(NextPlot);
                SaveAll.GetInstance().SavePlots();
                Application.Current.Properties["ThisLocation"] = null;
                PlotName.Text = null;
                Comments.Text = null;
                Location.Text = null;
                Owner.Text    = null;
                Latent.Text   = null;
                bool res = await DisplayAlert(AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("AddTree"), AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("AddTree2"), AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("yes"), AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("no"));

                if (res)
                {
                    Application.Current.Properties["Counter"] = ((List <Plot>)Application.Current.Properties["Plots"]).Count - 1;
                    MessagingCenter.Subscribe <AddTreePop>(this, "Save", async(sender) =>
                    {
                        SaveAll.GetInstance().SaveTrees2();
                        NameLabel.Text = AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("CreatePlot") + ": " + AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("Saved");
                        await Task.Delay(5000);
                        NameLabel.Text = AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("CreatePlot");
                    });
                    await PopupNavigation.Instance.PushAsync(AddTreePop.GetInstance());
                }
                else
                {
                    NameLabel.Text = AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("CreatePlot") + ": " + AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("Saved");
                    await Task.Delay(5000);

                    NameLabel.Text = AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("CreatePlot");
                }
            }
            else if (PlotName.Text == null)
            {
                NameLabel.Text = AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("EnterName");
            }
            else
            {
                NameLabel.Text = AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("EnterVDate");
            }
        }