Example #1
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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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
            {
            }
        }
Example #9
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
            {
            }
        }