protected void btnSave_Click(object sender, EventArgs e) { if (checkValidation()) { using (ModelTutor obj = new ModelTutor()) { tblCourse newCourse = new tblCourse { CourseCode = txtCourseCode.Text.Trim(), Name = txtCourseName.Text.Trim() }; try { obj.AddTotblCourses(newCourse); obj.SaveChanges(); DataClear(); //CourseEntity.DataBind(); GridView1.DataBind(); } catch (Exception) { } } } }
private void loadData() { try { int tutorId = Convert.ToInt32(Request.QueryString["tutor"]); int studentId = Convert.ToInt32(Session["studentId"]); int courseId = Convert.ToInt32(Request.QueryString["c"]); int tm = Convert.ToInt32(Request.QueryString["t"]); lblDate.Text = Convert.ToDateTime(Request.QueryString["d"]).ToLongDateString(); using (ModelTutor obj = new ModelTutor()) { lblTutorName.Text = (from e in obj.tblTutors where e.TutorId == tutorId select e.Name).First(); lblTime.Text = tm.ToString() + " to " + (tm + 1).ToString(); var result = (from e in obj.tblCourses where e.CourseId == courseId select e).First(); lblCourse.Text = result.CourseCode + " - " + result.Name; txtStudentName.Text = (from e in obj.tblStudents where e.StudentId == studentId select e.Name).First(); } } catch (Exception) { Response.Redirect("~/StudentDashboard.aspx"); } }
private void fillCourse() { using (ModelTutor obj = new ModelTutor()) { var result = (from e in obj.tblCourses select new { Name = e.CourseCode + " - " + e.Name, e.CourseId }).ToList(); cbCourse.DataSource = result; cbCourse.DataTextField = "Name"; cbCourse.DataValueField = "CourseId"; cbCourse.DataBind(); if (Request.QueryString.HasKeys()) { try { cbCourse.SelectedValue = Request.QueryString["c"].ToString(); loadTimetable(); } catch (Exception) { } } } }
protected void btnLogin_Click(object sender, EventArgs ev) { if (checkValidation()) { Thread.Sleep(1500); using (ModelTutor obj = new ModelTutor()) { try { var result = (from e in obj.tblTutors where e.Email == txtEmail.Text.Trim() && e.Password == txtPassword.Text.Trim() select e).First(); if (string.Compare(txtPassword.Text.Trim(), result.Password) == 0 && result.Active == true) { Session["tutorId"] = result.TutorId; Session["tutorEmail"] = result.Email; Session["tutorName"] = result.Name; Response.Redirect("~/TutorDashboard.aspx"); } else { Label1.Text = "Error: Enter correct email and password"; } } catch (Exception) { Label1.Text = "Error: Enter correct email and password"; } } } }
protected void btnConfirm_Click(object sender, EventArgs e) { if (checkValidation()) { int tutorId = Convert.ToInt32(Request.QueryString["tutor"]); int studentId = Convert.ToInt32(Session["studentId"]); int courseId = Convert.ToInt32(Request.QueryString["c"]); string tm = Request.QueryString["t"].ToString(); using (ModelTutor obj = new ModelTutor()) { obj.AddTotblBookings(new tblBooking { TutorId = tutorId, StudentId = studentId, DateOfBooking = Convert.ToDateTime(Request.QueryString["d"]), Description = txtDescription.Text.Trim(), TimeOfBooking = tm, CourseId = courseId }); try { obj.SaveChanges(); Response.Redirect("~/StudentDashboard.aspx?c=" + Request.QueryString["c"]); } catch (Exception) { } } } }
protected void btnLogin_Click(object sender, EventArgs ev) { if (checkValidation()) { using (ModelTutor obj = new ModelTutor()) { try { var result = (from e in obj.tblAdmins where e.Email == txtEmail.Text.Trim() && e.Password == txtPassword.Text.Trim() select e).First(); if (string.Compare(txtEmail.Text.Trim(), result.Email) == 0 && string.Compare(txtPassword.Text.Trim(), result.Password) == 0) { Session["adminid"] = result.AdminId; Session["adminEmail"] = result.Email; Response.Redirect("~/Admin/Default.aspx"); } else { Label1.Text = "Error: Enter correct details"; } } catch (Exception) { Label1.Text = "Error: Enter correct details"; } } } }
private void fillGrid() { int studentId = Convert.ToInt32(Session["studentId"]); using (ModelTutor obj = new ModelTutor()) { try { var result = (from e in obj.tblRatings where e.StudentId == studentId select new { e.tblTutor.Name, e.Rate }).ToArray(); gridRate.DataSource = result; gridRate.DataBind(); } catch (Exception) { } } }
private void fillData() { using (ModelTutor obj = new ModelTutor()) { try { int studentId = Convert.ToInt32(Session["studentId"]); string email = Session["studentEmail"].ToString(); var result = (from e in obj.tblStudents where e.StudentId == studentId && e.Email == email select e).First(); txtName.Text = result.Name; txtAddress.Text = result.Address; txtStudentId.Text = result.Id; } catch (Exception) { // Error..... Response.Redirect("~/Error.aspx"); } } }
protected void btnUpdate_Click(object sender, EventArgs ev) { using (ModelTutor obj = new ModelTutor()) { int studentId = Convert.ToInt32(Session["studentId"]); string email = Session["studentEmail"].ToString(); var result = (from e in obj.tblStudents where e.StudentId == studentId && e.Email == email select e).First(); result.Name = txtName.Text.Trim(); result.Address = txtAddress.Text.Trim(); result.Id = txtStudentId.Text.Trim(); try { obj.SaveChanges(); Session["studentName"] = result.Name; } catch (Exception) { } } }
protected void btnAddCourse_Click(object sender, EventArgs e) { using (ModelTutor obj = new ModelTutor()) { int id = Convert.ToInt32(Session["tutorId"]); #region AddCourses if (cbCourse1.SelectedValue != "0") { obj.AddTotblTutorCourses(new tblTutorCourse { TutorId = id, CourseId = Convert.ToInt32(cbCourse1.SelectedValue), Grade = txtGrade1.Text.Trim(), Active = false }); } if (cbCourse2.SelectedValue != "0") { obj.AddTotblTutorCourses(new tblTutorCourse { TutorId = id, CourseId = Convert.ToInt32(cbCourse2.SelectedValue), Grade = txtGrade2.Text.Trim(), Active = false }); } if (cbCourse3.SelectedValue != "0") { obj.AddTotblTutorCourses(new tblTutorCourse { TutorId = id, CourseId = Convert.ToInt32(cbCourse3.SelectedValue), Grade = txtGrade3.Text.Trim(), Active = false }); } if (cbCourse4.SelectedValue != "0") { obj.AddTotblTutorCourses(new tblTutorCourse { TutorId = id, CourseId = Convert.ToInt32(cbCourse4.SelectedValue), Grade = txtGrade4.Text.Trim(), Active = false }); } #endregion try { obj.SaveChanges(); txtGrade1.Text = ""; txtGrade2.Text = ""; txtGrade3.Text = ""; txtGrade4.Text = ""; cbCourse1.SelectedIndex = 0; cbCourse2.SelectedIndex = 0; cbCourse3.SelectedIndex = 0; cbCourse4.SelectedIndex = 0; gridCourses.DataBind(); } catch (Exception) { } } }
protected void btnRate_Click(object sender, EventArgs e) { using (ModelTutor obj = new ModelTutor()) { int studentId = Convert.ToInt32(Session["studentId"]); obj.AddTotblRatings(new tblRating { StudentId = studentId, TutorId = Convert.ToInt32(cbTutor.SelectedValue), Rate = Convert.ToInt32(cbrate.SelectedValue) }); try { obj.SaveChanges(); fillCombo(); fillGrid(); } catch (Exception) { } } }
protected void btnRegister_Click(object sender, EventArgs ev) { if (checkValidation()) { System.Threading.Thread.Sleep(1500); using (ModelTutor obj = new ModelTutor()) { string email = txtEmail.Text.Trim(); var result = (from e in obj.tblStudents where e.Email == email select e).Count(); if (result < 1) { tblStudent newStudent = new tblStudent { Id = txtStudentId.Text.Trim(), Name = txtName.Text.Trim(), Address = txtAddress.Text.Trim(), Email = txtEmail.Text.Trim(), Password = txtPassword.Text.Trim(), Active = true }; try { obj.AddTotblStudents(newStudent); obj.SaveChanges(); Response.Redirect("~/Sucess.aspx?m=Your account has been sucessfuly registered. Login to book tutor."); } catch (Exception) { } } else { Label1.Text = "Email already exist"; } } } }
protected void btnUpdatePassword_Click(object sender, EventArgs ev) { using (ModelTutor obj = new ModelTutor()) { int id = Convert.ToInt32(Session["tutorId"]); var result = (from e in obj.tblTutors where e.TutorId == id select e).First(); result.Password = txtPassword.Text.Trim(); try { obj.SaveChanges(); } catch (Exception) { } } }
private void fillCombo() { int studentId = Convert.ToInt32(Session["studentId"]); using (ModelTutor obj = new ModelTutor()) { var result = (from e in obj.tblBookings where e.StudentId == studentId select new { e.tblTutor.Name, e.TutorId }).Distinct().ToArray(); cbTutor.DataSource = result; cbTutor.DataTextField = "Name"; cbTutor.DataValueField = "TutorId"; cbTutor.DataBind(); } }
private void countRating() { using (ModelTutorBooking.ModelTutor obj = new ModelTutorBooking.ModelTutor()) { int tutorId = Convert.ToInt32(Session["tutorId"]); string rateBar = null; try { var result = (from e in obj.tblRatings where e.TutorId == tutorId select e.Rate).Average(); double per = (result * 100) / 5; rateBar = " <div style='float: left; font-weight: bold; font-size: 20px; color: lightred; margin-right: 10px;" + "padding-top: 3px;'>" + "Your Rating is " + per + "%" + "</div>" + "<div style='float: left;'>" + " <div class='meter animate' style='width: 750px;'>" + "<span style='width: " + per + "%'><span></span>" + "</div></div>"; } catch (Exception) { rateBar = " <div style='float: left; font-weight: bold; font-size: 20px; color: lightred; margin-right: 10px;" + "padding-top: 3px;'>" + "You are not rated yet." + "</div>"; } divRate.InnerHtml = rateBar; } }
protected void btnForget_Click(object sender, EventArgs ev) { using (ModelTutor obj = new ModelTutor()) { if (cbWho.SelectedValue == "1") { string email = txtEmail.Text.Trim(); var result = (from e in obj.tblStudents where e.Email == email select e).Count(); if (result == 1) { // sent mail Email m = new Email(); try { var pass = (from e in obj.tblStudents where e.Email == email select e.Password).First(); string body = "Your Email is : " + email + " and your password is : " + pass; m.sendEmail(email, body); Label1.Text = "Email has been sent to you."; txtEmail.Text = ""; } catch (Exception) { Label1.Text = "Email sending failed"; } } else Label1.Text = "Enter valid email"; } else { string email = txtEmail.Text.Trim(); var result = (from e in obj.tblTutors where e.Email == email select e).Count(); if (result == 1) { Email m = new Email(); try { var pass = (from e in obj.tblTutors where e.Email == email select e.Password).First(); string body = "Your Email is : " + email + " and your password is : " + pass; m.sendEmail(email, body); Label1.Text = "Email has been sent to you."; txtEmail.Text = ""; } catch (Exception) { Label1.Text = "Email sending failed"; } } else Label1.Text = "Enter valid email"; } } }
protected void btnUpdateTime_Click(object sender, EventArgs ev) { using (ModelTutor obj = new ModelTutor()) { int id = Convert.ToInt32(Session["tutorId"]); var result = (from e in obj.tblSchedules where e.TutorId == id select e).First(); #region Schedule result.Mo = cbMonStart.SelectedValue + "to" + cbMonEnd.SelectedValue; result.Tu = cbTueStart.SelectedValue + "to" + cbTueEnd.SelectedValue; result.We = cbWedStart.SelectedValue + "to" + cbWedEnd.SelectedValue; result.Th = cbThurStart.SelectedValue + "to" + cbThurEnd.SelectedValue; result.Fr = cbFriStart.SelectedValue + "to" + cbFriEnd.SelectedValue; try { obj.SaveChanges(); } catch (Exception) { } #endregion } }
private void loadData() { using (ModelTutor obj = new ModelTutor()) { int id = Convert.ToInt32(Session["tutorId"]); var result = (from e in obj.tblTutors where e.TutorId == id select e).First(); txtName.Text = result.Name; txtStudentId.Text = result.Id; var result2 = (from e in obj.tblSchedules where e.TutorId == id select e).First(); cbMonStart.SelectedValue = result2.Mo.Substring(0, 2); cbMonEnd.SelectedValue = result2.Mo.Substring(4, 2); cbTueStart.SelectedValue = result2.Tu.Substring(0, 2); cbTueEnd.SelectedValue = result2.Tu.Substring(4, 2); cbWedStart.SelectedValue = result2.We.Substring(0, 2); cbWedEnd.SelectedValue = result2.We.Substring(4, 2); cbThurStart.SelectedValue = result2.Th.Substring(0, 2); cbThurStart.SelectedValue = result2.Th.Substring(4, 2); cbFriStart.SelectedValue = result2.Fr.Substring(0, 2); cbFriEnd.SelectedValue = result2.Fr.Substring(4, 2); SqlDataSourceCourses.SelectParameters["TutorId"].DefaultValue = Session["tutorId"].ToString(); SqlDataSourceCourses.DataBind(); gridCourses.DataBind(); } }
private void Fill_Course_Combobox() { using (ModelTutor obj = new ModelTutor()) { var result = (from e in obj.tblCourses select new { Name = e.CourseCode + " - " + e.Name, e.CourseId }).ToList(); cbCourse1.DataSource = result; cbCourse1.DataTextField = "Name"; cbCourse1.DataValueField = "CourseId"; cbCourse1.DataBind(); cbCourse2.DataSource = result; cbCourse2.DataTextField = "Name"; cbCourse2.DataValueField = "CourseId"; cbCourse2.DataBind(); cbCourse3.DataSource = result; cbCourse3.DataTextField = "Name"; cbCourse3.DataValueField = "CourseId"; cbCourse3.DataBind(); cbCourse4.DataSource = result; cbCourse4.DataTextField = "Name"; cbCourse4.DataValueField = "CourseId"; cbCourse4.DataBind(); } }
protected void btnRegister_Click(object sender, EventArgs ev) { if (checkValidation()) { using (ModelTutor obj = new ModelTutor()) { string email = txtEmail.Text.Trim(); var result = (from e in obj.tblTutors where e.Email == email select e).Count(); if (result < 1) { tblTutor newTutor = new tblTutor { Id = txtStudentId.Text.Trim(), Name = txtName.Text.Trim(), Email = txtEmail.Text.Trim(), Password = txtPassword.Text.Trim(), Active = true }; obj.AddTotblTutors(newTutor); #region AddCourses if (cbCourse1.SelectedValue != "0") { obj.AddTotblTutorCourses(new tblTutorCourse { TutorId = newTutor.TutorId, CourseId = Convert.ToInt32(cbCourse1.SelectedValue), Grade = txtGrade1.Text.Trim(), Active = false }); } if (cbCourse2.SelectedValue != "0") { obj.AddTotblTutorCourses(new tblTutorCourse { TutorId = newTutor.TutorId, CourseId = Convert.ToInt32(cbCourse2.SelectedValue), Grade = txtGrade2.Text.Trim(), Active = false }); } if (cbCourse3.SelectedValue != "0") { obj.AddTotblTutorCourses(new tblTutorCourse { TutorId = newTutor.TutorId, CourseId = Convert.ToInt32(cbCourse3.SelectedValue), Grade = txtGrade3.Text.Trim(), Active = false }); } if (cbCourse4.SelectedValue != "0") { obj.AddTotblTutorCourses(new tblTutorCourse { TutorId = newTutor.TutorId, CourseId = Convert.ToInt32(cbCourse4.SelectedValue), Grade = txtGrade4.Text.Trim(), Active = false }); } #endregion #region Schedule string mon = cbMonStart.SelectedValue + "to" + cbMonEnd.SelectedValue; string tue = cbTueStart.SelectedValue + "to" + cbTueEnd.SelectedValue; string wed = cbWedStart.SelectedValue + "to" + cbWedEnd.SelectedValue; string thur = cbThurStart.SelectedValue + "to" + cbThurEnd.SelectedValue; string fri = cbFriStart.SelectedValue + "to" + cbFriEnd.SelectedValue; obj.AddTotblSchedules(new tblSchedule { TutorId = newTutor.TutorId, Mo = mon, Tu = tue, We = wed, Th = thur, Fr = fri }); #endregion try { obj.SaveChanges(); Email m = new Email(); try { string body = "Hello " + txtName.Text.Trim() + ",\n" + "You are registered for Tutoring."; m.sendEmail(email, body); } catch (Exception) { } Response.Redirect("~/Sucess.aspx?m=Your account has been sucessfuly registered. Login to book tutor."); } catch (Exception) { } } else { Label1.Text = "Email already exist"; } } } }
private void loadTimetable() { System.Threading.Thread.Sleep(1000); using (ModelTutor obj = new ModelTutor()) { #region 1 int courseId = Convert.ToInt32(cbCourse.SelectedValue); var result = from e in obj.tblTutorCourses where e.CourseId == courseId && e.Active == true && e.tblTutor.Active == true select new { e.tblTutor.Name, e.TutorId }; string row = null; string header = null; row += "<div style='float:left; display:block; width:100% ; margin-bottom:-25px;'><div style='float:right;'><span style='width: 30px; height: 30px; background-color: lightgreen; display: inline-block;'>" + "</span><span style='height: 30px; font-weight:bold; display: inline-block; vertical-align: middle;" + "padding-bottom: 5px; margin-left:5px;'>Available</span><span style='margin-left:10px; width: 30px; height: 30px; background-color: lightcoral; display: inline-block;'>" + "</span><span style='height: 30px;font-weight:bold; display: inline-block; vertical-align: middle;" + "padding-bottom: 5px; margin-left:5px;'>Booked</span><span style='margin-left:10px;width: 30px; height: 30px; background-color: #B0B0B0; display: inline-block;'>" + "</span><span style='height: 30px;font-weight:bold; display: inline-block; vertical-align: middle;" + "padding-bottom: 5px; margin-left:5px;'>Not Available</span></div></div>"; for (int k = 0; k < 3; k++) { string day = DateTime.Now.DayOfWeek.ToString().Substring(0, 2); DateTime dateforQuery = DateTime.Now; if (result.Count() > 0) { row += "<div style='float:left; margin-top:35px;'>"; switch (day) { case "Sa": day = DateTime.Now.AddDays((2 + k)).DayOfWeek.ToString().Substring(0, 2); dateforQuery = DateTime.Now.AddDays((2 + k)); row += "<div class='spanMain'>" + DateTime.Now.AddDays((2 + k)).ToLongDateString() + "</div>"; break; case "Su": day = DateTime.Now.AddDays((1 + k)).DayOfWeek.ToString().Substring(0, 2); dateforQuery = DateTime.Now.AddDays((1 + k)); row += "<div class='spanMain'>" + DateTime.Now.AddDays((1 + k)).ToLongDateString() + "</div>"; break; default: day = DateTime.Now.AddDays(k).DayOfWeek.ToString().Substring(0, 2); dateforQuery = DateTime.Now.AddDays(k); row += "<div class='spanMain'>" + DateTime.Now.AddDays(k).ToLongDateString() + "</div>"; break; } for (int i = 8; i < 20; i++) { row += "<div class='span header'>" + i + "</div>"; } row += "</div>"; } else { divNotifocation.Visible = true; } foreach (var item in result) { row += "<div style='float:left; margin-bottom:4px;'>"; row += "<div class='spanMain header'>" + item.Name + "</div>"; int start = 0; int end = 0; #region display day switch (day) { case "Mo": var moTime = (from e in obj.tblSchedules where e.TutorId == item.TutorId select e.Mo).First(); start = Convert.ToInt32(moTime.Substring(0, 2)); end = Convert.ToInt32(moTime.Substring(4, 2)); break; case "Tu": var tuTime = (from e in obj.tblSchedules where e.TutorId == item.TutorId select e.Tu).First(); start = Convert.ToInt32(tuTime.Substring(0, 2)); end = Convert.ToInt32(tuTime.Substring(4, 2)); break; case "We": var weTime = (from e in obj.tblSchedules where e.TutorId == item.TutorId select e.We).First(); start = Convert.ToInt32(weTime.Substring(0, 2)); end = Convert.ToInt32(weTime.Substring(4, 2)); break; case "Th": var thTime = (from e in obj.tblSchedules where e.TutorId == item.TutorId select e.Th).First(); start = Convert.ToInt32(thTime.Substring(0, 2)); end = Convert.ToInt32(thTime.Substring(4, 2)); break; case "Fr": var frTime = (from e in obj.tblSchedules where e.TutorId == item.TutorId select e.Fr).First(); start = Convert.ToInt32(frTime.Substring(0, 2)); end = Convert.ToInt32(frTime.Substring(4, 2)); break; default: break; } DateTime dt = dateforQuery.Date; var bookedTime = (from e in obj.tblBookings where e.TutorId == item.TutorId && e.DateOfBooking == dt select e.TimeOfBooking).ToArray(); bool flag = false; for (int i = 8; i < 20; i++) { flag = false; if (bookedTime.Count() > 0) { for (int j = 0; j < bookedTime.Count(); j++) { if (i == Convert.ToInt32(bookedTime[j])) { row += "<div class='span red'></div>"; flag = true; } } } if (!flag) { if (i >= start && i <= end) { row += " <a href='Booking.aspx?tutor=" + item.TutorId + "&student=" + Session["studentid"] + "&t=" + i + "&d=" + dateforQuery.ToShortDateString() + "&c=" + cbCourse.SelectedValue + "'><div class='span green'></div></a>"; } else row += "<div class='span'></div>"; } } #endregion row += "</div>"; } } contentDiv.InnerHtml = row; #endregion } }