//tao note moi private void btnNewNote_Click(object sender, EventArgs e) { //neu o che do Trash, khong the tao note moi if (mode == false) { return; } this.lv.SelectedIndices.Clear(); this.lbInfo.Text = ""; this.rtb.Clear(); this.rtb1.Clear(); this.txbFind.Text = ""; //tao note moi voi note.content trong truoc //nguoi dung se thay doi noi dung bang cach viet vao richtextbox rtb Note note = new Note(); note.Id = NoteControllers.getIdFromDb(); note.Tittle = "New note"; note.Content = ""; note.Info = DateTime.Now; note.isTrash = false; note.isPin = false; NoteControllers.AddNote(note); displayAllNotes(); int i = 0; while (i < idtemp.Count) { if (idtemp[i] == note.Id) { break; } i++; } this.lv.Items[i].Selected = true; this.lv.Select(); this.rtb.Text = NoteControllers.getANote(note.Id).Content; this.rtb.Focus(); }
//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 { } }