Beispiel #1
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     using (var db = new CarSaleEntities())
     {
         if (MakerEdit == null)
         {
             Proizvodac novi = new Proizvodac
             {
                 Naziv  = tBxMaker.Text,
                 Drzava = tBxCountry.Text,
                 Oznaka = tBxShort.Text,
             };
             db.Proizvodacs.Add(novi);
             db.SaveChanges();
         }
         else
         {
             db.Proizvodacs.Attach(MakerEdit);
             MakerEdit.Naziv  = tBxMaker.Text;
             MakerEdit.Drzava = tBxCountry.Text;
             MakerEdit.Oznaka = tBxShort.Text;
             db.SaveChanges();
         }
     }
     Close();
 }
Beispiel #2
0
        private void btnDeleteMaker_Click(object sender, EventArgs e)
        {
            Proizvodac odabraniProizvodac = proizvodacBindingSource.Current as Proizvodac;

            if (odabraniProizvodac != null)
            {
                if (MessageBox.Show("Da li ste sigurni da želite obrisati podatak", "Upozorenje", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                {
                    using (var db = new CarSaleEntities())
                    {
                        db.Proizvodacs.Attach(odabraniProizvodac);
                        if (odabraniProizvodac.Automobils.Count == 0)
                        {
                            db.Proizvodacs.Remove(odabraniProizvodac);
                            db.SaveChanges();
                        }
                        else
                        {
                            MessageBox.Show("Nije moguće obrisati proizvođača koji ima automobile");
                        }
                    }
                    PrikaziProizvodace();
                }
            }
        }
Beispiel #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            int  idP;
            bool res = int.TryParse(cBProizvodac.SelectedValue.ToString(), out idP);
            int  god;
            bool result = int.TryParse(cBGodina.SelectedValue.ToString(), out god);
            int  pow;
            bool respow = int.TryParse(tBxSnaga.Text, out pow);
            int  zap;
            bool reszap = int.TryParse(tBxZapremnina.Text, out zap);
            int  price;
            bool resprice = int.TryParse(tBxCijena.Text, out price);

            using (var db = new CarSaleEntities())
            {
                Automobil novi = new Automobil
                {
                    Naziv         = tBxAutomobil.Text,
                    ID_Proizvodac = idP,
                    Godina        = god,
                    Snaga         = pow,
                    Zapremnina    = zap,
                    Pogon         = cBPogon.SelectedValue.ToString(),
                    Gorivo        = cBGorivo.SelectedValue.ToString(),
                    Cijena        = price,
                };
                db.Automobils.Add(novi);
                db.SaveChanges();
            }
            Close();
        }
Beispiel #4
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            Automobil odabraniAutomobil = automobilBindingSource.Current as Automobil;

            if (automobilBindingSource.Current != null)
            {
                if (MessageBox.Show("Da li ste sigurni da želite obrisati podatak", "Upozorenje", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                {
                    using (var db = new CarSaleEntities())
                    {
                        db.Entry(odabraniAutomobil).State = System.Data.Entity.EntityState.Deleted;
                        db.SaveChanges();
                    }
                }
            }
        }