-
Notifications
You must be signed in to change notification settings - Fork 0
/
book_borrow_return.aspx.cs
228 lines (183 loc) · 7.79 KB
/
book_borrow_return.aspx.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
220
221
222
223
224
225
226
227
228
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
namespace School_Management_System
{
public partial class book_borrow_return : System.Web.UI.Page
{
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\School.mdb;");
OleDbDataAdapter da = new OleDbDataAdapter();
DataSet ds = new DataSet();
string accsno, bookname, authorname, edition;
string accs;
int copies;
string regno, std;
protected void Page_Load(object sender, EventArgs e)
{
bdate_txtbx.Text = DateTime.Now.ToString("dd/MM/yyyy");
retdate_txtbx.Text = DateTime.Now.ToString("dd/MM/yyyy");
}
protected void sub_btn_Click(object sender, EventArgs e)
{
if (book_dpdown.Text == "Borrow")
{
borrow_pan.Visible = true;
return_pan.Visible = false;
da.SelectCommand = new OleDbCommand("select * from addbook where copies>0", con);
ds.Clear();
da.Fill(ds);
book_grid.DataSource = ds;
book_grid.DataBind();
}
else
{
borrow_pan.Visible = false;
return_pan.Visible = true;
regno_validate.Enabled = true;
}
}
protected void reset0_btn_Click(object sender, EventArgs e)
{
stsret_lbl.Visible = false;
return_pan.Visible = false;
}
protected void view_grid_SelectedIndexChanged(object sender, EventArgs e)
{
return_btn.Enabled = true;
ret_val.Enabled = true;
}
protected void book_grid_SelectedIndexChanged(object sender, EventArgs e)
{
borrow_btn.Enabled = true;
reg_val.Enabled = true;
date_val.Enabled = true;
}
protected void book_dpdown_SelectedIndexChanged(object sender, EventArgs e)
{
if(book_dpdown.SelectedItem.Text=="Borrow")
{
reg_val.Enabled = true;
date_val.Enabled = true;
return_pan.Visible = false;
}
else
{
regno_validate.Enabled = true;
borrow_pan.Visible = false;
}
}
protected void close_btn_Click(object sender, EventArgs e)
{
Response.Redirect("student_info.aspx");
}
protected void borrow_btn_Click(object sender, EventArgs e)
{
GridViewRow gr = book_grid.SelectedRow;
accsno = gr.Cells[1].Text;
bookname = gr.Cells[2].Text;
authorname = gr.Cells[3].Text;
edition = gr.Cells[5].Text;
copies = int.Parse(gr.Cells[6].Text);
borrow_btn.Enabled = false;
da.SelectCommand = new OleDbCommand("select * from schooladmission where regno='" + reg_txtbx.Text + "'", con);
ds.Clear();
da.Fill(ds);
if (ds.Tables[0].Rows.Count == 0)
{
sts_lbl.Visible = true;
sts_lbl.ForeColor = System.Drawing.Color.Red;
sts_lbl.Text = "Please Check the Registration Number";
}
else
{
string std;
std = ds.Tables[0].Rows[0][7].ToString();
da.SelectCommand = new OleDbCommand("select regno,accsno from borrandret where regno='" + reg_txtbx.Text + "' AND accsno='"+accsno+"'", con);
ds.Clear();
da.Fill(ds);
if ((ds.Tables[0].Rows.Count==0))
{
copies = copies - 1;
con.Open();
da.InsertCommand = new OleDbCommand("insert into borrandret(regno,accsno,bookname,authorname,edition,borrdate,retdate,std) values('" + reg_txtbx.Text + "','" + accsno + "','" + bookname + "','" + authorname + "','" + edition + "','" + bdate_txtbx.Text + "','N/A','" + std + "')", con);
sts_lbl.Visible = true;
sts_lbl.ForeColor = System.Drawing.Color.Green;
sts_lbl.Text = "values are Inserted into table";
da.InsertCommand.ExecuteNonQuery();
da.UpdateCommand = new OleDbCommand("update addbook set copies='" + copies + "' where accsno='" + accsno + "'", con);
da.UpdateCommand.ExecuteNonQuery();
con.Close();
}
else
{
sts_lbl.Visible = true;
sts_lbl.ForeColor = System.Drawing.Color.Red;
sts_lbl.Text = "The Selected Book Was Already Taken By The User";
}
}
reg_val.Enabled = false;
date_val.Enabled = false;
}
protected void reset_btn_Click(object sender, EventArgs e)
{
borrow_pan.Visible = false;
sts_lbl.Visible = false;
da.SelectCommand = new OleDbCommand("select * from addbook where copies>0", con);
ds.Clear();
da.Fill(ds);
book_grid.DataSource = ds;
book_grid.DataBind();
reg_txtbx.Text = "";
bdate_txtbx.Text = "";
reg_val.Enabled = true;
}
protected void return_btn_Click(object sender, EventArgs e)
{
GridViewRow gr = view_grid.SelectedRow;
regno = gr.Cells[1].Text;
accs = gr.Cells[2].Text;
std = gr.Cells[7].Text;
con.Open();
da.UpdateCommand = new OleDbCommand("update borrandret set retdate='" + retdate_txtbx.Text + "' where accsno='" + accs + "' AND regno='" + regno_txtbx.Text + "'", con);
da.SelectCommand = new OleDbCommand("select copies from addbook where accsno='" + accs + "'", con);
ds.Clear();
da.Fill(ds);
int rcopies = int.Parse(ds.Tables[0].Rows[0][0].ToString());
rcopies++;
da.UpdateCommand.ExecuteNonQuery();
da.UpdateCommand = new OleDbCommand("update addbook set copies=" + rcopies + " where accsno='" + accs + "'", con);
stsret_lbl.Visible = true;
stsret_lbl.ForeColor = System.Drawing.Color.Green;
stsret_lbl.Text = "Values Are Stored Into Database";
da.UpdateCommand.ExecuteNonQuery();
return_btn.Enabled = false;
da.DeleteCommand=new OleDbCommand("delete * from borrandret where accsno='" + accs + "' AND regno='" + regno_txtbx.Text + "'", con);
da.DeleteCommand.ExecuteNonQuery();
con.Close();
ret_val.Visible = false;
}
protected void regok_btn_Click(object sender, EventArgs e)
{
da.SelectCommand = new OleDbCommand("select regno,accsno,bookname,authorname,edition,borrdate,std from borrandret where regno='" + regno_txtbx.Text + "'", con);
ds.Clear();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
view_grid.DataSource = ds;
view_grid.DataBind();
st_lbl.Visible = false;
}
else
{
st_lbl.Visible = true;
sts_lbl.ForeColor = System.Drawing.Color.Green;
st_lbl.Text = "You have not Borrowed Any Books to return";
}
}
}
}