private void UpdateInfoData() { if (dgvActionBrowser.Rows.Count <= 0) { return; } if (dgvActionBrowser.SelectedRows.Count <= 0) { return; } string conlogID = dgvActionBrowser.SelectedRows[0].Cells["ID"].Value.ToString(); string sqlQuery = $"SELECT *, " + $"(SELECT COUNT(*) FROM qd_assigns WHERE qd_assigns.UserID = qd_conlog.UserID) AS AssignedDriveCount, " + $"(SELECT COUNT(*) FROM (SELECT * FROM qd_conlog GROUP BY qd_conlog.UserID) AS TMP WHERE TMP.DeviceID = qd_devices.ID) AS UserCount " + $"FROM qd_conlog " + $"INNER JOIN qd_users ON qd_conlog.UserID = qd_users.ID " + $"INNER JOIN qd_devices ON qd_conlog.DeviceID = qd_devices.ID " + $"WHERE qd_conlog.ID = ?"; using (WrapMySQL mysql = new WrapMySQL(DBData)) { if (!QDLib.ManagedDBOpen(mysql)) { QDLib.DBOpenFailed(); return; } using (MySqlDataReader reader = (MySqlDataReader)mysql.ExecuteQuery(sqlQuery, conlogID)) { while (reader.Read()) { lblDateTime.Text = Convert.ToString(reader["LogTime"]); lblActionType.Text = Convert.ToString((QDLogAction)Convert.ToInt32(reader["LogAction"])); lblActionDescription.Text = QDLib.GetLogDescriptionFromAction((QDLogAction)Convert.ToInt32(reader["LogAction"])); lblDisplayName.Text = Convert.ToString(reader["Name"]); lblUsername.Text = Convert.ToString(reader["Username"]); lblAssignedDrives.Text = Convert.ToString(reader["AssignedDriveCount"]); lblDeviceName.Text = Convert.ToString(reader["DeviceName"]); lblLogonName.Text = Convert.ToString(reader["LogonName"]); lblMacAddress.Text = Convert.ToString(reader["MacAddress"]); lblUserCount.Text = QDLib.UserCountAtDevice(Convert.ToString(reader["DeviceID"]), DBData).ToString(); } } mysql.Close(); } }
private void lbxDevices_SelectedIndexChanged(object sender, EventArgs e) { if (!QDLib.ManagedDBOpen(mysql)) { QDLib.DBOpenFailed(); return; } txbDeviceMac.Text = mysql.ExecuteScalar <string>("SELECT MacAddress FROM qd_devices WHERE ID = ?", lbxDevices.SelectedValue); txbDeviceName.Text = mysql.ExecuteScalar <string>("SELECT DeviceName FROM qd_devices WHERE ID = ?", lbxDevices.SelectedValue); txbLogonName.Text = mysql.ExecuteScalar <string>("SELECT LogonName FROM qd_devices WHERE ID = ?", lbxDevices.SelectedValue); mysql.Close(); int userCount = QDLib.UserCountAtDevice(lbxDevices.SelectedValue.ToString(), dbData); if (userCount == 1) { lblDeviceUserCount.Text = $"{userCount} User logged into Q-Drive on this{Environment.NewLine}machine / account"; } else { lblDeviceUserCount.Text = $"{userCount} Users logged into Q-Drive on this{Environment.NewLine}machine / account"; } }