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);
            }
        }