private string GetQIValue(ListViewItem lvi, QueryInstance queryInstance) { string results = ""; try { object value = queryInstance.RunQuery(); MonitorStates currentstate = queryInstance.GetState(value); results = FormatUtils.N(value, "[null]"); if (currentstate == MonitorStates.Error) { lvi.ImageIndex = 3; } else if (currentstate == MonitorStates.Warning) { lvi.ImageIndex = 2; } else { lvi.ImageIndex = 1; } } catch (Exception ex) { results = ex.Message; } return(results); }
//private void chkIsReturnValueInt_CheckedChanged(object sender, EventArgs e) //{ // chkReturnValueNotInverted.Enabled = chkIsReturnValueInt.Checked; // chkUseRowCountAsValue.Enabled = chkIsReturnValueInt.Checked; //} #endregion #region Button click events private void cmdTest_Click(object sender, EventArgs e) { if (DoValidate()) { string lastStep = "Initialize values"; try { Cursor.Current = Cursors.WaitCursor; QueryInstance testQueryInstance = new QueryInstance(); testQueryInstance.Name = txtName.Text; testQueryInstance.SqlServer = txtServer.Text; testQueryInstance.Database = txtDatabase.Text; testQueryInstance.IntegratedSecurity = chkIntegratedSec.Checked; testQueryInstance.UserName = txtUserName.Text; testQueryInstance.Password = txtPassword.Text; testQueryInstance.CmndTimeOut = (int)numericUpDownCmndTimeOut.Value; testQueryInstance.UseSPForSummary = chkUseSPForSummary.Checked; testQueryInstance.SummaryQuery = txtStateQuery.Text; if (cboReturnType.SelectedIndex == 0) { testQueryInstance.ReturnValueIsNumber = false; testQueryInstance.UseRowCountAsValue = false; testQueryInstance.UseExecuteTimeAsValue = false; } else { testQueryInstance.ReturnValueIsNumber = true; if (cboReturnType.SelectedIndex == 2) { testQueryInstance.UseRowCountAsValue = true; } else if (cboReturnType.SelectedIndex == 3) { testQueryInstance.UseExecuteTimeAsValue = true; chkReturnValueNotInverted.Checked = true; } } testQueryInstance.ReturnValueInverted = !chkReturnValueNotInverted.Checked; testQueryInstance.SuccessValue = cboSuccessValue.Text; testQueryInstance.WarningValue = cboWarningValue.Text; testQueryInstance.ErrorValue = cboErrorValue.Text; testQueryInstance.UseSPForDetail = chkUseSPForDetail.Checked; testQueryInstance.DetailQuery = txtDetailQuery.Text; testQueryInstance.ApplicationName = txtApplicationName.Text; lastStep = "Run summary query"; object returnValue = testQueryInstance.RunQuery(); if (!testQueryInstance.UseRowCountAsValue && !testQueryInstance.UseExecuteTimeAsValue && !returnValue.IsNumber()) { throw new Exception(string.Format("Return value is not an integer!\r\nValue returned: {0}", returnValue)); } //if (!testQueryInstance.ReturnValueIsNumber) //{ // lastStep = "Run summary query"; // returnValue = testQueryInstance.RunQueryWithSingleResult(); //} //else if (!testQueryInstance.UseRowCountAsValue && !testQueryInstance.UseExecuteTimeAsValue) //{ // lastStep = "Run summary query (value is number)"; // returnValue = testQueryInstance.RunQueryWithSingleResult(); // if (!returnValue.IsNumber()) // throw new Exception(string.Format("Return value is not an integer!\r\nValue returned: {0}", returnValue)); //} //else if (testQueryInstance.UseRowCountAsValue) //{ // lastStep = "Run summary query (row count as value)"; // returnValue = testQueryInstance.RunQueryWithCountResult(); //} //else //{ // lastStep = "Run summary query (execution time as value)"; // returnValue = testQueryInstance.RunQueryWithExecutionTimeResult(); //} //testing detail query List <DataColumn> columns = new List <DataColumn>(); // = testQueryInstance.GetDetailQueryColumns(); lastStep = "Testing detail query"; DataSet ds = testQueryInstance.RunDetailQuery(); lastStep = "Testing detail query - Getting column names"; columns.AddRange((from DataColumn c in ds.Tables[0].Columns select c).ToArray()); MessageBox.Show(string.Format("Success!\r\nSummary value return: {0}\r\nDetail row count: {1}\r\nDetail columns returned: {2}", returnValue, ds.Tables[0].Rows.Count, columns.ToCSVString()), "Test", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(string.Format("Failed!\r\nLast step: {0}\r\n{1}", lastStep, ex.Message), "Test", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { Cursor.Current = Cursors.Default; } } }