Files
jdescopingtool/OLD/TestApp/Program.cs
T
Joseph Doherty 26ff8d9b4f Initial commit: JDE Scoping Tool migration project
Set up repository with legacy .NET Framework 4.8 source (OLD/),
new .NET 10 Blazor solution (NEW/), OpenSpec specifications,
documentation, and project configuration.
2026-01-02 07:43:29 -05:00

296 lines
14 KiB
C#
Executable File

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using DataModel.Models;
using DataModel.Process;
using OfficeOpenXml;
using TestApp.Templates;
using WorkerService.Helpers;
using WorkerService.Models.Reporting;
namespace TestApp
{
class Program
{
static void Main(string[] args)
{
List<Val> vals = new List<Val>();
using (ExcelPackage package = new ExcelPackage(new FileInfo(@"D:\OneDrive\OneDrive - Zimmer Biomet\scoping_tool_v4_queries.xlsx")))
{
ExcelWorksheet ws = package.Workbook.Worksheets.First();
for (int row = 2; row <= ws.Dimension.Rows; ++row)
{
Val val = new Val()
{
Name = ws.Cells[row, 1].GetValue<string>(),
TicketNumber = ws.Cells[row, 2].GetValue<string>(),
SearchID = ws.Cells[row, 3].GetValue<int>(),
IndependentShortSQL = ws.Cells[row, 4].GetValue<string>(),
IndependentLongSQL = ws.Cells[row, 5].GetValue<string>(),
ScopingToolSQL = ws.Cells[row, 6].GetValue<string>(),
IndependentReport = ws.Cells[row, 7].GetValue<string>(),
ScopingToolReport = ws.Cells[row, 8].GetValue<string>(),
MergeReport = ws.Cells[row, 9].GetValue<string>(),
};
val.Search = LotFinderDB.GetSearch(val.SearchID);
val.SearchModel = val.Search.ToSearchModel();
vals.Add(val);
}
}
if (false)
{
foreach (Val val in vals)
{
Search search = LotFinderDB.GetSearch(val.SearchID);
SearchModel searchModel = search.ToSearchModel();
string longSQL = new QueryTemplate2(searchModel, true).TransformText().TrimStart();
string shortSQL = new QueryTemplate2(searchModel, false).TransformText().TrimStart();
File.WriteAllText(val.IndependentLongSQL, longSQL);
File.WriteAllText(val.IndependentShortSQL, shortSQL);
}
}
if (true)
{
foreach (Val val in vals)
{
if (File.Exists(val.MergeReport)) { File.Delete(val.MergeReport); }
Console.WriteLine(val.Name);
using (ExcelPackage package = new ExcelPackage(new FileInfo(val.MergeReport)))
{
WriteInstructions(val, package);
using (ExcelPackage stPackage = new ExcelPackage(new FileInfo(val.ScopingToolReport)))
{
using (ExcelPackage iPackage = new ExcelPackage(new FileInfo(val.IndependentReport)))
{
WriteSearchResults(val, package, stPackage.Workbook.Worksheets["Search Results"], iPackage.Workbook.Worksheets["Search Results"]);
if (val.SearchModel.ExtractMisData)
{
WriteMIS(val, package, stPackage.Workbook.Worksheets["MIS Info"], iPackage.Workbook.Worksheets["MIS Info"]);
WriteInvestigation(val, package, stPackage.Workbook.Worksheets["Investigation"], iPackage.Workbook.Worksheets["Investigation"]);
}
}
}
package.Save();
}
}
}
Console.WriteLine("\r\nDONE\r\n");
}
private static void WriteInstructions(Val val, ExcelPackage package)
{
int row = 0;
ExcelWorksheet ws = package.Workbook.Worksheets.Add("Instructions");
//Write steps
ws.Cells[++row, 1].Value = "Step #";
ws.Cells[row, 2].Value = "Instruction";
ws.Cells[++row, 1].Value = "1";
ws.Cells[row, 2].Value = $"Copy data from 'Search Results' worksheet in '{val.Name}.xlsx' to 'SearchResults_ScopingToolOutput' worksheet.";
ws.Cells[++row, 1].Value = "2";
ws.Cells[row, 2].Value = $"Copy data from 'Search Results' worksheet in '{val.Name}_Independent.xlsx' to 'SearchResults_IndQueryOutput' worksheet.";
ws.Cells[++row, 1].Value = "3";
ws.Cells[row, 2].Value = "Verify the number of rows in 'SearchResults_ScopingToolOutput' worksheet matches the number of rows in 'SearchResults_IndQueryOutput' worksheet.";
ws.Cells[++row, 1].Value = "4";
ws.Cells[row, 2].Value = "Verify the no cells show 'No Match' in 'SearchResults_Merge' worksheet.";
if (val.SearchModel.ExtractMisData)
{
ws.Cells[++row, 1].Value = "5";
ws.Cells[row, 2].Value = $"Copy data from 'MIS Info' worksheet in '{val.Name}.xlsx' to 'MISInfo_ScopingToolOutput' worksheet.";
ws.Cells[++row, 1].Value = "6";
ws.Cells[row, 2].Value = $"Copy data from 'MIS Info' worksheet in '{val.Name}_Independent.xlsx' to 'MISInfo_IndQueryOutput' worksheet.";
ws.Cells[++row, 1].Value = "7";
ws.Cells[row, 2].Value = "Verify the number of rows in 'MISInfo_ScopingToolOutput' worksheet matches the number of rows in 'MISInfo_IndQueryOutput' worksheet.";
ws.Cells[++row, 1].Value = "8";
ws.Cells[row, 2].Value = "Verify the no cells show 'No Match' in 'MISInfo_Merge' worksheet.";
ws.Cells[++row, 1].Value = "9";
ws.Cells[row, 2].Value = $"Copy data from 'Investigation' worksheet in '{val.Name}.xlsx' to 'Investigation_ScopingToolOutput' worksheet.";
ws.Cells[++row, 1].Value = "10";
ws.Cells[row, 2].Value = $"Copy data from 'Investigation' worksheet in '{val.Name}_Independent.xlsx' to 'Investigation_IndQueryOutput' worksheet.";
ws.Cells[++row, 1].Value = "11";
ws.Cells[row, 2].Value = "Verify the number of rows in 'Investigation_ScopingToolOutput' worksheet matches the number of rows in 'Investigation_IndQueryOutput' worksheet.";
ws.Cells[++row, 1].Value = "12";
ws.Cells[row, 2].Value = "Verify the no cells show 'No Match' in 'Investigation_Merge' worksheet.";
}
//Write definitions
++row;
ws.Cells[++row, 1].Value = "Index";
ws.Cells[row, 2].Value = "Index is an Excel function that looks for a position of a cell in an Excel document and returns with the value of the cell at that position.";
ws.Cells[++row, 1].Value = "Match";
ws.Cells[row, 2].Value = "Match is an Excel function that looks for a value in a cell (user determines where to look) and returns with the position of that cell.";
ws.Cells[++row, 1].Value = "If";
ws.Cells[row, 2].Value = "If is an Excel function that performs a logical test, and if that test is true it will return a value. If the logic test is false it will return another value.";
ws.Cells[++row, 1].Value = "Hyperlink";
ws.Cells[row, 2].Value = "Hyperlink is an Excel function that connects a cell to a different location.";
//Write tab info
++row;
ws.Cells[++row, 2].Value = "For the SearchResults_Merge tab, the first column (Column A) is conducting a hyperlink function. This is looking in the SearchResults_ScopingToolOutput tab for the row number that corresponds with the associated row number from the SearchResults_Merge tab and outputting the corresponding row number.";
ws.Cells[row, 2].Style.WrapText = true;
ws.Cells[++row, 2].Value = "For the SearchResults_Merge tab, the second column (Column B) is conducting a hyperlink function after conducting an index + match function. The index match function looks in the SearchResults_IndQueryOutput tab for the Work Order Number that corresponds with the work order from the row returned in column A. It then outputs the row number from SearchResults_IndQueryOutput tab that has that corresponding work order number.";
ws.Cells[row, 2].Style.WrapText = true;
if (val.SearchModel.ExtractMisData)
{
ws.Cells[++row, 2].Value = "For all other cells in the SearchResults_Merge tab as well as the MISInfo_Merge & Investigation_Merge tabs an If function is used. The If function compares the output values of the corresponding cells from the JDE Scoping Tool output and the Independent Query Output.";
ws.Cells[row, 2].Style.WrapText = true;
}
ws.Column(1).Width = 10;
ws.Column(2).Width = 200;
}
private static void WriteSearchResults(Val val, ExcelPackage package, ExcelWorksheet stWS, ExcelWorksheet iWS)
{
string stWSName = "SearchResults_ScopingToolOutput";
string iWSName = "SearchResults_IndQueryOutput";
string mergeWSName = "SearchResults_Merge";
package.Workbook.Worksheets.Add(stWSName, stWS);
package.Workbook.Worksheets.Add(iWSName, iWS);
ExcelWorksheet ws = package.Workbook.Worksheets.Add(mergeWSName);
//Write header
ws.Cells[1, 1].Value = "Scoping Tool";
ws.Cells[1, 2].Value = "Independent Query";
for (int col = 1; col <= stWS.Dimension.Columns; col++)
{
ws.Cells[1, 2 + col].Value = stWS.Cells[1, col].Value;
}
int numRows = stWS.Dimension.Rows;
int numCols = stWS.Dimension.Columns;
ws.Cells[2, 1, numRows, 1].Formula = $"HYPERLINK(\"#{stWSName}!A\"&ROW(),ROW())";
ws.Cells[2, 2, numRows, 2].Formula = $"HYPERLINK(\"#{iWSName}!A\"&MATCH(INDEX({stWSName}!$A$1:$A${numRows},$A2),{iWSName}!$A$1:$A${numRows},0),MATCH(INDEX({stWSName}!$A$1:$A${numRows},$A2),{iWSName}!$A$1:$A${numRows},0))";
for (int col = 0; col < numCols; col++)
{
char colLetter = (char)(65 + col);
ws.Cells[2, col + 3, numRows, col + 3].Formula = $"IF(INDEX({stWSName}!${colLetter}$1:${colLetter}${numRows},$A2)=INDEX({iWSName}!${colLetter}$1:${colLetter}${numRows},$B2),\"Match\",\"No Match\")";
}
for (int col = 1; col <= ws.Dimension.Columns; col++)
{
ws.Column(col).AutoFit();
ws.Column(col).Width *= 1.15;
}
}
private static void WriteMIS(Val val, ExcelPackage package, ExcelWorksheet stWS, ExcelWorksheet iWS)
{
string stWSName = "MISInfo_ScopingToolOutput";
string iWSName = "MISInfo_IndQueryOutput";
string mergeWSName = "MISInfo_Merge";
package.Workbook.Worksheets.Add(stWSName, stWS);
package.Workbook.Worksheets.Add(iWSName, iWS);
ExcelWorksheet ws = package.Workbook.Worksheets.Add(mergeWSName);
//Write header
for (int col = 1; col <= stWS.Dimension.Columns; col++)
{
ws.Cells[1,col].Value = stWS.Cells[1, col].Value;
}
int numRows = stWS.Dimension.Rows;
int numCols = stWS.Dimension.Columns;
for (int col = 1; col <= numCols; col++)
{
char colLetter = (char)(65 + col);
ws.Cells[2, col, numRows, col].Formula = $"IF({stWSName}!{colLetter}2={iWSName}!{colLetter}2,\"Match\",\"No Match\")";
}
for (int col = 1; col <= ws.Dimension.Columns; col++)
{
ws.Column(col).AutoFit();
ws.Column(col).Width *= 1.15;
}
}
private static void WriteInvestigation(Val val, ExcelPackage package, ExcelWorksheet stWS, ExcelWorksheet iWS)
{
string stWSName = "Investigation_ScopingToolOutput";
string iWSName = "Investigation_IndQueryOutput";
string mergeWSName = "Investigation_Merge";
package.Workbook.Worksheets.Add(stWSName, stWS);
package.Workbook.Worksheets.Add(iWSName, iWS);
ExcelWorksheet ws = package.Workbook.Worksheets.Add(mergeWSName);
//Write header
for (int col = 1; col <= stWS.Dimension.Columns; col++)
{
ws.Cells[1, col].Value = stWS.Cells[1, col].Value;
}
int numRows = stWS.Dimension.Rows;
int numCols = stWS.Dimension.Columns;
for (int col = 1; col <= numCols; col++)
{
char colLetter = (char)(65 + col);
ws.Cells[2, col, numRows, col].Formula = $"IF({stWSName}!{colLetter}2={iWSName}!{colLetter}2,\"Match\",\"No Match\")";
}
for (int col = 1; col <= ws.Dimension.Columns; col++)
{
ws.Column(col).AutoFit();
ws.Column(col).Width *= 1.15;
}
}
}
class Val
{
public string Name { get; set; }
public string TicketNumber { get; set; }
public int SearchID { get; set; }
public Search Search { get; set; }
public SearchModel SearchModel { get; set; }
public string IndependentLongSQL { get; set; }
public string IndependentShortSQL { get; set; }
public string ScopingToolSQL { get; set; }
public string IndependentReport { get; set; }
public string ScopingToolReport { get; set; }
public string MergeReport { get; set; }
}
}