示例#1
0
        private void BtnOgrenciKaydet_Click(object sender, EventArgs e)
        {
            try
            {
                Ogrenci o = new Ogrenci();
                o.Ad         = txtAdOgrenci.Text.Trim().ToUpper();
                o.Soyad      = txtSoyadOgrenci.Text.Trim().ToUpper();
                o.SinifId    = (int)cmbSinif.SelectedValue;
                o.OkulNo     = txtOkulNo.Text.Trim();
                o.TCKimlikNo = txtTCogrenci.Text.Trim();
                o.Resim      = txtResim.Text;
                o.VeliAd     = txtVeliAd.Text.Trim().ToUpper();
                o.VeliSoyad  = txtVeliSoyad.Text.Trim().ToUpper();
                o.Adres      = txtAdresVeli.Text.Trim().ToUpper();
                o.Tel        = txtTelVeli.Text.Trim().ToUpper();
                o.Sifre      = txtSifre.Text.Trim();

                bool sonuc2 = OgrenciBL.OgrenciEkleme(o);

                if (sonuc2)
                {
                    MessageBox.Show("Öğrenci Kayıt Başarılı");
                    OgrenciListele();
                    Utility.CleanTextBoxes(grpOgrenciBilgileri.Controls);
                    Utility.CleanTextBoxes(grpVeliBilgileri.Controls);
                    pcbOgrenci.Image = Properties.Resources.indir;
                }
                else
                {
                    MessageBox.Show("Öğrenci Kayıt Başarısız!!");
                }
            }
            catch (SqlException ex)
            {
                switch (ex.Number)
                {
                case 2627:
                    if (ex.Message.Contains("TCKimlikNo"))
                    {
                        MessageBox.Show("Bu TC Kimlik numarası zaten kayıtlı!!" + ex.Number);
                    }
                    else
                    {
                        MessageBox.Show("Bu Öğrenci numarası zaten kayıtlı!!" + ex.Number);
                    }
                    break;

                default:
                    MessageBox.Show("Veritabanı Hatası!!" + ex.Number);
                    break;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Bilinmeyen Hata!!");
            }
            #region MyRegion
            //try
            //{
            //    Ogrenci o = new Ogrenci();
            //    o.Ad = txtAdOgrenci.Text.Trim().ToUpper();
            //    o.Soyad = txtSoyadOgrenci.Text.Trim().ToUpper();
            //    o.TCKimlikNo = txtTCogrenci.Text.Trim();
            //    o.OkulNo = txtOkulNo.Text.Trim();
            //    o.Resim = txtResim.Text;
            //    o.SinifId = (int)cmbSinif.SelectedValue;


            //    bool sonuc = OgrenciBL.OgrenciEkleme(o);
            //    if (sonuc)
            //    {
            //        MessageBox.Show("Öğrenci Kaydı Başarılı");
            //    }
            //    else
            //    {
            //        MessageBox.Show("Öğrenci Kaydı Başarısız!!");
            //    }
            //}
            //catch (SqlException ex)
            //{
            //    switch (ex.Number)
            //    {
            //        case 2627:
            //            if (ex.Message.Contains("TCKimlikNo"))
            //            {
            //                MessageBox.Show("Bu TC Kimlik numarası zaten kayıtlı!!" + ex.Number, "Hata", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //            }
            //            else
            //            {
            //                MessageBox.Show("Bu Öğrenci numarası zaten kayıtlı!!" + ex.Number, "Hata", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //            }
            //            break;
            //        default:
            //            MessageBox.Show("Veritabanı Hatası!!" + ex.Number);
            //            break;
            //    }
            //}
            //catch (Exception)
            //{

            //    MessageBox.Show("Bilinmeyen Hata!!", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //}
            #endregion
        }