Final Changes to Stats Excel - This has been tested via Fake Cam Test all scenearios and published and tested
This commit is contained in:
98
AiQ_GUI.cs
98
AiQ_GUI.cs
@@ -42,7 +42,7 @@ namespace AiQ_GUI
|
|||||||
Stopwatch stopwatch = Stopwatch.StartNew();
|
Stopwatch stopwatch = Stopwatch.StartNew();
|
||||||
|
|
||||||
Task? closeProcessesTask = Windows.CloseProcesses(); // Fire and forget closing other apps
|
Task? closeProcessesTask = Windows.CloseProcesses(); // Fire and forget closing other apps
|
||||||
//Windows.UpdateFirewall();
|
Windows.UpdateFirewall();
|
||||||
Task UniDataTask = Task.Run(() => Access.ReadUniData()); // Get universal data
|
Task UniDataTask = Task.Run(() => Access.ReadUniData()); // Get universal data
|
||||||
Task<LocalDataStore> LDSWAIT = Task.Run(() => LDS.GetLDS()); // Get and deserialise LDS.json
|
Task<LocalDataStore> LDSWAIT = Task.Run(() => LDS.GetLDS()); // Get and deserialise LDS.json
|
||||||
Task<string> guiVerTask = Task.Run(() => GUIUpdate.FindGUIVersion()); // Get GUI Version
|
Task<string> guiVerTask = Task.Run(() => GUIUpdate.FindGUIVersion()); // Get GUI Version
|
||||||
@@ -108,7 +108,7 @@ namespace AiQ_GUI
|
|||||||
CbBxIris.SelectedIndex = lds.Iris;
|
CbBxIris.SelectedIndex = lds.Iris;
|
||||||
CbBxGain.SelectedIndex = lds.Gain;
|
CbBxGain.SelectedIndex = lds.Gain;
|
||||||
|
|
||||||
if (lds.User == "Bradley")
|
if (lds.User == "Bradley" || lds.User == "Sophie")
|
||||||
BtnTest.Visible = true;
|
BtnTest.Visible = true;
|
||||||
|
|
||||||
TxBxCheckValid(TxBxPsuIP); // Set save button color if valid
|
TxBxCheckValid(TxBxPsuIP); // Set save button color if valid
|
||||||
@@ -269,7 +269,7 @@ namespace AiQ_GUI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StatsDiags(string redDiagLabels, string RhTxBxActionsText)
|
public void StatsDiags(string redDiagLabels, string RhTxBxActionsText, string IsRMA, int RMA)
|
||||||
{
|
{
|
||||||
using OleDbConnection conn = new(connString);
|
using OleDbConnection conn = new(connString);
|
||||||
conn.Open();
|
conn.Open();
|
||||||
@@ -280,26 +280,20 @@ namespace AiQ_GUI
|
|||||||
string model = string.IsNullOrWhiteSpace(CamOnTest?.Model) ? "-" : CamOnTest.Model;
|
string model = string.IsNullOrWhiteSpace(CamOnTest?.Model) ? "-" : CamOnTest.Model;
|
||||||
|
|
||||||
string sql = @"
|
string sql = @"
|
||||||
INSERT INTO DiagsStats ([Date], [Model], [Red Diags Labels], [RhTxBxActions Contents])
|
INSERT INTO DiagsStats ([Date], [Model], [Red Diags Labels], [RhTxBxActions Contents],[IsRMA],[RMA])
|
||||||
VALUES (?, ?, ?, ?)";
|
VALUES (?, ?, ?, ?, ?, ?)";
|
||||||
|
|
||||||
using OleDbCommand cmd = new(sql, conn);
|
using OleDbCommand cmd = new(sql, conn);
|
||||||
|
|
||||||
cmd.Parameters.Add(new OleDbParameter
|
// OleDb uses positional parameters — order must match the VALUES list above
|
||||||
{
|
cmd.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.Date, Value = DateTime.Now });
|
||||||
OleDbType = OleDbType.Date,
|
cmd.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.VarWChar, Value = model });
|
||||||
Value = DateTime.Now
|
cmd.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.VarWChar, Value = redVal });
|
||||||
});
|
cmd.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.VarWChar, Value = actVal });
|
||||||
cmd.Parameters.AddWithValue("?", model);
|
cmd.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.Boolean, Value = IsRMA });
|
||||||
cmd.Parameters.AddWithValue("?", redVal);
|
cmd.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.VarWChar, Value = RMA });
|
||||||
cmd.Parameters.AddWithValue("?", actVal);
|
|
||||||
|
|
||||||
int rows = cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
|
|
||||||
//if (rows > 0)
|
|
||||||
// AddToActionsList($"DiagsStats inserted ({rows} row) for model '{model}' on {DateTime.Now:yyyy-MM-dd}");
|
|
||||||
//else
|
|
||||||
// AddToActionsList("No rows inserted into DiagsStats (unexpected).");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -428,15 +422,6 @@ namespace AiQ_GUI
|
|||||||
// Indicators to the user the test has failed
|
// Indicators to the user the test has failed
|
||||||
Btn.BackColor = Color.Maroon;
|
Btn.BackColor = Color.Maroon;
|
||||||
Btn.Text = "Test Failed";
|
Btn.Text = "Test Failed";
|
||||||
if (!(CamOnTest.RMANum != 0)) // Yap to check if it is not a RMA
|
|
||||||
{
|
|
||||||
Stats( ["Final Tests Failed", ErrMssg]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Stats("RMA Final Tests Failed");
|
|
||||||
}
|
|
||||||
AddToActionsList(ErrMssg);
|
|
||||||
|
|
||||||
string RedLbls = string.Join(Environment.NewLine, PnlLbls.Controls
|
string RedLbls = string.Join(Environment.NewLine, PnlLbls.Controls
|
||||||
.OfType<Label>()
|
.OfType<Label>()
|
||||||
@@ -444,7 +429,18 @@ namespace AiQ_GUI
|
|||||||
.Select(lbl => lbl.Text)); // Extract text
|
.Select(lbl => lbl.Text)); // Extract text
|
||||||
string FullFailureValues = RhTxBxActions.Text + Environment.NewLine + RedLbls;
|
string FullFailureValues = RhTxBxActions.Text + Environment.NewLine + RedLbls;
|
||||||
|
|
||||||
StatsDiags(RedLbls, RhTxBxActions.Text); // Log to Access database
|
|
||||||
|
// Database logging \\
|
||||||
|
if (!(CamOnTest.RMANum != 0)) // Yap to check if it is not a RMA
|
||||||
|
{
|
||||||
|
Stats(["Final Tests Failed", ErrMssg]);
|
||||||
|
StatsDiags(RedLbls, RhTxBxActions.Text, "FALSE", CamOnTest.RMANum);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Stats("RMA Final Tests Failed");
|
||||||
|
StatsDiags(RedLbls, RhTxBxActions.Text, "TRUE", CamOnTest.RMANum);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (await DisplayQuestion("Test failed, appeal?" + Environment.NewLine + "See Actions textbox for details."))
|
if (await DisplayQuestion("Test failed, appeal?" + Environment.NewLine + "See Actions textbox for details."))
|
||||||
@@ -538,22 +534,24 @@ namespace AiQ_GUI
|
|||||||
BtnNo.Visible = false;
|
BtnNo.Visible = false;
|
||||||
Logging.LogMessage("Pre Test Failed");
|
Logging.LogMessage("Pre Test Failed");
|
||||||
|
|
||||||
if (CamOnTest.RMANum == 0) // Yap to check if it is not a RMA
|
|
||||||
{
|
|
||||||
Stats(["Pre Tests Failed", ErrMssg]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Stats("RMA Pre Tests Failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
string RedLbls = string.Join(Environment.NewLine, PnlLbls.Controls
|
string RedLbls = string.Join(Environment.NewLine, PnlLbls.Controls
|
||||||
.OfType<Label>()
|
.OfType<Label>()
|
||||||
.Where(lbl => lbl.ForeColor == Color.Red) // Only include red labels
|
.Where(lbl => lbl.ForeColor == Color.Red) // Only include red labels
|
||||||
.Select(lbl => lbl.Text)); // Extract text
|
.Select(lbl => lbl.Text)); // Extract text
|
||||||
string FullFailureValues = RhTxBxActions.Text + Environment.NewLine + RedLbls;
|
string FullFailureValues = RhTxBxActions.Text + Environment.NewLine + RedLbls;
|
||||||
|
|
||||||
StatsDiags(RedLbls, RhTxBxActions.Text); // Log to Access database
|
if (CamOnTest.RMANum == 0) // Yap to check if it is not a RMA
|
||||||
|
{
|
||||||
|
Stats(["Pre Tests Failed", ErrMssg]);
|
||||||
|
StatsDiags(RedLbls, RhTxBxActions.Text, "FALSE", CamOnTest.RMANum);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Stats("RMA Pre Tests Failed");
|
||||||
|
StatsDiags(RedLbls, RhTxBxActions.Text, "TRUE", CamOnTest.RMANum);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log to Access database
|
||||||
|
|
||||||
if (await DisplayQuestion("Test failed, restart?" + Environment.NewLine + "See Actions textbox for details."))
|
if (await DisplayQuestion("Test failed, restart?" + Environment.NewLine + "See Actions textbox for details."))
|
||||||
Helper.RestartApp();
|
Helper.RestartApp();
|
||||||
@@ -1860,11 +1858,11 @@ namespace AiQ_GUI
|
|||||||
StatsExcel excelExporter = new();
|
StatsExcel excelExporter = new();
|
||||||
excelExporter.ExportDatabaseToExcel();
|
excelExporter.ExportDatabaseToExcel();
|
||||||
|
|
||||||
// FakeCamera fakeCamera = new FakeCamera(80); // Create an instance of FakeCamera
|
//FakeCamera fakeCamera = new FakeCamera(80); // Create an instance of FakeCamera
|
||||||
|
|
||||||
// //CamOnTest.IP = CbBxFoundCams.Text;
|
////CamOnTest.IP = CbBxFoundCams.Text;
|
||||||
// _ = fakeCamera.StartAsync(CAMTYPE.BAD).ContinueWith(task =>
|
//_ = fakeCamera.StartAsync(CAMTYPE.GOOD).ContinueWith(task =>
|
||||||
// {
|
//{
|
||||||
// //Network.Initialize("developer", "Pass123");
|
// //Network.Initialize("developer", "Pass123");
|
||||||
|
|
||||||
// if (task.IsFaulted)
|
// if (task.IsFaulted)
|
||||||
@@ -1875,16 +1873,16 @@ namespace AiQ_GUI
|
|||||||
// {
|
// {
|
||||||
// AddToActionsList($"FakeCamera started successfully. IP: {fakeCamera}", false);
|
// AddToActionsList($"FakeCamera started successfully. IP: {fakeCamera}", false);
|
||||||
// }
|
// }
|
||||||
// });
|
//});
|
||||||
|
|
||||||
// await Task.Delay(3000); // Wait for server to start
|
//await Task.Delay(3000); // Wait for server to start
|
||||||
// CbBxFoundCams.Text = "localhost"; // Should force update in creds an network reinit
|
//CbBxFoundCams.Text = "localhost"; // Should force update in creds an network reinit
|
||||||
// CmBoFoundCams_TextChanged(sender, e);
|
//CmBoFoundCams_TextChanged(sender, e);
|
||||||
// CbBxCameraType.SelectedIndex = CbBxCameraType.Items.Count - 1; // Selects AB12CD as model number
|
//CbBxCameraType.SelectedIndex = CbBxCameraType.Items.Count - 1; // Selects AB12CD as model number
|
||||||
|
|
||||||
// await Task.Delay(3000); // Wait for server to start
|
//await Task.Delay(3000); // Wait for server to start
|
||||||
|
|
||||||
//BtnPreTest_Click(sender, e);
|
//BtnStartTest_Click(sender, e);
|
||||||
|
|
||||||
|
|
||||||
stopWatchTest.Stop();
|
stopWatchTest.Stop();
|
||||||
|
|||||||
@@ -26,6 +26,23 @@ namespace AiQ_GUI.Microsoft
|
|||||||
|
|
||||||
DateTime now = DateTime.Now;
|
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 ====================
|
// ==================== MAIN STATS EXPORT ====================
|
||||||
string selectColumns = @"
|
string selectColumns = @"
|
||||||
ModelNumber,
|
ModelNumber,
|
||||||
@@ -93,8 +110,21 @@ namespace AiQ_GUI.Microsoft
|
|||||||
ws.Cell(1, 1).InsertTable(dataTable, "AiQ_Stats", true);
|
ws.Cell(1, 1).InsertTable(dataTable, "AiQ_Stats", true);
|
||||||
ws.Columns().AdjustToContents();
|
ws.Columns().AdjustToContents();
|
||||||
|
|
||||||
ws.Cell(1, dataTable.Columns.Count + 2).Value = "Exported:";
|
// Write Data Period label and computed period string to the right of the table
|
||||||
ws.Cell(2, dataTable.Columns.Count + 2).Value = now.ToString("yyyy-MM-dd HH:mm:ss");
|
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) ====================
|
// ==================== DIAGS STATS EXPORT (CURRENT MONTH ONLY) ====================
|
||||||
MainForm.Instance.AddToActionsList("Exporting DiagsStats for current month...");
|
MainForm.Instance.AddToActionsList("Exporting DiagsStats for current month...");
|
||||||
@@ -107,20 +137,25 @@ namespace AiQ_GUI.Microsoft
|
|||||||
[Date],
|
[Date],
|
||||||
[Model],
|
[Model],
|
||||||
[Red Diags Labels],
|
[Red Diags Labels],
|
||||||
[RhTxBxActions Contents]
|
[RhTxBxActions Contents],
|
||||||
|
[IsRma],
|
||||||
|
[RMA]
|
||||||
FROM DiagsStats
|
FROM DiagsStats
|
||||||
WHERE [Date] >= ? AND [Date] < ?";
|
WHERE [Date] >= ? AND [Date] < ?";
|
||||||
|
|
||||||
OleDbDataAdapter diagsAdapter = new(diagsQuery, conn);
|
using (var diagsCmd = new OleDbCommand(diagsQuery, conn))
|
||||||
diagsAdapter.SelectCommand.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.Date, Value = monthStart });
|
{
|
||||||
diagsAdapter.SelectCommand.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.Date, Value = nextMonth });
|
diagsCmd.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.Date, Value = monthStart });
|
||||||
|
diagsCmd.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.Date, Value = nextMonth });
|
||||||
|
|
||||||
|
using (var diagsAdapter = new OleDbDataAdapter(diagsCmd))
|
||||||
|
{
|
||||||
DataTable diagsTable = new();
|
DataTable diagsTable = new();
|
||||||
diagsAdapter.Fill(diagsTable);
|
diagsAdapter.Fill(diagsTable);
|
||||||
|
|
||||||
if (diagsTable.Rows.Count > 0)
|
if (diagsTable.Rows.Count > 0)
|
||||||
{
|
{
|
||||||
int startRow = ws.LastRowUsed().RowNumber() + 3;
|
int startRow = (ws.LastRowUsed()?.RowNumber() ?? 0) + 3;
|
||||||
|
|
||||||
ws.Cell(startRow, 1).Value = "Diags Stats (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.Bold = true;
|
||||||
@@ -131,9 +166,7 @@ namespace AiQ_GUI.Microsoft
|
|||||||
|
|
||||||
MainForm.Instance.AddToActionsList($"Added DiagsStats ({diagsTable.Rows.Count} rows) starting at row {startRow}.");
|
MainForm.Instance.AddToActionsList($"Added DiagsStats ({diagsTable.Rows.Count} rows) starting at row {startRow}.");
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
|
||||||
MainForm.Instance.AddToActionsList("No DiagsStats data found for current month.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== SAVE MAIN SHEET ====================
|
// ==================== SAVE MAIN SHEET ====================
|
||||||
|
|||||||
Reference in New Issue
Block a user