📄 default.aspx
字号:
SqlCommand cmd = new SqlCommand("select count(*) from cs_SchemaVersion", connection);
cmd.CommandType = CommandType.Text;
SqlDataReader reader = null;
try {
reader = cmd.ExecuteReader();
}
catch(Exception e ) {
ReportException( "IsSchemaExisting", e );
}
if( reader != null ) {
reader.Read();
if( reader[0] != null && Int32.Parse(reader[0].ToString()) > 0 ) {
returnValue = true;
}
}
}
return returnValue;
}
public bool IsForumsSchemaExisting() {
bool returnValue = false;
using( SqlConnection connection = new SqlConnection(GetDatabaseConnectionString()) ) {
connection.Open();
SqlCommand cmd = new SqlCommand("select count(*) from forums_Users", connection);
cmd.CommandType = CommandType.Text;
SqlDataReader reader = null;
try {
reader = cmd.ExecuteReader();
if( reader != null ) {
reader.Read();
if( reader[0] != null && Int32.Parse(reader[0].ToString()) > 0 ) {
returnValue = true;
}
}
}
catch(Exception e ) {
ReportException( "IsForumExisting", e );
}
}
return returnValue;
}
public bool ExecuteCreateCommunity() {
bool returnValue = false;
using( SqlConnection connection = new SqlConnection(GetDatabaseConnectionString()) ) {
connection.Open();
SqlCommand cmd = new SqlCommand("cs_system_CreateCommunity", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@SiteUrl", SqlDbType.NVarChar, 512).Value = cs_siteurl.Text;
cmd.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 512).Value = "dev"; //cs_application_name.Text;
cmd.Parameters.Add("@AdminUserName", SqlDbType.NVarChar, 256).Value = cs_username_login.Text;
if( cs_password_login.Text != String.Empty )
cmd.Parameters.Add("@AdminPassword", SqlDbType.NVarChar, 256).Value = cs_password_login.Text;
cmd.Parameters.Add("@CreateSamples", SqlDbType.Bit).Value = chkCreateSample.Checked ;
try {
cmd.ExecuteNonQuery();
returnValue = true;
}
catch( Exception e ) {
ReportException( "CreateCommunity", e );
}
return returnValue;
}
}
public bool ExecuteSqlInFile(string pathToScriptFile ) {
SqlConnection connection;
try {
StreamReader _reader = null;
string sql = "";
if( false == System.IO.File.Exists( pathToScriptFile )) {
throw new Exception("File " + pathToScriptFile + " does not exists");
}
using( Stream stream = System.IO.File.OpenRead( pathToScriptFile ) ) {
_reader = new StreamReader( stream , System.Text.Encoding.Default);
connection = new SqlConnection(GetDatabaseConnectionString());
SqlCommand command = new SqlCommand();
connection.Open();
command.Connection = connection;
command.CommandType = System.Data.CommandType.Text;
while( null != (sql = ReadNextStatementFromStream( _reader ) )) {
command.CommandText = sql;
command.ExecuteNonQuery();
}
_reader.Close();
}
return true;
}
catch(Exception ex) {
ReportException( "ExecuteSqlInFile" , "Error in file:" + pathToScriptFile + "<br/>" + "Message:" + ex.Message );
return false;
}
connection.Close();
}
private static string ReadNextStatementFromStream( StreamReader _reader ) {
try {
StringBuilder sb = new StringBuilder();
string lineOfText;
while(true) {
lineOfText = _reader.ReadLine();
if( lineOfText == null ) {
if( sb.Length > 0 ) {
return sb.ToString();
}
else {
return null;
}
}
if( lineOfText.TrimEnd().ToUpper() == "GO" ) {
break;
}
sb.Append(lineOfText + Environment.NewLine);
}
return sb.ToString();
}
catch( Exception ex ) {
return null;
}
}
private string GetConnectionString() {
return String.Format("server={0};uid={1};pwd={2};Trusted_Connection={3}", db_server.Text, db_login.Text, db_password.Text, (db_Connect.SelectedIndex == 0 ? "yes" : "no"));
}
private string GetDatabaseConnectionString() {
return String.Format("{0};database={1}", GetConnectionString(), db_name_list.SelectedValue);
}
private bool Validate_ConnectToDb(out string errorMessage) {
// ConnectionString = "server=" + db_server.Text + ";uid="+ db_login.Text +";pwd=" + db_password.Text + ";Trusted_Connection=" + (db_Connect.SelectedIndex == 0 ? "yes" : "no");
try {
SqlConnection connection = new SqlConnection(GetConnectionString());
connection.Open();
connection.Close();
errorMessage = "";
return true;
} catch (Exception e) {
errorMessage = e.Message;
return false;
}
}
private bool Validate_SelectDb(out string errorMessage) {
try {
using( SqlConnection connection = new SqlConnection(GetDatabaseConnectionString() )) {
connection.Open();
connection.Close();
}
errorMessage = "";
return true;
}
catch( SqlException se ) {
switch( se.Number ) {
case 4060: // login fails
if( db_Connect.SelectedIndex == 0) {
errorMessage = "The installer is unable to access the specified database using the Windows credentials that the web server is running under. Contact your system administrator to have them add " + Environment.UserName + " to the list of authorized logins";
}
else {
errorMessage = "You can't login to that database. Please select another one<br />" + se.Message;
}
break;
default:
errorMessage = String.Format("Number:{0}:<br/>Message:{1}", se.Number, se.Message);
break;
}
return false;
}
catch( Exception e ) {
errorMessage = e.Message;
return false;
}
}
private bool Validate_SelectDb_ListDatabases(out string errorMessage) {
try {
SqlConnection connection = new SqlConnection(GetConnectionString());
SqlDataReader dr;
SqlCommand command = new SqlCommand("select name from master..sysdatabases order by name asc", connection);
connection.Open();
// Change to the master database
//
connection.ChangeDatabase("master");
dr = command.ExecuteReader();
db_name_list.Items.Clear();
while (dr.Read())
{
string dbName = dr["name"] as String;
if( dbName != null ) {
if( dbName == "master" ||
dbName == "msdb" ||
dbName == "tempdb" ||
dbName == "model" ) {
// skip the system databases
continue;
}
else {
db_name_list.Items.Add( dbName );
}
}
}
connection.Close();
errorMessage = "";
return true;
}
catch( Exception e ) {
errorMessage = e.Message;
return false;
}
}
public void NextPanel (Object sender, EventArgs e) {
string errorMessage = "";
switch (CurrentWizardPanel) {
case WizardPanel.Welcome:
SetActivePanel (WizardPanel.License, License);
break;
case WizardPanel.License:
if( chkIAgree.Checked )
SetActivePanel (WizardPanel.ConnectToDb, ConnectToDb);
break;
case WizardPanel.ConnectToDb:
if (Validate_ConnectToDb(out errorMessage)) {
if( Validate_SelectDb_ListDatabases(out errorMessage)) {
if( this.Request.QueryString[QSK_DATABASE] != null &&
this.Request.QueryString[QSK_DATABASE] != String.Empty ) {
try {
db_name_list.SelectedValue = HttpUtility.UrlDecode(this.Request.QueryString[QSK_DATABASE]);
SetActivePanel(WizardPanel.ScriptOptions, ScriptOptions );
}
catch {
// an error occured setting the database, lets let the user select the database
SetActivePanel(WizardPanel.SelectDb, SelectDb);
}
}
else
SetActivePanel (WizardPanel.SelectDb, SelectDb);
}
else {
lblErrMsgConnect.Text = errorMessage;
}
}
else {
lblErrMsgConnect.Text = errorMessage;
}
break;
case WizardPanel.SelectDb:
if (Validate_SelectDb(out errorMessage)) {
SetActivePanel (WizardPanel.ScriptOptions, ScriptOptions);
if( IsSchemaExisting() || IsForumsSchemaExisting() ) {
SetActivePanel( WizardPanel.SchemaExists, SchemaExists );
}
}
else {
lblErrMsg.Text = errorMessage;
}
break;
case WizardPanel.ScriptOptions:
SetActivePanel (WizardPanel.CreateCommunity, CreateCommunity);
if( cs_siteurl != null )
{
string hostName = Request.Url.Host.Replace("www.",string.Empty);
string applicationPath = Request.ApplicationPath;
if(applicationPath.EndsWith("/"))
applicationPath = applicationPath.Remove(applicationPath.Length-1,1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -