public void FetchAllQuestions() { List <QuestionsClass> QuestionsList = new List <QuestionsClass>(); using (SqlCommand cmd = new SqlCommand("FetchAllQuestions", db.DbConnect())) { cmd.CommandType = CommandType.StoredProcedure; SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { QuestionsClass questions = new QuestionsClass(); questions.DepartmentName = questions.FetchDeptById(Convert.ToInt16(rdr["dept_id"].ToString())); questions.SemId = Convert.ToInt16(rdr["sem_id"].ToString()); questions.SubjectName = questions.FetchSubjectById(Convert.ToInt16(rdr["subject_id"].ToString())); questions.QuestionType = questions.DetermineQuestionType(Convert.ToInt16(rdr["question_type"].ToString())); questions.Question = rdr["question"].ToString(); questions.OptionA = rdr["opt_a"].ToString(); questions.OptionB = rdr["opt_b"].ToString(); questions.OptionC = rdr["opt_c"].ToString(); questions.OptionD = rdr["opt_d"].ToString(); questions.CorrectAns = rdr["correct_ans"].ToString(); questions.Marks = Convert.ToInt16(rdr["marks"].ToString()); QuestionsList.Add(questions); } } JavaScriptSerializer js = new JavaScriptSerializer(); Context.Response.Write(js.Serialize(QuestionsList)); }
public void SaveQuestionsData() { // checking whether the feilds are filled bool FilledChecked = CheckAnswerNotNull(); //if all feilds are filled if (FilledChecked) { string path = Application.persistentDataPath + "/QuestionsAnswersData.dat"; // File.Delete(path); if (!File.Exists(path)) { CreateNewQuestionAnswerFile(); } else { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/QuestionsAnswersData.dat", FileMode.Open); Debug.Log(Application.persistentDataPath); //check if the Question ID redundunt //append new questions file.Seek(0, SeekOrigin.Begin); while (file.Position != file.Length) { QuestionsClass data = (QuestionsClass)bf.Deserialize(file); if (data.QuestionId == int.Parse(questionId.text)) { Debug.Log("The questionId: " + data.QuestionId + "" + data.Question + "with answer: " + data.Answer + "is Already exist"); isRedundant = true; file.Close(); break; } } if (isRedundant == false) { file.Close(); AppendNewDataToQuestionFile(); } } } //if there is empty feild else { Debug.Log("The three feilds needed to be filled!"); } }
private string LoadFirstQuestion() { string Questionpath = Application.persistentDataPath + "/QuestionsAnswersData.dat"; BinaryFormatter qbf = new BinaryFormatter(); FileStream qfile = File.Open( Questionpath, FileMode.Open); qfile.Seek(0, SeekOrigin.Begin); QuestionsClass qdata = (QuestionsClass)qbf.Deserialize(qfile); qfile.Close(); return(qdata.Answer); }
public void LoadNextQuestion(int previousQAns) { //add one to the previous question ID previousQAns += 1; string Questionpath = Application.persistentDataPath + "/QuestionsAnswersData.dat"; BinaryFormatter qbf = new BinaryFormatter(); FileStream qfile = File.Open( Questionpath, FileMode.Open); // find the last question user answered //Move it to the begining of the file qfile.Seek(0, SeekOrigin.Begin); while (qfile.Position != qfile.Length) { QuestionsClass qdata = (QuestionsClass)qbf.Deserialize(qfile); if (qdata.QuestionId == previousQAns) { user_question_ID_answered = previousQAns; question_to_be_asked.text = qdata.Question; List <string> shuffle = qdata.PossibleAnswers.ToList(); shuffle.Add(qdata.Answer); //Shuffle the answers var shuffledAnswers = shuffle.OrderBy(a => Guid.NewGuid()); List <string> items = shuffledAnswers.OrderBy(item => item).ToList(); First_Answer.text = items[0].ToString(); Second_Answer.text = items[1].ToString(); Third_Answer.text = items[2].ToString(); Fourths_Answer.text = items[3].ToString(); Debug.Log(health + "last student question: " + user_question_ID_answered); qfile.Close(); } } }
private void AppendNewDataToQuestionFile() { BinaryFormatter bfAppend = new BinaryFormatter(); FileStream bAppendfile = File.Open(Application.persistentDataPath + "/QuestionsAnswersData.dat", FileMode.Append); //FileStream appendFile = File.Open(Application.persistentDataPath // + "/QuestionsAnswersData.dat", FileMode.Append); //write data to file QuestionsClass data = new QuestionsClass(); data.QuestionId = int.Parse(questionId.text); data.Question = question.text; data.Answer = answer.text; data.PossibleAnswers.Add(Possible_Answer1.text); data.PossibleAnswers.Add(Possible_Answer2.text); data.PossibleAnswers.Add(Possible_Answer3.text); bfAppend.Serialize(bAppendfile, data); bAppendfile.Close(); Debug.Log("Data appended"); SceneManager.LoadScene("SaveQuestionAnsweDataSucess"); }
private void CreateNewQuestionAnswerFile() { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + "/QuestionsAnswersData.dat"); Debug.Log(Application.persistentDataPath); QuestionsClass data = new QuestionsClass(); data.QuestionId = int.Parse(questionId.text); data.Question = question.text; data.Answer = answer.text; data.PossibleAnswers.Add(Possible_Answer1.text); data.PossibleAnswers.Add(Possible_Answer2.text); data.PossibleAnswers.Add(Possible_Answer3.text); //write data to file bf.Serialize(file, data); file.Close(); Debug.Log("File is created and data saved"); SceneManager.LoadScene("SaveQuestionAnsweDataSucess"); }
public void Load() { string path = Application.persistentDataPath + "/playerLevelInfo.dat"; //File.Delete(path); //if student file already exist if (File.Exists(path)) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open( Application.persistentDataPath + "/playerLevelInfo.dat", FileMode.Open); while (file.Position != file.Length) { Level lData = (Level)bf.Deserialize(file); if (lData.StudentId == UserInputCheck.User_ID_All_Level) { // assign data from file to temporary feilds health = lData.LevelScore; user_question_ID_answered = lData.QuestionId; //question, answer, Debug.Log(health + "last student question: " + user_question_ID_answered); } } file.Close(); // Open File contain questions and answers string Questionpath = Application.persistentDataPath + "/QuestionsAnswersData.dat"; if (File.Exists(Questionpath)) { /* BinaryFormatter qbf = new BinaryFormatter(); * FileStream qfile = File.Open( * Questionpath, FileMode.Open); * // find the last question user answered * //Move it to the begining of the file * * qfile.Seek(0, SeekOrigin.Begin); * while (qfile.Position != qfile.Length) * { * QuestionsClass qdata = (QuestionsClass)bf.Deserialize(qfile); * * if (qdata.QuestionId == user_question_ID_answered) * { * tempQuestionId =qdata.QuestionId + 1; * question_to_be_asked.text = qdata.Question; * List<string> shuffle = qdata.PossibleAnswers.ToList(); * shuffle.Add(qdata.Answer); * //Shuffle the answers * var shuffledAnswers = shuffle.OrderBy(a => Guid.NewGuid()); * * List<string> items = shuffledAnswers.OrderBy(item => item).ToList(); * * First_Answer.text = items[0].ToString(); * Second_Answer.text = items[1].ToString(); * Third_Answer.text = items[2].ToString(); * Fourths_Answer.text = items[3].ToString(); * Debug.Log(health + "last student question: " + * user_question_ID_answered); * qfile.Close(); */ // Find the next question to be assigned to user LoadNextQuestion(user_question_ID_answered); } } else { string Questionpath = Application.persistentDataPath + "/QuestionsAnswersData.dat"; BinaryFormatter qbf = new BinaryFormatter(); FileStream qfile = File.Open( Questionpath, FileMode.Open); QuestionsClass qdata = (QuestionsClass)qbf.Deserialize(qfile); user_question_ID_answered = 1; question_to_be_asked.text = qdata.Question; List <string> shuffle = qdata.PossibleAnswers.ToList(); shuffle.Add(qdata.Answer); //Shuffle the answers var shuffledAnswers = shuffle.OrderBy(a => Guid.NewGuid()); List <string> items = shuffledAnswers.OrderBy(item => item).ToList(); First_Answer.text = items[0].ToString(); Second_Answer.text = items[1].ToString(); Third_Answer.text = items[2].ToString(); Fourths_Answer.text = items[3].ToString(); qfile.Close(); User_ID = UserInputCheck.User_ID_All_Level; } }