V4.1 with excel stats changes
This commit is contained in:
165
AiQ_GUI.cs
165
AiQ_GUI.cs
@@ -103,7 +103,7 @@ namespace AiQ_GUI
|
||||
CbBxIris.SelectedIndex = lds.Iris;
|
||||
CbBxGain.SelectedIndex = lds.Gain;
|
||||
|
||||
if (lds.User == "Bradley")
|
||||
if (lds.User == "Bradley" || lds.User == "Sophie")
|
||||
BtnTest.Visible = true;
|
||||
|
||||
TxBxCheckValid(TxBxPsuIP); // Set save button color if valid
|
||||
@@ -199,6 +199,7 @@ namespace AiQ_GUI
|
||||
if (!LEDreply.Contains("Power levels set successfully"))
|
||||
AddToActionsList($"LED level could not be set: {LEDreply}");
|
||||
}
|
||||
await FlexiAPI.SetVaxtorMinMaxPlate(CamOnTest.IP);
|
||||
|
||||
DateTime PCTime = DateTime.Now; // Grab PC time as close to the API as possible to pass onto PDF later
|
||||
|
||||
@@ -226,6 +227,69 @@ namespace AiQ_GUI
|
||||
await TestPassed(PCTime);
|
||||
}
|
||||
|
||||
public void Stats(string TypeOfTest)
|
||||
{
|
||||
Stats([TypeOfTest]);
|
||||
}
|
||||
|
||||
public void Stats(string[] TypeOfTest)
|
||||
{
|
||||
using OleDbConnection conn = new(connString); // Opens connection to Access database
|
||||
try
|
||||
{
|
||||
conn.Open(); // Opens DB
|
||||
string modelNumber = CbBxCameraType.Text.Substring(0, 6); // Get model number from combobox and make sure it is only 6 characters.
|
||||
|
||||
foreach (string type in TypeOfTest)
|
||||
{
|
||||
string query = $"UPDATE AiQ SET [{type}] = [{type}] + 1 WHERE [ModelNumber] = ?"; // Add one for every test ran of this type for this model number
|
||||
using OleDbCommand cmd = new(query, conn); // Create command
|
||||
cmd.Parameters.AddWithValue("?", modelNumber); // Add model number to prevent injection
|
||||
|
||||
int rowsAffected = cmd.ExecuteNonQuery();
|
||||
// Execute the command and get the number of rows affected
|
||||
//if (rowsAffected > 0) // If one or more rows were updated
|
||||
// AddToActionsList($"Updated {TypeOfTest} for {modelNumber}");
|
||||
//else
|
||||
// AddToActionsList($"No rows found for {modelNumber}");
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
AddToActionsList("Could not access Access in Google Drive. Is it running?");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void StatsDiags(string redDiagLabels, string RhTxBxActionsText, string IsRMA, int RMA)
|
||||
{
|
||||
using OleDbConnection conn = new(connString);
|
||||
conn.Open();
|
||||
|
||||
// Null checks
|
||||
string redVal = string.IsNullOrWhiteSpace(redDiagLabels) ? "-" : redDiagLabels;
|
||||
string actVal = string.IsNullOrWhiteSpace(RhTxBxActionsText) ? "-" : RhTxBxActionsText;
|
||||
string model = string.IsNullOrWhiteSpace(CamOnTest?.Model) ? "-" : CamOnTest.Model;
|
||||
|
||||
string sql = @"
|
||||
INSERT INTO DiagsStats ([Date], [Model], [Red Diags Labels], [RhTxBxActions Contents],[IsRMA],[RMA])
|
||||
VALUES (?, ?, ?, ?, ?, ?)";
|
||||
|
||||
using OleDbCommand cmd = new(sql, conn);
|
||||
|
||||
// OleDb uses positional parameters — order must match the VALUES list above
|
||||
cmd.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.Date, Value = DateTime.Now });
|
||||
cmd.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.VarWChar, Value = model });
|
||||
cmd.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.VarWChar, Value = redVal });
|
||||
cmd.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.VarWChar, Value = actVal });
|
||||
cmd.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.Boolean, Value = IsRMA });
|
||||
cmd.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.VarWChar, Value = RMA });
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private async void BtnPreTest_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Show user test has started
|
||||
@@ -273,8 +337,6 @@ namespace AiQ_GUI
|
||||
await AllocateSerial();
|
||||
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");
|
||||
// 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
|
||||
await AllocateSerial();
|
||||
@@ -286,8 +348,8 @@ namespace AiQ_GUI
|
||||
{
|
||||
await PreTestFailed("Diagnostic Failure");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// ***** Pass/Fails *****
|
||||
@@ -352,15 +414,6 @@ namespace AiQ_GUI
|
||||
// Indicators to the user the test has failed
|
||||
Btn.BackColor = Color.Maroon;
|
||||
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
|
||||
.OfType<Label>()
|
||||
@@ -368,7 +421,18 @@ namespace AiQ_GUI
|
||||
.Select(lbl => lbl.Text)); // Extract text
|
||||
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."))
|
||||
@@ -388,7 +452,6 @@ namespace AiQ_GUI
|
||||
Logging.LogErrorMessage(FullFailureValues);
|
||||
|
||||
|
||||
Logging.LogErrorMessage(FullFailureValues);
|
||||
|
||||
IList<IList<object>> values = GoogleAPI.service.Spreadsheets.Values.Get(GoogleAPI.spreadsheetId_ModelInfo, "'Approval'!A1:A").Execute().Values;
|
||||
|
||||
@@ -463,21 +526,25 @@ namespace AiQ_GUI
|
||||
BtnNo.Visible = false;
|
||||
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
|
||||
.OfType<Label>()
|
||||
.Where(lbl => lbl.ForeColor == Color.Red) // Only include red labels
|
||||
.Select(lbl => lbl.Text)); // Extract text
|
||||
string FullFailureValues = RhTxBxActions.Text + Environment.NewLine + RedLbls;
|
||||
|
||||
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
|
||||
|
||||
Access.StatsDiags(RedLbls, RhTxBxActions.Text, CamOnTest.Model); // Log to Access database
|
||||
|
||||
if (await DisplayQuestion("Test failed, restart?" + Environment.NewLine + "See Actions textbox for details."))
|
||||
@@ -679,7 +746,7 @@ namespace AiQ_GUI
|
||||
Access.Stats("Please Get A Valid Vaxtor Product Key Before Continuing", CamOnTest.Model);
|
||||
await TestFailed(BtnStartTest, "Please get a valid Vaxtor Product Key before continuing");
|
||||
}
|
||||
|
||||
|
||||
|
||||
DiagsAPI.licenses.raptorKeyID = TxBxProductKey.Text;
|
||||
lblVaxtor.Text += DiagsAPI.licenses.raptorKeyID;
|
||||
@@ -1060,6 +1127,7 @@ namespace AiQ_GUI
|
||||
PnlInputValue.Visible = true;
|
||||
|
||||
while (Flags.Done == false) // Waiting for user input in RMA Num panel
|
||||
{
|
||||
await Task.Delay(100); // Check every 100ms
|
||||
|
||||
Flags.Done = false; // Reset flag
|
||||
@@ -1722,36 +1790,37 @@ namespace AiQ_GUI
|
||||
//excelExporter.ExportDatabaseToExcel();
|
||||
|
||||
|
||||
//FakeCamera fakeCamera = new FakeCamera(80); // Create an instance of FakeCamera
|
||||
|
||||
////CamOnTest.IP = CbBxFoundCams.Text;
|
||||
//_ = fakeCamera.StartAsync(CAMTYPE.GOOD).ContinueWith(task =>
|
||||
//{
|
||||
// //Network.Initialize("developer", "Pass123");
|
||||
StatsExcel excelExporter = new();
|
||||
excelExporter.ExportDatabaseToExcel();
|
||||
|
||||
// if (task.IsFaulted)
|
||||
// {
|
||||
// AddToActionsList("Error starting FakeCamera: " + task.Exception?.Message);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// AddToActionsList($"FakeCamera started successfully. IP: {fakeCamera}", false);
|
||||
// }
|
||||
//});
|
||||
// FakeCamera fakeCamera = new FakeCamera(80); // Create an instance of FakeCamera
|
||||
|
||||
//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
|
||||
// //CamOnTest.IP = CbBxFoundCams.Text;
|
||||
// _ = fakeCamera.StartAsync(CAMTYPE.BAD).ContinueWith(task =>
|
||||
// {
|
||||
// //Network.Initialize("developer", "Pass123");
|
||||
|
||||
//await Task.Delay(3000); // Wait for server to start
|
||||
// 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);
|
||||
|
||||
|
||||
Teams.SendMssg("10", "Test User");
|
||||
|
||||
|
||||
stopWatchTest.Stop();
|
||||
AddToActionsList("RunTime " + stopWatchTest.Elapsed.ToString(@"hh\:mm\:ss\.ff"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user