//Xóa vĩnh viễn note private void btnDeleteForever_Click(object sender, EventArgs e) { try { int i = this.lv.SelectedItems[0].Index; int id = idtemp[i]; Note note = NoteControllers.getANote(id); NoteControllers.DeleteNote(note); displayTrash(); //xoa cac tag khong su dung List <Tag> tags = TagControllers.getAllTags(); foreach (Tag tag in tags) { if (tag.Note.Count() <= 0) { TagControllers.DeleteTag(tag); } } this.rtb.Clear(); this.rtb1.Clear(); this.lbInfo.Text = ""; } catch { } }
//xoa tag //tag.tagname nhap o textbox txbAddOrFindTag private void btnDeleteTag_Click(object sender, EventArgs e) { try { if (txbAddOrFindTag.Text == "" || this.lv.SelectedItems.Count <= 0) { return; } int i = this.lv.SelectedItems[0].Index; int id = idtemp[i]; Note note = NoteControllers.getANote(id); foreach (Tag tag in note.Tag) { //kiem tra tag da duoc gan cho note chua if (tag.tagname == this.txbAddOrFindTag.Text) { //xoa tag khoi note.Tags va cap nhat note note.Tag.Remove(tag); Note note1 = new Note(); note1.Id = note.Id; note1.Tittle = note.Tittle; note1.Content = note.Content; note1.Info = note.Info; note1.isTrash = note.isTrash; note1.isPin = note.isPin; foreach (Tag tag1 in note.Tag) { note1.Tag.Add(tag1); } NoteControllers.DeleteNote(note); NoteControllers.AddNote(note1); string displayTags = ""; foreach (Tag tag2 in note1.Tag) { displayTags = displayTags + tag2.tagname + " "; } this.rtb1.Text = displayTags; this.txbAddOrFindTag.Text = ""; //xoa tag khong su dung List <Tag> tags = TagControllers.getAllTags(); foreach (Tag tag3 in tags) { if (tag3.Note.Count() <= 0) { TagControllers.DeleteTag(tag3); } } return; } } return; } catch { } }