public bool TestMySql(string connStr)
 {
     try
     {
         connStr = connStr.Trim();
         if (CheckDBUpdateTool.TestMySqlConn(connStr))
         {
             MessageBoxX.Show("数据库连接成功!", "成功");
             this.BtnCheckDBUpdateEnabled = "True";
             return(true);
         }
         MessageBoxX.Show("数据库连接失败!", "失败");
         return(false);
     }
     catch (Exception)
     {
         MessageBoxX.Show("数据库连接失败!", "失败");
         return(false);
     }
 }
        public bool TestMySql(string connStr)
        {
            string message = "数据库连接失败:";

            try
            {
                connStr = connStr.Trim();
                if (CheckDBUpdateTool.TestMySqlConn(connStr))
                {
                    ShowMessage("数据库连接成功!");
                    this.EnableCheckUpdateResult = true;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                message += ex.ToString();
            }
            ShowMessage(message);
            MessageBoxHelper.MessageBoxShowWarning("数据库连接失败!");
            return(false);
        }
        private void CheckDBUpdate(object parameter)
        {
            try
            {
                string mySqlConnStr = GetConnStr();
                if (string.IsNullOrEmpty(mySqlConnStr))
                {
                    MessageBoxX.Show("请输入完整的数据库连接信息", "错误");
                    return;
                }
                if (string.IsNullOrEmpty(this.PackageFilePath))
                {
                    MessageBoxX.Show("安装包路径不能为空", "失败");
                    return;
                }
                string packagePath = this.PackageFilePath.Trim();

                packagePath = Path.Combine(packagePath, "sys\\DbInitScript");
                var files = from file in Directory.EnumerateFiles(packagePath, "*.json*", SearchOption.TopDirectoryOnly)
                            select file;

                if (files == null || files.Count() == 0)
                {
                    MessageBoxX.Show($"未找到数据库对比文件{packagePath}\\xxxxx.json", "失败");
                    return;
                }
                string packageDbJsonFile = files.First();
                if (TestMySql(mySqlConnStr))
                {
                    if (CheckDBUpdateTool.CheckDBUpdate(packageDbJsonFile, mySqlConnStr))
                    {
                        MessageBoxX.Show($"数据库升级成功!", "成功", null, MessageBoxButton.OK);
                    }
                    else
                    {
                        MessageBoxX.Show($"数据库升级失败!\n请按照下方步骤升级。", "失败", null, MessageBoxButton.OK);
                    }
                }
            }
            catch (UnauthorizedAccessException)
            {
                string msg = "检查升级出错,文件没有访问权限,请设置文件夹读写权限\n";
                MessageBoxX.Show(msg, "异常");
                return;
            }
            catch (PathTooLongException)
            {
                string msg = "检查升级出错,软件安装目录或安装包目录 指定的路径或文件名超过了系统定义的最大长度\n";
                MessageBoxX.Show(msg, "异常");
                return;
            }
            catch (DirectoryNotFoundException)
            {
                string msg = "检查升级出错,所检查的目录不存在\n";
                MessageBoxX.Show(msg, "异常");
                return;
            }
            catch (Exception)
            {
                string msg = "程序异常";
                MessageBoxX.Show(msg, "异常");
                return;
            }
        }
        private void CheckDBUpdate(object parameter)
        {
            string msg = "";

            try
            {
                string mySqlConnStr = GetConnStr();
                if (string.IsNullOrEmpty(mySqlConnStr))
                {
                    MessageBoxHelper.MessageBoxShowWarning("请输入完整的数据库连接信息");
                    return;
                }
                if (string.IsNullOrEmpty(CheckUpdateContext.SetUpPackagePath))
                {
                    MessageBoxHelper.MessageBoxShowWarning("安装包路径不能为空");
                    return;
                }
                string packagePath = CheckUpdateContext.SetUpPackagePath.Trim();

                packagePath = Path.Combine(packagePath, "DbInitScript");
                var files = from file in Directory.EnumerateFiles(packagePath, "*.json*", SearchOption.TopDirectoryOnly)
                            select file;

                if (files == null || files.Count() == 0)
                {
                    MessageBoxHelper.MessageBoxShowWarning($"未找到数据库对比文件{packagePath}\\xxxxx.json");
                    return;
                }
                string packageDbJsonFile = files.First();
                if (TestMySql(mySqlConnStr))
                {
                    if (CheckDBUpdateTool.CheckDBUpdate(packageDbJsonFile, mySqlConnStr))
                    {
                        MessageBoxHelper.MessageBoxShowSuccess("数据库升级成功!");
                        return;
                    }
                    else
                    {
                        Notice.Show("数据库升级失败", "通知", 3, MessageBoxIcon.Warning);
                        UpdateFaildNotify?.Invoke("CheckScripts");
                    }
                }
            }
            catch (UnauthorizedAccessException)
            {
                msg = "检查升级出错,文件没有访问权限,请设置文件夹读写权限";
            }
            catch (PathTooLongException)
            {
                msg = "检查升级出错,软件安装目录或安装包目录 指定的路径或文件名超过了系统定义的最大长度";
            }
            catch (DirectoryNotFoundException)
            {
                msg = "检查升级出错,所检查的目录不存在";
            }
            catch (Exception ex)
            {
                msg = "程序异常:" + ex.ToString();
            }

            ShowMessage(msg);
            MessageBoxHelper.MessageBoxShowError("检查升级出错!");
        }