using Microsoft.Extensions.Options; using MySql.Data.MySqlClient; using SolarPower.Models; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Threading.Tasks; namespace SolarPower.Helper { /// /// Database 介面 /// public interface IDatabaseHelper { /// /// 取得連線 /// /// IDbConnection GetConnection(); } public class DatabaseHelper : IDatabaseHelper { private readonly string _connectionString; public DatabaseHelper(DBConfig dbConfig) { EDFunction ed = new EDFunction(); var serverStr1 = ed.AESEncrypt(dbConfig.Server); var databaseStr1 = ed.DESEncrypt(dbConfig.Database); var rootStr1 = ed.DESEncrypt(dbConfig.Root); var passwordStr1 = ed.DESEncrypt(dbConfig.Password); var serverStr = ed.AESDecrypt(serverStr1); var databaseStr = ed.DESDecrypt(databaseStr1); var rootStr = ed.DESDecrypt(rootStr1); var passwordStr = ed.DESDecrypt(passwordStr1); //var connStr = $"server={serverStr};database={databaseStr};user={rootStr};password={passwordStr};charset=utf8;"; var connStr = $"server=127.0.0.1;database=solar_power;user=root;password=000000;charset=utf8;"; //var connStr = @"data source=127.0.0.1;initial catalog=SolarPower;integrated security=true;"; this._connectionString = connStr; } public IDbConnection GetConnection() { var conn = new MySqlConnection(this._connectionString); return conn; } } }