/// <summary>
 /// Load the list of device id's into the drop-down list control for
 /// all devices that recorded triage data from the provided session id.
 /// </summary>
 /// <param name="sessionId">The SessionId of interest.</param>
 private void LoadSessionDeviceIds(string sessionId)
 {
     using (TriageDbContext tdc = new TriageDbContext(tbDbServer.Text, tbDbName.Text))
     {
         cbDeviceId.DataSource    = tdc.GetDeviceIdsBySession(sessionId);
         cbDeviceId.SelectedIndex = 0;
     }
 }
        /// <summary>
        /// Get the list of SessionID's that are between the start and end
        /// dates and put them in the drop-down list control.
        /// </summary>
        private void LoadSessionInfo()
        {
            if (_sessionInfo != null)
            {
                _sessionInfo.Clear();
            }

            using (TriageDbContext tdc = new TriageDbContext(tbDbServer.Text, tbDbName.Text))
            {
                _sessionInfo = tdc.GetSessionInfoByDateRange(dtpStartDate.Value.ToUniversalTime(), dtpEndDate.Value.ToUniversalTime());
            }

            cbSessionId.DataSource = _sessionInfo.Keys.ToList();
        }
        /// <summary>
        /// Get the triage event data for the provided session and device id's.
        /// </summary>
        /// <param name="sessionId">The SessionId of interest.</param>
        /// <param name="deviceId">The DeviceId of interest.</param>
        private void LoadTriageEventData(string sessionId, string deviceId)
        {
            using (TriageDbContext tdc = new TriageDbContext(tbDbServer.Text, tbDbName.Text))
            {
                // Read the triage events from the database for the selected device.
                _dtTriageEvents = tdc.GetTriageEventsBySessionAndDeviceIds(sessionId, deviceId);
                DataView triageEventsView = new DataView(_dtTriageEvents);

                // Set the data BindingSource.
                bsTriageEvents.DataSource = triageEventsView;

                // Set the DataSource for the grid view.
                dgvTriageEvents.DataSource = bsTriageEvents;

                dgvTriageEvents.CurrentCell = dgvTriageEvents[1, 0];
            }
        }
        /// <summary>
        /// Get and display the triage events for the selected device.
        /// </summary>
        private void CbDeviceId_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(cbDeviceId.Text))
            {
                using (TriageDbContext tdc = new TriageDbContext(tbDbServer.Text, tbDbName.Text))
                {
                    TriageDeviceInfo devInfo = tdc.GetDeviceInfoBySessionAndDeviceIds(cbSessionId.Text, cbDeviceId.Text);
                    tbDeviceName.Text       = !string.IsNullOrEmpty(devInfo.DeviceName) ? devInfo.DeviceName : string.Empty;
                    tbProductName.Text      = !string.IsNullOrEmpty(devInfo.ProductName) ? devInfo.ProductName : string.Empty;
                    tbModelNumber.Text      = !string.IsNullOrEmpty(devInfo.ModelNumber) ? devInfo.ModelNumber : string.Empty;
                    tbFirmwareRevision.Text = !string.IsNullOrEmpty(devInfo.FirmwareRevision) ? devInfo.FirmwareRevision : string.Empty;
                    tbFirmwareDatecode.Text = !string.IsNullOrEmpty(devInfo.FirmwareDatecode) ? devInfo.FirmwareDatecode : string.Empty;
                    tbIpAddress.Text        = !string.IsNullOrEmpty(devInfo.IpAddress) ? devInfo.IpAddress : string.Empty;
                }

                LoadTriageEventData(cbSessionId.Text, cbDeviceId.Text);
            }
        }
        /// <summary>
        /// Gets the performance labels for the triage event that is selected
        /// in the Select Triage Event table and puts the information in the
        /// appropriate table.
        /// </summary>
        /// <param name="rowIndex">The selected row number within the Select
        /// Triage Event table that the user has highlighted.</param>
        private void UpdatePerformanceEvents(int rowIndex)
        {
            if (_dtTriageEvents.Columns.Contains("ActivityExecutionId"))
            {
                string activityExecutionId = _dtTriageEvents.Rows[rowIndex]["ActivityExecutionId"].ToString();

                if (!activityExecutionId.Equals(_activityExecutionId))
                {
                    using (TriageDbContext tdc = new TriageDbContext(tbDbServer.Text, tbDbName.Text))
                    {
                        _dtPerformanceEvents = tdc.GetPerformanceEventsByActivityExecutionId(activityExecutionId);
                        DataView performanceEventsView = new DataView(_dtPerformanceEvents);

                        bsPerformanceEvents.DataSource = performanceEventsView;

                        dgvPerformanceEvents.DataSource = bsPerformanceEvents;
                    }

                    _activityExecutionId = activityExecutionId;
                }
            }
        }
        /// <summary>
        /// Gets the device's control panel image for the triage event that is
        /// selected in the Select Triage Event table and puts it in the
        /// appropriate tab.
        /// </summary>
        /// <param name="rowIndex">The selected row number within the Select
        /// Triage Event table that the user has highlighted.</param>
        private void UpdateControlPanelImage(int rowIndex)
        {
            byte[] controlPanelImage;

            string triageDataId = _dtTriageEvents.Rows[rowIndex]["TriageDataId"].ToString();

            if (!triageDataId.Equals(_triageDataId))
            {
                using (TriageDbContext tdc = new TriageDbContext(tbDbServer.Text, tbDbName.Text))
                {
                    controlPanelImage = tdc.GetControlPanelImage(triageDataId);
                }

                // Convert the bytes stored in the Triage table into an image that canbe displayed.
                if (controlPanelImage != null && controlPanelImage.Length > 0)
                {
                    MemoryStream ms  = new MemoryStream(controlPanelImage);
                    Image        img = Image.FromStream(ms);
                    pbControlPanelImage.Image = img;
                }

                _triageDataId = triageDataId;
            }
        }