Ejemplo n.º 1
0
        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));

                //病患大頭照路徑
                PatientPhotoFolderInfo patientPhotoFolderInfo = PatientFolderSetting.PatientPhotoFolderSetting(Agencys, Patients.Patient_ID);
                //建立大頭照路徑
                PathCheck.CheckPathAndCreate(patientPhotoFolderInfo.PatientPhotoFullPath);

                string newPatientPhotoFileName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + dragImage.Image_Extension;
                string newPatientPhotoFile     = patientPhotoFolderInfo.PatientPhotoFullPath + @"\" + newPatientPhotoFileName;
                File.Copy(dragImage.Image_FullPath, newPatientPhotoFile);
                Thread.Sleep(500);

                patientInformationViewModel.Patient_Photo = new CreateBitmapImage().BitmapImageShow(newPatientPhotoFile, 400);

                new TablePatients().UpdatePatientPhoto(Patients, patientPhotoFolderInfo.PatientPhotoPath + @"\" + newPatientPhotoFileName);
            }
            catch (Exception ex)
            {
                ErrorLog.ErrorMessageOutput(ex.ToString());
                MessageBox.Show("移動圖片發生錯誤,聯絡資訊人員", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 2
0
 public void AssertPathAbsoluteInValid()
 {
     Assert.Throws <Exception>(() => PathCheck.IsAbsolute(@"\"));
     Assert.Throws <Exception>(() => PathCheck.IsAbsolute(@"c:foo"));
     Assert.Throws <Exception>(() => PathCheck.IsAbsolute(@"cache"));
     Assert.Throws <Exception>(() => PathCheck.IsAbsolute(@"locales\"));
 }
Ejemplo n.º 3
0
        private void Button_Pointofix_Click(object sender, RoutedEventArgs e)
        {
            string PointofixPath = ConfigManage.ReadAppConfig("PointofixPath");

            if (PathCheck.IsFileExist(PointofixPath))
            {
                //如果Pointofix已經執行 先關閉
                Process[] processes = Process.GetProcessesByName("Pointofix");
                if (processes.Length > 0)
                {
                    foreach (Process p in processes)
                    {
                        // 關閉目前程序前先等待 200 毫秒
                        p.WaitForExit(200);
                        p.CloseMainWindow();
                    }
                }
                //啟用Pointofix
                Process pointofix = new Process();
                pointofix.StartInfo.FileName = PointofixPath;
                pointofix.Start();
            }
            else
            {
                MessageBox.Show("尚未找到Pointofix的執行程式,請至設定重新設定");
            }
        }
Ejemplo n.º 4
0
 public void Update()
 {
     targetSOI = targetVessel.mainBody.name;
     targetAlt = (float)targetVessel.altitude / 1000f;
     if (hailerGUI.nearBeacon != null)
     {
         pathCheck = new PathCheck(hailerGUI.nearBeacon.Vessel, targetVessel, hailerGUI.nearBeacon.PathGLimit);
         float tripdist = Vector3.Distance(hailerGUI.nearBeacon.Vessel.GetWorldPos3D(), targetVessel.GetWorldPos3D());
         tripCost   = hailerGUI.nearBeacon.GetTripBaseCost(tripdist, hailerGUI.tonnage);
         tripCost   = hailerGUI.nearBeacon.GetTripFinalCost(tripCost, hailerGUI.vessel, targetVessel, hailerGUI.tonnage, hailerGUI.HCUPartsList);
         affordable = true;
         int i = hailerGUI.nearBeacon.JumpResources.Count - 1;
         while (i >= 0)
         {
             if (hailerGUI.nearBeacon.RequireResource(hailerGUI.nearBeacon.JumpResources[i].resID, (double)(tripCost * hailerGUI.nearBeacon.JumpResources[i].ratio), false))
             {
                 i--;
                 continue;
             }
             affordable = false;
             break;
         }
         returnCost       = float.PositiveInfinity;
         returnAffordable = false;
         if (farBeaconVessels.ContainsKey(targetVessel))
         {
             returnFuelCheck = farBeaconVessels[targetVessel].Any((ProtoBeacon pb) => pb.JumpResources.All((ESLDJumpResource res) => res.fuelCheck));
             precision       = 3.40282347E+38f;
             for (int i2 = farBeaconVessels[targetVessel].Count - 1; i2 >= 0; i2--)
             {
                 precision = Math.Min(farBeaconVessels[targetVessel][i2].GetTripSpread(tripdist), precision);
                 float possibleReturnCost = farBeaconVessels[targetVessel][i2].GetTripBaseCost(tripdist, hailerGUI.tonnage);
                 bool  flag = false;
                 if (returnFuelCheck)
                 {
                     flag = farBeaconVessels[targetVessel][i2].JumpResources.All((ESLDJumpResource res) => res.fuelCheck && (double)(res.ratio * possibleReturnCost) <= res.fuelOnBoard);
                     if (flag)
                     {
                         returnAffordable = true;
                     }
                 }
                 if (possibleReturnCost < returnCost && ((!returnFuelCheck || !returnAffordable) | flag))
                 {
                     returnCost   = possibleReturnCost;
                     returnBeacon = farBeaconVessels[targetVessel][i2];
                 }
             }
         }
         else
         {
             returnFuelCheck = false;
             precision       = hailerGUI.nearBeacon.GetTripSpread(tripdist);
         }
     }
     else
     {
         pathCheck = new PathCheck(null, targetVessel, 0f);
     }
 }
Ejemplo n.º 5
0
 public void IsPathAbsoluteInValid()
 {
     Assert.False(PathCheck.IsAbsolute(@"\"));
     Assert.False(PathCheck.IsAbsolute(@"/"));
     Assert.False(PathCheck.IsAbsolute(@"C:"));
     Assert.False(PathCheck.IsAbsolute(@"."));
     Assert.False(PathCheck.IsAbsolute(@".."));
     Assert.False(PathCheck.IsAbsolute(@"cache"));
     Assert.False(PathCheck.IsAbsolute(@"cache\"));
 }
Ejemplo n.º 6
0
 public void IsPathAbsoluteValid()
 {
     Assert.True(PathCheck.IsAbsolute(@"C:\foo1"));
     Assert.True(PathCheck.IsAbsolute(@"c:\"));
     Assert.True(PathCheck.IsAbsolute(@"C:\foo2"));
     Assert.True(PathCheck.IsAbsolute(@"C:\foo2\"));
     Assert.True(PathCheck.IsAbsolute(@"c:/"));
     Assert.True(PathCheck.IsAbsolute(@"C:/foo1"));
     Assert.True(PathCheck.IsAbsolute(@"c:\"));
     Assert.True(PathCheck.IsAbsolute(@"C:/foo2"));
 }
Ejemplo n.º 7
0
 public void IsPathAbsoluteValid()
 {
     Assert.True(PathCheck.IsAbsolute(@"C:\foo1"));
     Assert.True(PathCheck.IsAbsolute(@"c:\"));
     Assert.True(PathCheck.IsAbsolute(@"C:\foo2"));
     Assert.True(PathCheck.IsAbsolute(@"C:\foo2\"));
     Assert.True(PathCheck.IsAbsolute(@"c:/"));
     Assert.True(PathCheck.IsAbsolute(@"C:/foo1"));
     Assert.True(PathCheck.IsAbsolute(@"c:\"));
     Assert.True(PathCheck.IsAbsolute(@"C:/foo2"));
     Assert.True(PathCheck.IsAbsolute(@"C:\Users\appveyor\AppData\Local\CefSharp\Tests\Cache"));
 }
Ejemplo n.º 8
0
        public void LoadAllTemplatesImages(ObservableCollection <Templates_Images> observableCollection, Grid grid, int templateImagePixelWidth)
        {
            try
            {
                if (observableCollection.Count() > 0)
                {
                    ProgressDialog progressDialog = new ProgressDialog();
                    progressDialog.Dispatcher.Invoke(() =>
                    {
                        progressDialog.PText    = "圖片載入中( 0 / " + observableCollection.Count() + " )";
                        progressDialog.PMinimum = 0;
                        progressDialog.PValue   = 0;
                        progressDialog.PMaximum = observableCollection.Count();
                        progressDialog.Show();
                    });
                    //multi - thread
                    Task.Factory.StartNew(() =>
                    {
                        foreach (Templates_Images ti in observableCollection)
                        {
                            if (!string.IsNullOrEmpty(ti.Image_Path) && PathCheck.IsFileExist(ti.Image_Path))
                            {
                                grid.Dispatcher.Invoke(() =>
                                {
                                    Image iTarget  = (Image)grid.FindName("Image" + ti.Template_Image_Number);
                                    iTarget.Uid    = ti.Template_Image_ID.ToString();
                                    iTarget.Source = new CreateBitmapImage().BitmapImageShow(ti.Image_Path, templateImagePixelWidth);
                                });
                            }
                            progressDialog.Dispatcher.Invoke(() =>
                            {
                                progressDialog.PValue++;
                                progressDialog.PText = "圖片載入中( " + progressDialog.PValue + " / " + observableCollection.Count() + " )";
                            });
                        }
                    }).ContinueWith(t =>
                    {
                        progressDialog.Dispatcher.Invoke(() =>
                        {
                            progressDialog.PText = "載入完成";
                            progressDialog.Close();
                        });

                        GC.Collect();
                    });
                }
            }
            catch (Exception ex)
            {
                ErrorLog.ErrorMessageOutput(ex.ToString());
                MessageBox.Show("載入樣板圖片發生錯誤", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 9
0
 public TargetDetails(Vessel target, HailerGUI hailerGUI)
 {
     this.hailerGUI = hailerGUI;
     targetVessel   = target;
     vesselName     = target.vesselName;
     if (hailerGUI.nearBeacon != null)
     {
         pathCheck = new PathCheck(hailerGUI.nearBeacon.Vessel, targetVessel, hailerGUI.nearBeacon.PathGLimit);
     }
     else
     {
         pathCheck = new PathCheck(null, targetVessel, 0f);
     }
     Update();
 }
Ejemplo n.º 10
0
 private void ToggleButton_Save_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         //診所設定判斷
         Agencys agencys = agencySettingViewModel.Agencys;
         if (PathCheck.IsPathExist(agencys.Agency_ImagePath))
         {
             new TableAgencys().UpdateAgency(agencys, agencys.Agency_ImagePath, agencys.Agency_WifiCardPath, agencys.Agency_ViewType, agencys.Function_ID);
             ReturnDialogResult = true;
         }
         else
         {
             if (MessageBox.Show("您所設定的影像路徑無法使用,可能會導致影像無法存取,是否繼續?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
             {
                 new TableAgencys().UpdateAgency(agencys, agencys.Agency_ImagePath, agencys.Agency_WifiCardPath, agencys.Agency_ViewType, agencys.Function_ID);
                 ReturnDialogResult = true;
             }
         }
         //其他
         string PointofixPath = agencySettingViewModel.Pointofix;
         if (PathCheck.IsFileExist(PointofixPath) || string.IsNullOrEmpty(PointofixPath))
         {
             ConfigManage.AddUpdateAppConfig("PointofixPath", PointofixPath);
             ReturnDialogResult = true;
         }
         else
         {
             if (MessageBox.Show("您所設定的Pointofix的位置不存在,可能會導致該軟體無法使用,是否繼續?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
             {
                 ConfigManage.AddUpdateAppConfig("PointofixPath", PointofixPath);
                 ReturnDialogResult = true;
             }
         }
         string ImageDecodePixel = agencySettingViewModel.ImageDecodePixel;
         ConfigManage.AddUpdateAppConfig("ImageDecodePixel", ImageDecodePixel);
         MessageBox.Show("設定已更改");
     }
     catch (Exception ex)
     {
         MessageBox.Show("儲存設定時發生異常", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
         ErrorLog.ErrorMessageOutput(ex.ToString());
     }
     DialogResult = ReturnDialogResult;
     Close();
 }
Ejemplo n.º 11
0
    private void UnitGenerating(GameObject Tile, int tileType)
    {
        bool unitSpawned = false;

        while (!unitSpawned)
        {
            Vector3 candidate = new Vector3(Random.Range(1, 28), Random.Range(1, 28), 0);
            if (!GridOccupied(candidate) && PathCheck.AStarSearchPath(candidate, obstacles))
            {
                unitSpawned = true;
                Instantiate(Tile, candidate, Quaternion.identity).transform.SetParent(boardHolder);
                if (tileType != ENEMY_TILE)
                {
                    hasUnits.Add(candidate);
                }
            }
        }
    }
Ejemplo n.º 12
0
        public Webcam(FilterInfoCollection filterInfoCollection, Agencys agencys, Patients patients, DateTime registrationDate)
        {
            InitializeComponent();

            this.agencys = agencys;

            this.patients = patients;

            this.registrationDate = registrationDate;

            webcamViewModel = new WebcamViewModel(agencys, patients, registrationDate);

            DataContext = webcamViewModel;

            txtRegistratonDate.Text = "匯入日期:" + registrationDate.ToString("yyyy/MM/dd");

            patientImageFolderInfo = PatientFolderSetting.PatientImageFolderSetting(agencys, patients.Patient_ID, registrationDate);

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

            GetVideoDevices(filterInfoCollection);
        }
Ejemplo n.º 13
0
    private int GetNearestUnitDistance(Vector3 target)
    {
        int nearestDistance = -1;

        foreach (var unit in existingUnits)
        {
            int currentDis = PathCheck.GetDistance(target, unit);
            if (nearestDistance == -1)
            {
                nearestDistance = currentDis;
            }

            else
            {
                if (currentDis < nearestDistance)
                {
                    nearestDistance = currentDis;
                }
            }
            Debug.Log(currentDis);
        }
        return(nearestDistance);
    }
Ejemplo n.º 14
0
        //編輯
        public PatientSettingViewModel(string windowType, Agencys agencys, Patients patients)
        {
            WindowType = windowType;
            Patients   = patients;

            //設定病患資料
            //載入設定就好,避免多設定
            Patient_Number   = patients.Patient_Number;
            Patient_Name     = patients.Patient_Name;
            Patient_IDNumber = patients.Patient_IDNumber;
            Patient_Gender   = patients.Patient_Gender;
            Patient_Birth    = patients.Patient_Birth;
            if (PathCheck.IsFileExist(agencys.Agency_ImagePath + patients.Patient_Photo))
            {
                Patient_Photo = new CreateBitmapImage().BitmapImageShow(agencys.Agency_ImagePath + patients.Patient_Photo, 400);
            }
            Patient_FirstRegistrationDate = patients.Patient_FirstRegistrationDate == null ? DateTime.Now : (DateTime)patients.Patient_FirstRegistrationDate;
            DateTime lastRegistrationDate = new TableRegistrations().QueryLastRegistrationDate(patients);

            Patient_LastRegistrationDate = lastRegistrationDate == null?Patient_FirstRegistrationDate.ToString("yyyy/MM/dd") : lastRegistrationDate.ToString("yyyy/MM/dd");

            PatientCategoryInfo = new TablePatientCategorys().QueryPatientPatientCategoryInfo(Patients).ToList().FindAll(s => s.IsChecked == true);
        }
Ejemplo n.º 15
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.º 16
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);
                }
            }
        }
Ejemplo n.º 17
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.º 18
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.º 19
0
            public void Update()
            {
                targetSOI = targetVessel.mainBody.name;
                targetAlt = (float)targetVessel.altitude / 1000;
                if (hailerGUI.nearBeacon != null)
                {
                    pathCheck = new PathCheck(hailerGUI.nearBeacon.Vessel, targetVessel, hailerGUI.nearBeacon.PathGLimit);
                }
                else
                {
                    pathCheck = new PathCheck(null, targetVessel, 0);
                    return;
                }
                float tripdist = Vector3.Distance(hailerGUI.nearBeacon.Vessel.GetWorldPos3D(), targetVessel.GetWorldPos3D());

                tripCost = hailerGUI.nearBeacon.GetTripBaseCost(tripdist, hailerGUI.tonnage);
                tripCost = hailerGUI.nearBeacon.GetTripFinalCost(tripCost, hailerGUI.vessel, targetVessel, hailerGUI.tonnage, hailerGUI.HCUPartsList);
                //float cost = tripCost;
                affordable = true;
                for (int i = hailerGUI.nearBeacon.JumpResources.Count - 1; i >= 0; i--)
                {
                    if (!hailerGUI.nearBeacon.RequireResource(hailerGUI.nearBeacon.JumpResources[i].resID, tripCost * hailerGUI.nearBeacon.JumpResources[i].ratio, false))
                    {
                        affordable = false;
                        break;
                    }
                }
                //HailerGUI hailer = hailerGUI;
                //affordable = hailerGUI.nearBeacon.JumpResources.All(res => hailer.nearBeacon.RequireResource(res.resID, res.ratio * cost, false));
                returnCost       = float.PositiveInfinity;
                returnAffordable = false;
                if (farBeaconVessels.ContainsKey(targetVessel))
                {
                    returnFuelCheck = farBeaconVessels[targetVessel].Any(pb => pb.JumpResources.All(res => res.fuelCheck));
                    precision       = float.MaxValue;
                    for (int i = farBeaconVessels[targetVessel].Count - 1; i >= 0; i--)
                    {
                        precision = Math.Min(farBeaconVessels[targetVessel][i].GetTripSpread(tripdist), precision);
                        float possibleReturnCost = farBeaconVessels[targetVessel][i].GetTripBaseCost(tripdist, hailerGUI.tonnage);
                        bool  beaconCanAfford    = false;
                        if (returnFuelCheck)
                        {
                            beaconCanAfford = farBeaconVessels[targetVessel][i].JumpResources.All(res => res.fuelCheck && res.ratio * possibleReturnCost <= res.fuelOnBoard);
                            if (beaconCanAfford)
                            {
                                returnAffordable = true;
                            }
                        }
                        if (possibleReturnCost < returnCost && (!returnFuelCheck || !returnAffordable || beaconCanAfford))
                        {
                            returnCost   = possibleReturnCost;
                            returnBeacon = farBeaconVessels[targetVessel][i];
                        }
                    }
                }
                else
                {
                    returnFuelCheck = false;
                    precision       = hailerGUI.nearBeacon.GetTripSpread(tripdist);
                }
            }
Ejemplo n.º 20
0
        /// <summary>
        /// 開始載入判斷
        /// </summary>
        private void Loading()
        {
            try
            {
                //取得本機訊息
                //HostName、IP
                string      hostName    = Dns.GetHostName();
                string      localIP     = string.Empty;
                IPHostEntry ipHostEntry = Dns.GetHostEntry(hostName);
                foreach (IPAddress ip in ipHostEntry.AddressList)
                {
                    if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        localIP = ip.ToString();
                    }
                }

                TextBlockStatus.Dispatcher.Invoke(() =>
                {
                    TextBlockStatus.Text = "伺服器位置確認中";
                }, DispatcherPriority.Render);

                //判斷app.config
                if (!ConfigManage.IsConfigValue("Server"))//尚未設置
                {
                    AnswerDialogOne answerDialogOne = new AnswerDialogOne("請輸入伺服器位置:", "IP");
                    if (answerDialogOne.ShowDialog() == true)
                    {
                        //寫入config Server 欄位
                        string serverIP = answerDialogOne.Answer;
                        ConfigManage.AddUpdateAppConfig("Server", serverIP);
                    }
                }

                TextBlockStatus.Dispatcher.Invoke(() =>
                {
                    TextBlockStatus.Text = "嘗試連接伺服器...";
                }, DispatcherPriority.Render);

                //連接Server connection
                if (new ConnectionString().CheckConnection())
                {
                    TextBlockStatus.Dispatcher.Invoke(() =>
                    {
                        TextBlockStatus.Text = "取得本機資訊";
                    }, DispatcherPriority.Render);


                    TableAgencys tableAgencys = new TableAgencys();
                    //取得已經驗證的機構
                    Agencys agencys = tableAgencys.QueryVerifyAgencys();
                    if (agencys != null)
                    {
                        Agencys = agencys;

                        //開始判斷本機與伺服器關係
                        TableClients tableClients = new TableClients();
                        Clients      clients      = tableClients.QueryClient(hostName);
                        if (clients != null)
                        {
                            if (!string.IsNullOrEmpty(clients.Agency_VerificationCode) && clients.Agency_VerificationCode.Equals(agencys.Agency_VerificationCode))
                            {
                                if (clients.Client_IsVerify)
                                {
                                    TextBlockStatus.Dispatcher.Invoke(() =>
                                    {
                                        TextBlockStatus.Text = "本機已認證";
                                    }, DispatcherPriority.Render);

                                    //本機與伺服器認證通過
                                    //判斷軟體使用期限
                                    CheckServerTrialPeriod(agencys);
                                }
                                else
                                {
                                    MessageBoxTips = "此台電腦已經被停用,請聯絡資訊廠商...";
                                }
                            }
                            else
                            {
                                MessageBoxTips = "此台電腦與伺服器的驗證碼不符,請聯絡資訊廠商";
                            }
                        }
                        else
                        {
                            //第一次使用,輸入驗證碼
                            AnswerDialogOne answerDialogOne = new AnswerDialogOne("此台電腦為第一次登入,請輸入產品驗證碼:", "Verify");
                            if (answerDialogOne.ShowDialog() == true)
                            {
                                string verificationCodeClient = string.Empty;
                                verificationCodeClient = KeyGenerator.SHA384Encode(answerDialogOne.Answer);
                                if (verificationCodeClient.Equals(agencys.Agency_VerificationCode))
                                {
                                    TextBlockStatus.Dispatcher.Invoke(() =>
                                    {
                                        TextBlockStatus.Text = "本機與伺服器驗證成功";
                                    }, DispatcherPriority.Render);

                                    Clients insertClients = new Clients()
                                    {
                                        Client_HostName         = hostName,
                                        Client_IP               = localIP,
                                        Client_IsVerify         = true,
                                        Agency_VerificationCode = verificationCodeClient
                                    };
                                    tableClients.InsertClient(insertClients);

                                    //本機與伺服器認證通過
                                    //判斷軟體使用期限
                                    CheckServerTrialPeriod(agencys);
                                }
                                else
                                {
                                    MessageBoxTips = "與伺服器的驗證碼不符,請聯絡資訊廠商";
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBoxTips = "伺服器尚未被驗證,無法使用,請聯絡資訊廠商";
                    }
                }
                else
                {
                    MessageBoxTips = "伺服器連接失敗";
                    ConfigManage.AddUpdateAppConfig("Server", "");
                }

                //登入成功
                //show MessageBox
                if (ReturnDialogResult)
                {
                    TextBlockStatus.Dispatcher.Invoke(() =>
                    {
                        TextBlockStatus.Text = "載入病患資料";
                    }, DispatcherPriority.Render);
                    LoadPatient();

                    TextBlockStatus.Dispatcher.Invoke(() =>
                    {
                        TextBlockStatus.Text = "影像路徑測試中,請稍候";
                    }, DispatcherPriority.Render);

                    IsExistImagePath = PathCheck.IsPathExist(Agencys.Agency_ImagePath);

                    TextBlockStatus.Dispatcher.Invoke(() =>
                    {
                        TextBlockStatus.Text = "成功登入,歡迎使用iDental";
                    }, DispatcherPriority.Render);

                    if (IsValidTrialPeriod)//還在試用期內可以使用
                    {
                        MessageBox.Show(MessageBoxTips, "提示", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
                else
                {
                    TextBlockStatus.Dispatcher.Invoke(() =>
                    {
                        TextBlockStatus.Text = "登入失敗,原因:" + MessageBoxTips;
                    }, DispatcherPriority.Render);

                    MessageBox.Show(MessageBoxTips, "提示", MessageBoxButton.OK, MessageBoxImage.Stop);
                }

                //寫入ConnectingLog資訊
                TableConnectingLogs tableConnectingLogs = new TableConnectingLogs();
                ConnectingLogs      connectingLogs      = new ConnectingLogs()
                {
                    ConnectingLog_HostName = hostName,
                    ConnectingLog_IP       = localIP,
                    ConnectingLog_Error    = MessageBoxTips,
                    ConnectingLog_IsPermit = ReturnDialogResult
                };
                tableConnectingLogs.InsertConnectingLog(connectingLogs);

                Thread.Sleep(2000);
                //回傳結果
                DialogResult = ReturnDialogResult;
            }
            catch (Exception ex)
            {
                ErrorLog.ErrorMessageOutput(ex.ToString());
                DialogResult = false;
            }
            Close();
        }
Ejemplo n.º 21
0
        private void Button_Save_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (Patients != null)//編輯
                {
                    if (MessageBox.Show("確定修改病患資料<" + patientSettingViewModel.Patient_Number + ">?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        //新的影像路徑
                        string newPatientPhotoPath = null;
                        if (!IsRemove)
                        {
                            //如果沒觸發移除,要判斷有沒有匯入的路徑
                            if (!string.IsNullOrEmpty(ImportPatientPhotoPath))
                            {
                                //有,蓋掉舊圖
                                if (PathCheck.IsFileExist(ImportPatientPhotoPath))
                                {
                                    //病患大頭照路徑
                                    PatientPhotoFolderInfo patientPhotoFolderInfo = PatientFolderSetting.PatientPhotoFolderSetting(Agencys, Patients.Patient_ID);
                                    //建立大頭照路徑
                                    PathCheck.CheckPathAndCreate(patientPhotoFolderInfo.PatientPhotoFullPath);

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

                                    File.Copy(ImportPatientPhotoPath, patientPhotoFolderInfo.PatientPhotoFullPath + @"\" + newFileName + extension);
                                    Thread.Sleep(500);

                                    newPatientPhotoPath = patientPhotoFolderInfo.PatientPhotoPath + @"\" + newFileName + extension;
                                }
                                else
                                {
                                    MessageBox.Show("圖片路徑出現問題", "錯誤", MessageBoxButton.OK, MessageBoxImage.Error);
                                }
                            }
                            else
                            {
                                //沒有,保留原圖
                                newPatientPhotoPath = patientSettingViewModel.Patients.Patient_Photo;
                            }
                        }
                        Patients newPatient = new Patients()
                        {
                            Patient_ID       = patientSettingViewModel.Patients.Patient_ID,
                            Patient_Number   = patientSettingViewModel.Patient_Number,
                            Patient_Name     = patientSettingViewModel.Patient_Name,
                            Patient_Gender   = patientSettingViewModel.Patient_Gender,
                            Patient_Birth    = patientSettingViewModel.Patient_Birth,
                            Patient_IDNumber = patientSettingViewModel.Patient_IDNumber,
                            Patient_Photo    = newPatientPhotoPath,
                            Patient_FirstRegistrationDate = patientSettingViewModel.Patient_FirstRegistrationDate,
                            UpdateDate = DateTime.Now
                        };
                        Patients = tablePatients.UpdatePatients(newPatient);

                        //寫入分類
                        List <PatientCategoryInfo> PatientCategoryInfo = patientSettingViewModel.PatientCategoryInfo.FindAll(pci => pci.IsChecked == true);
                        tablePatientCategorys.InsertPatientsPatientCategorys(Patients, PatientCategoryInfo);

                        MessageBox.Show("修改完成", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
                        DialogResult = true;
                        Close();
                    }
                }
                else//新增
                {
                    if (MessageBox.Show("確定新增病患<" + patientSettingViewModel.Patient_Number + ">?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        string newPatientID = GetPatientID();

                        string newPatientPhotoPath = null;
                        if (!string.IsNullOrEmpty(ImportPatientPhotoPath))
                        {
                            if (PathCheck.IsFileExist(ImportPatientPhotoPath))
                            {
                                //病患大頭照路徑
                                PatientPhotoFolderInfo patientPhotoFolderInfo = PatientFolderSetting.PatientPhotoFolderSetting(Agencys, newPatientID);
                                //建立大頭照路徑
                                PathCheck.CheckPathAndCreate(patientPhotoFolderInfo.PatientPhotoFullPath);

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

                                File.Copy(ImportPatientPhotoPath, patientPhotoFolderInfo.PatientPhotoFullPath + @"\" + newFileName + extension);
                                Thread.Sleep(500);

                                newPatientPhotoPath = patientPhotoFolderInfo.PatientPhotoPath + @"\" + newFileName + extension;
                            }
                            else
                            {
                                MessageBox.Show("圖片路徑出現問題", "錯誤", MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                        }
                        DateTime nowDateTime = DateTime.Now;
                        //新增病患
                        Patients newPatient = new Patients()
                        {
                            Patient_ID       = newPatientID,
                            Patient_Number   = patientSettingViewModel.Patient_Number,
                            Patient_Name     = patientSettingViewModel.Patient_Name,
                            Patient_Gender   = patientSettingViewModel.Patient_Gender,
                            Patient_Birth    = patientSettingViewModel.Patient_Birth,
                            Patient_IDNumber = patientSettingViewModel.Patient_IDNumber,
                            Patient_Photo    = newPatientPhotoPath,
                            Patient_FirstRegistrationDate = patientSettingViewModel.Patient_FirstRegistrationDate,
                            UpdateDate = nowDateTime,
                            CreateDate = nowDateTime
                        };
                        Patients = tablePatients.InsertPatients(newPatient);
                        //寫入分類
                        //寫入分類
                        List <PatientCategoryInfo> PatientCategoryInfo = patientSettingViewModel.PatientCategoryInfo.FindAll(pci => pci.IsChecked == true);
                        if (PatientCategoryInfo.Count() > 0)
                        {
                            tablePatientCategorys.InsertPatientsPatientCategorys(Patients, PatientCategoryInfo);
                        }

                        MessageBox.Show("新增完成", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
                        DialogResult = true;
                        Close();
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLog.ErrorMessageOutput(ex.ToString());
                MessageBox.Show("儲存資料發生錯誤", "錯誤", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }