-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewBook.cs
More file actions
157 lines (130 loc) · 5.88 KB
/
Copy pathViewBook.cs
File metadata and controls
157 lines (130 loc) · 5.88 KB
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
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 Library_Management_System
{
public partial class ViewBook : Form
{
public ViewBook()
{
InitializeComponent();
}
private void ViewBook_Load(object sender, EventArgs e)
{
panel2.Visible = false;
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=BT-2105617\\SQLEXPRESS;Initial Catalog=library;Integrated Security=True;";
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select * from NewBook";
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource=ds.Tables[0];
}
int bid;
Int64 rowid;
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
{
bid = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
// MessageBox.Show(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
}
panel2.Visible=true;
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=BT-2105617\\SQLEXPRESS;Initial Catalog=library;Integrated Security=True;";
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select * from NewBook where bid = "+bid+"";
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
rowid = Int64.Parse(ds.Tables[0].Rows[0][0].ToString());
txtBName.Text = ds.Tables[0].Rows[0][1].ToString();
txtAuthor.Text= ds.Tables[0].Rows[0][2].ToString();
txtPublication.Text= ds.Tables[0].Rows[0][3].ToString();
txtPDate.Text= ds.Tables[0].Rows[0][4].ToString();
txtPrice.Text= ds.Tables[0].Rows[0][5].ToString();
txtQuantity.Text= ds.Tables[0].Rows[0][6].ToString();
}
private void btnCancel_Click(object sender, EventArgs e)
{
panel2.Visible=false;
}
private void txtBookName_TextChanged(object sender, EventArgs e)
{
if(txtBookName.Text != "")
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=BT-2105617\\SQLEXPRESS;Initial Catalog=library;Integrated Security=True;";
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select * from NewBook where bName LIKE '"+txtBookName.Text+ "%'";
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
else
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=BT-2105617\\SQLEXPRESS;Initial Catalog=library;Integrated Security=True;";
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select * from NewBook";
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
}
private void btnRefresh_Click(object sender, EventArgs e)
{
txtBookName.Clear();
panel2.Visible = false;
}
private void btnUpdate_Click(object sender, EventArgs e)
{
if(MessageBox.Show("Data will be Updated","Success",MessageBoxButtons.OKCancel,MessageBoxIcon.Question)==DialogResult.OK)
{
String bname = txtBName.Text;
String bauthor = txtAuthor.Text;
String publication = txtPublication.Text;
String pdate = txtPDate.Text;
Int64 price = Int64.Parse(txtPrice.Text);
Int64 quan = Int64.Parse(txtQuantity.Text);
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=BT-2105617\\SQLEXPRESS;Initial Catalog=library;Integrated Security=True;";
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "update NewBook set bName = '" + bname + "',bAuthor = '" + bauthor + "',bPubl = '" + publication + "', bPDate = '" + pdate + "', bPrice = '" + price + "' , bQuant = '" + quan + "' where bid = " + rowid + "";
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
ViewBook_Load(this, null);
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Data will be Deleted", "Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=BT-2105617\\SQLEXPRESS;Initial Catalog=library;Integrated Security=True;";
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "delete from NewBook where bid = " + rowid + "";
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
}
}
}
}