public override void RefreshDisplayData()
        {
            if (Notifier != null && Notifier.AgentConfig != null)
            {
                SQLDatabaseNotifierConfig dbConfig = (SQLDatabaseNotifierConfig)Notifier.AgentConfig;
                int infos  = 0;
                int warns  = 0;
                int errs   = 0;
                int debugs = 0;
                try
                {
                    lvwMessages.BeginUpdate();
                    if (chkStayCurrent.Checked)
                    {
                        dateTimeChooserTo.SelectedDateTime = DateTime.Now.AddMinutes(1);
                    }
                    int topCount = int.MaxValue;
                    if (cboTopCount.SelectedItem.ToString() != "All")
                    {
                        topCount = int.Parse(cboTopCount.SelectedItem.ToString());
                    }
                    string viewerName             = dbConfig.ViewerName.Replace("'", "''");
                    string alertParamName         = dbConfig.AlertFieldName.Replace("'", "''").Replace("@", "");
                    string collectorTypeParamName = dbConfig.CollectorTypeFieldName.Replace("'", "''").Replace("@", "");
                    string categoryParamName      = dbConfig.CategoryFieldName.Replace("'", "''").Replace("@", "");
                    string previousStateParamName = dbConfig.PreviousStateFieldName.Replace("'", "''").Replace("@", "");
                    string currentStateParamName  = dbConfig.CurrentStateFieldName.Replace("'", "''").Replace("@", "");
                    string detailsParamName       = dbConfig.DetailsFieldName.Replace("'", "''").Replace("@", "");
                    string datetimeParamName      = dbConfig.DateTimeFieldName.Replace("'", "''").Replace("@", "");
                    object alertTypeValue         = cboAlertLevel.SelectedIndex;
                    if (cboAlertLevel.SelectedIndex == 4)
                    {
                        alertTypeValue = DBNull.Value;
                    }
                    object currentStateValue = cboState.SelectedIndex;
                    if (cboState.SelectedIndex == 6)
                    {
                        currentStateValue = DBNull.Value;
                    }
                    object categoryValue;
                    if (txtCategory.Text.Length == 0)
                    {
                        categoryValue = DBNull.Value;
                    }
                    else
                    {
                        categoryValue = "%" + txtCategory.Text + "%";
                    }
                    object detailsValue;
                    if (txtSearchText.Text.Length == 0)
                    {
                        detailsValue = DBNull.Value;
                    }
                    else
                    {
                        detailsValue = "%" + txtSearchText.Text + "%";
                    }
                    object collectorTypeValue = DBNull.Value;

                    string sql = dbConfig.UseSPForViewer ? dbConfig.ViewerName : Properties.Resources.QueryTemplate
                                 .Replace("@top", cboTopCount.SelectedItem.ToString())
                                 .Replace("InsertDate", datetimeParamName)
                                 .Replace("AlertLevel", alertParamName)
                                 .Replace("CollectorType", collectorTypeParamName)
                                 .Replace("Category", categoryParamName)
                                 .Replace("PreviousState", previousStateParamName)
                                 .Replace("CurrentState", currentStateParamName)
                                 .Replace("Details", detailsParamName)
                                 .Replace("AlertMessages", viewerName);

                    using (SqlConnection conn = new SqlConnection(dbConfig.GetConnectionString()))
                    {
                        try
                        {
                            conn.Open();
                        }
                        catch (System.Data.SqlClient.SqlException ex)
                        {
                            if (ex.Message.Contains("The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement"))
                            {
                                System.Threading.Thread.Sleep(3000);
                                toolStripStatusLabelDetails.Text = "Connection timed out! Retrying...";
                                Application.DoEvents();
                                //try again
                                conn.Open();
                            }
                            else
                            {
                                throw;
                            }
                        }
                        SqlParameter[] paramArr = new SqlParameter[]
                        {
                            new SqlParameter("@Top", topCount),
                            new SqlParameter("@FromDate", dateTimeChooserFrom.SelectedDateTime),
                            new SqlParameter("@ToDate", dateTimeChooserTo.SelectedDateTime),
                            new SqlParameter("@" + alertParamName, alertTypeValue)
                            {
                                DbType = DbType.Byte
                            },
                            new SqlParameter("@" + collectorTypeParamName, collectorTypeValue),
                            new SqlParameter("@" + categoryParamName, categoryValue),
                            new SqlParameter("@" + currentStateParamName, currentStateValue),
                            new SqlParameter("@" + detailsParamName, detailsValue)
                        };
                        using (SqlCommand cmnd = new SqlCommand(sql, conn))
                        {
                            cmnd.Prepare();
                            cmnd.Parameters.AddRange(paramArr);
                            if (dbConfig.UseSPForViewer)
                            {
                                cmnd.CommandType = CommandType.StoredProcedure;
                            }
                            else
                            {
                                cmnd.CommandType = CommandType.Text;
                            }
                            cmnd.CommandTimeout = dbConfig.CmndTimeOut;
                            using (SqlDataReader r = cmnd.ExecuteReader())
                            {
                                lvwMessages.Items.Clear();
                                List <ListViewItem> items = new List <ListViewItem>();
                                while (r.Read())
                                {
                                    AlertMessage alertMessage = new AlertMessage();
                                    alertMessage.InsertDate    = (DateTime)r[datetimeParamName];
                                    alertMessage.AlertLevel    = AlertLevelConverter.GetAlertLevelFromText(r[alertParamName].ToString());
                                    alertMessage.CollectorType = r[collectorTypeParamName].ToString();
                                    alertMessage.PreviousState = CollectorStateConverter.GetCollectorStateFromText(r[previousStateParamName].ToString());
                                    alertMessage.CurrentState  = CollectorStateConverter.GetCollectorStateFromText(r[currentStateParamName].ToString());
                                    alertMessage.Category      = r[categoryParamName].ToString();
                                    alertMessage.Details       = r[detailsParamName].ToString();

                                    ListViewItem lvi = new ListViewItem(alertMessage.InsertDate.ToString("yyyy-MM-dd"));
                                    if (alertMessage.AlertLevel == AlertLevel.Info)// || alertMessage.AlertLevel == AlertLevel.Debug)
                                    {
                                        lvi.ImageIndex = 1;
                                        infos++;
                                    }
                                    else if (alertMessage.AlertLevel == AlertLevel.Warning)
                                    {
                                        lvi.ImageIndex = 2;
                                        warns++;
                                    }
                                    else if (alertMessage.AlertLevel == AlertLevel.Error || alertMessage.AlertLevel == AlertLevel.Crisis)
                                    {
                                        lvi.ImageIndex = 3;
                                        errs++;
                                    }
                                    else
                                    {
                                        lvi.ImageIndex = 0;
                                        debugs++;
                                    }
                                    lvi.SubItems.Add(alertMessage.InsertDate.ToString("HH:mm:ss"));
                                    lvi.SubItems.Add(alertMessage.Category);
                                    lvi.SubItems.Add(alertMessage.CurrentState.ToString());
                                    string details = alertMessage.Details;
                                    if (details.Length > 80)
                                    {
                                        details = details.Substring(0, 80);
                                    }
                                    lvi.SubItems.Add(details);
                                    lvi.Tag = alertMessage;
                                    items.Add(lvi);
                                }
                                lvwMessages.Items.AddRange(items.ToArray());
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    string counts = string.Format("{0} item(s), Info: {1}, Warn: {2}, Err {3}",
                                                  lvwMessages.Items.Count, infos, warns, errs);
                    if (debugs > 0)
                    {
                        counts += " Debug: " + debugs.ToString();
                    }
                    toolStripStatusLabelDetails.Text = counts;
                    lvwMessages.EndUpdate();
                }
            }
        }