private void Add_Click(object sender, EventArgs e) { if(tbxTitle.Text=="") { MessageBox.Show("Vui lòng nhập tiêu đề."); return; } GhiChu u = new GhiChu(); u.Title = tbxTitle.Text; u.Content = tbxContent.Text; string date = String.Format("{0:d}", datePicker.Value) + " " + String.Format("{0:t}", timePicker.Value); u.Time = DateTime.ParseExact(date, "M/d/yyyy h:m tt", CultureInfo.InvariantCulture, DateTimeStyles.None); if (u.Time <= DateTime.Now) { MessageBox.Show("Hạn chót phải sau thời điểm hiện tại."); return; } u.Complete = false; DatabaseHelper help = new DatabaseHelper(); help.Insert(u); if (u.Title.Length > 35) { u.Title = u.Title.Substring(0, 35) + "..."; } Reminder reminder = new Reminder(u.Id.ToString()); reminder.Title = u.Title; reminder.Content = u.Content; reminder.BeginTime = u.Time; reminder.NavigationUri = new Uri("/DetailPage.xaml?id=" + u.Id, UriKind.Relative); ScheduledActionService.Add(reminder); NavigationService.GoBack(); }
private void Update_Click(object sender, EventArgs e) { if (tbxTitle.Text == "") { MessageBox.Show("Vui lòng nhập tiêu đề."); return; } GhiChu u = new GhiChu(); u.Id = id; u.Title = tbxTitle.Text; u.Content = tbxContent.Text; string date = String.Format("{0:d}", datePicker.Value) + " " + String.Format("{0:t}", timePicker.Value); u.Time = DateTime.ParseExact(date, "M/d/yyyy h:m tt", CultureInfo.InvariantCulture, DateTimeStyles.None); if (cbComplete.IsChecked == true) { if (ScheduledActionService.Find(ghichu.Id.ToString()) != null) { ScheduledActionService.Remove(ghichu.Id.ToString()); } u.Complete = true; DatabaseHelper help = new DatabaseHelper(); help.UpdateContact(u); } else { if (u.Time <= DateTime.Now) { MessageBox.Show("Hạn chót phải sau thời điểm hiện tại."); return; } DatabaseHelper help = new DatabaseHelper(); u.Complete = false; help.UpdateContact(u); Reminder reminder = new Reminder(u.Id.ToString()); if (u.Title.Length > 35) { //u.Title = u.Title.Substring(0, u.Title.IndexOfAny(new char[] { ' ' }, 20)) + "..."; u.Title = u.Title.Substring(0, 35) + "..."; } reminder.Title = u.Title; reminder.Content = u.Content; reminder.BeginTime = u.Time; reminder.ExpirationTime = u.Time.AddMinutes(5); reminder.NavigationUri = new Uri("/DetailPage.xaml?id=" + u.Id, UriKind.Relative); if (ScheduledActionService.Find(ghichu.Id.ToString()) != null) { ScheduledActionService.Remove(ghichu.Id.ToString()); } ScheduledActionService.Add(reminder); } //NavigationService.Navigate(new Uri("/MainPage.xaml",UriKind.Relative)); NavigationService.GoBack(); }
protected override void OnNavigatedTo(NavigationEventArgs e) { if (first == 0) { string pm; NavigationContext.QueryString.TryGetValue("id", out pm); DatabaseHelper help = new DatabaseHelper(); ghichu = help.ReadContact(Convert.ToInt32(pm)); first = 1; id = ghichu.Id; tbxTitle.Text = ghichu.Title; tbxContent.Text = ghichu.Content; cbComplete.IsChecked = ghichu.Complete; datePicker.Value = ghichu.Time; timePicker.Value = ghichu.Time; } }
//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; dbConn.RunInTransaction(() => { dbConn.Update(existingconact); }); } } }
// 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); }); } }