Ejemplo n.º 1
0
        /// <summary>
        /// 新增或更新Templates_Images
        /// </summary>
        /// <param name="patients"></param>
        /// <param name="templates"></param>
        /// <param name="templateImportDate"></param>
        /// <param name="imageID"></param>
        /// <param name="imagePath"></param>
        /// <param name="tiNumber"></param>
        public string InsertOrUpdateTemplatesImages(Patients patients, Templates templates, DateTime templateImportDate, int imageID, string imagePath, string tiNumber)
        {
            using (var ide = new iDentalEntities())
            {
                Templates_Images templates_Images = new Templates_Images();
                var IsImageExist = from iie in ide.Templates_Images
                                   where iie.Template_ID == templates.Template_ID &&
                                   iie.Template_Image_Number == tiNumber &&
                                   iie.Template_Image_ImportDate == templateImportDate.Date &&
                                   iie.Patient_ID == patients.Patient_ID
                                   select iie;
                if (IsImageExist.Count() > 0)
                {
                    templates_Images            = IsImageExist.First();
                    templates_Images.Image_ID   = imageID;
                    templates_Images.Image_Path = imagePath;
                    ide.SaveChanges();
                }
                else
                {
                    templates_Images.Template_Image_Number     = tiNumber;
                    templates_Images.Template_ID               = templates.Template_ID;
                    templates_Images.Template_Image_ImportDate = templateImportDate.Date;
                    templates_Images.Image_ID   = imageID;
                    templates_Images.Image_Path = imagePath;
                    templates_Images.Patient_ID = patients.Patient_ID;

                    ide.Templates_Images.Add(templates_Images);
                    ide.SaveChanges();
                }
                return(templates_Images.Template_Image_ID.ToString());
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 寫入資訊者資訊
 /// </summary>
 /// <param name="clients">Clients</param>
 public void InsertClient(Clients clients)
 {
     using (var ide = new iDentalEntities())
     {
         ide.Clients.Add(clients);
         ide.SaveChanges();
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 寫入連線資訊
 /// </summary>
 /// <param name="connectingLogs">ConnectingLogs</param>
 public void InsertConnectingLog(ConnectingLogs connectingLogs)
 {
     using (var ide = new iDentalEntities())
     {
         ide.ConnectingLogs.Add(connectingLogs);
         ide.SaveChanges();
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="patientCategorys"></param>
 public void InsertPatientCategorys(PatientCategorys patientCategorys)
 {
     using (var ide = new iDentalEntities())
     {
         ide.PatientCategorys.Add(patientCategorys);
         ide.SaveChanges();
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="patients"></param>
 public Patients InsertPatients(Patients patients)
 {
     using (var ide = new iDentalEntities())
     {
         ide.Patients.Add(patients);
         ide.SaveChanges();
         return(patients);
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="patientCategorys"></param>
 /// <param name="newTitle"></param>
 public void DeletePatientCategorys(PatientCategorys patientCategorys)
 {
     using (var ide = new iDentalEntities())
     {
         var deleteItem = ide.PatientCategorys.Where(w => w.PatientCategory_ID == patientCategorys.PatientCategory_ID).First();
         deleteItem.Patients.Remove(new Patients());
         ide.PatientCategorys.Remove(deleteItem);
         ide.SaveChanges();
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="patientCategorys"></param>
 /// <param name="newTitle"></param>
 public void UpdatePatientCategorysTitle(PatientCategorys patientCategorys, string newTitle)
 {
     using (var ide = new iDentalEntities())
     {
         PatientCategorys updateItem = (from pc in ide.PatientCategorys
                                        where pc.PatientCategory_ID == patientCategorys.PatientCategory_ID
                                        select pc).First();
         updateItem.PatientCategory_Title = newTitle;
         ide.SaveChanges();
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 更新病患大頭照
 /// </summary>
 /// <param name="patients"></param>
 /// <param name="photoPath"></param>
 public void UpdatePatientPhoto(Patients patients, string photoPath)
 {
     using (var ide = new iDentalEntities())
     {
         Patients p = (from qp in ide.Patients
                       where qp.Patient_ID == patients.Patient_ID
                       select qp).First();
         p.Patient_Photo = photoPath;
         p.UpdateDate    = DateTime.Now;
         ide.SaveChanges();
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 更新機構資訊
 /// </summary>
 /// <param name="agencys"></param>
 /// <param name="imagePath"></param>
 /// <param name="wifiCardPath"></param>
 /// <param name="viewType"></param>
 /// <param name="functionID"></param>
 /// <returns></returns>
 public void UpdateAgency(Agencys agencys, string imagePath, string wifiCardPath, string viewType, int functionID)
 {
     using (var ide = new iDentalEntities())
     {
         Agencys newAgencys = (from a in ide.Agencys
                               where a.Agency_Code == agencys.Agency_Code
                               select a).First();
         newAgencys.Agency_ImagePath    = imagePath;
         newAgencys.Agency_WifiCardPath = wifiCardPath;
         newAgencys.Agency_ViewType     = viewType;
         newAgencys.Function_ID         = functionID;
         ide.SaveChanges();
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 更新病患大頭照
 /// </summary>
 /// <param name="patients"></param>
 /// <param name="photoPath"></param>
 public Patients UpdatePatients(Patients patients)
 {
     using (var ide = new iDentalEntities())
     {
         Patients p = (from qp in ide.Patients
                       where qp.Patient_ID == patients.Patient_ID
                       select qp).First();
         p.Patient_Number   = patients.Patient_Number;
         p.Patient_Name     = patients.Patient_Name;
         p.Patient_Gender   = patients.Patient_Gender;
         p.Patient_Birth    = patients.Patient_Birth;
         p.Patient_IDNumber = patients.Patient_IDNumber;
         p.Patient_Photo    = patients.Patient_Photo;
         p.Patient_FirstRegistrationDate = patients.Patient_FirstRegistrationDate;
         p.UpdateDate = patients.UpdateDate;
         ide.SaveChanges();
         return(p);
     }
 }
Ejemplo n.º 11
0
        private void Button_ImageDelete_Click(object sender, RoutedEventArgs e)
        {
            if (lbImages.SelectedItems.Count == 0)
            {
                lbImages.SelectAll();
            }
            if (MessageBox.Show("確定刪除已選定的" + lbImages.SelectedItems.Count + "個項目?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                using (var ide = new iDentalEntities())
                {
                    try
                    {
                        var selectedItemID = from si in DisplayImageInfo
                                             where si.IsSelected == true
                                             select si.Image_ID;
                        var deleteItem = (from i in ide.Images
                                          where selectedItemID.Contains(i.Image_ID)
                                          select i).ToList();
                        deleteItem.ForEach(i => i.Image_IsEnable = false);
                        ide.SaveChanges();

                        foreach (ImageInfo ii in DisplayImageInfo.ToArray())
                        {
                            if (ii.IsSelected)
                            {
                                DisplayImageInfo.Remove(ii);
                            }
                        }
                        functionListViewModel.CountImages = DisplayImageInfo.Count();
                        if (DisplayImageInfo.Count() == 0)
                        {
                            ReturnValueCallback();
                        }
                    }
                    catch (Exception ex)
                    {
                        ErrorLog.ErrorMessageOutput(ex.ToString());
                        MessageBox.Show("刪除圖片發生錯誤", "錯誤", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="template_image_id"></param>
 public string RemoveAndReturnUidTemplatesImages(int template_image_id)
 {
     using (var ide = new iDentalEntities())
     {
         var qti = from ti in ide.Templates_Images
                   where ti.Template_Image_ID == template_image_id
                   select ti;
         if (qti.Count() > 0)
         {
             Templates_Images templates_Images = new Templates_Images();
             templates_Images            = qti.First();
             templates_Images.Image_ID   = null;
             templates_Images.Image_Path = string.Empty;
             ide.SaveChanges();
             var qt = ide.Templates.Where(w => w.Template_ID == templates_Images.Template_ID).First();
             return(qt.Template_DefaultImage);
         }
         return(null);
     }
 }
Ejemplo n.º 13
0
 /// <summary>
 /// 新增查詢病患並回傳
 /// </summary>
 /// <param name="patients">Patients</param>
 /// <returns></returns>
 public Patients QueryNewOldPatient(Patients patients)
 {
     using (var ide = new iDentalEntities())
     {
         var queryPatient = from p in ide.Patients
                            where p.Patient_ID == patients.Patient_ID
                            select p;
         if (queryPatient.Count() > 0)
         {
             return(queryPatient.First());
         }
         else
         {
             patients.Patient_FirstRegistrationDate = DateTime.Now.Date;
             ide.Patients.Add(patients);
             ide.SaveChanges();
             return(patients);
         }
     }
 }
Ejemplo n.º 14
0
        public void InsertPatientsPatientCategorys(Patients patients, List <PatientCategoryInfo> list)
        {
            using (var ide = new iDentalEntities())
            {
                Patients p = (from ps in ide.Patients
                              where ps.Patient_ID == patients.Patient_ID
                              select ps).First();

                foreach (PatientCategorys pc in ide.PatientCategorys)
                {
                    var queryCheck = list.FindAll(pci => pci.PatientCategory_ID == pc.PatientCategory_ID);
                    if (queryCheck.Count() > 0)
                    {
                        p.PatientCategorys.Remove(pc);
                        p.PatientCategorys.Add(pc);
                    }
                    else
                    {
                        p.PatientCategorys.Remove(pc);
                    }
                }
                ide.SaveChanges();
            }
        }
Ejemplo n.º 15
0
        private void Button_Capture_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string imageFileName = string.Empty;
                string extension     = string.Empty;
                string imageFullName = string.Empty;

                extension     = @".jpg";
                imageFileName = @"device_" + DateTime.Now.ToString("yyyyMMddHHmmssffff");
                imageFullName = imageFileName + extension;

                var encoder = new JpegBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create((BitmapSource)iVideoPlayer.Source));
                using (FileStream stream = new FileStream(patientImageFolderInfo.PatientImageFullPath + @"\" + imageFullName, FileMode.Create))
                {
                    encoder.Save(stream);
                }

                //Bitmap current = (Bitmap)bitmap.Clone();
                //bitmap.Save(patientImageFolderInfo.PatientImageFullPath + @"\" + imageFullName);
                //bitmap.Dispose();

                //寫入db
                using (var ide = new iDentalEntities())
                {
                    registrations = new Registrations();
                    var queryRegistrations = from r in ide.Registrations
                                             where r.Patient_ID == patients.Patient_ID && r.Registration_Date == registrationDate.Date
                                             select r;
                    if (queryRegistrations.Count() > 0)
                    {
                        registrations = queryRegistrations.First();
                    }
                    else
                    {
                        registrations.Patient_ID        = patients.Patient_ID;
                        registrations.Registration_Date = registrationDate.Date;
                        ide.Registrations.Add(registrations);
                        //寫入Registrations
                        ide.SaveChanges();
                    }

                    Images images = new Images()
                    {
                        Image_Path      = patientImageFolderInfo.PatientImagePath + @"\" + imageFullName,
                        Image_FileName  = imageFileName,
                        Image_Extension = extension
                    };
                    registrations.Images.Add(images);
                    //Images
                    ide.SaveChanges();
                }
                webcamViewModel.RefreshDisplayImageInfoList();
                webcamViewModel.SelectedItem = webcamViewModel.DisplayImageInfoList.Last();

                dialogResul = true;
            }
            catch (Exception ex)
            {
                ErrorLog.ErrorMessageOutput(ex.ToString());
                MessageBox.Show("裝置擷取畫面出現問題,請洽資訊廠商", "錯誤", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 16
0
        private void Button_Import_Click(object sender, RoutedEventArgs e)
        {
            btnImport.Dispatcher.Invoke(() =>
            {
                btnImport.IsEnabled = false;
            });

            OpenFileDialog ofd = new OpenFileDialog()
            {
                Multiselect = true,
                DefaultExt  = ".png",
                Filter      = "All Files (*.*)|*.*|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)
            {
                if (PathCheck.IsPathExist(Agencys.Agency_ImagePath))
                {
                    DateTime RegistrationDate = patientInformationViewModel.ImportDate;
                    //設定病患資料夾
                    PatientImageFolderInfo patientImageFolderInfo = PatientFolderSetting.PatientImageFolderSetting(Agencys, Patients.Patient_ID, RegistrationDate);
                    //檢查是否存在,不存在就新增
                    PathCheck.CheckPathAndCreate(patientImageFolderInfo.PatientImageFullPath);

                    ProgressDialog progressDialog = new ProgressDialog();

                    progressDialog.Dispatcher.Invoke(() =>
                    {
                        progressDialog.PMinimum = 0;
                        progressDialog.PValue   = 0;
                        progressDialog.PMaximum = ofd.FileNames.Count();
                        progressDialog.PText    = "圖片匯入中,請稍後( 0" + " / " + progressDialog.PMaximum + " )";
                        progressDialog.Show();
                    });

                    Registrations registrations = new Registrations();

                    Task t = Task.Factory.StartNew(() =>
                    {
                        using (var ide = new iDentalEntities())
                        {
                            var queryRegistrations = from r in ide.Registrations
                                                     where r.Patient_ID == Patients.Patient_ID && r.Registration_Date == RegistrationDate.Date
                                                     select r;
                            if (queryRegistrations.Count() > 0)
                            {
                                registrations = queryRegistrations.First();
                            }
                            else
                            {
                                registrations.Patient_ID        = Patients.Patient_ID;
                                registrations.Registration_Date = RegistrationDate.Date;
                                ide.Registrations.Add(registrations);
                                //寫入Registrations
                                ide.SaveChanges();
                            }

                            foreach (string fileName in ofd.FileNames)
                            {
                                string extension     = Path.GetExtension(fileName).ToUpper();
                                string newFileName   = DateTime.Now.ToString("yyyyMMddHHmmssffff");
                                string imageFileName = newFileName + extension;

                                //判斷圖片是否為正
                                //不是,旋轉後儲存
                                //是,直接File.Copy
                                ImageHelper.RotateImageByExifOrientationData(fileName, patientImageFolderInfo.PatientImageFullPath + @"\" + newFileName + extension, extension, true);

                                Images images = new Images()
                                {
                                    Image_Path      = patientImageFolderInfo.PatientImagePath + @"\" + imageFileName,
                                    Image_FileName  = imageFileName,
                                    Image_Extension = extension
                                };
                                registrations.Images.Add(images);

                                progressDialog.Dispatcher.Invoke(() =>
                                {
                                    progressDialog.PValue++;
                                    progressDialog.PText = "圖片匯入中,請稍後( " + progressDialog.PValue + " / " + progressDialog.PMaximum + " )";
                                });

                                Thread.Sleep(200);
                            }

                            //Images
                            ide.SaveChanges();
                        }
                    }).ContinueWith(cw =>
                    {
                        progressDialog.Dispatcher.Invoke(() =>
                        {
                            progressDialog.PText = "匯入完成";
                            progressDialog.Close();
                        });

                        ReloadOrAddImage(registrations, RegistrationDate);
                        //patientInformationViewModel.RegistrationSetting();
                        //patientInformationViewModel.ComboBoxItemInfo = patientInformationViewModel.RegistrationsList.Where(w => w.SelectedValue.Equals(registrations.Registration_ID)).First();
                        GC.Collect();
                    }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
                }
                else
                {
                    MessageBox.Show("影像路徑有問題,請至<設定>檢查是否有誤", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }

            btnImport.Dispatcher.Invoke(() =>
            {
                btnImport.IsEnabled = true;
            });
        }
Ejemplo n.º 17
0
        bool isStop = false; //接ProcessingDialog 回傳值 停止
        private void ToggleButton_AutoImport_Click(object sender, RoutedEventArgs e)
        {
            if (btnAutoImport.IsChecked == true)
            {
                if (PathCheck.IsPathExist(Agencys.Agency_ImagePath) && PathCheck.IsPathExist(Agencys.Agency_WifiCardPath))
                {
                    DateTime RegistrationDate = patientInformationViewModel.ImportDate;

                    ProgressDialogIndeterminate progressDialogIndeterminate = new ProgressDialogIndeterminate();

                    progressDialogIndeterminate.Dispatcher.Invoke(() =>
                    {
                        progressDialogIndeterminate.PText                   = "準備匯入至(" + RegistrationDate.ToString("yyyy/MM/dd") + "),圖片偵測中";
                        progressDialogIndeterminate.PIsIndeterminate        = true;
                        progressDialogIndeterminate.ButtonContentVisibility = Visibility.Hidden;
                        progressDialogIndeterminate.ReturnValueCallback    += new ProgressDialogIndeterminate.ReturnValueDelegate(SetReturnValueCallbackFun);

                        progressDialogIndeterminate.Show();
                    });

                    Registrations registrations = new Registrations();
                    //匯入的圖片數
                    int imageCount = 0;

                    Task task = Task.Factory.StartNew(() =>
                    {
                        using (var ide = new iDentalEntities())
                        {
                            while (true)
                            {
                                //偵測資料夾
                                foreach (string f in Directory.GetFiles(Agencys.Agency_WifiCardPath))
                                {
                                    Thread.Sleep(1000);

                                    //設定病患資料夾
                                    PatientImageFolderInfo patientImageFolderInfo = PatientFolderSetting.PatientImageFolderSetting(Agencys, Patients.Patient_ID, RegistrationDate);
                                    //檢查是否存在,不存在就新增
                                    PathCheck.CheckPathAndCreate(patientImageFolderInfo.PatientImageFullPath);

                                    string extension     = Path.GetExtension(f).ToUpper();
                                    string newFileName   = DateTime.Now.ToString("yyyyMMddHHmmssffff");
                                    string imageFileName = newFileName + extension;

                                    //判斷圖片是否為正
                                    //不是,旋轉後儲存
                                    //是,直接File.Copy
                                    ImageHelper.RotateImageByExifOrientationData(f, patientImageFolderInfo.PatientImageFullPath + @"\" + newFileName + extension, extension, true);

                                    var queryRegistrations = from r in ide.Registrations
                                                             where r.Patient_ID == Patients.Patient_ID && r.Registration_Date == RegistrationDate.Date
                                                             select r;
                                    if (queryRegistrations.Count() > 0)
                                    {
                                        registrations = queryRegistrations.First();
                                    }
                                    else
                                    {
                                        registrations.Patient_ID        = Patients.Patient_ID;
                                        registrations.Registration_Date = RegistrationDate.Date;
                                        ide.Registrations.Add(registrations);
                                        //寫入Registrations
                                        ide.SaveChanges();
                                    }

                                    //複製完如果刪除發生問題
                                    //嘗試五次每次間隔3秒
                                    int deleteTime = 0;
                                    while (deleteTime < 5)
                                    {
                                        Thread.Sleep(3000);
                                        try
                                        {
                                            File.Delete(f);
                                            deleteTime = 5;
                                        }
                                        catch (Exception ex)
                                        {
                                            deleteTime++;
                                            if (deleteTime == 5)
                                            {
                                                if (MessageBox.Show("影像搬移中出現問題", "錯誤", MessageBoxButton.OK, MessageBoxImage.Error) == MessageBoxResult.OK)
                                                {
                                                    isStop = true;
                                                    ErrorLog.ErrorMessageOutput(ex.ToString());
                                                }
                                            }
                                        }
                                    }

                                    Images images = new Images()
                                    {
                                        Image_Path      = patientImageFolderInfo.PatientImagePath + @"\" + imageFileName,
                                        Image_FileName  = imageFileName,
                                        Image_Extension = extension
                                    };
                                    registrations.Images.Add(images);
                                    ide.SaveChanges();

                                    //已匯入
                                    imageCount++;
                                    progressDialogIndeterminate.Dispatcher.Invoke(() =>
                                    {
                                        progressDialogIndeterminate.PText = "圖片匯入中,已匯入" + imageCount + "張";
                                    });

                                    Thread.Sleep(200);
                                }
                                //按停止
                                if (isStop)
                                {
                                    isStop = false;
                                    return;
                                }
                            }
                        }
                    }).ContinueWith(cw =>
                    {
                        progressDialogIndeterminate.Dispatcher.Invoke(() =>
                        {
                            progressDialogIndeterminate.PText = "處理完畢";
                            progressDialogIndeterminate.Close();
                        });

                        btnAutoImport.IsChecked = false;

                        if (imageCount > 0)
                        {
                            ReloadOrAddImage(registrations, RegistrationDate);
                            //patientInformationViewModel.RegistrationSetting();
                            //patientInformationViewModel.ComboBoxItemInfo = patientInformationViewModel.RegistrationsList.Where(w => w.SelectedValue.Equals(registrations.Registration_ID)).First();
                        }

                        GC.Collect();
                    }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
                }
                else
                {
                    MessageBox.Show("影像路徑或Wifi Card路徑有問題,請至<設定>檢查是否有誤", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
        }
Ejemplo n.º 18
0
        private void TransferImages()
        {
            DateTime RegistrationDate = DateTime.Parse(imageTransferIntoViewModel.TransRegistrationDate);
            //設定病患資料夾
            PatientImageFolderInfo patientImageFolderInfo = PatientFolderSetting.PatientImageFolderSetting(imageTransferIntoViewModel.Agencys, imageTransferIntoViewModel.TargetPatients.Patient_ID, RegistrationDate);

            //檢查是否存在,不存在就新增
            PathCheck.CheckPathAndCreate(patientImageFolderInfo.PatientImageFullPath);

            ProgressDialog progressDialog = new ProgressDialog();

            progressDialog.Dispatcher.Invoke(() =>
            {
                progressDialog.PMinimum = 0;
                progressDialog.PValue   = 0;
                progressDialog.PMaximum = imageTransferIntoViewModel.DisplayImageInfoListCount;
                progressDialog.PText    = "圖片匯入中,請稍後( 0" + " / " + progressDialog.PMaximum + " )";
                progressDialog.Show();
            });

            Registrations registrations = new Registrations();

            Task t = Task.Factory.StartNew(() =>
            {
                using (var ide = new iDentalEntities())
                {
                    var queryRegistrations = from r in ide.Registrations
                                             where r.Patient_ID == imageTransferIntoViewModel.TargetPatients.Patient_ID && r.Registration_Date == RegistrationDate.Date
                                             select r;
                    if (queryRegistrations.Count() > 0)
                    {
                        registrations = queryRegistrations.First();
                    }
                    else
                    {
                        registrations.Patient_ID        = imageTransferIntoViewModel.TargetPatients.Patient_ID;
                        registrations.Registration_Date = RegistrationDate.Date;
                        ide.Registrations.Add(registrations);
                        //寫入Registrations
                        ide.SaveChanges();
                    }

                    foreach (ImageInfo ii in imageTransferIntoViewModel.DisplayImageInfoList)
                    {
                        string extension     = Path.GetExtension(ii.Image_FullPath).ToUpper();
                        string imageFileName = Path.GetFileName(ii.Image_FullPath);
                        //路徑不同再轉入
                        if (!ii.Image_FullPath.Equals(patientImageFolderInfo.PatientImageFullPath + @"\" + imageFileName))
                        {
                            File.Move(ii.Image_FullPath, patientImageFolderInfo.PatientImageFullPath + @"\" + imageFileName);

                            Images queryImage = (from i in ide.Images
                                                 where i.Image_ID.Equals(ii.Image_ID)
                                                 select i).First();
                            queryImage.Image_Path      = patientImageFolderInfo.PatientImagePath + @"\" + imageFileName;
                            queryImage.Image_FileName  = imageFileName;
                            queryImage.Image_Extension = extension;
                            queryImage.Registration_ID = registrations.Registration_ID;
                            ide.SaveChanges();
                        }
                        progressDialog.Dispatcher.Invoke(() =>
                        {
                            progressDialog.PValue++;
                            progressDialog.PText = "圖片匯入中,請稍後( " + progressDialog.PValue + " / " + progressDialog.PMaximum + " )";
                        });

                        Thread.Sleep(200);
                    }

                    //判斷那些掛號日底下已經沒有圖片了
                    var queryNoImageInRegistrations = from r in ide.Registrations
                                                      where r.Patient_ID.Equals(imageTransferIntoViewModel.Patients.Patient_ID) &&
                                                      r.Images.Count.Equals(0)
                                                      select r;
                    ide.Registrations.RemoveRange(queryNoImageInRegistrations);

                    if (!imageTransferIntoViewModel.Patients.Patient_ID.Equals(imageTransferIntoViewModel.TargetPatients.Patient_ID))
                    {
                        var queryImageID = from ti in imageTransferIntoViewModel.DisplayImageInfoList
                                           where ti.IsSelected == true
                                           select ti.Image_ID;
                        var deleteItem = from ti in ide.Templates_Images
                                         where queryImageID.Contains((int)ti.Image_ID) &&
                                         ti.Patient_ID.Equals(imageTransferIntoViewModel.Patients.Patient_ID)
                                         select ti;
                        ide.Templates_Images.RemoveRange(deleteItem);
                    }
                    ide.SaveChanges();
                }
            }).ContinueWith(cw =>
            {
                progressDialog.Dispatcher.Invoke(() =>
                {
                    progressDialog.PText = "匯入完成";
                    progressDialog.Close();
                });

                MessageBox.Show("轉換成功", "提示", MessageBoxButton.OK);

                GC.Collect();

                DialogResult = true;
                Close();
            }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
        }
Ejemplo n.º 19
0
        bool isSkip = true;  //ProgressDialogIndeterminate 回傳值 略過

        private void Button_AutoImport_Click(object sender, RoutedEventArgs e)
        {
            if (btnAutoImport.IsChecked == true)
            {
                if (PathCheck.IsPathExist(Agencys.Agency_ImagePath) && PathCheck.IsPathExist(Agencys.Agency_WifiCardPath))
                {
                    bool isEverChanged = false;

                    ProgressDialogIndeterminate progressDialogIndeterminate = new ProgressDialogIndeterminate();

                    progressDialogIndeterminate.Dispatcher.Invoke(() =>
                    {
                        progressDialogIndeterminate.PText                = "圖片偵測中";
                        progressDialogIndeterminate.PIsIndeterminate     = true;
                        progressDialogIndeterminate.ButtonContent        = "跳過";
                        progressDialogIndeterminate.ReturnValueCallback += new ProgressDialogIndeterminate.ReturnValueDelegate(SetReturnValueCallbackFun);
                        progressDialogIndeterminate.Show();
                    });

                    Registrations registrations = new Registrations();

                    Task t = Task.Factory.StartNew(() =>
                    {
                        using (var ide = new iDentalEntities())
                        {
                            CreateBitmapImage createBitmapImage = new CreateBitmapImage();

                            ObservableCollection <Templates_Images> Templates_ImagesCollect = tableTemplates_Images.QueryTemplatesImagesImportDateAndReturnFullImagePath(Agencys, Patients, SelectedTemplate, functionTemplateViewModel.SelectedDate);

                            //default Image[i] in UserControl Templates
                            int Imagei = 0;
                            //載入樣板設定
                            int ImageCount       = (int)SelectedTemplate.Template_ImageCount;
                            int DecodePixelWidth = (int)SelectedTemplate.Template_DecodePixelWidth;
                            while (Imagei < ImageCount)
                            {
                                progressDialogIndeterminate.Dispatcher.Invoke(() =>
                                {
                                    progressDialogIndeterminate.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));
                                });

                                //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(1000);

                                        //設定病患資料夾
                                        PatientImageFolderInfo patientImageFolderInfo = PatientFolderSetting.PatientImageFolderSetting(Agencys, Patients.Patient_ID, RegistrationDate);
                                        //檢查是否存在,不存在就新增
                                        PathCheck.CheckPathAndCreate(patientImageFolderInfo.PatientImageFullPath);

                                        string extension     = Path.GetExtension(f).ToUpper();
                                        string newFileName   = DateTime.Now.ToString("yyyyMMddHHmmssffff");
                                        string imageFileName = newFileName + extension;

                                        //判斷圖片是否為正
                                        //不是,旋轉後儲存
                                        //是,直接File.Copy
                                        ImageHelper.RotateImageByExifOrientationData(f, patientImageFolderInfo.PatientImageFullPath + @"\" + newFileName + extension, extension, true);

                                        var queryRegistrations = from r in ide.Registrations
                                                                 where r.Patient_ID == Patients.Patient_ID && r.Registration_Date == RegistrationDate.Date
                                                                 select r;
                                        if (queryRegistrations.Count() > 0)
                                        {
                                            registrations = queryRegistrations.First();
                                        }
                                        else
                                        {
                                            registrations.Patient_ID        = Patients.Patient_ID;
                                            registrations.Registration_Date = RegistrationDate.Date;
                                            ide.Registrations.Add(registrations);
                                            //寫入Registrations
                                            ide.SaveChanges();
                                        }

                                        Images images = new Images()
                                        {
                                            Image_Path      = patientImageFolderInfo.PatientImagePath + @"\" + imageFileName,
                                            Image_FileName  = imageFileName,
                                            Image_Extension = extension
                                        };

                                        registrations.Images.Add(images);
                                        ide.SaveChanges();

                                        //複製完如果刪除發生問題
                                        //嘗試五次每次間隔3秒
                                        int deleteTime = 0;
                                        while (deleteTime < 5)
                                        {
                                            Thread.Sleep(3000);
                                            try
                                            {
                                                File.Delete(f);
                                                deleteTime = 5;
                                            }
                                            catch (Exception ex)
                                            {
                                                deleteTime++;
                                                if (deleteTime == 5)
                                                {
                                                    if (MessageBox.Show("影像搬移中出現問題", "錯誤", MessageBoxButton.OK, MessageBoxImage.Error) == MessageBoxResult.OK)
                                                    {
                                                        isStop = true;
                                                        ErrorLog.ErrorMessageOutput(ex.ToString());
                                                    }
                                                }
                                            }
                                        }

                                        TemplateContent.Dispatcher.Invoke(() =>
                                        {
                                            //INSERT TemplateImages
                                            //寫入資料庫再帶回畫面
                                            string ImageUID = string.Empty;
                                            ImageUID        = tableTemplates_Images.InsertOrUpdateTemplatesImages(Patients, functionTemplateViewModel.SelectedTemplate, functionTemplateViewModel.SelectedDate, images.Image_ID, images.Image_Path, Imagei.ToString());

                                            iTarget        = new Image();
                                            iTarget        = (Image)TemplateContent.FindName("Image" + Imagei);
                                            iTarget.Uid    = ImageUID;
                                            iTarget.Source = createBitmapImage.BitmapImageShow(patientImageFolderInfo.PatientImageFullPath + @"\" + imageFileName, DecodePixelWidth);
                                            isChanged      = true;
                                        });

                                        isEverChanged = true;
                                        //代表以處理完結束這回合的偵測
                                        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 Templates_ImagesCollect
                                                               where tc.Template_Image_Number == Imagei.ToString()
                                                               select tc;
                                            if (findOriImage.Count() > 0)
                                            {
                                                iTarget.Source = createBitmapImage.BitmapImageShow(findOriImage.First().Image_Path, DecodePixelWidth);
                                            }
                                            else
                                            {
                                                //iTarget.Source = new BitmapImage(new Uri(@"/DigiDental;component/Resource/no.png", UriKind.RelativeOrAbsolute));
                                            }
                                        });
                                        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 Templates_ImagesCollect
                                                                       where tc.Template_Image_Number == Imagei.ToString()
                                                                       select tc;
                                                    if (findOriImage.Count() > 0)
                                                    {
                                                        iTarget.Source = createBitmapImage.BitmapImageShow(findOriImage.First().Image_Path, DecodePixelWidth);
                                                    }
                                                    else
                                                    {
                                                        //iTarget.Source = new BitmapImage(new Uri(@"/DigiDental;component/Resource/no.png", UriKind.RelativeOrAbsolute));
                                                    }
                                                });
                                            }
                                            Imagei++;
                                            isSkip = true;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }).ContinueWith(cw =>
                    {
                        //結束
                        progressDialogIndeterminate.Dispatcher.Invoke(() =>
                        {
                            progressDialogIndeterminate.PText = "處理完畢";
                            progressDialogIndeterminate.Close();
                        });

                        //委派回傳MainWindow
                        //刷新Registrations 資料
                        //刷新Images 資料
                        if (isEverChanged)
                        {
                            ReturnValueCallback(registrations.Registration_Date);
                        }

                        GC.Collect();

                        btnAutoImport.IsChecked = false;
                    }, TaskScheduler.FromCurrentSynchronizationContext());
                }
                else
                {
                    MessageBox.Show("影像路徑或Wifi Card路徑有問題,請至<設定>檢查是否有誤", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
        }