/
Form4.cs
219 lines (199 loc) · 7.67 KB
/
Form4.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
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;
//using System.Data;
namespace LibraryManagementSystem
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
DataTable dt;
private void Form4_Load(object sender, EventArgs e)
{
Class1 c = new Class1();
SqlDataReader dr = c.readrecord("select * from Books");
dt = new DataTable();
dt.Load(dr);
dataGridView1.DataSource = dt;
showall();
groupBox2.Hide();
groupBox3.Hide();
groupBox4.Hide();
if(con.State==ConnectionState.Open)
{
con.Close();
}
con.Open();
}
public void Click()
{
SqlDataReader dr = c.readrecord("select * from Books");
dt = new DataTable();
dt.Load(dr);
dataGridView1.DataSource = dt;
}
Class1 c =new Class1();
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1)
{
DataGridViewRow drv = dataGridView1.Rows[e.RowIndex];
c.ins_del_up("delete from Books where book_id=" + drv.Cells[2].Value.ToString());
}
Click();
if (e.RowIndex >= 0)
{
//gets a collection that contains all the rows
DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
//populate the textbox from specific value of the coordinates of column and row.
textBox4.Text = row.Cells[3].Value.ToString();
textBox5.Text = row.Cells[4].Value.ToString();
textBox6.Text = row.Cells[5].Value.ToString();
textBox7.Text = row.Cells[7].Value.ToString();
textBox8.Text = row.Cells[8].Value.ToString();
textBox9.Text = row.Cells[2].Value.ToString();
showall();
}
}
public void showall()
{
// dataGridView1.Rows.Clear();
DataSet ds = c.FillData("select * from Books");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
// dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells["Se"].Value = "Select";
dataGridView1.Rows[i].Cells["DEL"].Value = "Delete";
}
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if(radioButton1.Checked==true)
groupBox2.Show();
else
{
groupBox2.Hide();
groupBox3.Hide();
groupBox4.Hide();
}
showall();
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked == true)
groupBox3.Show();
else
{
groupBox2.Hide();
groupBox3.Hide();
groupBox4.Hide();
}
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
if (radioButton3.Checked == true)
groupBox4.Show();
else
{
groupBox2.Hide();
groupBox3.Hide();
groupBox4.Hide();
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
/* DataView dv = new DataView(dt);
dv.RowFilter = string.Format("book_name LIKE '%{0}%'", textBox1.Text);
dataGridView1.DataSource = dv;
showall();*/
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
/* DataView dv = new DataView(dt);
dv.RowFilter = string.Format("book_publication_name LIKE '%{0}%'", textBox2.Text);
dataGridView1.DataSource = dv;
showall();*/
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
/* DataView dv = new DataView(dt);
dv.RowFilter = string.Format("book_author_name LIKE '%{0}%'", textBox3.Text);
dataGridView1.DataSource = dv;
showall();*/
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
var textBoxes = new TextBox[] { textBox4, textBox5, textBox6, textBox7,
textBox8,textBox9,};
if (textBoxes.Any(tb => tb.Text == String.Empty))
{
MessageBox.Show("Fill All Entries", "Message!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
c.ins_del_up("update Books set book_name='" + textBox4.Text + "',book_author_name='" + textBox5.Text + "',book_publication_name='" + textBox6.Text + "',book_purchase_date='" + dateTimePicker1.Value.Date + "',book_price=" + textBox7.Text + ",book_quantity=" + textBox8.Text + "where book_id= " + textBox9.Text + " ");
MessageBox.Show("Book Updated Successfully", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
Click();
showall();
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Hide();
MDIParent1 p = new MDIParent1();
p.Show();
}
SqlConnection con = new SqlConnection(@"server=LAPTOP-J067EJBG;database=Library;integrated security=true");
private void textBox2_KeyUp(object sender, KeyEventArgs e)
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from Books where book_publication_name like('%" + textBox2.Text + "%')";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
dataGridView1.DataSource = dt;
dataGridView1.Rows[0].Cells["Se"].Value = "Select";
dataGridView1.Rows[0].Cells["DEL"].Value = "Delete";
}
private void textBox3_KeyUp(object sender, KeyEventArgs e)
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from Books where book_author_name like('%" + textBox3.Text + "%')";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
dataGridView1.DataSource = dt;
}
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from Books where book_name like('%" + textBox3.Text + "%')";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
dataGridView1.DataSource = dt;
}
}
}