private void ToggleButton_Save_Click(object sender, RoutedEventArgs e) { try { //診所設定判斷 Agencys agencys = agencySettingViewModel.Agencys; if (PathCheck.IsPathExist(agencys.Agency_ImagePath)) { new TableAgencys().UpdateAgency(agencys, agencys.Agency_ImagePath, agencys.Agency_WifiCardPath, agencys.Agency_ViewType, agencys.Function_ID); ReturnDialogResult = true; } else { if (MessageBox.Show("您所設定的影像路徑無法使用,可能會導致影像無法存取,是否繼續?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { new TableAgencys().UpdateAgency(agencys, agencys.Agency_ImagePath, agencys.Agency_WifiCardPath, agencys.Agency_ViewType, agencys.Function_ID); ReturnDialogResult = true; } } //其他 string PointofixPath = agencySettingViewModel.Pointofix; if (PathCheck.IsFileExist(PointofixPath) || string.IsNullOrEmpty(PointofixPath)) { ConfigManage.AddUpdateAppConfig("PointofixPath", PointofixPath); ReturnDialogResult = true; } else { if (MessageBox.Show("您所設定的Pointofix的位置不存在,可能會導致該軟體無法使用,是否繼續?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { ConfigManage.AddUpdateAppConfig("PointofixPath", PointofixPath); ReturnDialogResult = true; } } string ImageDecodePixel = agencySettingViewModel.ImageDecodePixel; ConfigManage.AddUpdateAppConfig("ImageDecodePixel", ImageDecodePixel); MessageBox.Show("設定已更改"); } catch (Exception ex) { MessageBox.Show("儲存設定時發生異常", "提示", MessageBoxButton.OK, MessageBoxImage.Error); ErrorLog.ErrorMessageOutput(ex.ToString()); } DialogResult = ReturnDialogResult; Close(); }
/// <summary> /// 開始載入判斷 /// </summary> private void Loading() { try { //取得本機訊息 //HostName、IP string hostName = Dns.GetHostName(); string localIP = string.Empty; IPHostEntry ipHostEntry = Dns.GetHostEntry(hostName); foreach (IPAddress ip in ipHostEntry.AddressList) { if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { localIP = ip.ToString(); } } TextBlockStatus.Dispatcher.Invoke(() => { TextBlockStatus.Text = "伺服器位置確認中"; }, DispatcherPriority.Render); //判斷app.config if (!ConfigManage.IsConfigValue("Server"))//尚未設置 { AnswerDialogOne answerDialogOne = new AnswerDialogOne("請輸入伺服器位置:", "IP"); if (answerDialogOne.ShowDialog() == true) { //寫入config Server 欄位 string serverIP = answerDialogOne.Answer; ConfigManage.AddUpdateAppConfig("Server", serverIP); } } TextBlockStatus.Dispatcher.Invoke(() => { TextBlockStatus.Text = "嘗試連接伺服器..."; }, DispatcherPriority.Render); //連接Server connection if (new ConnectionString().CheckConnection()) { TextBlockStatus.Dispatcher.Invoke(() => { TextBlockStatus.Text = "取得本機資訊"; }, DispatcherPriority.Render); TableAgencys tableAgencys = new TableAgencys(); //取得已經驗證的機構 Agencys agencys = tableAgencys.QueryVerifyAgencys(); if (agencys != null) { Agencys = agencys; //開始判斷本機與伺服器關係 TableClients tableClients = new TableClients(); Clients clients = tableClients.QueryClient(hostName); if (clients != null) { if (!string.IsNullOrEmpty(clients.Agency_VerificationCode) && clients.Agency_VerificationCode.Equals(agencys.Agency_VerificationCode)) { if (clients.Client_IsVerify) { TextBlockStatus.Dispatcher.Invoke(() => { TextBlockStatus.Text = "本機已認證"; }, DispatcherPriority.Render); //本機與伺服器認證通過 //判斷軟體使用期限 CheckServerTrialPeriod(agencys); } else { MessageBoxTips = "此台電腦已經被停用,請聯絡資訊廠商..."; } } else { MessageBoxTips = "此台電腦與伺服器的驗證碼不符,請聯絡資訊廠商"; } } else { //第一次使用,輸入驗證碼 AnswerDialogOne answerDialogOne = new AnswerDialogOne("此台電腦為第一次登入,請輸入產品驗證碼:", "Verify"); if (answerDialogOne.ShowDialog() == true) { string verificationCodeClient = string.Empty; verificationCodeClient = KeyGenerator.SHA384Encode(answerDialogOne.Answer); if (verificationCodeClient.Equals(agencys.Agency_VerificationCode)) { TextBlockStatus.Dispatcher.Invoke(() => { TextBlockStatus.Text = "本機與伺服器驗證成功"; }, DispatcherPriority.Render); Clients insertClients = new Clients() { Client_HostName = hostName, Client_IP = localIP, Client_IsVerify = true, Agency_VerificationCode = verificationCodeClient }; tableClients.InsertClient(insertClients); //本機與伺服器認證通過 //判斷軟體使用期限 CheckServerTrialPeriod(agencys); } else { MessageBoxTips = "與伺服器的驗證碼不符,請聯絡資訊廠商"; } } } } else { MessageBoxTips = "伺服器尚未被驗證,無法使用,請聯絡資訊廠商"; } } else { MessageBoxTips = "伺服器連接失敗"; ConfigManage.AddUpdateAppConfig("Server", ""); } //登入成功 //show MessageBox if (ReturnDialogResult) { TextBlockStatus.Dispatcher.Invoke(() => { TextBlockStatus.Text = "載入病患資料"; }, DispatcherPriority.Render); LoadPatient(); TextBlockStatus.Dispatcher.Invoke(() => { TextBlockStatus.Text = "影像路徑測試中,請稍候"; }, DispatcherPriority.Render); IsExistImagePath = PathCheck.IsPathExist(Agencys.Agency_ImagePath); TextBlockStatus.Dispatcher.Invoke(() => { TextBlockStatus.Text = "成功登入,歡迎使用iDental"; }, DispatcherPriority.Render); if (IsValidTrialPeriod)//還在試用期內可以使用 { MessageBox.Show(MessageBoxTips, "提示", MessageBoxButton.OK, MessageBoxImage.Information); } } else { TextBlockStatus.Dispatcher.Invoke(() => { TextBlockStatus.Text = "登入失敗,原因:" + MessageBoxTips; }, DispatcherPriority.Render); MessageBox.Show(MessageBoxTips, "提示", MessageBoxButton.OK, MessageBoxImage.Stop); } //寫入ConnectingLog資訊 TableConnectingLogs tableConnectingLogs = new TableConnectingLogs(); ConnectingLogs connectingLogs = new ConnectingLogs() { ConnectingLog_HostName = hostName, ConnectingLog_IP = localIP, ConnectingLog_Error = MessageBoxTips, ConnectingLog_IsPermit = ReturnDialogResult }; tableConnectingLogs.InsertConnectingLog(connectingLogs); Thread.Sleep(2000); //回傳結果 DialogResult = ReturnDialogResult; } catch (Exception ex) { ErrorLog.ErrorMessageOutput(ex.ToString()); DialogResult = false; } Close(); }