Esempio n. 1
0
        private void btnObrisiKlijenta_Click(object sender, EventArgs e)
        {
            try
            {
                if (gridKlijenti.SelectedRows.Count > 0)
                {
                    int     klijentId         = Convert.ToInt32(gridKlijenti.SelectedRows[0].Cells[0].Value);
                    Klijent klijentZaBrisanje = db.Klijents.SingleOrDefault(k => k.Id == klijentId);

                    db.Klijents.Remove(klijentZaBrisanje);
                }

                if (gridServisi.SelectedRows.Count > 0)
                {
                    int    servisId         = Convert.ToInt32(gridServisi.SelectedRows[0].Cells[0].Value);
                    Servis servisZaBrisanje = db.Servis.SingleOrDefault(s => s.Id == servisId);

                    db.Servis.Remove(servisZaBrisanje);
                }

                int ret = db.SaveChanges();

                if (ret != 0)
                {
                    MessageBox.Show("Obrisano!");
                }

                GetData();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Esempio n. 2
0
        private void btnDodajServis_Click(object sender, EventArgs e)
        {
            Servis novServis = new Servis();

            try
            {
                if (string.IsNullOrEmpty(txtOpisUsluge.Text))
                {
                    MessageBox.Show("Unesite opis usluge!");
                    txtOpisUsluge.Focus();
                    return;
                }
                else
                {
                    novServis.OpisUsluge = txtOpisUsluge.Text;
                }

                if (dtpUsluga.Value == null)
                {
                    MessageBox.Show("Izaberite datum usluge!");
                    dtpUsluga.Focus();
                    return;
                }
                else
                {
                    novServis.DatumServisa = dtpUsluga.Value;
                }

                if (cmbKlijenti.SelectedValue == null)
                {
                    MessageBox.Show("Izaberite klijenta!");
                    cmbKlijenti.Focus();
                    return;
                }
                else
                {
                    novServis.KlijentId = Convert.ToInt32(cmbKlijenti.SelectedValue);
                }

                db.Servis.Add(novServis);

                int ret = db.SaveChanges();

                if (ret != 0)
                {
                    MessageBox.Show("Sacuvano!");
                }

                GetData();
            }
            catch (DbEntityValidationException EFex)
            {
                foreach (DbEntityValidationResult s in EFex.EntityValidationErrors)
                {
                    foreach (DbValidationError x in s.ValidationErrors)
                    {
                        MessageBox.Show(x.ErrorMessage);
                    }
                }

                db.Dispose();
                db = new DbModel();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }