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 serverStr = ed.AESDecrypt(dbConfig.Server); var databaseStr = ed.AESDecrypt(dbConfig.Database); var rootStr = ed.AESDecrypt(dbConfig.Root); var passwordStr = ed.AESDecrypt(dbConfig.Password); //var connStr = $"server={serverStr};database={databaseStr};user={rootStr};password={passwordStr};charset=utf8;"; var connStr = @"server=210.61.91.43;port=10068;database=solar_power_test;user=idafenweb;password=P@ssw0rd;charset=utf8;"; this._connectionString = connStr; } public IDbConnection GetConnection() { var conn = new MySqlConnection(this._connectionString); return conn; } } }