private bool DeleteItem() { bool success = false; try { SPA.TrngAnswer item = new SPA.TrngAnswer(ItemID); int answerID = item.ID; string answer = item.Answer; if (item.Delete()) { Action.Write(string.Format("Deleted Answer ID: {0}, Answer: {1}", answerID, answer), CurrentUser.DisplayName); success = true; ItemID = 0; } else { // display message that item is im use } } catch (Exception ex) { SPA.Error.WriteError(ex); if (ShowDebug) { lblErrorMessage.Text = ex.ToString(); } } return(success); }
private bool DeleteItem() { bool success = false; try { SPA.TrngAnswer item = new SPA.TrngAnswer(ItemID); if (item.Delete()) { success = true; ItemID = 0; } else { // display message that item is im use } } catch (Exception ex) { SPA.Error.WriteError(ex); if (ShowDebug) { lblErrorMessage.Text = ex.ToString(); } } return(success); }
//This is the GridView of all the items in the Table protected override void Fill() { try { if (IView == ItemView.List) { // set table visibility tblItem.Visible = false; tblList.Visible = true; // set ribbon visibility tdNew.Visible = true; tdSave.Visible = false; tdDelete.Visible = false; tdView.Visible = false; tdEdit.Visible = false; btnCancel.Text = "Close"; // bind answers to list gvData.EmptyDataText = Message.EMPTY_LIST; DataView dv = new DataView(SPA.TrngAnswer.Items(QuestionID).Tables[0]); gvData.DataSource = dv; gvData.DataBind(); } else { // set table visibility tblList.Visible = false; tblItem.Visible = true; // set ribbon visibility bool isView = (IView == ItemView.View); bool isNew = (IView == ItemView.New); tdEdit.Visible = isView; tdView.Visible = !isView && ItemID != 0; tdDelete.Visible = !isView && ItemID != 0; tdSave.Visible = !isView; btnSave.Visible = !isView; btnCancel.Text = isView ? "Close" : "Cancel"; // bind data TrngAnswer item = new SPA.TrngAnswer(ItemID); txtAnswer.Text = item.Answer; txtAnswer.Visible = !isView; lblAnswerView.Text = item.Answer; lblAnswerView.Visible = isView; lblAnswerRequired.Visible = !isView; ckbxIsCorrect.Checked = item.IsCorrect; ckbxIsCorrect.Visible = !isView; lblIsCorrectView.Text = item.IsCorrect ? "Yes" : "No"; lblIsCorrectView.Visible = isView; lblCreatedInfo.Text = string.Format("Created at {0} by {1}", SPA.Common.ConvertUTCToWebLocalTime(this.Web, item.CreatedOn), item.CreatedBy); lblCreatedInfo.Visible = (item.ID != 0); lblUpdatedInfo.Text = string.Format("Last modified at {0} by {1}", SPA.Common.ConvertUTCToWebLocalTime(this.Web, item.ModifiedOn), item.ModifiedBy); lblUpdatedInfo.Visible = (item.ID != 0); //Action.Write(string.Format("Opened SlideAnswers [AnswerID: {0}]", ItemID), CurrentUser.DisplayName); } } catch (Exception ex) { SPA.Error.WriteError(ex); if (ShowDebug) { lblErrorMessage.Text = ex.ToString(); } } }
protected void btnNext_Click(object sender, EventArgs e) { try { bool bContinue = true; lblWrong.Visible = false; TrngCourse course = new TrngCourse(CourseID); if (!rbtnlAnswers.SelectedValue.IsNullOrWhiteSpace()) { // answer selected SPA.TrngAnswer answer = new SPA.TrngAnswer(int.Parse(rbtnlAnswers.SelectedValue.ToString())); if (answer.IsCorrect) { // add 1 to correct answer count Session["QuestionsCorrect"] = int.Parse(Session["QuestionsCorrect"].ToString()) + 1; //lblErrorMessage.Text = "Correct Answers: " + Session["QuestionsCorrect"].ToString(); bContinue = true; } else { // do not add 1 to correct answer count //lblErrorMessage.Text = "Correct Answers: " + Session["QuestionsCorrect"].ToString(); if (course.IsGraded) { bContinue = true; } else { bContinue = false; lblWrong.Text = "Answer Wrong! Try Again!<br>"; lblWrong.Visible = true; } } } else if (rbtnlAnswers.SelectedIndex == -1 && trQuestion.Visible) { bContinue = false; lblWrong.Visible = true; lblWrong.Text = "You Must Select an Answer! Try Again!<br>"; } if (btnNext.Text == "Finish" && bContinue) // on last step { btnNext.Visible = false; btnPrevious.Visible = false; trContent.Visible = false; trQuestion.Visible = false; trFinished.Visible = true; TrngRecord userRecord = new TrngRecord(CourseID, CurrentUser.ID); string courseDuration = BuildDurationString(DateTime.Now); userRecord.CourseName = course.Name; userRecord.CourseDescription = course.Description; userRecord.CourseCode = course.Code; userRecord.DateCompleted = DateTime.Now; userRecord.TimeToComplete = courseDuration; // if course graded, check score for passing bool completeCourse = true; //lblErrorMessage.Text = "Finish - Correct Answers: " + Session["QuestionsCorrect"].ToString() + " Course Graded: " + course.IsGraded.ToString(); if (course.IsGraded) { int questionCorrect = int.Parse(Session["QuestionsCorrect"].ToString()); int minimumScore = course.MinimumScore; int questionCount = TrngCourse.QuestionCount(course.ID); double score = (double)questionCorrect / questionCount * 100; //lblErrorMessage.Text += string.Format("</br> Correct: {0}, Minimum Score: {1}, Total Questions: {2}, Score: {3}", questionCorrect, minimumScore, questionCount, score); if (score < minimumScore) { completeCourse = false; Action.Write(string.Format("<font color='red'>Score of {0} <b>failed to meet minimum score</b> of {1} for {2}</font>", score, minimumScore, course.Name), CurrentUser.DisplayName); lblFinished.Text = string.Format("You failed to meet the minimum score and will need to reaccomplish the course!</br>Your score was {0}% and the minimum score to pass is {1}%</br></br>Select Close to return to your training record.", score, minimumScore); btnClose.Visible = true; btnNext.Visible = false; btnPrevious.Visible = false; } } if (completeCourse) { if (userRecord.ID != 0) { userRecord.ModifiedBy = CurrentUser.DisplayName; if (userRecord.Update()) { Action.Write(string.Format("Completed Course: {0}", course.Name), CurrentUser.DisplayName); lblFinished.Text = "Course completed and updated successfully!</br></br>Select Close to return to your training record."; btnClose.Visible = true; btnNext.Visible = false; btnPrevious.Visible = false; } else { // record failure and send email to admins to investigate Action.Write(string.Format("Course Failed to Finish: {0}", course.Name), CurrentUser.DisplayName); lblFinished.Text = "Course completion failed to update successfully!</br></br>The failure has been reported to the application administrators"; btnClose.Visible = true; btnNext.Visible = false; btnPrevious.Visible = false; } } else { userRecord.CourseID = course.ID; userRecord.UserID = CurrentUser.ID; userRecord.CreatedBy = CurrentUser.DisplayName; userRecord.ModifiedBy = CurrentUser.DisplayName; if (userRecord.Insert()) { Action.Write(string.Format("Completed Course: {0}", course.Name), CurrentUser.DisplayName); lblFinished.Text = "Course completed and assigned successfully!</br></br>Select Close to return to your training record."; btnClose.Visible = true; btnNext.Visible = false; btnPrevious.Visible = false; } else { // record failure and send email to admins to investigate Action.Write(string.Format("Course Failed to Finish: {0}", course.Name), CurrentUser.DisplayName); lblFinished.Text = "Course failed to assign successfully!</br></br>The failure has been reported to the application administrators"; btnClose.Visible = true; btnNext.Visible = false; btnPrevious.Visible = false; } } } } else { if (bContinue) { SlideNumber++; BuildSlide(CourseID, SlideNumber); } } if (course.IsGraded) { btnPrevious.Enabled = false; } } catch (Exception ex) { SPA.Error.WriteError(ex); if (ShowDebug) { lblErrorMessage.Text = ex.ToString(); } } }