private void btnOdaKaydet_Click(object sender, EventArgs e)
        {
            using (YurtContex ctx = new YurtContex())
            {
                try
                {
                    switch (odaid)
                    {
                    case 0:
                        ctx.Odas.Add(new Oda {
                            Kat = Convert.ToInt32(txtKat.Text.Trim()), Kontenjan = Convert.ToInt32(txtKontenjan.Text.Trim()), Oda_No = Convert.ToInt32(txtOdaNo.Text.Trim())
                        });

                        ctx.SaveChanges();
                        break;

                    default:
                        Oda oda = ctx.Odas.Find(odaid);
                        oda.Oda_No    = Convert.ToInt32(txtOdaNo.Text.Trim());
                        oda.Kontenjan = Convert.ToInt32(txtKontenjan.Text.Trim());
                        oda.Kat       = Convert.ToInt32(txtKat.Text.Trim());
                        ctx.Entry <Oda>(oda).State = EntityState.Modified;
                        ctx.SaveChanges();
                        Temizle();
                        break;
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Esempio n. 2
0
 private void btnOdaBul_Click(object sender, EventArgs e)
 {
     try
     {
         using (YurtContex ctx = new YurtContex())
         {
             Oda         o   = ctx.Odas.Find(Convert.ToInt32(cmbOdalar.SelectedValue));
             frmOdaKayit odk = new frmOdaKayit();
             odk.Show();
             odk.txtKat.Text       = o.Kat.ToString();
             odk.txtOdaNo.Text     = o.Oda_No.ToString();
             odk.txtKontenjan.Text = o.Kontenjan.ToString();
             odk.btnSil.Enabled    = true;
             odk.odaid             = o.Oda_ID;
             odk.btnOdaKaydet.Text = "Guncelle";
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
        private void btnSil_Click(object sender, EventArgs e)
        {
            DialogResult cvp = MessageBox.Show("Kayıt Silinecek. Emin misiniz?", "Silme Onayı", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (cvp == DialogResult.Yes)
            {
                {
                    using (YurtContex ctx = new YurtContex())
                    {
                        Oda oda = ctx.Odas.Find(odaid);
                        ctx.Odas.Remove(oda);
                        ctx.SaveChanges();
                    }
                    MessageBox.Show("Silme Başarılı");
                    Temizle();
                }
            }
            else
            {
                MessageBox.Show("İşlem İptal Edildi");
                Temizle();
            }
        }