Exemplo n.º 1
0
        private void silToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (lstUrunler.SelectedItem == null)
            {
                return;
            }

            var urunId = (lstUrunler.SelectedItem as ProductViewModel).ProductID;

            var cevap = MessageBox.Show("Secili urunu silmek istiyor musunuz?", "Uyarı!", MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Question);

            if (cevap != DialogResult.Yes)
            {
                return;
            }

            try
            {
                var db   = new NorthEntities();
                var urun = db.Products.Find(urunId);
                db.Products.Remove(urun);
                MessageBox.Show($"{db.SaveChanges()} kayıt silindi.");
                KategorileriGetir();
            }
            catch (DbUpdateException)
            {
                MessageBox.Show("Silmek istediginiz kayıt baska bir tabloda bulundugu icin silemezsiniz.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
 private void btnKatKaydet_Click(object sender, EventArgs e)
 {
     try
     {
         var db = new NorthEntities();
         db.Categories.Add(new Category()
         {
             CategoryName = string.IsNullOrEmpty(txtKategoriAdi.Text) ? null: txtKategoriAdi.Text,
             Description  = txtAciklama.Text,
         });
         var sonuc = db.SaveChanges();
         MessageBox.Show($@"{sonuc} kayit eklendi.");
         KategorileriGetir();
     }
     catch (DbEntityValidationException dbEx)
     {
         foreach (var validationError in dbEx.EntityValidationErrors)
         {
             foreach (var error in validationError.ValidationErrors)
             {
                 if (error.PropertyName == "CategoryName")
                 {
                     ep1.SetError(txtKategoriAdi, error.ErrorMessage);
                 }
             }
         }
         MessageBox.Show(EntityHelper.ValidationMessage(dbEx), @"Bir Hata Olustu", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 3
0
        private void btnUrunGuncelle_Click(object sender, EventArgs e)
        {
            try
            {
                ep1.Clear();
                var db         = new NorthEntities();
                var seciliUrun = lstUrunler.SelectedItem as ProductViewModel;
                var urun       = db.Products.Find(seciliUrun.ProductID);

                urun.ProductName = txtUrunAdi.Text;
                urun.UnitPrice   = nuFiyat.Value;
                urun.CategoryID  = (cmbUrunKategori.SelectedItem as CategoryViewModel).CategoryID;
                int sonuc = db.SaveChanges();
                KategorileriGetir();
                MessageBox.Show($"{sonuc} urun guncellendi.");
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationError in dbEx.EntityValidationErrors)
                {
                    foreach (var error in validationError.ValidationErrors)
                    {
                        if (error.PropertyName == "ProductName")
                        {
                            ep1.SetError(txtUrunAdi, error.ErrorMessage);
                        }
                    }
                }
                MessageBox.Show(EntityHelper.ValidationMessage(dbEx), @"Bir Hata Olustu", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }