public void FillWorkplace(QC.SqlConnection connection, Workplaces workplace) { using (var command = new QC.SqlCommand()) { command.Connection = connection; command.CommandType = DT.CommandType.Text; command.CommandText = @" SELECT * FROM Workplaces WHERE workplace_id = " + workplace.workplace_id + ";"; QC.SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { workplace.workplace_name = reader.SafeGetString(1); workplace.active_operator = reader.SafeGetInt(2); workplace.active_maintenance = reader.SafeGetInt(3); workplace.active_engineer = reader.SafeGetInt(4); workplace.active_reference = reader.SafeGetString(5); workplace.sibling_workplace = reader.SafeGetInt(6); workplace.sibling_workplace_name = reader.SafeGetString(7); workplace.workplace_unique = reader.GetBoolean(8); workplace.workplace_exclusive = reader.GetBoolean(9); } reader.Close(); } }
public void SwipeProcess(QC.SqlConnection connection, SwipeData swipe) { bool processComplete = false; // Set up "shells" for database data Workers swipeWorker = new Workers(); swipeWorker.worker_id = swipe.sent_id; Workplaces newWorkplace = new Workplaces(); newWorkplace.workplace_id = swipe.sent_workplace; Workplaces oldWorkplace = new Workplaces(); // Fill worker "shell" FillWorker(connection, swipeWorker); FillWorkplace(connection, newWorkplace); oldWorkplace.workplace_id = swipeWorker.workplace_id; FillWorkplace(connection, oldWorkplace); // Check if ID exists // If not, add to the workers database if (!CheckExist(connection, swipeWorker.worker_id)) { //Console.WriteLine("CREATE WORKER ID"); using (var command = new QC.SqlCommand()) { command.Connection = connection; command.CommandType = DT.CommandType.Text; command.CommandText = @" INSERT INTO Workers (worker_id, worker_clearance, login_status) VALUES (" + swipeWorker.worker_id + ", 1, 'FALSE');"; command.ExecuteNonQuery(); } } // What are we doing? Logging in or logging out? if (swipeWorker.worker_id != 0) { // Logout of old workplace if necessary if (swipeWorker.login_status) { if (oldWorkplace.workplace_id == newWorkplace.workplace_id || oldWorkplace.workplace_id == newWorkplace.sibling_workplace) { change_login_status(connection, swipeWorker.worker_id, false); MakeFrame(false, swipeWorker.worker_id, oldWorkplace.workplace_name, oldWorkplace.sibling_workplace_name); processComplete = true; } if (!processComplete && (newWorkplace.workplace_exclusive || oldWorkplace.workplace_exclusive)) { change_login_status(connection, swipeWorker.worker_id, false); MakeFrame(false, swipeWorker.worker_id, oldWorkplace.workplace_name, oldWorkplace.sibling_workplace_name); } } // If new workplace is unique if (!processComplete && newWorkplace.workplace_unique) { // log out current worker change_login_status(connection, newWorkplace.active_operator, false); MakeFrame(false, newWorkplace.active_operator, newWorkplace.workplace_name, newWorkplace.sibling_workplace_name); } // Log into new workplace if (!processComplete) { change_login_status(connection, swipeWorker.worker_id, true); MakeFrame(true, swipeWorker.worker_id, newWorkplace.workplace_name, newWorkplace.sibling_workplace_name); change_worker_workplace(connection, swipeWorker.worker_id, newWorkplace.workplace_name, newWorkplace.sibling_workplace_name, newWorkplace.workplace_id, newWorkplace.sibling_workplace); if (newWorkplace.workplace_unique) { change_workplace_worker(connection, swipeWorker.worker_id, newWorkplace.active_operator); } processComplete = true; } } }