Ejemplo n.º 1
0
 public bool DeleteItem(long itemId)
 {
     try
     {
         RemarkNote item = GetItemById(itemId);
         if (item == null)
         {
             return(false);
         }
         if (Notes != null)//remove item from memory
         {
             Notes.Remove(item);
         }
         if (!XmlFile.RemoveSection(itemId + ""))
         {
             return(false);
         }
         else
         {
             RiseEvent(OnItemRemoved, item);
             XmlFile.SaveDocument();
             return(true);
         }
     }
     catch (Exception ex) { LastException = ex; return(false); }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Save this item to xml file
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 private bool SaveItem(RemarkNote item)
 {
     try
     {
         string section = item.Id + "";
         XmlFile.SetValue(section, RemarkNoteDataNames.Text, item.Text);
         XmlFile.SetValue(section, RemarkNoteDataNames.Time, item.Time.ToBinary() + "");
         XmlFile.SetValue(section, RemarkNoteDataNames.IsRead, item.IsRead + "");
         return(true);
     }
     catch (Exception ex) { LastException = ex; return(false); }
 }
Ejemplo n.º 3
0
 private RemarkNote GetRecord(string section)
 {
     try
     {
         Dictionary <string, string> data = XmlFile.GetEntryValues(section);
         RemarkNote item = new RemarkNote();
         item.Text   = data[RemarkNoteDataNames.Text];
         item.Time   = DateTime.FromBinary(long.Parse(data[RemarkNoteDataNames.Time]));
         item.IsRead = bool.Parse(data[RemarkNoteDataNames.IsRead]);
         return(item);
     }
     catch { return(null); }
 }
Ejemplo n.º 4
0
 private void item_OnDataChanged(object sender, DataChangeEventArgs e)
 {
     try
     {
         RemarkNote item = (RemarkNote)sender;
         if (item == null)
         {
             return;
         }
         RiseEvent(OnItemEdited, sender, e);
         string section  = item.Id + "";
         string newValue = e.NewValue is DateTime ? ((DateTime)e.NewValue).ToBinary() + "" : e.NewValue + "";
         if (e.DataName == RemarkNoteDataNames.Time && ((DateTime)e.NewValue) > DateTime.Now)
         {
             item.IsRead = false;
         }
         XmlFile.SetValue(section, e.DataName, newValue);
         XmlFile.SaveDocument();
     }
     catch { }
 }
Ejemplo n.º 5
0
        private void LoadRecords()
        {
            Notes = new List <RemarkNote>();
            List <string> sections = XmlFile.GetSectionNames();

            foreach (string section in sections)
            {
                RemarkNote item = GetRecord(section);
                if (item == null)
                {
                    continue;
                }
                item.Id = long.Parse(section);
                if (item.Id > MaxId)
                {
                    MaxId = item.Id;
                }
                RegisterItemEvents(item);
                Notes.Add(item);
            }
            //    Items.Sort(PhoneItemComparer.Instance);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// If the item found return
 /// Return null if the add item failied
 /// </summary>
 /// <param name="item"></param>
 public RemarkNote AddItem(string Text, DateTime Time)
 {
     try
     {
         RemarkNote item = new RemarkNote(Text, Time);
         item.Id = ++MaxId;
         if (SaveItem(item))
         {
             RegisterItemEvents(item);
             if (Notes != null)
             {
                 Notes.Add(item);
             }
             RiseEvent(OnItemAdded, item);
             XmlFile.SaveDocument();
             return(item);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception ex) { LastException = ex; return(null); }
 }
Ejemplo n.º 7
0
 private void RegisterItemEvents(RemarkNote item)
 {
     item.OnDataChanged += new SIPProvider.SIPCore.DataChanged(item_OnDataChanged);
 }