V4.1 with excel stats changes
This commit is contained in:
@@ -8,6 +8,9 @@ namespace AiQ_GUI
|
||||
{
|
||||
private const string exportPath = @"G:\Shared drives\MAV Production GUI's\AiQ\GUI's\AiQ_Test_Stats.xlsx";
|
||||
|
||||
private readonly string exportPath =
|
||||
@"C:\Users\BradleyBorn\OneDrive - MAV Systems Ltd\Desktop\AiQ_Test_Stats.xlsx";
|
||||
|
||||
public void ExportDatabaseToExcel()
|
||||
{
|
||||
try
|
||||
@@ -20,32 +23,52 @@ namespace AiQ_GUI
|
||||
MainForm.Instance.AddToActionsList("Connected to Access database.");
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
// Read LastStatsRun from UniversalData (if any)
|
||||
DateTime? lastStatsRun = null;
|
||||
try
|
||||
{
|
||||
using (var cmdPeriod = new OleDbCommand("SELECT LastStatsRun FROM UniversalData", conn))
|
||||
{
|
||||
object res = cmdPeriod.ExecuteScalar();
|
||||
if (res != null && res != DBNull.Value)
|
||||
lastStatsRun = (DateTime)res;
|
||||
}
|
||||
MainForm.Instance.AddToActionsList($"Fetched LastStatsRun: {(lastStatsRun.HasValue ? lastStatsRun.Value.ToString("yyyy-MM-dd HH:mm:ss") : "none")}");
|
||||
}
|
||||
catch (Exception periodEx)
|
||||
{
|
||||
MainForm.Instance.AddToActionsList($"Warning: could not read LastStatsRun. Details: {periodEx.Message}");
|
||||
}
|
||||
|
||||
// ==================== MAIN STATS EXPORT ====================
|
||||
string selectColumns = @"
|
||||
ModelNumber,
|
||||
[Total Tests Run],
|
||||
[Pre Tests Passed],
|
||||
[Pre Tests Failed],
|
||||
[Final Tests Passed],
|
||||
[Final Tests Failed],
|
||||
[RMA Total Tests Run],
|
||||
[RMA Pre Tests Passed],
|
||||
[RMA Pre Tests Failed],
|
||||
[RMA Final Tests Passed],
|
||||
[RMA Final Tests Failed],
|
||||
[Diagnostic Failure],
|
||||
[Failed To Set Model Or Serial Number],
|
||||
[Camera Not In Test Tube],
|
||||
[Could Not Zoom Modules To 8000],
|
||||
[Could Not Zoom Modules To Full Wide],
|
||||
[Please Get RMA Number From Operations Team Before Continuing],
|
||||
[Please Get A Valid Vaxtor Product Key Before Continuing],
|
||||
[Visual Test Fail - Sleeve Not Aligned],
|
||||
[Visual Test Fail - Not All Front Screws Fitted],
|
||||
[Visual Test Fail - Not All Rear Screws Fitted],
|
||||
[Visual Test Fail - Unit rattles]";
|
||||
ModelNumber,
|
||||
[Total Tests Run],
|
||||
[Pre Tests Passed],
|
||||
[Pre Tests Failed],
|
||||
[Final Tests Passed],
|
||||
[Final Tests Failed],
|
||||
[RMA Total Tests Run],
|
||||
[RMA Pre Tests Passed],
|
||||
[RMA Pre Tests Failed],
|
||||
[RMA Final Tests Passed],
|
||||
[RMA Final Tests Failed],
|
||||
[Diagnostic Failure],
|
||||
[Failed To Set Model Or Serial Number],
|
||||
[Camera Not In Test Tube],
|
||||
[Could Not Zoom Modules To 8000],
|
||||
[Could Not Zoom Modules To Full Wide],
|
||||
[Please Get RMA Number From Operations Team Before Continuing],
|
||||
[Please Get A Valid Vaxtor Product Key Before Continuing],
|
||||
[Visual Test Fail - Sleeve Not Aligned],
|
||||
[Visual Test Fail - Not All Front Screws Fitted],
|
||||
[Visual Test Fail - Not All Rear Screws Fitted],
|
||||
[Visual Test Fail - Unit rattles]";
|
||||
|
||||
string query = $@"SELECT {selectColumns} FROM AiQ";
|
||||
string query = $@"
|
||||
SELECT
|
||||
{selectColumns}
|
||||
FROM AiQ";
|
||||
|
||||
OleDbDataAdapter adapter = new(query, conn);
|
||||
DataTable dataTable = new();
|
||||
@@ -84,8 +107,21 @@ namespace AiQ_GUI
|
||||
ws.Cell(1, 1).InsertTable(dataTable, "AiQ_Stats", true);
|
||||
ws.Columns().AdjustToContents();
|
||||
|
||||
ws.Cell(1, dataTable.Columns.Count + 2).Value = "Exported:";
|
||||
ws.Cell(2, dataTable.Columns.Count + 2).Value = now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
// Write Data Period label and computed period string to the right of the table
|
||||
int infoCol = dataTable.Columns.Count + 2;
|
||||
ws.Cell(1, infoCol).Value = "Data Period";
|
||||
|
||||
string periodText;
|
||||
if (lastStatsRun.HasValue)
|
||||
{
|
||||
periodText = $"{lastStatsRun.Value:yyyy-MM-dd HH:mm:ss} - {now:yyyy-MM-dd HH:mm:ss}";
|
||||
}
|
||||
else
|
||||
{
|
||||
periodText = $"Up to {now:yyyy-MM-dd HH:mm:ss}";
|
||||
}
|
||||
|
||||
ws.Cell(2, infoCol).Value = periodText;
|
||||
|
||||
// ==================== DIAGS STATS EXPORT (CURRENT MONTH ONLY) ====================
|
||||
MainForm.Instance.AddToActionsList("Exporting DiagsStats for current month...");
|
||||
@@ -98,33 +134,36 @@ namespace AiQ_GUI
|
||||
[Date],
|
||||
[Model],
|
||||
[Red Diags Labels],
|
||||
[RhTxBxActions Contents]
|
||||
[RhTxBxActions Contents],
|
||||
[IsRma],
|
||||
[RMA]
|
||||
FROM DiagsStats
|
||||
WHERE [Date] >= ? AND [Date] < ?";
|
||||
|
||||
OleDbDataAdapter diagsAdapter = new(diagsQuery, conn);
|
||||
diagsAdapter.SelectCommand.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.Date, Value = monthStart });
|
||||
diagsAdapter.SelectCommand.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.Date, Value = nextMonth });
|
||||
|
||||
DataTable diagsTable = new();
|
||||
diagsAdapter.Fill(diagsTable);
|
||||
|
||||
if (diagsTable.Rows.Count > 0)
|
||||
using (var diagsCmd = new OleDbCommand(diagsQuery, conn))
|
||||
{
|
||||
int startRow = ws.LastRowUsed().RowNumber() + 3;
|
||||
diagsCmd.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.Date, Value = monthStart });
|
||||
diagsCmd.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.Date, Value = nextMonth });
|
||||
|
||||
ws.Cell(startRow, 1).Value = "Diags Stats (Current Month)";
|
||||
ws.Cell(startRow, 1).Style.Font.Bold = true;
|
||||
ws.Cell(startRow, 1).Style.Font.FontSize = 12;
|
||||
using (var diagsAdapter = new OleDbDataAdapter(diagsCmd))
|
||||
{
|
||||
DataTable diagsTable = new();
|
||||
diagsAdapter.Fill(diagsTable);
|
||||
|
||||
ws.Cell(startRow + 1, 1).InsertTable(diagsTable, "Diags_Stats", true);
|
||||
ws.Columns().AdjustToContents();
|
||||
if (diagsTable.Rows.Count > 0)
|
||||
{
|
||||
int startRow = (ws.LastRowUsed()?.RowNumber() ?? 0) + 3;
|
||||
|
||||
MainForm.Instance.AddToActionsList($"Added DiagsStats ({diagsTable.Rows.Count} rows) starting at row {startRow}.");
|
||||
}
|
||||
else
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("No DiagsStats data found for current month.");
|
||||
ws.Cell(startRow, 1).Value = "Diags Stats (Current Month)";
|
||||
ws.Cell(startRow, 1).Style.Font.Bold = true;
|
||||
ws.Cell(startRow, 1).Style.Font.FontSize = 12;
|
||||
|
||||
ws.Cell(startRow + 1, 1).InsertTable(diagsTable, "Diags_Stats", true);
|
||||
ws.Columns().AdjustToContents();
|
||||
|
||||
MainForm.Instance.AddToActionsList($"Added DiagsStats ({diagsTable.Rows.Count} rows) starting at row {startRow}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== SAVE MAIN SHEET ====================
|
||||
@@ -145,7 +184,6 @@ namespace AiQ_GUI
|
||||
{selectColumns}
|
||||
INTO [{backupTableName}]
|
||||
FROM AiQ";
|
||||
|
||||
try
|
||||
{
|
||||
using (OleDbCommand cmdBackup = new(backupSql, conn))
|
||||
@@ -161,10 +199,11 @@ namespace AiQ_GUI
|
||||
return;
|
||||
}
|
||||
|
||||
using OleDbTransaction tx = conn.BeginTransaction();
|
||||
try
|
||||
using (var tx = conn.BeginTransaction())
|
||||
{
|
||||
string resetSql = @"
|
||||
try
|
||||
{
|
||||
string resetSql = @"
|
||||
UPDATE AiQ SET
|
||||
[Total Tests Run] = 0,
|
||||
[Pre Tests Passed] = 0,
|
||||
|
||||
Reference in New Issue
Block a user