Ejemplo n.º 1
0
        public void Add(JournalItem item)
        {
            Collection.Insert(0, item);
            item.Id = Collection.Count.ToString();

            Update();
        }
Ejemplo n.º 2
0
        public ObservableCollection <JournalItem> Load()
        {
            string[] text = File.ReadAllText(FileName).Split('\n');
            ObservableCollection <JournalItem> collection = new ObservableCollection <JournalItem>();

            foreach (string journalItemTxt in text)
            {
                if (journalItemTxt != string.Empty)
                {
                    JournalItem journalItem = new JournalItem();
                    try
                    {
                        string[] textSplit = journalItemTxt.Split(":");

                        journalItem.Id         = textSplit[1];
                        journalItem.Expression = textSplit[2];
                        collection.Add(journalItem);
                    }
                    catch
                    {
                        continue;
                    }
                }
            }
            for (int i = 0; i < collection.Count; i++)
            {
                collection[i].Id = (collection.Count - i).ToString();
            }

            return(collection);
        }
Ejemplo n.º 3
0
        public void Remove(JournalItem item)
        {
            Collection.Remove(item);
            for (int i = 0; i < Collection.Count; i++)
            {
                Collection[i].Id = (Collection.Count - i).ToString();
            }

            Update();
        }
Ejemplo n.º 4
0
        public void Add(JournalItem item)
        {
            Collection.Insert(0, item);
            item.Id = Collection.Count.ToString();

            using SQLiteConnection dataBase = new SQLiteConnection($"Data Source=Calc.db; Version=3");
            string            command    = @$ "Insert into Journal(Id, Expression)
                                Values(@id, @expression)";
            DynamicParameters parameters = new DynamicParameters();

            parameters.Add("id", item.Id);
            parameters.Add("expression", item.Expression);
            dataBase.Query <JournalItem>(command, parameters);
        }
Ejemplo n.º 5
0
        public void Remove(JournalItem item)
        {
            Collection.Remove(item);
            for (int i = 0; i < Collection.Count; i++)
            {
                Collection[i].Id = (Collection.Count - i).ToString();
            }

            using SQLiteConnection dataBase = new SQLiteConnection($"Data Source=Calc.db; Version=3");
            dataBase.Query(@$ "Delete from Journal
                                  Where Id = {item.Id}");
            for (int i = int.Parse(item.Id) + 1; i <= Collection.Count + 1; i++)
            {
                dataBase.Query(@$ "Update Journal
                                      Set Id = {i - 1} where Id = {i}");
            }
        }