Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added MySQL connection object, external dll for global application fu…
…nctions, and custom messagebox utils.
- Loading branch information
Evan Langlais
authored and
Evan Langlais
committed
Feb 21, 2017
1 parent
c76366d
commit 6464816
Showing
17 changed files
with
627 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
</startup> | ||
</configuration> | ||
<system.data> | ||
<DbProviderFactories> | ||
<remove name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" /> | ||
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> | ||
</DbProviderFactories> | ||
</system.data></configuration> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="MetroModernUI" version="1.4.0.0" targetFramework="net452" /> | ||
<package id="MySql.ConnectorNET.Data" version="6.8.3.2" targetFramework="net452" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using MySql.Data.MySqlClient; | ||
|
||
namespace EnigmaX | ||
{ | ||
public class DBConnect | ||
{ | ||
|
||
private MySqlConnection connection; | ||
|
||
public DBConnect() | ||
{ | ||
Initialize(); | ||
} | ||
|
||
private void Initialize() | ||
{ | ||
connection = new MySqlConnection("Server=4156.hostgator.com; database=ttech_enigma; UID=ttech_enigma; password=JaQE7eKrY4Rr"); | ||
} | ||
|
||
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) | ||
{ | ||
case 0: | ||
//GlobalFunctions.showDialog("Database Error", "Couldn't connect to the Database.", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); | ||
break; | ||
|
||
case 1045: | ||
// GlobalFunctions.showDialog("Database Error", "Database Credentials are Incorrect", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); | ||
break; | ||
} | ||
return false; | ||
} | ||
|
||
} | ||
|
||
private bool CloseConnection() | ||
{ | ||
|
||
try | ||
{ | ||
connection.Close(); | ||
return true; | ||
} | ||
catch (MySqlException ex) | ||
{ | ||
// GlobalFunctions.showDialog("Database Error", ex.ToString(), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); | ||
return false; | ||
} | ||
|
||
} | ||
|
||
public void WriteCommand(string str) | ||
{ | ||
|
||
if (this.OpenConnection() == true) | ||
{ | ||
//create command and assign the query and connection from the constructor | ||
MySqlCommand cmd = new MySqlCommand(str, connection); | ||
|
||
//Execute command | ||
cmd.ExecuteNonQuery(); | ||
|
||
//close connection | ||
this.CloseConnection(); | ||
} | ||
|
||
} | ||
|
||
public List<Dictionary<string, string>> ReadCommand(string str, params string[] collect) | ||
{ | ||
|
||
List<Dictionary<string, string>> total = new List<Dictionary<string, string>>(); | ||
|
||
if (this.OpenConnection() == true) | ||
{ | ||
//Create Command | ||
MySqlCommand cmd = new MySqlCommand(str, connection); | ||
//Create a data reader and Execute the command | ||
MySqlDataReader dataReader = cmd.ExecuteReader(); | ||
|
||
//Read the data and store them in the list | ||
while (dataReader.Read()) | ||
{ | ||
Dictionary<string, string> tmp = new Dictionary<string, string>(); | ||
foreach (string t in collect) | ||
{ | ||
tmp.Add(t, dataReader[t] + ""); | ||
} | ||
total.Add(tmp); | ||
} | ||
|
||
//close Data Reader | ||
dataReader.Close(); | ||
|
||
//close Connection | ||
this.CloseConnection(); | ||
|
||
//return list to be displayed | ||
return total; | ||
} | ||
else | ||
{ | ||
return total; | ||
} | ||
|
||
} | ||
|
||
/*public string ReadSingleCommand(string str) { | ||
if (this.OpenConnection() == true) | ||
{ | ||
//Create Mysql Command | ||
MySqlCommand cmd = new MySqlCommand(str, connection); | ||
//ExecuteScalar will return one value | ||
Count = int.Parse(cmd.ExecuteScalar() + ""); | ||
//close Connection | ||
this.CloseConnection(); | ||
return Count; | ||
} | ||
else | ||
{ | ||
return Count; | ||
} | ||
}*/ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace EnigmaX.Classes | ||
{ | ||
public class XMessageBox | ||
{ | ||
private string _title = ""; | ||
private string _message = ""; | ||
private string[] _buttons; | ||
|
||
public XMessageBox(string title, string message, string leftButton, string rightButton = "") { | ||
|
||
_title = title; | ||
_message = message; | ||
_buttons = new string[] { leftButton, rightButton }; | ||
|
||
} | ||
|
||
public int showMessage() { | ||
XMessageBoxForm window = new XMessageBoxForm(_title, _message, _buttons[0], _buttons[1]); | ||
var dialog = window.ShowDialog(); | ||
if (dialog == System.Windows.Forms.DialogResult.OK) | ||
{ | ||
if (window.returnValue.Equals("primary")) | ||
{ | ||
return 0; | ||
} | ||
else | ||
{ | ||
return 1; | ||
} | ||
} | ||
else { | ||
return -1; | ||
} | ||
} | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.