82 lines
2.4 KiB
C#
82 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace WpfApp1
|
|
{
|
|
/// <summary>
|
|
/// Логика взаимодействия для ViewRecordsWindow.xaml
|
|
/// </summary>
|
|
public partial class ViewRecordsWindow : Window
|
|
{
|
|
private Client _client;
|
|
private List<Entry> _allEntries = new List<Entry>();
|
|
private const string FilePath = "entries.json";
|
|
|
|
public ViewRecordsWindow(Client client)
|
|
{
|
|
InitializeComponent();
|
|
_client = client;
|
|
txtClientName.Text = $"{client.surname} {client.name[0]}.{client.patronymic[0]}.";
|
|
|
|
LoadEntries();
|
|
}
|
|
|
|
private void LoadEntries()
|
|
{
|
|
if (File.Exists(FilePath))
|
|
{
|
|
string json = File.ReadAllText(FilePath);
|
|
_allEntries = JsonSerializer.Deserialize<List<Entry>>(json) ?? new List<Entry>();
|
|
}
|
|
RefreshList();
|
|
}
|
|
|
|
private void RefreshList()
|
|
{
|
|
if (_allEntries == null) return;
|
|
|
|
var clientEntries = _allEntries
|
|
.Where(e => e.Client != null &&
|
|
e.Client.subscriptionNumber == _client.subscriptionNumber)
|
|
.ToList();
|
|
|
|
RecordsListBox.ItemsSource = clientEntries;
|
|
}
|
|
|
|
private void btnCancel_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var selected = RecordsListBox.SelectedItem as Entry;
|
|
if (selected == null)
|
|
{
|
|
MessageBox.Show("Выберите запись для отмены!");
|
|
return;
|
|
}
|
|
|
|
if (MessageBox.Show("Вы уверены, что хотите отменить запись?", "Удаление", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
|
{
|
|
_allEntries.Remove(selected);
|
|
File.WriteAllText(FilePath, JsonSerializer.Serialize(_allEntries));
|
|
RefreshList();
|
|
}
|
|
}
|
|
|
|
private void btnBack_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
}
|
|
}
|