Esempio n. 1
0
        protected void wzdInstaller_OnNextButtonClick(object sender, WizardNavigationEventArgs e)
        {
            if (this.wzdInstaller.ActiveStepIndex == this.wzdInstaller.WizardSteps.IndexOf(this.stpWelcome))
            {
                #region Welcome screen
                this.Install = this.rbInstall.Checked;
                #endregion
            }
            else if (this.wzdInstaller.ActiveStepIndex == this.wzdInstaller.WizardSteps.IndexOf(this.stpUserServer))
            {
                #region Server
                ViewState["install.password"] = this.txtPassword.Text;

                this.TrustedConnection = this.rbWindowsAuthentication.Checked;

                if (String.IsNullOrEmpty(this.txtServerName.Text.Trim()))
                {
                    handleError("Please enter the SQL Server name or IP address");
                    e.Cancel = true;
                    return;
                }
                string error = InstallerHelper.TestConnection(this.TrustedConnection, this.txtServerName.Text.Trim(), string.Empty, this.txtUsername.Text.Trim(), Convert.ToString(ViewState["install.password"]));
                if (!String.IsNullOrEmpty(error))
                {
                    handleError(error);
                    e.Cancel = true;
                    return;
                }
                #endregion
            }
            else if (this.wzdInstaller.ActiveStepIndex == this.wzdInstaller.WizardSteps.IndexOf(this.stpDatabase))
            {
                #region Database
                string database = string.Empty;
                if (rbCreateNew.Checked)
                {
                    database = txtNewDatabaseName.Text.Trim();
                }
                else
                {
                    database = txtExistingDatabaseName.Text.Trim();
                }
                this.ConnectionString = InstallerHelper.CreateConnectionString(this.TrustedConnection, this.txtServerName.Text.Trim(), database, this.txtUsername.Text.Trim(), Convert.ToString(ViewState["install.password"]), 120);

                if (this.rbUseExisting.Checked)
                {
                    // Use existing database
                    if (String.IsNullOrEmpty(database))
                    {
                        handleError("Please enter the database name");
                        e.Cancel = true;
                        return;
                    }
                    else
                    {
                        if (!chkDontCheckDatabase.Checked)
                        {
                            if (!InstallerHelper.DatabaseExists(this.TrustedConnection, this.txtServerName.Text.Trim(), database, this.txtUsername.Text.Trim(), Convert.ToString(ViewState["install.password"])))
                            {
                                handleError(string.Format("The database '{0}' doesn't exist!", database));
                                e.Cancel = true;
                                return;
                            }
                        }
                    }
                }
                else
                {
                    // Create a new database
                    if (!createDatabase())
                    {
                        handleError(string.Format("Error creating the Database {0}", this.txtNewDatabaseName.Text));
                        e.Cancel = true;
                        return;
                    }
                    else
                    {
                        this.txtExistingDatabaseName.Text = this.txtNewDatabaseName.Text;
                        this.rbCreateNew.Checked          = false;
                        this.rbUseExisting.Checked        = true;
                    }
                }

                if (this.Install)
                {
                    bool createSampleData = chkCreateSampleData.Checked;
                    if (!installDatabase(ConnectionString, createSampleData))
                    {
                        handleError("An error occured during the database setup");
                        e.Cancel = true;
                        return;
                    }
                }
                else
                {
                    string currentVersion = InstallerHelper.GetCurrentVersion(this.ConnectionString);


                    if (String.IsNullOrEmpty(currentVersion))
                    {
                        handleError("Upgrade script from your version is not available");
                        e.Cancel = true;
                        return;
                    }

                    if (currentVersion == newVersion)
                    {
                        handleError(string.Format("You already have version '{0}'", currentVersion));
                        e.Cancel = true;
                        return;
                    }

                    if (!upgradeableVersions.Contains(currentVersion))
                    {
                        handleError(string.Format("Upgrade script from your version '{0}' to '{1}' is not available", currentVersion, newVersion));
                        e.Cancel = true;
                        return;
                    }

                    bool flag1 = false;
                    foreach (string version in upgradeableVersions)
                    {
                        if (currentVersion == version)
                        {
                            flag1 = true;
                            continue;
                        }

                        if (flag1)
                        {
                            if (!upgradeDatabase(version, ConnectionString))
                            {
                                handleError("An error occured during the database upgrade");
                                e.Cancel = true;
                                return;
                            }
                        }
                    }
                }

                string setCurrentVersionError = InstallerHelper.SetCurrentVersion(this.ConnectionString, newVersion);
                if (!String.IsNullOrEmpty(setCurrentVersionError))
                {
                    this.pnlLog.Visible = true;
                    addResult(string.Format("An error occured during setting new version: {0}", setCurrentVersionError));
                    return;
                }

                this.pnlLog.Visible = false;

                if (InstallerHelper.SaveConnectionString("NopSqlConnection", ConnectionString))
                {
                    wzdInstaller.ActiveStepIndex = this.wzdInstaller.WizardSteps.IndexOf(this.stpFinish);
                }
                else
                {
                    string connStringDisplay = InstallerHelper.CreateConnectionString(this.TrustedConnection, this.txtServerName.Text.Trim(), database, this.txtUsername.Text.Trim(), Convert.ToString(ViewState["install.password"]), 120);
                    wzdInstaller.ActiveStepIndex = this.wzdInstaller.WizardSteps.IndexOf(this.stpConnectionString);
                    string message = "The installer couldn't update the ConnectionStrings.config file on your server. This may be caused by limited file system permissions. Please open your ConnectionStrings.config file manually in Notepad and add the following line inside the &lt;connectionStrings&gt;&lt;/connectionStrings&gt;: <br/><br/><b>&lt;add name=\"NopSqlConnection\" connectionString=\"" + connStringDisplay + "\"/&gt;</b><br/><br/>";
                    lblErrorConnMessage.Text = message;
                }
                #endregion
            }
            else if (this.wzdInstaller.ActiveStepIndex == this.wzdInstaller.WizardSteps.IndexOf(this.stpConnectionString))
            {
                #region Connection String
                if (NopConfig.ConnectionString != ConnectionString)
                {
                    handleError("The connection string you added doesn't match. Make sure, the connection string is correct.");
                    e.Cancel = true;
                    return;
                }
                else
                {
                    wzdInstaller.ActiveStepIndex = this.wzdInstaller.WizardSteps.IndexOf(this.stpFinish);
                }
                #endregion
            }
        }
Esempio n. 2
0
        protected void wzdInstaller_OnNextButtonClick(object sender, WizardNavigationEventArgs e)
        {
            if (this.wzdInstaller.ActiveStepIndex == this.wzdInstaller.WizardSteps.IndexOf(this.stpWelcome))
            {
                this.Install = this.rbInstall.Checked;
            }
            else if (this.wzdInstaller.ActiveStepIndex == this.wzdInstaller.WizardSteps.IndexOf(this.stpUserServer))
            {
                ViewState["install.password"]    = this.txtPassword.Text;
                ViewState["install.hisPassword"] = this.txtHisPassword.Text;
                this.TrustedConnection           = this.rbWindowsAuthentication.Checked;
                this.HisTrustedConnection        = this.rbHisWindowsAuthentication.Checked;
                if (String.IsNullOrEmpty(this.txtServerName.Text.Trim()))
                {
                    handleError("请输入配置库服务器的IP地址");
                    e.Cancel = true;
                    return;
                }
                if (String.IsNullOrEmpty(this.txtHisServerName.Text.Trim()))
                {
                    handleError("请输入历史库服务器的IP地址");
                    e.Cancel = true;
                    return;
                }

                var error = InstallerHelper.TestConnection(this.TrustedConnection, this.txtServerName.Text.Trim(), Int32.Parse(this.txtServerPort.Text.Trim()), String.Empty, this.txtUsername.Text.Trim(), ViewState["install.password"].ToString());
                if (!String.IsNullOrEmpty(error))
                {
                    handleError(error);
                    e.Cancel = true;
                    return;
                }
                error = InstallerHelper.TestConnection(this.HisTrustedConnection, this.txtHisServerName.Text.Trim(), Int32.Parse(this.txtHisServerPort.Text.Trim()), String.Empty, this.txtHisUsername.Text.Trim(), ViewState["install.hisPassword"].ToString());
                if (!String.IsNullOrEmpty(error))
                {
                    handleError(error);
                    e.Cancel = true;
                    return;
                }
            }
            else if (this.wzdInstaller.ActiveStepIndex == this.wzdInstaller.WizardSteps.IndexOf(this.stpDatabase))
            {
                var database = String.Empty;
                if (rbCreateNew.Checked)
                {
                    database = txtNewDatabaseName.Text.Trim();
                }
                else
                {
                    database = txtExistingDatabaseName.Text.Trim();
                }
                this.ConnectionString = InstallerHelper.CreateConnectionString(this.TrustedConnection, this.txtServerName.Text.Trim(), Int32.Parse(this.txtServerPort.Text.Trim()), database, this.txtUsername.Text.Trim(), ViewState["install.password"].ToString(), 120);

                var hisDatabase = String.Empty;
                if (rbHisCreateNew.Checked)
                {
                    hisDatabase = txtHisNewDatabaseName.Text.Trim();
                }
                else
                {
                    hisDatabase = txtHisExistingDatabaseName.Text.Trim();
                }
                this.HisConnectionString = InstallerHelper.CreateConnectionString(this.HisTrustedConnection, this.txtHisServerName.Text.Trim(), Int32.Parse(this.txtHisServerPort.Text.Trim()), hisDatabase, this.txtHisUsername.Text.Trim(), ViewState["install.hisPassword"].ToString(), 120);

                if (this.rbUseExisting.Checked)
                {
                    if (String.IsNullOrEmpty(database))
                    {
                        handleError("请输入配置库名称");
                        e.Cancel = true;
                        return;
                    }
                    else
                    {
                        if (!chkDontCheckDatabase.Checked)
                        {
                            if (!InstallerHelper.DatabaseExists(this.TrustedConnection, this.txtServerName.Text.Trim(), Int32.Parse(this.txtServerPort.Text.Trim()), database, this.txtUsername.Text.Trim(), ViewState["install.password"].ToString()))
                            {
                                handleError(String.Format("配置库 '{0}' 不存在!", database));
                                e.Cancel = true;
                                return;
                            }
                        }
                    }
                }
                else
                {
                    if (!createDatabase())
                    {
                        handleError(String.Format("创建配置库错误: {0}", this.txtNewDatabaseName.Text));
                        e.Cancel = true;
                        return;
                    }
                    else
                    {
                        this.txtExistingDatabaseName.Text = this.txtNewDatabaseName.Text;
                        this.rbCreateNew.Checked          = false;
                        this.rbUseExisting.Checked        = true;
                    }
                }

                if (this.rbHisUseExisting.Checked)
                {
                    if (String.IsNullOrEmpty(hisDatabase))
                    {
                        handleError("请输入历史库名称");
                        e.Cancel = true;
                        return;
                    }
                    else
                    {
                        if (!chkHisDontCheckDatabase.Checked)
                        {
                            if (!InstallerHelper.DatabaseExists(this.HisTrustedConnection, this.txtHisServerName.Text.Trim(), Int32.Parse(this.txtHisServerPort.Text.Trim()), hisDatabase, this.txtHisUsername.Text.Trim(), ViewState["install.hisPassword"].ToString()))
                            {
                                handleError(String.Format("历史库 '{0}' 不存在!", database));
                                e.Cancel = true;
                                return;
                            }
                        }
                    }
                }
                else
                {
                    if (!createHisDatabase())
                    {
                        handleError(String.Format("创建历史库错误: {0}", this.txtHisNewDatabaseName.Text));
                        e.Cancel = true;
                        return;
                    }
                    else
                    {
                        this.txtHisExistingDatabaseName.Text = this.txtHisNewDatabaseName.Text;
                        this.rbHisCreateNew.Checked          = false;
                        this.rbHisUseExisting.Checked        = true;
                    }
                }

                if (this.Install)
                {
                    if (!installDatabase(ConnectionString))
                    {
                        handleError("在配置库安装过程中捕获异常");
                        e.Cancel = true;
                        return;
                    }

                    if (!installHisDatabase(HisConnectionString))
                    {
                        handleError("在历史库安装过程中捕获异常");
                        e.Cancel = true;
                        return;
                    }
                }
                else
                {
                    if (String.IsNullOrEmpty(currentVersion))
                    {
                        handleError("无法找到当前版本,升级失败");
                        e.Cancel = true;
                        return;
                    }

                    if (currentVersion == newVersion)
                    {
                        handleError(String.Format("已经是最新版本 '{0}'", currentVersion));
                        e.Cancel = true;
                        return;
                    }

                    if (!upgradeableVersions.Contains(currentVersion))
                    {
                        handleError(String.Format("从版本 '{0}' 升级到版本 '{1}' 无效", currentVersion, newVersion));
                        e.Cancel = true;
                        return;
                    }

                    bool flag1 = false;
                    foreach (var version in upgradeableVersions)
                    {
                        if (currentVersion == version)
                        {
                            flag1 = true;
                            continue;
                        }

                        if (flag1)
                        {
                            if (!upgradeDatabase(version, ConnectionString))
                            {
                                handleError("更新配置库脚本时捕获异常");
                                e.Cancel = true;
                                return;
                            }

                            if (!upgradeHisDatabase(version, ConnectionString))
                            {
                                handleError("更新历史库脚本时捕获异常");
                                e.Cancel = true;
                                return;
                            }
                        }
                    }
                }

                var setCurrentVersionError = InstallerHelper.SetCurrentVersion(newVersion);
                if (!String.IsNullOrEmpty(setCurrentVersionError))
                {
                    this.pnlLog.Visible = true;
                    addResult(String.Format("设置新版本时捕获异常: {0}", setCurrentVersionError));
                    return;
                }

                this.pnlLog.Visible = false;
                if (InstallerHelper.SaveConnectionString(SqlHelper.ConnectionStringLocalName, ConnectionString) && InstallerHelper.SaveConnectionString(SqlHelper.HisConnectionStringLocalName, HisConnectionString))
                {
                    this.gvLsc_DataBind();
                    wzdInstaller.ActiveStepIndex = this.wzdInstaller.WizardSteps.IndexOf(this.stpLscSetting);
                }
                else
                {
                    wzdInstaller.ActiveStepIndex = this.wzdInstaller.WizardSteps.IndexOf(this.stpConnectionString);
                    lblErrorConnMessage.Text     = String.Format("此安装无法更新服务器上的ConnectionStrings.config配置文件,这可能由于修改此文件的系统权限被限制。请用记事本打开服务器上的ConnectionStrings.config配置文件,手动添加以下信息到 &lt;connectionStrings&gt;&lt;/connectionStrings&gt;节点之内: <br/><b>&lt;clear /&gt;<br/>&lt;add name=\"{0}\" connectionString=\"{1}\" /&gt;<br/>&lt;add name=\"{2}\" connectionString=\"{3}\" /&gt;</b><br/>", SqlHelper.ConnectionStringLocalName, ConnectionString, SqlHelper.HisConnectionStringLocalName, HisConnectionString);
                    lblErrorConnMessage.Visible  = true;
                }
            }
            else if (this.wzdInstaller.ActiveStepIndex == this.wzdInstaller.WizardSteps.IndexOf(this.stpConnectionString))
            {
                if (InstallerHelper.ConnectionString != ConnectionString || InstallerHelper.HisConnectionString != HisConnectionString)
                {
                    handleError("已存在的连接字符串与生成的连接字符串不匹配,请确认连接字符串是否正确。");
                    e.Cancel = true;
                    return;
                }
                else
                {
                    this.gvLsc_DataBind();
                    wzdInstaller.ActiveStepIndex = this.wzdInstaller.WizardSteps.IndexOf(this.stpLscSetting);
                }
            }
            else if (this.wzdInstaller.ActiveStepIndex == this.wzdInstaller.WizardSteps.IndexOf(this.stpLscSetting))
            {
                if (!InstallerHelper.LscDataExists())
                {
                    handleError("必须配置LSC信息,否则系统无法正常使用。");
                    e.Cancel = true;
                    return;
                }
            }
            else if (this.wzdInstaller.ActiveStepIndex == this.wzdInstaller.WizardSteps.IndexOf(this.stpStartService))
            {
            }
        }