コード例 #1
0
        public static DBPrecinctViceMayor GetDataByPrecinct(string precinct, string municipality, int candidate_id)
        {
            DBPrecinctViceMayor 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 DBPrecinctViceMayor();
                    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);
        }
コード例 #2
0
        public static List <DBPrecinctViceMayor> SumationDataTabulation(string municipality)
        {
            List <DBPrecinctViceMayor> data = new List <DBPrecinctViceMayor>();

            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())
                    {
                        DBPrecinctViceMayor rawData = new DBPrecinctViceMayor();
                        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);
        }