Move files for better organization
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using ReceiptPDFBuilder.Helpers;
|
||||
|
||||
namespace ReceiptPDFBuilder.Models;
|
||||
|
||||
class PDFReport : ChangeNotifier
|
||||
{
|
||||
private string _baseFolder;
|
||||
private string _title;
|
||||
private List<ReportFile> _files;
|
||||
private DateTime _lastSaved;
|
||||
private DateTime? _lastGenerated;
|
||||
|
||||
public PDFReport()
|
||||
{
|
||||
_baseFolder = "";
|
||||
_title = "";
|
||||
_files = [];
|
||||
_lastSaved = DateTime.Now;
|
||||
_lastGenerated = null;
|
||||
}
|
||||
|
||||
public string BaseFolder
|
||||
{
|
||||
get => _baseFolder;
|
||||
set { _baseFolder = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
public string Title
|
||||
{
|
||||
get => _title;
|
||||
set { _title = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
public List<ReportFile> Files
|
||||
{
|
||||
get => _files;
|
||||
set { _files = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
public DateTime LastSaved
|
||||
{
|
||||
get => _lastSaved;
|
||||
set { _lastSaved = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
public DateTime? LastGenerated
|
||||
{
|
||||
get => _lastGenerated;
|
||||
set { _lastGenerated = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.Json.Serialization;
|
||||
using ReceiptPDFBuilder.Helpers;
|
||||
|
||||
namespace ReceiptPDFBuilder.Models;
|
||||
|
||||
class ReportFile : ChangeNotifier
|
||||
{
|
||||
private string _title;
|
||||
private DateTime _receiptDateTime;
|
||||
private string _notes;
|
||||
private string _filePath;
|
||||
|
||||
public ReportFile()
|
||||
{
|
||||
_title = "";
|
||||
_receiptDateTime = DateTime.Now;
|
||||
_notes = "";
|
||||
_filePath = "";
|
||||
}
|
||||
|
||||
public ReportFile(ReportFile other)
|
||||
{
|
||||
Title = _title = other.Title;
|
||||
ReceiptDateTime = _receiptDateTime = other.ReceiptDateTime;
|
||||
Notes = _notes = other.Notes;
|
||||
FilePath = _filePath = other.FilePath;
|
||||
}
|
||||
|
||||
public string Title
|
||||
{
|
||||
get => _title;
|
||||
set { _title = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
public DateTime ReceiptDateTime
|
||||
{
|
||||
get => _receiptDateTime;
|
||||
set
|
||||
{
|
||||
_receiptDateTime = value;
|
||||
NotifyPropertyChanged();
|
||||
NotifyPropertyChanged(nameof(ReceiptDate));
|
||||
}
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public DateOnly ReceiptDate
|
||||
{
|
||||
get => DateOnly.FromDateTime(_receiptDateTime);
|
||||
}
|
||||
|
||||
public string Notes
|
||||
{
|
||||
get => _notes;
|
||||
set { _notes = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
public string FilePath
|
||||
{
|
||||
get => _filePath;
|
||||
set
|
||||
{
|
||||
_filePath = value;
|
||||
NotifyPropertyChanged();
|
||||
NotifyPropertyChanged(nameof(FileName));
|
||||
NotifyPropertyChanged(nameof(IsFileFoundOnDisk));
|
||||
}
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public string FileName
|
||||
{
|
||||
get => Path.GetFileName(_filePath);
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool IsFileFoundOnDisk
|
||||
{
|
||||
get => File.Exists(FilePath);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using ReceiptPDFBuilder.Helpers;
|
||||
using ReceiptPDFBuilders.Helpers;
|
||||
|
||||
namespace ReceiptPDFBuilder.Models;
|
||||
|
||||
class Settings : ChangeNotifier
|
||||
{
|
||||
private string _lastUsedPath;
|
||||
|
||||
public Settings()
|
||||
{
|
||||
_lastUsedPath = "";
|
||||
}
|
||||
|
||||
[JsonInclude]
|
||||
public string LastUsedPath
|
||||
{
|
||||
get => _lastUsedPath;
|
||||
set { _lastUsedPath = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
public static string GetSettingsFileName()
|
||||
{
|
||||
return "settings.json";
|
||||
}
|
||||
|
||||
public static string GetSettingsPath()
|
||||
{
|
||||
var path = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||
"ReceiptPDFBuilder"
|
||||
);
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
return Path.Combine(path, GetSettingsFileName());
|
||||
}
|
||||
|
||||
public async Task<string> SaveSettingsAsync()
|
||||
{
|
||||
var jsonContext = new SourceGenerationContext(Utilities.GetSerializerOptions());
|
||||
using MemoryStream memoryStream = new MemoryStream();
|
||||
await JsonSerializer.SerializeAsync(memoryStream, this, jsonContext.Settings);
|
||||
memoryStream.Position = 0;
|
||||
using var reader = new StreamReader(memoryStream);
|
||||
var json = await reader.ReadToEndAsync();
|
||||
await File.WriteAllTextAsync(GetSettingsPath(), json);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static Settings LoadSettings()
|
||||
{
|
||||
var path = GetSettingsPath();
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
return new Settings();
|
||||
}
|
||||
var json = File.ReadAllText(GetSettingsPath());
|
||||
var jsonContext = new SourceGenerationContext(Utilities.GetSerializerOptions());
|
||||
return JsonSerializer.Deserialize<Settings>(json, jsonContext.Settings) ?? new Settings();
|
||||
}
|
||||
|
||||
public static async Task<Settings> LoadSettingsAsync()
|
||||
{
|
||||
using FileStream fileStream = File.OpenRead(GetSettingsPath());
|
||||
var jsonContext = new SourceGenerationContext(Utilities.GetSerializerOptions());
|
||||
var output = await JsonSerializer.DeserializeAsync<Settings>(fileStream, jsonContext.Settings) ?? new Settings();
|
||||
return output;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user