-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDepartments.cs
More file actions
153 lines (135 loc) · 4.35 KB
/
Copy pathDepartments.cs
File metadata and controls
153 lines (135 loc) · 4.35 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
namespace Student_Registration_System
{
public partial class Departments : Form
{
Functions Con;
public Departments()
{
InitializeComponent();
this.DoubleBuffered = true;
Con = new Functions();
ShowDepartments();
}
private void ShowDepartments()
{
string Query = "Select * from DepartmentTbl";
DepartmentsList.DataSource = Con.GetData(Query);
}
private void AddBtn_Click(object sender, EventArgs e)
{
if (DepNameTb.Text == "" || DetailsTb.Text == "")
{
MessageBox.Show("Missing Data!!!");
}
else
{
try
{
string DName = DepNameTb.Text;
string Details = DetailsTb.Text;
string Query = "insert into DepartmentTbl values('{0}','{1}')";
Query = string.Format(Query, DName, Details);
Con.SetData(Query);
ShowDepartments();
MessageBox.Show("Department Added!!!");
clear();
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
}
int Key = 0;
private void DepartmentsList_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
DepNameTb.Text = DepartmentsList.SelectedRows[0].Cells[1].Value.ToString();
DetailsTb.Text = DepartmentsList.SelectedRows[0].Cells[2].Value.ToString();
if (DepNameTb.Text == "")
{
Key = 0;
}
else
{
Key = Convert.ToInt32(DepartmentsList.SelectedRows[0].Cells[0].Value.ToString());
}
}
private void UpdateBtn_Click(object sender, EventArgs e)
{
if (DepNameTb.Text == "" || DetailsTb.Text == "")
{
MessageBox.Show("Missing Data!!!");
}
else
{
try
{
string DName = DepNameTb.Text;
string Details = DetailsTb.Text;
string Query = "Update DepartmentTbl set DepName='{0}',DepDetails='{1}' where DepId='{2}'";
Query = string.Format(Query, DName, Details, Key);
Con.SetData(Query);
ShowDepartments();
MessageBox.Show("Department Updated!!!");
clear();
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
}
private void clear()
{
DepNameTb.Text = "";
DetailsTb.Text = "";
}
private void DeleteBtn_Click(object sender, EventArgs e)
{
if (Key == 0)
{
MessageBox.Show("Select a Department!!!");
}
else
{
try
{
string DName = DepNameTb.Text;
string Details = DetailsTb.Text;
string Query = "Delete from DepartmentTbl where DepId='{0}'";
Query = string.Format(Query, Key);
Con.SetData(Query);
ShowDepartments();
MessageBox.Show("Department Deleted!!!");
clear();
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
}
private void StudentLbl_Click_1(object sender, EventArgs e)
{
Students Obj = new Students();
Obj.ShowDialog();
this.Close();
}
private void Dashboard_Click_1(object sender, EventArgs e)
{
Dashboard Obj = new Dashboard();
Obj.ShowDialog();
this.Close();
}
private void label10_Click_1(object sender, EventArgs e)
{
Login Obj = new Login();
Obj.ShowDialog();
this.Close();
}
private void CloseBtn_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}