コード例 #1
0
ファイル: DatabaseHelper.cs プロジェクト: ThanhBui92/T.note
 // Insert the new contact in the Contacts table. 
 public void Insert(GhiChu newcontact)
 {
     using (var dbConn = new SQLiteConnection(App.DB_PATH))
     {
         dbConn.RunInTransaction(() =>
         {
             dbConn.Insert(newcontact);
         });
     }
 }
コード例 #2
0
ファイル: DetailPage.xaml.cs プロジェクト: ThanhBui92/T.note
        private async void Image_Tapped(object sender, TappedRoutedEventArgs e)
        {
            if (tbxTitle.Text == "")
            {
                MessageDialog ms = new MessageDialog("Vui lòng nhập tiêu đề!");
                await ms.ShowAsync();
                return;
            }
            if (tbxContent.Text == "")
            {
                MessageDialog ms = new MessageDialog("Vui lòng nhập nội dung!");
                await ms.ShowAsync();
                return;
            }
            var t = time.Time;
            var d = String.Format("{0:d}", date.Date);
            var k = DateTime.ParseExact(d + " " + t, "M/d/yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None);
            if (k <= DateTime.Now && cbComplete.IsChecked == false)
            {
                MessageDialog ms = new MessageDialog("Hạn chót phải sau thời điểm hiện tại!");
                await ms.ShowAsync();
                return;
            }
            IReadOnlyList<ScheduledToastNotification> scheduled = ToastNotificationManager.CreateToastNotifier().GetScheduledToastNotifications();

            foreach (ScheduledToastNotification notify in scheduled)
            {
                if (notify.Id == ("T.note" + ((GhiChu)this.DataContext).Id))
                {
                    ToastNotificationManager.CreateToastNotifier().RemoveFromSchedule(notify);
                }
            }
            GhiChu u = new GhiChu();
            u.Id = ((GhiChu)this.DataContext).Id;
            u.Title = tbxTitle.Text;
            u.Content = tbxContent.Text;
            u.Complete = (bool)cbComplete.IsChecked;
            u.Remind = (bool)cbNhacNho.IsChecked;
            u.Time = k.ToString();
            DatabaseHelper help = new DatabaseHelper();
            help.UpdateContact(u);
            if ((bool)cbNhacNho.IsChecked)
            {
                ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01;
                XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
                XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image");
                ((XmlElement)toastImageAttributes[0]).SetAttribute("src", "/Assets/noteicon.png");
                ((XmlElement)toastImageAttributes[0]).SetAttribute("alt", "alt text");
                XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
                if ((bool)cbComplete.IsChecked)
                    toastTextElements[0].AppendChild(toastXml.CreateTextNode(u.Title + " Hoàn thành!"));
                else
                    toastTextElements[0].AppendChild(toastXml.CreateTextNode(u.Title));
                var dueTime = new DateTimeOffset(k);
                var toast = new Windows.UI.Notifications.ScheduledToastNotification(toastXml, dueTime);
                toast.Id = "T.note" + u.Id.ToString();
                Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
            }
            if (Frame.CanGoBack)
            {
                Frame.GoBack();
            }
        }
コード例 #3
0
ファイル: DatabaseHelper.cs プロジェクト: ThanhBui92/T.note
 //Update existing conatct 
 public void UpdateContact(GhiChu user)
 {
     using (var dbConn = new SQLiteConnection(App.DB_PATH))
     {
         var existingconact = dbConn.Query<GhiChu>("select * from GhiChu where Id =" + user.Id).FirstOrDefault();
         if (existingconact != null)
         {
             existingconact.Title = user.Title;
             existingconact.Content = user.Content;
             existingconact.Time = user.Time;
             existingconact.Complete = user.Complete;
             existingconact.Remind = user.Remind;
             dbConn.RunInTransaction(() =>
             {
                 dbConn.Update(existingconact);
             });
         }
     }
 }