/// <summary> /// 用路徑抓出使用者電腦容量 /// </summary> /// <param name="Drive">路徑</param> /// <returns></returns> bool RemainingSpace(string Drive) { try { if (Directory.Exists(Drive) == false) { Directory.CreateDirectory(Drive); } string str = Path.GetPathRoot(Drive); bool success = GetDiskFreeSpaceEx(Path.GetPathRoot(Drive), out ulong FreeBytesAvailable, out ulong TotalNumberOfBytes, out ulong TotalNumberOfFreeBytes); if (!success) { Inteware_Messagebox Msg = new Inteware_Messagebox(); Msg.ShowMessage(TranslationSource.Instance["CannnotGetRemainingSpace"]); return(false); } label_AvailableSpace.Tag = TotalNumberOfFreeBytes; label_AvailableSpace.Content = ConvertDiskUnit(TotalNumberOfFreeBytes, (int)_diskUnit.MB); return(true); } catch (Exception ex) { Inteware_Messagebox Msg = new Inteware_Messagebox(); Msg.ShowMessage(ex.Message); return(false); } }
void CompletedWork(object sender, RunWorkerCompletedEventArgs e) { Log.RecordLog(new StackTrace(true).GetFrame(0).GetFileLineNumber().ToString(), "BeforeDownlad_CompletedWork", "IntoFunc"); if (e.Error != null) { tmr.Stop(); Log.RecordLog(new StackTrace(true).GetFrame(0).GetFileLineNumber().ToString(), "BeforeDownload.xaml.cs_CompletedWork()_Error", e.Error.Message); Handler_snackbarShow(TranslationSource.Instance["Error"]); //錯誤 SetHttpResponseOK(_ReceiveDataStatus.Error); } else if (e.Cancelled) { tmr.Stop(); Log.RecordLog(new StackTrace(true).GetFrame(0).GetFileLineNumber().ToString(), "BeforeDownload.xaml.cs_CompletedWork()_exception", "e.Cancelled"); Inteware_Messagebox Msg = new Inteware_Messagebox(); Msg.ShowMessage(TranslationSource.Instance["ReceivingDataNotResponding"], TranslationSource.Instance["Warning"], MessageBoxButton.YesNo, MessageBoxImage.Warning); if (Msg.ReturnClickWhitchButton == (int)Inteware_Messagebox._ReturnButtonName.YES) { OrderManagerFunctions omFunc = new OrderManagerFunctions(); omFunc.RunCommandLine(http_url, ""); } Handler_snackbarShow(TranslationSource.Instance["Cancel"]); //取消(超過時間,也許再讓使用者可以自行增加秒數?) SetHttpResponseOK(_ReceiveDataStatus.Cancel); } else { tmr.Stop(); Log.RecordLog(new StackTrace(true).GetFrame(0).GetFileLineNumber().ToString(), "BeforeDownload.xaml.cs_CompletedWork()", "OK"); SetHttpResponseOK(_ReceiveDataStatus.OK); } }
/// <summary> /// 設定Detail顯示資訊 /// </summary> /// <param name="Import">要匯入的CadInformation</param> public void SetDetailInfo(CadInformation Import) { CADInfo = Import; textbox_Order.Text = CADInfo.OrderID.TrimStart('-'); textbox_Client.Text = CADInfo.Client; textbox_Patient.Text = CADInfo.PatientName; textbox_Technician.Text = CADInfo.Technician; textbox_Note.Text = CADInfo.Note; string imgPath = CADInfo.CaseXmlPath.Replace(".xml", ".jpg"); try { image_toothJPG.BeginInit(); image_toothJPG.Source = new BitmapImage(new Uri(imgPath, UriKind.RelativeOrAbsolute)); image_toothJPG.EndInit(); image_toothJPG.Visibility = Visibility.Visible; } catch { image_toothJPG.Visibility = Visibility.Hidden; } try { ReadToothProductDetail(); } catch (Exception ex) { Inteware_Messagebox Msg = new Inteware_Messagebox(); Msg.ShowMessage(ex.Message); } }
/// <summary> /// 讀取HL.xml的詳細更新資訊 /// </summary> public void LoadHLXml() { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); XDocument xDoc; try { omInfo = new NewOMInfo(); updateInfo = new NewOMInfo(); xDoc = XDocument.Load(HLXMLlink); var OrderManagerInfo = from q in xDoc.Descendants("DownloadLink").Descendants("OrderManager") select new { m_Version = q.Descendants("Version").First().Value, m_HyperLink = q.Descendants("HyperLink").First().Value, }; var UpdateInfo = from q in xDoc.Descendants("DownloadLink").Descendants("Updates") select new { m2_Version = q.Descendants("Version").First().Value, m2_HyperLink = q.Descendants("HyperLink").First().Value, }; foreach (var item in OrderManagerInfo) { omInfo.VersionFromWeb = new Version(item.m_Version); omInfo.DownloadLink = item.m_HyperLink.Replace("\n ", "").Replace("\r ", "").Replace(" ", "");; } foreach (var item in UpdateInfo) { updateInfo.VersionFromWeb = new Version(item.m2_Version); updateInfo.DownloadLink = item.m2_HyperLink.Replace("\n ", "").Replace("\r ", "").Replace(" ", "");; } } catch (Exception ex) { Console.WriteLine(ex.Message); Inteware_Messagebox Msg = new Inteware_Messagebox(); Msg.ShowMessage(TranslationSource.Instance["CannotGetnewOMXML"] + TranslationSource.Instance["Contact"]); JumpIntoOrderEXE(false); } }
void DoWork_Unpacking(object sender, DoWorkEventArgs e) { try { //解壓縮 using (var zip = ZipFile.Read(DownloadFileName)) { foreach (var zipEntry in zip) { zipEntry.Extract(System.Environment.CurrentDirectory, ExtractExistingFileAction.OverwriteSilently);//解壓縮到同一個資料夾 } } } catch { Inteware_Messagebox Msg = new Inteware_Messagebox(); Msg.ShowMessage(TranslationSource.Instance["UnpackingError"] + TranslationSource.Instance["Contact"]); JumpIntoOrderEXE(false); } }
void DoWork_Cmd(object sender, DoWorkEventArgs e) { try { if (e.Argument is BackgroundArgs) { Process processer = new Process(); processer.StartInfo.FileName = ((BackgroundArgs)e.Argument).FileName; if (((BackgroundArgs)e.Argument).Arguments != "") { processer.StartInfo.Arguments = ((BackgroundArgs)e.Argument).Arguments; } processer.Start(); } } catch (Exception ex) { Inteware_Messagebox Msg = new Inteware_Messagebox(); Msg.ShowMessage(ex.Message); } }
private void Click_OK(object sender, RoutedEventArgs e) { if (textbox_Account.Text == "") { textbox_Account.BorderThickness = new Thickness(2); textbox_Account.BorderBrush = Brushes.Red; return; } if (textbox_PWD.Text == "") { passwordbox_PWD.BorderThickness = new Thickness(2); textbox_PWD.BorderThickness = new Thickness(2); passwordbox_PWD.BorderBrush = Brushes.Red; textbox_PWD.BorderBrush = Brushes.Red; return; } string[] LoginData = new string[3] { Airdental_main.APIPortal, textbox_Account.Text, passwordbox_PWD.Password }; //API網址、帳號、密碼 UserDetail = new string[4] { "", "", "", "" }; string NewCookie = ""; WebException _exception = Airdental_main.Login(LoginData, ref UserDetail, ref NewCookie); if (_exception == null) { Properties.Settings.Default.AirdentalCookie = NewCookie; Properties.Settings.Default.AirdentalAcc = textbox_Account.Text; Properties.Settings.Default.Save(); if (UserDetail[(int)_AirD_LoginDetail.UID] != "") { Properties.OrderManagerProps.Default.AirD_uid = UserDetail[(int)_AirD_LoginDetail.UID]; DialogResult = true; } else { DialogResult = false; } } else { if (_exception.Status == WebExceptionStatus.ProtocolError) { string errMessage = ""; if (_exception.Response is HttpWebResponse response) { switch (response.StatusCode) { case HttpStatusCode.BadRequest: { image_loginFail.Visibility = Visibility.Visible; label_loginFail.Visibility = Visibility.Visible; passwordbox_PWD.Password = ""; textbox_PWD.Text = ""; textbox_Account.BorderThickness = new Thickness(2); textbox_Account.BorderBrush = Brushes.Red; break; } default: { errMessage = "ErrorCode: " + (object)(int)response.StatusCode + ", " + Enum.GetName(typeof(HttpStatusCode), (int)response.StatusCode); break; } } } else { errMessage = _exception.ToString(); } if (errMessage != "") { Inteware_Messagebox Msg = new Inteware_Messagebox(); Msg.ShowMessage(errMessage, TranslationSource.Instance["Login"] + TranslationSource.Instance["Error"], MessageBoxButton.OK, MessageBoxImage.Warning); log.RecordLog(new StackTrace(true).GetFrame(0).GetFileLineNumber().ToString(), "UserLogin.xaml.cs_ClickOK_exception", errMessage); } } } }
private void Click_systemButton(object sender, RoutedEventArgs e) { void GOTODownload() { try { if (Directory.Exists(textbox_InstallPath.Text) != true) { Directory.CreateDirectory(textbox_InstallPath.Text); } SetPropertiesSoftwarePath(currentSoftwareID, textbox_InstallPath.Text); this.DialogResult = true; } catch (Exception ex) { Inteware_Messagebox Msg = new Inteware_Messagebox(); Msg.ShowMessage(ex.Message); this.DialogResult = false; } } if (sender is Button) { switch (((Button)sender).Name) { case "sysBtn_Yes": { //檢查客戶端容量是否比軟體檔案所需空間大超過3倍,如果沒有就Messagebox警告 if (label_AvailableSpace.Foreground == Brushes.Orange) { Inteware_Messagebox Msg = new Inteware_Messagebox(); Msg.ShowMessage(TranslationSource.Instance["SpaceMaynotBeEnough"], TranslationSource.Instance["Warning"], MessageBoxButton.YesNo, MessageBoxImage.Warning); if (Msg.ReturnClickWhitchButton == (int)Inteware_Messagebox._ReturnButtonName.YES) { GOTODownload(); } else { this.DialogResult = false; } } else if (label_AvailableSpace.Foreground == Brushes.Orange) { Inteware_Messagebox Msg = new Inteware_Messagebox(); Msg.ShowMessage(TranslationSource.Instance["NoEnoughSpaceToInstall"]); //磁碟空間不足以安裝軟體 this.DialogResult = false; } else { GOTODownload(); } break; } case "sysBtn_Cancel": { this.DialogResult = false; break; } } } }
/// <summary> /// 設定UI所顯示的資訊 /// </summary> public bool SetInformation() { if (currentSoftwareID == -1 || http_url == "") { return(false); } OrderManagerFunctions omFunc = new OrderManagerFunctions(); string[] SoftwareNameArray = new string[6] { omFunc.GetSoftwareName(_softwareID.EZCAD), omFunc.GetSoftwareName(_softwareID.Implant), omFunc.GetSoftwareName(_softwareID.Ortho), omFunc.GetSoftwareName(_softwareID.Tray), omFunc.GetSoftwareName(_softwareID.Splint), omFunc.GetSoftwareName(_softwareID.Guide) }; label_TitleBar.Content = TranslationSource.Instance["Install"] + "-" + SoftwareNameArray[currentSoftwareID]; label_Header.Content = TranslationSource.Instance["AboutToInstall"] + " " + SoftwareNameArray[currentSoftwareID]; if (Properties.OrderManagerProps.Default.mostsoftwareDisk != "") { textbox_InstallPath.Text = Properties.OrderManagerProps.Default.mostsoftwareDisk + @"IntewareInc\" + SoftwareNameArray[currentSoftwareID].Replace(".", " ") + @"\"; } else { textbox_InstallPath.Text = @"C:\IntewareInc\" + SoftwareNameArray[currentSoftwareID].Replace(".", " ") + @"\"; } jlabel_RequireSpace.Content += ":"; jlabel_AvailableSpace.Content += ":"; try { if (((HttpWebResponse)httpResponse).StatusDescription == "OK" && httpResponse.ContentLength > 1) { // 取得下載的檔名 Uri uri = new Uri(http_url); string downloadfileRealName = Path.GetFileName(uri.LocalPath); label_DownloadFileName.Content = "(" + downloadfileRealName + ")"; if (RemainingSpace(textbox_InstallPath.Text) == true) //客戶電腦剩餘空間 { label_RequireSpace.Tag = Convert.ToUInt64(httpResponse.ContentLength); label_RequireSpace.Content = ConvertDiskUnit(Convert.ToUInt64(httpResponse.ContentLength), (int)_diskUnit.MB); if ((ulong)label_AvailableSpace.Tag < (ulong)label_RequireSpace.Tag) { label_AvailableSpace.Foreground = Brushes.Orange; label_AvailableSpace.ToolTip = TranslationSource.Instance["NoEnoughSpaceToInstall"];//磁碟空間不足以安裝軟體 } else if ((ulong)label_AvailableSpace.Tag < (ulong)label_RequireSpace.Tag * 3) { label_AvailableSpace.Foreground = Brushes.Orange; label_AvailableSpace.ToolTip = TranslationSource.Instance["SpaceMaynotBeEnough"];//磁碟空間可能不足以安裝軟體 } else { label_AvailableSpace.Foreground = Brushes.White; label_AvailableSpace.ToolTip = TranslationSource.Instance["SpaceAvailable"]; } } else { Inteware_Messagebox Msg = new Inteware_Messagebox(); Msg.ShowMessage(TranslationSource.Instance["CannnotGetRemainingSpace"]); if (httpResponse != null) { httpResponse.Close(); } return(false); } } } catch (Exception ex) { Inteware_Messagebox Msg = new Inteware_Messagebox(); Msg.ShowMessage(ex.Message, TranslationSource.Instance["NetworkError"]); //網路連線異常or載點掛掉 if (httpResponse != null) { httpResponse.Close(); } return(false); } if (httpResponse != null) { httpResponse.Close(); } return(true); }
void DoWork_DownloadSoftware(object sender, DoWorkEventArgs e) { if (sender is BackgroundWorker) { BackgroundWorker bw = sender as BackgroundWorker; //跳過https檢測 & Win7 相容 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); //Request資料 HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(readyInstallSoftwareInfo.softwareDownloadLink); httpRequest.Credentials = CredentialCache.DefaultCredentials; httpRequest.UserAgent = ".NET Framework Example Client"; httpRequest.Method = "GET"; Handler_snackbarShow(TranslationSource.Instance["ReceivingData"]); //開始取得資料 HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse(); try { if (((HttpWebResponse)httpResponse).StatusDescription == "OK" && httpResponse.ContentLength > 1) { //覆蓋軟體大小,以直接抓檔案內容最準 readyInstallSoftwareInfo.softwareSize = Convert.ToDouble(Math.Round(((double)(Int64)httpResponse.ContentLength / 1024.0 / 1024.0), 1)); if (Directory.Exists(Properties.Settings.Default.DownloadFolder) == false) { log.RecordLog(new StackTrace(true).GetFrame(0).GetFileLineNumber().ToString(), "DoWork_DownloadSoftware_exception", "DownloadFolder not found"); Inteware_Messagebox Msg = new Inteware_Messagebox(); Msg.ShowMessage("Download folder not found!"); return; } // 取得下載的檔名 Uri uri = new Uri(readyInstallSoftwareInfo.softwareDownloadLink); downloadfilepath = Properties.Settings.Default.DownloadFolder + @"\" + Path.GetFileName(uri.LocalPath); Stream netStream = httpResponse.GetResponseStream(); Stream fileStream = new FileStream(downloadfilepath, FileMode.Create); byte[] read = new byte[1024]; long progressBarValue = 0; int realReadLen = netStream.Read(read, 0, read.Length); while (realReadLen > 0) { fileStream.Write(read, 0, realReadLen); //realReadLen 是一個封包大小,progressBarValue會一直累加 progressBarValue += realReadLen; double percent = (double)progressBarValue / (double)httpResponse.ContentLength; bw.ReportProgress(Convert.ToInt32(percent * 100)); realReadLen = netStream.Read(read, 0, read.Length); } fileStream.Close(); netStream.Close(); } else { } httpResponse.Close(); } catch (Exception ex) { Handler_snackbarShow(ex.Message); e.Cancel = true; } } }
void DoWork_Download(object sender, DoWorkEventArgs e) { if (sender is BackgroundWorker) { BackgroundWorker bw = sender as BackgroundWorker; //跳過https檢測 & Win7 相容 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); string downloadLink; if (UpdateOM_Main == true) { downloadLink = omInfo.DownloadLink; } else { downloadLink = updateInfo.DownloadLink; } //Request資料 HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(downloadLink); httpRequest.Credentials = CredentialCache.DefaultCredentials; httpRequest.UserAgent = ".NET Framework Example Client"; httpRequest.Method = "GET"; HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse(); try { if (((HttpWebResponse)httpResponse).StatusDescription == "OK" && httpResponse.ContentLength > 1) { // 取得下載的檔名 Uri uri = new Uri(downloadLink); DownloadFileName = Path.GetFileName(uri.LocalPath); if (File.Exists(DownloadFileName) == true) { File.Delete(DownloadFileName); } Stream netStream = httpResponse.GetResponseStream(); Stream fileStream = new FileStream(DownloadFileName, FileMode.Create); byte[] read = new byte[1024]; long progressBarValue = 0; int realReadLen = netStream.Read(read, 0, read.Length); while (realReadLen > 0) { fileStream.Write(read, 0, realReadLen); progressBarValue += realReadLen; double percent = (double)progressBarValue / (double)httpResponse.ContentLength; bw.ReportProgress(Convert.ToInt32(percent * 100)); realReadLen = netStream.Read(read, 0, read.Length); } fileStream.Close(); netStream.Close(); httpResponse.Close(); } else { httpResponse.Close(); Inteware_Messagebox Msg = new Inteware_Messagebox(); Msg.ShowMessage(TranslationSource.Instance["CannotDownloadOM"] + TranslationSource.Instance["Contact"]); JumpIntoOrderEXE(false); } } catch { Inteware_Messagebox Msg = new Inteware_Messagebox(); Msg.ShowMessage(TranslationSource.Instance["DownloadingError"] + TranslationSource.Instance["Contact"]); JumpIntoOrderEXE(false); } } }
void CompletedWork_UpdateCheck(object sender, RunWorkerCompletedEventArgs e) { bool GoUpdate = false; try { FileVersionInfo verInfo; verInfo = FileVersionInfo.GetVersionInfo("Order Manager.exe"); if (omInfo.VersionFromWeb > new Version(verInfo.FileVersion)) { GoUpdate = true; UpdateOM_Main = true; } else if (omInfo.VersionFromWeb == new Version(verInfo.FileVersion) && updateInfo.VersionFromWeb > new Version(verInfo.FileVersion)) { GoUpdate = true; UpdateOM_Main = false; } } catch (Exception ex) { Inteware_Messagebox Msg = new Inteware_Messagebox(); Msg.ShowMessage(ex.Message, "UpdateCheck error"); GoUpdate = true; } if (GoUpdate == false) //不用更新 { JumpIntoOrderEXE(false); } else //進入更新 { DialogUpdateCheck DlgUpdateChk = new DialogUpdateCheck { Owner = this }; DlgUpdateChk.ShowDialog(); if (DlgUpdateChk.DialogResult == true) //進入更新 { if (DlgUpdateChk.NoAutoChk == true) { Properties.Settings.Default.NeedUpdate = false; } else { Properties.Settings.Default.NeedUpdate = true; } Properties.Settings.Default.Save(); RunCommandLine("Order Manager.exe", "-ExportProps");//匯出Properties progressbar_update.IsIndeterminate = false; label_describe.Content = TranslationSource.Instance["Downloading"]; BgWorker_Main = new BackgroundWorker(); BgWorker_Main.DoWork += new DoWorkEventHandler(DoWork_Download); BgWorker_Main.ProgressChanged += new ProgressChangedEventHandler(UpdateProgress_Download); BgWorker_Main.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedWork_Download); BgWorker_Main.WorkerReportsProgress = true; BgWorker_Main.WorkerSupportsCancellation = false; BgWorker_Main.RunWorkerAsync(); } else //不更新 { if (DlgUpdateChk.NoAutoChk == true) { Properties.Settings.Default.NeedUpdate = false; } else { Properties.Settings.Default.NeedUpdate = true; } Properties.Settings.Default.Save(); JumpIntoOrderEXE(false); } } }