//Katmanlı Mimari private void BtnKaydet_Click(object sender, EventArgs e) { try { MusteriBL obl = new MusteriBL(); Musteri ogr = new Musteri(); ogr.Ad = txtAd.Text.Trim(); ogr.Soyad = txtSoyad.Text.Trim(); ogr.Telefon = int.Parse(txtTel.Text.Trim()); MessageBox.Show(obl.Kaydet(ogr) ? "Başarılı" : "Başarısız"); } catch (SqlException ex) { switch (ex.Number) { case 245: MessageBox.Show("Numara alanına sadece rakam giriniz"); break; default: MessageBox.Show("Veritabanı Hatası" + ex.Number); break; } } catch (FormatException) { MessageBox.Show("Numara alanına sadece rakam giriniz"); } catch (Exception) { MessageBox.Show("Bilinmeyen Hata!!"); } }
private void btnKaydet_Click(object sender, EventArgs e) { MusteriBL mbl = new MusteriBL(); foreach (DataRow item in dt.Rows) { Musteri m = new Musteri(); if (item.RowState != DataRowState.Deleted) { m.Ad = item[1].ToString(); m.Soyad = item[2].ToString(); m.Telefon = item[3].ToString(); m.Sifre = item[4].ToString(); m.EPosta = item[5].ToString(); m.Adres = item[6].ToString(); m.TCKNo = item[7].ToString(); } switch (item.RowState) { case DataRowState.Added: mbl.Kaydet(m); break; case DataRowState.Deleted: mbl.MusteriSil(Convert.ToInt32(item[0, DataRowVersion.Original])); break; case DataRowState.Modified: m.Musteriid = Convert.ToInt32(item[0]); mbl.Guncelle(m); break; default: break; } } }