Added Viewer and
change to App Setting File from Constants
This commit is contained in:
@ -14,17 +14,16 @@ namespace OI.Metrology.Archive.Repositories;
|
||||
|
||||
public class MetrologyRepo : IMetrologyRepo
|
||||
{
|
||||
private IDbConnectionFactory DBConnectionFactory { get; }
|
||||
private readonly IDbConnectionFactory _DBConnectionFactory;
|
||||
private readonly IMemoryCache _Cache;
|
||||
|
||||
public MetrologyRepo(IDbConnectionFactory dbConnectionFactory, IMemoryCache memoryCache)
|
||||
{
|
||||
DBConnectionFactory = dbConnectionFactory;
|
||||
_DBConnectionFactory = dbConnectionFactory;
|
||||
_Cache = memoryCache;
|
||||
}
|
||||
|
||||
private DbConnection GetDbConnection() => DBConnectionFactory.GetDbConnection(Constants.ConnStringName);
|
||||
private DbConnection GetDbConnection2() => DBConnectionFactory.GetDbConnection(Constants.ConnStringName2);
|
||||
private DbConnection GetDbConnection() => _DBConnectionFactory.GetDbConnection();
|
||||
|
||||
protected DbProviderFactory GetDbProviderFactory(IDbConnection conn) => DbProviderFactories.GetFactory(conn.GetType().Namespace);
|
||||
|
||||
@ -57,19 +56,6 @@ public class MetrologyRepo : IMetrologyRepo
|
||||
string cacheKey = "GetToolTypes";
|
||||
if (_Cache.TryGetValue(cacheKey, out cached))
|
||||
return cached;
|
||||
//List<string> r = new List<string>();
|
||||
//r.Add("BioRad");
|
||||
//r.Add("CDE");
|
||||
//r.Add("Tencor");
|
||||
//r.Add("MercuryProbe");
|
||||
//r.Add("StratusBioRad");
|
||||
//r.Add("TencorSP1");
|
||||
|
||||
//CacheItem(cacheKey, r);
|
||||
|
||||
//return r;
|
||||
|
||||
//var conn =
|
||||
|
||||
using DbConnection conn = GetDbConnection();
|
||||
IEnumerable<ToolType> r = conn.Query<ToolType>("SELECT * FROM ToolType");
|
||||
@ -95,7 +81,7 @@ public class MetrologyRepo : IMetrologyRepo
|
||||
|
||||
return r;
|
||||
}
|
||||
//Changed by Jonathan : Changed this as the table ToolType doesn't exist in the Metrology_Archive DB
|
||||
// Changed by Jonathan : Changed this as the table ToolType doesn't exist in the Metrology_Archive DB
|
||||
public ToolType GetToolTypeByID(int id)
|
||||
{
|
||||
ToolType cached;
|
||||
@ -103,7 +89,6 @@ public class MetrologyRepo : IMetrologyRepo
|
||||
if (_Cache.TryGetValue(cacheKey, out cached))
|
||||
return cached;
|
||||
|
||||
//using (var conn = GetDbConnection2())
|
||||
using DbConnection conn = GetDbConnection();
|
||||
ToolType r = conn.QueryFirstOrDefault<ToolType>(
|
||||
"SELECT * FROM ToolType WHERE ID = @id",
|
||||
@ -113,12 +98,10 @@ public class MetrologyRepo : IMetrologyRepo
|
||||
|
||||
return r;
|
||||
}
|
||||
//Changed by Jonathan : Changed this to look at Metrology DB because table ToolTypeMetaData does not exist in Metrology_Archive. This still fails when BioRad is the tool.
|
||||
// Changed by Jonathan : Changed this to look at Metrology DB because table ToolTypeMetaData does not exist in Metrology_Archive. This still fails when BioRad is the tool.
|
||||
public IEnumerable<ToolTypeMetadata> GetToolTypeMetadataByToolTypeID(int id)
|
||||
{
|
||||
string cacheKey = "GetToolTypeMetadataByToolTypeID_" + id.ToString();
|
||||
//if (_cache.TryGetValue(cacheKey, out cached))
|
||||
//return cached;
|
||||
|
||||
using DbConnection conn = GetDbConnection();
|
||||
IEnumerable<ToolTypeMetadata> r = conn.Query<ToolTypeMetadata>(
|
||||
@ -335,8 +318,8 @@ public class MetrologyRepo : IMetrologyRepo
|
||||
_ = sb.AppendFormat(" FROM [{0}] ", tableName);
|
||||
return sb.ToString();
|
||||
}
|
||||
//Set DB Connection based on isArchive flag, for prod need to set isArchive outside of this function.
|
||||
public DataTable GetHeaders(int toolTypeId, DateTime? startTime, DateTime? endTime, int? pageNo, int? pageSize, long? headerId, out long totalRecords, bool isArchive)
|
||||
|
||||
public DataTable GetHeaders(int toolTypeId, DateTime? startTime, DateTime? endTime, int? pageNo, int? pageSize, long? headerId, out long totalRecords)
|
||||
{
|
||||
ToolType tt = GetToolTypeByID(toolTypeId);
|
||||
if (tt == null)
|
||||
@ -348,14 +331,7 @@ public class MetrologyRepo : IMetrologyRepo
|
||||
|
||||
DataTable dt = new();
|
||||
|
||||
//bool isArchive = true;
|
||||
|
||||
DbConnection conn = GetDbConnection();
|
||||
if (isArchive == true)
|
||||
{
|
||||
conn = GetDbConnection2();
|
||||
}
|
||||
|
||||
using (conn)
|
||||
{
|
||||
System.Text.StringBuilder sb = new();
|
||||
@ -433,10 +409,9 @@ public class MetrologyRepo : IMetrologyRepo
|
||||
|
||||
return dt;
|
||||
}
|
||||
//Go Here Next
|
||||
public DataTable GetData(int toolTypeId, long headerid, bool isArchive)
|
||||
// Go Here Next
|
||||
public DataTable GetData(int toolTypeId, long headerid)
|
||||
{
|
||||
//isArchive = true;
|
||||
ToolType tt = GetToolTypeByID(toolTypeId);
|
||||
if (tt == null)
|
||||
throw new Exception("Invalid tool type ID");
|
||||
@ -448,11 +423,6 @@ public class MetrologyRepo : IMetrologyRepo
|
||||
DataTable dt = new();
|
||||
|
||||
DbConnection conn = GetDbConnection();
|
||||
if (isArchive == true)
|
||||
{
|
||||
conn = GetDbConnection2();
|
||||
}
|
||||
|
||||
using (conn)
|
||||
{
|
||||
System.Text.StringBuilder sb = new();
|
||||
@ -467,7 +437,6 @@ public class MetrologyRepo : IMetrologyRepo
|
||||
DbCommand cmd = factory.CreateCommand();
|
||||
|
||||
_ = sb.Append("WHERE [HeaderID] = @HeaderID ");
|
||||
//sb.Append("WHERE [OriginID] = @HeaderID ");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(tt.DataGridSortBy))
|
||||
{
|
||||
@ -537,7 +506,7 @@ public class MetrologyRepo : IMetrologyRepo
|
||||
|
||||
return dt;
|
||||
}
|
||||
public string GetAttachmentInsertDateByGUID(String tableName, Guid attachmentId)
|
||||
public string GetAttachmentInsertDateByGUID(string tableName, Guid attachmentId)
|
||||
{
|
||||
using DbConnection conn = GetDbConnection();
|
||||
string sql = "";
|
||||
@ -554,7 +523,6 @@ public class MetrologyRepo : IMetrologyRepo
|
||||
}
|
||||
public DataTable GetDataSharePoint(int toolTypeId, string headerid)
|
||||
{
|
||||
//isArchive = true;
|
||||
ToolType tt = GetToolTypeByID(toolTypeId);
|
||||
if (tt == null)
|
||||
throw new Exception("Invalid tool type ID");
|
||||
@ -566,10 +534,6 @@ public class MetrologyRepo : IMetrologyRepo
|
||||
DataTable dt = new();
|
||||
|
||||
DbConnection conn = GetDbConnection();
|
||||
//if (isArchive == true)
|
||||
//{
|
||||
// conn = GetDbConnection2();
|
||||
//}
|
||||
|
||||
using (conn)
|
||||
{
|
||||
@ -585,15 +549,12 @@ public class MetrologyRepo : IMetrologyRepo
|
||||
DbCommand cmd = factory.CreateCommand();
|
||||
|
||||
_ = sb.Append("WHERE [Title] LIKE '%" + headerid + "%' ");
|
||||
//sb.Append("WHERE [OriginID] = @HeaderID ");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(tt.DataGridSortBy))
|
||||
{
|
||||
_ = sb.AppendFormat("ORDER BY {0} ", tt.DataGridSortBy);
|
||||
}
|
||||
|
||||
//AddParameter(cmd, "@HeaderID", headerid);
|
||||
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandText = sb.ToString();
|
||||
cmd.CommandType = CommandType.Text;
|
||||
@ -716,18 +677,13 @@ public class MetrologyRepo : IMetrologyRepo
|
||||
return ds;
|
||||
}
|
||||
|
||||
public IEnumerable<HeaderCommon> GetHeaderTitles(int toolTypeId, int? pageNo, int? pageSize, out long totalRecords, bool isArchive)
|
||||
public IEnumerable<HeaderCommon> GetHeaderTitles(int toolTypeId, int? pageNo, int? pageSize, out long totalRecords)
|
||||
{
|
||||
ToolType tt = GetToolTypeByID(toolTypeId);
|
||||
if (tt == null)
|
||||
throw new Exception("Invalid tool type ID");
|
||||
|
||||
DbConnection conn = GetDbConnection();
|
||||
if (isArchive == true)
|
||||
{
|
||||
conn = GetDbConnection2();
|
||||
}
|
||||
|
||||
using (conn)
|
||||
{
|
||||
string sql = $"SELECT ID, InsertDate, AttachmentID, Title, [Date] FROM {tt.HeaderTableName} ORDER BY [Date] DESC ";
|
||||
@ -753,7 +709,7 @@ public class MetrologyRepo : IMetrologyRepo
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<KeyValuePair<string, string>> GetHeaderFields(int toolTypeId, long headerid, bool isArchive)
|
||||
public IEnumerable<KeyValuePair<string, string>> GetHeaderFields(int toolTypeId, long headerid)
|
||||
{
|
||||
ToolType tt = GetToolTypeByID(toolTypeId);
|
||||
if (tt == null)
|
||||
@ -766,11 +722,6 @@ public class MetrologyRepo : IMetrologyRepo
|
||||
List<KeyValuePair<string, string>> r = new();
|
||||
|
||||
DbConnection conn = GetDbConnection();
|
||||
if (isArchive == true)
|
||||
{
|
||||
conn = GetDbConnection2();
|
||||
}
|
||||
|
||||
using (conn)
|
||||
{
|
||||
DbProviderFactory factory = GetDbProviderFactory(conn);
|
||||
@ -811,7 +762,7 @@ public class MetrologyRepo : IMetrologyRepo
|
||||
using DbConnection conn = GetDbConnection();
|
||||
return conn.Query<AwaitingDispo>("GetAwaitingDispo", commandType: CommandType.StoredProcedure);
|
||||
}
|
||||
//Jonathan changed this to remove the reviewDate update on the database.
|
||||
// Jonathan changed this to remove the reviewDate update on the database.
|
||||
public int UpdateReviewDate(int toolTypeId, long headerId, bool clearDate)
|
||||
{
|
||||
ToolType tt = GetToolTypeByID(toolTypeId);
|
||||
@ -821,7 +772,7 @@ public class MetrologyRepo : IMetrologyRepo
|
||||
using DbConnection conn = GetDbConnection();
|
||||
if (clearDate)
|
||||
{
|
||||
//if it's already past the 6 hour window, then it won't show in queue anyway, so need to return value so we can show that
|
||||
// if it's already past the 6 hour window, then it won't show in queue anyway, so need to return value so we can show that
|
||||
string sql = $"SELECT DATEDIFF(HH, INSERTDATE, GETDATE()) FROM [{tt.HeaderTableName}] WHERE ID = @HeaderID";
|
||||
int hrs = conn.ExecuteScalar<int>(sql, param: new { HeaderId = headerId });
|
||||
_ = conn.Execute($"UPDATE [{tt.HeaderTableName}] SET ReviewDate = NULL WHERE ID = @HeaderID", new { HeaderID = headerId });
|
||||
@ -829,7 +780,6 @@ public class MetrologyRepo : IMetrologyRepo
|
||||
}
|
||||
else
|
||||
{
|
||||
//conn.Execute($"UPDATE [{tt.HeaderTableName}] SET ReviewDate = GETDATE() WHERE ID = @HeaderID", new { HeaderID = headerId });
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -857,4 +807,9 @@ public class MetrologyRepo : IMetrologyRepo
|
||||
$"SELECT TOP 1 AttachmentID FROM [{tt.DataTableName}] WHERE Title = @Title ORDER BY InsertDate DESC";
|
||||
return conn.ExecuteScalar<Guid>(sql, param: new { Title = title });
|
||||
}
|
||||
|
||||
string IMetrologyRepo.GetHeaderInsertDate(int toolTypeId, long headerId) => throw new NotImplementedException();
|
||||
void IMetrologyRepo.SetHeaderDirName(string tableName, long headerId, string dateDir) => throw new NotImplementedException();
|
||||
string IMetrologyRepo.GetDataInsertDate(int toolTypeId, long headerId, string title) => throw new NotImplementedException();
|
||||
void IMetrologyRepo.SetDataDirName(string tableName, long headerId, string title, string dateDir) => throw new NotImplementedException();
|
||||
}
|
Reference in New Issue
Block a user