Beispiel #1
0
        public ImageWindow()
        {
            InitializeComponent();

            Data = new ExaminationData();

            DataContext = Data;

            SetHandlers();
        }
Beispiel #2
0
        public ImageWindow(int id)
        {
            InitializeComponent();

            Data = unitOfWork.ExaminationDatas.Get(id);

            DataContext = Data;

            SetHandlers();
        }
Beispiel #3
0
        public void SetHandlers()
        {
            DataBox.SelectionChanged += (object sender, SelectionChangedEventArgs args) =>
            {
                var data = DataBox.SelectedItem as ExaminationData;
                if (data != null)
                {
                    ImageWindow imageWindow = new ImageWindow(data.Id);
                    imageWindow.Owner = this;
                    imageWindow.Show();
                }
                DataBox.SelectedIndex = -1;
            };

            DeleteButton.Click += (object sender, RoutedEventArgs e) =>
            {
                string message = "Ви впевнені що хочете видалити "
                                 + Examination.ExaminationType.TypeName + " "
                                 + Examination.Diagnosis
                                 + " " + Examination.ExaminationDate.ToString("dd.MM.yyyy") + " ?";

                DialogWindow dialogWindow = new DialogWindow(message);
                bool?        dialogResult = dialogWindow.ShowDialog();

                if (dialogResult != true)
                {
                    return;
                }

                Examination.DeletedDate = DateTime.Now;
                unitOfWork.Examinations.Update(Examination);
                unitOfWork.Save();

                foreach (var data in Examination.ExaminationDatas)
                {
                    data.DeletedDate = DateTime.Now;
                    unitOfWork.ExaminationDatas.Update(data);
                }

                unitOfWork.Save();

                Close();
            };

            EditButton.Click += (object sender, RoutedEventArgs e) =>
            {
                ExaminationWindow examinationWindow = new ExaminationWindow(Examination, ActionType.Edit);
                examinationWindow.ShowDialog();

                SetContent();
            };

            CreateButton.Click += (object sender, RoutedEventArgs e) =>
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter      = "Image files (*.png;*.jpeg;*.jpg)|*.png;*.jpeg;*.jpg|All files (*.*)|*.*";
                openFileDialog.Multiselect = false;
                if (openFileDialog.ShowDialog() == true)
                {
                    string fileExt =
                        System.IO.Path.GetExtension(openFileDialog.FileName);

                    if (fileExt == ".jpeg" || fileExt == ".jpg" || fileExt == ".png")
                    {
                        ExaminationData data = new ExaminationData();
                        data.ExaminationId = Examination.Id;
                        data.Examination   = Examination;
                        data.Data          = File.ReadAllBytes(openFileDialog.FileName);
                        unitOfWork.ExaminationDatas.Create(data);
                    }
                    else
                    {
                        MessageBox.Show("Ви вибрали файл з непідртимуваним розширенням" +
                                        ", будь-ласка виберіть зображення"
                                        , "Неправильний файл", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    }

                    SetContent();
                }
            };
        }
Beispiel #4
0
        private void ExaminationInit(DataContext db)
        {
            Random rand = new Random();

            byte[]            bytes     = File.ReadAllBytes("../../Images/forest.jpg");
            PngToJpgConverter converter = new PngToJpgConverter();
            var some    = converter.ConvertImage(bytes);
            var stream1 = new MemoryStream(bytes);
            JpegBitmapDecoder decoder = new JpegBitmapDecoder(stream1, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
            BitmapFrame       frame   = decoder.Frames[0];
            JpegBitmapEncoder encoder = new JpegBitmapEncoder();

            encoder.QualityLevel = 60;
            encoder.Frames.Add(frame);
            byte[] newBytes;
            using (var stream = new MemoryStream())
            {
                encoder.Save(stream);
                newBytes = stream.GetBuffer();
            }

            byte[]            bytes2   = File.ReadAllBytes("../../Images/mountain.jpg");
            var               stream2  = new MemoryStream(bytes2);
            var               some2    = converter.ConvertImage(bytes2);
            JpegBitmapDecoder decoder2 = new JpegBitmapDecoder(stream2, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
            BitmapFrame       frame2   = decoder2.Frames[0];
            JpegBitmapEncoder encoder2 = new JpegBitmapEncoder();

            encoder2.QualityLevel = 60;
            encoder2.Frames.Add(frame2);
            byte[] newBytes2;
            using (var stream = new MemoryStream())
            {
                encoder2.Save(stream);
                newBytes2 = stream.GetBuffer();
            }

            var list = db.Patients.ToList();

            foreach (var patient in list)
            {
                if (rand.Next(0, 2) == 0)
                {
                    continue;
                }
                for (int i = 0; i < 1; i++)
                {
                    ExaminationType type = db.ExaminationTypes.ToList()
                                           [rand.Next(0, db.ExaminationTypes.ToList().Count)];

                    Examination examination = new Examination
                    {
                        Diagnosis         = "Some Diagnosis",
                        PatientId         = patient.Id,
                        ExaminationTypeId = type.Id,
                        ExaminationDate   = DateTime.Now,
                        Descripton        = "Some Descripton"
                    };

                    Examination examination2 = new Examination
                    {
                        Diagnosis         = "Some Diagnosis2",
                        PatientId         = patient.Id,
                        ExaminationTypeId = type.Id,
                        ExaminationDate   = DateTime.Now,
                        Descripton        = "Some Descripton2"
                    };

                    db.Examinations.Add(examination);
                    db.Examinations.Add(examination2);
                    db.SaveChanges();

                    ExaminationData data = new ExaminationData
                    {
                        ExaminationId = examination.Id,
                        Data          = newBytes
                    };

                    ExaminationData data2 = new ExaminationData
                    {
                        ExaminationId = examination.Id,
                        Data          = newBytes2
                    };

                    db.ExaminationDatas.Add(data);
                    db.ExaminationDatas.Add(data2);
                    db.SaveChanges();
                }
            }
        }