Skip to content

Commit

Permalink
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
Show file tree
Hide file tree
Showing 17 changed files with 627 additions and 14 deletions.
6 changes: 6 additions & 0 deletions Enigma.sln
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Enigma", "Enigma\Enigma.csproj", "{64F7824B-48B9-40FE-BAD7-B2DF49BFCEA8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EnigmaX", "EnigmaX\EnigmaX.csproj", "{9C277A65-39FE-466D-8AE9-4B3A12A5E61E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{64F7824B-48B9-40FE-BAD7-B2DF49BFCEA8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64F7824B-48B9-40FE-BAD7-B2DF49BFCEA8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64F7824B-48B9-40FE-BAD7-B2DF49BFCEA8}.Release|Any CPU.Build.0 = Release|Any CPU
{9C277A65-39FE-466D-8AE9-4B3A12A5E61E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9C277A65-39FE-466D-8AE9-4B3A12A5E61E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9C277A65-39FE-466D-8AE9-4B3A12A5E61E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9C277A65-39FE-466D-8AE9-4B3A12A5E61E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
9 changes: 7 additions & 2 deletions Enigma/App.config
@@ -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>
8 changes: 4 additions & 4 deletions Enigma/Form1.Designer.cs → Enigma/DebugForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Enigma/Form1.cs → Enigma/DebugForm.cs
Expand Up @@ -11,9 +11,9 @@ using MetroFramework.Forms;

namespace Enigma
{
public partial class Form1 : MetroForm
public partial class DebugForm : MetroForm
{
public Form1()
public DebugForm()
{
InitializeComponent();
}
Expand Down
File renamed without changes.
14 changes: 9 additions & 5 deletions Enigma/Enigma.csproj
Expand Up @@ -45,6 +45,10 @@
<HintPath>..\packages\MetroModernUI.1.4.0.0\lib\net\MetroFramework.Fonts.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MySql.Data, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<HintPath>..\packages\MySql.ConnectorNET.Data.6.8.3.2\lib\net45\MySql.Data.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -58,16 +62,16 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<Compile Include="DebugForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
<Compile Include="DebugForm.Designer.cs">
<DependentUpon>DebugForm.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
<EmbeddedResource Include="DebugForm.resx">
<DependentUpon>DebugForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
Expand Down
2 changes: 1 addition & 1 deletion Enigma/Program.cs
Expand Up @@ -17,7 +17,7 @@ namespace Enigma
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Application.Run(new DebugForm());
}
}
}
1 change: 1 addition & 0 deletions Enigma/packages.config
@@ -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>
150 changes: 150 additions & 0 deletions EnigmaX/Classes/DBConnect.cs
@@ -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;
}
}*/

}
}
44 changes: 44 additions & 0 deletions EnigmaX/Classes/XMessageBox.cs
@@ -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;
}
}


}
}

0 comments on commit 6464816

Please sign in to comment.