-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRedmineMySqlDataAccess.cs
109 lines (97 loc) · 3.29 KB
/
RedmineMySqlDataAccess.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using MySql.Data.MySqlClient;
using System;
using System.Configuration;
using System.Data;
using System.Windows.Forms;
namespace combit.RedmineReports
{
sealed class RedmineMySqlDataAccess : RedmineDataAccessBase
{
public RedmineMySqlDataAccess() : this(null) { }
public RedmineMySqlDataAccess(string ConnectionString, bool isPlain)
{
// create connection
_connection = new MySqlConnection();
if (ConnectionString == null)
{
_connection.ConnectionString = ConfigurationManager.ConnectionStrings["combit.RedmineReports.Properties.Settings.RedmineConnectionString"].ConnectionString;
}
else
{
_connection.ConnectionString = ConnectionString;
}
try
{
_connection.Open();
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
}
}
public RedmineMySqlDataAccess(string ConnectionString)
{
// create connection
_connection = new MySqlConnection();
if (String.IsNullOrEmpty(ConnectionString))
{
string convertString = ConfigurationManager.ConnectionStrings["combit.RedmineReports.Properties.Settings.RedmineConnectionString"].ConnectionString;
//decrypt connectionstring
_connection.ConnectionString = RedmineReportsConfigDataHelper.DecryptData(convertString);
}
else
{
_connection.ConnectionString = ConnectionString;
}
try
{
_connection.Open();
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
}
}
public override string GetParameterFormat()
{
return "@{0}";
}
public override DataTable GetDataTable(string sql, IDbDataParameter[] parameters, bool raiseException)
{
try
{
DataTable dt = new DataTable();
MySqlCommand command = new MySqlCommand(sql, _connection as MySqlConnection);
if (parameters != null)
{
foreach (IDbDataParameter parameter in parameters)
{
command.Parameters.AddWithValue(parameter.ParameterName, parameter.Value);
}
}
MySqlDataAdapter myAdapter = new MySqlDataAdapter();
myAdapter.SelectCommand = command;
myAdapter.Fill(dt);
return dt;
}
catch (MySqlException ex)
{
if (raiseException)
throw;
MessageBox.Show(ex.Message + "\n" + "Command was: " + sql);
return null;
}
catch (Exception ex)
{
if (raiseException)
throw;
MessageBox.Show(ex.Message);
return null;
}
}
public override IDbDataParameter GetParameter()
{
return _connection.CreateCommand().CreateParameter();
}
}
}