public void ResultsCellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { // Set the background to red for negative values in the Balance column. ChurnStatus status = ChurnStatuses.GetStatus(_view.Rows[e.RowIndex].Cells["Status"].Value); switch (status) { case ChurnStatus.Added: e.CellStyle.BackColor = ChurnStatuses.Added; break; case ChurnStatus.Deleted: e.CellStyle.BackColor = ChurnStatuses.Deleted; break; case ChurnStatus.Changed: e.CellStyle.BackColor = ChurnStatuses.Changed; break; } //if ((e.ColumnIndex == 3) && e.Value != null) //{ // DataGridViewCell cell = _view.Rows[e.RowIndex].Cells[e.ColumnIndex]; // cell.ToolTipText = ChurnStatuses.GetToolTipText(status); //} }
/// <summary> /// Retrieve the results from the database, building a crosstab with key Sourcefile attributes followed by all the /// metrics in the selected MetricSet (if any). /// </summary> /// <param name="set">DataSet into which the results should be added.</param> /// <param name="tableName"></param> /// <param name="tableName">Desired name for the results table.</param> /// <param name="metricSet">Selected MetricSet to use as a filter (may be null to include all metrics).</param> public void GetResults(DataSet set, string tableName, MetricSet metricSet) { lock (_semaphore) { if ((_cmdResults == null) || (_cmdResults.Connection != Connection)) { string sql = "SELECT sf.sfid, p.pr_name, sf.sf_shortname, sf.sf_type, cf.status, sm.mid, sm.mvalue " + "FROM sourcefile sf, comparefile cf, project p, sourcemetric sm " + "WHERE cf.sfid = sf.sfid " + "AND p.projid = sf.projid " + "AND sm.sfid = sf.sfid " + "AND sm.mvalue <> 0 " + "ORDER BY sf.sfid, sm.mid"; _cmdResults = new MySqlCommand(sql, Connection); _cmdResults.Prepare(); } } MetricCollection metrics = ChooseMetrics(metricSet); DataTable table = BuildTable(set, tableName, metrics); MySqlDataReader dr = _cmdResults.ExecuteReader(); DataRow row = null; long id; long prevousId = -1; long mid = 0; Metric m = null; while (dr.Read()) { id = long.Parse(dr["sfid"].ToString()); if (id != prevousId) { row = table.NewRow(); table.Rows.Add(row); row["Project"] = dr["pr_name"].ToString(); row["Filename"] = dr["sf_shortname"].ToString(); row["Lang"] = dr["sf_type"].ToString(); row["Status"] = ChurnStatuses.GetShortCode(dr["status"].ToString()); } mid = long.Parse(dr["mid"].ToString()); if (metrics.Contains(mid)) { m = metrics[mid]; if (table.Columns.Contains(m.Code)) { row[m.Code] = double.Parse(dr["mvalue"].ToString()); } } prevousId = id; } }