ver 1.1
This commit is contained in:
@@ -123,7 +123,6 @@ namespace WpfApp1
|
||||
{
|
||||
if (_selectedClient == null) return;
|
||||
|
||||
// Адрес и Телефон
|
||||
_selectedClient.address = txtAddress.Text;
|
||||
_selectedClient.phoneNumber = txtPhone.Text;
|
||||
|
||||
@@ -139,7 +138,6 @@ namespace WpfApp1
|
||||
return;
|
||||
}
|
||||
|
||||
// Пример списка тренеров (обычно загружается из файла)
|
||||
List<Coach> coaches = new List<Coach> {
|
||||
new Coach { Surname="Ахматова В.А.", Speciality="Фитнес-ЙОГА" },
|
||||
new Coach { Surname="Петров И.И.", Speciality="Силовой тренинг" }
|
||||
@@ -148,5 +146,20 @@ namespace WpfApp1
|
||||
RecordWindow recordWin = new RecordWindow(_selectedClient, coaches);
|
||||
recordWin.ShowDialog();
|
||||
}
|
||||
|
||||
private void btnViewRecords_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (ClientListBox.SelectedItem == null)
|
||||
{
|
||||
MessageBox.Show("Сначала выберите клиента в списке!", "Внимание", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_selectedClient != null)
|
||||
{
|
||||
ViewRecordsWindow viewWin = new ViewRecordsWindow(_selectedClient);
|
||||
viewWin.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
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;
|
||||
@@ -20,7 +22,7 @@ namespace WpfApp1
|
||||
public partial class RecordWindow : Window
|
||||
{
|
||||
private Client _currentClient;
|
||||
private List<Coach> _allCoaches; // Список всех тренеров (загрузи его из файла или создай вручную)
|
||||
private List<Coach> _allCoaches;
|
||||
|
||||
public RecordWindow(Client client, List<Coach> coaches)
|
||||
{
|
||||
@@ -30,12 +32,10 @@ namespace WpfApp1
|
||||
|
||||
txtClientName.Text = $"{client.surname} {client.name}";
|
||||
|
||||
// Заполняем специальности уникальными значениями
|
||||
cbSpeciality.ItemsSource = _allCoaches.Select(c => c.Speciality).Distinct().ToList();
|
||||
dpDate.SelectedDate = DateTime.Now;
|
||||
}
|
||||
|
||||
// Фильтрация тренеров при выборе специальности
|
||||
private void cbSpeciality_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
string selectedSpec = cbSpeciality.SelectedItem as string;
|
||||
@@ -44,25 +44,51 @@ namespace WpfApp1
|
||||
|
||||
private void btnSaveRecord_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (cbCoach.SelectedItem == null || dpDate.SelectedDate == null)
|
||||
if (cbCoach.SelectedItem == null || dpDate.SelectedDate == null || string.IsNullOrWhiteSpace(txtTime.Text))
|
||||
{
|
||||
MessageBox.Show("Выберите тренера и дату!");
|
||||
MessageBox.Show("Заполните все поля записи!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Создаем объект записи
|
||||
Entry newEntry = new Entry
|
||||
try
|
||||
{
|
||||
Client = _currentClient,
|
||||
Coach = (Coach)cbCoach.SelectedItem,
|
||||
DateEntry = dpDate.SelectedDate.Value,
|
||||
TimeRecord = DateTime.Parse(txtTime.Text) // Упрощенно для примера
|
||||
};
|
||||
// 1. Создаем новый экземпляр записи
|
||||
Entry newEntry = new Entry
|
||||
{
|
||||
Client = _currentClient,
|
||||
Coach = (Coach)cbCoach.SelectedItem,
|
||||
DateEntry = dpDate.SelectedDate.Value,
|
||||
TimeRecord = DateTime.Parse(txtTime.Text)
|
||||
};
|
||||
|
||||
// Тут добавь логику сохранения Entry в твой глобальный List или файл
|
||||
|
||||
MessageBox.Show("Запись успешно создана!");
|
||||
this.Close(); // Возврат на главную форму
|
||||
string filePath = "entries.json";
|
||||
List<Entry> allEntries;
|
||||
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
string existingJson = File.ReadAllText(filePath);
|
||||
allEntries = JsonSerializer.Deserialize<List<Entry>>(existingJson) ?? new List<Entry>();
|
||||
}
|
||||
else
|
||||
{
|
||||
allEntries = new List<Entry>();
|
||||
}
|
||||
|
||||
allEntries.Add(newEntry);
|
||||
|
||||
|
||||
string updatedJson = JsonSerializer.Serialize(allEntries, new JsonSerializerOptions { WriteIndented = true });
|
||||
File.WriteAllText(filePath, updatedJson);
|
||||
|
||||
MessageBox.Show("Запись успешно создана и сохранена!");
|
||||
this.DialogResult = true;
|
||||
this.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Ошибка при сохранении: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
35
WpfApp1/WpfApp1/ViewRecordsWindow.xaml
Normal file
35
WpfApp1/WpfApp1/ViewRecordsWindow.xaml
Normal file
@@ -0,0 +1,35 @@
|
||||
<Window x:Class="WpfApp1.ViewRecordsWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:WpfApp1"
|
||||
mc:Ignorable="d"
|
||||
Style="{StaticResource MainDarkWindow}"
|
||||
Title="ViewRecordsWindow" Height="450" Width="299">
|
||||
<Grid Margin="15">
|
||||
<StackPanel>
|
||||
<TextBlock Text="Клиент" Margin="0,5" Foreground="White"/>
|
||||
<TextBox x:Name="txtClientName" IsReadOnly="True" Background="#3D3D3D" Foreground="White" Margin="0,0,0,15"/>
|
||||
|
||||
<TextBlock Text="Записи:" Margin="0,5" Foreground="White"/>
|
||||
<ListBox x:Name="RecordsListBox" Height="150" Background="#2D2D2D" Foreground="White" BorderBrush="White">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
|
||||
<!-- Кнопки управления -->
|
||||
<Grid Margin="0,15,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button x:Name="btnBack" Content="Назад" Grid.Column="0" Margin="0,0,5,0" Height="35" Click="btnBack_Click"/>
|
||||
<Button x:Name="btnCancel" Content="Отменить запись" Grid.Column="1" Margin="5,0,0,0" Height="35" Click="btnCancel_Click"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
81
WpfApp1/WpfApp1/ViewRecordsWindow.xaml.cs
Normal file
81
WpfApp1/WpfApp1/ViewRecordsWindow.xaml.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,6 +88,9 @@
|
||||
<Compile Include="RecordWindow.xaml.cs">
|
||||
<DependentUpon>RecordWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ViewRecordsWindow.xaml.cs">
|
||||
<DependentUpon>ViewRecordsWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Page Include="MainWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
@@ -107,6 +110,10 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="ViewRecordsWindow.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
|
||||
Reference in New Issue
Block a user