diff --git a/.vs/MauiApp1/DesignTimeBuild/.dtbcache.v2 b/.vs/MauiApp1/DesignTimeBuild/.dtbcache.v2 index 3130c5e..7174939 100644 Binary files a/.vs/MauiApp1/DesignTimeBuild/.dtbcache.v2 and b/.vs/MauiApp1/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/MauiApp1/FileContentIndex/07bcac18-d13c-48fb-bc34-d27bcb98c376.vsidx b/.vs/MauiApp1/FileContentIndex/07bcac18-d13c-48fb-bc34-d27bcb98c376.vsidx deleted file mode 100644 index d91b1ed..0000000 Binary files a/.vs/MauiApp1/FileContentIndex/07bcac18-d13c-48fb-bc34-d27bcb98c376.vsidx and /dev/null differ diff --git a/.vs/MauiApp1/FileContentIndex/53ee47c9-2117-4d2f-b4c0-83d36685dac5.vsidx b/.vs/MauiApp1/FileContentIndex/53ee47c9-2117-4d2f-b4c0-83d36685dac5.vsidx deleted file mode 100644 index 89729c1..0000000 Binary files a/.vs/MauiApp1/FileContentIndex/53ee47c9-2117-4d2f-b4c0-83d36685dac5.vsidx and /dev/null differ diff --git a/.vs/MauiApp1/FileContentIndex/5e1b8111-85c6-444e-b8b3-9e58c2165839.vsidx b/.vs/MauiApp1/FileContentIndex/5e1b8111-85c6-444e-b8b3-9e58c2165839.vsidx deleted file mode 100644 index 86e090c..0000000 Binary files a/.vs/MauiApp1/FileContentIndex/5e1b8111-85c6-444e-b8b3-9e58c2165839.vsidx and /dev/null differ diff --git a/.vs/MauiApp1/FileContentIndex/77b6ad76-2213-4118-845e-0c2eb65e3657.vsidx b/.vs/MauiApp1/FileContentIndex/77b6ad76-2213-4118-845e-0c2eb65e3657.vsidx deleted file mode 100644 index 0a4ec63..0000000 Binary files a/.vs/MauiApp1/FileContentIndex/77b6ad76-2213-4118-845e-0c2eb65e3657.vsidx and /dev/null differ diff --git a/.vs/MauiApp1/FileContentIndex/882a1cff-bacc-45f6-98ad-885c20c709b3.vsidx b/.vs/MauiApp1/FileContentIndex/882a1cff-bacc-45f6-98ad-885c20c709b3.vsidx new file mode 100644 index 0000000..fbe52b0 Binary files /dev/null and b/.vs/MauiApp1/FileContentIndex/882a1cff-bacc-45f6-98ad-885c20c709b3.vsidx differ diff --git a/.vs/MauiApp1/FileContentIndex/8a1eb807-278c-4697-9186-1a845940fce8.vsidx b/.vs/MauiApp1/FileContentIndex/8a1eb807-278c-4697-9186-1a845940fce8.vsidx new file mode 100644 index 0000000..3d8f9be Binary files /dev/null and b/.vs/MauiApp1/FileContentIndex/8a1eb807-278c-4697-9186-1a845940fce8.vsidx differ diff --git a/.vs/MauiApp1/FileContentIndex/ae8105b5-eb1f-40cb-b6d3-9ebd2e6c6bad.vsidx b/.vs/MauiApp1/FileContentIndex/ae8105b5-eb1f-40cb-b6d3-9ebd2e6c6bad.vsidx new file mode 100644 index 0000000..51636d0 Binary files /dev/null and b/.vs/MauiApp1/FileContentIndex/ae8105b5-eb1f-40cb-b6d3-9ebd2e6c6bad.vsidx differ diff --git a/.vs/MauiApp1/FileContentIndex/d9ba7ea8-bffe-4f4d-95c8-936b9a538f0f.vsidx b/.vs/MauiApp1/FileContentIndex/d9ba7ea8-bffe-4f4d-95c8-936b9a538f0f.vsidx new file mode 100644 index 0000000..16ccbd0 Binary files /dev/null and b/.vs/MauiApp1/FileContentIndex/d9ba7ea8-bffe-4f4d-95c8-936b9a538f0f.vsidx differ diff --git a/.vs/MauiApp1/v17/.futdcache.v2 b/.vs/MauiApp1/v17/.futdcache.v2 index 12af9c5..403b5ee 100644 Binary files a/.vs/MauiApp1/v17/.futdcache.v2 and b/.vs/MauiApp1/v17/.futdcache.v2 differ diff --git a/.vs/MauiApp1/v17/.suo b/.vs/MauiApp1/v17/.suo index 5ecb70a..77fb53f 100644 Binary files a/.vs/MauiApp1/v17/.suo and b/.vs/MauiApp1/v17/.suo differ diff --git a/.vs/ProjectEvaluation/mauiapp1.metadata.v3 b/.vs/ProjectEvaluation/mauiapp1.metadata.v3 index ebf81e0..af9a25d 100644 Binary files a/.vs/ProjectEvaluation/mauiapp1.metadata.v3 and b/.vs/ProjectEvaluation/mauiapp1.metadata.v3 differ diff --git a/.vs/ProjectEvaluation/mauiapp1.projects.v3 b/.vs/ProjectEvaluation/mauiapp1.projects.v3 index 521b493..409b54a 100644 Binary files a/.vs/ProjectEvaluation/mauiapp1.projects.v3 and b/.vs/ProjectEvaluation/mauiapp1.projects.v3 differ diff --git a/MauiApp1/Helpers/ChangeTransactionFile.cs b/MauiApp1/Helpers/ChangeTransactionFile.cs new file mode 100644 index 0000000..53c7d44 --- /dev/null +++ b/MauiApp1/Helpers/ChangeTransactionFile.cs @@ -0,0 +1,55 @@ +using MauiApp1.Model; +using Newtonsoft.Json; +using System.Collections.ObjectModel; + +namespace MauiApp1.Helpers +{ + public class ChangeTransactionFile + { + static string folder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); + + public static ObservableCollection LoadData(ObservableCollection transactions) + { + ObservableCollection data; + string fileName = "Transactions.json"; + string path = Path.Combine(folder, fileName); + + if (!File.Exists(path)) + { + File.Create(path).Close(); + data = new ObservableCollection(); + } + else + { + string json = ""; + using (StreamReader sr = new StreamReader(path)) + { + json = sr.ReadToEnd(); + } + + data = JsonConvert.DeserializeObject>(json); + if (data == null) + { + foreach (Transaction transaction in data) + { + transactions.Add(transaction); + } + } + } + return data; + } + + public static void SaveData(ObservableCollection transactions) + { + string fileName = "Transactions.json"; + string path = Path.Combine(folder, fileName); + string json = JsonConvert.SerializeObject(transactions); + + using (StreamWriter sw = new StreamWriter(path)) + { + sw.WriteLine(json); + } + } + + } +} diff --git a/MauiApp1/MauiApp1.csproj b/MauiApp1/MauiApp1.csproj index 6ef4b98..497d886 100644 --- a/MauiApp1/MauiApp1.csproj +++ b/MauiApp1/MauiApp1.csproj @@ -57,6 +57,13 @@ + + + + + + MSBuild:Compile + MSBuild:Compile diff --git a/MauiApp1/Model/Transaction.cs b/MauiApp1/Model/Transaction.cs index c2124f8..7bf574b 100644 --- a/MauiApp1/Model/Transaction.cs +++ b/MauiApp1/Model/Transaction.cs @@ -1,32 +1,65 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel; +using Newtonsoft.Json; namespace MauiApp1.Model { - public class Transaction + public class Transaction : INotifyPropertyChanged { private string category; private float price; - + private DateTime date; + + [JsonConstructor] public Transaction(string category, float price) { this.category = category; this.price = price; + date = DateTime.Now; + } + + [JsonProperty] + public DateTime Date + { + get { return date; } + set { date = value; } } + [JsonProperty] public string Category { get { return category; } - set { category = value; } + set + { + if (value != category) + { + category = value; + OnPropertyChanged(nameof(Category)); + } + } } + [JsonProperty] public float Price { get { return price; } - set { price = value; } + set + { + if (value != price) + { + price = value; + OnPropertyChanged(nameof(Price)); + } + } + } + + public event PropertyChangedEventHandler PropertyChanged; + + public void OnPropertyChanged(string property) + { + if (property != null) + { + PropertyChanged(this, new(property)); + } } } } diff --git a/MauiApp1/View/AddTransactionView.xaml b/MauiApp1/View/AddTransactionView.xaml index 5fb61e6..87014fc 100644 --- a/MauiApp1/View/AddTransactionView.xaml +++ b/MauiApp1/View/AddTransactionView.xaml @@ -7,13 +7,16 @@