Esempio n. 1
0
        //tim kiem note, theo noi dung va theo tag
        private void txbFind_TextChanged(object sender, EventArgs e)
        {
            this.lv.SelectedIndices.Clear();
            this.lbInfo.Text = "";
            this.rtb.Clear();
            this.rtb1.Clear();

            if (this.txbFind.Text == "")
            {
                if (mode == true)
                {
                    displayAllNotes();
                }
                else
                {
                    displayTrash();
                }
                return;
            }

            this.lv.Items.Clear();
            List <Note> notes = NoteControllers.getAllNotes(this.txbFind.Text);
            List <Tag>  tags  = TagControllers.getAllTags(this.txbFind.Text);

            //khi o che do All Notes
            if (mode == true)
            {
                idtemp.Clear();

                //tim kiem theo noi dung
                ListViewItem eVent2 = new ListViewItem("### Search by content:");
                this.lv.Items.Add(eVent2);
                idtemp.Add(-1);

                //note duoc pin hien truoc
                foreach (Note note in notes)
                {
                    if (note.isTrash == false && note.isPin == true)
                    {
                        ListViewItem eVent = new ListViewItem(note.Tittle.Trim());
                        eVent.SubItems.Add(new ListViewItem.ListViewSubItem(eVent, "x"));
                        this.lv.Items.Add(eVent);
                        idtemp.Add(note.Id);
                    }
                }
                //note khong duoc pin
                foreach (Note note in notes)
                {
                    if (note.isTrash == false && note.isPin == false)
                    {
                        ListViewItem eVent = new ListViewItem(note.Tittle.Trim());
                        eVent.SubItems.Add(new ListViewItem.ListViewSubItem(eVent, ""));
                        this.lv.Items.Add(eVent);
                        idtemp.Add(note.Id);
                    }
                }

                //tim kiem theo tag
                ListViewItem eVent1 = new ListViewItem("### Search by tag:");
                this.lv.Items.Add(eVent1);
                idtemp.Add(-1);

                foreach (Tag tag in tags)
                {
                    //note duoc pin hien truoc
                    foreach (Note note in tag.Note)
                    {
                        if (note.isTrash == false && note.isPin == true)
                        {
                            ListViewItem eVent = new ListViewItem(note.Tittle.Trim());
                            eVent.SubItems.Add(new ListViewItem.ListViewSubItem(eVent, "x"));
                            this.lv.Items.Add(eVent);
                            idtemp.Add(note.Id);
                        }
                    }
                    //note khong duoc pin
                    foreach (Note note in tag.Note)
                    {
                        if (note.isTrash == false && note.isPin == false)
                        {
                            ListViewItem eVent = new ListViewItem(note.Tittle.Trim());
                            eVent.SubItems.Add(new ListViewItem.ListViewSubItem(eVent, ""));
                            this.lv.Items.Add(eVent);
                            idtemp.Add(note.Id);
                        }
                    }
                }
            }

            //khi o che do Trash
            if (mode == false)
            {
                idtemp.Clear();

                //tim kiem theo noi dung
                ListViewItem eVent2 = new ListViewItem("### Search by content:");
                this.lv.Items.Add(eVent2);
                idtemp.Add(-1);
                foreach (Note note in notes)
                {
                    if (note.isTrash == true)
                    {
                        ListViewItem eVent = new ListViewItem(note.Tittle.Trim());
                        eVent.SubItems.Add(new ListViewItem.ListViewSubItem(eVent, ""));
                        this.lv.Items.Add(eVent);
                        idtemp.Add(note.Id);
                    }
                }

                //tim kiem theo tag
                ListViewItem eVent1 = new ListViewItem("### Search from tag:");
                this.lv.Items.Add(eVent1);
                idtemp.Add(-1);
                foreach (Tag tag in tags)
                {
                    foreach (Note note in tag.Note)
                    {
                        if (note.isTrash == true)
                        {
                            ListViewItem eVent = new ListViewItem(note.Tittle.Trim());
                            eVent.SubItems.Add(new ListViewItem.ListViewSubItem(eVent, ""));
                            this.lv.Items.Add(eVent);
                            idtemp.Add(note.Id);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        //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
            {
            }
        }