V4.0
This commit is contained in:
@@ -4,7 +4,7 @@ namespace AiQ_GUI
|
||||
{
|
||||
class Access
|
||||
{
|
||||
const string connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\Shared drives\MAV Production GUI's\AiQ\GUI's\AiQ_Final_Test.accdb;Persist Security Info=False;OLE DB Services=-1;";
|
||||
public const string connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\Shared drives\MAV Production GUI's\AiQ\GUI's\AiQ_Final_Test.accdb;Persist Security Info=False;OLE DB Services=-1;";
|
||||
|
||||
// Reads camera model numbers and descriptions from the database, sorts them alphabetically by model number (except "AB12CD", which appears last), and formats each entry as "ModelNumber - Description".
|
||||
public static string[] ReadCamTypes()
|
||||
@@ -101,11 +101,74 @@ namespace AiQ_GUI
|
||||
CameraAccessInfo.SpreadsheetID = Convert.ToString(reader["SSID"]);
|
||||
conn.Close();
|
||||
}
|
||||
|
||||
public static void Stats(string TypeOfTest, string modelNumber)
|
||||
{
|
||||
Stats([TypeOfTest], modelNumber);
|
||||
}
|
||||
|
||||
public static void Stats(string[] TypeOfTest, string modelNumber)
|
||||
{
|
||||
using OleDbConnection conn = new(connString); // Opens connection to Access database
|
||||
try
|
||||
{
|
||||
conn.Open(); // Opens DB
|
||||
|
||||
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}");
|
||||
}
|
||||
conn.Close();
|
||||
}
|
||||
catch
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("Could not access Access in Google Drive. Is it running?");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static void StatsDiags(string redDiagLabels, string RhTxBxActionsText, string ModelNumber)
|
||||
{
|
||||
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(ModelNumber) ? "-" : ModelNumber;
|
||||
|
||||
const string sql = @"INSERT INTO DiagsStats ([Date], [Model], [Red Diags Labels], [RhTxBxActions Contents]) VALUES (?, ?, ?, ?)";
|
||||
|
||||
using OleDbCommand cmd = new(sql, conn);
|
||||
|
||||
cmd.Parameters.Add(new OleDbParameter
|
||||
{
|
||||
OleDbType = OleDbType.Date,
|
||||
Value = DateTime.Now
|
||||
});
|
||||
cmd.Parameters.AddWithValue("?", model);
|
||||
cmd.Parameters.AddWithValue("?", redVal);
|
||||
cmd.Parameters.AddWithValue("?", actVal);
|
||||
|
||||
int rows = cmd.ExecuteNonQuery();
|
||||
conn.Close();
|
||||
|
||||
//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).");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Expected universal data for the GUI, read from the database
|
||||
public class UniversalData
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user