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