123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- using Microsoft.Win32;
- using System;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using System.Windows.Media.Imaging;
- namespace Hotel_Course_Project
- {
- /// <summary>
- /// Логика взаимодействия для ClientChangeOrAddPage.xaml
- /// </summary>
- public partial class ClientChangeOrAddPage : Page
- {
- public Client _client;
- public int idClient;
- public byte[] PassportImage;
- public string FilePath;
- public ClientChangeOrAddPage(Client client)
- {
- InitializeComponent();
- DataContext = client;
- _client = client;
- if (DataContext != null)
- {
- ClientChangeOrAddBtn.Content = "Изменить данные";
- this.Title = "Информация о клиенте";
- idClient = client.Id;
- ClientDeleteOrRestoreBtn.Visibility = Visibility.Visible;
- if (client.Id_PersStatus == 1)
- {
- ClientDeleteOrRestoreBtn.Content = "Удалить клиента";
- }
- else
- {
- ClientDeleteOrRestoreBtn.Content = "Востановить клиента";
- }
- }
- else
- {
- ClientChangeOrAddBtn.Content = "Добавить клиента";
- this.Title = "Окно добавления клиента";
- ClientDeleteOrRestoreBtn.Visibility = Visibility.Collapsed;
- }
- if (client == null || client.Passport == null)
- {
- CPassportPhoto.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/PersDefaultPhoto.png"));
- }
- }
- private void ClientChangeOrAddBtn_Click(object sender, RoutedEventArgs e)
- {
- if (DataContext == null)
- {
- }
- if (CLName.Text == null || CFName.Text == null)
- {
- MessageBox.Show("Ключевые поля не были заполнены!");
- return;
- }
- else if (CPassportPhoto == null)
- {
- MessageBox.Show("Фотография паспорта не была загружена!");
- return;
- }
- else
- {
- if (DataContext == null)
- {
- Client client = new Client()
- {
- LName = CLName.Text,
- FName = CFName.Text,
- MName = CMName.Text,
- Passport = PassportImage,
- Id_PersStatus = 1
- };
- DataBase.db.Client.Add(client);
- var lastId = DataBase.db.Client.OrderByDescending(item => item.Id).FirstOrDefault().Id;
- DataBase.db.SaveChanges();
- MessageBox.Show("Клиент добавлен в базу.");
- }
- else
- {
- MessageBox.Show("Данные по клиенту изменены.");
- _client.Passport = PassportImage;
- DataBase.db.SaveChanges();
- }
- PChanger.MainFrame.GoBack();
- }
- }
- private void ClientDeleteOrRestoreBtn_Click(object sender, RoutedEventArgs e)
- {
- if (_client.Id_PersStatus == 1)
- {
- _client.Id_PersStatus = 2;
- MessageBox.Show("Статус пользователя изменился на <удалён>");
- }
- else
- {
- _client.Id_PersStatus = 1;
- MessageBox.Show("Статус пользователя восстановлен");
- }
- DataBase.db.SaveChanges();
- PChanger.MainFrame.GoBack();
- }
- private void CPassportPhoto_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- OpenFileDialog openFileDialog = new OpenFileDialog();
- if (openFileDialog.ShowDialog() == true)
- {
- FilePath = openFileDialog.FileName;
- string uriString = $"{FilePath}";
- BitmapImage bitimage = new BitmapImage(new Uri(@uriString));
- CPassportPhoto.Source = bitimage;
- PassportImage = SomeMethods.ConvertBitmapImageToByte(bitimage);
- }
- else
- {
- FilePath = string.Empty;
- }
- }
- }
- }
|