private void PopuniPolja()
 {
     tbNaziv.Text        = apot.nazivApoteke;
     tbAdresa.Text       = apot.adresa;
     tbTelefon.Text      = apot.telefon;
     tbEmail.Text        = apot.email;
     tbWebSajt.Text      = apot.webSajt;
     tbRadnoVrijeme.Text = apot.radnoVrijeme;
     try
     {
         using (ApotekaDb context = new ApotekaDb())
         {
             apot = (apoteka)(from a in context.apotekas
                              where a.idApoteke == 1
                              select a).FirstOrDefault();
             cbMjesto.SelectedItem = apot.mjesto;
         }
     }
     catch (Exception)
     {
         string prk = "Došlo je do greške.";
         MessageBox.Show(prk, "Greška", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     dtpDatumOsnivanja.Text       = apot.datumOsnivanja.ToString();
     cbDezurnaApoteka.Checked     = apot.dezurnaApoteka;
     tbStandard.Text              = sertif.standard;
     tbIzdatOd.Text               = sertif.izdatOd;
     tbPodrucjePrimjene.Text      = sertif.podrucjePrimjene;
     dtpDatumIsteka.Value         = sertif.datumIsteka;
     dtpDatumSertifikovanja.Value = sertif.datumSertifikovanja;
 }
 public InformacijeOApoteciForma(ToolStripMenuItem infoOApoteci, ToolStripStatusLabel statusnaLabela, bool adminPregled)
 {
     InitializeComponent();
     this.statusnaLabela = statusnaLabela;
     this.infoOApoteci   = infoOApoteci;
     this.adminPregled   = adminPregled;
     try
     {
         using (ApotekaDb context = new ApotekaDb())
         {
             apot = (apoteka)(from a in context.apotekas
                              where a.idApoteke == 1
                              select a).FirstOrDefault();
             sertif = (sertifikat)(from s in context.sertifikats
                                   where s.idApoteke == apot.idApoteke
                                   select s).FirstOrDefault();
         }
     }
     catch (Exception)
     {
         string prk = "Došlo je do greške.";
         MessageBox.Show(prk, "Greška", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        private void btnSacuvati_Click(object sender, EventArgs e)
        {
            string poruka = "";

            if (string.IsNullOrEmpty(tbNaziv.Text.Trim()))
            {
                poruka += "Naziv nije unijet.\n";
            }
            if (string.IsNullOrEmpty(tbAdresa.Text.Trim()))
            {
                poruka += "Ime nije unijeto.\n";
            }
            if (string.IsNullOrEmpty(tbTelefon.Text.Trim()))
            {
                poruka += "Telefon nije unijeto.\n";
            }
            if (string.IsNullOrEmpty(tbStandard.Text.Trim()))
            {
                poruka += "Standard nije unijet.\n";
            }
            if (string.IsNullOrEmpty(tbIzdatOd.Text.Trim()))
            {
                poruka += "Izdat od nije unijeto.\n";
            }
            if (string.IsNullOrEmpty(tbPodrucjePrimjene.Text.Trim()))
            {
                poruka += "Područje primjene nije unijeto.\n";
            }
            if (cbMjesto.SelectedItem == null)
            {
                poruka += "Mjesto nije izabrato.\n";
            }
            try
            {
                using (ApotekaDb context = new ApotekaDb())
                {
                    if (string.IsNullOrEmpty(poruka))
                    {
                        apot = (apoteka)(from a in context.apotekas
                                         where a.idApoteke == 1
                                         select a).FirstOrDefault();
                        sertif = (sertifikat)(from s in context.sertifikats
                                              where s.idApoteke == apot.idApoteke
                                              select s).FirstOrDefault();
                        apot.nazivApoteke   = tbNaziv.Text.Trim();
                        apot.adresa         = tbAdresa.Text.Trim();
                        apot.telefon        = tbTelefon.Text.Trim();
                        apot.email          = tbEmail.Text.Trim();
                        apot.webSajt        = tbWebSajt.Text.Trim();
                        apot.radnoVrijeme   = tbRadnoVrijeme.Text.Trim();
                        apot.idMjesta       = ((mjesto)cbMjesto.SelectedItem).idMjesta;
                        apot.datumOsnivanja = dtpDatumOsnivanja.Value;
                        apot.dezurnaApoteka = cbDezurnaApoteka.Checked;
                        context.SaveChanges();
                        sertif.standard            = tbStandard.Text.Trim();
                        sertif.izdatOd             = tbIzdatOd.Text.Trim();
                        sertif.podrucjePrimjene    = tbPodrucjePrimjene.Text.Trim();
                        sertif.datumIsteka         = dtpDatumIsteka.Value;
                        sertif.datumSertifikovanja = dtpDatumSertifikovanja.Value;
                        statusnaLabela.Text        = "Podaci o apoteci su uspješno izmjenjeni.";
                        context.SaveChanges();
                        lbFokus.Select();
                        OmoguciPoljaNaFormi(false, gbPodaciOApoteci);
                        OmoguciPoljaNaFormi(false, gbPodaciOSertifikatu);
                        btnIzmjeniti.Enabled = true;
                        btnSacuvati.Enabled  = false;
                        btnOdustati.Enabled  = false;
                    }
                    else
                    {
                        MessageBox.Show(poruka, "Greška", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch (Exception)
            {
                string prk = "Došlo je do greške.";
                MessageBox.Show(prk, "Greška", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }