Example #1
0
        private void btnDeleteTag_Click(object sender, EventArgs e)
        {
            if (txbTypeTag.Text == "")
            {
                return;
            }
            if (this.listViewNoiDung.SelectedItems.Count <= 0)
            {
                return;
            }
            int i = this.listViewNoiDung.SelectedItems[0].Index;
            //int j = this.listViewNoiDung.SelectedItems[1].Index;
            int  stt    = idList[i]++;
            Note source = NoteControllers.getNote(stt);

            foreach (Tag tag in source.Tags)
            {
                if (tag.TenTag == this.txbTypeTag.Text)
                {
                    source.Tags.Remove(tag);

                    Note get = new Note();
                    get.SoThuTu  = source.SoThuTu;
                    get.TieuDe   = source.TieuDe;
                    get.NoiDung  = source.NoiDung;
                    get.ThongTin = source.ThongTin;
                    get.Rac      = source.Rac;
                    get.PintoTop = source.PintoTop;
                    foreach (Tag getsource in source.Tags)
                    {
                        get.Tags.Add(getsource);
                    }

                    NoteControllers.deleteNote(source);
                    NoteControllers.addNote(get);

                    string showtag = "";
                    foreach (Tag gettag in get.Tags)
                    {
                        showtag = showtag + gettag.TenTag + " ";
                    }
                    this.rtbShowTag.Text = showtag;
                    this.rtbred.Text     = showtag;

                    this.txbTypeTag.Text = "";

                    List <Tag> sourcetag = TagControllers.getAllTag();
                    foreach (Tag take in sourcetag)
                    {
                        if (take.Notes.Count() <= 0)
                        {
                            TagControllers.deleteTag(take);
                        }
                    }

                    return;
                }
            }
            return;
        }
Example #2
0
        private void btnDelFor_Click(object sender, EventArgs e)
        {
            if (this.listViewNoiDung.SelectedItems.Count <= 0)
            {
                return;
            }
            int i = this.listViewNoiDung.SelectedItems[0].Index;
            //int j = this.listViewNoiDung.SelectedItems[1].Index;
            int  stt     = idList[i];
            Note getnote = NoteControllers.getNote(stt);

            NoteControllers.deleteNote(getnote);
            showRac();

            List <Tag> listtag = TagControllers.getAllTag();

            foreach (Tag gettag in listtag)
            {
                if (gettag.Notes.Count() <= 0)
                {
                    TagControllers.deleteTag(gettag);
                }
            }

            this.rtbTypeNoiDung.Clear();
            this.rtbShowTag.Clear();
            this.rtbred.Clear();
            this.lbInfo.Text = "";
        }
Example #3
0
        //hien thi danh sach note trong All Notes theo note.Tittle tren listview lv
        //dong thoi cap nhat idtemp
        private void displayAllNotes()
        {
            idtemp.Clear();
            this.lv.Items.Clear();
            List <Note> notes = NoteControllers.getAllNotes();

            //hien thi cac note duoc pin truoc
            for (int i = (notes.Count() - 1); i >= 0; i--)
            {
                Note note = notes[i];
                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);
                }
            }

            //cac note khong duoc pin
            for (int i = (notes.Count() - 1); i >= 0; i--)
            {
                Note note = notes[i];
                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);
                }
            }
        }
Example #4
0
        //chon note bang cach click vao tieu de cua note tren listview lv
        //note.content se hien len richtextbox rtb va note.Tags se hien len richtetbox rtb1
        //dong thoi co the su dung cac nut chuc nang de cap nhat note voi note duoc chon
        private void lv_Click(object sender, EventArgs e)
        {
            try
            {
                this.lbInfo.Text = "";
                int i  = this.lv.SelectedItems[0].Index;
                int id = idtemp[i];

                if (id == -1)
                {
                    this.lv.SelectedIndices.Clear();
                    return;
                }

                Note note = NoteControllers.getANote(id);

                this.rtb.Text = note.Content;

                this.rtb1.Clear();
                if (note.Tag.Count <= 0)
                {
                    return;
                }
                string displayTags = "";
                foreach (Tag tag in note.Tag)
                {
                    displayTags = displayTags + tag.tagname + " ";
                }
                this.rtb1.Text = displayTags;
            }
            catch
            {
            }
        }
Example #5
0
        //pin note len tren dau, note.isPin chuyen tu false sang true
        //nguoc lai, note.isPin chuyen tu true sang false
        //neu co nhieu note duoc pin se sap xep theo thu tu
        private void btnPin_Click(object sender, EventArgs e)
        {
            try
            {
                int  i    = this.lv.SelectedItems[0].Index;
                int  id   = idtemp[i];
                Note note = NoteControllers.getANote(id);
                if (note.isPin == false)
                {
                    note.isPin = true;
                }
                else
                {
                    note.isPin = false;
                }

                NoteControllers.UpdateNote(note);
                displayAllNotes();

                int j = 0;
                while (j < idtemp.Count)
                {
                    if (idtemp[j] == note.Id)
                    {
                        break;
                    }
                    j++;
                }
                this.lv.Items[j].Selected = true;
                this.lv.Select();
            }
            catch
            {
            }
        }
Example #6
0
        private void showNotes()
        {
            idList.Clear();
            this.listViewNoiDung.Items.Clear();
            List <Note> get = NoteControllers.getAllNotes();

            for (int i = (get.Count() - 1); i >= 0; i--)
            {
                Note note = get[i];
                if (note.Rac == false && note.PintoTop == true)
                {
                    ListViewItem show = new ListViewItem(note.TieuDe.Trim());
                    show.SubItems.Add(new ListViewItem.ListViewSubItem(show, "o"));
                    this.listViewNoiDung.Items.Add(show);
                    idList.Add(note.SoThuTu);
                }
            }
            for (int i = (get.Count() - 1); i >= 0; i--)
            {
                Note note = get[i];
                if (note.Rac == false && note.PintoTop == false)
                {
                    ListViewItem show2 = new ListViewItem(note.TieuDe.Trim());
                    show2.SubItems.Add(new ListViewItem.ListViewSubItem(show2, ""));
                    this.listViewNoiDung.Items.Add(show2);
                    idList.Add(note.SoThuTu);
                }
            }
        }
Example #7
0
        //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
            {
            }
        }
Example #8
0
        private void listViewNoiDung_Click(object sender, EventArgs e)
        {
            if (this.listViewNoiDung.SelectedItems.Count <= 0)
            {
                return;
            }
            this.lbInfo.Text = "";
            int i = this.listViewNoiDung.SelectedItems[0].Index;
            //int j = this.listViewNoiDung.SelectedItems[1].Index;
            int stt = idList[i];

            if (stt == -1)
            {
                this.listViewNoiDung.SelectedIndices.Clear();
                return;
            }
            Note source = NoteControllers.getNote(stt);

            this.rtbTypeNoiDung.Text = source.NoiDung;
            this.rtbShowTag.Clear();
            this.rtbred.Clear();
            if (source.Tags.Count <= 0)
            {
                return;
            }
            string showTags = "";

            foreach (Tag tag in source.Tags)
            {
                showTags = showTags + tag.TenTag + " ";
            }
            this.rtbShowTag.Text = showTags;
            this.rtbred.Text     = showTags;
        }
Example #9
0
        private void txbTypeTag_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                {
                    if (this.txbTypeTag.Text == "")
                    {
                        return;
                    }
                    if (this.listViewNoiDung.SelectedItems.Count <= 0)
                    {
                        return;
                    }

                    List <Tag> get    = TagControllers.getAllTag();
                    Tag        gettag = new Tag();
                    gettag.TenTag = this.txbTypeTag.Text;
                    TagControllers.addTag(gettag);

                    Tag tagforadd = TagControllers.getoneTag(this.txbTypeTag.Text);
                    int selectt   = this.listViewNoiDung.SelectedItems[0].Index;
                    //int i2 = this.listViewNoiDung.SelectedItems[1].Index;
                    int  chose    = idList[selectt]++;
                    Note getchose = NoteControllers.getNote(chose);
                    getchose.Tags.Add(tagforadd);

                    Note temp = new Note();
                    temp.SoThuTu  = getchose.SoThuTu;
                    temp.TieuDe   = getchose.TieuDe;
                    temp.NoiDung  = getchose.NoiDung;
                    temp.ThongTin = getchose.ThongTin;
                    temp.Rac      = getchose.Rac;
                    temp.PintoTop = getchose.PintoTop;
                    foreach (Tag fina in getchose.Tags)
                    {
                        temp.Tags.Add(fina);
                    }

                    NoteControllers.deleteNote(getchose);
                    NoteControllers.addNote(getchose);

                    string show = "";
                    foreach (Tag forshow in getchose.Tags)
                    {
                        show = show + forshow.TenTag + " ";
                    }
                    this.rtbShowTag.Text = show;
                    this.rtbred.Text     = show;

                    this.txbTypeTag.Text = "";
                }
            }
        }
Example #10
0
        //hien thi danh sach note trong Trash theo note.Tittle tren listview lv
        //dong thoi cap nhat idtemp
        private void displayTrash()
        {
            idtemp.Clear();
            this.lv.Items.Clear();
            List <Note> notes = NoteControllers.getAllNotes();

            for (int i = (notes.Count() - 1); i >= 0; i--)
            {
                Note note = notes[i];
                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);
                }
            }
        }
Example #11
0
        private void showRac()
        {
            idList.Clear();
            this.listViewNoiDung.Items.Clear();
            List <Note> get = NoteControllers.getAllNotes();

            for (int i = (get.Count() - 1); i >= 0; i--)
            {
                Note source = get[i];
                if (source.Rac == true)
                {
                    ListViewItem show = new ListViewItem(source.TieuDe.Trim());
                    show.SubItems.Add(new ListViewItem.ListViewSubItem(show, ""));
                    this.listViewNoiDung.Items.Add(show);
                    idList.Add(source.SoThuTu);
                }
            }
        }
Example #12
0
        private void newNoteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (StateofMenu == false)
            {
                return;
            }

            this.listViewNoiDung.SelectedIndices.Clear();

            this.lbInfo.Text = "";

            this.rtbTypeNoiDung.Clear();
            this.rtbShowTag.Clear();
            this.rtbred.Clear();
            this.txbSearch.Text = "";

            Note getnote = new Note();

            getnote.SoThuTu  = NoteControllers.getIdFromDb();
            getnote.TieuDe   = "New note";
            getnote.NoiDung  = "";
            getnote.ThongTin = DateTime.Now;
            getnote.Rac      = false;
            getnote.PintoTop = false;

            NoteControllers.addNote(getnote);
            showNotes();

            int stt = 0;

            while (stt < idList.Count)
            {
                if (idList[stt] == getnote.SoThuTu)
                {
                    break;
                }
                stt++;
            }

            this.listViewNoiDung.Items[stt].Selected = true;
            this.listViewNoiDung.Select();
            this.rtbTypeNoiDung.Text = NoteControllers.getNote(getnote.SoThuTu).NoiDung;
            this.rtbTypeNoiDung.Focus();
        }
Example #13
0
        //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();
        }
Example #14
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.listViewNoiDung.SelectedItems.Count == 0)
            {
                return;
            }

            int  i     = this.listViewNoiDung.SelectedItems[0].Index;
            int  stt   = idList[i];
            Note souce = NoteControllers.getNote(stt);

            souce.Rac = true;
            NoteControllers.updateNote(souce);
            showNotes();
            this.rtbTypeNoiDung.Clear();
            this.rtbShowTag.Clear();
            this.rtbred.Clear();
            this.lbInfo.Text = "";
        }
Example #15
0
        private void btnRes_Click(object sender, EventArgs e)
        {
            if (this.listViewNoiDung.SelectedItems.Count <= 0)
            {
                return;
            }
            int i = this.listViewNoiDung.SelectedItems[0].Index;
            //int j = this.listViewNoiDung.SelectedItems[1].Index;
            int stt = idList[i];

            Note get = NoteControllers.getNote(stt);

            get.Rac = false;
            NoteControllers.updateNote(get);
            showRac();
            this.rtbTypeNoiDung.Clear();
            this.rtbShowTag.Clear();
            this.rtbred.Clear();
            this.lbInfo.Text = "";
        }
Example #16
0
        //khoi phuc note tu Trash tro lai All Notes, note.isTrash chuyen tu true sang false
        private void btnRestore_Click(object sender, EventArgs e)
        {
            try
            {
                int  i    = this.lv.SelectedItems[0].Index;
                int  id   = idtemp[i];
                Note note = NoteControllers.getANote(id);
                note.isTrash = false;

                NoteControllers.UpdateNote(note);
                displayTrash();

                this.rtb.Clear();
                this.rtb1.Clear();
                this.lbInfo.Text = "";
            }
            catch
            {
            }
        }
Example #17
0
        private void btnInfo_Click(object sender, EventArgs e)
        {
            if (this.listViewNoiDung.SelectedItems.Count <= 0)
            {
                return;
            }
            this.panel1.BringToFront();
            if (this.lbInfo.Text == "")
            {
                int  i      = this.listViewNoiDung.SelectedItems[0].Index;
                int  stt    = idList[i];
                Note source = NoteControllers.getNote(stt);

                this.lbInfo.Text = "Modified: " + source.ThongTin.ToString().Trim();
            }
            else
            {
                this.lbInfo.Text = "";
                this.panel1.SendToBack();
            }
        }
Example #18
0
        //hien thi hoac tat hien thi thoi diem cap nhat cuoi cung cua note
        private void btnInfo_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.lbInfo.Text == "")
                {
                    int  i    = this.lv.SelectedItems[0].Index;
                    int  id   = idtemp[i];
                    Note note = NoteControllers.getANote(id);

                    this.lbInfo.Text = "Modified: " + note.Info.ToString().Trim();
                }
                else
                {
                    this.lbInfo.Text = "";
                }
            }
            catch
            {
            }
        }
Example #19
0
        private void rtbTypeNoiDung_TextChanged(object sender, EventArgs e)
        {
            if (StateofMenu == true)
            {
                if (listViewNoiDung.SelectedItems.Count == 0)
                {
                    return;
                }

                int i = this.listViewNoiDung.SelectedItems[0].Index;

                //int j = this.listViewNoiDung.SelectedItems[1].Index;
                int  stt    = idList[i];
                Note source = NoteControllers.getNote(stt);

                string nd = source.NoiDung;

                source.NoiDung = this.rtbTypeNoiDung.Text.ToString();

                source.TieuDe = source.NoiDung.Substring(0, DatTieuDe(source.NoiDung));
                if (source.NoiDung != nd)
                {
                    this.lbInfo.Text = "";
                    source.ThongTin  = DateTime.Now;
                }
                if (source.NoiDung == "")
                {
                    source.TieuDe = "New note";
                }

                NoteControllers.updateNote(source);

                this.listViewNoiDung.SelectedItems[0].Text = source.TieuDe.ToString();
            }
            else
            {
                return;
            }
        }
Example #20
0
        //viet hoac thay doi note.content khi o che do All Notes
        //khong the lam dieu tuong tu khi o che do Trash
        private void rtb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (mode == true)
                {
                    int  i    = this.lv.SelectedItems[0].Index;
                    int  id   = idtemp[i];
                    Note note = NoteControllers.getANote(id);

                    string old_Content = note.Content;

                    note.Content = this.rtb.Text.ToString();

                    note.Tittle = note.Content.Substring(0, getfirstline(note.Content));
                    if (note.Content != old_Content)
                    {
                        this.lbInfo.Text = "";
                        note.Info        = DateTime.Now;
                    }
                    if (note.Content == "")
                    {
                        note.Tittle = "New note";
                    }

                    NoteControllers.UpdateNote(note);

                    this.lv.SelectedItems[0].Text = note.Tittle.ToString();
                }
                else
                {
                    return;
                }
            }
            catch
            {
            }
        }
Example #21
0
        private void bunifuSwitch1_Click(object sender, EventArgs e)
        {
            if (this.listViewNoiDung.SelectedItems.Count <= 0)
            {
                return;
            }
            int i = this.listViewNoiDung.SelectedItems[0].Index;
            //int j = this.listViewNoiDung.SelectedItems[1].Index;
            int  stt = idList[i];
            Note get = NoteControllers.getNote(stt);

            if (get.PintoTop == false)
            {
                get.PintoTop = true;
            }
            else
            {
                get.PintoTop = false;
            }

            NoteControllers.updateNote(get);
            showNotes();

            int x = 0;

            while (x < idList.Count)
            {
                if (idList[x] == get.SoThuTu)
                {
                    break;
                }
                x++;
            }
            this.listViewNoiDung.Items[x].Selected = true;
            this.listViewNoiDung.Select();
        }
Example #22
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
            {
            }
        }
Example #23
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);
                        }
                    }
                }
            }
        }
Example #24
0
        private void txbSearch_TextChanged(object sender, EventArgs e)
        {
            if (this.txbSearch.Text == "")
            {
                if (StateofMenu == true)
                {
                    showNotes();
                }
                else
                {
                    showRac();
                }
                return;
            }
            this.listViewNoiDung.SelectedIndices.Clear();
            this.lbInfo.Text = "";
            this.rtbTypeNoiDung.Clear();
            this.rtbShowTag.Clear();
            this.rtbred.Clear();
            this.listViewNoiDung.Items.Clear();
            List <Note> notes = NoteControllers.getAllNotesbyString(this.txbSearch.Text);
            List <Tag>  tags  = TagControllers.getAllTagbyString(this.txbSearch.Text);

            if (StateofMenu == true)
            {
                idList.Clear();
                ListViewItem timkiem = new ListViewItem("Tim kiem theo noi dung:");
                this.listViewNoiDung.Items.Add(timkiem);
                idList.Add(-1);


                foreach (Note get in notes)
                {
                    if (get.Rac == false && get.PintoTop == true)
                    {
                        ListViewItem duocpin = new ListViewItem(get.TieuDe.Trim());
                        duocpin.SubItems.Add(new ListViewItem.ListViewSubItem(duocpin, "o"));
                        this.listViewNoiDung.Items.Add(duocpin);
                        idList.Add(get.SoThuTu);
                    }
                }

                foreach (Note get in notes)
                {
                    if (get.Rac == false && get.PintoTop == false)
                    {
                        ListViewItem kduocpin = new ListViewItem(get.TieuDe.Trim());
                        kduocpin.SubItems.Add(new ListViewItem.ListViewSubItem(kduocpin, ""));
                        this.listViewNoiDung.Items.Add(kduocpin);
                        idList.Add(get.SoThuTu);
                    }
                }


                ListViewItem kiemtag = new ListViewItem("Tim kiem theo hashtag:");
                this.listViewNoiDung.Items.Add(kiemtag);
                idList.Add(-1);

                foreach (Tag source in tags)
                {
                    foreach (Note get in source.Notes)
                    {
                        if (get.Rac == false && get.PintoTop == true)
                        {
                            ListViewItem tagpin = new ListViewItem(get.TieuDe.Trim());
                            tagpin.SubItems.Add(new ListViewItem.ListViewSubItem(tagpin, "o"));
                            this.listViewNoiDung.Items.Add(tagpin);
                            idList.Add(get.SoThuTu);
                        }
                    }

                    foreach (Note get in source.Notes)
                    {
                        if (get.Rac == false && get.PintoTop == false)
                        {
                            ListViewItem tagnotpin = new ListViewItem(get.TieuDe.Trim());
                            tagnotpin.SubItems.Add(new ListViewItem.ListViewSubItem(tagnotpin, ""));
                            this.listViewNoiDung.Items.Add(tagnotpin);
                            idList.Add(get.SoThuTu);
                        }
                    }
                }
            }

            if (StateofMenu == false)
            {
                idList.Clear();

                ListViewItem nd = new ListViewItem("Tim kiem theo noi dung:");
                this.listViewNoiDung.Items.Add(nd);
                idList.Add(-1);

                foreach (Note get in notes)
                {
                    if (get.Rac == true)
                    {
                        ListViewItem searchnd = new ListViewItem(get.TieuDe.Trim());
                        searchnd.SubItems.Add(new ListViewItem.ListViewSubItem(searchnd, ""));
                        this.listViewNoiDung.Items.Add(searchnd);
                        idList.Add(get.SoThuTu);
                    }
                }


                ListViewItem tg = new ListViewItem("Tim kiem theo hashTag:");
                this.listViewNoiDung.Items.Add(tg);
                idList.Add(-1);
                foreach (Tag tag in tags)
                {
                    foreach (Note get in tag.Notes)
                    {
                        if (get.Rac == true)
                        {
                            ListViewItem searchtg = new ListViewItem(get.TieuDe.Trim());
                            searchtg.SubItems.Add(new ListViewItem.ListViewSubItem(searchtg, ""));
                            this.listViewNoiDung.Items.Add(searchtg);
                            idList.Add(get.SoThuTu);
                        }
                    }
                }
            }
        }
Example #25
0
        //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
            {
            }
        }