-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewStudentInformation.cs
More file actions
182 lines (140 loc) · 6.36 KB
/
Copy pathViewStudentInformation.cs
File metadata and controls
182 lines (140 loc) · 6.36 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
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
namespace Library_Management_System
{
public partial class ViewStudentInformation : Form
{
public ViewStudentInformation()
{
InitializeComponent();
}
private void txtSearchEnrollment_TextChanged(object sender, EventArgs e)
{
if (txtSearchEnrollment.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 NewStudent where enroll LIKE '"+txtSearchEnrollment.Text+"%' ";
SqlDataAdapter DA = new SqlDataAdapter();
DA.SelectCommand = 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 NewStudent";
SqlDataAdapter DA = new SqlDataAdapter();
DA.SelectCommand = cmd;
DataSet DS = new DataSet();
DA.Fill(DS);
dataGridView1.DataSource = DS.Tables[0];
}
}
private void ViewStudentInformation_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 NewStudent";
SqlDataAdapter DA = new SqlDataAdapter();
DA.SelectCommand = 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());
}
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 NewStudent where stuid = "+bid+" ";
SqlDataAdapter DA = new SqlDataAdapter();
DA.SelectCommand = cmd;
DataSet DS = new DataSet();
DA.Fill(DS);
rowid = Int64.Parse(DS.Tables[0].Rows[0][0].ToString());
txtSName.Text = DS.Tables[0].Rows[0][1].ToString();
txtEnrollment.Text= DS.Tables[0].Rows[0][2].ToString();
txtDepartment.Text= DS.Tables[0].Rows[0][3].ToString();
txtSemester.Text = DS.Tables[0].Rows[0][4].ToString();
txtContact.Text = DS.Tables[0].Rows[0][5].ToString();
txtEmail.Text = DS.Tables[0].Rows[0][6].ToString();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
String sname = txtSName.Text;
String enroll = txtEnrollment.Text;
String dep = txtDepartment.Text;
String sem = txtSemester.Text;
Int64 contact = Int64.Parse(txtContact.Text);
String semail = txtEmail.Text;
if (MessageBox.Show("Are you Sure? ", "Success", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == 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 = "update NewStudent set sname = '" + sname + "',enroll = '" + enroll + "',dep = '" + dep + "',sem= '" + sem + "',contact = " + contact + ",email = '" + semail + "' where stuid = " + rowid + "";
SqlDataAdapter DA = new SqlDataAdapter();
DA.SelectCommand = cmd;
DataSet DS = new DataSet();
DA.Fill(DS);
ViewStudentInformation_Load(this,null);
}
}
private void btnRefresh_Click(object sender, EventArgs e)
{
ViewStudentInformation_Load(this, null);
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you Sure? ", "Delete", 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 NewStudent where stuid = " + rowid + "";
SqlDataAdapter DA = new SqlDataAdapter();
DA.SelectCommand = cmd;
DataSet DS = new DataSet();
DA.Fill(DS);
ViewStudentInformation_Load(this, null);
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
if(MessageBox.Show("Unsaved Data will be lost","Are you Sure?",MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
{
this.Close();
}
}
}
}