|
using System;
using System.Windows.Forms;
using ClassGeneratorEvents;
namespace ClassGeneratorControls
{
/// <summary>
/// The class that contains that contains the server box information.
/// </summary>
public partial class ServerBox : UserControl
{
private DatabaseBox databaseBox;
/// <summary>
/// The constructor that initializes the server box class.
/// </summary>
/// <param name="databaseBox">The database box object.</param>
public ServerBox(DatabaseBox databaseBox)
{
InitializeComponent();
this.databaseBox = databaseBox;
}
/// <summary>
/// The instance of the server.
/// </summary>
public string ServerInstance
{
get { return txtServerName.Text; }
set { txtServerName.Text = value; }
}
/// <summary>
/// The username of the server.
/// </summary>
public string ServerUsername
{
get { return txtUsername.Text; }
set { txtUsername.Text = value; }
}
/// <summary>
/// The password of the server.
/// </summary>
public string ServerPassword
{
get { return txtPassword.Text; }
set { txtPassword.Text = value; }
}
/// <summary>
/// Checks whether the values are empty are not.
/// </summary>
public bool IsValuesEmpty
{
get { return string.IsNullOrEmpty(txtServerName.Text) || string.IsNullOrEmpty(txtUsername.Text) || string.IsNullOrEmpty(txtPassword.Text); }
}
private void btnConnect_Click(object sender, System.EventArgs e)
{
try
{
ServerBoxEvents serverBoxEvent = new ServerBoxEvents(this);
if (IsValuesEmpty)
CommonFunctions.ShowMessageBox("Please enter Server Name, Username and Password!", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
{
bool connectionResult = serverBoxEvent.Connect();
if (connectionResult)
{
databaseBox.Databases = CommonFunctions.SqlServerEventHandler.GetDatabases();
CommonFunctions.ShowMessageBox("Connection successful!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
CommonFunctions.ShowMessageBox("Connection failed, please check whether the server name, username and password are correct!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
CommonFunctions.ShowMessageBox("Error occured while establishing a connection." + Environment.NewLine + "Please debug the error: " + ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.