TargetFramework update,

reference updates and added tests for Viewer
This commit is contained in:
2023-01-06 21:17:30 -07:00
parent 791724fdd4
commit f0c2140f93
82 changed files with 10187 additions and 1052 deletions

View File

@ -0,0 +1,37 @@
using OI.Metrology.Shared.Models.Stateless;
using OI.Metrology.Viewer.Models;
using System.Text.Json;
namespace OI.Metrology.Viewer.Repository;
public class AppSettingsRepository : IAppSettingsRepository
{
private readonly AppSettings _AppSettings;
public AppSettingsRepository(AppSettings appSettings) => _AppSettings = appSettings;
public List<string> GetAppSettings()
{
List<string> results = new();
string json = JsonSerializer.Serialize(_AppSettings);
JsonElement jsonElement = JsonSerializer.Deserialize<JsonElement>(json);
JsonProperty[] jsonProperties = jsonElement.EnumerateObject().ToArray();
foreach (JsonProperty jsonProperty in jsonProperties)
results.Add(jsonProperty.Value.ToString());
if (!_AppSettings.IsDevelopment)
throw new Exception("Shouldn't expose!");
return results;
}
List<string> IAppSettingsRepository.GetAppSettings() => GetAppSettings();
public string GetBuildNumberAndGitCommitSeven()
{
string result = string.Concat(_AppSettings.BuildNumber, '-', _AppSettings.GitCommitSeven);
return result;
}
string IAppSettingsRepository.GetBuildNumberAndGitCommitSeven() => GetBuildNumberAndGitCommitSeven();
}

View File

@ -0,0 +1,36 @@
using OI.Metrology.Shared.Models.Stateless;
using OI.Metrology.Viewer.Models;
using System.Net;
namespace OI.Metrology.Viewer.Repository;
public class ClientSettingsRepository : IClientSettingsRepository
{
private readonly AppSettings _AppSettings;
public ClientSettingsRepository(AppSettings appSettings) => _AppSettings = appSettings;
public List<string> GetClientSettings(IPAddress? remoteIpAddress)
{
List<string> results = new();
if (remoteIpAddress is null)
results.Add(nameof(remoteIpAddress));
else
results.Add(remoteIpAddress.ToString());
if (!_AppSettings.IsDevelopment)
throw new Exception("Shouldn't expose!");
return results;
}
List<string> IClientSettingsRepository.GetClientSettings(IPAddress? remoteIpAddress) => GetClientSettings(remoteIpAddress);
public string GetIpAddress(IPAddress? remoteIpAddress)
{
string result = remoteIpAddress is null ? string.Empty : remoteIpAddress.ToString();
return result;
}
string IClientSettingsRepository.GetIpAddress(IPAddress? remoteIpAddress) => GetIpAddress(remoteIpAddress);
}

View File

@ -0,0 +1,88 @@
using Newtonsoft.Json.Linq;
using OI.Metrology.Shared.DataModels;
using OI.Metrology.Shared.Models;
using OI.Metrology.Shared.Models.Stateless;
using OI.Metrology.Shared.Services;
using System.Net;
namespace OI.Metrology.Viewer.Repository;
public class InboundRepository : IInboundRepository
{
private readonly Serilog.ILogger _Log;
public InboundRepository() => _Log = Serilog.Log.ForContext<InboundRepository>();
bool IInboundRepository.IsIPAddressAllowed(string inboundApiAllowedIPList, IPAddress? remoteIP)
{
if (string.IsNullOrWhiteSpace(inboundApiAllowedIPList))
return true;
if (remoteIP is null)
return false;
byte[] remoteIPBytes = remoteIP.GetAddressBytes();
string[] allowedIPs = inboundApiAllowedIPList.Split(';');
foreach (string ip in allowedIPs)
{
IPAddress? parsedIP;
if (IPAddress.TryParse(ip, out parsedIP))
{
if (parsedIP.GetAddressBytes().SequenceEqual(remoteIPBytes))
return true;
}
}
return false;
}
// this is the main endpoint, it accepts a JSON message that contains both the header and data records together
// tooltype is the ToolTypeName column from the ToolType table
// JToken is how you can accept a JSON message without deserialization.
// Using "string" doesn't work because ASP.NET Core will expect a json encoded string, not give you the actual string.
DataResponse IInboundRepository.Data(IMetrologyRepository metrologyRepository, IInboundDataService inboundDataService, string tooltype, JToken jsonbody)
{
DataResponse result = new();
ToolType? toolType = metrologyRepository.GetToolTypeByName(tooltype);
if (toolType is null)
result.Errors.Add("Invalid tool type: " + tooltype);
else
{
List<ToolTypeMetadata> metaData = metrologyRepository.GetToolTypeMetadataByToolTypeID(toolType.ID).ToList();
if (metaData is null)
result.Errors.Add("Invalid metadata for tool type: " + tooltype);
else if (jsonbody is null)
result.Errors.Add("Invalid json");
else
inboundDataService.ValidateJSONFields(jsonbody, 0, metaData, result.Errors, result.Warnings);
if (metaData is not null && jsonbody is not null && !result.Errors.Any())
{
try
{
result.HeaderID = inboundDataService.DoSQLInsert(jsonbody, toolType, metaData);
result.Success = result.HeaderID > 0;
}
catch (Exception ex) { result.Errors.Add(ex.Message); }
}
}
return result;
}
// this is the endpoint for attaching a field. It is not JSON, it is form-data/multipart like an HTML form because that's the normal way.
// header ID is the ID value from the Header table
// datauniqueid is the Title value from the Data/Detail table
string? IInboundRepository.AttachFile(IMetrologyRepository metrologyRepository, IAttachmentsService attachmentsService, string tooltype, long headerid, string datauniqueid, string fileName, object uploadedFile)
{
string? result = null;
ToolType toolType = metrologyRepository.GetToolTypeByName(tooltype);
if (toolType is null)
result = $"Invalid tool type: {tooltype}";
string filename = Path.GetFileName(fileName);
if (string.IsNullOrWhiteSpace(filename))
result = "Empty filename";
if (filename.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
result = "Invalid filename";
if (result is null && toolType is not null)
attachmentsService.SaveAttachment(toolType, headerid, datauniqueid, filename, uploadedFile);
return result;
}
}

View File

@ -2,22 +2,22 @@
using Microsoft.Extensions.Caching.Memory;
using Newtonsoft.Json.Linq;
using OI.Metrology.Shared.DataModels;
using OI.Metrology.Shared.Models.Stateless;
using OI.Metrology.Shared.Repositories;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Transactions;
#pragma warning disable CS8600, CS8602, CS8603, CS8604, CS8625
namespace OI.Metrology.Viewer.Repositories;
public class MetrologyRepo : IMetrologyRepo
public class MetrologyRepository : IMetrologyRepository
{
private readonly IMemoryCache _Cache;
private readonly IDbConnectionFactory _DBConnectionFactory;
public MetrologyRepo(IDbConnectionFactory dbConnectionFactory, IMemoryCache memoryCache)
public MetrologyRepository(IDbConnectionFactory dbConnectionFactory, IMemoryCache memoryCache)
{
_Cache = memoryCache;
_DBConnectionFactory = dbConnectionFactory;
@ -139,10 +139,10 @@ public class MetrologyRepo : IMetrologyRepo
// build field map
foreach (ToolTypeMetadata f in fields)
{
if ((f.ApiName != null) && f.ApiName.Contains('\\'))
if ((f.ApiName is not null) && f.ApiName.Contains('\\'))
{
string n = f.ApiName.Split('\\')[0].Trim().ToUpper();
if (containerField == null)
if (containerField is null)
containerField = n;
else if (!string.Equals(containerField, n))
throw new Exception("Only one container field is allowed");
@ -156,7 +156,7 @@ public class MetrologyRepo : IMetrologyRepo
}
}
if (containerField == null)
if (containerField is null)
{
// No container field, just insert a single row
@ -167,7 +167,7 @@ public class MetrologyRepo : IMetrologyRepo
// Find the container field in the json
JProperty contJP = jsonrow.Children<JProperty>().Where(c => string.Equals(c.Name.Trim(), containerField, StringComparison.OrdinalIgnoreCase)).SingleOrDefault();
if ((contJP != null) && (contJP.Value is JArray array))
if ((contJP is not null) && (contJP.Value is JArray array))
{
JArray contRows = array;
@ -220,11 +220,11 @@ public class MetrologyRepo : IMetrologyRepo
{
string apifield = jp.Name.Trim().ToUpper();
if (fieldmap.ContainsKey(apifield))
if (fieldmap.TryGetValue(apifield, out string value))
{
string parmname = string.Format("@p{0}", parmnumber);
columns += string.Format("[{0}],", fieldmap[apifield]);
columns += string.Format("[{0}],", value);
parms += parmname;
parms += ",";
parmnumber += 1;
@ -236,18 +236,18 @@ public class MetrologyRepo : IMetrologyRepo
}
}
if ((containerrow != null) && (containerFieldmap != null))
if ((containerrow is not null) && (containerFieldmap is not null))
{
foreach (JProperty jp in containerrow.Children<JProperty>())
{
string apifield = jp.Name.Trim().ToUpper();
if (containerFieldmap.ContainsKey(apifield))
if (containerFieldmap.TryGetValue(apifield, out string value))
{
string parmname = string.Format("@p{0}", parmnumber);
columns += string.Format("[{0}],", containerFieldmap[apifield]);
columns += string.Format("[{0}],", value);
parms += parmname;
parms += ",";
parmnumber += 1;
@ -267,7 +267,7 @@ public class MetrologyRepo : IMetrologyRepo
cmd.CommandText = columns.TrimEnd(',') + parms.TrimEnd(',') + ";SELECT SCOPE_IDENTITY();";
object o = cmd.ExecuteScalar();
if ((o == null) || Convert.IsDBNull(o))
if ((o is null) || Convert.IsDBNull(o))
throw new Exception("Unexpected query result");
return Convert.ToInt64(o);
}
@ -307,7 +307,7 @@ public class MetrologyRepo : IMetrologyRepo
{
if (!firstField)
_ = sb.Append(',');
if (f.GridAttributes != null && f.GridAttributes.Contains("isNull"))
if (f.GridAttributes is not null && f.GridAttributes.Contains("isNull"))
{
_ = sb.AppendFormat("{0}", "ISNULL(" + f.ColumnName + ", '')[" + f.ColumnName + "]");
}
@ -325,11 +325,11 @@ public class MetrologyRepo : IMetrologyRepo
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)
if (tt is null)
throw new Exception("Invalid tool type ID");
IEnumerable<ToolTypeMetadata> md = GetToolTypeMetadataByToolTypeID(toolTypeId);
if (md == null)
if (md is null)
throw new Exception("Invalid tool type metadata");
DataTable dt = new();
@ -418,11 +418,11 @@ public class MetrologyRepo : IMetrologyRepo
public DataTable GetData(int toolTypeId, long headerid)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (tt is null)
throw new Exception("Invalid tool type ID");
IEnumerable<ToolTypeMetadata> md = GetToolTypeMetadataByToolTypeID(toolTypeId);
if (md == null)
if (md is null)
throw new Exception("Invalid tool type metadata");
DataTable dt = new();
@ -513,7 +513,7 @@ public class MetrologyRepo : IMetrologyRepo
public Guid GetHeaderAttachmentID(int toolTypeId, long headerId)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (tt is null)
throw new Exception("Invalid tool type ID");
using DbConnection conn = GetDbConnection();
@ -525,7 +525,7 @@ public class MetrologyRepo : IMetrologyRepo
public string GetHeaderInsertDate(int toolTypeId, long headerId)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (tt is null)
throw new Exception("Invalid tool type ID");
using DbConnection conn = GetDbConnection();
@ -557,7 +557,7 @@ public class MetrologyRepo : IMetrologyRepo
public Guid GetDataAttachmentID(int toolTypeId, long headerId, string title)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (tt is null)
throw new Exception("Invalid tool type ID");
using DbConnection conn = GetDbConnection();
@ -570,7 +570,7 @@ public class MetrologyRepo : IMetrologyRepo
public string GetDataInsertDate(int toolTypeId, long headerId, string title)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (tt is null)
throw new Exception("Invalid tool type ID");
using DbConnection conn = GetDbConnection();
@ -603,7 +603,7 @@ public class MetrologyRepo : IMetrologyRepo
public DataSet GetOIExportData(int toolTypeId, long headerid)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (tt is null)
throw new Exception("Invalid tool type ID");
if (string.IsNullOrWhiteSpace(tt.OIExportSPName))
@ -632,7 +632,7 @@ public class MetrologyRepo : IMetrologyRepo
public IEnumerable<HeaderCommon> GetHeaderTitles(int toolTypeId, int? pageNo, int? pageSize, out long totalRecords)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (tt is null)
throw new Exception("Invalid tool type ID");
using DbConnection conn = GetDbConnection();
@ -661,11 +661,11 @@ public class MetrologyRepo : IMetrologyRepo
public IEnumerable<KeyValuePair<string, string>> GetHeaderFields(int toolTypeId, long headerid)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (tt is null)
throw new Exception("Invalid tool type ID");
IEnumerable<ToolTypeMetadata> md = GetToolTypeMetadataByToolTypeID(toolTypeId);
if (md == null)
if (md is null)
throw new Exception("Invalid tool type metadata");
List<KeyValuePair<string, string>> r = new();
@ -692,10 +692,10 @@ public class MetrologyRepo : IMetrologyRepo
foreach (ToolTypeMetadata m in md.Where(m => m.Header == true && m.TableDisplayOrder > 0).OrderBy(m => m.TableDisplayOrder))
{
string v = "";
if (dr != null)
if (dr is not null)
{
object o = dr[m.ColumnName];
if (o != null && !Convert.IsDBNull(o))
if (o is not null && !Convert.IsDBNull(o))
v = Convert.ToString(o);
}
KeyValuePair<string, string> kvp = new(m.DisplayTitle, v);
@ -714,7 +714,7 @@ public class MetrologyRepo : IMetrologyRepo
public int UpdateReviewDate(int toolTypeId, long headerId, bool clearDate)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (tt is null)
throw new Exception("Invalid tool type ID");
using DbConnection conn = GetDbConnection();
@ -736,7 +736,7 @@ public class MetrologyRepo : IMetrologyRepo
public Guid GetHeaderAttachmentIDByTitle(int toolTypeId, string title)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (tt is null)
throw new Exception("Invalid tool type ID");
using DbConnection conn = GetDbConnection();
@ -748,7 +748,7 @@ public class MetrologyRepo : IMetrologyRepo
public Guid GetDataAttachmentIDByTitle(int toolTypeId, string title)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (tt is null)
throw new Exception("Invalid tool type ID");
using DbConnection conn = GetDbConnection();
@ -757,5 +757,5 @@ public class MetrologyRepo : IMetrologyRepo
return conn.ExecuteScalar<Guid>(sql, param: new { Title = title });
}
DataTable IMetrologyRepo.GetDataSharePoint(int toolTypeId, string headerId) => throw new NotImplementedException();
DataTable IMetrologyRepository.GetDataSharePoint(int toolTypeId, string headerId) => throw new NotImplementedException();
}

View File

@ -1,29 +0,0 @@
using OI.Metrology.Shared.Repositories;
using OI.Metrology.Viewer.Models;
using System;
using System.Data.Common;
using System.Data.SqlClient;
namespace OI.Metrology.Viewer.Repositories;
public class SQLDbConnectionFactory : IDbConnectionFactory
{
private readonly AppSettings _AppSettings;
public SQLDbConnectionFactory(AppSettings appSettings) => _AppSettings = appSettings;
public DbConnection GetDbConnection()
{
DbProviderFactories.RegisterFactory(
typeof(SqlConnection).Namespace,
SqlClientFactory.Instance);
if (string.IsNullOrEmpty(_AppSettings.ConnectionString))
throw new Exception("Connection string is missing");
DbConnection c = SqlClientFactory.Instance.CreateConnection();
c.ConnectionString = _AppSettings.ConnectionString;
c.Open();
return c;
}
}

View File

@ -0,0 +1,56 @@
using OI.Metrology.Shared.Models.Stateless;
using OI.Metrology.Shared.ViewModels;
using Serilog.Context;
using System.Text.Json;
namespace OI.Metrology.Viewer.Repository;
public class ServiceShopOrderRepository : IServiceShopOrderRepository
{
private readonly Serilog.ILogger _Log;
public ServiceShopOrderRepository() => _Log = Serilog.Log.ForContext<ServiceShopOrderRepository>();
private static ServiceShopOrder[] GetServiceShopOrders(Shared.Models.ServiceShop? serviceShop)
{
ServiceShopOrder[] result = IServiceShopOrder.GetServiceShopOrders(serviceShop);
return result;
}
private static Shared.Models.ServiceShop? GetServiceShopOrders()
{
Shared.Models.ServiceShop? result;
string jsonFile;
string checkDirectory = Path.Combine(AppContext.BaseDirectory, "Data/Mike");
if (Directory.Exists(checkDirectory))
jsonFile = Path.Combine(checkDirectory, "service-shop.json");
else
jsonFile = Path.Combine(AppContext.BaseDirectory, "service-shop.json");
string json = File.ReadAllText(jsonFile);
result = JsonSerializer.Deserialize<Shared.Models.ServiceShop>(json);
return result;
}
async Task<ServiceShopOrder[]> IServiceShopOrderRepository.GetAllServiceShopOrders()
{
ServiceShopOrder[] results;
string? methodName = IMethodName.GetActualAsyncMethodName();
using (LogContext.PushProperty("MethodName", methodName))
{
_Log.Debug("() => ...");
Shared.Models.ServiceShop? serviceShop = await Task.Run(GetServiceShopOrders);
results = GetServiceShopOrders(serviceShop);
}
return results.ToArray();
}
async Task<ServiceShopOrder[]> IServiceShopOrderRepository.GetServiceShopOrders(string id)
{
ServiceShopOrder[] results;
Shared.Models.ServiceShop? serviceShop = await Task.Run(GetServiceShopOrders);
results = GetServiceShopOrders(serviceShop).Where(l => l.Id == id).ToArray();
return results;
}
}

View File

@ -0,0 +1,177 @@
using Newtonsoft.Json;
using OI.Metrology.Shared.DataModels;
using OI.Metrology.Shared.Models.Stateless;
using OI.Metrology.Shared.Services;
namespace OI.Metrology.Viewer.Repository;
public class ToolTypesRepository : IToolTypesRepository
{
private readonly Serilog.ILogger _Log;
public ToolTypesRepository() => _Log = Serilog.Log.ForContext<ToolTypesRepository>();
// Get a list of tooltypes, returns just Name and ID
object IToolTypesRepository.Index(IMetrologyRepository metrologyRepository)
{
var r = new
{
Results = metrologyRepository.GetToolTypes().Select(tt => new { tt.ToolTypeName, tt.ID })
};
return r;
}
// Gets the metadata for a tooltype, accepts a parameter which sorts the results
// This is used to setup the grid displays on the UI
object IToolTypesRepository.GetToolTypeMetadata(IMetrologyRepository metrologyRepository, int id, string sortby)
{
ToolType tt = metrologyRepository.GetToolTypeByID(id);
IEnumerable<ToolTypeMetadata> md = metrologyRepository.GetToolTypeMetadataByToolTypeID(id);
if (string.Equals(sortby, "grid", StringComparison.OrdinalIgnoreCase))
md = md.OrderBy(f => f.GridDisplayOrder).ToList();
if (string.Equals(sortby, "table", StringComparison.OrdinalIgnoreCase))
md = md.OrderBy(f => f.GridDisplayOrder).ToList();
var r = new
{
Results = new
{
ToolType = tt,
Metadata = md
}
};
return r;
}
// Gets headers, request/response format is to allow paging with igniteUI
// The headerid parameter is used for navigating directly to a header, when the button is clicked in Awaiting Dispo
string IToolTypesRepository.GetHeaders(IMetrologyRepository metrologyRepository, int id, DateTime? datebegin, DateTime? dateend, int? page, int? pagesize, long? headerid)
{
string result;
long totalRecs;
System.Data.DataTable dt = metrologyRepository.GetHeaders(id, datebegin, dateend, page, pagesize, headerid, out totalRecs);
var r = new
{
Results = dt,
TotalRows = totalRecs,
};
result = JsonConvert.SerializeObject(r);
return result;
}
// Gets header titles, used in the Run Headers UI
string IToolTypesRepository.GetHeaderTitles(IMetrologyRepository metrologyRepository, int id, int? page, int? pagesize)
{
string result;
long totalRecs;
IEnumerable<HeaderCommon> dt = metrologyRepository.GetHeaderTitles(id, page, pagesize, out totalRecs);
var r = new
{
Results = dt,
TotalRows = totalRecs,
};
result = JsonConvert.SerializeObject(r);
return result;
}
// Get all of the fields for a header, used with the Run Header UI
string IToolTypesRepository.GetHeaderFields(IMetrologyRepository metrologyRepository, int id, long headerid)
{
string result;
var r = new
{
Results = metrologyRepository.GetHeaderFields(id, headerid).Select(x => new { Column = x.Key, x.Value }).ToList()
};
result = JsonConvert.SerializeObject(r);
return result;
}
// Get the data for a header, used with the Run Info UI
string IToolTypesRepository.GetData(IMetrologyRepository metrologyRepository, int id, long headerid)
{
string result;
var r = new
{
Results = metrologyRepository.GetData(id, headerid)
};
result = JsonConvert.SerializeObject(r);
return result;
}
// Display an attachment, used for Run Info - note it is by tool type ID and attachment GUID, so it is best for internal use
(string?, string?, Stream?) IToolTypesRepository.GetAttachment(IMetrologyRepository metrologyRepository, IAttachmentsService attachmentsService, int toolTypeId, string tabletype, string attachmentId, string filename)
{
Stream? stream = null;
string? message = null;
Guid attachmentIdParsed;
string? contenttype = null;
ToolType tt = metrologyRepository.GetToolTypeByID(toolTypeId);
bool header = !string.Equals(tabletype.Trim(), "data", StringComparison.OrdinalIgnoreCase);
if (!Guid.TryParse(attachmentId, out attachmentIdParsed))
message = "Invalid attachment id";
else
{
try
{
// figure out what content type to use. this is very simple because there are only two types being used
contenttype = "application/pdf";
if (filename.ToLower().TrimEnd().EndsWith(".txt"))
contenttype = "text/plain";
// Get attachment stream and feed it to the client
stream = attachmentsService.GetAttachmentStreamByAttachmentId(tt, header, attachmentIdParsed, filename);
}
catch (Exception ex) { message = ex.Message; }
}
return new(message, contenttype, stream);
}
// This endpoint triggers writing of the OI Export file
Exception? IToolTypesRepository.OIExport(IMetrologyRepository metrologyRepository, string oiExportPath, int toolTypeId, long headerid)
{
Exception? result = null;
// Call the export stored procedure
_Log.Debug($"Exporting to <{oiExportPath}>");
System.Data.DataSet ds = metrologyRepository.GetOIExportData(toolTypeId, headerid);
try
{
// The SP must return 3 result tables
if (ds.Tables.Count != 3)
throw new Exception("Error exporting, invalid results");
// The first table has just one row, which is the export filename
if (ds.Tables[0].Rows.Count != 1)
throw new Exception("Error exporting, invalid filename");
string? filename = Convert.ToString(ds.Tables[0].Rows[0][0]);
// The second table has the header data
if (ds.Tables[1].Rows.Count != 1)
throw new Exception("Error exporting, invalid header data");
System.Text.StringBuilder sb = new();
foreach (object? o in ds.Tables[1].Rows[0].ItemArray)
{
if ((o is not null) && (!Convert.IsDBNull(o)))
_ = sb.Append(Convert.ToString(o));
_ = sb.Append('\t');
}
// The third table has the detail data
foreach (System.Data.DataRow dr in ds.Tables[2].Rows)
{
foreach (object? o in dr.ItemArray)
{
if ((o is not null) && (!Convert.IsDBNull(o)))
_ = sb.Append(Convert.ToString(o));
_ = sb.Append('\t');
}
}
_ = sb.AppendLine();
// The output file will only have one line, the header columns are output first
// Then each detail rows has it's columns appended
// H1, H2, H3, D1.1, D1.2, D1.3, D2.1, D2.2, D2.3, etc
// Write the file
File.WriteAllText(Path.Join(oiExportPath, filename), sb.ToString());
}
catch (Exception ex) { result = ex; }
return result;
}
}