//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 { } }
//Thêm tag vao note //tag.tagname nhap o textbox txbAddOrFindTag private void btnAddTag_Click(object sender, EventArgs e) { try { //txbAddOrFindTag rong hoac chua chon note de add tag, thoat if (this.txbAddOrFindTag.Text == "" || this.lv.SelectedItems.Count <= 0) { return; } List <Tag> tags1 = TagControllers.getAllTags(); foreach (Tag tag1 in tags1) { //kiem tra tag ton tai chua if (this.txbAddOrFindTag.Text == tag1.tagname) { goto b2; } } //tao tag moi neu tag chua ton tai Tag tag2 = new Tag(); tag2.tagname = this.txbAddOrFindTag.Text; TagControllers.AddTag(tag2); goto b3; //neu tag da duoc gan cho note truoc do roi, thoat b2: int i1 = this.lv.SelectedItems[0].Index; int id1 = idtemp[i1]; Note note1 = NoteControllers.getANote(id1); foreach (Tag tag3 in note1.Tag) { if (this.txbAddOrFindTag.Text == tag3.tagname) { this.txbAddOrFindTag.Text = ""; return; } } goto b3; //gan tag cho note va cap nhat note b3: Tag tag4 = TagControllers.getATag(this.txbAddOrFindTag.Text); int i2 = this.lv.SelectedItems[0].Index; int id2 = idtemp[i2]; Note note2 = NoteControllers.getANote(id2); note2.Tag.Add(tag4); Note note3 = new Note(); note3.Id = note2.Id; note3.Tittle = note2.Tittle; note3.Content = note2.Content; note3.Info = note2.Info; note3.isTrash = note2.isTrash; note3.isPin = note2.isPin; foreach (Tag tag5 in note2.Tag) { note3.Tag.Add(tag5); } NoteControllers.DeleteNote(note2); NoteControllers.AddNote(note2); string displayTags = ""; foreach (Tag tag in note2.Tag) { displayTags = displayTags + tag.tagname + " "; } this.rtb1.Text = displayTags; this.txbAddOrFindTag.Text = ""; } catch { } }