コード例 #1
0
        /// <summary>
        /// 更新脚本
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnNext_Click(object sender, EventArgs e)
        {
            if (this.tbxServerIPAddress.Text.Trim().Length == 0)
            {
                MessageBox.Show("服务器地址不能为空!", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                return;
            }

            if (this.tbxDataBase.Text.Trim().Length == 0)
            {
                MessageBox.Show("数据库名称不能为空!", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                return;
            }

            if (this.tbxUserName.Text.Trim().Length == 0)
            {
                MessageBox.Show("用户名不能为空!", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                return;
            }
            if (this.tbxPassword.Text.Trim().Length == 0)
            {
                MessageBox.Show("密码不能为空!", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                return;
            }

            SqlHelper.ConnectionString = GetDataBaseConnectionString();

            //检查数据库连接
            try
            {
                UpdScriptService.ChkConnectSetting();
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
                MessageBox.Show("尝试连接数据库失败,请重新输入!", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                return;
            }

            this.Visible = false;
            //更新
            UpgradeForm updFileFrm = new UpgradeForm();

            updFileFrm.Show();
        }
コード例 #2
0
        /// <summary>
        /// 更新事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpgrade_Click(object sender, EventArgs e)
        {
            if (this.tbxFolderLocation.Text.Trim().Length == 0)
            {
                MessageBox.Show("网站根目录不能为空!", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                return;
            }

            if (MessageBox.Show("确定更新程序?", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
            {
                return;
            }

            //判断版本号
            ParamModel paramModel = UpdScriptService.GetParamByCode("VN");

            if (paramModel == null)
            {
                //初始化版本号
                paramModel           = new ParamModel();
                paramModel.ParamName = "V1.0.1";
                paramModel.ParamCode = "VN";
                UpdScriptService.InsertParam(paramModel);
            }
            else
            {
                string upgradeVersion = String.Format("{0}", System.Configuration.ConfigurationManager.AppSettings["UpgradeVersion"]);
                if (!(String.Compare(upgradeVersion, paramModel.ParamName) > 0))
                {
                    MessageBox.Show("升级版本不正确!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            //更新操作
            bgWorker.WorkerReportsProgress = true;
            bgWorker.RunWorkerAsync();
            progressFrm.ShowDialog();
        }
コード例 #3
0
        /// <summary>
        /// 更新脚本
        /// </summary>
        private bool UpgradeScript()
        {
            try
            {
                string scriptPath = string.Format("{0}{1}", Application.StartupPath, System.Configuration.ConfigurationManager.AppSettings["ScriptsPath"]);
                UpdScriptService.ExcuteScript(scriptPath);
                bgWorker.ReportProgress(50);
                return(true);
            }
            catch (Exception ex)
            {
                log.Error("更新脚本失败,错误信息:" + ex.Message);

                string rollBackScript = String.Format("{0}", System.Configuration.ConfigurationManager.AppSettings["RollBackScript"]);
                if (rollBackScript == "true")
                {
                    string rollBackScriptPath = string.Format("{0}{1}", Application.StartupPath, System.Configuration.ConfigurationManager.AppSettings["RollBackScriptPath"]);
                    UpdScriptService.ExcuteScript(rollBackScriptPath);
                }
                return(false);
            }
        }
コード例 #4
0
        private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            progressFrm.Close();
            if (updSuccess == true)
            {
                //更新版本号
                ParamModel paramModel = new ParamModel();
                paramModel.ParamName = String.Format("{0}", System.Configuration.ConfigurationManager.AppSettings["UpgradeVersion"]);
                paramModel.ParamCode = "VN";
                UpdScriptService.UpdateParam(paramModel);

                //提示成功
                this.Visible = false;
                if (MessageBox.Show("更新成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    Application.Exit();
                }
            }
            else
            {
                //提示失败
                MessageBox.Show("更新失败,请查看日志文件!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }