diff --git a/AiQ_GUI.Designer.cs b/AiQ_GUI.Designer.cs index b951a47..1b71868 100644 --- a/AiQ_GUI.Designer.cs +++ b/AiQ_GUI.Designer.cs @@ -270,7 +270,7 @@ namespace AiQ_GUI CbBxUserName.Font = new Font("Segoe UI Semibold", 10F, FontStyle.Bold); CbBxUserName.ForeColor = SystemColors.Control; CbBxUserName.FormattingEnabled = true; - CbBxUserName.Items.AddRange(new object[] { "Guest", "Clive", "Conor", "Charlie", "Henry", "Sam C", "Sam L", "Simon", "Toby", "Tom" }); + CbBxUserName.Items.AddRange(new object[] { "Guest", "Clive", "Conor", "Charlie", "Henry", "Sam C", "Sam L", "Simon", "Sophie", "Toby", "Tom" }); CbBxUserName.Location = new Point(10, 262); CbBxUserName.Margin = new Padding(4, 3, 4, 3); CbBxUserName.MaxDropDownItems = 20; diff --git a/AiQ_GUI.cs b/AiQ_GUI.cs index 14f0091..7d6dce6 100644 --- a/AiQ_GUI.cs +++ b/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