Ejemplo n.º 1
0
        private async void Next_Click(object sender, RoutedEventArgs e)
        {
            String filename = trip.Text;

            if (filename.Equals(""))
            {
                filename = "Trip";
            }
            try
            {
                StorageFolder localFolder = KnownFolders.DocumentsLibrary;
                StorageFile   storageFile = await localFolder.CreateFileAsync(filename + ".csv", CreationCollisionOption.GenerateUniqueName);

                Stream writeStream = await storageFile.OpenStreamForWriteAsync();

                using (StreamWriter writer = new StreamWriter(writeStream))
                {
                    try
                    {
                        writer.WriteLine(no.ToString() + ",0");
                        for (int i = 4; i < Stacks.Children.Count; i++)
                        {
                            TextBox fl = (TextBox)Stacks.Children.ElementAt(i);
                            writer.Write(fl.Text + Environment.NewLine);
                        }
                    }
                    catch (Exception) { }
                    // MessageDialogHelper.Show("Success", "Added");
                }
                filename = storageFile.DisplayName;

                /*storageFile = await localFolder.CreateFileAsync("Exfrienditure.csv", CreationCollisionOption.OpenIfExists);
                 * Stream readStream = await storageFile.OpenStreamForReadAsync();
                 * //int no = 0;
                 * using (StreamReader reader = new StreamReader(readStream))
                 * {
                 *  no = Convert.ToInt16(reader.ReadLine());
                 * }
                 * storageFile = await localFolder.CreateFileAsync("Exfrienditure.csv", CreationCollisionOption.OpenIfExists);
                 * readStream = await storageFile.OpenStreamForReadAsync();
                 * string[] trips=new string[no];
                 * using (StreamReader reader = new StreamReader(readStream))
                 * {
                 *  reader.ReadLine();
                 *  for (int i = 0; i < no; i++)
                 *  {
                 *      trips[i] = reader.ReadLine();
                 *  }
                 * }*/
                storageFile = await localFolder.CreateFileAsync("Exfrienditure.csv", CreationCollisionOption.OpenIfExists);

                writeStream = await storageFile.OpenStreamForWriteAsync();

                using (StreamWriter writer = new StreamWriter(writeStream))
                {
                    writer.WriteLine(MainPage.no + 1);
                    for (int i = 0; i < MainPage.no; i++)
                    {
                        writer.WriteLine(MainPage.trips[i]);//Trip[i].Name);
                    }
                    writer.WriteLine(filename);
                }
                this.Frame.Navigate(typeof(Timeline), filename + ".csv");
            }
            catch (Exception e1) { MessageDialogHelper.Show(e1.ToString(), "Error"); }
        }
Ejemplo n.º 2
0
        private async void Next_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                StorageFolder localFolder = KnownFolders.DocumentsLibrary;
                StorageFile   storageFile = await localFolder.CreateFileAsync(fileName, CreationCollisionOption.OpenIfExists);

                Stream writeStream = await storageFile.OpenStreamForWriteAsync();

                using (StreamWriter writer = new StreamWriter(writeStream))
                {
                    writer.WriteLine(no + "," + (ntran + 1));
                    try
                    {
                        for (int i = 0; i < no; i++)
                        {
                            TextBox bx = (TextBox)Prices.Children.ElementAt(i + 1);
                            writer.Write(list.ElementAt(i) + "," + bx.Text + Environment.NewLine);
                        }
                        if (geo == null)
                        {
                            geo = new Geolocator();
                        }
                        try
                        {
                            Geoposition pos = await geo.GetGeopositionAsync();

                            if (geo.LocationStatus == PositionStatus.Disabled)
                            {
                                MessageDialogHelper.Show("Location has been disabled in Settings.", "No Location.");
                                for (int i = 0; i < ntran; i++)
                                {
                                    writer.WriteLine(list.ElementAt(no + i));
                                }
                                writer.WriteLine(DateTime.Now.ToString() + ",0,0,0");
                            }
                            else
                            {
                                for (int i = 0; i < ntran; i++)
                                {
                                    writer.WriteLine(list.ElementAt(no + i));
                                }
                                writer.WriteLine(DateTime.Now.ToString() + "," + pos.Coordinate.Point.Position.Latitude.ToString() + "," + pos.Coordinate.Point.Position.Longitude.ToString() + "," + pos.Coordinate.Accuracy.ToString());
                            }
                        }
                        catch (Exception)
                        {
                            MessageDialogHelper.Show("Location is not available. Check whether it is enabled in the Settings.", "No Location.");
                            for (int i = 0; i < ntran; i++)
                            {
                                writer.WriteLine(list.ElementAt(no + i));
                            }
                            writer.WriteLine(DateTime.Now.ToString() + ",0,0,0");
                        }
                        for (int i = 0; i < ntran; i++)
                        {
                            writer.WriteLine(list.ElementAt(no + ntran + i));
                        }
                        writer.WriteLine(path);
                    }

                    catch (Exception eq) { }
                    // MessageDialogHelper.Show("Success", "Added");
                }
                NavigationHelper.GoBack();
            }
            catch (Exception) { }
        }