예제 #1
0
        public void Add(MemoryItem item)
        {
            Collection.Insert(0, item);
            item.Id = Collection.Count.ToString();

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

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

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

            return(collection);
        }
예제 #3
0
        public void Remove(MemoryItem item)
        {
            Collection.Remove(item);
            for (int i = 0; i < Collection.Count; i++)
            {
                Collection[i].Id = (Collection.Count - i).ToString();
            }

            Update();
        }
예제 #4
0
        public void Add(MemoryItem 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 Memory(Id, Result)
                                Values(@id, @result)";
            DynamicParameters parameters = new DynamicParameters();

            parameters.Add("id", item.Id);
            parameters.Add("result", item.Result);
            dataBase.Query <MemoryItem>(command, parameters);
        }
예제 #5
0
        public void Remove(MemoryItem 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 Memory
                                  Where Id = {item.Id}");
            for (int i = int.Parse(item.Id) + 1; i <= Collection.Count + 1; i++)
            {
                dataBase.Query(@$ "Update Memory
                                      Set Id = {i - 1} where Id = {i}");
            }
        }