Permalink
Browse files

* Code cleanup, who taught you how to clean up your code! Probably th…

…e same person who taught me :)
  • Loading branch information...
unknown unknown
unknown authored and unknown committed Aug 5, 2011
1 parent e039634 commit a3e42995ef19cb165b9c12a31dae9c4d048a3d4a
Showing with 89 additions and 89 deletions.
  1. +89 −89 DBConnection/DBconnection.cs
@@ -13,113 +13,113 @@
namespace EveControlPanelApplication
{
-
+
class DBConnect
{
- private MySqlConnection connection;
- private string server;
- private string database;
- private string uid;
- private string password;
- private EveControlPanelApplication.mySqlLogin DBinfo = new EveControlPanelApplication.mySqlLogin();
-
- //Constructor
- public DBConnect()
- {
- Initialize();
-
- }
-
- //Initialize values
- private void Initialize()
- {
-
-
-
- server = DBinfo.hostTextBox.Text;
- database = DBinfo.databaseTextBox.Text;
- uid = DBinfo.usernameTextBox.Text;
- password = DBinfo.passwordTextBox.Text;
- string connectionString;
- connectionString = "SERVER=" + server + ";" + "DATABASE=" +
- database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
+ private MySqlConnection connection;
+ private string server;
+ private string database;
+ private string uid;
+ private string password;
+ private EveControlPanelApplication.mySqlLogin DBinfo = new EveControlPanelApplication.mySqlLogin();
- connection = new MySqlConnection(connectionString);
- }
-
- //open connection to database
- private bool OpenConnection()
- {
- try
+ //Constructor
+ public DBConnect()
{
- connection.Open();
- return true;
+ Initialize();
}
- catch (MySqlException ex)
- { //When handling errors, you can your application's response based
- //on the error number.
- //The two most common error numbers when connecting are as follows:
- //0: Cannot connect to server.
- //1045: Invalid user name and/or password.
- switch (ex.Number)
+
+ //Initialize values
+ private void Initialize()
{
- case 0:
- MessageBox.Show("Cannot connect to server. Contact administrator");
- break;
+ // We need a cleaner way of doing this, i think accessing the settings we already have through the xml file.
+ server = DBinfo.hostTextBox.Text;
+ database = DBinfo.databaseTextBox.Text;
+ uid = DBinfo.usernameTextBox.Text;
+ password = DBinfo.passwordTextBox.Text;
+ string connectionString;
+ connectionString = "SERVER=" + server + ";" + "DATABASE=" +
+ database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
- case 1045:
- MessageBox.Show("Invalid username/password, please try again");
- break;
- }
- return false;
-
+ connection = new MySqlConnection(connectionString);
}
- }
- //Close connection
- private bool CloseConnection()
- {
- try
- {
- connection.Close();
- return true;
- }
- catch (MySqlException ex)
+ //open connection to database
+ private bool OpenConnection()
+ {
+ try
+ {
+ connection.Open();
+ return true;
+ }
+ catch (MySqlException ex)
+ {
+ //When handling errors, you can your application's response based
+ //on the error number.
+ //The two most common error numbers when connecting are as follows:
+ //0: Cannot connect to server.
+ //1045: Invalid user name and/or password.
+ switch (ex.Number)
{
- MessageBox.Show(ex.Message);
- return false;
+ case 0:
+ MessageBox.Show("Cannot connect to server. Contact administrator");
+ break;
+
+ case 1045:
+ MessageBox.Show("Invalid username/password, please try again");
+ break;
}
- }
+ return false;
-// Example of what an insert should look like
- public void Insert()
- {
- string query = "INSERT INTO tabelinfo (age) VALUES('32')";
+ }
+ }
+
+ //Close connection
+ private bool CloseConnection()
+ {
+ try
+ {
+ connection.Close();
+ return true;
+ }
+ catch (MySqlException ex)
+ {
+ MessageBox.Show(ex.Message);
+ return false;
+ }
+ }
- //open connection
- if (this.OpenConnection() == true)
+ // Example of what an insert should look like
+ public void Insert()
{
- //create command and assign the query and connection from the constructor
- MySqlCommand cmd = new MySqlCommand(query, connection);
+ string query = "INSERT INTO tabelinfo (age) VALUES('32')";
- //Execute command
- cmd.ExecuteNonQuery();
+ //open connection
+ if (this.OpenConnection() == true)
+ {
+ //create command and assign the query and connection from the constructor
+ MySqlCommand cmd = new MySqlCommand(query, connection);
- //close connection
- this.CloseConnection();
+ //Execute command
+ cmd.ExecuteNonQuery();
+
+ //close connection
+ this.CloseConnection();
+ }
}
- }
-
- //Backup
- public void Backup()
- {
- }
- //Restore
- public void Restore()
- {
- }
-
+ //Backup
+ public void Backup()
+ {
+
+ }
+
+ //Restore
+ public void Restore()
+ {
+
+ }
+
}
}

0 comments on commit a3e4299

Please sign in to comment.