-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,253 additions
and
9 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
Rdmp.Core/CatalogueAnalysisTools/Data/UserDefinedChart.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
using NPOI.OpenXmlFormats.Dml.Diagram; | ||
using NPOI.SS.Formula.Functions; | ||
using Rdmp.Core.Curation.Data; | ||
using Rdmp.Core.QueryBuilding; | ||
using Rdmp.Core.Repositories; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Data.Common; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Rdmp.Core.CatalogueAnalysisTools.Data | ||
{ | ||
public class UserDefinedChart : DatabaseEntity | ||
{ | ||
private DQERepository _DQERepository { get; set; } | ||
private Catalogue _catalogue; | ||
private string _queryString; | ||
private int _chartType; //SeriesChartType | ||
private string _title; | ||
private string _seriesName; | ||
|
||
|
||
public Catalogue Catalogue { get => _catalogue; set => SetField(ref _catalogue, value); } | ||
public String QueryString { get => _queryString; set => SetField(ref _queryString, value); } | ||
public String Title { get => _title; set => SetField(ref _title, value); } | ||
public String SeriesName { get => _seriesName; set => SetField(ref _seriesName, value); } | ||
public int ChartType { get => _chartType; set => SetField(ref _chartType, value); } | ||
|
||
public void Generate() | ||
{ | ||
//seems to be an issue with the dbdatareader already being open | ||
var existingResults = _DQERepository.GetAllObjectsWhere<UserDefinedChartResult>("UserDefinedChart_ID", this.ID); | ||
foreach(var result in existingResults) | ||
{ | ||
result.DeleteInDatabase(); | ||
} | ||
var server = _catalogue.GetDistinctLiveDatabaseServer(ReusableLibraryCode.DataAccess.DataAccessContext.InternalDataProcessing,false); | ||
var con = server.GetConnection(); | ||
con.Open(); | ||
var cmd = server.GetCommand(_queryString, con); | ||
using var r = cmd.ExecuteReader(); | ||
while (r.Read()) | ||
{ | ||
var y = r[r.GetName(0)].ToString(); | ||
var x = r[r.GetName(1)].ToString(); | ||
var result = new UserDefinedChartResult(_DQERepository, this, x, y); | ||
result.SaveToDatabase(); | ||
} | ||
} | ||
|
||
|
||
public DataTable GetResults() | ||
{ | ||
//seems to be an issue with the dbdatareader already being open | ||
var dt = new DataTable(); | ||
dt.Columns.Add("Y"); | ||
dt.Columns.Add("X"); | ||
var results = _DQERepository.GetAllObjectsWhere<UserDefinedChartResult>("UserDefinedChart_ID", this.ID); | ||
foreach(var result in results) | ||
{ | ||
dt.Rows.Add([result.Y, result.X]); | ||
} | ||
|
||
return dt; | ||
} | ||
|
||
public UserDefinedChart(DQERepository repository, Catalogue catalogue, string queryString, int chartType,string title = null, string seriesName = null) | ||
{ | ||
_DQERepository = repository; | ||
_catalogue = catalogue; | ||
_queryString = queryString; | ||
_title = title; | ||
_seriesName = seriesName; | ||
_chartType = chartType; | ||
|
||
_DQERepository.InsertAndHydrate(this, new Dictionary<string, object> | ||
{ | ||
{"Catalogue_ID",catalogue.ID }, | ||
{"QueryString",queryString }, | ||
{"Title",title }, | ||
{"SeriesName",seriesName }, | ||
{"ChartType",chartType } | ||
}); | ||
} | ||
|
||
public UserDefinedChart(DQERepository repository, DbDataReader r): base(repository, r) | ||
{ | ||
_DQERepository = repository; | ||
_catalogue = _DQERepository.CatalogueRepository.GetObjectByID<Catalogue>(int.Parse(r["Catalogue_ID"].ToString())); | ||
_queryString = r["QueryString"].ToString(); | ||
_title = r["Title"].ToString(); | ||
_seriesName = r["SeriesName"].ToString(); | ||
_chartType = int.Parse(r["ChartType"].ToString()); | ||
} | ||
|
||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
Rdmp.Core/CatalogueAnalysisTools/Data/UserDefinedChartResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Rdmp.Core.Curation.Data; | ||
using Rdmp.Core.Repositories; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.Common; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Rdmp.Core.CatalogueAnalysisTools.Data | ||
{ | ||
class UserDefinedChartResult: DatabaseEntity | ||
{ | ||
private string _x; | ||
private string _y; | ||
private UserDefinedChart _userDefinedChart; | ||
private DQERepository _DQERepository { get; set; } | ||
|
||
|
||
public string X { get => _x; set => SetField(ref _x, value); } | ||
public string Y { get => _x; set => SetField(ref _x, value); } | ||
|
||
public UserDefinedChart UserDefinedChart { get => _userDefinedChart; set => SetField(ref _userDefinedChart, value); } | ||
|
||
|
||
public UserDefinedChartResult(DQERepository repository, DbDataReader r): base(repository, r) | ||
{ | ||
_DQERepository = repository; | ||
_x = r["X"].ToString(); | ||
_y = r["Y"].ToString(); | ||
_userDefinedChart = _DQERepository.GetObjectByID<UserDefinedChart>(int.Parse(r["UserDefinedChart_ID"].ToString())); | ||
} | ||
|
||
public UserDefinedChartResult(DQERepository repository,UserDefinedChart userDefinedChart, string x, string y) | ||
{ | ||
_DQERepository = repository; | ||
_userDefinedChart = userDefinedChart; | ||
_x = x; | ||
_y = y; | ||
|
||
_DQERepository.InsertAndHydrate(this, new Dictionary<string, object> { | ||
{"UserDefinedChart_ID", userDefinedChart.ID }, | ||
{"X",x }, | ||
{"Y",y } | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.