Дипломная работа: Автоматизация учета пациентов на примере ООО «АРХИДЕНТ»

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам
132
Padding="5"/>
<Button Content="Сохранить" Grid.Column="1" Margin="5 5 15 5"
Padding="5" Click="ButtonSave_Click"/>
</Grid>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
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 Reception
{
/// <summary>
/// Логикавзаимодействиядля PatientCard.xaml
/// </summary>
133
public partial class PatientCard : Window
{
SqlConnection connection;
SqlCommand command;
SqlDataReader reader;
string sqlExpression;
Patient patient;
bool newobject;
public PatientCard(Patient patient, SqlConnection connection, bool
newobject = false)
{
InitializeComponent();
this.newobject = newobject;
this.patient = patient;
this.connection = connection;
if (newobject) { patient.registration_date = DateTime.Now; }
this.DataContext = this.patient;
if (!newobject)
{
//загрузкарасписаниядляконкретногопацента
sqlExpression = "SELECT [Reception].[Id_Reception],
[Reception].[doctor], [Doctor].[nameDoctor], [Doctor].[surname],
[Doctor].[patronymic], [Reception].[patient], [Patient].[namePatient],
[Patient].[surname], [Patient].[patronymic], [Reception].[procedure],
[Procedure].[nameProcedure], [Reception].[begin_reception], [Reception].[status],
134
[Reception].[price] FROM (([Reception] LEFT JOIN [Doctor] ON
[Reception].[doctor] = [Doctor].[Id_doc]) LEFT JOIN [Patient] ON
[Reception].[patient] = [Patient].[Id_patient]) LEFT JOIN [Procedure] ON
[Reception].[procedure] = [Procedure].[Id_Procedure] WHERE
[Reception].[patient] = " + patient.Id;
command = new SqlCommand(sqlExpression, connection);
reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
Reception_ temp = new Reception_();
temp.Id = reader.GetInt32(0);
temp.doctor_id = reader.GetInt32(1);
temp.nameDoctor = reader.GetString(2);
temp.surnameDoctor = reader.GetString(3);
temp.patronymicDoctor = reader.GetString(4);
temp.patient_id = reader.GetInt32(5);
temp.namePatient = reader.GetString(6);
temp.surnamePatient = reader.GetString(7);
temp.patronymicPatient = reader.GetString(8);
temp.procedure = reader.GetInt32(9);
temp.nameProcedure = reader.GetString(10);
temp.begin_reception = reader.GetDateTime(11);
temp.status = reader.GetBoolean(12);
temp.price = reader.GetInt32(13);
135
ReceptionDataGrid.Items.Add(temp);
}
}
}
}
//save
private void ButtonSave_Click(object sender, RoutedEventArgs e)
{
try
{
if (patient.namePatient.Length <= 1) { new Exception("введитеимя"); }
if (patient.surname.Length == 0) { new Exception("введитефамилию"); }
if (patient.patronymic.Length == 0) { new Exception("введитефамилию");
}
if (patient.age < 18 || patient.age >= 100) { new
Exception("введитевозраст"); }
if (patient.passport == "") { new Exception("введитепасспорт"); }
if (patient.phone.Length != 11) { new
Exception("введитеномертелефона"); }
//запросвбд
if (newobject)
{
patient.registration_date = DateTime.Now;
//добавлениеновогопациентавбазу
136
sqlExpression = string.Format("INSERT INTO [Patient]
([namePatient], [surname], [age], [passport], [phone], [registration_date],
[patronymic]) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}');",
patient.namePatient, patient.surname, patient.age, patient.passport, patient.phone,
patient.registration_date, patient.patronymic);
command = new SqlCommand(sqlExpression, connection);
if (command.ExecuteNonQuery() == 1)
MessageBox.Show("Операциядобавлениявыполненауспешно.", "info",
MessageBoxButton.OK, MessageBoxImage.Information);
else
MessageBox.Show("Произошлаошибканасторонебазыданных.", "Error",
MessageBoxButton.OK, MessageBoxImage.Error);
}
else
{
//Сохранение измененной информации о пациенте
sqlExpression = string.Format("UPDATE [Patient] SET
[Patient].[namePatient] = '{1}', [Patient].[surname] = '{2}', [Patient].[age] = '{3}',
[Patient].[passport] = '{4}', [Patient].[phone] = '{5}', [Patient].[patronymic] = '{6}'
WHERE [Patient].[Id_patient] = {0}", patient.Id, patient.namePatient,
patient.surname, patient.age, patient.passport, patient.phone, patient.patronymic);
command = new SqlCommand(sqlExpression, connection);
if (command.ExecuteNonQuery() == 1)
MessageBox.Show("Операциясохранениявыполненауспешно.", "info",
MessageBoxButton.OK, MessageBoxImage.Information);
else
MessageBox.Show("Произошлаошибканасторонебазыданных.", "Error",
MessageBoxButton.OK, MessageBoxImage.Error);
}
}
Источник: https://baza.diplomsite.ru/previewfile/286