Виктор Пиктор

master
vikto 2026-05-19 20:48:39 +10:00
parent 42674a1eaf
commit 2832adf6b9
25 changed files with 316 additions and 113 deletions

View File

@ -78,7 +78,6 @@ public class RecordRep:BaseRep
Console.WriteLine($"ExecuteNonQuery returned");
}
// Получаем ID последней вставленной записи
string lastIdSql = "SELECT LAST_INSERT_ID() as last_id";
using (var mc = new MySqlCommand(lastIdSql, connection))
{
@ -117,11 +116,44 @@ public class RecordRep:BaseRep
return -1;
}
public bool UpdateRecord(Record record)
{
string sql = @"update `records`
set client_name = @client_name,
client_surname = @client_surname,
doctor_id = @doctor_id,
service_id = @service_id,
total_amount = @total_amount,
record_date = @record_date
where id = @id";
try
{
using (var mc = new MySqlCommand(sql, connection))
{
mc.Parameters.AddWithValue("@id", record.Id);
mc.Parameters.AddWithValue("@client_name", record.ClientName ?? "");
mc.Parameters.AddWithValue("@client_surname", record.ClientSurname ?? "");
mc.Parameters.AddWithValue("@doctor_id", record.DoctorId);
mc.Parameters.AddWithValue("@service_id", record.ServiceId);
mc.Parameters.AddWithValue("@total_amount", record.TotalAmount);
mc.Parameters.AddWithValue("@record_date", record.RecordDate);
int rows = mc.ExecuteNonQuery();
Console.WriteLine($"Updated {rows} rows");
return rows > 0;
}
}
catch (Exception e)
{
Console.WriteLine($"Error updating record: {e}");
}
return false;
}
public bool Delete(int id)
{
try
{
// Сначала удаляем все связанные record_items
string deleteItemsSql = @"delete from `record_items` where `record_id` = @id";
using (var mc = new MySqlCommand(deleteItemsSql, connection))
{
@ -130,7 +162,6 @@ public class RecordRep:BaseRep
Console.WriteLine($"Deleted record items for record {id}");
}
// Затем удаляем саму запись
string deleteRecordSql = @"delete from `records` where `id` = @id";
using (var mc = new MySqlCommand(deleteRecordSql, connection))
{

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Options;
using MySqlConnector;
@ -82,6 +82,40 @@ public class ServiceRepository : BaseRep
return s;
}
public List<Service> GetServicesByTest()
{
List<Service> result = new List<Service>();
string sql = "select * from services";
try
{
using (var mc = new MySqlCommand(sql, connection))
using (var dr = mc.ExecuteReader())
{
while (dr.Read())
{
result.Add(new Service
{
Id = dr.GetInt32("id"),
DoctorId = dr.GetInt32("doctor_id"),
ServiceName = dr.GetString("service_name"),
Price = dr.GetDecimal("price"),
});
}
}
}
catch (MySqlException ex)
{
Console.WriteLine(ex);
}
catch (Exception e)
{
Console.WriteLine(e);
}
return result;
}
public void Dispose()
{
base.Dispose();

View File

@ -28,7 +28,6 @@ sealed class Program
s.Configure<DatabaseConnection>(c.Configuration.
GetSection("DatabaseConnection"));
//окна
s.AddTransient<AutorizationView>();
s.AddTransient<AutorizationViewModel>();
@ -51,8 +50,7 @@ sealed class Program
s.AddTransient<DoctorViewModel>();
s.AddTransient<RecordItemsView>();
// s.AddTransient<RecordItemsViewModel>();
//Репозитории
s.AddTransient<DoctorRepository>();
s.AddTransient<UserRepository>();

View File

@ -18,6 +18,9 @@ public partial class AdminViewModel : ViewModelBase
private readonly RecordRep _recordRep;
private readonly User _user;
private readonly UserRepository _userRepository;
private readonly DoctorRepository _doctorRepository;
private readonly ServiceRepository _serviceRepository;
[ObservableProperty] string _login;
[ObservableProperty] int _id;
[ObservableProperty] ObservableCollection<Record> _recordsList = new();
@ -25,16 +28,26 @@ public partial class AdminViewModel : ViewModelBase
[ObservableProperty] private ObservableCollection<User> userList = new ObservableCollection<User>();
[ObservableProperty] string statusMessage = "";
public AdminViewModel(Navigation navigation, IServiceProvider provider, RecordRep recordRep,User user,UserRepository userRepository)
{
[ObservableProperty] string editClientName = "";
[ObservableProperty] string editClientSurname = "";
[ObservableProperty] ObservableCollection<Doctor> doctorList = new();
[ObservableProperty] Doctor editSelectedDoctor;
[ObservableProperty] ObservableCollection<Service> editServiceList = new();
[ObservableProperty] Service editSelectedService;
[ObservableProperty] decimal editTotalAmount = 0;
[ObservableProperty] string editRecordDate = "";
public AdminViewModel(Navigation navigation, IServiceProvider provider, RecordRep recordRep, User user, UserRepository userRepository, DoctorRepository doctorRepository, ServiceRepository serviceRepository)
{
_navigation = navigation;
_provider = provider;
_recordRep = recordRep;
_user = user;
_userRepository = userRepository;
_doctorRepository = doctorRepository;
_serviceRepository = serviceRepository;
UserList = new ObservableCollection<User>(userRepository.GetUserId(user.Login,user.Password));
UserList = new ObservableCollection<User>(userRepository.GetUserId(user.Login, user.Password));
foreach (var obj in UserList)
{
@ -42,6 +55,107 @@ public partial class AdminViewModel : ViewModelBase
}
RecordsList = new ObservableCollection<Record>(recordRep.GetRecord(Id));
DoctorList = new ObservableCollection<Doctor>(doctorRepository.GetDoctorsByTest());
}
partial void OnSelectedRecordChanged(Record value)
{
if (value != null)
{
EditClientName = value.ClientName;
EditClientSurname = value.ClientSurname;
EditSelectedDoctor = DoctorList.FirstOrDefault(d => d.Id == value.DoctorId);
EditTotalAmount = value.TotalAmount;
EditRecordDate = value.RecordDate.ToString("yyyy-MM-dd");
}
}
partial void OnEditSelectedDoctorChanged(Doctor value)
{
if (value != null)
{
var services = _serviceRepository.GetServicesByDoctors(value.Id);
EditServiceList = new ObservableCollection<Service>(services);
EditSelectedService = null;
}
else
{
EditServiceList.Clear();
EditSelectedService = null;
}
}
partial void OnEditSelectedServiceChanged(Service value)
{
if (value != null)
{
EditTotalAmount = value.Price;
}
}
[RelayCommand]
void UpdateRecord()
{
if (SelectedRecord == null)
{
StatusMessage = "Выберите запись для обновления";
return;
}
if (string.IsNullOrWhiteSpace(EditClientName) || string.IsNullOrWhiteSpace(EditClientSurname))
{
StatusMessage = "Имя и фамилия клиента обязательны";
return;
}
if (EditSelectedDoctor == null || EditSelectedService == null)
{
StatusMessage = "Выберите врача и услугу";
return;
}
try
{
SelectedRecord.ClientName = EditClientName;
SelectedRecord.ClientSurname = EditClientSurname;
SelectedRecord.DoctorId = EditSelectedDoctor.Id;
SelectedRecord.ServiceId = EditSelectedService.Id;
SelectedRecord.TotalAmount = EditTotalAmount;
if (DateTime.TryParse(EditRecordDate, out DateTime recordDate))
{
SelectedRecord.RecordDate = recordDate;
}
bool updated = _recordRep.UpdateRecord(SelectedRecord);
if (updated)
{
StatusMessage = "Запись успешно обновлена";
RecordsList = new ObservableCollection<Record>(_recordRep.GetRecord(Id));
SelectedRecord = null;
ClearEditFields();
}
else
{
StatusMessage = "Ошибка при обновлении записи";
}
}
catch (Exception ex)
{
StatusMessage = $"Ошибка: {ex.Message}";
Console.WriteLine($"Error updating record: {ex}");
}
}
private void ClearEditFields()
{
EditClientName = "";
EditClientSurname = "";
EditSelectedDoctor = null;
EditServiceList.Clear();
EditSelectedService = null;
EditTotalAmount = 0;
EditRecordDate = "";
}
[RelayCommand]
@ -61,6 +175,8 @@ public partial class AdminViewModel : ViewModelBase
{
StatusMessage = "Запись успешно удалена";
RecordsList = new ObservableCollection<Record>(_recordRep.GetRecord(Id));
SelectedRecord = null;
ClearEditFields();
}
else
{

View File

@ -41,7 +41,6 @@ public partial class AutorizationViewModel : ViewModelBase
return;
}
// Копируем все данные авторизованного пользователя в синглтон
_user.Id = SpUser[0].Id;
_user.Name = SpUser[0].Name;
_user.Surname = SpUser[0].Surname;

View File

@ -41,7 +41,6 @@ public partial class RecordItemsViewModel : ViewModelBase
clientName = name;
clientSurname = surname;
// Расчет общей суммы
totalAmount = selectedServices.Sum(s => s.Price);
}
@ -62,12 +61,10 @@ public partial class RecordItemsViewModel : ViewModelBase
try
{
// Используем первую услугу
int mainServiceId = selectedServices[0].Id;
Console.WriteLine($"Main service ID: {mainServiceId}");
Console.WriteLine($"Selected services count: {selectedServices.Count}");
// Создаем запись с данными КЛИЕНТА
var record = new Record
{
ClientName = clientName,
@ -81,7 +78,6 @@ public partial class RecordItemsViewModel : ViewModelBase
Console.WriteLine($"Saving record: Name={record.ClientName}, Surname={record.ClientSurname}, DoctorId={record.DoctorId}, UserId={record.UserId}, ServiceId={record.ServiceId}");
// Сохраняем запись в БД и получаем ID
int recordId = _recordRepository.InsertRecord(record);
if (recordId <= 0)
@ -93,7 +89,6 @@ public partial class RecordItemsViewModel : ViewModelBase
Console.WriteLine($"Record saved with ID: {recordId}");
// Сохраняем все выбранные услуги в record_items
foreach (var service in selectedServices)
{
Console.WriteLine($"Saving record item for service: {service.Id} (price: {service.Price})");
@ -114,7 +109,6 @@ public partial class RecordItemsViewModel : ViewModelBase
StatusMessage = "Запись успешно сохранена!";
// Переходим в админ-панель
var vm = ActivatorUtilities.CreateInstance<AdminViewModel>(_provider);
_navigation.Navigate(vm);
}

View File

@ -57,11 +57,6 @@ public partial class RegistrationViewModel : ViewModelBase
rep.AddUser(user);
}
// var vm = ActivatorUtilities.CreateInstance<RecordViewModel>(_serviceProvider);
// var win = _serviceProvider.GetRequiredService<Records>();
//win.DataContext = vm;
//win.Show();
//_navigation.Close();
var vm = _serviceProvider.GetRequiredService<AutorizationViewModel>();
_navigation.Navigate(vm);
}

View File

@ -35,7 +35,6 @@ public partial class ServiceViewModel : ViewModelBase
surname = clientSurname;
Services = new ObservableCollection<ServiceSelected>(repository.GetServicesByDoctors(selectedDoctor.Id).Select(service => new ServiceSelected(service)).ToList());
//Console.WriteLine(CurrentUser.login);
}
@ -54,15 +53,11 @@ public partial class ServiceViewModel : ViewModelBase
if (selectedServices.Count == 0)
{
// Можно добавить уведомление об ошибке
return;
}
// Получаем репозитории для передачи в ViewModel
var recordRepository = _provider.GetRequiredService<RecordRep>();
var recordItemsRepository = _provider.GetRequiredService<RecordItemsRepository>();
// Создаем ViewModel для показа подтверждения записи
var vm = ActivatorUtilities.CreateInstance<RecordItemsViewModel>(_provider,
_navigation, _selectedDoctor, selectedServices, recordRepository, recordItemsRepository, Name, Surname);

View File

@ -36,7 +36,6 @@ public partial class SugarCheckViewModel : ViewModelBase
return;
}
// Получаем значения из TextBox'ов
var weightInput = _view.FindControl<TextBox>("WeightInput");
var heightInput = _view.FindControl<TextBox>("HeightInput");
@ -61,7 +60,6 @@ public partial class SugarCheckViewModel : ViewModelBase
try
{
// Расчет BMI (индекс массы тела)
decimal heightInMeters = height / 100;
decimal bmi = weight / (heightInMeters * heightInMeters);

View File

@ -3,16 +3,28 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="clr-namespace:Policlinica.ViewModels"
mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="700"
mc:Ignorable="d" d:DesignWidth="1200" d:DesignHeight="900"
x:Class="Policlinica.Views.AdminView"
x:DataType="viewModels:AdminViewModel">
<UserControl.Styles>
<Style Selector="TextBox">
<Setter Property="Background" Value="White"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="CaretBrush" Value="Red"/>
<Setter Property="SelectionBrush" Value="LightBlue"/>
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="1"/>
</Style>
</UserControl.Styles>
<ScrollViewer>
<StackPanel Margin="30" Spacing="20">
<TextBlock Text="Управление записями" FontSize="24" FontWeight="Bold" HorizontalAlignment="Center"/>
<TextBlock Text="Управление записями" FontSize="24" FontWeight="Bold" HorizontalAlignment="Center" Foreground="Black"/>
<Border BorderBrush="LightGray" BorderThickness="1" Padding="15" CornerRadius="5">
<StackPanel Spacing="10">
<TextBlock Text="Список записей:" FontWeight="Bold" FontSize="16"/>
<TextBlock Text="Список записей (кликните для редактирования):" FontWeight="Bold" FontSize="16" Foreground="Black"/>
<DataGrid ItemsSource="{Binding RecordsList }" SelectedItem="{Binding SelectedRecord }" MinHeight="300">
<DataGrid.Columns>
<DataGridCheckBoxColumn IsVisible="True"/>
@ -27,9 +39,57 @@
</StackPanel>
</Border>
<Border BorderBrush="DodgerBlue" BorderThickness="2" Padding="20" CornerRadius="5" Background="White">
<StackPanel Spacing="20">
<TextBlock Text="Редактирование записи:" FontWeight="Bold" FontSize="16" Foreground="Black"/>
<StackPanel Spacing="8">
<TextBlock Text="Имя клиента:" FontWeight="Bold" Foreground="Black" FontSize="14"/>
<TextBox Text="{Binding EditClientName}" Padding="12" FontSize="14"/>
</StackPanel>
<StackPanel Spacing="8">
<TextBlock Text="Фамилия клиента:" FontWeight="Bold" Foreground="Black" FontSize="14"/>
<TextBox Text="{Binding EditClientSurname}" Padding="12" FontSize="14"/>
</StackPanel>
<StackPanel Spacing="8">
<TextBlock Text="Врач:" FontWeight="Bold" Foreground="Black" FontSize="14"/>
<ComboBox ItemsSource="{Binding DoctorList}"
SelectedItem="{Binding EditSelectedDoctor}"
DisplayMemberBinding="{Binding Title}"
Padding="12" FontSize="14" Background="White" Foreground="Black"/>
</StackPanel>
<StackPanel Spacing="8">
<TextBlock Text="Услуга:" FontWeight="Bold" Foreground="Black" FontSize="14"/>
<ComboBox ItemsSource="{Binding EditServiceList}"
SelectedItem="{Binding EditSelectedService}"
DisplayMemberBinding="{Binding ServiceName}"
Padding="12" FontSize="14" Background="White" Foreground="Black"/>
</StackPanel>
<StackPanel Spacing="8">
<TextBlock Text="Сумма:" FontWeight="Bold" Foreground="Black" FontSize="14"/>
<TextBox Text="{Binding EditTotalAmount}" Padding="12" FontSize="14"/>
</StackPanel>
<StackPanel Spacing="8">
<TextBlock Text="Дата (YYYY-MM-DD):" FontWeight="Bold" Foreground="Black" FontSize="14"/>
<TextBox Text="{Binding EditRecordDate}" Padding="12" FontSize="14"/>
</StackPanel>
</StackPanel>
</Border>
<TextBlock Text="{Binding StatusMessage}" Foreground="Green" FontSize="14" TextWrapping="Wrap"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Spacing="20">
<Button Content="Обновить запись"
FontSize="16"
Padding="18,12"
Background="Blue"
Foreground="White"
Command="{Binding UpdateRecordCommand}"/>
<Button Content="Удалить запись"
FontSize="16"
Padding="18,12"
@ -50,4 +110,5 @@
Command="{Binding GoSugarCheckCommand}"/>
</StackPanel>
</StackPanel>
</ScrollViewer>
</UserControl>

View File

@ -11,7 +11,6 @@
<TextBlock Text="Создание записи" FontSize="24" FontWeight="Bold" HorizontalAlignment="Center"/>
<!-- Ввод имени клиента -->
<Border BorderBrush="LightGray" BorderThickness="1" Padding="15" CornerRadius="5">
<StackPanel Spacing="10">
<TextBlock Text="Имя клиента:" FontWeight="Bold" FontSize="14"/>
@ -19,7 +18,6 @@
</StackPanel>
</Border>
<!-- Ввод фамилии клиента -->
<Border BorderBrush="LightGray" BorderThickness="1" Padding="15" CornerRadius="5">
<StackPanel Spacing="10">
<TextBlock Text="Фамилия клиента:" FontWeight="Bold" FontSize="14"/>
@ -27,7 +25,6 @@
</StackPanel>
</Border>
<!-- Выбор врача -->
<Border BorderBrush="LightGray" BorderThickness="1" Padding="15" CornerRadius="5">
<StackPanel Spacing="10">
<TextBlock Text="Выберите врача:" FontWeight="Bold" FontSize="14"/>
@ -39,7 +36,6 @@
</StackPanel>
</Border>
<!-- Кнопка -->
<Button Content="Далее"
FontSize="16"
Padding="20,12"

View File

@ -8,10 +8,8 @@
x:DataType="viewModels:RecordItemsViewModel">
<StackPanel Margin="30" Spacing="20">
<!-- Заголовок -->
<TextBlock Text="Подтверждение записи" FontSize="24" FontWeight="Bold" HorizontalAlignment="Center"/>
<!-- Информация о клиенте -->
<Border BorderBrush="LightGray" BorderThickness="1" Padding="15" CornerRadius="5">
<StackPanel Spacing="10">
<TextBlock Text="Клиент:" FontWeight="Bold" FontSize="16"/>
@ -20,7 +18,6 @@
</StackPanel>
</Border>
<!-- Информация о враче -->
<Border BorderBrush="LightGray" BorderThickness="1" Padding="15" CornerRadius="5">
<StackPanel Spacing="10">
<TextBlock Text="Врач:" FontWeight="Bold" FontSize="16"/>
@ -28,7 +25,6 @@
</StackPanel>
</Border>
<!-- Выбранные услуги -->
<Border BorderBrush="LightGray" BorderThickness="1" Padding="15" CornerRadius="5">
<StackPanel Spacing="10">
<TextBlock Text="Выбранные услуги:" FontWeight="Bold" FontSize="16"/>
@ -46,7 +42,6 @@
</StackPanel>
</Border>
<!-- Итоговая сумма -->
<Border BorderBrush="DodgerBlue" BorderThickness="2" Padding="20" CornerRadius="5" Background="WhiteSmoke">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="30">
<TextBlock Text="Итого:" FontWeight="Bold" FontSize="16"/>
@ -54,10 +49,8 @@
</StackPanel>
</Border>
<!-- Сообщение статуса -->
<TextBlock Text="{Binding StatusMessage}" Foreground="Green" FontSize="14" TextWrapping="Wrap"/>
<!-- Кнопки -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Spacing="20">
<Button Content="Сохранить запись"
FontSize="16"

View File

@ -8,10 +8,8 @@
x:DataType="viewModels:SugarCheckViewModel">
<StackPanel Margin="30" Spacing="20">
<!-- Заголовок -->
<TextBlock Text="Быстрая проверка нормы сахара в крови" FontSize="22" FontWeight="Bold" HorizontalAlignment="Center"/>
<!-- Ввод веса -->
<Border BorderBrush="LightGray" BorderThickness="1" Padding="15" CornerRadius="5">
<StackPanel Spacing="10">
<TextBlock Text="Вес (кг):" FontWeight="Bold" FontSize="14"/>
@ -19,7 +17,6 @@
</StackPanel>
</Border>
<!-- Ввод роста -->
<Border BorderBrush="LightGray" BorderThickness="1" Padding="15" CornerRadius="5">
<StackPanel Spacing="10">
<TextBlock Text="Рост (см):" FontWeight="Bold" FontSize="14"/>
@ -27,11 +24,9 @@
</StackPanel>
</Border>
<!-- Кнопка расчета -->
<Button Content="Рассчитать" FontSize="16" Padding="20,12" Background="Blue" Foreground="White"
HorizontalAlignment="Center" Command="{Binding CalculateCommand}"/>
<!-- Результат -->
<TextBlock Text="{Binding Result}"
FontSize="15"
TextWrapping="Wrap"
@ -41,10 +36,8 @@
Margin="0,10,0,10"
MinHeight="100"/>
<!-- Сообщение об ошибке -->
<TextBlock Text="{Binding StatusMessage}" Foreground="Red" FontSize="13" TextWrapping="Wrap"/>
<!-- Кнопка вернуться -->
<Button Content="Вернуться в меню" FontSize="16" Padding="20,12" Background="Gray" Foreground="White"
HorizontalAlignment="Center" Command="{Binding BackCommand}"/>
</StackPanel>

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Policlinica")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+feb4764a4fcddaa70e99683af87359573bd8e35b")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+42674a1eafd52a914f3b85957d38411bca2434ad")]
[assembly: System.Reflection.AssemblyProductAttribute("Policlinica")]
[assembly: System.Reflection.AssemblyTitleAttribute("Policlinica")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
10f51693c0826b528319475d8348b6577f4364ecbd4895b9c02338d1ad7de0ca
2b3375ad610e5fbc841535e991e0833d98ba70a8d5acdd80554ef8703e1f2a91

View File

@ -1 +1 @@
{"documents":{"C:\\Users\\vikto\\RiderProjects\\Policlinica\\*":"https://raw.githubusercontent.com/Dezkriminant/Policlinica/db9efc98b91a70b6344005d5ebea1d14bf5ea637/*"}}
{"documents":{"C:\\Users\\vikto\\RiderProjects\\Policlinica\\*":"https://raw.githubusercontent.com/Dezkriminant/Policlinica/42674a1eafd52a914f3b85957d38411bca2434ad/*"}}