/
BookLab.aspx.cs
145 lines (120 loc) · 5.43 KB
/
BookLab.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
public partial class BookLectHall : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
System.Data.DataTable datedrop = new System.Data.DataTable();
datedrop.Columns.Add(new System.Data.DataColumn("Dates"));
datedrop.Rows.Add(System.DateTime.Today.ToShortDateString());
for (int i = 1; i < 7; i++)
{
datedrop.Rows.Add(System.DateTime.Today.AddDays(i).ToShortDateString());
}
dropdown_date.DataSource = datedrop;
dropdown_date.DataTextField = datedrop.Columns["Dates"].ToString();
dropdown_date.DataBind();
string connetionString = null;
MySqlConnection con;
connetionString = "server=localhost;database=mydb;Uid=root;Pwd=;";
con = new MySqlConnection(connetionString);
con.Open();
MySqlCommand sda = new MySqlCommand("SELECT LabId FROM lab", con);
MySqlDataReader dr;
dr = sda.ExecuteReader();
dropdown_lab_id.Items.Clear();
while (dr.Read())
{
dropdown_lab_id.Items.Add(new ListItem(dr[0].ToString(), dr[0].ToString()));
}
dropdown_lab_id.DataBind();
con.Close();
con.Open();
sda = new MySqlCommand("SELECT LecturerName FROM tablelecturer", con);
dr = sda.ExecuteReader();
dropdown_lect_name.Items.Clear();
while (dr.Read())
{
dropdown_lect_name.Items.Add(new ListItem(dr[0].ToString(), dr[0].ToString()));
}
dropdown_lect_name.DataBind();
con.Close();
}
}
protected void dropdown_lect_name_SelectedIndexChanged(object sender, EventArgs e)
{
string connetionString = null;
MySqlConnection con;
connetionString = "server=localhost;database=mydb;Uid=root;Pwd=;";
con = new MySqlConnection(connetionString);
con.Open();
MySqlCommand sda = new MySqlCommand("SELECT LecturerID FROM tablelecturer where LecturerName = '" + dropdown_lect_name.Text + "'", con);
MySqlDataReader dr;
dr = sda.ExecuteReader();
dr.Read();
lbl_lec_id.Text = dr["LecturerID"].ToString();
con.Close();
}
protected void btn_submit_Click(object sender, EventArgs e)
{
string connectionString = null;
MySqlConnection con;
connectionString = "server=localhost;database=mydb;Uid=root;Pwd=;";
con = new MySqlConnection(connectionString);
MySqlDataAdapter sdx = new MySqlDataAdapter("SELECT COUNT(*) FROM labbooking WHERE LabId='" + dropdown_lab_id.SelectedValue + "' AND BookingDate='" + dropdown_date.SelectedValue + "' AND BookingTime='" + dropdown_time.SelectedValue + "'", con);
System.Data.DataTable dt = new System.Data.DataTable();
sdx.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
System.Windows.MessageBox.Show("Lab already booked!");
return;
}
con.Close();
sdx = new MySqlDataAdapter("SELECT COUNT(*) FROM labbooking WHERE LecturerName='" + dropdown_lect_name.SelectedValue + "' AND BookingDate='" + dropdown_date.SelectedValue + "' AND BookingTime='" + dropdown_time.SelectedValue + "'", con);
dt = new System.Data.DataTable();
sdx.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
System.Windows.MessageBox.Show("Selected Lecturer is already booked!");
return;
}
con.Close();
sdx = new MySqlDataAdapter("SELECT COUNT(*) FROM labbooking WHERE LecturerName='" + dropdown_lect_name.SelectedValue + "' AND BookingDate='" + dropdown_date.SelectedValue + "' AND BookingTime='" + dropdown_time.SelectedValue + "'", con);
dt = new System.Data.DataTable();
sdx.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
System.Windows.MessageBox.Show("Selected Lecturer is already booked!");
return;
}
con.Close();
con.Open();
MySqlCommand sda = new MySqlCommand("SELECT MaxCapacity FROM lab where labId = '" + dropdown_lab_id.SelectedValue + "'", con);
MySqlDataReader dr;
dr = sda.ExecuteReader();
dr.Read();
int maxcap = Convert.ToInt32(dr["MaxCapacity"].ToString());
if(maxcap<Convert.ToInt32(txt_participants.Text))
{
System.Windows.MessageBox.Show("The participants have exceeded the maximum capacity!");
return;
}
con.Close();
DateTime date = Convert.ToDateTime(dropdown_date.SelectedValue);
string d = date.ToShortDateString();
con.Open();
string comm = "INSERT INTO labbooking (BookingDate, BookingTime, LabId, Participants, LecturerName, LecturerId, BatchId) VALUES ('"+d+"', '"+dropdown_time.SelectedValue+"', '"+dropdown_lab_id.SelectedValue+"', '"+txt_participants.Text+"', '"+dropdown_lect_name.SelectedValue+"', '"+lbl_lec_id.Text+"', '"+txt_batch_id.Text+"')";
sda = new MySqlCommand(comm, con);
sda.ExecuteNonQuery();
System.Windows.MessageBox.Show("DONE");
con.Close();
Response.Redirect("main.aspx");
}
}