コード例 #1
0
        private async Task DeleteEntryIntoJsonAsync()
        {
            try
            {

                string content = String.Empty;
                List<string> ListCars = new List<string>();
                StorageFolder local = ApplicationData.Current.LocalFolder;
                // Create a new file named DataFile.txt.
                var file = await local.CreateFileAsync("DataFile.json", CreationCollisionOption.OpenIfExists);
                CultureInfo provider = new CultureInfo("es-ES");
                if (local != null)
                {
                    // var dataFolder = await local.GetFolderAsync("DataFolder");
                    var myStream = await local.OpenStreamForReadAsync("DataFile.json");
                    using (StreamReader reader = new StreamReader(myStream))
                    {
                        content = await reader.ReadToEndAsync();
                    }

                    if (content != "")
                    {
                        //Now add one more Entry.
                        ListCars = FavClass.ConvertToFavEvent(content);

                        foreach (var favEvent in ListCars)
                        {
                            if (String.Compare(favEvent, subitem.UniqueId) == 0)
                            {

                                //ListCars.Remove(favEvent);
                                int i = ListCars.FindIndex(f => f == subitem.UniqueId);
                                ListCars.RemoveAt(i);
                                break;
                                //ListCars.Remove(new FavClass() { UniqueId = subitem.UniqueId, Id = subitem.Id, Title = subitem.Title, Subtitle = subitem.Subtitle, Subtitle = subitem.Subtitle, Content = subitem.Content });
                            }
                        }
                        ListCars.TrimExcess();
                        var subitemDet = await SampleDataSource.GetGroupAsync("Schedule");
                        schedulednotif n = new schedulednotif();
                        n.schedulenotifrem(subitem.Title);
                        //int noOfItems = subitemDet.Items.Count;
                        //string date = "25/10/2015";
                        //for (int i = 0; i < noOfItems; i++)
                        //{
                        //    int noOfsubitems = subitemDet.Items[i].SubItems.Count;
                        //    MessageDialog msgbox4 = new MessageDialog(noOfsubitems.ToString());
                        //    await msgbox4.ShowAsync();
                        //    if (i == 0)
                        //    {
                        //        date = "26/10/2015";
                        //    }
                        //    else if (i == 1)
                        //    {
                        //        date = "26/10/2015";
                        //    }
                        //    else if (i == 2)
                        //    {
                        //        date = "30/10/2015";
                        //    }
                        //    else if (i == 3)
                        //    {
                        //        date = "31/10/2015";
                        //    }
                        //    else if (i == 4)
                        //    {
                        //        date = "01/11/2015";
                        //    }
                        //    for (int j = 0; j < noOfsubitems; j++)
                        //    {
                        //        if (subitemDet.Items[i].SubItems[j].UniqueId.CompareTo(subitem.UniqueId) == 0)
                        //        {
                        //            string date1 = date + " " + subitemDet.Items[i].SubItems[j].Subtitle;
                        //            MessageDialog msgbox5 = new MessageDialog(date1);
                        //            await msgbox5.ShowAsync();
                        //            //DateTime dt = Convert.ToDateTime(date + subitemDet.Items[0].SubItems[0].Subtitle);
                        //            DateTime dt = DateTime.ParseExact(date1, "g", provider);

                        //            DateTime ddt = DateTime.Now;
                        //            var diffInSeconds = (dt - ddt).TotalSeconds;
                        //            MessageDialog msgbox6 = new MessageDialog(diffInSeconds.ToString());
                        //            await msgbox6.ShowAsync();
                        //            diffInSeconds = diffInSeconds - 900;
                        //            if ((diffInSeconds + 10) > 0)

                        //            MessageDialog msgbox7 = new MessageDialog("conv");
                        //            await msgbox7.ShowAsync();
                        //        }
                        //    }
                        //}

                        //if (item != null)
                        //ListCars.Add(new FavClass() { UniqueId = item1.UniqueId, Id = item1.Id, Title = item1.Title, Subtitle = item1.Subtitle, Subtitle = item1.Subtitle, Content = item1.Content });
                        //else
                        //  ListCars.Add(new FavClass() { UniqueId = subitem.UniqueId, Id = subitem.Id, Title = subitem.Title, Subtitle = subitem.Subtitle, Subtitle = subitem.Subtitle, Content = subitem.Content });
                       
                            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List<string>));
                            using (var stream = await local.OpenStreamForWriteAsync(
                                          "DataFile.json",
                                          CreationCollisionOption.ReplaceExisting))
                            {
                                serializer.WriteObject(stream, ListCars);
                            }
                        
                        
                    }

                }
            }
            catch
            { }
        }
コード例 #2
0
        private async Task DeleteEntryIntoJsonAsync()
        {
            try
            {
                string content = String.Empty;
                List<string> ListCars = new List<string>();
                StorageFolder local = ApplicationData.Current.LocalFolder;
                // Create a new file named DataFile.txt.
                var file = await local.CreateFileAsync("DataFile.json",
                CreationCollisionOption.OpenIfExists);

                if (local != null)
                {
                    // var dataFolder = await local.GetFolderAsync("DataFolder");
                    var myStream = await local.OpenStreamForReadAsync("DataFile.json");
                    using (StreamReader reader = new StreamReader(myStream))
                    {
                        content = await reader.ReadToEndAsync();
                    }
                    if (content != "")
                    {
                        //Now add one more Entry.
                        ListCars = FavClass.ConvertToFavEvent(content);

                        foreach (var favEvent in ListCars)
                        {
                            if (String.Compare(favEvent, item.UniqueId) == 0)
                            {
                                //ListCars.Remove((string)favEvent);
                                int i = ListCars.FindIndex(f => f == item.UniqueId);
                                ListCars.RemoveAt(i);
                                break;
                            }
                        }
                        ListCars.TrimExcess();
                        var subitemDet = await SampleDataSource.GetGroupAsync("Schedule");
                        schedulednotif n = new schedulednotif();
                        n.schedulenotifrem(item.Title);


                        //if (item != null)
                        //ListCars.Add(new FavClass() { UniqueId = item1.UniqueId, Id = item1.Id, Title = item1.Title, Subtitle = item1.Subtitle, Subtitle = item1.Subtitle, Content = item1.Content });
                        //else
                        //  ListCars.Add(new FavClass() { UniqueId = subitem.UniqueId, Id = subitem.Id, Title = subitem.Title, Subtitle = subitem.Subtitle, Subtitle = subitem.Subtitle, Content = subitem.Content });
                       
                            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List<string>));
                            using (var stream = await local.OpenStreamForWriteAsync(
                                          "DataFile.json",
                                          CreationCollisionOption.ReplaceExisting))
                            {
                                serializer.WriteObject(stream, ListCars);
                            }
                        
                       
                    }

                }
            }
            catch { }
            }
コード例 #3
0
        private async Task evntnow()
        {
            try
            {
                CultureInfo provider = new CultureInfo("es-ES");
                var subitemDet = await SampleDataSource.GetGroupAsync("Schedule");
                schedulednotif n = new schedulednotif();
                int noOfItems = subitemDet.Items.Count;
                string date = "25/10/2015";
                DateTime ddt = DateTime.Now;
                List<SampleDataSubItem> evobj = new List<SampleDataSubItem>();

                for (int i = 0; i < noOfItems; i++)
                {
                    int noOfsubitems = subitemDet.Items[i].SubItems.Count;
                    //MessageDialog msgbox4 = new MessageDialog(noOfsubitems.ToString());
                    //await msgbox4.ShowAsync();
                    if (i == 0)
                    {
                        date = "28/10/2015";
                    }
                    else if (i == 1)
                    {
                        date = "29/10/2015";
                    }
                    else if (i == 2)
                    {
                        date = "30/10/2015";
                    }
                    else if (i == 3)
                    {
                        date = "31/10/2015";
                    }
                    else if (i == 4)
                    {
                        date = "01/11/2015";
                    }
                    string z111;
                    for (int j = 0; j < noOfsubitems; j++)
                    {
                        if (subitemDet.Items[i].SubItems[j].Subtitle.Length != 5)
                        {
                            z111 = "0" + subitemDet.Items[i].SubItems[j].Subtitle;

                        }
                        else
                            z111 = subitemDet.Items[i].SubItems[j].Subtitle;
                        //MessageDialog msgbox4 = new MessageDialog(z111);
                        //await msgbox4.ShowAsync();
                        string date1 = date + " " + z111;
                        DateTime dt = DateTime.ParseExact(date1, "g", provider);
                        var diffInSeconds = (dt - ddt).TotalSeconds;
                        if (diffInSeconds < 0 && diffInSeconds > -7200)
                        {
                            evobj.Add(subitemDet.Items[i].SubItems[j]);
                        }
                        else if (diffInSeconds > 0 && diffInSeconds < 10800)
                        {
                            evobj.Add(subitemDet.Items[i].SubItems[j]);
                        }

                        //DateTime dt = Convert.ToDateTime(date + subitemDet.Items[0].SubItems[0].Subtitle);







                    }
                }
                FavListView.ItemsSource = evobj;
            }
            catch
            {

            }
        }
コード例 #4
0
        private async Task AddEntryIntoJsonAsync()
        {
            try
            {
                string content = String.Empty;
                List<string> ListCars = new List<string>();
                StorageFolder local = ApplicationData.Current.LocalFolder;
                // Create a new file named DataFile.txt.
                var file = await local.CreateFileAsync("DataFile.json",
                CreationCollisionOption.OpenIfExists);

                if (local != null)
                {
                    // var dataFolder = await local.GetFolderAsync("DataFolder");
                    var myStream = await local.OpenStreamForReadAsync("DataFile.json");
                    using (StreamReader reader = new StreamReader(myStream))
                    {
                        content = await reader.ReadToEndAsync();
                    }
                    if (content != "")
                    {
                        //Now add one more Entry.
                        ListCars = FavClass.ConvertToFavEvent(content);
                    }
                    //if (item != null)
                    CultureInfo provider = new CultureInfo("es-ES");
                    //if (item != null)
                    ListCars.Add(item.UniqueId);
                    var subitemDet = await SampleDataSource.GetGroupAsync("Schedule");
                    schedulednotif n = new schedulednotif();
                    int noOfItems = subitemDet.Items.Count;
                    string date = "25/10/2015";
                    for (int i = 0; i < noOfItems; i++)
                    {
                        int noOfsubitems = subitemDet.Items[i].SubItems.Count;

                        if (i == 0)
                        {
                            date = "28/10/2015";
                        }
                        else if (i == 1)
                        {
                            date = "29/10/2015";
                        }
                        else if (i == 2)
                        {
                            date = "30/10/2015";
                        }
                        else if (i == 3)
                        {
                            date = "31/10/2015";
                        }
                        else if (i == 4)
                        {
                            date = "01/11/2015";
                        }
                        string z111;
                        for (int j = 0; j < noOfsubitems; j++)
                        {
                            if (subitemDet.Items[i].SubItems[j].UniqueId.CompareTo(item.UniqueId) == 0)
                            {
                                if (subitemDet.Items[i].SubItems[j].Subtitle.Length != 5)
                                {
                                    z111 = "0" + subitemDet.Items[i].SubItems[j].Subtitle;

                                }
                                else
                                    z111 = subitemDet.Items[i].SubItems[j].Subtitle;
                                string date1 = date + " " + subitemDet.Items[i].SubItems[j].Subtitle;

                                //DateTime dt = Convert.ToDateTime(date + subitemDet.Items[0].SubItems[0].Subtitle);
                                DateTime dt = DateTime.ParseExact(date1, "g", provider);

                                DateTime ddt = DateTime.Now;
                                var diffInSeconds = (dt - ddt).TotalSeconds;

                                diffInSeconds = diffInSeconds - 900;
                                if ((diffInSeconds + 10) > 0)
                                    n.schedulenotif(diffInSeconds, subitemDet.Items[i].SubItems[j].Title);

                            }
                        }
                    }

                    //else
                    //  ListCars.Add(new FavClass() { UniqueId = subitem.UniqueId, Id = subitem.Id, Title = subitem.Title, Subtitle = subitem.Subtitle, Subtitle = subitem.Subtitle, Content = subitem.Content });
                    
                        DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List<string>));
                        using (var stream = await local.OpenStreamForWriteAsync(
                                      "DataFile.json",
                                      CreationCollisionOption.ReplaceExisting))
                        {
                            serializer.WriteObject(stream, ListCars);
                        }
                   
                    

                }

            }
            catch { }
        }