public PosyanduData[] GetAllPosyandu()
        {
            PosyanduData[] allPosyandu = null;

            try
            {
                using (DbBhmEntities db = new DbBhmEntities())
                {
                    IQueryable<Posyandu> results = from p in db.Posyandus
                                                   select p;

                    int counter = results.Count<Posyandu>();
                    allPosyandu = new PosyanduData[counter];

                    int i = 0;
                    foreach (Posyandu posyandu in results)
                    {
                        allPosyandu[i] = new PosyanduData();
                        allPosyandu[i].idPosyandu = posyandu.idPosyandu;
                        allPosyandu[i].namaPosyandu = posyandu.namaPosyandu;
                        allPosyandu[i].desaPosyandu = posyandu.desaPosyandu;
                        allPosyandu[i].kecPosyandu = posyandu.kecPosyandu;
                        allPosyandu[i].kabPosyandu = posyandu.kabPosyandu;
                        allPosyandu[i++].provPosyandu = posyandu.provPosyandu;
                    }
                }
            }
            catch
            {
                // Ignore exceptions
            }

            return allPosyandu;
        }
        public PegawaiData GetPegawai(string nama)
        {
            PegawaiData pegawaiData = null;

            try
            {
                using (DbBhmEntities db = new DbBhmEntities())
                {
                    Pegawai matchingPegawai = db.Pegawais.First(
                        p => String.Compare(p.namaPgw, nama) == 0);

                    pegawaiData = new PegawaiData()
                    {
                        idPgw = matchingPegawai.idPgw,
                        namaPgw = matchingPegawai.namaPgw,
                        instansi = matchingPegawai.instansi,
                        usernamePgw = matchingPegawai.usernamePgw,
                        passwordPgw = matchingPegawai.passwordPgw,
                        isAdmin = matchingPegawai.isAdmin
                    };
                }
            }
            catch
            {
                // Ignore exceptions
            }

            return pegawaiData;
        }
        public PosyanduData GetPosyandu(string nama)
        {
            PosyanduData posyanduData = null;

            try
            {
                using (DbBhmEntities db = new DbBhmEntities())
                {
                    Posyandu matchingPosyandu = db.Posyandus.First(
                        p => String.Compare(p.namaPosyandu, nama) == 0);

                    posyanduData = new PosyanduData()
                    {
                        idPosyandu = matchingPosyandu.idPosyandu,
                        namaPosyandu = matchingPosyandu.namaPosyandu,
                        desaPosyandu = matchingPosyandu.desaPosyandu,
                        kecPosyandu = matchingPosyandu.kecPosyandu,
                        kabPosyandu = matchingPosyandu.kabPosyandu,
                        provPosyandu = matchingPosyandu.provPosyandu
                    };
                }
            }
            catch
            {
                // Ignore exceptions
            }

            return posyanduData;
        }
        public ImunisasiData GetImunisasiById(int idImunisasi)
        {
            ImunisasiData imunisasiData = null;

            try
            {
                using (DbBhmEntities db = new DbBhmEntities())
                {
                    Imunisasi matching = db.Imunisasis.First(
                        p => p.idImunisasi == idImunisasi);

                    imunisasiData = new ImunisasiData()
                    {
                        idImunisasi = Convert.ToInt32(matching.idImunisasi),
                        hbo = Convert.ToDateTime(matching.hbo),
                        bcg_Polio1 = Convert.ToDateTime(matching.bcg_Polio1),
                        dptHb1_Polio2 = Convert.ToDateTime(matching.dptHb1_Polio2),
                        dptHb2_Polio2 = Convert.ToDateTime(matching.dptHb2_Polio2),
                        dptHb3_Polio4 = Convert.ToDateTime(matching.dptHb3_Polio4),
                        campak = Convert.ToDateTime(matching.campak)
                    };
                }
            }
            catch
            {
                // Ignore exceptions
            }

            return imunisasiData;
        }
        public AyahData GetAyahById(int id)
        {
            AyahData ayahData = null;

            try
            {
                using (DbBhmEntities db = new DbBhmEntities())
                {
                    Ayah matchingAyah = db.Ayahs.First(p => p.idAyah == id);

                    ayahData = new AyahData()
                    {
                        namaAyah = matchingAyah.namaAyah,
                        pkjAyah = matchingAyah.pkjAyah,
                        tlAyah = Convert.ToDateTime(matchingAyah.tlAyah),
                        alamatAyah = matchingAyah.alamatAyah
                    };
                }
            }
            catch
            {
                // Ignore exceptions
            }

            return ayahData;
        }
        public BalitaData GetBalitaByName(string nama)
        {
            BalitaData balitaData = null;

            try
            {
                using (DbBhmEntities db = new DbBhmEntities())
                {
                    Balita matchingBalita = db.Balitas.First(
                        p => String.Compare(p.namaBalita, nama) == 0);

                    balitaData = new BalitaData()
                    {
                        idBalita = matchingBalita.idBalita,
                        idAyah = matchingBalita.idAyah,
                        idIbu = matchingBalita.idIbu,
                        idImunisasi = Convert.ToInt32(matchingBalita.idImunisasi),
                        idVitamin = Convert.ToInt32(matchingBalita.idVitamin),
                        namaBalita = matchingBalita.namaBalita,
                        tlBalita = Convert.ToDateTime(matchingBalita.tlBalita),
                        alamatBalita = matchingBalita.alamatBalita,
                        anakKe = Convert.ToInt32(matchingBalita.anakKe),
                        jnsKelamin = matchingBalita.jnsKelamin,
                        bbl = Convert.ToDouble(matchingBalita.bbl),
                        tbl = Convert.ToDouble(matchingBalita.tbl)
                    };
                }
            }
            catch
            {
                // Ignore exceptions
            }

            return balitaData;
        }
        public IbuData GetIbuById(int id)
        {
            IbuData ibuData = null;

            try
            {
                using (DbBhmEntities db = new DbBhmEntities())
                {
                    Ibu matching = db.Ibus.First(p => p.idIbu == id);

                    ibuData = new IbuData()
                    {
                        namaIbu = matching.namaIbu,
                        pkjIbu = matching.pkjIbu,
                        tlIbu = Convert.ToDateTime(matching.tlIbu),
                        alamatIbu = matching.alamatIbu
                    };
                }
            }
            catch
            {
                // Ignore exceptions
            }

            return ibuData;
        }
        public void InsertAyah(string nama, string pkj, DateTime tl, string alamat)
        {
            using (DbBhmEntities dc = new DbBhmEntities())
            {
                Ayah ayah = new Ayah();

                ayah.namaAyah = nama;
                ayah.pkjAyah = pkj;
                ayah.tlAyah = tl;
                ayah.alamatAyah = alamat;

                dc.Ayahs.AddObject(ayah);
                dc.SaveChanges();
            }
        }
        public void InsertIbu(string nama, string pkj, DateTime tl, string alamat)
        {
            using (DbBhmEntities dc = new DbBhmEntities())
            {
                Ibu ibu = new Ibu();

                ibu.namaIbu = nama;
                ibu.pkjIbu = pkj;
                ibu.tlIbu = tl;
                ibu.alamatIbu = alamat;

                dc.Ibus.AddObject(ibu);
                dc.SaveChanges();
            }
        }
        public void InsertKegiatan(int idBalita, int idPosyandu, DateTime tgl, double bb, double tb)
        {
            using (DbBhmEntities dc = new DbBhmEntities())
            {
                Kegiatan kegiatan = new Kegiatan();

                kegiatan.idBalita = idBalita;
                kegiatan.idPosyandu = idPosyandu;
                kegiatan.tglPeriksa = tgl;
                kegiatan.bb = bb;
                kegiatan.tb = tb;

                dc.Kegiatans.AddObject(kegiatan);
                dc.SaveChanges();
            }
        }
        public void InsertVitamin(DateTime kapsulBiru, DateTime kapsulMerah1, DateTime kapsulMerah2, DateTime kapsulMerah3,
            DateTime kapsulMerah4)
        {
            using (DbBhmEntities dc = new DbBhmEntities())
            {
                Vitamin vitamin = new Vitamin();

                vitamin.kapsulBiru = DateTime.Now;
                vitamin.kapsulMerah1 = DateTime.Now;
                vitamin.kapsulMerah2 = DateTime.Now;
                vitamin.kapsulMerah3 = DateTime.Now;
                vitamin.kapsulMerah4 = DateTime.Now;

                dc.Vitamins.AddObject(vitamin);
                dc.SaveChanges();
            }
        }
        public void InsertImunisasi(DateTime hbo, DateTime bcg_Polio1, DateTime dptHb1_Polio2, DateTime dptHb2_Polio2,
            DateTime dptHb3_Polio4, DateTime campak)
        {
            using (DbBhmEntities dc = new DbBhmEntities())
            {
                Imunisasi imun = new Imunisasi();

                imun.hbo = hbo;
                imun.bcg_Polio1 = bcg_Polio1;
                imun.dptHb1_Polio2 = dptHb1_Polio2;
                imun.dptHb2_Polio2 = dptHb2_Polio2;
                imun.dptHb3_Polio4 = dptHb3_Polio4;
                imun.campak = campak;

                dc.Imunisasis.AddObject(imun);
                dc.SaveChanges();
            }
        }
        public int GetIdByName(string nama)
        {
            int idPosyandu = 0;

            try
            {
                using (DbBhmEntities db = new DbBhmEntities())
                {
                    Posyandu matching = db.Posyandus.First(
                        p => String.Compare(p.namaPosyandu, nama) == 0);

                    idPosyandu = matching.idPosyandu;
                }
            }
            catch
            {
                // Ignore exceptions
            }

            return idPosyandu;
        }
        public int GetIdByName(string nama)
        {
            int idIbu = 0;

            try
            {
                using (DbBhmEntities db = new DbBhmEntities())
                {
                    Ibu matchingIbu = db.Ibus.First(
                        p => String.Compare(p.namaIbu, nama) == 0);

                    idIbu = matchingIbu.idIbu;
                }
            }
            catch
            {
                // Ignore exceptions
            }

            return idIbu;
        }
        public int GetIdByName(string nama)
        {
            int idAyah = 0;

            try
            {
                using (DbBhmEntities db = new DbBhmEntities())
                {
                    Ayah matchingAyah = db.Ayahs.First(
                        p => String.Compare(p.namaAyah, nama) == 0);

                    idAyah = matchingAyah.idAyah;
                }
            }
            catch
            {
                // Ignore exceptions
            }

            return idAyah;
        }
        public void InsertPegawai(string nama, string instansi, string username, string password, bool isAdmin)
        {
            try
            {
                using (DbBhmEntities db = new DbBhmEntities())
                {
                    Pegawai pegawai = new Pegawai();

                    pegawai.namaPgw = nama;
                    pegawai.instansi = instansi;
                    pegawai.usernamePgw = username;
                    pegawai.passwordPgw = password;
                    pegawai.isAdmin = isAdmin;

                    db.Pegawais.AddObject(pegawai);
                    db.SaveChanges();
                }
            }
            catch
            {
                // Ignore exceptions
            }
        }
        public void UpdateImunisasi(int id, DateTime hbo, DateTime bcg_Polio1, DateTime dptHb1_Polio2, DateTime dptHb2_Polio2,
            DateTime dptHb3_Polio4, DateTime campak)
        {
            try
            {
                using (DbBhmEntities db = new DbBhmEntities())
                {
                    Imunisasi imun = db.Imunisasis.Single(p => p.idImunisasi == id);

                    imun.hbo = hbo;
                    imun.bcg_Polio1 = bcg_Polio1;
                    imun.dptHb1_Polio2 = dptHb1_Polio2;
                    imun.dptHb2_Polio2 = dptHb2_Polio2;
                    imun.dptHb3_Polio4 = dptHb3_Polio4;
                    imun.campak = campak;

                    db.SaveChanges();
                }
            }
            catch
            {
                // Ignore exceptions
            }
        }
        public void UpdatePosyandu(int id, string nama, string desa, string kec, string kab, string prov)
        {
            try
            {
                using (DbBhmEntities db = new DbBhmEntities())
                {
                    Posyandu posyandu = db.Posyandus.Single(p => p.idPosyandu == id);

                    posyandu.namaPosyandu = nama;
                    posyandu.desaPosyandu = desa;
                    posyandu.kecPosyandu = kec;
                    posyandu.kabPosyandu = kab;
                    posyandu.provPosyandu = prov;

                    db.SaveChanges();
                }
            }
            catch
            {
                // Ignore exceptions
            }
        }
        public List<string> ListPosyandu()
        {
            List<string> posyanduList = new List<string>();

            try
            {
                using (DbBhmEntities db = new DbBhmEntities())
                {
                    var posyandus = from Posyandu in db.Posyandus
                                    select Posyandu.namaPosyandu;

                    posyanduList = posyandus.ToList();
                }
            }
            catch
            {
                // Ignore exceptions
            }

            return posyanduList;
        }
        public List<string> ListBalita()
        {
            List<string> balitaList = new List<string>();

            try
            {
                using (DbBhmEntities db = new DbBhmEntities())
                {
                    var balitas = from Balita in db.Balitas
                                  select Balita.namaBalita;

                    balitaList = balitas.ToList();
                }
            }
            catch
            {
                // Ignore exceptions
            }

            return balitaList;
        }
        public void InsertPosyandu(string nama, string desa, string kec, string kab, string prov)
        {
            try
            {
                using (DbBhmEntities db = new DbBhmEntities())
                {
                    Posyandu posyandu = new Posyandu();

                    posyandu.namaPosyandu = nama;
                    posyandu.desaPosyandu = desa;
                    posyandu.kecPosyandu = kec;
                    posyandu.kabPosyandu = kab;
                    posyandu.provPosyandu = prov;

                    db.Posyandus.AddObject(posyandu);
                    db.SaveChanges();
                }
            }
            catch
            {
                // Ignore exceptions
            }
        }
        public void InsertBalita(int idAyah, int idIbu, string nama, DateTime tl, string alamat, int anak,
            string jk, double bbl, double tbl)
        {
            using (DbBhmEntities dc = new DbBhmEntities())
            {
                Balita balita = new Balita();

                balita.idAyah = idAyah;
                balita.idIbu = idIbu;
                balita.idVitamin = null;
                balita.idImunisasi = null;
                balita.namaBalita = nama;
                balita.tlBalita = tl;
                balita.alamatBalita = alamat;
                balita.anakKe = anak;
                balita.jnsKelamin = jk;
                balita.bbl = bbl;
                balita.tbl = tbl;

                dc.Balitas.AddObject(balita);
                dc.SaveChanges();
            }
        }
        public int GetIdByName(string nama)
        {
            int idBalita = 0;

            try
            {
                using (DbBhmEntities db = new DbBhmEntities())
                {
                    Balita matching = db.Balitas.First(
                        p => String.Compare(p.namaBalita, nama) == 0);

                    idBalita = matching.idBalita;
                }
            }
            catch
            {
                // Ignore exceptions
            }

            return idBalita;
        }
        public List<string> ListKecamatan()
        {
            List<string> kecamatanList = new List<string>();

            try
            {
                using (DbBhmEntities db = new DbBhmEntities())
                {
                    var kecamatans = (from Posyandu in db.Posyandus
                                     select Posyandu.kecPosyandu).Distinct();

                    kecamatanList = kecamatans.ToList();

                }
            }
            catch
            {
                // Ignore exceptions
            }

            return kecamatanList;
        }
        public List<string> ListPegawai()
        {
            List<string> pegawaiList = new List<string>();

            try
            {
                using (DbBhmEntities db = new DbBhmEntities())
                {
                    var pegawais = from Pegawai in db.Pegawais
                                   select Pegawai.namaPgw;

                    pegawaiList = pegawais.ToList();
                }
            }
            catch
            {
                // Ignore exceptions
            }

            return pegawaiList;
        }
        public void UpdateBalita(int id, int idAyah, int idIbu, int idVit, int idImun, string nama, DateTime tl, string alamat, int anak,
            string jk, double bbl, double tbl)
        {
            using (DbBhmEntities db = new DbBhmEntities())
            {
                Balita balita = db.Balitas.Single(p => p.idBalita == id);

                balita.idAyah = idAyah;
                balita.idIbu = idIbu;
                balita.idVitamin = idVit;
                balita.idImunisasi = idImun;
                balita.namaBalita = nama;
                balita.tlBalita = tl;
                balita.alamatBalita = alamat;
                balita.anakKe = anak;
                balita.jnsKelamin = jk;
                balita.bbl = bbl;
                balita.tbl = tbl;

                db.SaveChanges();
            }
        }