-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkitapListele.cs
179 lines (151 loc) · 6.97 KB
/
kitapListele.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace KütüphaneOtomasyonu
{
public partial class kitapListele : Form
{
public kitapListele()
{
InitializeComponent();
}
SqlConnection baglanti;
SqlCommand komut;
SqlDataAdapter da;
void KitaplariGetir()
{
baglanti = new SqlConnection("Server=(localdb)\\V11.0; Initial Catalog=KütüphaneDB;Integrated Security=SSPI");
baglanti.Open();
da = new SqlDataAdapter("Select * From Kitaplar", baglanti);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
baglanti.Close();
}
private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
{
textBox2.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
textBox3.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
textBox4.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
textBox5.Text = dataGridView1.CurrentRow.Cells[3].Value.ToString();
textBox6.Text = dataGridView1.CurrentRow.Cells[4].Value.ToString();
comboBox2.Text = dataGridView1.CurrentRow.Cells[5].Value.ToString();
comboBox3.Text = dataGridView1.CurrentRow.Cells[6].Value.ToString();
dateTimePicker1.Text= dataGridView1.CurrentRow.Cells[7].Value.ToString();
textBox7.Text = dataGridView1.CurrentRow.Cells[8].Value.ToString();
numericUpDown1.Text = dataGridView1.CurrentRow.Cells[9].Value.ToString();
}
private void kitapListele_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("BarkodNo");
comboBox1.Items.Add("KitapAdi");
comboBox1.Items.Add("YazarAdi");
comboBox1.Items.Add("YayinEvi");
comboBox1.Items.Add("SayfaSayisi");
comboBox1.Items.Add("KitapTürü");
comboBox1.Items.Add("TeminTürü");
comboBox1.Items.Add("CiltNo");
comboBox1.Items.Add("StokSayisi");
KitaplariGetir();
}
private void button3_Click(object sender, EventArgs e)//Yenile butonuna basıldığında kitapbilgilerini silme
{
textclear(this);
comboBox2.Text = "";
comboBox3.Text = "";
dateTimePicker1.Text = "";
}
private void textclear(Control ctl) //Yenile butonuna basıldığında textbox verileri silme
{
foreach (Control item in ctl.Controls)
{
if (item is TextBox)
{
((TextBox)item).Clear();
}
if (item.Controls.Count > 0)
{
textclear(item);
}
}
}
private void button2_Click(object sender, EventArgs e) // Tabloyu Excele Aktarma
{
Microsoft.Office.Interop.Excel.Application uyg = new Microsoft.Office.Interop.Excel.Application();
uyg.Visible = true;
Microsoft.Office.Interop.Excel.Workbook kitap = uyg.Workbooks.Add(System.Reflection.Missing.Value);
Microsoft.Office.Interop.Excel.Worksheet sheet1 = (Microsoft.Office.Interop.Excel.Worksheet)kitap.Sheets[1];
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
Microsoft.Office.Interop.Excel.Range myRange = (Microsoft.Office.Interop.Excel.Range)sheet1.Cells[1, i + 1];
myRange.Value2 = dataGridView1.Columns[i].HeaderText;
}
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
for (int j = 0; j < dataGridView1.Rows.Count; j++)
{
Microsoft.Office.Interop.Excel.Range myRange = (Microsoft.Office.Interop.Excel.Range)sheet1.Cells[j + 2, i + 1];
myRange.Value2 = dataGridView1[i, j].Value;
}
}
}
private void button4_Click(object sender, EventArgs e)//Güncelle
{
string sorgu = "update Kitaplar Set BarkodNo=@BarkodNo, KitapAdi=@KitapAdi, YazarAdi=@YazarAdi, YayinEvi=@YayinEvi,SayfaSayisi = @SayfaSayisi, KitapTürü = @KitapTürü, TeminTürü = @TeminTürü, TeminTarihi = @TeminTarihi, CiltNo = @CiltNo,StokSayisi = @StokSayisi Where BarkodNo = @BarkodNo";
komut = new SqlCommand(sorgu, baglanti);
komut.Parameters.AddWithValue("@BarkodNo", Convert.ToInt32(textBox2.Text));
komut.Parameters.AddWithValue("@KitapAdi", textBox3.Text);
komut.Parameters.AddWithValue("@YazarAdi", textBox4.Text);
komut.Parameters.AddWithValue("@YayinEvi", textBox5.Text);
komut.Parameters.AddWithValue("@SayfaSayisi", Convert.ToInt32(textBox6.Text));
komut.Parameters.AddWithValue("@KitapTürü", comboBox2.Text);
komut.Parameters.AddWithValue("@TeminTürü", comboBox3.Text);
komut.Parameters.AddWithValue("@TeminTarihi", dateTimePicker1.Value);
komut.Parameters.AddWithValue("@CiltNo", Convert.ToInt32(textBox7.Text));
komut.Parameters.AddWithValue("@StokSayisi",numericUpDown1.Value);
baglanti.Open();
komut.ExecuteNonQuery();
baglanti.Close();
KitaplariGetir();
}
private void button6_Click(object sender, EventArgs e) //Çıkış
{
this.Close();
KütüphaneTakipIslemleri yeni = new KütüphaneTakipIslemleri();
yeni.Hide();
yeni.Show();
}
private void button5_Click(object sender, EventArgs e) //Sil
{
string sorgu = "Delete From Kitaplar Where BarkodNo=@BarkodNo";
komut = new SqlCommand(sorgu, baglanti);
komut.Parameters.AddWithValue("@BarkodNo", Convert.ToInt32(textBox2.Text));
baglanti.Open();
komut.ExecuteNonQuery();
baglanti.Close();
KitaplariGetir();
}
private void textBox1_TextChanged(object sender, EventArgs e) //ARAMA
{
if (comboBox1.SelectedItem != null)
{
SqlCommand cmd = new SqlCommand("Select * From Kitaplar " + " where(" + comboBox1.SelectedItem + " like '" + textBox1.Text + "%' )", baglanti);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
baglanti.Open();
da.Fill(ds, "Kitaplar");
dataGridView1.DataSource = ds.Tables["Kitaplar"];
baglanti.Close();
}
else
MessageBox.Show("Lütfen arama türünü seçiniz..");
}
}
}