public int SaveNote(NoteStruct Note)
        {
            XmlElement root = doc.DocumentElement;

            if (Note.NoteID == -1)
            {
                XmlElement noteElement = doc.CreateElement(tag_note);
                int        id          = int.Parse(root.GetAttribute(atb_lastid));
                Note.SetID(++id);
                NoteToXml(Note, noteElement);
                root.AppendChild(noteElement);
                root.SetAttribute(atb_lastid, id.ToString());
            }
            else
            {
                bool found = false;
                foreach (XmlElement childElement in root.ChildNodes)
                {
                    if (childElement.GetAttribute(atb_noteid) == Note.NoteID.ToString())
                    {
                        NoteToXml(Note, childElement);
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    XmlElement noteElement = doc.CreateElement(tag_note);
                    NoteToXml(Note, noteElement);
                    root.AppendChild(noteElement);
                }
            }
            doc.Save(fileName);
            return(Note.NoteID);
        }
Exemple #2
0
 private void LoadNote(NoteStruct Note)
 {
     for (int i = 0; i < 24; i++)
     {
         combo_hours.Items.Add(i);
     }
     for (int i = 0; i < 60; i++)
     {
         combo_minutes.Items.Add(i);
     }
     ownNote       = Note;
     txt_note.Text = Note.Note;
     date_deadline.SelectedDate = Note.DeadLine;
     combo_hours.SelectedItem   = Note.DeadLine.Hour;
     combo_minutes.SelectedItem = Note.DeadLine.Minute;
     if (!Note.HasDeadline)
     {
         DisableDatePanel();
     }
     txt_note.Focus();
     txt_note.SelectAll();
     check_do_notify.IsChecked     = Note.DoNotify;
     check_do_notify.IsEnabled     = MainWindow.notificationsEnabled;
     check_pinned_to_top.IsChecked = Note.Pinned;
 }
 private void Init(NoteStruct Note)
 {
     updater          = new DispatcherTimer();
     updater.Interval = MainWindow.CheckInterval;
     updater.Tick    += Refresh;
     ownNote          = Note;
     SetUI();
     updater.Start();
 }
        private void AddNewNote()
        {
            NoteStruct n = new NoteStruct();

            list_todos.Items.Add(n);
            list_todos.SelectedIndex = list_todos.Items.Count - 1;
            backup.SaveNote(n);
            SetWindowHeight();
            EditNote();
        }
 /// <summary>
 /// Serialize (backup) Note object to XML
 /// </summary>
 private void NoteToXml(NoteStruct Note, XmlElement NoteElement)
 {
     NoteElement.SetAttribute(atb_noteid, Note.NoteID.ToString());
     NoteElement.SetAttribute(atb_note, Note.Note);
     NoteElement.SetAttribute(atb_deadline, String.Format("{0}-{1}-{2}-{3}-{4}", Note.DeadLine.Year, Note.DeadLine.Month, Note.DeadLine.Day, Note.DeadLine.Hour, Note.DeadLine.Minute));
     NoteElement.SetAttribute(atb_lastmod, String.Format("{0}-{1}-{2}-{3}-{4}-{5}", Note.LastModified.Year, Note.LastModified.Month, Note.LastModified.Day, Note.LastModified.Hour, Note.LastModified.Minute, Note.LastModified.Second));
     NoteElement.SetAttribute(atb_hasdl, Note.HasDeadline ? "1" : "0");
     NoteElement.SetAttribute(atb_notify, Note.DoNotify.ToString());
     NoteElement.SetAttribute(atb_pinned, Note.Pinned.ToString());
     NoteElement.SetAttribute(atb_done, Note.Done.ToString());
 }
        private void RemoveNote()
        {
            int idx = list_todos.SelectedIndex;

            if (idx != -1)
            {
                NoteStruct note = list_todos.Items[idx] as NoteStruct;
                list_todos.Items.RemoveAt(idx);
                note.DeleteNote();
                backup.DeleteNote(note);
            }
            SetWindowHeight();
        }
        public void DeleteNote(NoteStruct Note)
        {
            lastDeleted = Note;
            XmlElement root = doc.DocumentElement;

            foreach (XmlElement noteElement in root.ChildNodes)
            {
                if (noteElement.GetAttribute(atb_noteid) == Note.NoteID.ToString())
                {
                    root.RemoveChild(noteElement);
                    break;
                }
            }
            doc.Save(filePath);
            // if archiválás ... save to another file
        }
        /// <summary>
        /// Parse note backup (XML) back to object
        /// </summary>
        private NoteStruct XmlToNote(XmlElement NoteElement)
        {
            string[]   deadline     = NoteElement.GetAttribute(atb_deadline).Split('-');
            string[]   lastmod      = NoteElement.GetAttribute(atb_lastmod).Split('-');
            string     has_deadline = NoteElement.GetAttribute(atb_hasdl);
            string     notify       = NoteElement.GetAttribute(atb_notify);
            string     pinned       = NoteElement.GetAttribute(atb_pinned);
            string     done         = NoteElement.GetAttribute(atb_done);
            bool       isPinned     = pinned != String.Empty ? bool.Parse(pinned) : false;
            bool       isDone       = done != String.Empty ? bool.Parse(done) : false;
            NoteStruct note         = new NoteStruct(NoteElement.GetAttribute(atb_note), new DateTime(int.Parse(deadline[0]), int.Parse(deadline[1]), int.Parse(deadline[2]), int.Parse(deadline[3]), int.Parse(deadline[4]), 0), int.Parse(NoteElement.GetAttribute(atb_noteid)), has_deadline == "1" ? true : false, isPinned, isDone);

            if (notify != String.Empty)
            {
                note.SetDoNotify(bool.Parse(notify));
            }
            note.SetLastModifiedDate(new DateTime(int.Parse(lastmod[0]), int.Parse(lastmod[1]), int.Parse(lastmod[2]), int.Parse(lastmod[3]), int.Parse(lastmod[4]), int.Parse(lastmod[5])));
            return(note);
        }
        private void MakeNoteDone()
        {
            int idx = list_todos.SelectedIndex;

            if (idx != -1)
            {
                NoteStruct note = list_todos.Items[idx] as NoteStruct;
                note.MakeDone();
                note.CheckPriority();
                backup.SaveNote(note);
                if (sorted)
                {
                    Sort(lastOrder);
                }
                else
                {
                    RefreshItemsView();
                }
            }
        }
        private void EditNote()
        {
            if (list_todos.SelectedIndex == -1)
            {
                return;
            }
            NoteStruct note  = list_todos.SelectedItem as NoteStruct;
            NoteEditor nedit = new NoteEditor(note);

            nedit.ShowDialog();
            backup.SaveNote(note);
            note.CheckPriority();
            if (sorted)
            {
                Sort(lastOrder);
            }
            else
            {
                RefreshItemsView();
            }
        }
Exemple #11
0
 public NoteEditor(NoteStruct Note)
 {
     InitializeComponent();
     LoadNote(Note);
 }
 public NoteWarn(NoteStruct Note)
 {
     InitializeComponent();
     Init(Note);
 }