private void DataGrid_Update_CellEditEnding(object sender, System.Windows.Controls.DataGridCellEditEndingEventArgs e)
 {
     try
     {
         string            editTex           = ((TextBox)e.EditingElement).Text;
         PatientCategories patientCategories = ((FrameworkElement)e.Row).DataContext as PatientCategories;
         if (!patientCategories.PatientCategory_Title.Equals(editTex))
         {
             if (MessageBox.Show("確定將<" + patientCategories.PatientCategory_Title + ">修改為<" + editTex + ">?\r\n如果是的話,所有擁有此分類的病患分類也會被更動", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
             {
                 PatientCategories updateItem = (from pc in dde.PatientCategories
                                                 where pc.PatientCategory_ID == patientCategories.PatientCategory_ID
                                                 select pc).First();
                 updateItem.PatientCategory_Title = editTex;
                 dde.SaveChanges();
             }
             else
             {
                 pcvm.PatientCategories = dde.PatientCategories.ToList();
             }
         }
     }
     catch (Exception ex)
     {
         Error_Log.ErrorMessageOutput(ex.ToString());
     }
 }
Exemple #2
0
        private void Button_Save_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                switch (ImageInfo.Image_Extension.ToUpper())
                {
                case ".JPG":
                case ".JPEG":
                    JpegBitmapEncoder jbe = new JpegBitmapEncoder();
                    ImageProcess.SaveUsingEncoder(BitmapSource, ImageInfo.Image_FullPath, jbe);
                    break;

                case ".PNG":
                    PngBitmapEncoder pbe = new PngBitmapEncoder();
                    ImageProcess.SaveUsingEncoder(BitmapSource, ImageInfo.Image_FullPath, pbe);
                    break;

                case ".GIF":
                    GifBitmapEncoder gbe = new GifBitmapEncoder();
                    ImageProcess.SaveUsingEncoder(BitmapSource, ImageInfo.Image_FullPath, gbe);
                    break;
                }
                MessageBox.Show("儲存成功", "提示", MessageBoxButton.OK);
            }
            catch (Exception ex)
            {
                Error_Log.ErrorMessageOutput(ex.ToString());
                MessageBox.Show("寫入失敗", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemple #3
0
        //Handle the Internal Exceptions, Log them and Redirect the user to Difertent URL
        void Application_Error(object sender, EventArgs e)
        {
            Exception     excep            = Server.GetLastError();
            HttpException lastErrorWrapper = Server.GetLastError() as HttpException;

            Exception lastError = lastErrorWrapper;

            if (lastErrorWrapper.InnerException != null)
            {
                lastError = lastErrorWrapper.InnerException;
            }

            string lastErrorTypeName   = lastError.GetType().ToString();
            string lastErrorMessage    = lastError.Message;
            string lastErrorStackTrace = lastError.StackTrace;

            //Log  the Error in Data Store
            Error_Log log           = new Error_Log();
            String    strConnString = ConfigurationManager.ConnectionStrings["ConnStringDeltoneCRM"].ConnectionString;

            log.Log_Error(lastErrorTypeName, lastErrorMessage, lastErrorStackTrace, DateTime.Now, strConnString);
            var _logger1 = LogManager.GetLogger(typeof(Global));

            _logger1.Error("Application error :" + excep);

            //Server.Transfer("~/Error/ErrorPage.aspx");
            //Response.Redirect("~/Error/ErrorPage.aspx"); //Redirect the page the Custom Error Page
        }
Exemple #4
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();
        }
        public void LogException(Exception e, string extraInfo = null)
        {
            SecurityAgencyEntities context = new SecurityAgencyEntities();

            Error_Log obj = new Error_Log();

            obj.Message = e.Message;

            if (!string.IsNullOrEmpty(extraInfo))
            {
                obj.Message = obj.Message + "<br/> Extar Info :" + extraInfo;
            }

            obj.Source          = e.Source;
            obj.StackTrace      = e.StackTrace;
            obj.TargetSite      = e.TargetSite.ToString();
            obj.ErrorDate       = DateTime.Now;
            obj.ExceptionDetail = e.ToString();

            DateTime dt = (DateTime)obj.ErrorDate;


            context.Error_Log.Add(obj);
            try
            {
                context.SaveChanges();
            }
            catch
            {
            }
        }
        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());
                    }
                }
            }
        }
        private void Button_Save_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("確定完成旋轉並儲存?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Information) == MessageBoxResult.OK)
            {
                try
                {
                    double ratio = heightRatio == 0 ? widthRatio : heightRatio;

                    double oriWidth  = rect2WAndH[0] / ratio;
                    double oriHeight = rect2WAndH[1] / ratio;

                    double sourceCenX = bi.PixelWidth / 2;
                    double sourceCenY = bi.PixelHeight / 2;

                    double oriStartX = sourceCenX - (oriWidth / 2);
                    double oriStartY = sourceCenY - (oriHeight / 2);

                    RotateAndSaveImage(bi, rotateAngle, (int)oriStartX, (int)oriStartY, (int)oriWidth, (int)oriHeight, ImageInfo.Image_FullPath);
                    MessageBox.Show("儲存成功", "提示", MessageBoxButton.OK);

                    Cvs.Children.Clear();
                    SetImageDefault(ImageInfo);
                }
                catch (Exception ex)
                {
                    Error_Log.ErrorMessageOutput(ex.ToString());
                }
            }
        }
 private void Button_SearchAll_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         pcsvm.ShowPatientCategoryInfo = PatientCategoryInfo;
     }
     catch (Exception ex)
     {
         Error_Log.ErrorMessageOutput(ex.ToString());
     }
 }
        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();
            }
        }
 private void Button_Search_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         pcsvm.ShowPatientCategoryInfo = PatientCategoryInfo.Where(w => w.PatientCategory_Title.Contains(textBoxCategoryInput.Text)).ToList();
     }
     catch (Exception ex)
     {
         Error_Log.ErrorMessageOutput(ex.ToString());
     }
 }
Exemple #11
0
 private void Button_PatientCategoryRemove_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         //取出選定的分類
         PatientCategoryInfo patientCategoryInfo = ((FrameworkElement)e.Source).DataContext as PatientCategoryInfo;
         patientCategoryInfo.IsChecked = false;
         pvm.PatientCategoryInfo       = pvm.PatientCategoryInfo.FindAll(spcs => spcs.IsChecked == true);
     }
     catch (Exception ex)
     {
         Error_Log.ErrorMessageOutput(ex.ToString());
     }
 }
        private void Image_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            try
            {
                ImageInfo  dragImage = (ImageInfo)((Image)e.Source).DataContext;
                DataObject data      = new DataObject(DataFormats.Text, dragImage);

                DragDrop.DoDragDrop((DependencyObject)e.Source, data, DragDropEffects.Copy);
            }
            catch (Exception ex)
            {
                Error_Log.ErrorMessageOutput(ex.ToString());
                MessageBox.Show("移動圖片發生錯誤,聯絡資訊人員", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemple #13
0
 protected override void OnStartup(StartupEventArgs e)
 {
     try
     {
         if (e.Args.Length > 0)
         {
             p.Patient_ID       = !string.IsNullOrEmpty(e.Args[0].ToString()) ? e.Args[0].ToString() : string.Empty;
             p.Patient_Number   = !string.IsNullOrEmpty(e.Args[1].ToString()) ? e.Args[1].ToString() : string.Empty;
             p.Patient_Name     = !string.IsNullOrEmpty(e.Args[2].ToString()) ? e.Args[2].ToString() : string.Empty;
             p.Patient_Gender   = TransGender(e.Args[3].ToString());
             p.Patient_Birth    = DateTime.TryParse(e.Args[4].ToString(), out DateTime patientBirth) ? DateTime.Parse(e.Args[4].ToString()) : default(DateTime);
             p.Patient_IDNumber = !string.IsNullOrEmpty(e.Args[5].ToString()) ? e.Args[5].ToString() : string.Empty;
         }
         else
         {
             //測試資料
             //1. Patient = null
             p = new Patients();
             //2.Patient Testing
             //p = new Patients()
             //{
             //    Patient_ID = "0001",
             //    Patient_Number = "E0001",
             //    Patient_Name = "Eason",
             //    Patient_Gender = true,
             //    Patient_Birth = DateTime.Parse("1986-08-11"),
             //    Patient_IDNumber = "W100399932"
             //};
             //3. Patient 2 Testing
             //p = new Patients()
             //{
             //    Patient_ID = "0005",
             //    Patient_Number = "0005J",
             //    Patient_Name = "JOE",
             //    Patient_Gender = false,
             //    Patient_Birth = DateTime.Parse("1984-11-27"),
             //    Patient_IDNumber = "W100339105"
             //};
         }
         base.OnStartup(e);
     }
     catch (Exception ex)
     {
         Error_Log.ErrorMessageOutput(ex.ToString());
         MessageBox.Show("帶入的參數有誤,DigiDental無法啟動", "警告", MessageBoxButton.OK, MessageBoxImage.Error);
         Current.Shutdown();
     }
 }
 /// <summary>
 /// 判斷是否能連線
 /// </summary>
 /// <returns></returns>
 public bool CheckConnection()
 {
     try
     {
         using (EntityConnection conn = new EntityConnection(EFConnectionString()))
         {
             conn.Open();
             conn.Close();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Error_Log.ErrorMessageOutput(ex.ToString());
         return(false);
     }
 }
 private void Button_CategoryAdd_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         var pc = new PatientCategories()
         {
             PatientCategory_Title = textBoxCategoryInput.Text
         };
         dde.PatientCategories.Add(pc);
         dde.SaveChanges();
         pcvm.PatientCategories    = dde.PatientCategories.ToList();
         textBoxCategoryInput.Text = string.Empty;
     }
     catch (Exception ex)
     {
         Error_Log.ErrorMessageOutput(ex.ToString());
     }
 }
 private void Button_CategoryDelete_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         PatientCategories patientCategories = ((FrameworkElement)sender).DataContext as PatientCategories;
         if (MessageBox.Show("確定刪除<" + patientCategories.PatientCategory_Title + ">分類?\r\n如果是的話,所有擁有此分類的病患分類也會被取消", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
         {
             var deleteItem = dde.PatientCategories.Where(w => w.PatientCategory_ID == patientCategories.PatientCategory_ID).First();
             deleteItem.Patients.Remove(new Patients());
             dde.PatientCategories.Remove(deleteItem);
             dde.SaveChanges();
             pcvm.PatientCategories = dde.PatientCategories.ToList();
         }
     }
     catch (Exception ex)
     {
         Error_Log.ErrorMessageOutput(ex.ToString());
     }
 }
        private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            try
            {
                rotateAngle = e.NewValue;

                if (rotateAngle != 0)
                {
                    ButtonSave.IsEnabled = true;
                    ButtonUndo.IsEnabled = true;
                }

                rtf       = new RotateTransform();
                rtf.Angle = rotateAngle;
                ImageRotated.RenderTransformOrigin = new Point(0.5, 0.5);
                ImageRotated.RenderTransform       = rtf;

                imageCenterX = Cvs.ActualWidth / 2;
                imageCenterY = Cvs.ActualHeight / 2;

                rect2WAndH = GetLargestRectangle(ImageRotated.Width, ImageRotated.Height, rotateAngle);

                double halfWidth  = rect2WAndH[0] / 2;
                double halfHeight = rect2WAndH[1] / 2;

                rect2StartX = imageCenterX - halfWidth;
                rect2StartY = imageCenterY - halfHeight;

                //XOR的區域
                rect2 = new Rect(rect2StartX, rect2StartY, rect2WAndH[0], rect2WAndH[1]);
                //CombinedGeometry.Geometry2 Setting
                rectangleGeometry2 = new RectangleGeometry(rect2);
                //Path 的 CombinedGeometry
                combinedGeometry.Geometry2 = rectangleGeometry2;
                path.Data = combinedGeometry;
            }
            catch (Exception ex)
            {
                Error_Log.ErrorMessageOutput(ex.ToString());
            }
        }
Exemple #18
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));

                LoadBitmapImage lbi = new LoadBitmapImage();
                img.Source = lbi.SettingBitmapImage(dragImage.Image_FullPath, TemplateImagePixelWidth);

                //BEFORE TemplateImage_Number = 0
                dbTI.InsertOrUpdateImage(Patients, Templates, TemplateImportDate, dragImage.Image_ID, dragImage.Image_Path, img.Uid);
            }
            catch (Exception ex)
            {
                Error_Log.ErrorMessageOutput(ex.ToString());
                MessageBox.Show("移動圖片發生錯誤,聯絡資訊人員", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemple #19
0
        private void Button_SaveAs_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.DefaultExt = ".png";
                sfd.Filter     = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif";
                if (sfd.ShowDialog() == true)
                {
                    string extension = sfd.SafeFileName.Substring(sfd.SafeFileName.IndexOf('.'), (sfd.SafeFileName.Length - sfd.SafeFileName.IndexOf('.')));

                    switch (extension.ToUpper())
                    {
                    case ".JPG":
                    case ".JPEG":
                        JpegBitmapEncoder jbe = new JpegBitmapEncoder();
                        ImageProcess.SaveUsingEncoder(BitmapSource, sfd.FileName, jbe);
                        break;

                    case ".PNG":
                        PngBitmapEncoder pbe = new PngBitmapEncoder();
                        ImageProcess.SaveUsingEncoder(BitmapSource, sfd.FileName, pbe);
                        break;

                    case ".GIF":
                        GifBitmapEncoder gbe = new GifBitmapEncoder();
                        ImageProcess.SaveUsingEncoder(BitmapSource, sfd.FileName, gbe);
                        break;
                    }

                    MessageBox.Show("檔案建立成功,存放位置於" + sfd.FileName, "提示", MessageBoxButton.OK);
                }
            }
            catch (Exception ex)
            {
                Error_Log.ErrorMessageOutput(ex.ToString());
                MessageBox.Show("寫入失敗", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void Image_Drop(object sender, DragEventArgs e)
        {
            try
            {
                Image img = e.Source as Image;

                ImageInfo dragImage = new ImageInfo();
                dragImage = ((ImageInfo)e.Data.GetData(DataFormats.Text));

                pf = new PatientsFolder(Agencys, Patients);
                if (!Directory.Exists(pf.PatientFullPatientPhotoPath))
                {
                    Directory.CreateDirectory(pf.PatientFullPatientPhotoPath);
                }
                string newPatientPhotoName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + dragImage.Image_Extension;
                string newPatientPhotoPath = pf.PatientFullPatientPhotoPath + @"\" + newPatientPhotoName;
                File.Copy(dragImage.Image_FullPath, newPatientPhotoPath);
                Thread.Sleep(200);

                mwvm.PatientPhoto = new LoadBitmapImage().SettingBitmapImage(newPatientPhotoPath, 400);

                //update database Patients Patient_Photo
                Patients patients = (from q in dde.Patients
                                     where q.Patient_ID == Patients.Patient_ID
                                     select q).First();
                patients.Patient_Photo = pf.PatientPhotoPath + @"\" + newPatientPhotoName;
                patients.UpdateDate    = DateTime.Now;
                dde.SaveChanges();

                Patients      = patients;
                mwvm.Patients = patients;
            }
            catch (Exception ex)
            {
                Error_Log.ErrorMessageOutput(ex.ToString());
                MessageBox.Show("移動圖片發生錯誤,聯絡資訊人員", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemple #21
0
        private void Button_Sure_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("確定完成裁切並儲存?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Information) == MessageBoxResult.OK)
            {
                try
                {
                    switch (ImageInfo.Image_Extension.ToUpper())
                    {
                    case ".JPG":
                    case ".JPEG":
                        JpegBitmapEncoder jbe = new JpegBitmapEncoder();
                        ImageProcess.SaveUsingEncoder((BitmapSource)image.Source, ImageInfo.Image_FullPath, jbe);
                        break;

                    case ".PNG":
                        PngBitmapEncoder pbe = new PngBitmapEncoder();
                        ImageProcess.SaveUsingEncoder((BitmapSource)image.Source, ImageInfo.Image_FullPath, pbe);
                        break;

                    case ".GIF":
                        GifBitmapEncoder gbe = new GifBitmapEncoder();
                        ImageProcess.SaveUsingEncoder((BitmapSource)image.Source, ImageInfo.Image_FullPath, gbe);
                        break;
                    }
                    //編輯過 可以復原
                    buttonUndo.IsEnabled = false;
                    //未執行過編輯 不可以儲存
                    buttonSure.IsEnabled = false;
                    MessageBox.Show("儲存成功", "提示", MessageBoxButton.OK);
                }
                catch (Exception ex)
                {
                    Error_Log.ErrorMessageOutput(ex.ToString());
                    MessageBox.Show("寫入失敗", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
        public void RotateAndSaveImage(BitmapImage sourceImage, double angle,
                                       int startX, int startY, int width, int height,
                                       string filePath)
        {
            try
            {
                TransformGroup  transformGroup  = new TransformGroup();
                RotateTransform rotateTransform = new RotateTransform(angle);
                rotateTransform.CenterX = sourceImage.PixelWidth / 2.0;
                rotateTransform.CenterY = sourceImage.PixelHeight / 2.0;
                transformGroup.Children.Add(rotateTransform);
                TranslateTransform translateTransform = new TranslateTransform();
                translateTransform.X = -startX;
                translateTransform.Y = -startY;
                transformGroup.Children.Add(translateTransform);

                DrawingVisual  vis  = new DrawingVisual();
                DrawingContext cont = vis.RenderOpen();
                cont.PushTransform(transformGroup);
                cont.DrawImage(sourceImage, new Rect(new Size(sourceImage.PixelWidth, sourceImage.PixelHeight)));
                cont.Close();

                RenderTargetBitmap rtb = new RenderTargetBitmap(width, height, 96d, 96d, PixelFormats.Default);
                rtb.Render(vis);

                System.IO.FileStream stream  = new System.IO.FileStream(filePath, System.IO.FileMode.Create);
                PngBitmapEncoder     encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(rtb));
                encoder.Save(stream);
                stream.Close();
            }
            catch (Exception ex)
            {
                Error_Log.ErrorMessageOutput(ex.ToString());
            }
        }
Exemple #23
0
 private void Button_PatientCategorySetting_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         PatientCategorySetting patientCategorySetting;
         if (Patients != null)//編輯
         {
             patientCategorySetting = new PatientCategorySetting(Patients);
         }
         else//新增
         {
             patientCategorySetting = new PatientCategorySetting();
         }
         patientCategorySetting.ShowDialog();
         if (patientCategorySetting.DialogResult == true)
         {
             pvm.PatientCategoryInfo = patientCategorySetting.PatientCategoryInfo.FindAll(pcs => pcs.IsChecked == true);
         }
     }
     catch (Exception ex)
     {
         Error_Log.ErrorMessageOutput(ex.ToString());
     }
 }
        private void Button_PhotoEditor_Click(object sender, RoutedEventArgs e)
        {
            if (lfvm.ShowImages.Count() > 0)
            {
                PhotoEditor pe;
                if (lfvm.ShowImages.Where(i => i.IsSelected).Count() > 0)
                {
                    pe = new PhotoEditor(new ObservableCollection <ImageInfo>(lfvm.ShowImages.Where(i => i.IsSelected).OrderBy(o => o.Registration_Date).OrderBy(o2 => o2.Image_ID)));
                }
                else
                {
                    pe = new PhotoEditor(new ObservableCollection <ImageInfo>(lfvm.ShowImages.OrderBy(o => o.Registration_Date).OrderBy(o2 => o2.Image_ID)));
                }
                if (pe.ShowDialog() == true)
                {
                    try
                    {
                        pd = new ProgressDialog();

                        pd.Dispatcher.Invoke(() =>
                        {
                            pd.PText    = "圖片載入中( 0 / " + lfvm.ShowImages.Count() + " )";
                            pd.PMinimum = 0;
                            pd.PValue   = 0;
                            pd.PMaximum = lfvm.ShowImages.Count();
                            pd.Show();
                        });

                        //multi - thread
                        Task t = Task.Factory.StartNew(() =>
                        {
                            Parallel.ForEach(lfvm.ShowImages, imgs =>
                            {
                                BitmapImage bi = new BitmapImage();

                                if (File.Exists(imgs.Image_FullPath))
                                {
                                    FileStream fs = new FileStream(imgs.Image_FullPath, FileMode.Open);
                                    bi.BeginInit();
                                    bi.StreamSource     = fs;
                                    bi.DecodePixelWidth = 800;
                                    bi.CacheOption      = BitmapCacheOption.OnLoad;
                                    bi.EndInit();
                                    bi.Freeze();
                                    fs.Close();
                                }
                                imgs.BitmapImageSet = bi;

                                pd.Dispatcher.Invoke(() =>
                                {
                                    pd.PValue++;
                                    pd.PText = "圖片載入中( " + pd.PValue + " / " + lfvm.ShowImages.Count() + " )";
                                });
                            });
                        }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).ContinueWith(cw =>
                        {
                            pd.Dispatcher.Invoke(() =>
                            {
                                pd.PText = "載入完成";
                                pd.Close();
                            });
                            GC.Collect();
                        });
                    }
                    catch (Exception ex)
                    {
                        Error_Log.ErrorMessageOutput(ex.ToString());
                    }
                }
                lbImages.UnselectAll();
            }
            else
            {
                MessageBox.Show("尚未載入圖片", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
Exemple #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();
        }
Exemple #26
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());
     }
 }
Exemple #27
0
        private void SettingImage(BitmapSource bs)
        {
            try
            {
                image = new Image()
                {
                    Source = bs
                };

                //Control Image (X,Y)
                double imageStartX = 0;
                double imageStartY = 0;

                if (bi.PixelHeight < Cvs.ActualHeight && bi.PixelWidth < Cvs.ActualWidth)
                {
                    heightRatio     = 1;
                    widthRatio      = 1;
                    image.MaxHeight = bi.PixelHeight;
                    image.Height    = image.MaxHeight;
                    image.MaxWidth  = bi.PixelWidth;
                    image.Width     = image.MaxWidth;
                    imageStartX     = (Cvs.ActualWidth - bi.PixelWidth) / 2;
                    imageStartY     = (Cvs.ActualHeight - bi.PixelHeight) / 2;
                }
                else
                {
                    //Canvas 的寬高關係
                    if (Cvs.ActualWidth > Cvs.ActualHeight)
                    {
                        //高的比例
                        heightRatio = Cvs.ActualHeight / bs.PixelHeight;
                        //高填滿
                        image.MaxHeight = Cvs.ActualHeight;
                        image.Height    = image.MaxHeight;
                        //計算寬比例
                        image.Width = bs.PixelWidth * heightRatio;

                        //如果圖片是橫的 但是寬度超過CVS
                        if (image.Width > Cvs.ActualWidth)
                        {
                            widthRatio     = Cvs.ActualWidth / bs.PixelWidth;
                            image.MaxWidth = Cvs.ActualWidth;
                            image.Width    = image.MaxWidth;
                            image.Height   = bs.PixelHeight * widthRatio;

                            //Image 起始座標 高度置中
                            imageStartX = 0;
                            imageStartY = (Cvs.ActualHeight - image.Height) / 2;
                        }
                        else
                        {
                            //Image 起始座標 寬度置中
                            imageStartX = (Cvs.ActualWidth - image.Width) / 2;
                            imageStartY = 0;
                        }
                    }
                    else
                    {
                        //寬的比例
                        widthRatio = Cvs.ActualWidth / bs.PixelWidth;
                        //寬填滿
                        image.MaxWidth = Cvs.ActualWidth;
                        image.Width    = ActualWidth;
                        //計算高比例
                        image.Height = bs.PixelHeight * widthRatio;
                        if (image.Height > Cvs.ActualHeight)
                        {
                            heightRatio     = Cvs.ActualHeight / bs.PixelHeight;
                            image.MaxHeight = Cvs.ActualHeight;
                            image.Height    = image.MaxHeight;
                            image.Width     = bs.PixelWidth * heightRatio;

                            //Image 起始座標 寬度置中
                            imageStartX = (Cvs.ActualWidth - image.Width) / 2;
                            imageStartY = 0;
                        }
                        else
                        {
                            //Image 起始座標 高度置中
                            imageStartX = 0;
                            imageStartY = (Cvs.ActualHeight - image.Height) / 2;
                        }
                    }
                }
                //圖片的起始(x1,y1)與結束(x2,y2)
                ImageStartPoint = new Point(imageStartX, imageStartY);
                ImageEndPoint   = new Point(imageStartX + image.Width, imageStartY + image.Height);

                Cvs.Children.Add(image);
                Canvas.SetTop(image, imageStartY);
                Canvas.SetLeft(image, imageStartX);

                //CombinedGeometry.Geometry1 Setting
                //包圍Image的Rect(反灰)
                RectangleGeometry rectangleGeometry = new RectangleGeometry(new Rect(imageStartX, imageStartY, image.Width, image.Height));

                //Path 的 CombinedGeometry
                combinedGeometry = new CombinedGeometry()
                {
                    GeometryCombineMode = GeometryCombineMode.Xor,
                    Geometry1           = rectangleGeometry
                };

                //建立Rect 覆蓋Image
                path = new Path
                {
                    Fill = (Brush)(new BrushConverter().ConvertFromString("#AAFFFFFF")),
                    Data = combinedGeometry
                };
                Cvs.Children.Add(path);
            }
            catch (Exception ex)
            {
                Error_Log.ErrorMessageOutput(ex.ToString());
            }
        }
        public void ShowTemplateImage(Agencys agencys, Patients patients, Templates templates, int templateImagePixelWidth, Grid mainGrid, DateTime templateImportDate)
        {
            try
            {
                var IsImageExist = (from iie in dde.TemplateImages
                                    where iie.Template_ID == templates.Template_ID &&
                                    iie.Patient_ID == patients.Patient_ID &&
                                    iie.TemplateImage_ImportDate == templateImportDate.Date
                                    select new
                {
                    TemplateImage_ID = iie.TemplateImage_ID,
                    TemplateImage_Number = iie.TemplateImage_Number,
                    TemplateImage_ImportDate = iie.TemplateImage_ImportDate,
                    Template_ID = iie.Template_ID,
                    Image_ID = iie.Image_ID,
                    Image_Path = agencys.Agency_ImagePath + iie.Image_Path,
                    Patient_ID = iie.Patient_ID
                }).ToList().Select(s => new TemplateImages
                {
                    TemplateImage_ID         = s.TemplateImage_ID,
                    TemplateImage_Number     = s.TemplateImage_Number,
                    TemplateImage_ImportDate = s.TemplateImage_ImportDate,
                    Template_ID = s.Template_ID,
                    Image_ID    = s.Image_ID,
                    Image_Path  = s.Image_Path,
                    Patient_ID  = s.Patient_ID
                });
                if (IsImageExist.Count() > 0)
                {
                    tICollection = new ObservableCollection <TemplateImages>(IsImageExist);
                    lbi          = new LoadBitmapImage();

                    ProgressDialog pd = new ProgressDialog();
                    pd.Dispatcher.Invoke(() =>
                    {
                        pd.PText    = "圖片載入中( 0 / " + tICollection.Count + " )";
                        pd.PMinimum = 0;
                        pd.PValue   = 0;
                        pd.PMaximum = tICollection.Count;
                        pd.Show();
                    });
                    //multi - thread
                    Task.Factory.StartNew(() =>
                    {
                        foreach (TemplateImages imgs in tICollection)
                        {
                            if (!string.IsNullOrEmpty(imgs.Image_Path) && File.Exists(imgs.Image_Path))
                            {
                                mainGrid.Dispatcher.Invoke(() =>
                                {
                                    ((Image)mainGrid.FindName("Image" + imgs.TemplateImage_Number)).Source = lbi.SettingBitmapImage(imgs.Image_Path, templateImagePixelWidth);
                                });
                            }
                            pd.Dispatcher.Invoke(() =>
                            {
                                pd.PValue++;
                                pd.PText = "圖片載入中( " + pd.PValue + " / " + tICollection.Count + " )";
                            });
                        }
                    }).ContinueWith(t =>
                    {
                        pd.Dispatcher.Invoke(() =>
                        {
                            pd.PText = "載入完成";
                            pd.Close();
                        });

                        GC.Collect();
                    });
                }
            }
            catch (Exception ex)
            {
                Error_Log.ErrorMessageOutput(ex.ToString());
            }
        }
        private void SetImageDefault(ImageInfo imageInfo)
        {
            try
            {
                bi           = new LoadBitmapImage().SettingBitmapImage(ImageInfo.Image_FullPath, 0);
                ImageRotated = new Image()
                {
                    Source = bi
                };

                //Control Image (X,Y)
                imageStartX = 0;
                imageStartY = 0;

                if (bi.PixelHeight < Cvs.ActualHeight && bi.PixelWidth < Cvs.ActualWidth)
                {
                    heightRatio            = 1;
                    widthRatio             = 1;
                    ImageRotated.MaxHeight = bi.PixelHeight;
                    ImageRotated.Height    = ImageRotated.MaxHeight;
                    ImageRotated.MaxWidth  = bi.PixelWidth;
                    ImageRotated.Width     = ImageRotated.MaxWidth;
                    imageStartX            = (Cvs.ActualWidth - bi.PixelWidth) / 2;
                    imageStartY            = (Cvs.ActualHeight - bi.PixelHeight) / 2;
                }
                else
                {
                    //Canvas 的寬高關係
                    if (Cvs.ActualWidth > Cvs.ActualHeight)
                    {
                        //高的比例
                        heightRatio = Cvs.ActualHeight / bi.PixelHeight;
                        //高填滿
                        ImageRotated.MaxHeight = Cvs.ActualHeight;
                        ImageRotated.Height    = ImageRotated.MaxHeight;
                        //計算寬比例
                        ImageRotated.Width = bi.PixelWidth * heightRatio;

                        //如果圖片是橫的 但是寬度超過CVS
                        if (ImageRotated.Width > Cvs.ActualWidth)
                        {
                            widthRatio            = Cvs.ActualWidth / bi.PixelWidth;
                            ImageRotated.MaxWidth = Cvs.ActualWidth;
                            ImageRotated.Width    = ImageRotated.MaxWidth;
                            ImageRotated.Height   = bi.PixelHeight * widthRatio;

                            //Image 起始座標 高度置中
                            imageStartX = 0;
                            imageStartY = (Cvs.ActualHeight - ImageRotated.Height) / 2;
                        }
                        else
                        {
                            //Image 起始座標 寬度置中
                            imageStartX = (Cvs.ActualWidth - ImageRotated.Width) / 2;
                            imageStartY = 0;
                        }
                    }
                    else
                    {
                        //寬的比例
                        widthRatio = Cvs.ActualWidth / bi.PixelWidth;
                        //寬填滿
                        ImageRotated.MaxWidth = Cvs.ActualWidth;
                        ImageRotated.Width    = ActualWidth;
                        //計算高比例
                        ImageRotated.Height = bi.PixelHeight * widthRatio;
                        if (ImageRotated.Height > Cvs.ActualHeight)
                        {
                            heightRatio            = Cvs.ActualHeight / bi.PixelHeight;
                            ImageRotated.MaxHeight = Cvs.ActualHeight;
                            ImageRotated.Height    = ImageRotated.MaxHeight;
                            ImageRotated.Width     = bi.PixelWidth * heightRatio;

                            //Image 起始座標 寬度置中
                            imageStartX = (Cvs.ActualWidth - ImageRotated.Width) / 2;
                            imageStartY = 0;
                        }
                        else
                        {
                            //Image 起始座標 高度置中
                            imageStartX = 0;
                            imageStartY = (Cvs.ActualHeight - ImageRotated.Height) / 2;
                        }
                    }
                }

                Cvs.Children.Add(ImageRotated);

                Canvas.SetTop(ImageRotated, imageStartY);
                Canvas.SetLeft(ImageRotated, imageStartX);

                //CombinedGeometry.Geometry1 Setting
                //包圍Image的Rect(反灰)
                RectangleGeometry rectangleGeometry = new RectangleGeometry(new Rect(0, 0, Cvs.ActualWidth, Cvs.ActualHeight));

                rect2 = new Rect(imageStartX, imageStartY, ImageRotated.Width, ImageRotated.Height);
                //CombinedGeometry.Geometry2 Setting
                //包圍Image的Rect(透明區)初始與圖片一樣
                rectangleGeometry2 = new RectangleGeometry(rect2);

                //Path 的 CombinedGeometry
                combinedGeometry = new CombinedGeometry()
                {
                    GeometryCombineMode = GeometryCombineMode.Xor,
                    Geometry1           = rectangleGeometry,
                    Geometry2           = rectangleGeometry2
                };

                //建立Rect 覆蓋Image
                path = new Path
                {
                    Fill = (Brush)(new BrushConverter().ConvertFromString("#AA000000")),
                    Data = combinedGeometry
                };

                Cvs.Children.Add(path);

                ButtonSave.IsEnabled = false;
                ButtonUndo.IsEnabled = false;

                RotateAngle.Value = 0;
            }
            catch (Exception ex)
            {
                Error_Log.ErrorMessageOutput(ex.ToString());
            }
        }