{"id":2700,"date":"2026-04-14T11:26:12","date_gmt":"2026-04-14T08:26:12","guid":{"rendered":"https:\/\/www.aydiner.gen.tr\/?p=2700"},"modified":"2026-04-14T14:04:26","modified_gmt":"2026-04-14T11:04:26","slug":"kutuphane","status":"publish","type":"post","link":"https:\/\/www.aydiner.gen.tr\/index.php\/2026\/04\/14\/kutuphane\/","title":{"rendered":"k\u00fct\u00fcphane"},"content":{"rendered":"<p>using System;<br \/>\nusing System.Collections.Generic;<br \/>\nusing System.ComponentModel;<br \/>\nusing System.Data;<br \/>\nusing System.Data.SqlClient;<br \/>\nusing System.Drawing;<br \/>\nusing System.IO;<br \/>\nusing System.Linq;<br \/>\nusing System.Text;<br \/>\nusing System.Threading.Tasks;<br \/>\nusing System.Windows.Forms;<\/p>\n<p>namespace kutuphane<br \/>\n{<br \/>\npublic partial class Form1 : Form<br \/>\n{<br \/>\npublic Form1()<br \/>\n{<br \/>\nInitializeComponent();<br \/>\n}<br \/>\nSqlConnection baglanti = new SqlConnection(@&#8221;Data Source=LAB3OGRTMEN\\SQLEXPRESS01;Initial Catalog=KutuphaneDB;Integrated Security=True&#8221;);<\/p>\n<p>string secilenResimYolu = &#8220;&#8221;;<\/p>\n<p>void Listele()<br \/>\n{<br \/>\ntry<br \/>\n{<br \/>\nbaglanti.Open();<br \/>\nSqlDataAdapter da = new SqlDataAdapter(&#8220;SELECT * FROM Kitaplar&#8221;, baglanti);<br \/>\nDataTable dt = new DataTable();<br \/>\nda.Fill(dt);<br \/>\ndataGridView1.DataSource = dt;<br \/>\nbaglanti.Close();<br \/>\n}<br \/>\ncatch (Exception ex)<br \/>\n{<br \/>\nMessageBox.Show(&#8220;Hata: &#8221; + ex.Message);<br \/>\nbaglanti.Close();<br \/>\n}<br \/>\n}<\/p>\n<p>private void Form1_Load(object sender, EventArgs e)<br \/>\n{<br \/>\nListele();<\/p>\n<p>\/\/ Sat\u0131rlar\u0131n genel g\u00f6r\u00fcn\u00fcm\u00fc<br \/>\ndataGridView1.BorderStyle = BorderStyle.None;<br \/>\ndataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(238, 239, 249); \/\/ Bir dolu bir bo\u015f sat\u0131r rengi<br \/>\ndataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.SingleHorizontal;<br \/>\ndataGridView1.DefaultCellStyle.SelectionBackColor = Color.DarkTurquoise; \/\/ Se\u00e7ili sat\u0131r rengi<br \/>\ndataGridView1.DefaultCellStyle.SelectionForeColor = Color.WhiteSmoke;<br \/>\ndataGridView1.BackgroundColor = Color.White;<\/p>\n<p>\/\/ Ba\u015fl\u0131k (Header) tasar\u0131m\u0131<br \/>\ndataGridView1.EnableHeadersVisualStyles = false;<br \/>\ndataGridView1.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;<br \/>\ndataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.FromArgb(20, 25, 72); \/\/ Ba\u015fl\u0131k arka plan (Lacivert)<br \/>\ndataGridView1.ColumnHeadersDefaultCellStyle.ForeColor = Color.White; \/\/ Ba\u015fl\u0131k yaz\u0131 rengi<br \/>\ndataGridView1.ColumnHeadersHeight = 40; \/\/ Ba\u015fl\u0131k y\u00fcksekli\u011fi<\/p>\n<p>\/\/ Sat\u0131r y\u00fcksekli\u011fi ve yaz\u0131 tipi<br \/>\ndataGridView1.RowTemplate.Height = 35;<br \/>\ndataGridView1.DefaultCellStyle.Font = new Font(&#8220;Segoe UI&#8221;, 10);<\/p>\n<p>\/\/ Otomatik boyutland\u0131rma<br \/>\ndataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; \/\/ S\u00fctunlar\u0131 geni\u015fli\u011fe yay<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/ Proje i\u00e7inde Resimler klas\u00f6r\u00fc yoksa olu\u015fturur<br \/>\nstring resimKlasoru = Path.Combine(Application.StartupPath, &#8220;Resimler&#8221;);<br \/>\nif (!Directory.Exists(resimKlasoru))<br \/>\n{<br \/>\nDirectory.CreateDirectory(resimKlasoru);<br \/>\n}<br \/>\n}<\/p>\n<p>private void btnResimSec_Click(object sender, EventArgs e)<br \/>\n{<br \/>\nOpenFileDialog ofd = new OpenFileDialog();<br \/>\nofd.Filter = &#8220;Resim Dosyalar\u0131 (*.jpg;*.jpeg;*.png)|*.jpg;*.jpeg;*.png&#8221;;<\/p>\n<p>if (ofd.ShowDialog() == DialogResult.OK)<br \/>\n{<br \/>\npictureBox1.ImageLocation = ofd.FileName;<br \/>\nsecilenResimYolu = ofd.FileName;<br \/>\n}<br \/>\n}<\/p>\n<p>private void button1_Click(object sender, EventArgs e)<br \/>\n{<\/p>\n<p>try<br \/>\n{<br \/>\nstring yeniResimYolu = &#8220;&#8221;;<\/p>\n<p>\/\/ E\u011fer resim se\u00e7ildiyse kopyalama yap<br \/>\nif (!string.IsNullOrEmpty(secilenResimYolu))<br \/>\n{<br \/>\nstring dosyaAdi = Guid.NewGuid().ToString() + Path.GetExtension(secilenResimYolu); \/\/ \u0130sim \u00e7ak\u0131\u015fmas\u0131 olmamas\u0131 i\u00e7in benzersiz isim<br \/>\nyeniResimYolu = Path.Combine(Application.StartupPath, &#8220;Resimler&#8221;, dosyaAdi);<br \/>\nFile.Copy(secilenResimYolu, yeniResimYolu);<br \/>\n}<\/p>\n<p>baglanti.Open();<br \/>\nSqlCommand komut = new SqlCommand(&#8220;INSERT INTO Kitaplar (KitapAd, Yazar, SayfaSayisi, Ozet, KitapKapakYolu, ISBN, RafYeri, Adet) VALUES (@p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8)&#8221;, baglanti);<\/p>\n<p>komut.Parameters.AddWithValue(&#8220;@p1&#8221;, txtKitapAd.Text);<br \/>\nkomut.Parameters.AddWithValue(&#8220;@p2&#8221;, txtYazar.Text);<br \/>\nkomut.Parameters.AddWithValue(&#8220;@p3&#8221;, string.IsNullOrEmpty(txtSayfa.Text) ? 0 : int.Parse(txtSayfa.Text));<br \/>\nkomut.Parameters.AddWithValue(&#8220;@p4&#8221;, txtOzet.Text);<br \/>\nkomut.Parameters.AddWithValue(&#8220;@p5&#8221;, yeniResimYolu); \/\/ Kopyalanan yeni adres<br \/>\nkomut.Parameters.AddWithValue(&#8220;@p6&#8221;, txtISBN.Text);<br \/>\nkomut.Parameters.AddWithValue(&#8220;@p7&#8221;, txtRaf.Text);<br \/>\nkomut.Parameters.AddWithValue(&#8220;@p8&#8221;, string.IsNullOrEmpty(txtAdet.Text) ? 0 : int.Parse(txtAdet.Text));<\/p>\n<p>komut.ExecuteNonQuery();<br \/>\nbaglanti.Close();<\/p>\n<p>MessageBox.Show(&#8220;Kitap ba\u015far\u0131yla kaydedildi!&#8221;);<br \/>\nListele();<br \/>\nTemizle();<br \/>\n}<br \/>\ncatch (Exception ex)<br \/>\n{<br \/>\nMessageBox.Show(&#8220;Hata olu\u015ftu: &#8221; + ex.Message);<br \/>\nbaglanti.Close();<br \/>\n}<br \/>\n}<\/p>\n<p>void Temizle()<br \/>\n{<br \/>\ntxtKitapAd.Clear();<br \/>\ntxtYazar.Clear();<br \/>\ntxtSayfa.Clear();<br \/>\ntxtOzet.Clear();<br \/>\ntxtISBN.Clear();<br \/>\ntxtRaf.Clear();<br \/>\ntxtAdet.Clear();<br \/>\npictureBox1.Image = null;<br \/>\nsecilenResimYolu = &#8220;&#8221;;<br \/>\n}<\/p>\n<p>&nbsp;<\/p>\n<p>private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)<br \/>\n{<br \/>\nint secilen = dataGridView1.SelectedCells[0].RowIndex;<\/p>\n<p>txtKitapAd.Text = dataGridView1.Rows[secilen].Cells[1].Value.ToString();<br \/>\ntxtYazar.Text = dataGridView1.Rows[secilen].Cells[2].Value.ToString();<br \/>\ntxtOzet.Text = dataGridView1.Rows[secilen].Cells[4].Value.ToString();<\/p>\n<p>string resimYolu = dataGridView1.Rows[secilen].Cells[5].Value.ToString();<br \/>\nif (File.Exists(resimYolu))<br \/>\n{<br \/>\npictureBox1.ImageLocation = resimYolu;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\npictureBox1.Image = null;<br \/>\n}<br \/>\n}<\/p>\n<p>private void dataGridView1_SelectionChanged(object sender, EventArgs e)<br \/>\n{<\/p>\n<p>\/\/ HATA \u00d6NLEY\u0130C\u0130 KONTROL:<br \/>\n\/\/ E\u011fer sat\u0131r se\u00e7ili de\u011filse veya sat\u0131r say\u0131s\u0131 0 ise i\u015flem yapma ve metoddan \u00e7\u0131k<br \/>\nif (dataGridView1.CurrentRow == null || dataGridView1.SelectedRows.Count == 0)<br \/>\n{<br \/>\nreturn;<br \/>\n}<\/p>\n<p>try<br \/>\n{<br \/>\nDataGridViewRow satir = dataGridView1.SelectedRows[0];<\/p>\n<p>\/\/ H\u00fccre de\u011ferlerini al\u0131rken bo\u015f (null) kontrol\u00fc eklemek daha g\u00fcvenlidir<br \/>\ntxtKitapAd.Text = satir.Cells[&#8220;KitapAd&#8221;].Value?.ToString();<br \/>\ntxtYazar.Text = satir.Cells[&#8220;Yazar&#8221;].Value?.ToString();<br \/>\ntxtSayfa.Text = satir.Cells[&#8220;SayfaSayisi&#8221;].Value?.ToString();<br \/>\ntxtOzet.Text = satir.Cells[&#8220;Ozet&#8221;].Value?.ToString();<br \/>\ntxtISBN.Text = satir.Cells[&#8220;ISBN&#8221;].Value?.ToString();<br \/>\ntxtRaf.Text = satir.Cells[&#8220;RafYeri&#8221;].Value?.ToString();<br \/>\ntxtAdet.Text = satir.Cells[&#8220;Adet&#8221;].Value?.ToString();<\/p>\n<p>string resimYolu = satir.Cells[&#8220;KitapKapakYolu&#8221;].Value?.ToString();<br \/>\nif (!string.IsNullOrEmpty(resimYolu) &amp;&amp; File.Exists(resimYolu))<br \/>\n{<br \/>\npictureBox1.ImageLocation = resimYolu;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\npictureBox1.Image = null;<br \/>\n}<br \/>\n}<br \/>\ncatch (Exception)<br \/>\n{<br \/>\n\/\/ Hata durumunda program\u0131n \u00e7\u00f6kmesini engellemek i\u00e7in bo\u015f b\u0131rak\u0131labilir<br \/>\n}<br \/>\n}<\/p>\n<p>private void txtArama_TextChanged(object sender, EventArgs e)<br \/>\n{<br \/>\n\/\/ Arama kutusu bo\u015fsa t\u00fcm listeyi getir, doluysa filtrele<br \/>\ntry<br \/>\n{<br \/>\nif (baglanti.State == ConnectionState.Closed)<br \/>\nbaglanti.Open();<\/p>\n<p>\/\/ SQL&#8217;deki &#8220;LIKE&#8221; operat\u00f6r\u00fc ile i\u00e7inde ge\u00e7en kelimeleri ar\u0131yoruz<br \/>\n\/\/ &#8216;%&#8217; i\u015fareti aranan kelimenin ba\u015f\u0131nda veya sonunda herhangi bir karakter olabilece\u011fini s\u00f6yler<br \/>\nstring sorgu = &#8220;SELECT * FROM Kitaplar WHERE KitapAd LIKE @p1 OR Yazar LIKE @p1&#8221;;<\/p>\n<p>SqlDataAdapter da = new SqlDataAdapter(sorgu, baglanti);<br \/>\nda.SelectCommand.Parameters.AddWithValue(&#8220;@p1&#8221;, &#8220;%&#8221; + txtArama.Text + &#8220;%&#8221;);<\/p>\n<p>DataTable dt = new DataTable();<br \/>\nda.Fill(dt);<br \/>\ndataGridView1.DataSource = dt;<\/p>\n<p>baglanti.Close();<br \/>\n}<br \/>\ncatch (Exception ex)<br \/>\n{<br \/>\nMessageBox.Show(&#8220;Arama s\u0131ras\u0131nda hata olu\u015ftu: &#8221; + ex.Message);<br \/>\nif (baglanti.State == ConnectionState.Open)<br \/>\nbaglanti.Close();<br \/>\n}<br \/>\n}<\/p>\n<p>private void button2_Click(object sender, EventArgs e)<br \/>\n{<\/p>\n<p>\/\/ 1. Kontrol: Se\u00e7ili sat\u0131r var m\u0131?<br \/>\nif (dataGridView1.SelectedRows.Count &gt; 0)<br \/>\n{<br \/>\n\/\/ Kullan\u0131c\u0131dan onay alal\u0131m<br \/>\nDialogResult onay = MessageBox.Show(&#8220;Bu kitab\u0131 silmek istedi\u011finize emin misiniz?&#8221;, &#8220;Silme Onay\u0131&#8221;, MessageBoxButtons.YesNo, MessageBoxIcon.Question);<\/p>\n<p>if (onay == DialogResult.Yes)<br \/>\n{<br \/>\ntry<br \/>\n{<br \/>\n\/\/ Se\u00e7ili sat\u0131rdaki KitapID de\u011ferini al\u0131yoruz (S\u00fctun ad\u0131 veya indeksi do\u011fru olmal\u0131)<br \/>\nint seciliId = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[&#8220;KitapID&#8221;].Value);<\/p>\n<p>baglanti.Open();<br \/>\nSqlCommand komutSil = new SqlCommand(&#8220;DELETE FROM Kitaplar WHERE KitapID = @p1&#8221;, baglanti);<br \/>\nkomutSil.Parameters.AddWithValue(&#8220;@p1&#8221;, seciliId);<\/p>\n<p>komutSil.ExecuteNonQuery();<br \/>\nbaglanti.Close();<\/p>\n<p>MessageBox.Show(&#8220;Kitap ba\u015far\u0131yla silindi.&#8221;);<\/p>\n<p>\/\/ Listeyi yenile ve kutular\u0131 temizle<br \/>\nListele();<br \/>\nTemizle();<br \/>\n}<br \/>\ncatch (Exception ex)<br \/>\n{<br \/>\nMessageBox.Show(&#8220;Silme hatas\u0131: &#8221; + ex.Message);<br \/>\nbaglanti.Close();<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nMessageBox.Show(&#8220;L\u00fctfen silmek istedi\u011finiz kitab\u0131 tablodan se\u00e7in.&#8221;);<br \/>\n}<br \/>\n}<\/p>\n<p>private void button4_Click(object sender, EventArgs e)<br \/>\n{<br \/>\ntxtKitapAd.Clear();<br \/>\ntxtYazar.Clear();<br \/>\ntxtOzet.Clear();<br \/>\ntxtRaf.Clear();<br \/>\ntxtSayfa.Clear();<br \/>\ntxtISBN.Clear();<br \/>\ntxtAdet.Clear();<br \/>\ntxtKitapAd.Focus();<br \/>\npictureBox1.Image=null;<\/p>\n<p>}<\/p>\n<p>private void button3_Click(object sender, EventArgs e)<br \/>\n{<br \/>\nif (dataGridView1.SelectedRows.Count &gt; 0)<br \/>\n{<br \/>\ntry<br \/>\n{<br \/>\nbaglanti.Open();<br \/>\n\/\/ SQL Sorgusu: Sadece se\u00e7ili ID&#8217;ye sahip olan kitab\u0131 g\u00fcnceller<br \/>\nstring sorgu = &#8220;UPDATE Kitaplar SET KitapAd=@p1, Yazar=@p2, SayfaSayisi=@p3, Ozet=@p4, ISBN=@p5, RafYeri=@p6, Adet=@p7 WHERE KitapID=@p0&#8221;;<\/p>\n<p>SqlCommand komutGuncelle = new SqlCommand(sorgu, baglanti);<\/p>\n<p>\/\/ De\u011ferleri parametre olarak ekliyoruz<br \/>\nkomutGuncelle.Parameters.AddWithValue(&#8220;@p1&#8221;, txtKitapAd.Text);<br \/>\nkomutGuncelle.Parameters.AddWithValue(&#8220;@p2&#8221;, txtYazar.Text);<br \/>\nkomutGuncelle.Parameters.AddWithValue(&#8220;@p3&#8221;, int.Parse(txtSayfa.Text));<br \/>\nkomutGuncelle.Parameters.AddWithValue(&#8220;@p4&#8221;, txtOzet.Text);<br \/>\nkomutGuncelle.Parameters.AddWithValue(&#8220;@p5&#8221;, txtISBN.Text);<br \/>\nkomutGuncelle.Parameters.AddWithValue(&#8220;@p6&#8221;, txtRaf.Text);<br \/>\nkomutGuncelle.Parameters.AddWithValue(&#8220;@p7&#8221;, int.Parse(txtAdet.Text));<\/p>\n<p>\/\/ Hangi sat\u0131r\u0131n g\u00fcncellenece\u011fini belirleyen ID (SelectionChanged ile gelen ID)<br \/>\nint seciliId = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[&#8220;KitapID&#8221;].Value);<br \/>\nkomutGuncelle.Parameters.AddWithValue(&#8220;@p0&#8221;, seciliId);<\/p>\n<p>komutGuncelle.ExecuteNonQuery();<br \/>\nbaglanti.Close();<\/p>\n<p>MessageBox.Show(&#8220;Kitap bilgileri ba\u015far\u0131yla g\u00fcncellendi!&#8221;);<br \/>\nListele(); \/\/ Tabloyu yenile<br \/>\n}<br \/>\ncatch (Exception ex)<br \/>\n{<br \/>\nMessageBox.Show(&#8220;G\u00fcncelleme hatas\u0131: &#8221; + ex.Message);<br \/>\nbaglanti.Close();<br \/>\n}<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nMessageBox.Show(&#8220;L\u00fctfen g\u00fcncellemek istedi\u011finiz kitab\u0131 listeden se\u00e7in!&#8221;);<br \/>\n}<br \/>\n}<\/p>\n<p>private void button5_Click(object sender, EventArgs e)<br \/>\n{<br \/>\nApplication.Exit();<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2700","post","type-post","status-publish","format-standard","hentry","category-genel"],"_links":{"self":[{"href":"https:\/\/www.aydiner.gen.tr\/index.php\/wp-json\/wp\/v2\/posts\/2700","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aydiner.gen.tr\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aydiner.gen.tr\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aydiner.gen.tr\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aydiner.gen.tr\/index.php\/wp-json\/wp\/v2\/comments?post=2700"}],"version-history":[{"count":3,"href":"https:\/\/www.aydiner.gen.tr\/index.php\/wp-json\/wp\/v2\/posts\/2700\/revisions"}],"predecessor-version":[{"id":2703,"href":"https:\/\/www.aydiner.gen.tr\/index.php\/wp-json\/wp\/v2\/posts\/2700\/revisions\/2703"}],"wp:attachment":[{"href":"https:\/\/www.aydiner.gen.tr\/index.php\/wp-json\/wp\/v2\/media?parent=2700"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aydiner.gen.tr\/index.php\/wp-json\/wp\/v2\/categories?post=2700"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aydiner.gen.tr\/index.php\/wp-json\/wp\/v2\/tags?post=2700"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}