//編輯 public PatientViewModel(Agencys agencys, Patients patients) { Agencys = agencys; Patients = patients; PatientNumber = Patients.Patient_Number; PatientName = Patients.Patient_Name; PatientIDNumber = Patients.Patient_IDNumber; GenderM = Patients.Patient_Gender; Birth = Patients.Patient_Birth.Date; if (!string.IsNullOrEmpty(Patients.Patient_Photo)) { PatientsFolder patientsFolder = new PatientsFolder(Agencys, Patients); if (!Directory.Exists(patientsFolder.PatientFullPatientPhotoPath)) { Directory.CreateDirectory(patientsFolder.PatientFullPatientPhotoPath); } PatientPhoto = new LoadBitmapImage().SettingBitmapImage(Agencys.Agency_ImagePath + @"\" + Patients.Patient_Photo, 400); } using (var dde = new DigiDentalEntities()) { var qpc = from pc in dde.PatientCategories select new PatientCategoryInfo() { PatientCategory_ID = pc.PatientCategory_ID, PatientCategory_Title = pc.PatientCategory_Title, IsChecked = pc.Patients.Where(p => p.Patient_ID == patients.Patient_ID).Count() > 0 ? true : false }; PatientCategoryInfo = qpc.ToList().FindAll(pci => pci.IsChecked == true); } }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { BitmapImage bi = new BitmapImage(); bi = new LoadBitmapImage().SettingBitmapImage(ImageInfo.Image_FullPath, 0); Border border = new Border(); if (bi.PixelWidth > bi.PixelHeight) { border.MaxWidth = (cvs.ActualWidth / 5) * 3; border.Width = border.MaxWidth; border.Height = (border.MaxWidth / bi.PixelWidth) * bi.PixelHeight; } else { border.MaxHeight = (cvs.ActualHeight / 5) * 3; border.Height = border.MaxHeight; border.Width = (border.MaxHeight / bi.PixelHeight) * bi.PixelWidth; } oriHeight = border.Height; oriWidth = border.Width; i = new Image(); i.Source = bi; border.Child = i; double imageStartX = (cvs.ActualWidth - border.Width) / 2; double imageStartY = (cvs.ActualHeight - border.Height) / 2; ImageStartPoint = new Point(imageStartX, imageStartY); ImageEndPoint = new Point(imageStartX + border.Width, imageStartY + border.Height); cvs.Children.Add(border); Canvas.SetTop(border, imageStartY); Canvas.SetLeft(border, imageStartX); r = new Rectangle { Stroke = Brushes.White, StrokeThickness = 1, Width = border.Width, Height = border.Height }; cvs.Children.Add(r); Canvas.SetTop(r, imageStartY); Canvas.SetLeft(r, imageStartX); }
private void Image_Drop(object sender, DragEventArgs e) { try { Image img = e.Source as Image; ImageInfo dragImage = new ImageInfo(); dragImage = ((ImageInfo)e.Data.GetData(DataFormats.Text)); LoadBitmapImage lbi = new LoadBitmapImage(); img.Source = lbi.SettingBitmapImage(dragImage.Image_FullPath, TemplateImagePixelWidth); //BEFORE TemplateImage_Number = 0 dbTI.InsertOrUpdateImage(Patients, Templates, TemplateImportDate, dragImage.Image_ID, dragImage.Image_Path, img.Uid); } catch (Exception ex) { Error_Log.ErrorMessageOutput(ex.ToString()); MessageBox.Show("移動圖片發生錯誤,聯絡資訊人員", "提示", MessageBoxButton.OK, MessageBoxImage.Error); } }
public MainWindowViewModel(string hostName, Agencys agencys, Patients patients, DateTime selectedDate) { if (dde == null) { dde = new DigiDentalEntities(); } HostName = hostName; Agencys = agencys; Patients = patients; //設定病患大頭貼 if (!string.IsNullOrEmpty(Patients.Patient_Photo)) { PatientPhoto = new LoadBitmapImage().SettingBitmapImage(Agencys.Agency_ImagePath + @"\" + Patients.Patient_Photo, 400); } PatientCategoryInfo = (from pc in dde.PatientCategories where pc.Patients.Any(p => p.Patient_ID == Patients.Patient_ID) select new PatientCategoryInfo() { PatientCategory_ID = pc.PatientCategory_ID, PatientCategory_Title = pc.PatientCategory_Title, IsChecked = true }).ToList(); //取掛號資訊清單 Registration var queryRegistrations = from qr in dde.Registrations where qr.Patient_ID == Patients.Patient_ID orderby qr.Registration_Date descending select qr; RegistrationsCollection = new ObservableCollection <Registrations>(queryRegistrations.ToList()); SelectedDate = selectedDate; LoadFunctions(); }
public void ShowTemplateImage(Agencys agencys, Patients patients, Templates templates, int templateImagePixelWidth, Grid mainGrid, DateTime templateImportDate) { try { var IsImageExist = (from iie in dde.TemplateImages where iie.Template_ID == templates.Template_ID && iie.Patient_ID == patients.Patient_ID && iie.TemplateImage_ImportDate == templateImportDate.Date select new { TemplateImage_ID = iie.TemplateImage_ID, TemplateImage_Number = iie.TemplateImage_Number, TemplateImage_ImportDate = iie.TemplateImage_ImportDate, Template_ID = iie.Template_ID, Image_ID = iie.Image_ID, Image_Path = agencys.Agency_ImagePath + iie.Image_Path, Patient_ID = iie.Patient_ID }).ToList().Select(s => new TemplateImages { TemplateImage_ID = s.TemplateImage_ID, TemplateImage_Number = s.TemplateImage_Number, TemplateImage_ImportDate = s.TemplateImage_ImportDate, Template_ID = s.Template_ID, Image_ID = s.Image_ID, Image_Path = s.Image_Path, Patient_ID = s.Patient_ID }); if (IsImageExist.Count() > 0) { tICollection = new ObservableCollection <TemplateImages>(IsImageExist); lbi = new LoadBitmapImage(); ProgressDialog pd = new ProgressDialog(); pd.Dispatcher.Invoke(() => { pd.PText = "圖片載入中( 0 / " + tICollection.Count + " )"; pd.PMinimum = 0; pd.PValue = 0; pd.PMaximum = tICollection.Count; pd.Show(); }); //multi - thread Task.Factory.StartNew(() => { foreach (TemplateImages imgs in tICollection) { if (!string.IsNullOrEmpty(imgs.Image_Path) && File.Exists(imgs.Image_Path)) { mainGrid.Dispatcher.Invoke(() => { ((Image)mainGrid.FindName("Image" + imgs.TemplateImage_Number)).Source = lbi.SettingBitmapImage(imgs.Image_Path, templateImagePixelWidth); }); } pd.Dispatcher.Invoke(() => { pd.PValue++; pd.PText = "圖片載入中( " + pd.PValue + " / " + tICollection.Count + " )"; }); } }).ContinueWith(t => { pd.Dispatcher.Invoke(() => { pd.PText = "載入完成"; pd.Close(); }); GC.Collect(); }); } } catch (Exception ex) { Error_Log.ErrorMessageOutput(ex.ToString()); } }
bool isSkip = true; //接ProcessingDialog 回傳值 略過 private void Button_AutoImport_Click(object sender, RoutedEventArgs e) { Button btnAutoImport = (Button)sender; //先載入原本樣板的圖片 //如果略過就塞回原圖 btnAutoImport.Dispatcher.Invoke(() => { bool isEverChanged = false; btnAutoImport.IsEnabled = false; pd = new ProcessingDialog(); Task t = Task.Factory.StartNew(() => { pd.Dispatcher.Invoke(() => { pd.PText = "圖片偵測中"; pd.PIsIndeterminate = true; pd.ButtonContent = "跳過"; pd.ReturnValueCallback += new ProcessingDialog.ReturnValueDelegate(this.SetReturnValueCallbackFun); pd.Show(); }); //病患資料夾路徑 if (pf == null) { pf = new PatientsFolder(Agencys, Patients, Registration_Date); } //資料表Registrations 處理 if (dbr == null) { dbr = new DBRegistrations(); } //資料表Images 處理 if (dbi == null) { dbi = new DBImages(); } //處理載入BitmapImage if (lbi == null) { lbi = new LoadBitmapImage(); } //載入TemplateImages if (dbti == null) { dbti = new DBTemplateImages(); } tICollection = new ObservableCollection <TemplateImages>(); tICollection = dbti.GetTemplateImagesCollection(Agencys, Patients, TemplateItem, tfvm.TemplateImportDate); //default Image[i] in UserControl Templates int Imagei = 0; int ImageCount = (int)TemplateItem.Template_ImageCount; int DecodePixelWidth = (int)TemplateItem.Template_DecodePixelWidth; while (Imagei < ImageCount) { pd.PText = "圖片 " + (Imagei + 1) + " 偵測中"; //目前處理的Image[i] Image iTarget; TemplateContent.Dispatcher.Invoke(() => { iTarget = new Image(); iTarget = (Image)TemplateContent.FindName("Image" + Imagei); iTarget.Source = new BitmapImage(new Uri(@"/DigiDental;component/Resource/yes.png", UriKind.RelativeOrAbsolute)); //iTarget.Source = lbi.SettingBitmapImage(@"/DigiDental;component/Resource/yes.png", DecodePixelWidth); }); //set the paramater default bool isChanged = false; bool detecting = true; while (true) { //開始偵測wifi card路徑 foreach (string f in Directory.GetFiles(Agencys.Agency_WifiCardPath)) { Thread.Sleep(500); string extension = Path.GetExtension(f).ToUpper(); string newFileName = DateTime.Now.ToString("yyyyMMddHHmmssffff"); if (!Directory.Exists(pf.PatientFullFolderPathOriginal)) { Directory.CreateDirectory(pf.PatientFullFolderPathOriginal); } //System.Drawing.RotateFlipType rft = ImageHelper.RotateImageByExifOrientationData(f, pf.PatientFullFolderPathOriginal + @"\" + newFileName + @"ori" + extension, GetImageFormat(extension), true); ////複製原圖到目的Original //File.Copy(f, pf.PatientFullFolderPathOriginal + @"\" + newFileName + @"ori" + extension); // Rotate the image according to EXIF data var bmp = new System.Drawing.Bitmap(f); System.Drawing.RotateFlipType fType = ImageHelper.RotateImageByExifOrientationData(bmp, true); if (fType != System.Drawing.RotateFlipType.RotateNoneFlipNone) { bmp.Save(pf.PatientFullFolderPathOriginal + @"\" + newFileName + @"ori" + extension, GetImageFormat(extension)); } else { File.Copy(f, pf.PatientFullFolderPathOriginal + @"\" + newFileName + @"ori" + extension); } Registration_ID = dbr.CreateRegistrationsAndGetID(Patients, Registration_Date); string imagePath = @"\" + pf.PatientFolderPathOriginal + @"\" + newFileName + @"ori" + extension; string imageFileName = newFileName + @"ori" + extension; string imageSize = "Original"; string imageExtension = extension; //寫資料庫 //INSERT Images int imageID = dbi.InsertImage(imagePath, imageFileName, imageSize, imageExtension, Registration_ID); isEverChanged = true; TemplateContent.Dispatcher.Invoke(() => { iTarget = new Image(); iTarget = (Image)TemplateContent.FindName("Image" + Imagei); //INSERT TemplateImages dbti.InsertOrUpdateImage(Patients, TemplateItem, tfvm.TemplateImportDate, imageID, imagePath, iTarget.Uid); iTarget.Source = lbi.SettingBitmapImage(pf.PatientFullFolderPathOriginal + @"\" + newFileName + @"ori" + extension, DecodePixelWidth); isChanged = true; }); File.Delete(f); detecting = false; } //ProcessingDialog STOP if (isStop) { isStop = false; TemplateContent.Dispatcher.Invoke(() => { iTarget = new Image(); iTarget = (Image)TemplateContent.FindName("Image" + Imagei); var findOriImage = from tc in tICollection where tc.TemplateImage_Number == Imagei.ToString() select tc; if (findOriImage.Count() > 0) { iTarget.Source = lbi.SettingBitmapImage(findOriImage.First().Image_Path, DecodePixelWidth); } else { iTarget.Source = new BitmapImage(new Uri(@"/DigiDental;component/Resource/no.png", UriKind.RelativeOrAbsolute)); //iTarget.Source = lbi.SettingBitmapImage(@"/DigiDental;component/Resource/key.ico", DecodePixelWidth); } }); return; } else { // import pic OR skip import (NEXT) if (!detecting || !isSkip) { if (!isChanged) { TemplateContent.Dispatcher.Invoke(() => { iTarget = new Image(); iTarget = (Image)TemplateContent.FindName("Image" + Imagei); var findOriImage = from tc in tICollection where tc.TemplateImage_Number == Imagei.ToString() select tc; if (findOriImage.Count() > 0) { iTarget.Source = lbi.SettingBitmapImage(findOriImage.First().Image_Path, DecodePixelWidth); } else { iTarget.Source = new BitmapImage(new Uri(@"/DigiDental;component/Resource/no.png", UriKind.RelativeOrAbsolute)); //iTarget.Source = lbi.SettingBitmapImage(@"/DigiDental;component/Resource/key.ico", DecodePixelWidth); } }); } Imagei++; isSkip = true; break; } } } } }).ContinueWith(cw => { //結束 pd.PText = "處理完畢"; pd.Close(); //委派回傳MainWindow //刷新Registrations 資料 //刷新Images 資料 if (isEverChanged) { ReturnValueCallback(Registration_ID, Registration_Date); } GC.Collect(); btnAutoImport.IsEnabled = true; }, TaskScheduler.FromCurrentSynchronizationContext()); }); }