public static DBPrecinctMayor GetDataByPrecinct(string precinct, string municipality, int candidate_id) { DBPrecinctMayor data = null; SQLiteConnection con = DBConnection.ConnectDatabase(); try { SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM " + tablename + " WHERE precinct='" + precinct + "' AND municipality='" + municipality + "' AND candidate_id=" + candidate_id, con); SQLiteDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { reader.Read(); data = new DBPrecinctMayor(); data.Id = reader.GetInt32(0); data.Municipality = reader.GetString(1); data.Precinct = reader.GetString(2); data.Votes = reader.GetInt32(3); data.Candidate_id = reader.GetInt32(4); } reader.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { con.Close(); } return(data); }
public static List <DBPrecinctMayor> SumationDataTabulation(string municipality) { List <DBPrecinctMayor> data = new List <DBPrecinctMayor>(); SQLiteConnection con = DBConnection.ConnectDatabase(); try { SQLiteCommand cmd = new SQLiteCommand("SELECT candidate_id,SUM(votes) FROM " + tablename + " WHERE municipality='" + municipality + "' GROUP by candidate_id", con); SQLiteDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { DBPrecinctMayor rawData = new DBPrecinctMayor(); rawData.Candidate_id = reader.GetInt32(0); rawData.Votes = reader.GetInt32(1); data.Add(rawData); } } reader.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { con.Close(); } return(data); }