private void businessesStatisticsCountButton_Click(object sender, RoutedEventArgs e) { if (businessesLocationCityComboBox.SelectedItem == null) { return; } else { Dictionary <string, int> checkins = new Dictionary <string, int>(); using (var connection = new NpgsqlConnection(buildConnectionString())) { connection.Open(); using (var cmd = new NpgsqlCommand()) { cmd.Connection = connection; cmd.CommandText = "SELECT " + "postalcode, " + "COUNT(bid) as count " + "FROM " + "businesses " + "WHERE " + "state ='" + businessesLocationStateComboBox.SelectedItem.ToString() + "' AND " + "city ='" + businessesLocationCityComboBox.SelectedItem.ToString() + "' " + "GROUP BY " + "postalcode " + "ORDER BY " + "postalcode;"; using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { checkins.Add(reader.GetString(0), reader.GetInt32(1)); } } } connection.Close(); } ChartWindow chartWindow = new ChartWindow("Businesses per Postal Code", "# of Businesses", checkins); chartWindow.Show(); } }
private void businessesStatisticsCheckinsButton_Click(object sender, RoutedEventArgs e) { if (businessesBusinessesBusinessesDataGrid.SelectedItem == null) { return; } else { Dictionary <string, int> checkins = new Dictionary <string, int>(); using (var connection = new NpgsqlConnection(buildConnectionString())) { connection.Open(); using (var cmd = new NpgsqlCommand()) { string bid = ((Business)businessesBusinessesBusinessesDataGrid.SelectedItem).bid; cmd.Connection = connection; cmd.CommandText = "SELECT " + "day, " + "SUM(morning + afternoon + evening + night) AS count " + "FROM " + "checkins " + "WHERE " + "bid = '" + bid + "' " + "GROUP BY " + "day;"; using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { checkins.Add(reader.GetString(0), reader.GetInt32(1)); } } } connection.Close(); } ChartWindow chartWindow = new ChartWindow("Checkins", "# of Checkins", checkins); chartWindow.Show(); } }