Exemplo n.º 1
0
        /// <summary>
        /// Handle click when user click on "Xong" button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void doneClick(object sender, RoutedEventArgs e)
        {
            FlowDocument content = contentNote.Document;

            TextPointer startPointer = content.ContentStart.GetNextInsertionPosition(LogicalDirection.Forward);
            TextPointer endPointer   = content.ContentEnd.GetNextInsertionPosition(LogicalDirection.Backward);

            if (startPointer == null || endPointer == null || startPointer.CompareTo(endPointer) == 0)
            {
                MessageBoxResult boxResult = MessageBox.Show("Chưa có nội dung note", "Notification", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                MemoryStream memoryStream = new MemoryStream();
                TextRange    textRange    = new TextRange(content.ContentStart, content.ContentEnd);
                textRange.Save(memoryStream, System.Windows.DataFormats.XamlPackage);
                byte[] byteArray = new byte[memoryStream.Length];
                byteArray = memoryStream.ToArray();

                Tag itemToRemove = null;
                do
                {
                    itemToRemove = noteTags.FirstOrDefault(r => r.IsSelected == false);
                    if (itemToRemove != null)
                    {
                        noteTags.Remove(itemToRemove);
                    }
                } while (itemToRemove != null);

                if (editableNote == null)
                {
                    editableNote = new Note()
                    {
                        Id           = -1,
                        Title        = titleNote.Text,
                        Document     = byteArray,
                        LastModified = DateTime.Now,
                        ColorNote    = colorTag
                    };
                }
                else
                {
                    editableNote.Title        = titleNote.Text;
                    editableNote.Document     = byteArray;
                    editableNote.LastModified = DateTime.Now;
                    editableNote.ColorNote    = colorTag;
                }

                NoteUpdateEventArgs args = new NoteUpdateEventArgs(editableNote, noteTags);
                NoteUpdate(this, args);

                this.Close();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handle Done Click on NoteWindow send
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NoteWindow_DoneClick(object sender, NoteUpdateEventArgs e)
        {
            if (e.Note.Id == -1 || databaseManager.CheckNoteExist(e.Note.Id) == false)
            {
                databaseManager.InsertNote(e.Note, e.Tags);
            }
            else
            {
                databaseManager.ModifyNote(e.Note, e.Tags);
            }

            dataTags            = new ObservableCollection <QuickNote.Tag>(databaseManager.GetListTag());
            listTag.DataContext = new TagsViewModel(dataTags);
            listTag.Items.Refresh();
            listTag.Focus();

            OnClick_AllNotes(allNotesBtn, null);
        }