Пример #1
0
        private void SendReportButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(App.reportSettingModel.MailAddress) || string.IsNullOrEmpty(App.reportSettingModel.MailHost)
                || string.IsNullOrEmpty(App.reportSettingModel.MailUsername) || string.IsNullOrEmpty(App.reportSettingModel.MailPwd)
                || string.IsNullOrEmpty(App.reportSettingModel.ToMailAddress))
            {
                MessageBox.Show(this, App.Current.FindResource("Message_15").ToString());
                return;
            }
            string deviceNo = App.reportSettingModel.DeviceNo;
            int deviceType = App.reportSettingModel.DeviceType;
            var selectedUserList = this.CodeListBox.SelectedItems;
            if (selectedUserList == null || selectedUserList.Count==0)
            {
                MessageBox.Show(this, App.Current.FindResource("Message_35").ToString());
                return;
            }
                                                
            MessageBoxResult result = MessageBox.Show(this, App.Current.FindResource("Message_17").ToString(), "Send Report", MessageBoxButton.YesNo, MessageBoxImage.Information);
            if (result == MessageBoxResult.Yes)
            {                
                foreach (Person selectedUser in selectedUserList)
                {
                    selectedUser.Uploaded = Visibility.Collapsed.ToString();
                }
                ProgressBarGridDelegate progressBarGridDelegate = new ProgressBarGridDelegate(progressBarGrid.SetValue);
                UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(uploadProgressBar.SetValue);
                //使用系统代理方式显示进度条面板
                Dispatcher.Invoke(progressBarGridDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.Grid.VisibilityProperty, Visibility.Visible });
                try
                {
                    List<string> errMsg = new List<string>();
                    int n = 0;
                    double groupValue = 100 / selectedUserList.Count;
                    double sizeValue = groupValue / 10;
                    //循环处理选择的每一个患者档案
                    foreach (Person selectedUser in selectedUserList)
                    {                        
                        string dataFile = selectedUser.ArchiveFolder + System.IO.Path.DirectorySeparatorChar + selectedUser.Code + ".dat";
                        //如果是医生模式但当前的患者档案中却没有报告数据,则不能发送数据
                        if (!File.Exists(dataFile) && deviceType == 2)
                        {
                            errMsg.Add(selectedUser.Code + " :: " + App.Current.FindResource("Message_16").ToString());
                            continue;
                        }                        

                        Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(groupValue * n + sizeValue) });

                        //打包数据文件,并上传到FPT服务
                        string zipFile = dataFolder + System.IO.Path.DirectorySeparatorChar + "R_" + selectedUser.Code + "-" + selectedUser.SurName;                        
                        zipFile = zipFile + (string.IsNullOrEmpty(selectedUser.GivenName) ? "" : "," + selectedUser.GivenName) + (string.IsNullOrEmpty(selectedUser.OtherName) ? "" : " " + selectedUser.OtherName) + ".zip";                        

                        try
                        {
                            //ZipTools.Instance.ZipFolder(selectedUser.ArchiveFolder, zipFile, deviceType);
                            ZipTools.Instance.ZipFiles(selectedUser.ArchiveFolder, zipFile,2);
                            Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(groupValue * n + sizeValue * 5) });
                        }
                        catch (Exception ex1)
                        {
                            errMsg.Add(selectedUser.Code + " :: " + string.Format(App.Current.FindResource("Message_21").ToString() + " " + ex1.Message, selectedUser.ArchiveFolder));
                            continue;
                        }

                        //上传到FTP服务器
                        try
                        {
                            FtpHelper.Instance.Upload(App.reportSettingModel.FtpUser, App.reportSettingModel.FtpPwd, App.reportSettingModel.FtpPath+"Send/", zipFile);
                            //上传成功后保存上传状态,以便让用户知道这个患者今天已经成功提交过数据
                            if (!App.uploadedCodeList.Contains(selectedUser.Code))
                            {
                                App.uploadedCodeList.Add(selectedUser.Code);
                            }
                            selectedUser.Uploaded = Visibility.Visible.ToString();
                            try
                            {
                                File.Delete(zipFile);
                            }
                            catch { }
                        }
                        catch (Exception ex2)
                        {
                            errMsg.Add(selectedUser.Code + " :: " + App.Current.FindResource("Message_52").ToString() + " " + ex2.Message);
                            continue;
                        }
                        Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(groupValue * n + sizeValue * 9) });
                        
                        n++;
                    }

                    try
                    {
                        //发送通知邮件  
                        SendEmail((selectedUserList.Count - errMsg.Count), true);
                    }
                    catch (Exception ex3)
                    {
                        errMsg.Add(App.Current.FindResource("Message_19").ToString() + " " + ex3.Message);                        
                    }
                    //完成进度条
                    Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(100) });

                    //显示没有成功发送数据的错误消息
                    if (errMsg.Count > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append(string.Format(App.Current.FindResource("Message_36").ToString(), errMsg.Count));
                        foreach (var err in errMsg)
                        {
                            sb.Append("\r\n" + err);
                        }
                        MessageBox.Show(this, sb.ToString());
                    }
                    else
                    {
                        MessageBox.Show(this, App.Current.FindResource("Message_18").ToString());
                    }
                }
                finally
                {
                    //关闭进度条蒙板
                    Dispatcher.Invoke(progressBarGridDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.Grid.VisibilityProperty, Visibility.Collapsed });
                }
                
            }
        }
Пример #2
0
        /// <summary>
        /// Technician发送数据事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SendDataButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(App.reportSettingModel.MailAddress) || string.IsNullOrEmpty(App.reportSettingModel.MailHost)
                || string.IsNullOrEmpty(App.reportSettingModel.MailUsername) || string.IsNullOrEmpty(App.reportSettingModel.MailPwd)
                || string.IsNullOrEmpty(App.reportSettingModel.ToMailAddress))
            {
                MessageBox.Show(this, App.Current.FindResource("Message_15").ToString());
                return;
            }
            string deviceNo = App.reportSettingModel.DeviceNo;
            int deviceType = App.reportSettingModel.DeviceType;
            var selectedUserList = this.CodeListBox.SelectedItems;
            if (selectedUserList == null || selectedUserList.Count == 0)
            {
                MessageBox.Show(this, App.Current.FindResource("Message_35").ToString());
                return;
            }

            MessageBoxResult result = MessageBox.Show(this, App.Current.FindResource("Message_17").ToString(), "Send Data", MessageBoxButton.YesNo, MessageBoxImage.Information);
            if (result == MessageBoxResult.Yes)
            {
                //判断报告是否已经填写Techinican名称
                SelectTechnicianPage SelectTechnicianPage = new SelectTechnicianPage(App.reportSettingModel.TechNames);
                SelectTechnicianPage.Owner = this;
                SelectTechnicianPage.ShowDialog();
                if (string.IsNullOrEmpty(App.reportSettingModel.ReportTechName))
                {
                    return;
                }

                //隐藏已MRN区域显示的上传过的图标
                foreach (Person selectedUser in selectedUserList)
                {
                    selectedUser.Uploaded = Visibility.Collapsed.ToString();
                }
                //定义委托代理
                ProgressBarGridDelegate progressBarGridDelegate = new ProgressBarGridDelegate(progressBarGrid.SetValue);
                UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(uploadProgressBar.SetValue);
                //使用系统代理方式显示进度条面板
                Dispatcher.Invoke(progressBarGridDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.Grid.VisibilityProperty, Visibility.Visible });
                try
                {
                    List<string> errMsg = new List<string>();
                    int n = 0;
                    double groupValue = 100 / selectedUserList.Count;
                    double sizeValue = groupValue / 10;
                    //循环处理选择的每一个患者档案
                    foreach (Person selectedUser in selectedUserList)
                    {
                        //string dataFile = dataFolder + System.IO.Path.DirectorySeparatorChar + selectedUser.Code + ".dat";
                        string dataFile = selectedUser.ArchiveFolder + System.IO.Path.DirectorySeparatorChar + selectedUser.Code + ".dat";
                        //如果是医生模式但当前的患者档案中却没有报告数据,则不能发送数据
                        if (!File.Exists(dataFile) && deviceType == 2)
                        {
                            errMsg.Add(selectedUser.Code + " :: " + App.Current.FindResource("Message_16").ToString());
                            continue;
                        }

                        //把检测员名称和证书写入.crd文件
                        try
                        {
                            OperateIniFile.WriteIniData("Report", "Technician Name", selectedUser.TechName, selectedUser.IniFilePath);
                            OperateIniFile.WriteIniData("Report", "Technician License", selectedUser.TechLicense, selectedUser.IniFilePath);
                            OperateIniFile.WriteIniData("Report", "Screen Venue", App.reportSettingModel.ScreenVenue, selectedUser.IniFilePath);                            
                        }
                        catch (Exception exe)
                        {
                            //如果不能写入ini文件
                            FileHelper.SetFolderPower(selectedUser.ArchiveFolder, "Everyone", "FullControl");
                            FileHelper.SetFolderPower(selectedUser.ArchiveFolder, "Users", "FullControl");
                        }

                        Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(groupValue * n + sizeValue) });

                        //打包数据文件,并上传到FPT服务
                        string zipFile = dataFolder + System.IO.Path.DirectorySeparatorChar + selectedUser.Code + "-" + selectedUser.SurName;
                        zipFile = zipFile + (string.IsNullOrEmpty(selectedUser.GivenName) ? "" : "," + selectedUser.GivenName) + (string.IsNullOrEmpty(selectedUser.OtherName) ? "" : " " + selectedUser.OtherName) + ".zip";

                        try
                        {
                            //ZipTools.Instance.ZipFolder(selectedUser.ArchiveFolder, zipFile, 1);
                            ZipTools.Instance.ZipFiles(selectedUser.ArchiveFolder, zipFile, 1);
                            Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(groupValue * n + sizeValue * 5) });
                        }
                        catch (Exception ex1)
                        {
                            errMsg.Add(selectedUser.Code + " :: " + string.Format(App.Current.FindResource("Message_21").ToString() + " " + ex1.Message, selectedUser.ArchiveFolder));
                            continue;
                        }

                        //上传到FTP服务器
                        try
                        {
                            FtpHelper.Instance.Upload(App.reportSettingModel.FtpUser, App.reportSettingModel.FtpPwd, App.reportSettingModel.FtpPath + "Send/", zipFile);
                            //上传成功后保存上传状态,以便让用户知道这个患者今天已经成功提交过数据
                            if (!App.uploadedCodeList.Contains(selectedUser.Code))
                            {
                                App.uploadedCodeList.Add(selectedUser.Code);
                            }
                            selectedUser.Uploaded = Visibility.Visible.ToString();
                            try
                            {
                                File.Delete(zipFile);
                            }
                            catch { }
                        }
                        catch (Exception ex2)
                        {
                            errMsg.Add(selectedUser.Code + " :: " + App.Current.FindResource("Message_52").ToString() + " " + ex2.Message);
                            continue;
                        }
                        Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(groupValue * n + sizeValue * 9) });

                        ////如果是检测员模式,则每天要上传一次扫描记录
                        //string currentDate = System.DateTime.Now.ToString("yyyyMMdd");
                        //if (App.countDictionary.Count > 0 && !currentDate.Equals(App.reportSettingModel.RecordDate))
                        //{
                        //    string excelFile = dataFolder + System.IO.Path.DirectorySeparatorChar + deviceNo + "_Count.xls";
                        //    try
                        //    {
                        //        if (File.Exists(excelFile))
                        //        {
                        //            try
                        //            {
                        //                File.Delete(excelFile);
                        //            }
                        //            catch { }
                        //        }
                        //        exportExcel(excelFile);
                        //        if (!FtpHelper.Instance.FolderExist(App.reportSettingModel.FtpUser, App.reportSettingModel.FtpPwd, App.reportSettingModel.FtpPath, "ScreeningRecords"))
                        //        {
                        //            FtpHelper.Instance.MakeDir(App.reportSettingModel.FtpUser, App.reportSettingModel.FtpPwd, App.reportSettingModel.FtpPath, "ScreeningRecords");
                        //        }
                        //        FtpHelper.Instance.Upload(App.reportSettingModel.FtpUser, App.reportSettingModel.FtpPwd, App.reportSettingModel.FtpPath + "/ScreeningRecords/", excelFile);
                        //        App.reportSettingModel.RecordDate = currentDate;
                        //        OperateIniFile.WriteIniData("Data", "Record Date", currentDate, System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini");
                        //        try
                        //        {
                        //            File.Delete(excelFile);
                        //        }
                        //        catch { }
                        //    }
                        //    catch { }
                        //}
                        n++;
                    }

                    try
                    {
                        //发送通知邮件  
                        SendEmail((selectedUserList.Count - errMsg.Count), true);
                    }
                    catch (Exception ex3)
                    {
                        errMsg.Add(App.Current.FindResource("Message_19").ToString() + " " + ex3.Message);
                    }

                    Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(100) });
                    //显示没有成功发送数据的错误消息
                    if (errMsg.Count > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append(string.Format(App.Current.FindResource("Message_36").ToString(), errMsg.Count));
                        foreach (var err in errMsg)
                        {
                            sb.Append("\r\n" + err);
                        }
                        MessageBox.Show(this, sb.ToString());
                    }
                    else
                    {
                        MessageBox.Show(this, App.Current.FindResource("Message_18").ToString());
                    }
                }
                finally
                {
                    Dispatcher.Invoke(progressBarGridDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.Grid.VisibilityProperty, Visibility.Collapsed });
                }
            }
        }
Пример #3
0
 private void tabSetting_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (e.AddedItems!=null&&e.AddedItems.Count > 0)
     {
         var tabItem=e.AddedItems[0] as TabItem;
         if (tabItem!=null&&"tabVersion".Equals(tabItem.Name))
         {
             if (this.radradDeviceType1.DataContext.Equals(App.reportSettingModel.DeviceType.ToString()))
             {
                 this.radradDeviceType1.IsChecked = true;
             }
             else if (this.radradDeviceType2.DataContext.Equals(App.reportSettingModel.DeviceType.ToString()))
             {
                 this.radradDeviceType2.IsChecked = true;
             }
             else
             {
                 this.radradDeviceType3.IsChecked = true;
             }
     
             //定义委托代理
             ProgressBarGridDelegate progressBarGridDelegate = new ProgressBarGridDelegate(progressBarGrid.SetValue);
             UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(uploadProgressBar.SetValue);
             //使用系统代理方式显示进度条面板
             Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(10) });
             Dispatcher.Invoke(progressBarGridDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.Grid.VisibilityProperty, Visibility.Visible });
             Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(20) });
             List<string> fileList = new List<string>();
             try
             {
                 string ftpPath = App.reportSettingModel.FtpPath.Replace("home", "MeikUpdate");
                 //查询FTP上所有版本文件列表要下载的文件列表
                 fileList = FtpHelper.Instance.GetFileList(App.reportSettingModel.FtpUser, App.reportSettingModel.FtpPwd, ftpPath);
                 Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(90) });
             }
             catch (Exception ex)
             {
                 MessageBox.Show(this, App.Current.FindResource("Message_47").ToString() + " " + ex.Message);
                 Dispatcher.Invoke(progressBarGridDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.Grid.VisibilityProperty, Visibility.Collapsed });
                 return;
             }
             try
             {
                 fileList.Reverse();
                 foreach (var setupFileName in fileList)
                 {
                     if (setupFileName.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
                     {
                         var verStr = setupFileName.ToLower().Replace(".exe", "").Replace("meiksetup.", "");
                         string currentVer = App.reportSettingModel.Version;
                         if (string.Compare(verStr, currentVer,StringComparison.OrdinalIgnoreCase) > 0)
                         {                                                                
                             labVerCheckInfo.Content = App.Current.FindResource("SettingVersionCheckInfo2").ToString();
                             btnUpdateNow.IsEnabled = true;                            
                         }
                         break;
                     }
                     else
                     {
                         continue;
                     }
                 }
             }
             catch (Exception ex1)
             {
                 MessageBox.Show(this, ex1.Message);
             }
             Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(100) });
             Dispatcher.Invoke(progressBarGridDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.Grid.VisibilityProperty, Visibility.Collapsed });
     
         }
     }
 }
Пример #4
0
        /// <summary>
        /// Technician模式接收PDF報告
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnReceivePdf_Click(object sender, RoutedEventArgs e)
        {
            ProgressBarGridDelegate progressBarGridDelegate = new ProgressBarGridDelegate(progressBarGrid.SetValue);
            UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(uploadProgressBar.SetValue);
            //使用系统代理方式显示进度条面板
            Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(0) });
            Dispatcher.Invoke(progressBarGridDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.Grid.VisibilityProperty, Visibility.Visible });
            
            List<string> errMsg = new List<string>();
            try
            {
                //查询FTP上要下载的文件列表
                var fileArr = FtpHelper.Instance.GetFileList(App.reportSettingModel.FtpUser, App.reportSettingModel.FtpPwd, App.reportSettingModel.FtpPath + "Receive/");
                //判断是否存在已下载的目录IsDownloaded
                if (!FtpHelper.Instance.FolderExist(App.reportSettingModel.FtpUser, App.reportSettingModel.FtpPwd, App.reportSettingModel.FtpPath, "IsDownloaded"))
                {
                    FtpHelper.Instance.MakeDir(App.reportSettingModel.FtpUser, App.reportSettingModel.FtpPwd, App.reportSettingModel.FtpPath, "IsDownloaded");
                }

                int n = 0;
                double groupValue = 100 / (fileArr.Count + 1);                

                foreach (var file in fileArr)
                {
                    if (file.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase))
                    {
                        Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(groupValue * n) });
                        n++;
                        //创建下载目录路径
                        string folderpath = "";
                        try
                        {
                            string monthfolder = file.Substring(2, 2) + "_20" + file.Substring(0, 2);
                            //folderpath = App.reportSettingModel.DataBaseFolder + System.IO.Path.DirectorySeparatorChar + monthfolder + System.IO.Path.DirectorySeparatorChar + file.Substring(4, 2);
                            folderpath = App.reportSettingModel.DataBaseFolder + System.IO.Path.DirectorySeparatorChar + monthfolder;
                            if (!Directory.Exists(folderpath))
                            {
                                Directory.CreateDirectory(folderpath);
                            }
                        }
                        catch (Exception e1)
                        {
                            //MessageBox.Show(this, e1.Message);
                            errMsg.Add(file + " :: " + App.Current.FindResource("Message_39").ToString() + e1.Message);
                            continue;
                        }
                        //从FTP下载PDF文件
                        try
                        {
                            FtpHelper.Instance.Download(App.reportSettingModel.FtpUser, App.reportSettingModel.FtpPwd, App.reportSettingModel.FtpPath + "Receive/", folderpath, file);
                            Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(groupValue * n + groupValue/2) });
                            FtpHelper.Instance.MovieFile(App.reportSettingModel.FtpUser, App.reportSettingModel.FtpPwd, App.reportSettingModel.FtpPath + "Receive/", file, "/home/IsDownloaded/" + file);
                        }
                        catch (Exception e2)
                        {
                            //MessageBox.Show(this, e2.Message);
                            errMsg.Add(file + " :: " + App.Current.FindResource("Message_40").ToString() + e2.Message);
                            continue;
                        }                        
                        
                    }
                }
                Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(100) });
                Dispatcher.Invoke(progressBarGridDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.Grid.VisibilityProperty, Visibility.Collapsed });
                if (errMsg.Count == 0)
                {
                    if (n == 0)
                    {
                        MessageBox.Show(this, App.Current.FindResource("Message_43").ToString());
                    }
                    else
                    {
                        MessageBox.Show(this, App.Current.FindResource("Message_37").ToString());
                    }
                }
                else
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append(App.Current.FindResource("Message_38").ToString());
                    foreach (var err in errMsg)
                    {
                        sb.Append("\r\n" + err);
                    }
                    MessageBox.Show(this, sb.ToString());
                }
            }
            catch (Exception exe)
            {
                Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(100) });
                Dispatcher.Invoke(progressBarGridDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.Grid.VisibilityProperty, Visibility.Collapsed });
                MessageBox.Show(this, App.Current.FindResource("Message_45").ToString() + exe.Message);
            }
        }
Пример #5
0
        //private void LoadInitConfig()
        //{
        //    //加载ini文件内容
        //    try
        //    {
        //        if (App.reportSettingModel == null)
        //        {
        //            App.reportSettingModel = new ReportSettingModel();
        //            App.reportSettingModel.MeikBase = OperateIniFile.ReadIniData("Base", "MEIK base", "C:\\MEIKData", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini");
        //            App.reportSettingModel.Version = OperateIniFile.ReadIniData("Base", "Version", "1.0.0", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini");
        //            App.reportSettingModel.HasNewer = Convert.ToBoolean(OperateIniFile.ReadIniData("Base", "Newer", "false", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini"));
        //            App.reportSettingModel.MailSsl = Convert.ToBoolean(OperateIniFile.ReadIniData("Report", "Use Default Signature", "false", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini"));
        //            string doctorNames = OperateIniFile.ReadIniData("Report", "Doctor Names List", "", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini");                    
        //            if (!string.IsNullOrEmpty(doctorNames))
        //            {                        
        //                var doctorList = doctorNames.Split(';').ToList<string>();
        //                //doctorList.ForEach(item => App.reportSettingModel.DoctorNames.Add(item));
        //                foreach (var item in doctorList)
        //                {
        //                    User doctorUser=new User();
        //                    string[] arr = item.Split('|');
        //                    doctorUser.Name = arr[0];
        //                    doctorUser.License = arr[1];
        //                    App.reportSettingModel.DoctorNames.Add(doctorUser);
        //                }                        
        //            }
        //            string techNames = OperateIniFile.ReadIniData("Report", "Technician Names List", "", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini");                    
        //            if (!string.IsNullOrEmpty(techNames))
        //            {
        //                var techList = techNames.Split(';').ToList<string>();
        //                //techList.ForEach(item => App.reportSettingModel.TechNames.Add(item));
        //                foreach (var item in techList)
        //                {
        //                    User techUser = new User();
        //                    string[] arr = item.Split('|');
        //                    techUser.Name = arr[0];
        //                    techUser.License = arr[1];
        //                    App.reportSettingModel.TechNames.Add(techUser);
        //                }
        //            }

        //            App.reportSettingModel.NoShowDoctorSignature = Convert.ToBoolean(OperateIniFile.ReadIniData("Report", "Hide Doctor Signature", "false", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini"));
        //            App.reportSettingModel.NoShowTechSignature = Convert.ToBoolean(OperateIniFile.ReadIniData("Report", "Hide Technician Signature", "false", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini"));
        //            App.reportSettingModel.FtpPath = OperateIniFile.ReadIniData("FTP", "FTP Path", "", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini");
        //            App.reportSettingModel.FtpUser = OperateIniFile.ReadIniData("FTP", "FTP User", "", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini");
        //            string ftpPwd = OperateIniFile.ReadIniData("FTP", "FTP Password", "", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini");
        //            if (!string.IsNullOrEmpty(ftpPwd))
        //            {
        //                App.reportSettingModel.FtpPwd = SecurityTools.DecryptText(ftpPwd);
        //            }
                    
        //            App.reportSettingModel.PrintPaper = (PageSize)Enum.Parse(typeof(PageSize),OperateIniFile.ReadIniData("Report", "Print Paper", "Letter", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini"),true);
        //            App.reportSettingModel.MailAddress = OperateIniFile.ReadIniData("Mail", "My Mail Address", "", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini");
        //            App.reportSettingModel.ToMailAddress = OperateIniFile.ReadIniData("Mail", "To Mail Address", "", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini");
        //            App.reportSettingModel.MailSubject = OperateIniFile.ReadIniData("Mail", "Mail Subject", "", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini");
        //            App.reportSettingModel.MailBody = OperateIniFile.ReadIniData("Mail", "Mail Content", "", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini");
        //            App.reportSettingModel.MailHost = OperateIniFile.ReadIniData("Mail", "Mail Host", "", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini");
        //            App.reportSettingModel.MailPort = Convert.ToInt32(OperateIniFile.ReadIniData("Mail", "Mail Port", "25", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini"));
        //            App.reportSettingModel.MailUsername = OperateIniFile.ReadIniData("Mail", "Mail Username", "", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini");
        //            string mailPwd=OperateIniFile.ReadIniData("Mail", "Mail Password", "", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini");
        //            if(!string.IsNullOrEmpty(mailPwd)){
        //                App.reportSettingModel.MailPwd = SecurityTools.DecryptText(mailPwd);
        //            }                    
        //            App.reportSettingModel.MailSsl = Convert.ToBoolean(OperateIniFile.ReadIniData("Mail", "Mail SSL", "false", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini"));
        //            App.reportSettingModel.DeviceNo = OperateIniFile.ReadIniData("Device", "Device No", "000", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini");
        //            App.reportSettingModel.DeviceType = Convert.ToInt32(OperateIniFile.ReadIniData("Device", "Device Type", "1", System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini"));
        //        }                
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(this, App.Current.FindResource("Message_9").ToString() + " " + ex.Message);
        //    }
                        
        //}
        

        /// <summary>
        /// 立即进行版本更新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpdateNow_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show(this, App.Current.FindResource("Message_46").ToString(), "Update Now", MessageBoxButton.YesNo, MessageBoxImage.Information);
            if (result == MessageBoxResult.Yes)
            {
                //定义委托代理
                ProgressBarGridDelegate progressBarGridDelegate = new ProgressBarGridDelegate(progressBarGrid.SetValue);
                UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(uploadProgressBar.SetValue);
                //使用系统代理方式显示进度条面板
                Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(5) });
                Dispatcher.Invoke(progressBarGridDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.Grid.VisibilityProperty, Visibility.Visible });
                
                try
                {
                    string ftpPath = App.reportSettingModel.FtpPath.Replace("home", "MeikUpdate");
                    //查询FTP上所有版本文件列表要下载的文件列表
                    var fileList = FtpHelper.Instance.GetFileList(App.reportSettingModel.FtpUser, App.reportSettingModel.FtpPwd, ftpPath);                    
                    fileList.Reverse();
                    foreach (var setupFileName in fileList)
                    {
                        if (setupFileName.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
                        {
                            var verStr = setupFileName.ToLower().Replace(".exe", "").Replace("meiksetup.", "");
                            string currentVer=App.reportSettingModel.Version;
                            if (string.Compare(verStr, currentVer,StringComparison.OrdinalIgnoreCase) > 0)
                            {
                                //下載新的升級安裝包
                                FtpWebRequest reqFTP;
                                try
                                {
                                    FileStream outputStream = new FileStream(App.reportSettingModel.DataBaseFolder + System.IO.Path.DirectorySeparatorChar + setupFileName, FileMode.Create);
                                    reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpPath + setupFileName));
                                    reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
                                    reqFTP.UseBinary = true;
                                    reqFTP.Credentials = new NetworkCredential(App.reportSettingModel.FtpUser, App.reportSettingModel.FtpPwd);
                                    reqFTP.UsePassive = false;
                                    FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
                                    Stream ftpStream = response.GetResponseStream();
                                    long cl = response.ContentLength;
                                    int bufferSize = 2048;
                                    double moveSize = 100d / (cl / 2048);
                                    int x = 1;
                                    int readCount;
                                    byte[] buffer = new byte[bufferSize];
                                    readCount = ftpStream.Read(buffer, 0, bufferSize);
                                    while (readCount > 0)
                                    {
                                        outputStream.Write(buffer, 0, readCount);
                                        readCount = ftpStream.Read(buffer, 0, bufferSize);
                                        Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(moveSize * x) });
                                        x++;
                                    }
                                    ftpStream.Close();
                                    outputStream.Close();
                                    response.Close();
                                }
                                catch (Exception ex2)
                                {
                                    throw ex2;
                                }

                                //FtpHelper.Instance.Download(App.reportSettingModel.FtpUser, App.reportSettingModel.FtpPwd, ftpPath, App.reportSettingModel.DataBaseFolder, setupFileName);
                                Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(100) });
                                Dispatcher.Invoke(progressBarGridDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.Grid.VisibilityProperty, Visibility.Collapsed });
                                MessageBox.Show(this, App.Current.FindResource("Message_48").ToString());

                                try
                                {
                                    //启动外部程序
                                    Process setupProc = Process.Start(App.reportSettingModel.DataBaseFolder + System.IO.Path.DirectorySeparatorChar + setupFileName);
                                    if (setupProc != null)
                                    {                                       
                                        //proc.WaitForExit();//等待外部程序退出后才能往下执行
                                        setupProc.WaitForInputIdle();                                        
                                        File.Copy(System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini", System.AppDomain.CurrentDomain.BaseDirectory + "Config_bak.ini", true);                                        
                                        OperateIniFile.WriteIniData("Base", "Version", verStr, System.AppDomain.CurrentDomain.BaseDirectory + "Config_bak.ini");                                                                       
                                        //关闭当前程序
                                        App.Current.Shutdown();
                                    }
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(App.Current.FindResource("Message_51").ToString() + " " + ex.Message);
                                }


                            }
                            break;
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, App.Current.FindResource("Message_47").ToString() + " " + ex.Message);
                }
                finally
                {
                    Dispatcher.Invoke(progressBarGridDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.Grid.VisibilityProperty, Visibility.Collapsed });
                }
            }
        }