using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using MMDAL.DTO.ForeCast; using MMDAL.Query.ForeCast; using Newtonsoft.Json; using static GB5Shared.GB5Constant.Constant; namespace MMDAL.CustomCode.ForeCast { public class ForeCastDAL : IForeCastDAL { private readonly IQueryExecutor _QueryExecutor; public ForeCastDAL(IQueryExecutor queryExecutor) { _QueryExecutor = queryExecutor; } public async Task GetSelectListForeCast(int FirstNumber, int MaxResult, CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { string SQL = string.Empty; switch (LoginDTO.DatabaseType) { case DBType.SQL: SQL = ForeCastQB.GET_SELECTLIST_FORECAST_SQL; break; case DBType.PostGre: SQL = ForeCastQB.GET_SELECTLIST_FORECAST_PG; break; case DBType.Oracle: SQL = ForeCastQB.GET_SELECTLIST_FORECAST_ORACLE; break; case DBType.MySQL: SQL = ForeCastQB.GET_SELECTLIST_FORECAST_MYSQL; break; default: throw new Exception("Unsupported database type"); } var Parameters = new { firstnumber = FirstNumber, maxresult = MaxResult }; var Result = await _QueryExecutor.QueryAsync(LoginDTO, SQL, Parameters); string Json = JsonConvert.SerializeObject(Result); return Json; } catch (Exception) { throw; } } public async Task GetSelectListForeCastVersion(int ForeCastId, LoginDTO LoginDTO) { try { string SQL = LoginDTO.DatabaseType switch { DBType.SQL => ForeCastQB.GET_SELECTLIST_FORECAST_VERSION_SQL, DBType.PostGre => ForeCastQB.GET_SELECTLIST_FORECAST_VERSION_PG, _ => throw new Exception("Unsupported database type") }; var Parameters = new { ForeCastId = ForeCastId }; var Result = await _QueryExecutor.QueryAsync(LoginDTO, SQL, Parameters); return JsonConvert.SerializeObject(Result); } catch (Exception) { throw; } } } }