-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIssueBook.cs
More file actions
288 lines (270 loc) · 10.6 KB
/
IssueBook.cs
File metadata and controls
288 lines (270 loc) · 10.6 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
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
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.Threading;
using System.Data.SqlClient;
namespace Library_Management_Syatem
{
public partial class IssueBook : Form
{
Thread th;
SqlCommand cmd;
SqlDataAdapter ad;
SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-9CRFK3A;Initial Catalog=Library_Management_System;Integrated Security=True");
DataTable dt = new DataTable();
DataTable dt1 = new DataTable();
DataTable dt2 = new DataTable();
DataTable dt3 = new DataTable();
DataTable dt4 = new DataTable();
public IssueBook()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
th = new Thread(openhomeform);
th.SetApartmentState(ApartmentState.STA);
th.Start();
}
private void openhomeform()
{
Application.Run(new Home());
}
private void btnissuestudentsearch_Click(object sender, EventArgs e)
{
CheckStu();
if (dt.Rows.Count == 1)
{
label2.Visible = true;
label3.Visible = true;
label4.Visible = true;
label5.Visible = true;
label6.Visible = true;
label7.Visible = true;
textBoxissuestudentfname.Visible = true;
textBoxissuestudentlname.Visible = true;
textBoxissuestudentphoneno.Visible = true;
textBoxissuestudentaddress.Visible = true;
textBoxissuestudentdepartment.Visible = true;
textBoxissuestudentcnic.Visible = true;
textBoxissuestudentfname.Text = dt.Rows[0]["First_Name"].ToString();
textBoxissuestudentlname.Text = dt.Rows[0]["Second_Name"].ToString();
textBoxissuestudentphoneno.Text = dt.Rows[0]["Phone_Number"].ToString();
textBoxissuestudentaddress.Text = dt.Rows[0]["Student_Address"].ToString();
textBoxissuestudentdepartment.Text = dt.Rows[0]["Department"].ToString();
textBoxissuestudentcnic.Text = dt.Rows[0]["CNIC"].ToString();
}
else
{
MessageBox.Show("No Student Exists with this ID");
this.Close();
th = new Thread(openissueform);
th.SetApartmentState(ApartmentState.STA);
th.Start();
}
}
private void CheckStu()
{
con.Open();
cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from Student_Table where Registration_Number='" + textBoxissuestudentid.Text + "'";
cmd.ExecuteNonQuery();
ad = new SqlDataAdapter(cmd);
ad.Fill(dt);
con.Close();
}
private void CheckBook()
{
con.Open();
cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from Book_Table where Book_ISBN='" + textBoxissuebookisbn.Text + "'";
cmd.ExecuteNonQuery();
ad = new SqlDataAdapter(cmd);
ad.Fill(dt1);
con.Close();
}
private void btnissuestudentbook_Click(object sender, EventArgs e)
{
CheckBook();
if (dt1.Rows.Count == 1)
{
label8.Visible = true;
label9.Visible = true;
label10.Visible = true;
label12.Visible = true;
label13.Visible = true;
labelretdate.Visible = true;
textBoxretdate.Visible = true;
textBoxissuebooktitle.Visible = true;
textBoxissuebookauthor1.Visible = true;
textBoxissuebookpages.Visible = true;
textBoxissuebookprice.Visible = true;
textBoxissuebookcopies.Visible = true;
textBoxissuebooktitle.Text = dt1.Rows[0]["Book_Title"].ToString();
textBoxissuebookauthor1.Text = dt1.Rows[0]["Author_Name"].ToString();
textBoxissuebookpages.Text = dt1.Rows[0]["Pages"].ToString();
textBoxissuebookprice.Text = dt1.Rows[0]["Price"].ToString();
textBoxissuebookcopies.Text = dt1.Rows[0]["Copies"].ToString();
}
else
{
MessageBox.Show("No Book available with this ISBN");
this.Close();
th = new Thread(openissueform);
th.SetApartmentState(ApartmentState.STA);
th.Start();
}
}
private void deccopies()
{
con.Open();
con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "update Book_Table set copies=" + (int.Parse(dt1.Rows[0]["Copies"].ToString()) - 1) + " where Book_ISBN='" + dt1.Rows[0]["Book_ISBN"].ToString() + "'";
cmd.ExecuteNonQuery();
con.Close();
}
private void Alreadyassignedcheck()
{
con.Open();
cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * From IssueBook_Table where Book_ISBN='" + textBoxissuebookisbn.Text + "' and Registration_Number='" + textBoxissuestudentid.Text + "'";
cmd.ExecuteNonQuery();
ad = new SqlDataAdapter(cmd);
ad.Fill(dt2);
con.Close();
}
private void chechlimit()
{
con.Open();
cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * From IssueBook_Table where Registration_Number='" + textBoxissuestudentid.Text + "'";
cmd.ExecuteNonQuery();
ad = new SqlDataAdapter(cmd);
ad.Fill(dt4);
con.Close();
}
private void btnissue_Click(object sender, EventArgs e)
{
if (textBoxretdate.Enabled == false)
{
MessageBox.Show("Plz Enter Return Date");
}
else
{
chechlimit();
Alreadyassignedcheck();
if (dt2.Rows.Count == 1)
{
MessageBox.Show("This book already issued to this student");
}
else if (int.Parse(dt1.Rows[0]["Copies"].ToString()) == 1)
{
MessageBox.Show("This book is not available right now");
}
else if (dt4.Rows.Count == 3)
{
MessageBox.Show("This Student cannot issue more books");
}
else
{
DialogResult dr;
if (checkfine() == true)
{
dr = MessageBox.Show("You have to Pay Fine First", "Fine", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dr == DialogResult.Yes)
{
delfromfinetable();
deccopies();
insertintoissuebooktable();
insertintoactivitylog();
MessageBox.Show("Congratulations!!! Book is Issued Successfully.");
}
}
else
{
deccopies();
insertintoissuebooktable();
insertintoactivitylog();
MessageBox.Show("Congratulations!!! Book is Issued Successfully.");
}
}
}
this.Close();
th = new Thread(openissueform);
th.SetApartmentState(ApartmentState.STA);
th.Start();
}
private void openissueform()
{
Application.Run(new IssueBook());
}
private void delfromfinetable()
{
con.Open();
cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "delete from Fine_Table where Registration_Number='"+textBoxissuestudentid.Text+"'";
cmd.ExecuteNonQuery();
con.Close();
}
private bool checkfine()
{
con.Open();
cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from Fine_Table where Registration_Number='" + textBoxissuestudentid.Text + "'";
cmd.ExecuteNonQuery();
ad = new SqlDataAdapter(cmd);
ad.Fill(dt3);
con.Close();
if (dt3.Rows.Count == 1)
{
return true;
}
else
{
return false;
}
}
private void insertintoactivitylog()
{
con.Open();
cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Insert into ActivityLog_Table values(Default,'Book with ISBN(" + textBoxissuebookisbn.Text + ") is Issued to Student with Registration_No("+textBoxissuestudentid.Text+").')";
cmd.ExecuteNonQuery();
con.Close();
}
private void insertintoissuebooktable()
{
con.Open();
con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into IssueBook_Table values('" + textBoxissuestudentid.Text + "','" + textBoxissuebookisbn.Text + "','" + Login.Admin_ID + "',Default,'" + textBoxretdate.Value + "')";
cmd.ExecuteNonQuery();
con.Close();
}
private void IssueBook_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Escape)
{
this.Close();
th = new Thread(openhomeform);
th.SetApartmentState(ApartmentState.STA);
th.Start();
}
}
}
}