Exemplo n.º 1
0
        //loads data from .xls files plots. data for plots is stored in Plots.xls
        public void LoadPlotFiles()
        {
            bool doesExist = File.Exists(DependencyService.Get <ISave>().GetFileName() + "/Plots.xls");

            if (doesExist)
            {
                ExcelEngine  excelEngine = new ExcelEngine();
                FileStream   inputStream = new FileStream(DependencyService.Get <ISave>().GetFileName() + "/Plots.xls", FileMode.Open);
                IApplication application = excelEngine.Excel;
                IWorkbook    workbook    = application.Workbooks.Open(inputStream);
                for (int x = 0; x < workbook.Worksheets.Count; x++)
                {
                    SortedList <double, double> bracket = new SortedList <double, double>();
                    IWorksheet sheet = workbook.Worksheets[x];
                    if (sheet.GetValueRowCol(1, 1).ToString() == "Name")
                    {
                        string   name   = sheet.GetValueRowCol(1, 2).ToString();
                        double[] geotag = { double.Parse(sheet.GetValueRowCol(2, 2).ToString()), double.Parse(sheet.GetValueRowCol(2, 3).ToString()) };

                        Plot newPlot = new Plot(name);
                        newPlot.SetTag(geotag);
                        newPlot.Owner = sheet.GetValueRowCol(1, 5).ToString();
                        try { newPlot.YearPlanted = int.Parse(sheet.GetValueRowCol(3, 5).ToString()); } catch { };
                        newPlot.NearestTown = sheet.GetValueRowCol(2, 5).ToString();
                        newPlot.Owner       = sheet.GetValueRowCol(1, 5).ToString();
                        newPlot.Describe    = sheet.GetValueRowCol(4, 5).ToString();
                        List <Position> PolyPlot = new List <Position>();
                        for (int y = 0; y < int.Parse(sheet.GetValueRowCol(3, 3).ToString()); y++)
                        {
                            PolyPlot.Add(new Position(double.Parse(sheet.GetValueRowCol(5 + y, 1).ToString()), double.Parse(sheet.GetValueRowCol(5 + y, 2).ToString())));
                        }
                        newPlot.AddPolygon(PolyPlot);
                        ((List <Plot>)Application.Current.Properties["Plots"]).Add(newPlot);
                    }
                }
                inputStream.Dispose();
            }
        }
Exemplo n.º 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");
            }
        }