123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.IO;
- 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.Navigation;
- using System.Windows.Shapes;
- namespace school
- {
- /// <summary>
- /// Логика взаимодействия для pageEditServiseImage.xaml
- /// </summary>
- public partial class pageEditServiseImage : Page
- {
- Service thisService;
- private void convertImage(byte[] byteArray, System.Windows.Controls.Image img)
- {
- BitmapImage BI = new BitmapImage();
- BI.BeginInit();
- BI.StreamSource = new MemoryStream(byteArray);
- BI.EndInit();
- img.Source = BI;
- img.Stretch = Stretch.Uniform;
- }
- public pageEditServiseImage(int idServise)
- {
- thisService = baseConnect.thisBase.Service.Where(tb => tb.ID == idServise).FirstOrDefault();
- InitializeComponent();
- init();
- }
- private void init()
- {
- List<ServicePhoto> list = baseConnect.thisBase.ServicePhoto.Where(tb => tb.ServiceID == thisService.ID).ToList();//получаем все дополнительные фото
- if (list != null)
- {
- if (list.Count > 0) TBNoPhoto.Visibility = Visibility.Collapsed;
- else TBNoPhoto.Visibility = Visibility.Visible;
- LVImageService.ItemsSource = list;
- }
- }
- private void BtnBackClick(object sender, RoutedEventArgs e)
- {
- dataFrame.mainFrame.Navigate(new pageEditService(thisService.ID));//возвращаемся на страницу редактирования услуги
- }
- private void BtnAddClick(object sender, RoutedEventArgs e)
- {
- try
- {
- OpenFileDialog OFD = new OpenFileDialog();
- OFD.Multiselect = true;
- if (OFD.ShowDialog() == true)
- {
- foreach (string file in OFD.FileNames)
- {
- ServicePhoto photo = new ServicePhoto();
- photo.ServiceID = thisService.ID;
- photo.PhotoPath = File.ReadAllBytes(file);
- baseConnect.thisBase.ServicePhoto.Add(photo);
- }
- }
- baseConnect.thisBase.SaveChanges();
- init();
- MessageBox.Show("Фото успешно загружено", "Успешно", MessageBoxButton.OK, MessageBoxImage.Information);
- }
- catch
- {
- MessageBox.Show("Не удалось загрузить фото", "Ошибка загрузки фото", MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
- private void BtnDeleteClick(object sender, RoutedEventArgs e)
- {
- Button btn = (Button)sender;
- int id = Convert.ToInt32(btn.Uid);
- ServicePhoto photo = baseConnect.thisBase.ServicePhoto.Where(tb => tb.ID == id).FirstOrDefault();
- if (photo != null)
- {
- try
- {
- baseConnect.thisBase.ServicePhoto.Remove(photo);
- baseConnect.thisBase.SaveChanges();
- init();
- }
- catch
- {
- MessageBox.Show("Ошибка удаления фото");
- }
- }
- }
- }
- }
|