Exemplo n.º 1
0
        public void SavePlots()
        {
            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                excelEngine.Excel.DefaultVersion = ExcelVersion.Excel2013;
                IWorkbook workbook = excelEngine.Excel.Workbooks.Create(1);
                workbook.Version = ExcelVersion.Excel97to2003;

                for (int y = 0; y < ((List <Plot>)Application.Current.Properties["Plots"]).Count(); y++)
                {
                    Plot thisPlot = ((List <Plot>)Application.Current.Properties["Plots"]).ElementAt(y);
                    workbook.Worksheets.Create(thisPlot.GetName());
                    IWorksheet worksheet = workbook.Worksheets[y + 1];


                    worksheet.SetValue(1, 1, "Name");
                    worksheet.SetValue(2, 1, "Co-ordinates");
                    worksheet.SetValue(1, 4, "Owner");
                    worksheet.SetValue(2, 4, "Location");
                    worksheet.SetValue(3, 4, "Year Planted");
                    worksheet.SetValue(4, 4, "Comments");
                    if (thisPlot.Owner != null)
                    {
                        worksheet.SetValue(1, 5, thisPlot.Owner);
                    }
                    if (thisPlot.NearestTown != null)
                    {
                        worksheet.SetValue(2, 5, thisPlot.NearestTown);
                    }
                    if (thisPlot.Describe != null)
                    {
                        worksheet.SetValue(4, 5, thisPlot.Describe);
                    }
                    worksheet.SetValue(3, 5, thisPlot.YearPlanted.ToString());
                    worksheet.SetValue(1, 2, thisPlot.GetName());
                    worksheet.SetValue(2, 2, thisPlot.GetTag()[0].ToString());
                    worksheet.SetValue(2, 3, thisPlot.GetTag()[1].ToString());
                    worksheet.SetValue(3, 1, "Pricing Name");
                    //  if (thisPlot.GetRange() != null){
                    //    worksheet.SetValue(3, 2, thisPlot.GetRange().GetName());
                    // }
                    worksheet.SetValue(3, 3, thisPlot.GetPolygon().Count.ToString());

                    worksheet.SetValue(4, 1, "Border Co-ordinates");
                    worksheet.Range["$A$4:$B$4"].Merge();
                    for (int x = 0; x < thisPlot.GetPolygon().Count; x++)
                    {
                        worksheet.SetValue(5 + x, 1, thisPlot.GetPolygon().ElementAt(x).Latitude.ToString());
                        worksheet.SetValue(5 + x, 2, thisPlot.GetPolygon().ElementAt(x).Longitude.ToString());
                    }
                }

                workbook.Worksheets[0].Remove();
                MemoryStream stream = new MemoryStream();
                workbook.SaveAs(stream);
                workbook.Close();
                Xamarin.Forms.DependencyService.Get <ISave>().Save("Plots.xls", "application/msexcel", stream);
            }
        }
Exemplo n.º 2
0
        public async Task NewPlot()
        {
            //If setpoly not = -1 (pin selected) converts a set of placed pins into a polygon

            if (setpoly > -1)
            {
                List <double> lat = new List <double>();
                List <double> lon = new List <double>();
                for (int x = 0; x < newpolygon.Count; x++)
                {
                    lat.Add(newpolygon.ElementAt(x).Latitude);
                    lon.Add(newpolygon.ElementAt(x).Longitude);
                }
                Plot thisPLot = (((List <Plot>)Application.Current.Properties["Plots"]).ElementAt(setpoly));
                if (thisPLot.GetTag()[0] > lat.Min() && thisPLot.GetTag()[1] > lon.Min() && thisPLot.GetTag()[0] < lat.Max() && thisPLot.GetTag()[1] < lon.Max())
                {
                    ((List <Plot>)Application.Current.Properties["Plots"]).ElementAt(setpoly).AddPolygon(newpolygon);
                    SaveAll.GetInstance().SavePlots();
                }
                else
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        DisplayAlert(AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("Apin"), AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("Apin"), "OK");
                    });
                }

                setpoly = -1;
                StartMap(false);
                PolyMap();
                return;
            }
            // setpoly = -1 (no pin selected) adds placed pin into list of plots
            else if (!CanAdd)
            {
                double[] geo = new double[2];
                Application.Current.Properties["ThisLocation"] = new double[2];
                geo[0] = Pins.ElementAt(Pins.Count - 1).Position.Latitude;
                geo[1] = Pins.ElementAt(Pins.Count - 1).Position.Longitude;
                Application.Current.Properties["ThisLocation"] = geo;
                MessagingCenter.Send <CreatePlotPopup>(this, "Add");
                await PopupNavigation.Instance.PopAsync();
            }
            else
            {
                Application.Current.Properties["ThisLocation"] = null;
                //MessagingCenter.Subscribe<Popup>(this, "Add", (sender) =>
                //{
                //    CanAdd = true;
                //    StartMap(false);
                //    PolyMap();
                //    SaveAll.GetInstance().SavePlots();
                //});
                //await PopupNavigation.Instance.PushAsync(Popup.GetInstance());
            }
        }
Exemplo n.º 3
0
 private PlotPopupEdit()
 {
     InitializeComponent();
     if (Application.Current.Properties["Language"] != null)
     {
         Thread.CurrentThread.CurrentCulture = (CultureInfo)Application.Current.Properties["Language"];
     }
     EditPlot         = ((List <Plot>)Application.Current.Properties["Plots"]).ElementAt((int)Application.Current.Properties["ThisPlot"]);
     Latent.IsVisible = true;
     //Longent.IsVisible = true;
     PlotName.Text = EditPlot.GetName();
     Comments.Text = EditPlot.Describe;
     Location.Text = EditPlot.NearestTown;
     PlotYear.Text = EditPlot.YearPlanted.ToString();
     double[] geo = EditPlot.GetTag();
     Latent.Text = geo[0].ToString() + ", " + geo[1].ToString();
     //Longent.Text = geo[1].ToString();
     Owner.Text = EditPlot.Owner;
 }
Exemplo n.º 4
0
 protected override void OnAppearing()
 {
     Find.IsVisible = false;
     if (Application.Current.Properties["Language"] != null)
     {
         Thread.CurrentThread.CurrentCulture = (CultureInfo)Application.Current.Properties["Language"];
     }
     EditPlot         = ((List <Plot>)Application.Current.Properties["Plots"]).ElementAt((int)Application.Current.Properties["ThisPlot"]);
     Latent.IsVisible = true;
     //Longent.IsVisible = true;
     PlotName.Text = EditPlot.GetName();
     Comments.Text = EditPlot.Describe;
     Location.Text = EditPlot.NearestTown;
     PlotYear.Text = EditPlot.YearPlanted.ToString();
     double[] geo = EditPlot.GetTag();
     Latent.Text = geo[0].ToString() + ", " + geo[1].ToString();
     //Longent.Text = geo[1].ToString();
     Owner.Text = EditPlot.Owner;
     base.OnAppearing();
 }