private void btnKaydet_Click(object sender, EventArgs e)
        {
            OgrenciBL obl = new OgrenciBL();

            try
            {
                Ogrenci ogrenci = new Ogrenci();
                ogrenci.Ad     = txtAd.Text.Trim();
                ogrenci.Soyad  = txtSoyad.Text.Trim();
                ogrenci.Numara = txtNumara.Text.Trim();
                MessageBox.Show(obl.OgrenciEkle(ogrenci) ? "Başarılı" : "Başarısız");
            }
            catch (SqlException ex)
            {
                switch (ex.Number)
                {
                case 245:
                    MessageBox.Show("Numara girişinde hata");
                    break;

                default:
                    MessageBox.Show("Veritabanı hatası!" + ex.Number);
                    break;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Bir hata oluştu..");
            }
            finally
            {
                obl.Dispose();
            }
        }
示例#2
0
        private void btnKaydet_Click(object sender, EventArgs e)
        {
            if (cmbSiniflar.SelectedValue.ToString() == "0")
            {
                MessageBox.Show("Sinif Seciniz!");
                return;
            }
            OgrenciModel o = new OgrenciModel {
                Ad = txt_Ad.Text.Trim(), Numara = txt_Numara.Text.Trim(), Soyad = txt_Soyad.Text.Trim(), TelNo = txt_TelNo.Text.Trim(), Sinifid = Convert.ToInt32(cmbSiniflar.SelectedValue)
            };
            OgrenciBL ob = OgrenciBL.Instance;

            ob.OgrenciEkle(o);
        }
        public ActionResult OgrenciEkle(FormCollection frm)
        {
            if (ModelState.IsValid)
            {
                Ogrenci ogr = new Ogrenci();
                ogr.Ad           = frm["txtAd"];
                ogr.Soyad        = frm["txtSoyad"];
                ogr.KullaniciAdi = frm["txtKullaniciAd"];
                ogr.Sifre        = frm["txtSifre"];
                var sonuc = OgrenciBL.OgrenciEkle(ogr);

                if (sonuc)
                {
                    return(Redirect("/Home/Index"));
                }

                return(View());
            }

            return(View());
        }