forked from dalbemil/AdvisorBooking
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Confirm.aspx.cs
144 lines (115 loc) · 5.38 KB
/
Confirm.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Globalization;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Prevent exceptions,corruptions.
if (Session["date"] == null || Session["AdvisorID"] == null)
{
Server.Transfer("Advisor.aspx");
}
int studentId = Convert.ToInt32(Session["StudentID"].ToString());
int advisorId = Convert.ToInt32(Session["AdvisorID"].ToString());
string date = Session["date"].ToString();
ronUtil2 get = new ronUtil2(advisorId);
Submit.Visible = true;
//if (get.getCheck(studentId) == true)
//{ Submit.Visible = true; }
//else
//{ Cancel.Visible = true; }
DateTime datev2 = DateTime.ParseExact(Session["date"].ToString(), "MM/dd/yyyy", null);
DateTime[] advisorAllSlots = get.getSlots(advisorId, date);
DateTime[] taken = get.getTaken(advisorId, date);
DateTime[] availibility = get.getAvailability(advisorAllSlots, taken);
string[] shorttime = new string[availibility.Length];
for (int i = 0; i < availibility.Length; i++)
{ shorttime[i] = availibility[i].ToShortTimeString(); }
txtAdvisorName.Text = get.FullName;
//Label1.Text = "Date : " + datev2.ToLongDateString();
txtDate.Text = datev2.ToShortDateString();
DropDownList1.DataSource = shorttime;
// DropDownList1.DataBind();
if (!IsPostBack)
{
DropDownList1.DataBind();
}
if (availibility.Length==0)
{Response.Write("<script type='text/javascript'>alert('It is fully booked.');</script>");
Server.Transfer("Schedule.aspx");}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//Prevent corruption. Double check availability. Delete cookies
if (Session["date"] != null && Session["AdvisorID"] != null)
{
int advisorId = Convert.ToInt32(Session["AdvisorID"].ToString());
string date = Session["date"].ToString();
int studentId = Convert.ToInt32(Session["StudentID"].ToString());
Session["date"] = null;
Session["AdvisorID"] = null;
ronUtil2 get = new ronUtil2(advisorId);
DateTime datev2 = DateTime.ParseExact(date, "MM/dd/yyyy", null);
DateTime[] advisorAllSlots = get.getSlots(advisorId, date);
DateTime[] taken = get.getTaken(advisorId, date);
DateTime[] availibility = get.getAvailability(advisorAllSlots, taken);
bool proceed = false;
for (int i = 0; i < availibility.Length; i++)
{
if (DropDownList1.SelectedValue.ToString() == availibility[i].ToShortTimeString())
{
proceed = true;
}
}
if (proceed)
{
DateTime picked = new DateTime();
picked = DateTime.ParseExact(DropDownList1.SelectedValue.ToString(), "h:mm tt", CultureInfo.InvariantCulture);
int Student_Id = studentId;
int Advisor_Id = advisorId;
string Time = picked.ToString("HH:mm:ss");
string Date = datev2.ToString("yyyy-MM-dd");
Label1.Text = Time;
string Comments = TextArea1.Value.ToString();
int Availability_ID= get.getAvailableID(Advisor_Id, date);
string sqlQuery = "INSERT INTO Appointment (Availability_ID, Student_Id,Time,Date,Comment)";
sqlQuery += " VALUES (@Availability_ID,@Student_Id,@Time,@Date,@Comment)";
string connectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString();
using (SqlConnection dataConnection = new SqlConnection(connectionString))
{
using (SqlCommand dataCommand = new SqlCommand(sqlQuery, dataConnection))
{
dataCommand.Parameters.AddWithValue("Availability_ID", Availability_ID);
dataCommand.Parameters.AddWithValue("Student_Id", studentId);
dataCommand.Parameters.AddWithValue("Time", Time);
dataCommand.Parameters.AddWithValue("Date", Date);
dataCommand.Parameters.AddWithValue("Comment", Comments);
dataConnection.Open();
dataCommand.ExecuteNonQuery();
dataConnection.Close();
}
}
Response.Write("<script type='text/javascript'>alert('You are booked');</script>");
Server.Transfer("Advisor.aspx");
}
else
{
Response.Write("<script type='text/javascript'>alert('Something went wrong. Try again later');</script>");
Server.Transfer("Advisor.aspx");
}
}
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
}