Exemplo 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
            }
        }