V4.1 with excel stats changes

This commit is contained in:
2025-10-28 16:13:05 +00:00
parent 95fb5d6ab8
commit f95e958ffb
2 changed files with 144 additions and 178 deletions

View File

@@ -1,5 +1,6 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using System.ComponentModel; using System.ComponentModel;
using System.Data.OleDb;
using System.Diagnostics; using System.Diagnostics;
using System.Reflection; using System.Reflection;
@@ -226,7 +227,6 @@ namespace AiQ_GUI
await TestPassed(PCTime); await TestPassed(PCTime);
} }
public void Stats(string TypeOfTest) public void Stats(string TypeOfTest)
{ {
Stats([TypeOfTest]); Stats([TypeOfTest]);
@@ -234,7 +234,7 @@ namespace AiQ_GUI
public void Stats(string[] TypeOfTest) public void Stats(string[] TypeOfTest)
{ {
using OleDbConnection conn = new(connString); // Opens connection to Access database using OleDbConnection conn = new(Access.connString); // Opens connection to Access database
try try
{ {
conn.Open(); // Opens DB conn.Open(); // Opens DB
@@ -263,7 +263,7 @@ namespace AiQ_GUI
public void StatsDiags(string redDiagLabels, string RhTxBxActionsText, string IsRMA, int RMA) public void StatsDiags(string redDiagLabels, string RhTxBxActionsText, string IsRMA, int RMA)
{ {
using OleDbConnection conn = new(connString); using OleDbConnection conn = new(Access.connString);
conn.Open(); conn.Open();
// Null checks // Null checks
@@ -288,8 +288,6 @@ namespace AiQ_GUI
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
private async void BtnPreTest_Click(object sender, EventArgs e) private async void BtnPreTest_Click(object sender, EventArgs e)
{ {
// Show user test has started // Show user test has started
@@ -337,6 +335,8 @@ namespace AiQ_GUI
await AllocateSerial(); await AllocateSerial();
else if (GoogleAPI.UpdateSpreadSheetRePreTest(CameraAccessInfo.SpreadsheetID, Vers) != "OK") // If rerun might be different values so update SS else if (GoogleAPI.UpdateSpreadSheetRePreTest(CameraAccessInfo.SpreadsheetID, Vers) != "OK") // If rerun might be different values so update SS
AddToActionsList("Failed to write to spreadsheet, please check manually"); AddToActionsList("Failed to write to spreadsheet, please check manually");
// else if (Excel.UpdateSpreadSheetPreTest(CameraAccessInfo.SpreadsheetID, Vers, CamOnTest.GetCamDesc(), CamOnTest.Model) != "OK")
// AddToActionsList("Failed to write to spreadsheet, please check manually");
} }
else // No serial or model so allocate one else // No serial or model so allocate one
await AllocateSerial(); await AllocateSerial();
@@ -415,25 +415,23 @@ namespace AiQ_GUI
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
{
Access.Stats(["Final Tests Failed", ErrMssg], CamOnTest.Model);
}
else
{
Access.Stats("RMA Final Tests Failed", CamOnTest.Model);
}
AddToActionsList(ErrMssg);
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;
Access.StatsDiags(RedLbls, RhTxBxActions.Text, CamOnTest.Model); // 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."))
{ {
@@ -451,8 +449,6 @@ namespace AiQ_GUI
// Joins the actions box to any red labels to use as a full failed text // Joins the actions box to any red labels to use as a full failed text
Logging.LogErrorMessage(FullFailureValues); Logging.LogErrorMessage(FullFailureValues);
IList<IList<object>> values = GoogleAPI.service.Spreadsheets.Values.Get(GoogleAPI.spreadsheetId_ModelInfo, "'Approval'!A1:A").Execute().Values; IList<IList<object>> values = GoogleAPI.service.Spreadsheets.Values.Get(GoogleAPI.spreadsheetId_ModelInfo, "'Approval'!A1:A").Execute().Values;
if (values?.Count > 0) if (values?.Count > 0)
@@ -526,12 +522,23 @@ 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
{
Access.Stats(["Pre Tests Failed", ErrMssg], CamOnTest.Model);
}
else
{
Access.Stats("RMA Pre Tests Failed", CamOnTest.Model);
}
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;
Access.StatsDiags(RedLbls, RhTxBxActions.Text, CamOnTest.Model); // Log to Access database
if (CamOnTest.RMANum == 0) // Yap to check if it is not a RMA if (CamOnTest.RMANum == 0) // Yap to check if it is not a RMA
{ {
Stats(["Pre Tests Failed", ErrMssg]); Stats(["Pre Tests Failed", ErrMssg]);
@@ -543,10 +550,6 @@ namespace AiQ_GUI
StatsDiags(RedLbls, RhTxBxActions.Text, "TRUE", CamOnTest.RMANum); StatsDiags(RedLbls, RhTxBxActions.Text, "TRUE", CamOnTest.RMANum);
} }
// Log to Access database
Access.StatsDiags(RedLbls, RhTxBxActions.Text, CamOnTest.Model); // 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();
} }
@@ -1127,7 +1130,6 @@ namespace AiQ_GUI
PnlInputValue.Visible = true; PnlInputValue.Visible = true;
while (Flags.Done == false) // Waiting for user input in RMA Num panel while (Flags.Done == false) // Waiting for user input in RMA Num panel
{
await Task.Delay(100); // Check every 100ms await Task.Delay(100); // Check every 100ms
Flags.Done = false; // Reset flag Flags.Done = false; // Reset flag
@@ -1786,41 +1788,9 @@ namespace AiQ_GUI
{ {
Stopwatch stopWatchTest = Stopwatch.StartNew(); Stopwatch stopWatchTest = Stopwatch.StartNew();
//StatsExcel excelExporter = new();
//excelExporter.ExportDatabaseToExcel();
StatsExcel excelExporter = new(); StatsExcel excelExporter = new();
excelExporter.ExportDatabaseToExcel(); excelExporter.ExportDatabaseToExcel();
// FakeCamera fakeCamera = new FakeCamera(80); // Create an instance of FakeCamera
// //CamOnTest.IP = CbBxFoundCams.Text;
// _ = fakeCamera.StartAsync(CAMTYPE.BAD).ContinueWith(task =>
// {
// //Network.Initialize("developer", "Pass123");
// if (task.IsFaulted)
// {
// AddToActionsList("Error starting FakeCamera: " + task.Exception?.Message);
// }
// else
// {
// AddToActionsList($"FakeCamera started successfully. IP: {fakeCamera}", false);
// }
// });
// await Task.Delay(3000); // Wait for server to start
// CbBxFoundCams.Text = "localhost"; // Should force update in creds an network reinit
// CmBoFoundCams_TextChanged(sender, e);
// CbBxCameraType.SelectedIndex = CbBxCameraType.Items.Count - 1; // Selects AB12CD as model number
// await Task.Delay(3000); // Wait for server to start
//BtnPreTest_Click(sender, e);
stopWatchTest.Stop(); stopWatchTest.Stop();
AddToActionsList("RunTime " + stopWatchTest.Elapsed.ToString(@"hh\:mm\:ss\.ff")); AddToActionsList("RunTime " + stopWatchTest.Elapsed.ToString(@"hh\:mm\:ss\.ff"));
} }

View File

@@ -8,17 +8,13 @@ namespace AiQ_GUI
{ {
private const string exportPath = @"G:\Shared drives\MAV Production GUI's\AiQ\GUI's\AiQ_Test_Stats.xlsx"; 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() public void ExportDatabaseToExcel()
{ {
try try
{ {
MainForm.Instance.AddToActionsList("=== ExportDatabaseToExcel START ==="); MainForm.Instance.AddToActionsList("=== ExportDatabaseToExcel START ===");
using (OleDbConnection conn = new(Access.connString)) using OleDbConnection conn = new(Access.connString);
{
conn.Open(); conn.Open();
MainForm.Instance.AddToActionsList("Connected to Access database."); MainForm.Instance.AddToActionsList("Connected to Access database.");
DateTime now = DateTime.Now; DateTime now = DateTime.Now;