示例#1
0
        private void txtDodajKlijenta_Click(object sender, EventArgs e)
        {
            Klijent novKlijent = new Klijent();

            try
            {
                if (string.IsNullOrEmpty(txtImeKlijenta.Text))
                {
                    MessageBox.Show("Unesite ime!");
                    txtImeKlijenta.Focus();
                    return;
                }
                else
                {
                    novKlijent.NazivKlijenta = txtImeKlijenta.Text;
                }

                if (string.IsNullOrEmpty(txtRegBr.Text))
                {
                    MessageBox.Show("Unesite registarski broj!");
                    txtRegBr.Focus();
                    return;
                }
                else
                {
                    novKlijent.RegistarskiBroj = txtRegBr.Text;
                }

                if (string.IsNullOrEmpty(txtKontakt.Text))
                {
                    MessageBox.Show("Unesite kontakt!");
                    txtKontakt.Focus();
                    return;
                }
                else
                {
                    novKlijent.Kontakt = txtKontakt.Text;
                }

                novKlijent.DodatniKomentar = txtDodatniKom.Text;

                db.Klijents.Add(novKlijent);

                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());
            }
        }
示例#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());
            }
        }