//編輯 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 Image_Drop(object sender, DragEventArgs e) { try { Image img = e.Source as Image; ImageInfo dragImage = new ImageInfo(); dragImage = ((ImageInfo)e.Data.GetData(DataFormats.Text)); pf = new PatientsFolder(Agencys, Patients); if (!Directory.Exists(pf.PatientFullPatientPhotoPath)) { Directory.CreateDirectory(pf.PatientFullPatientPhotoPath); } string newPatientPhotoName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + dragImage.Image_Extension; string newPatientPhotoPath = pf.PatientFullPatientPhotoPath + @"\" + newPatientPhotoName; File.Copy(dragImage.Image_FullPath, newPatientPhotoPath); Thread.Sleep(200); mwvm.PatientPhoto = new LoadBitmapImage().SettingBitmapImage(newPatientPhotoPath, 400); //update database Patients Patient_Photo Patients patients = (from q in dde.Patients where q.Patient_ID == Patients.Patient_ID select q).First(); patients.Patient_Photo = pf.PatientPhotoPath + @"\" + newPatientPhotoName; patients.UpdateDate = DateTime.Now; dde.SaveChanges(); Patients = patients; mwvm.Patients = patients; } catch (Exception ex) { Error_Log.ErrorMessageOutput(ex.ToString()); MessageBox.Show("移動圖片發生錯誤,聯絡資訊人員", "提示", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void Button_Save_Click(object sender, RoutedEventArgs e) { try { if (Patients != null)//編輯 { if (MessageBox.Show("確定修改病患資料<" + pvm.PatientNumber + ">?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { using (var dde = new DigiDentalEntities()) { DateTime updateTime = DateTime.Now; Patients patients = (from p in dde.Patients where p.Patient_ID == Patients.Patient_ID select p).First(); patients.Patient_Number = pvm.PatientNumber; patients.Patient_Name = pvm.PatientName; patients.Patient_IDNumber = pvm.PatientIDNumber; patients.Patient_Birth = pvm.Birth; patients.Patient_Gender = pvm.GenderM; patients.UpdateDate = updateTime; if (IsRemove) { patients.Patient_Photo = null; } else { if (!string.IsNullOrEmpty(ImportPatientPhotoPath)) { PatientsFolder pf = new PatientsFolder(Agencys, patients); if (!Directory.Exists(pf.PatientFullPatientPhotoPath)) { Directory.CreateDirectory(pf.PatientFullPatientPhotoPath); } string extension = Path.GetExtension(ImportPatientPhotoPath).ToUpper(); string newFileName = DateTime.Now.ToString("yyyyMMddHHmmssffff"); File.Copy(ImportPatientPhotoPath, pf.PatientFullPatientPhotoPath + @"\" + newFileName + extension); patients.Patient_Photo = pf.PatientPhotoPath + @"\" + newFileName + extension; } } //寫入分類 List <PatientCategories> PatientCategories = dde.PatientCategories.ToList(); List <PatientCategoryInfo> PatientCategoryInfo = pvm.PatientCategoryInfo.FindAll(pci => pci.IsChecked == true); foreach (PatientCategories pc in PatientCategories) { var queryCheck = PatientCategoryInfo.FindAll(pci => pci.PatientCategory_ID == pc.PatientCategory_ID); if (queryCheck.Count() > 0) { patients.PatientCategories.Remove(pc); patients.PatientCategories.Add(pc); } else { patients.PatientCategories.Remove(pc); } } dde.SaveChanges(); MessageBox.Show("修改完成", "提示", MessageBoxButton.OK, MessageBoxImage.Information); DialogResult = true; Close(); } } } else//新增 { if (MessageBox.Show("確定新增病患<" + pvm.PatientNumber + ">?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { using (var dde = new DigiDentalEntities()) { string newPatientID = GetPatientID(); DateTime newPatientDate = DateTime.Now; //新增病患 Patients patients = new Patients() { Patient_ID = newPatientID, Patient_Number = pvm.PatientNumber, Patient_Name = pvm.PatientName, Patient_IDNumber = pvm.PatientIDNumber, Patient_Birth = pvm.Birth, Patient_Gender = pvm.GenderM, CreateDate = newPatientDate, UpdateDate = newPatientDate }; if (!string.IsNullOrEmpty(ImportPatientPhotoPath)) { PatientsFolder pf = new PatientsFolder(Agencys, patients); if (!Directory.Exists(pf.PatientFullPatientPhotoPath)) { Directory.CreateDirectory(pf.PatientFullPatientPhotoPath); } string extension = Path.GetExtension(ImportPatientPhotoPath).ToUpper(); string newFileName = DateTime.Now.ToString("yyyyMMddHHmmssffff"); File.Copy(ImportPatientPhotoPath, pf.PatientFullPatientPhotoPath + @"\" + newFileName + extension); patients.Patient_Photo = pf.PatientPhotoPath + @"\" + newFileName + extension; } //寫入分類 if (pvm.PatientCategoryInfo != null) { List <PatientCategoryInfo> PatientCategoryInfo = pvm.PatientCategoryInfo.FindAll(pcs => pcs.IsChecked == true); foreach (PatientCategoryInfo pci in PatientCategoryInfo) { PatientCategories patientCategories = (from pc in dde.PatientCategories where pc.PatientCategory_ID == pci.PatientCategory_ID select pc).First(); patients.PatientCategories.Add(patientCategories); } } dde.Patients.Add(patients); dde.SaveChanges(); MessageBox.Show("新增完成", "提示", MessageBoxButton.OK, MessageBoxImage.Information); Close(); } } } } catch (Exception ex) { Error_Log.ErrorMessageOutput(ex.ToString()); } }
bool isStop = false; //接ProcessingDialog 回傳值 停止 private void ToggleButton_WifiImport_Click(object sender, RoutedEventArgs e) { ToggleButton toggleButton = (ToggleButton)sender; if (toggleButton.IsChecked == true) { if (!string.IsNullOrEmpty(Agencys.Agency_WifiCardPath)) { if (Directory.Exists(Agencys.Agency_WifiCardPath)) { //讀寫Registrations //確認掛號資料 DateTime RegistrationDate = mwvm.SelectedDate; int Registration_ID = dbr.CreateRegistrationsAndGetID(Patients, RegistrationDate); processingDialog = new ProcessingDialog(); Task task = Task.Factory.StartNew(() => { processingDialog.Dispatcher.Invoke(() => { processingDialog.PText = "圖片偵測中"; processingDialog.PIsIndeterminate = true; processingDialog.ButtonContentVisibility = Visibility.Hidden; processingDialog.ReturnValueCallback += new ProcessingDialog.ReturnValueDelegate(this.SetReturnValueCallbackFun); processingDialog.Show(); }); int imageCount = 0; while (true) { //偵測資料夾 foreach (string f in Directory.GetFiles(Agencys.Agency_WifiCardPath)) { Thread.Sleep(500); pf = new PatientsFolder(Agencys, Patients, RegistrationDate); if (!Directory.Exists(pf.PatientFullFolderPath)) { Directory.CreateDirectory(pf.PatientFullFolderPathOriginal); } string extension = Path.GetExtension(f).ToUpper(); string newFileName = DateTime.Now.ToString("yyyyMMddHHmmssffff"); //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); } string imagePath = @"\" + pf.PatientFolderPathOriginal + @"\" + newFileName + @"ori" + extension; string imageFileName = newFileName + @"ori" + extension; string imageSize = "Original"; string imageExtension = extension; //寫資料庫 ImageInfo importImage = dbi.InsertImageReturnImageInfo(imagePath, imageFileName, imageSize, imageExtension, Registration_ID, RegistrationDate, Agencys.Agency_ImagePath, 800); File.Delete(f); //加入showImage清單 mwvm.ShowImages.Add(importImage); //已匯入 imageCount++; processingDialog.Dispatcher.Invoke(() => { processingDialog.PText = "圖片匯入中,已匯入" + imageCount + "張"; }); } //按停止 if (isStop) { isStop = false; return; } } }).ContinueWith(cw => { //結束 processingDialog.PText = "處理完畢"; processingDialog.Close(); toggleButton.IsChecked = false; ReloadRegistration(Registration_ID, RegistrationDate); GC.Collect(); }, TaskScheduler.FromCurrentSynchronizationContext()); } else { MessageBox.Show("Wifi Card實體資料夾位置尚未建立", "提示", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("尚未設置Wifi Card資料夾位置", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); } } }
private void Button_Import_Click(object sender, RoutedEventArgs e) { Button btnImport = (Button)sender; btnImport.IsEnabled = false; btnImport.Refresh(); OpenFileDialog ofd = new OpenFileDialog() { Multiselect = true, DefaultExt = ".png", Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif" }; bool?ofdResult = ofd.ShowDialog(); if (ofdResult.HasValue && ofdResult.Value)//OpenFileDialog 選確定 { if (Directory.Exists(Agencys.Agency_ImagePath)) { //讀寫Registrations //確認掛號資料 DateTime RegistrationDate = mwvm.SelectedDate; int Registration_ID = dbr.CreateRegistrationsAndGetID(Patients, RegistrationDate); pf = new PatientsFolder(Agencys, Patients, RegistrationDate); #region 小圖路徑(未使用) ////..\病患資料夾\掛號日期\Small //string PatientFolderPathSmall = pf.PatientFolderPathSmall; ////Agencys_ImagePath\病患資料夾\掛號日期\Small //string PatientFullFolderPathSmall = pf.PatientFullFolderPathSmall; #endregion if (!Directory.Exists(pf.PatientFullFolderPathOriginal)) { Directory.CreateDirectory(pf.PatientFullFolderPathOriginal); //Directory.CreateDirectory(PatientFullFolderPathSmall); } pd = new ProgressDialog(); pd.Dispatcher.Invoke(() => { pd.PMinimum = 0; pd.PValue = 0; pd.PMaximum = ofd.FileNames.Count(); pd.PText = "圖片匯入中,請稍後( 0" + " / " + pd.PMaximum + " )"; pd.Show(); }); Task t = Task.Factory.StartNew(() => { foreach (string fileName in ofd.FileNames) { string extension = Path.GetExtension(fileName).ToUpper(); string newFileName = DateTime.Now.ToString("yyyyMMddHHmmssffff"); //System.Drawing.RotateFlipType rft = ImageHelper.RotateImageByExifOrientationData(fileName, pf.PatientFullFolderPathOriginal + @"\" + newFileName + @"ori" + extension, GetImageFormat(extension), true); ////複製原圖到目的Original //File.Copy(fileName, pf.PatientFullFolderPathOriginal + @"\" + newFileName + @"ori" + extension); // Rotate the image according to EXIF data var bmp = new System.Drawing.Bitmap(fileName); 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(fileName, pf.PatientFullFolderPathOriginal + @"\" + newFileName + @"ori" + extension); } string imagePath = @"\" + pf.PatientFolderPathOriginal + @"\" + newFileName + @"ori" + extension; string imageFileName = newFileName + @"ori" + extension; string imageSize = "Original"; string imageExtension = extension; //寫資料庫 ImageInfo importImage = dbi.InsertImageReturnImageInfo(imagePath, imageFileName, imageSize, imageExtension, Registration_ID, RegistrationDate, Agencys.Agency_ImagePath, 800); //加入showImage清單 mwvm.ShowImages.Add(importImage); #region 產生小圖(未使用) //產生縮圖到Small //ImageProcess.SaveThumbPic(fileName, 300, PatientFullFolderPathSmall + @"\" + newFileName + @"sml" + extension); //寫資料庫 //dde.Images.Add(new Images //{ // Image_Path = @"\" + PatientFolderPathSmall + @"\" + newFileName + @"sml" + extension, // Image_FileName = newFileName + @"sml" + extension, // Image_Size = "Small", // Image_Extension = extension, // Registration_ID = Registration_ID //}); //dde.SaveChanges(); #endregion pd.Dispatcher.Invoke(() => { pd.PValue++; pd.PText = "圖片匯入中,請稍後( " + pd.PValue + " / " + pd.PMaximum + " )"; }); Thread.Sleep(200); } }).ContinueWith(cw => { pd.Dispatcher.Invoke(() => { pd.PText = "匯入完成"; pd.Close(); }); ReloadRegistration(Registration_ID, RegistrationDate); GC.Collect(); }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); } else { MessageBox.Show("影像資料夾有問題,請檢查設定是否有誤", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); } } btnImport.IsEnabled = true; btnImport.Refresh(); }
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()); }); }