public SinifOgrenci getUser(long ogrencino, string sifre) { SinifOgrenci user = null; using (var connection = Database.GetConnection()) { var command = new SqlCommand("SELECT *FROM ogrenci WHERE ogrenci_no='" + ogrencino + "'and ogrenci_sifre='" + sifre + "'"); command.Connection = connection; connection.Open(); using (var reader = command.ExecuteReader()) { while (reader.Read()) { user = new SinifOgrenci(); user.OgrenciNo = reader.GetInt64(0); // () parantez içindeki sayılar tablonun yerini belli ediyor. user.Sifre = reader.GetString(4); İsim1 = reader.GetString(1); Soyisim1 = reader.GetString(2); OgrenciNo1 = reader.GetInt64(0); BolumID1 = reader.GetInt32(3); // Ogrenci tablosunda 2 sütun Ogrenci no 3-sütun Sifre olduğu için böyle yazılmıştır. 0 isim 1 soyisim //user.İsim = reader.GetString(0); // user.Soyisim = reader.GetString(1); } } connection.Close(); } return(user); }
private void kaydetbuton_Click(object sender, EventArgs e) { if (isimbox.Text == "" || soyisimbox.Text == "" || ogrsifrebox.Text == "" || nobox.Text == "") { MessageBox.Show("Lütfen eksik kutu bırakmayınız. Alanları doldurunuz. Eğer öğrenci silme işlemi yapmak istiyorsanız butona tıklamayı unutmayınız."); } else { islem2 = new SinifOgrenciGiris(); user2 = new SinifOgrenci(); user2.İsim = isimbox.Text; user2.Soyisim = soyisimbox.Text; user2.OgrenciNo = Convert.ToInt64(nobox.Text); user2.Sifre = ogrsifrebox.Text; if (islem2.InsertUser(user2)) { MessageBox.Show("Öğrenci Ekleme işleminiz başarıyla gerçekleşti."); } else { MessageBox.Show("Bu okul numarası ile kayıtlı öğrenci sistemde zaten mevcuttur. Lütfen tekrar deneyiniz."); } } KayitSonrasiTemizleme(this); }
private void button2_Click(object sender, EventArgs e) { if (boxİsim.Text == "" || boxSoyisim.Text == "" || boxSifre.Text == "" || boxNO.Text == "" || boxBolumID.Text == "") { MessageBox.Show("Lütfen eksik kutu bırakmayınız. Alanları doldurunuz. Bölümünüzü seçmeyi unutmayınız."); } else { SinifOgrenciGiris islem2 = new SinifOgrenciGiris(); SinifOgrenci user2 = new SinifOgrenci(); //islem2 = new SinifOgrenciGiris(); //user2 = new SinifOgrenci(); user2.İsim = boxİsim.Text; user2.Soyisim = boxSoyisim.Text; user2.OgrenciNo = Convert.ToInt64(boxNO.Text); user2.Sifre = boxSifre.Text; user2.BolumID = Convert.ToInt32(boxBolumID.Text); if (islem2.InsertUser(user2)) { MessageBox.Show("Öğrenci Ekleme işleminiz başarıyla gerçekleşti."); } else { MessageBox.Show("Bu okul numarası ile kayıtlı öğrenci sistemde zaten mevcuttur. Lütfen tekrar deneyiniz."); } } }
private bool ContainsUser(SinifOgrenci user) { bool result = false; using (var connection = Database.GetConnection()) { var command = new SqlCommand("SELECT *FROM ogrenci WHERE ogrenci_no='" + user.OgrenciNo + "'"); //var command = new SqlCommand("SELECT *FROM Users WHERE Name='" + user.Name + "' and Password='******'"); command.Connection = connection; connection.Open(); using (var reader = command.ExecuteReader()) { if (reader.Read()) { result = true; } } connection.Close(); } return(result); }
public bool InsertUser(SinifOgrenci user) { bool result = false; if (!ContainsUser(user)) { using (var connection = Database.GetConnection()) { // var command = new SqlCommand("INSERT INTO ogretmenn(isim,soyisim,kullaniciadi,sifre,unvan) VALUES('" + user.İsim + "','" + user.Soyisim + "','" + user.KullaniciAdi + "','" + user.Sifre + "','" + user.Unvan + ")'"); // var command = new SqlCommand("INSERT INTO ogretmenn(ad,soyad,kullaniciadi,sifre,unvan) VALUES ("+ user.İsim + "," + user.Soyisim + "," + user.KullaniciAdi + "," + user.Sifre + "," + user.Unvan + ","); var command = new SqlCommand("INSERT INTO ogrenci(ad,soyad,ogrenci_no,ogrenci_sifre,bolum_id) VALUES('" + user.İsim + "','" + user.Soyisim + "','" + user.OgrenciNo + "','" + user.Sifre + "','" + user.BolumID + "')"); command.Connection = connection; connection.Open(); if (command.ExecuteNonQuery() != -1) { result = true; } connection.Close(); } } return(result); }
private void girisyapbuton_Click(object sender, EventArgs e) { try { islem2 = new SinifOgrenciGiris(); user2 = islem2.getUser(Convert.ToInt64(ogrencino.Text), ogrencisifre.Text); if (user2 != null) { OgrenciAnaMenu a = new OgrenciAnaMenu(); //a.label2.Text = user.İsim.ToString(); a.Show(); this.Hide(); } else { MessageBox.Show("Öğrenci no veya şifreniz yanlıştır. Lütfen tekrar deneyiniz."); } } catch (Exception hata) { MessageBox.Show("Bir hata oluştu. \n"); MessageBox.Show(hata.Message); } }