public void CreateFilteredLessonsTable(string filterType, int selectedValue) { // Show the filtered lesson table and hide the lesson table and 'filterLessons' div tblFilteredLessons.Visible = true; tblLessons.Visible = false; filterLessons.Visible = false; List <Lesson> filteredLessons = DatabaseWebService.ListAllLessonsByType(filterTypeFromURL, filterIDFromURL); foreach (var lesson in filteredLessons) { TableRow row = new TableRow(); // This button has the lesson name and uses the 'btnViewLesson' event TableCell title = new TableCell(); Button btnViewLesson = new Button(); btnViewLesson.Text = lesson.Title; btnViewLesson.CommandArgument = lesson.Id.ToString(); btnViewLesson.Click += new EventHandler(btnViewLesson_Click); btnViewLesson.CssClass += "hidden_btn"; title.Controls.Add(btnViewLesson); if (currentUser != null && currentUser.UserType == 2) { // If logged in user is a teacher // This button is for editing a lesson and uses the 'btnEditLesson' event Button btnEditLesson = new Button(); btnEditLesson.Text = "Edit"; btnEditLesson.CommandArgument = lesson.Id.ToString(); btnEditLesson.Click += new EventHandler(btnEditLesson_Click); btnEditLesson.CssClass += "hidden_edit_btn"; title.Controls.Add(btnEditLesson); // This button is for deleting a lesson and uses the 'btnDeleteLesson' event Button btnDeleteLesson = new Button(); btnDeleteLesson.Text = "Delete"; btnDeleteLesson.CommandArgument = lesson.Id.ToString(); btnDeleteLesson.Click += new EventHandler(btnDeleteLesson_Click); btnDeleteLesson.CssClass += "hidden_delete_btn"; title.Controls.Add(btnDeleteLesson); } row.Cells.Add(title); TableCell teacher = new TableCell(); teacher.Text = lesson.LessonTeacher.Title + " " + lesson.LessonTeacher.Surname; row.Cells.Add(teacher); TableCell topic = new TableCell(); topic.Text = lesson.LessonTopic.Name; row.Cells.Add(topic); TableCell date = new TableCell(); date.Text = lesson.Date; row.Cells.Add(date); tblFilteredLessons.Rows.Add(row); } }
protected void btnDeleteAnswer_Click(object sender, EventArgs e) { if (DatabaseWebService.DeleteAnswer(int.Parse(((Button)sender).CommandArgument)) == true) { // Answer deleted successfully Response.Redirect("DiscussionBoard.aspx?questionID=" + questionIDFromURL); } }
protected void btnSaveQuestion_Click(object sender, EventArgs e) { if (DatabaseWebService.EditQuestion(editQuestionFromURL, txtEditQuestionTitle.Text, txtEditQuestionText.Text) == true) { // Question edited and save successfully Response.Redirect("DiscussionBoard.aspx"); } }
protected void btnDeleteLesson_Click(object sender, EventArgs e) { // Delete the selected lesson using the 'DeleteLesson' method if (DatabaseWebService.DeleteLesson(int.Parse(((Button)sender).CommandArgument)) == true) { Response.Redirect("InteractiveLesson.aspx"); } }
protected void btnSaveLesson_Click(object sender, EventArgs e) { // Save the edited lesson using the 'EditLesson' method if (DatabaseWebService.EditLesson(editLessonFromURL, txtEditLessonTitle.Text, txtEditLessonText.Text) == true) { Response.Redirect("InteractiveLesson.aspx"); } }
protected void btnAddReply_Click(object sender, EventArgs e) { if (DatabaseWebService.SaveAnswer(questionIDFromURL, txtAddReplyTxt.Text, currentUser.UserType, UserLogin.LoggedInUser.Id) == true) { // Answer saved successfully Response.Redirect("DiscussionBoard.aspx?questionID=" + questionIDFromURL); } }
protected void btnDeleteQuestion_Click(object sender, EventArgs e) { if (DatabaseWebService.DeleteQuestion(int.Parse(((Button)sender).CommandArgument)) == true) { // Question deleted successfully Response.Redirect("DiscussionBoard.aspx"); } }
protected void btnSaveQuestion_Click(object sender, EventArgs e) { if (DatabaseWebService.SaveQuestion(currentUser.Id, txtQuestionTitle.Text, txtQuestionText.Text, int.Parse(dropQuestionLesson.SelectedValue)) == true) { lblConfirmation.Text = "Success, " + txtQuestionTitle.Text + " has been saved."; } else { lblConfirmation.Text = "Error saving " + txtQuestionTitle.Text + " to database, please try again."; } }
public void CreateLessonsTable() { List <Lesson> lessons = DatabaseWebService.ListAllLessons(); foreach (var lesson in lessons) { TableRow row = new TableRow(); // This button has the lesson name and uses the 'btnViewLesson' event TableCell title = new TableCell(); Button btnViewLesson = new Button(); btnViewLesson.Text = lesson.Title; btnViewLesson.CommandArgument = lesson.Id.ToString(); btnViewLesson.Click += new EventHandler(btnViewLesson_Click); btnViewLesson.CssClass += "hidden_btn"; title.Controls.Add(btnViewLesson); if (currentUser != null && currentUser.UserType == 2) { // If logged in user is a teacher // This button is for editing a lesson and uses the 'btnEditLesson' event Button btnEditLesson = new Button(); btnEditLesson.Text = "Edit"; btnEditLesson.CommandArgument = lesson.Id.ToString(); btnEditLesson.Click += new EventHandler(btnEditLesson_Click); btnEditLesson.CssClass += "hidden_edit_btn"; title.Controls.Add(btnEditLesson); // This button is for deleting a lesson and uses the 'btnDeleteLesson' event Button btnDeleteLesson = new Button(); btnDeleteLesson.Text = "Delete"; btnDeleteLesson.CommandArgument = lesson.Id.ToString(); btnDeleteLesson.Click += new EventHandler(btnDeleteLesson_Click); btnDeleteLesson.CssClass += "hidden_delete_btn"; title.Controls.Add(btnDeleteLesson); } row.Cells.Add(title); TableCell teacher = new TableCell(); teacher.Text = lesson.LessonTeacher.Title + " " + lesson.LessonTeacher.Surname; row.Cells.Add(teacher); TableCell topic = new TableCell(); topic.Text = lesson.LessonTopic.Name; row.Cells.Add(topic); TableCell date = new TableCell(); date.Text = lesson.Date; row.Cells.Add(date); tblLessons.Rows.Add(row); } }
protected void btnLogIn_Click(object sender, EventArgs e) { // Find out if user is a child or teacher and log them in DatabaseWebService.LogInUser(txtUsername.Text, txtPassword.Text); if (Session["loggedInUser"] != null) { User currentUser = ((User)Session["loggedInUser"]); if (currentUser.UserType == 1) { // Successful log in as a child lblInfo.Text = "Success, " + currentUser.FirstName + ", you are now logged in as a child."; if (currentUser.Gender == 1) { // If logged in user is male // Change master page css to male colour scheme this.Master.ChangePageColourOnGender(1); } else if (currentUser.Gender == 2) { // If logged in user is female // Change master page css to female colour scheme this.Master.ChangePageColourOnGender(2); } } else if (currentUser.UserType == 2) { // Successful log in as a teacher lblInfo.Text = "Success, " + currentUser.Title + " " + currentUser.Surname + ", you are now logged in as a teacher."; } // Enable log out fields btnLogOut.Enabled = true; // Disable log in fields txtUsername.Enabled = false; txtPassword.Enabled = false; btnLogIn.Enabled = false; // Clear text from log in fields txtUsername.Text = ""; txtPassword.Text = ""; } else { // Unsuccessful log in lblInfo.Text = "Error logging in, check username and password."; } }
public void ShowEditQuestion(int questionSelected) { List <Question> showQuestion = DatabaseWebService.ShowQuestionByID(questionSelected); // Hide the 'allQuestions' div and show the 'editQuestion' div allQuestions.Visible = false; editQuestion.Visible = true; foreach (var question in showQuestion) { txtEditQuestionTitle.Text = question.Title; lblEditQuestionAsker.Text = question.QuestionUser.FirstName + " " + question.QuestionUser.Surname; lblEditQuestionDate.Text = question.Date; txtEditQuestionText.Text = question.Text; } }
public void ShowEditLesson(int lessonSelected) { List <Lesson> showLesson = DatabaseWebService.ShowLessonByID(lessonSelected); // Hide the 'allLessons' dov and show the 'editLesson' div allLessons.Visible = false; editLesson.Visible = true; foreach (var lesson in showLesson) { txtEditLessonTitle.Text = lesson.Title; lblEditLessonTeacher.Text = lesson.LessonTeacher.Title + " " + lesson.LessonTeacher.Surname; lblEditLessonTopic.Text = lesson.LessonTopic.Name; lblEditLessonDate.Text = lesson.Date; txtEditLessonText.Text = lesson.Text; } }
public void ShowLesson(int lessonSelected) { List <Lesson> showLesson = DatabaseWebService.ShowLessonByID(lessonSelected); // Hide the 'allLessons' div and show the 'selectedLesson' div allLessons.Visible = false; selectedLesson.Visible = true; foreach (var lesson in showLesson) { lblLessonTitle.Text = lesson.Title; lblLessonTeacher.Text = lesson.LessonTeacher.Title + " " + lesson.LessonTeacher.Surname; lblLessonTopic.Text = lesson.LessonTopic.Name; lblLessonDate.Text = lesson.Date; txtLessonText.Text = lesson.Text; imgLessonImage.ImageUrl = lesson.LessonImage.Source; } }
protected void btnSaveLesson_Click(object sender, EventArgs e) { int lessonImageID; if (rbImage1.Checked == true) { lessonImageID = 1; } else if (rbImage2.Checked == true) { lessonImageID = 2; } else if (rbImage3.Checked == true) { lessonImageID = 3; } else if (rbImage4.Checked == true) { lessonImageID = 4; } else if (rbImage5.Checked == true) { lessonImageID = 5; } else { lessonImageID = 0; } if (DatabaseWebService.SaveLesson(currentUser.Id, txtLessonTitle.Text, txtLessonText.Text, int.Parse(dropLessonTopic.SelectedValue), lessonImageID) == true) { lblConfirmation.Text = "Success, " + txtLessonTitle.Text + " has been saved."; txtLessonTitle.Text = ""; txtLessonText.Text = ""; } else { // If lesson hasn't been saved lblConfirmation.Text = "Error saving " + txtLessonTitle.Text + " to database, please try again."; } }
public void CreateScoresTable() { List <Score> scores = DatabaseWebService.GetScoresByUser(currentUser.Id); try { foreach (var score in scores) { TableRow row = new TableRow(); TableCell position = new TableCell(); position.Text = score.Position.ToString(); row.Cells.Add(position); TableCell name = new TableCell(); name.Text = score.User.FirstName + " " + score.User.Surname; row.Cells.Add(name); TableCell playerScore = new TableCell(); playerScore.Text = score.PlayerScore.ToString(); row.Cells.Add(playerScore); TableCell dateTime = new TableCell(); dateTime.Text = score.DateTime; row.Cells.Add(dateTime); userScoresTbl.Rows.Add(row); } } catch (Exception ex) { // Error connecting to database TableRow row = new TableRow(); TableCell errorMessage = new TableCell(); errorMessage.Text = "Error loading scores, please try again."; errorMessage.ColumnSpan = 4; row.Cells.Add(errorMessage); userScoresTbl.Rows.Add(row); } }
protected void Page_Load(object sender, EventArgs e) { // Get logged in user if (UserLogin.LoggedInUser != null) { // Logged in currentUser = UserLogin.LoggedInUser; if (currentUser.UserType == 1) { lblInfo.Text = currentUser.FirstName + " " + currentUser.Surname + ", you are logged in as a child."; } else if (currentUser.UserType == 2) { lblInfo.Text = currentUser.Title + " " + currentUser.Surname + ", you are logged in as a teacher."; } } else { // If not logged in // Must be logged in, redirect to Discussion Board Page Response.Redirect("InteractiveLesson.aspx"); } List <LessonImage> allLessonImages = DatabaseWebService.ListLessonImages(); int count = 0; foreach (var image in allLessonImages) { count++; switch (count) { case 0: break; case 1: imgImage1.ImageUrl = image.Source; rbImage1.Text = image.Description; break; case 2: imgImage2.ImageUrl = image.Source; rbImage2.Text = image.Description; break; case 3: imgImage3.ImageUrl = image.Source; rbImage3.Text = image.Description; break; case 4: imgImage4.ImageUrl = image.Source; rbImage4.Text = image.Description; break; case 5: imgImage5.ImageUrl = image.Source; rbImage5.Text = image.Description; break; } } }
public void ShowQuestion(int questionSelected) { // Show the 'selectedQuestion' div selectedQuestion.Visible = true; List <Question> showQuestion = DatabaseWebService.ShowQuestionByID(questionSelected); foreach (var question in showQuestion) { lblQuestionTitle.Text = question.Title; txtShowQuestionText.Text = question.Text; lblQuestionDate.Text = question.Date; lblQuestionChild.Text = question.QuestionUser.FirstName + " " + question.QuestionUser.Surname; lblQuestionTopic.Text = question.QuestionLesson.LessonTopic.Name; lblQuestionLesson.Text = question.QuestionLesson.Title; } List <Answer> answers = DatabaseWebService.ListAllAnswers(questionSelected); if (answers.Count == 0) { // There are no replies lblReplies.Text = "No Replies to selected question"; } else { // There are replies lblReplies.Text = "Replies"; foreach (var answer in answers) { TableRow answerDetailsRow = new TableRow(); TableCell answerDetailsCell = new TableCell(); Label answerByText = new Label(); answerByText.Text = "Reply by "; answerByText.Font.Bold = true; answerDetailsCell.Controls.Add(answerByText); Label answererName = new Label(); if (answer.Answerer.UserType == 1) { answererName.Text = answer.Answerer.FirstName + " " + answer.Answerer.Surname; } else { answererName.Text = answer.Answerer.Title + " " + answer.Answerer.Surname; } answerDetailsCell.Controls.Add(answererName); Label answerDatePrefix = new Label(); answerDatePrefix.Text = " on "; answerDatePrefix.Font.Bold = true; answerDetailsCell.Controls.Add(answerDatePrefix); Label answerDate = new Label(); answerDate.Text = answer.Date; answerDetailsCell.Controls.Add(answerDate); if (currentUser != null && currentUser.UserType == 2) { // If logged in user is a teacher // This button is for deleting a lesson and uses the 'btnDeleteAnswer' event Button btnDeleteAnswer = new Button(); btnDeleteAnswer.Text = "Delete"; btnDeleteAnswer.CommandArgument = answer.Id.ToString(); btnDeleteAnswer.Click += new EventHandler(btnDeleteAnswer_Click); btnDeleteAnswer.CssClass += "hidden_delete_answer_btn"; answerDetailsCell.Controls.Add(btnDeleteAnswer); } answerDetailsRow.Cells.Add(answerDetailsCell); answerDetailsRow.BackColor = System.Drawing.ColorTranslator.FromHtml("#F2F2F2"); tblAnswers.Rows.Add(answerDetailsRow); TableRow answerRow = new TableRow(); TableCell answerCell = new TableCell(); answerCell.Text = answer.Text; answerRow.Cells.Add(answerCell); tblAnswers.Rows.Add(answerRow); TableRow dividerRow = new TableRow(); TableCell dividerCell = new TableCell(); dividerRow.Cells.Add(dividerCell); tblAnswers.Rows.Add(dividerRow); } } }
int editQuestionFromURL; // the questionID of the lesson to edit protected void Page_Load(object sender, EventArgs e) { // Get logged in user if (UserLogin.LoggedInUser != null) { // Logged in currentUser = UserLogin.LoggedInUser; if (currentUser.UserType == 1) { lblInfo.Text = currentUser.FirstName + " " + currentUser.Surname + ", you are logged in as a child."; btnAskQuestion.Enabled = true; } else if (currentUser.UserType == 2) { lblInfo.Text = currentUser.Title + " " + currentUser.Surname + ", you are logged in as a teacher."; btnAskQuestion.Text = "Log in as a child to ask questions"; } } else { // If not logged in lblInfo.Text = "You are not logged in."; // Hide the 'answerQuestion' div as user must be logged in to answer answerQuestion.Visible = false; } try { // Gets the 'questionID' from the URL if available, and passes it to the 'ShowEditQuestion' method editQuestionFromURL = int.Parse(Request.QueryString["editQuestionID"]); // Check to see if the page has posted back if (!Page.IsPostBack) { // Page hasn't posted back ShowEditQuestion(editQuestionFromURL); } } catch { } try { // Gets the 'questionID' from the URL if available, and passes it to the 'ShowQuestion' method questionIDFromURL = int.Parse(Request.QueryString["questionID"]); ShowQuestion(questionIDFromURL); } catch { } List <Question> questions = DatabaseWebService.ListAllQuestions(); foreach (var question in questions) { TableRow row = new TableRow(); // This button has the question title and uses the 'btnViewQuestion' event TableCell title = new TableCell(); Button btnViewQuestion = new Button(); btnViewQuestion.Text = question.Title; btnViewQuestion.CommandArgument = question.Id.ToString(); btnViewQuestion.Click += new EventHandler(btnViewQuestion_Click); btnViewQuestion.CssClass += "hidden_btn"; title.Controls.Add(btnViewQuestion); if (currentUser != null && currentUser.UserType == 2) { // If logged in user is a teacher // This button is for editing a question and uses the 'btnEditQuestion' event Button btnEditLesson = new Button(); btnEditLesson.Text = "Edit"; btnEditLesson.CommandArgument = question.Id.ToString(); btnEditLesson.Click += new EventHandler(btnEditQuestion_Click); btnEditLesson.CssClass += "hidden_edit_btn"; title.Controls.Add(btnEditLesson); // This button is for deleting a question and uses the 'btnDeleteQuestion' event Button btnDeleteLesson = new Button(); btnDeleteLesson.Text = "Delete"; btnDeleteLesson.CommandArgument = question.Id.ToString(); btnDeleteLesson.Click += new EventHandler(btnDeleteQuestion_Click); btnDeleteLesson.CssClass += "hidden_delete_btn"; title.Controls.Add(btnDeleteLesson); } row.Cells.Add(title); TableCell asker = new TableCell(); asker.Text = question.QuestionUser.FirstName + " " + question.QuestionUser.Surname; row.Cells.Add(asker); TableCell topic = new TableCell(); topic.Text = question.QuestionLesson.LessonTopic.Name; row.Cells.Add(topic); TableCell date = new TableCell(); date.Text = question.Date; row.Cells.Add(date); tblQuestions.Rows.Add(row); } }