Доделать создание записей клиентов в классе AppointmentWindow.xaml.cs
Реализовать просмотр списка записей у клиента
This commit is contained in:
@@ -10,5 +10,13 @@ namespace UP01Task2App.Models
|
||||
public string Name { get; set; }
|
||||
public string Patronymic { get; set; }
|
||||
public string Speciality { get; set; }
|
||||
|
||||
public string ShortName
|
||||
{
|
||||
get
|
||||
{
|
||||
return $"{Surmname} {Name[0]}.{Patronymic[0]}.";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,5 +67,44 @@ namespace UP01Task2App.Services
|
||||
public void SaveTrainerDataToJson(List<Trainer> trainersList) => SaveToJson(trainerPath, trainersList);
|
||||
public void SaveClientDataToJson(List<Client> clientsList) => SaveToJson(clientPath, clientsList);
|
||||
public void SaveRecordDataToJson(List<Record> recordsList) => SaveToJson(recordPath, recordsList);
|
||||
|
||||
#if DEBUG
|
||||
private void CreateTrainersJson()
|
||||
{
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
|
||||
string text = File.ReadAllText("asd.txt", Encoding.GetEncoding(1251));
|
||||
|
||||
List<Trainer> trList = new();
|
||||
|
||||
foreach (var line in text.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
var parts = line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
trList.Add(new Trainer
|
||||
{
|
||||
Surmname = parts[0],
|
||||
Name = parts[1],
|
||||
Patronymic = parts[2],
|
||||
Speciality = string.Join(" ", parts.Skip(3))
|
||||
});
|
||||
}
|
||||
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
};
|
||||
|
||||
string json = JsonSerializer.Serialize(trList, options);
|
||||
|
||||
MessageBox.Show(json);
|
||||
|
||||
string path = "data/trainers.json";
|
||||
|
||||
Directory.CreateDirectory(System.IO.Path.GetDirectoryName(path)!);
|
||||
|
||||
File.WriteAllText(path, json, Encoding.UTF8);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,5 +56,10 @@ namespace UP01Task2App.Services
|
||||
if (!Regex.IsMatch(obj.Text.Trim(), pattern))
|
||||
throw new ArgumentException($"Номер телефона в поле \"{fieldName}\" имеет неверный формат \nВерный формат: +79999999999 или 79999999999");
|
||||
}
|
||||
public static void ValidateNotNullComboBox(ComboBox obj, string fieldName)
|
||||
{
|
||||
if (obj.SelectedValue == null)
|
||||
throw new ArgumentException($"Выберите значение в поле \"{fieldName}\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,13 +13,14 @@
|
||||
<TextBlock Text="{Binding SelectedClient.LastName}" Margin="0,0,0,10" FontSize="16"/>
|
||||
|
||||
<TextBlock Text="Тренировка"/>
|
||||
<ComboBox ItemsSource="{Binding Specializations}"
|
||||
SelectedItem="{Binding SelectedSpecialization}"
|
||||
Style="{StaticResource ComboBoxStyle}"/>
|
||||
<ComboBox Name="TrainingTextBox"
|
||||
ItemsSource="{Binding TrainersSpeciality}"
|
||||
Style="{StaticResource ComboBoxStyle}" SelectionChanged="TrainingTextBox_SelectionChanged"/>
|
||||
|
||||
<TextBlock Text="Тренер"/>
|
||||
<ComboBox ItemsSource="{Binding Trainers}"
|
||||
SelectedItem="{Binding SelectedTrainer}"
|
||||
<ComboBox Name="TrainerTextBox"
|
||||
DisplayMemberPath = "ShortName"
|
||||
ItemsSource="{Binding Trainers}"
|
||||
Style="{StaticResource ComboBoxStyle}"/>
|
||||
|
||||
<TextBlock Text="Дата"/>
|
||||
@@ -27,10 +28,9 @@
|
||||
Style="{StaticResource DatePickerStyle}"/>
|
||||
|
||||
<Button Content="Записать"
|
||||
Command="{Binding SaveAppointmentCommand}"
|
||||
Margin="0,30,0,0"
|
||||
Width="200"
|
||||
Style="{StaticResource ButtonStyle}"/>
|
||||
Style="{StaticResource ButtonStyle}" Click="Button_Click"/>
|
||||
|
||||
</StackPanel>
|
||||
</Window>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Security.Policy;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@@ -9,6 +11,8 @@ using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using UP01Task2App.Models;
|
||||
using UP01Task2App.Services;
|
||||
|
||||
namespace UP01Task2App.Windows
|
||||
{
|
||||
@@ -17,9 +21,62 @@ namespace UP01Task2App.Windows
|
||||
/// </summary>
|
||||
public partial class AppointmentWindow : Window
|
||||
{
|
||||
public AppointmentWindow()
|
||||
private List<Trainer> TrainersList { get; set; }
|
||||
public List<string> TrainersSpecialities { get; set; }
|
||||
public Record OutputRecord { get; private set; }
|
||||
public ObservableCollection<Trainer> Trainers { get; set; } = new ObservableCollection<Trainer>();
|
||||
public ObservableCollection<string> TrainersSpeciality { get; set; } = new ObservableCollection<string>();
|
||||
|
||||
public AppointmentWindow(List<Trainer> _trainersList, Client client)
|
||||
{
|
||||
TrainersList = _trainersList;
|
||||
|
||||
foreach (var item in TrainersList)
|
||||
{
|
||||
Trainers.Add(item);
|
||||
}
|
||||
|
||||
TrainersSpecialities = TrainersList
|
||||
.Select(t => t.Speciality)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
foreach (var item in TrainersSpecialities)
|
||||
{
|
||||
TrainersSpeciality.Add(item);
|
||||
MessageBox.Show(item.ToString());
|
||||
}
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
this.DataContext = this;
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ValidationHelper.ValidateNotNullComboBox(TrainingTextBox, "Тренировка");
|
||||
ValidationHelper.ValidateNotNullComboBox(TrainerTextBox, "Тренировка");
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void TrainingTextBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (TrainingTextBox.SelectedIndex != -1)
|
||||
{
|
||||
string? selectedSpeciality = TrainingTextBox.SelectedItem.ToString();
|
||||
|
||||
var filtered = TrainersList
|
||||
.Where(t => t.Speciality == selectedSpeciality)
|
||||
.ToList();
|
||||
|
||||
Trainers.Clear();
|
||||
|
||||
foreach (var trainer in filtered)
|
||||
{
|
||||
Trainers.Add(trainer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,11 +67,11 @@
|
||||
<StackPanel>
|
||||
<Button Content="Запись клиента"
|
||||
Style="{StaticResource ButtonStyle}"
|
||||
Margin="10"/>
|
||||
Margin="10" Click="Button_Click_2"/>
|
||||
|
||||
<Button Content="Просмотреть записи"
|
||||
Style="{StaticResource ButtonStyle}"
|
||||
Margin="10"/>
|
||||
Margin="10" Click="Button_Click_3"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@@ -171,5 +171,23 @@ namespace UP01Task2App.Windows
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void Button_Click_2(object sender, RoutedEventArgs e)
|
||||
{
|
||||
AppointmentWindow wnd = new(TrainersList, new Client { Name = "Лох"}); //Временное добавление клиента
|
||||
bool? res = wnd.ShowDialog();
|
||||
|
||||
if (res == true)
|
||||
{
|
||||
RecordsList.Add(new Record()); //Временная заглушка, добавить результат из Dialog
|
||||
|
||||
Json.SaveRecordDataToJson(RecordsList);
|
||||
}
|
||||
}
|
||||
|
||||
private void Button_Click_3(object sender, RoutedEventArgs e)
|
||||
{
|
||||
//Json.CreateTrainersJson();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user