Example #1
0
        private void Button_OK_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (dde == null)
                {
                    dde = new DigiDentalEntities();
                }
                Agencys a = (from q in dde.Agencys
                             where q.Agency_Code == svm.Agencys.Agency_Code
                             select q).First();
                a.Agency_ViewType     = svm.ViewType;
                a.Agency_ImagePath    = svm.ImagePath;
                a.Agency_WifiCardPath = svm.WifiCardPath;
                a.Function_ID         = svm.StartFunction;
                dde.SaveChanges();

                Agencys      = a;
                DialogResult = true;
            }
            catch (Exception ex)
            {
                Error_Log.ErrorMessageOutput(ex.ToString());
                DialogResult = false;
            }
            Close();
        }
Example #2
0
 public DBTemplateImages()
 {
     if (dde == null)
     {
         dde = new DigiDentalEntities();
     }
 }
Example #3
0
 private void Button_PatientCategorySearchAll_Click(object sender, RoutedEventArgs e)
 {
     using (var dde = new DigiDentalEntities())
     {
         psvm.ListPatientCategories = dde.PatientCategories.ToList();
     }
 }
 /// <summary>
 /// 載入影像 全部
 /// </summary>
 private void SetImagesCollectionAll()
 {
     using (var dde = new DigiDentalEntities())
     {
         //載入Images
         //取圖片清單 Images
         var queryImages = from r in RegistrationsCollection
                           join i in dde.Images
                           on r.Registration_ID equals i.Registration_ID into ri
                           from qri in ri.DefaultIfEmpty()
                           where qri.Image_Size.Equals("Original") &&
                           qri.Image_IsEnable == true
                           select new ImageInfo()
         {
             Registration_Date = qri.Registrations.Registration_Date,
             Image_ID          = qri.Image_ID,
             Image_Path        = qri.Image_Path,
             Image_FullPath    = Agencys.Agency_ImagePath + qri.Image_Path,
             Image_FileName    = qri.Image_FileName,
             Image_Extension   = qri.Image_Extension,
             Registration_ID   = qri.Registration_ID,
             CreateDate        = qri.CreateDate
         };
         ImageInfo = new ObservableCollection <ImageInfo>(queryImages);
     }
 }
Example #5
0
 private void Button_PatientCategorySearch_Click(object sender, RoutedEventArgs e)
 {
     using (var dde = new DigiDentalEntities())
     {
         psvm.ListPatientCategories = dde.PatientCategories.Where(pc => pc.PatientCategory_Title.Contains(textPatientCategoryKeyword.Text)).ToList();
     }
 }
Example #6
0
 public DBRegistrations()
 {
     if (dde == null)
     {
         dde = new DigiDentalEntities();
     }
 }
Example #7
0
 //編輯
 public PatientViewModel(Agencys agencys, Patients patients)
 {
     Agencys         = agencys;
     Patients        = patients;
     PatientNumber   = Patients.Patient_Number;
     PatientName     = Patients.Patient_Name;
     PatientIDNumber = Patients.Patient_IDNumber;
     GenderM         = Patients.Patient_Gender;
     Birth           = Patients.Patient_Birth.Date;
     if (!string.IsNullOrEmpty(Patients.Patient_Photo))
     {
         PatientsFolder patientsFolder = new PatientsFolder(Agencys, Patients);
         if (!Directory.Exists(patientsFolder.PatientFullPatientPhotoPath))
         {
             Directory.CreateDirectory(patientsFolder.PatientFullPatientPhotoPath);
         }
         PatientPhoto = new LoadBitmapImage().SettingBitmapImage(Agencys.Agency_ImagePath + @"\" + Patients.Patient_Photo, 400);
     }
     using (var dde = new DigiDentalEntities())
     {
         var qpc = from pc in dde.PatientCategories
                   select new PatientCategoryInfo()
         {
             PatientCategory_ID    = pc.PatientCategory_ID,
             PatientCategory_Title = pc.PatientCategory_Title,
             IsChecked             = pc.Patients.Where(p => p.Patient_ID == patients.Patient_ID).Count() > 0 ? true : false
         };
         PatientCategoryInfo = qpc.ToList().FindAll(pci => pci.IsChecked == true);
     }
 }
        private void Button_Delete_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("確定刪除已選定的" + lfvm.ImageSelectedCount + "個項目?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                using (var dde = new DigiDentalEntities())
                {
                    try
                    {
                        var selectedItemID = from si in lfvm.ShowImages
                                             where si.IsSelected == true
                                             select si.Image_ID;
                        var deleteItem = (from i in dde.Images
                                          where selectedItemID.Contains(i.Image_ID)
                                          select i).ToList();
                        deleteItem.ForEach(i => i.Image_IsEnable = false);
                        dde.SaveChanges();

                        var selectedItem = from si in lfvm.ShowImages
                                           where si.IsSelected == true
                                           select si;
                        foreach (ImageInfo ii in selectedItem.ToArray())
                        {
                            lfvm.ShowImages.Remove(ii);
                        }
                        lfvm.CountImages = ShowImages.Count();
                    }
                    catch (Exception ex)
                    {
                        Error_Log.ErrorMessageOutput(ex.ToString());
                    }
                }
            }
        }
Example #9
0
        private void Button_Edit_Click(object sender, RoutedEventArgs e)
        {
            Patient patient = new Patient(Agencys, Patients);

            patient.ShowDialog();
            if (patient.DialogResult == true)
            {
                using (var dde = new DigiDentalEntities())
                {
                    Patients patients = (from p in dde.Patients
                                         where p.Patient_ID == Patients.Patient_ID
                                         select p).First();
                    Patients      = patients;
                    mwvm.Patients = patients;
                    if (!string.IsNullOrEmpty(patients.Patient_Photo))
                    {
                        mwvm.PatientPhoto = new LoadBitmapImage().SettingBitmapImage(Agencys.Agency_ImagePath + @"\" + Patients.Patient_Photo, 400);
                    }
                    else
                    {
                        mwvm.PatientPhoto = new BitmapImage(new Uri(@"/DigiDental;component/Resource/user.png", UriKind.RelativeOrAbsolute));
                    }
                    mwvm.PatientCategoryInfo = (from pc in dde.PatientCategories
                                                where pc.Patients.Any(p => p.Patient_ID == Patients.Patient_ID)
                                                select new PatientCategoryInfo()
                    {
                        PatientCategory_ID = pc.PatientCategory_ID,
                        PatientCategory_Title = pc.PatientCategory_Title,
                        IsChecked = true
                    }).ToList();
                }
            }
        }
Example #10
0
 public PatientCategoryViewModel()
 {
     if (dde == null)
     {
         dde = new DigiDentalEntities();
     }
     PatientCategories = dde.PatientCategories.ToList();
 }
Example #11
0
 public PatientSearchViewModel()
 {
     using (var dde = new DigiDentalEntities())
     {
         ListPatientCategories = dde.PatientCategories.ToList();
         ListPatients          = dde.Patients.ToList();
     }
 }
Example #12
0
        public MainWindow()
        {
            InitializeComponent();
            try
            {
                Loading Loading = new Loading();
                bool?   result  = Loading.ShowDialog();
                if ((bool)result)
                {
                    //Client 電腦名稱
                    HostName = Loading.HostName;
                    //Agencys 載入的機構設定
                    Agencys = Loading.Agencys;
                    //Patients載入的病患 或 沒有
                    Patients = Loading.Patients;

                    if (Patients != null)
                    {
                        mwvm = new MainWindowViewModel(HostName, Agencys, Patients, DateTime.Now);
                    }
                    else
                    {
                        mwvm = new MainWindowViewModel();
                    }
                    DataContext = mwvm;

                    //mwvm.SelectedDate = DateTime.Now;

                    if (dde == null)
                    {
                        dde = new DigiDentalEntities();
                    }

                    if (dbr == null)
                    {
                        dbr = new DBRegistrations();
                    }

                    if (dbi == null)
                    {
                        dbi = new DBImages();
                    }
                }
                else
                {
                    Application.Current.Shutdown();
                }
            }
            catch (Exception ex)
            {
                Error_Log.ErrorMessageOutput(ex.ToString());
                Application.Current.Shutdown();
            }
        }
Example #13
0
        private void Button_PatientCategory_Click(object sender, RoutedEventArgs e)
        {
            PatientCategories patientCategories = ((FrameworkElement)sender).DataContext as PatientCategories;

            using (var dde = new DigiDentalEntities())
            {
                psvm.ListPatients = (from pc in dde.Patients
                                     where pc.PatientCategories.Any(w => w.PatientCategory_ID == patientCategories.PatientCategory_ID)
                                     select pc).ToList();
            }
        }
 public TemplateFunctionViewModel(Agencys agencys, Patients patients, MTObservableCollection <ImageInfo> showImages)
 {
     Agencys    = agencys;
     Patients   = patients;
     ShowImages = showImages;
     using (var dde = new DigiDentalEntities())
     {
         var temp = from t in dde.Templates
                    select t;
         Templates = new ObservableCollection <Templates>(temp);
     }
 }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (dde == null)
            {
                dde = new DigiDentalEntities();
            }

            if (pcvm == null)
            {
                pcvm = new PatientCategoryViewModel();
            }
            DataContext = pcvm;
        }
Example #16
0
 private void Button_PatientSearch_Click(object sender, RoutedEventArgs e)
 {
     using (var dde = new DigiDentalEntities())
     {
         psvm.ListPatients = (from lp in dde.Patients.AsEnumerable()
                              where lp.Patient_Number.Contains(textPatientKeyword.Text) ||
                              lp.Patient_Name.Contains(textPatientKeyword.Text) ||
                              lp.Patient_IDNumber.Contains(textPatientKeyword.Text) ||
                              lp.Patient_Birth.ToString("yyyyMMdd").Contains(textPatientKeyword.Text) ||
                              lp.Patient_Birth.ToString("yyyy-MM-dd").Contains(textPatientKeyword.Text) ||
                              lp.Patient_Birth.ToString("yyyy/MM/dd").Contains(textPatientKeyword.Text)
                              select lp).ToList();
     }
 }
 public PatientCategorySettingViewModel(Patients patients)
 {
     using (var dde = new DigiDentalEntities())
     {
         var qpc = from pc in dde.PatientCategories
                   select new PatientCategoryInfo()
         {
             PatientCategory_ID    = pc.PatientCategory_ID,
             PatientCategory_Title = pc.PatientCategory_Title,
             IsChecked             = pc.Patients.Where(p => p.Patient_ID == patients.Patient_ID).Count() > 0 ? true : false
         };
         ShowPatientCategoryInfo = PatientCategoryInfo = qpc.ToList();
     }
 }
 public PatientCategorySettingViewModel()
 {
     using (var dde = new DigiDentalEntities())
     {
         var qpc = from pc in dde.PatientCategories
                   select new PatientCategoryInfo()
         {
             PatientCategory_ID    = pc.PatientCategory_ID,
             PatientCategory_Title = pc.PatientCategory_Title,
             IsChecked             = false
         };
         ShowPatientCategoryInfo = PatientCategoryInfo = qpc.ToList();
     }
 }
        private void ShowPresentation(string fileName)
        {
            if (dde == null)
            {
                dde = new DigiDentalEntities();
            }

            List <TemplateImages> liTI = new List <TemplateImages>();
            var templateImages         = from ti in dde.TemplateImages
                                         where ti.Patient_ID == Patients.Patient_ID &&
                                         ti.Template_ID == TemplateItem.Template_ID
                                         select ti;

            liTI = templateImages.ToList();

            if (liTI.Count > 0)
            {
                PowerPoint.Application pptApplication = new PowerPoint.Application();

                Slides    slides;
                _Slide    slide;
                TextRange objText;

                // Create the Presentation File
                Presentation pptPresentation = pptApplication.Presentations.Add(MsoTriState.msoTrue);

                CustomLayout customLayout = pptPresentation.SlideMaster.CustomLayouts[PpSlideLayout.ppLayoutText];

                for (int i = 0; i < liTI.Count; i++)
                {
                    // Create new Slide
                    slides = pptPresentation.Slides;
                    slide  = slides.AddSlide(i + 1, customLayout);

                    // Add title
                    objText           = slide.Shapes[1].TextFrame.TextRange;
                    objText.Text      = TemplateItem.Template_Title;
                    objText.Font.Name = "Arial";
                    objText.Font.Size = 32;

                    PowerPoint.Shape shape = slide.Shapes[2];
                    slide.Shapes.AddPicture(Agencys.Agency_ImagePath + liTI[i].Image_Path, MsoTriState.msoFalse, MsoTriState.msoTrue, shape.Left, shape.Top, shape.Width, shape.Height);

                    slide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "This document is created by DigiDental.";
                }
                pptPresentation.SaveAs(fileName, PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue);
                //pptApplication.Quit();
            }
        }
Example #20
0
        private void MenuItem_PatientCategory_Click(object sender, RoutedEventArgs e)
        {
            PatientCategory pc = new PatientCategory();

            pc.ShowDialog();
            if (Patients != null)
            {
                using (var dde = new DigiDentalEntities())
                {
                    mwvm.PatientCategoryInfo = (from pcs in dde.PatientCategories
                                                where pcs.Patients.Any(p => p.Patient_ID == Patients.Patient_ID)
                                                select new PatientCategoryInfo()
                    {
                        PatientCategory_ID = pcs.PatientCategory_ID,
                        PatientCategory_Title = pcs.PatientCategory_Title,
                        IsChecked = true
                    }).ToList();
                }
            }
        }
Example #21
0
        private string GetPatientID()
        {
            byte[] newPatientIDByte = Guid.NewGuid().ToByteArray();
            string newPatientID     = BitConverter.ToInt64(newPatientIDByte, 0).ToString();

            using (var dde = new DigiDentalEntities())
            {
                var checkUnique = from p in dde.Patients
                                  where p.Patient_ID == newPatientID
                                  select p;
                if (checkUnique.Count() > 0)
                {
                    Thread.Sleep(1000);
                    return(GetPatientID());
                }
                else
                {
                    return(newPatientID);
                }
            }
        }
        public MainWindowViewModel(string hostName, Agencys agencys, Patients patients, DateTime selectedDate)
        {
            if (dde == null)
            {
                dde = new DigiDentalEntities();
            }

            HostName = hostName;
            Agencys  = agencys;
            Patients = patients;

            //設定病患大頭貼
            if (!string.IsNullOrEmpty(Patients.Patient_Photo))
            {
                PatientPhoto = new LoadBitmapImage().SettingBitmapImage(Agencys.Agency_ImagePath + @"\" + Patients.Patient_Photo, 400);
            }

            PatientCategoryInfo = (from pc in dde.PatientCategories
                                   where pc.Patients.Any(p => p.Patient_ID == Patients.Patient_ID)
                                   select new PatientCategoryInfo()
            {
                PatientCategory_ID = pc.PatientCategory_ID,
                PatientCategory_Title = pc.PatientCategory_Title,
                IsChecked = true
            }).ToList();

            //取掛號資訊清單 Registration
            var queryRegistrations = from qr in dde.Registrations
                                     where qr.Patient_ID == Patients.Patient_ID
                                     orderby qr.Registration_Date descending
                                     select qr;

            RegistrationsCollection = new ObservableCollection <Registrations>(queryRegistrations.ToList());

            SelectedDate = selectedDate;

            LoadFunctions();
        }
        private void SetTemplateContent(Templates templateItem)
        {
            switch (templateItem.Template_UserControlName)
            {
            case "TBeforeAfter":
                //if (tBA == null)
                //{
                //    tBA = new TBeforeAfter(Agencys, Patients, templateItem, TemplateImportDate);
                //}
                tBA             = new TBeforeAfter(Agencys, Patients, templateItem, TemplateImportDate);
                TemplateContent = tBA;
                break;

            case "TIn6s":
                //if (tI6 == null)
                //{
                //    tI6 = new TIn6s(Agencys, Patients, templateItem, TemplateImportDate);
                //}
                tI6             = new TIn6s(Agencys, Patients, templateItem, TemplateImportDate);
                TemplateContent = tI6;
                break;

            case "TInOut9s":
                //if (tIO9 == null)
                //{
                //    tIO9 = new TInOut9s(Agencys, Patients, templateItem, TemplateImportDate);
                //}
                tIO9            = new TInOut9s(Agencys, Patients, templateItem, TemplateImportDate);
                TemplateContent = tIO9;
                break;

            case "TInOut10s":
                //if (tIO10 == null)
                //{
                //    tIO10 = new TInOut10s(Agencys, Patients, templateItem, TemplateImportDate);
                //}
                tIO10           = new TInOut10s(Agencys, Patients, templateItem, TemplateImportDate);
                TemplateContent = tIO10;
                break;

            case "TInOut11s":
                //if (tIO11 == null)
                //{
                //    tIO11 = new TInOut11s(Agencys, Patients, templateItem, TemplateImportDate);
                //}
                tIO11           = new TInOut11s(Agencys, Patients, templateItem, TemplateImportDate);
                TemplateContent = tIO11;
                break;

            case "TXRay6s":
                //if (tXR6 == null)
                //{
                //    tXR6 = new TXRay6s(Agencys, Patients, templateItem, TemplateImportDate);
                //}
                tXR6            = new TXRay6s(Agencys, Patients, templateItem, TemplateImportDate);
                TemplateContent = tXR6;
                break;

            case "TXRay19s":
                //if (tXR19 == null)
                //{
                //    tXR19 = new TXRay19s(Agencys, Patients, templateItem, TemplateImportDate);
                //}
                tXR19           = new TXRay19s(Agencys, Patients, templateItem, TemplateImportDate);
                TemplateContent = tXR19;
                break;

            case "TPlasterModel5s":
                //if (tPM15 == null)
                //{
                //    tPM15 = new TPlasterModel5s(Agencys, Patients, templateItem, TemplateImportDate);
                //}
                tPM15           = new TPlasterModel5s(Agencys, Patients, templateItem, TemplateImportDate);
                TemplateContent = tPM15;
                break;

            case "TFdi52s":
                //if (tF52 == null)
                //{
                //    tF52 = new TFdi52s(Agencys, Patients, templateItem, TemplateImportDate);
                //}
                tF52            = new TFdi52s(Agencys, Patients, templateItem, TemplateImportDate);
                TemplateContent = tF52;
                break;

            case "TOthers1s":
                //if (tO1 == null)
                //{
                //    tO1 = new TOthers1s(Agencys, Patients, templateItem, TemplateImportDate);
                //}
                tO1             = new TOthers1s(Agencys, Patients, templateItem, TemplateImportDate);
                TemplateContent = tO1;
                break;
            }
            using (var dde = new DigiDentalEntities())
            {
                var queryImportDate = from ti in dde.TemplateImages
                                      where ti.Patient_ID == Patients.Patient_ID &&
                                      ti.Template_ID == TemplateItem.Template_ID
                                      group ti by ti.TemplateImage_ImportDate into tt
                                      select tt.Key.ToString();

                ImportDateCollect = queryImportDate.ToList();
                //ImportDateCollect = new ObservableCollection<string>(queryImportDate);
            }
        }
Example #24
0
 private void Button_Save_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (Patients != null)//編輯
         {
             if (MessageBox.Show("確定修改病患資料<" + pvm.PatientNumber + ">?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
             {
                 using (var dde = new DigiDentalEntities())
                 {
                     DateTime updateTime = DateTime.Now;
                     Patients patients   = (from p in dde.Patients
                                            where p.Patient_ID == Patients.Patient_ID
                                            select p).First();
                     patients.Patient_Number   = pvm.PatientNumber;
                     patients.Patient_Name     = pvm.PatientName;
                     patients.Patient_IDNumber = pvm.PatientIDNumber;
                     patients.Patient_Birth    = pvm.Birth;
                     patients.Patient_Gender   = pvm.GenderM;
                     patients.UpdateDate       = updateTime;
                     if (IsRemove)
                     {
                         patients.Patient_Photo = null;
                     }
                     else
                     {
                         if (!string.IsNullOrEmpty(ImportPatientPhotoPath))
                         {
                             PatientsFolder pf = new PatientsFolder(Agencys, patients);
                             if (!Directory.Exists(pf.PatientFullPatientPhotoPath))
                             {
                                 Directory.CreateDirectory(pf.PatientFullPatientPhotoPath);
                             }
                             string extension   = Path.GetExtension(ImportPatientPhotoPath).ToUpper();
                             string newFileName = DateTime.Now.ToString("yyyyMMddHHmmssffff");
                             File.Copy(ImportPatientPhotoPath, pf.PatientFullPatientPhotoPath + @"\" + newFileName + extension);
                             patients.Patient_Photo = pf.PatientPhotoPath + @"\" + newFileName + extension;
                         }
                     }
                     //寫入分類
                     List <PatientCategories>   PatientCategories   = dde.PatientCategories.ToList();
                     List <PatientCategoryInfo> PatientCategoryInfo = pvm.PatientCategoryInfo.FindAll(pci => pci.IsChecked == true);
                     foreach (PatientCategories pc in PatientCategories)
                     {
                         var queryCheck = PatientCategoryInfo.FindAll(pci => pci.PatientCategory_ID == pc.PatientCategory_ID);
                         if (queryCheck.Count() > 0)
                         {
                             patients.PatientCategories.Remove(pc);
                             patients.PatientCategories.Add(pc);
                         }
                         else
                         {
                             patients.PatientCategories.Remove(pc);
                         }
                     }
                     dde.SaveChanges();
                     MessageBox.Show("修改完成", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
                     DialogResult = true;
                     Close();
                 }
             }
         }
         else//新增
         {
             if (MessageBox.Show("確定新增病患<" + pvm.PatientNumber + ">?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
             {
                 using (var dde = new DigiDentalEntities())
                 {
                     string   newPatientID   = GetPatientID();
                     DateTime newPatientDate = DateTime.Now;
                     //新增病患
                     Patients patients = new Patients()
                     {
                         Patient_ID       = newPatientID,
                         Patient_Number   = pvm.PatientNumber,
                         Patient_Name     = pvm.PatientName,
                         Patient_IDNumber = pvm.PatientIDNumber,
                         Patient_Birth    = pvm.Birth,
                         Patient_Gender   = pvm.GenderM,
                         CreateDate       = newPatientDate,
                         UpdateDate       = newPatientDate
                     };
                     if (!string.IsNullOrEmpty(ImportPatientPhotoPath))
                     {
                         PatientsFolder pf = new PatientsFolder(Agencys, patients);
                         if (!Directory.Exists(pf.PatientFullPatientPhotoPath))
                         {
                             Directory.CreateDirectory(pf.PatientFullPatientPhotoPath);
                         }
                         string extension   = Path.GetExtension(ImportPatientPhotoPath).ToUpper();
                         string newFileName = DateTime.Now.ToString("yyyyMMddHHmmssffff");
                         File.Copy(ImportPatientPhotoPath, pf.PatientFullPatientPhotoPath + @"\" + newFileName + extension);
                         patients.Patient_Photo = pf.PatientPhotoPath + @"\" + newFileName + extension;
                     }
                     //寫入分類
                     if (pvm.PatientCategoryInfo != null)
                     {
                         List <PatientCategoryInfo> PatientCategoryInfo = pvm.PatientCategoryInfo.FindAll(pcs => pcs.IsChecked == true);
                         foreach (PatientCategoryInfo pci in PatientCategoryInfo)
                         {
                             PatientCategories patientCategories = (from pc in dde.PatientCategories
                                                                    where pc.PatientCategory_ID == pci.PatientCategory_ID
                                                                    select pc).First();
                             patients.PatientCategories.Add(patientCategories);
                         }
                     }
                     dde.Patients.Add(patients);
                     dde.SaveChanges();
                     MessageBox.Show("新增完成", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
                     Close();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Error_Log.ErrorMessageOutput(ex.ToString());
     }
 }
Example #25
0
        private void Window_ContentRendered(object sender, EventArgs e)
        {
            try
            {
                Status.Text = "伺服器位置確認中...";
                Status.Refresh();

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

                Status.Text = "嘗試連接伺服器...";
                Status.Refresh();

                //連接Server connection
                if (new ConnectionString().CheckConnection())
                {
                    dde = new DigiDentalEntities();

                    Status.Text = "取得本機資訊...";
                    Status.Refresh();

                    //取得本機訊息
                    //HostName IP
                    string LocalIP = string.Empty;
                    HostName = Dns.GetHostName();
                    IPHostEntry ipHostEntry = Dns.GetHostEntry(HostName);
                    foreach (IPAddress ip in ipHostEntry.AddressList)
                    {
                        if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                        {
                            LocalIP = ip.ToString();
                        }
                    }

                    Status.Text = "確認本機註冊資訊...";
                    Status.Refresh();

                    //判斷client 有無資料
                    var isExistClient = from iec in dde.Clients
                                        where iec.Client_HostName == HostName
                                        select iec;
                    string VerificationCodeClient = string.Empty;
                    if (isExistClient.Count() > 0)//已註冊//判斷VerificationCode 與Server的狀態
                    {
                        Status.Text = "本機已註冊...";
                        Status.Refresh();

                        VerificationCodeClient = isExistClient.First().Agency_VerificationCode;
                    }
                    else//第一次使用,輸入驗證碼
                    {
                        Status.Text = "本機尚未註冊...";
                        Status.Refresh();

                        InputDialog idVerify = new InputDialog("此台電腦為第一次登入,請輸入產品驗證碼:", "Verify");
                        if (idVerify.ShowDialog() == true)
                        {
                            VerificationCodeClient = idVerify.Answer;
                            dde.Clients.Add(new Clients
                            {
                                Client_HostName         = HostName,
                                Client_IP               = LocalIP,
                                Client_IsVerify         = true,
                                Agency_VerificationCode = VerificationCodeClient
                            });
                            dde.SaveChanges();
                        }
                    }

                    Status.Text = "取得伺服器認證資訊...";
                    Status.Refresh();

                    //用驗證碼(VerificationCodeClient)與Agencys確認目前狀態
                    var checkAgencyStatus = from cas in dde.Agencys
                                            where cas.Agency_VerificationCode == VerificationCodeClient
                                            select cas;
                    if (checkAgencyStatus.Count() > 0)
                    {
                        Agencys = checkAgencyStatus.First();
                        bool?IsVerify = Agencys.Agency_IsVerify;
                        bool?IsTry    = Agencys.Agency_IsTry;
                        if ((bool)IsVerify)
                        {
                            if ((bool)IsTry)
                            {
                                if (Agencys.Agency_TrialPeriod < DateTime.Now.Date)
                                {
                                    MessageBoxTips = "試用期限已到,請聯絡資訊廠商";
                                }
                                else
                                {
                                    MessageBoxStatus = true;
                                    MessageBoxTips   = "此為試用版本,試用日期至" + ((DateTime)Agencys.Agency_TrialPeriod).ToShortDateString();

                                    Status.Text = "病患資訊確認中...";
                                    Status.Refresh();

                                    //判斷病患
                                    addNewPatient();

                                    ReturnDialogResult = true;
                                }
                            }
                            else
                            {
                                Status.Text = "病患資訊確認中...";
                                Status.Refresh();

                                //判斷此病患
                                addNewPatient();

                                ReturnDialogResult = true;
                            }
                        }
                        else
                        {
                            MessageBoxTips = "此驗證碼已停用,如欲使用請聯絡資訊廠商";
                        }
                    }
                    else
                    {
                        MessageBoxTips = "伺服器尚未建立認證";
                    }
                    //寫入ConnectingLog資訊
                    addConnectingLog(HostName, LocalIP, MessageBoxTips, ReturnDialogResult);
                }
                else
                {
                    MessageBoxTips = "伺服器連接失敗";
                    ConfigManage.AddUpdateAppCongig("Server", "");
                }

                //show MessageBox
                if (ReturnDialogResult)
                {
                    Status.Text = "成功登入,歡迎使用DigiDental...";
                    Status.Refresh();

                    if (MessageBoxStatus)//還在試用期內可以使用
                    {
                        MessageBox.Show(MessageBoxTips, "提示", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
                else
                {
                    Status.Text = "登入失敗,原因:" + MessageBoxTips;
                    Status.Refresh();
                    MessageBox.Show(MessageBoxTips, "提示", MessageBoxButton.OK, MessageBoxImage.Stop);
                }
                Thread.Sleep(1000);
                //回傳結果
                DialogResult = ReturnDialogResult;
            }
            catch (Exception ex)
            {
                Error_Log.ErrorMessageOutput(ex.ToString());
                DialogResult = ReturnDialogResult;
            }
            Thread.Sleep(1000);
            Close();
        }