public void TestInit() { surveydb = Database.GetConnection(); surveyDal = new SurveyDAL(); userDAL = new UserDAL(); questionDAL = new QuestionDAL(); user = new users(); user.User_name = userName; user.User_password = password; HelperDAL.AddUser(user); survey = new surveys(); survey.Name = surveyName; //survey.users = user; survey.User_name = userName; SurveyCode = HelperDAL.GenerateRandomSurveyCode(); survey.Survey_code = SurveyCode; HelperDAL.AddSurvey(survey); question = new questions(); question.Question_name = questionName; question.Surveys_id = survey.Id; question.Input_type_id = 2; this.questionDAL.AddQuestion(question); this.optionChoicesDAL = new OptionChoicesDAL(); this.optionChoice = new option_choices(); this.optionChoice.Question_id = question.Id; this.optionChoice.Option_choices_name = OptionChoiceName; }
public ActionResult search_question(string search_text) { category(); questions q_list = new questions(); string connStr = ConfigurationManager.ConnectionStrings["QBDDBContex"].ConnectionString; SqlConnection con = new SqlConnection(connStr); SqlCommand cmd = con.CreateCommand(); cmd.CommandText = "SELECT question.QuestionID,question.Question,question.answer_count,question.follow,users.Name FROM question inner join users on question.UserID = users.UserID and Question LIKE '%" + search_text + "%'"; con.Open(); SqlDataReader sdr = cmd.ExecuteReader(); List <questions> d_questions_list = new List <questions>(); if (sdr.HasRows) { while (sdr.Read()) { var questions_list = new questions(); questions_list.QuestionID = sdr["QuestionID"].ToString(); questions_list.Question = sdr["Question"].ToString(); questions_list.answer_count = sdr["answer_count"].ToString(); questions_list.follow = sdr["follow"].ToString(); questions_list.userName = sdr["Name"].ToString(); d_questions_list.Add(questions_list); } q_list.questions_list = d_questions_list; con.Close(); } return(View(q_list)); }
public ActionResult Index(string id) { questions q_list = new questions(); category(); string connStr = ConfigurationManager.ConnectionStrings["QBDDBContex"].ConnectionString; SqlConnection con = new SqlConnection(connStr); SqlCommand cmd = new SqlCommand("select question.QuestionID,question.Question,question.answer_count,question.follow ,users.Name from question inner join users on question.UserID=users.UserID"); cmd.Connection = con; con.Open(); SqlDataReader sdr = cmd.ExecuteReader(); List <questions> d_questions_list = new List <questions>(); if (sdr.HasRows) { while (sdr.Read()) { var questions_list = new questions(); questions_list.QuestionID = sdr["QuestionID"].ToString(); questions_list.Question = sdr["Question"].ToString(); questions_list.answer_count = sdr["answer_count"].ToString(); questions_list.follow = sdr["follow"].ToString(); questions_list.userName = sdr["Name"].ToString(); d_questions_list.Add(questions_list); } q_list.questions_list = d_questions_list; } con.Close(); return(View(q_list)); }
public void DeleteQuestion(questions question) { if (inputTypeDAL.GetInputTypeName(question) == "text") { List <text_answers> texts = textAswersDAL.GetTextAnswers(question); foreach (var text in texts) { textAswersDAL.DeleteTextAnswer(text); } questionDAL.DeleteQuestion(question); } else { List <option_choices> options = optionChoiceDAL.GetOptionsChoices(question); foreach (var option in options) { List <answers> answers = answerDAL.GetAnswers(option.Id); foreach (var answer in answers) { answerDAL.DeleteAnswer(answer); } optionChoiceDAL.DeleteOptionChoice(option); } questionDAL.DeleteQuestion(question); } }
//For Questionniare Model public List <questions> Questionniare() { List <questions> listid = new List <questions>(); string strcon = ConfigurationManager.ConnectionStrings["Dbconnection"].ConnectionString; SqlConnection conn = new SqlConnection(strcon); string queryString = " select * from QuestionsTable"; conn.Open(); SqlCommand cmd = new SqlCommand(queryString, conn); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { questions question = new questions(); question.QuestionId = Convert.ToInt32(dr["QuestionId"]); question.Questions = dr["Questions"].ToString(); question.OptionA = dr["OptionA"].ToString(); question.OptionB = dr["OptionB"].ToString(); question.OptionC = dr["OptionC"].ToString(); question.OptionD = dr["OptionD"].ToString(); question.OptionE = dr["OptionE"].ToString(); question.Correct_Answer = dr["Correct_Answer"].ToString(); listid.Add(question); } return(listid); }
public IHttpActionResult Putquestions(int id, questions questions) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != questions.id_question) { return(BadRequest()); } db.Entry(questions).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!questionsExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void TestInit() { surveydb = Database.GetConnection(); surveyDal = new SurveyDAL(); userDAL = new UserDAL(); questionDAL = new QuestionDAL(); user = new users(); user.User_name = userName; user.User_password = password; HelperDAL.AddUser(user); survey = new surveys(); survey.Name = surveyName; //survey.users = user; survey.User_name = userName; SurveyCode = HelperDAL.GenerateRandomSurveyCode(); survey.Survey_code = SurveyCode; HelperDAL.AddSurvey(survey); question = new questions(); question.Question_name = questionName; question.Surveys_id = survey.Id; question.Input_type_id = 1; this.questionDAL.AddQuestion(question); this.textAnswerDAL = new TextAnswerDAL(); this.textAnswer = new text_answers(); this.textAnswer.User_name = userName; this.textAnswer.Question_id = question.Id; this.textAnswer.Answer = TextAnswerText; }
public ActionResult DeleteConfirmed(int id) { questions questions = db.Question.Find(id); db.Question.Remove(questions); db.SaveChanges(); return(RedirectToAction("Index")); }
public void DataBaseShouldReturnQuestion() { this.questionDAL.AddQuestion(question); questions question2 = this.questionDAL.GetQuestion(question.Id); this.questionDAL.DeleteQuestion(question); Assert.That(question, Is.EqualTo(question2)); }
public static void AddQuestionsToDataBase(questions question) { for (int i = 1; i <= 3; i++) { question.Question_name += i; questionDAL.AddQuestion(question); } }
public void QestionNameShouldBeUpdated() { this.questionDAL.AddQuestion(question); this.questionDAL.UpdateQuestion(this.question, newQuestionName); questions question2 = this.questionDAL.GetQuestion(this.question.Id); this.questionDAL.DeleteQuestion(question); Assert.AreEqual(question2.Question_name, newQuestionName); }
void interf(questions que) //Интерфейс вопроса { richTextBoxQue.Text = que.question; radioButtonAns1.Text = que.answer1; radioButtonAns2.Text = que.answer2; radioButtonAns3.Text = que.answer3; radioButtonAns4.Text = que.answer4; radioButtonAns1.Checked = true; }
public static void DeleteOptionChoicesFromDataBase(questions question) { List <option_choices> optionChoice = optionChoicesDAL.GetOptionsChoices(question); foreach (var item in optionChoice) { optionChoicesDAL.DeleteOptionChoice(item); } }
public static void DeleteTextAnswersFromDataBase(questions question) { List <text_answers> text_Answers = txtan.GetTextAnswers(question); foreach (var item in text_Answers) { txtan.DeleteTextAnswer(item); } }
public ActionResult Edit([Bind(Include = "questionID,question,answer,programID")] questions questions) { if (ModelState.IsValid) { db.Entry(questions).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(questions)); }
//This is the handle adding new questions to the model // GET: questions/Create public ActionResult Create(int progid, int questionid) { int iNumQuestion = questionid + 1; int iNumProgram = progid; db.Database.ExecuteSqlCommand("INSERT INTO questions (questionID, programID) VALUES (" + iNumQuestion + ", " + progid + ")"); questions newquestion = db.Database.SqlQuery <questions>("SELECT questionID, question, answer, programID FROM questions WHERE questionID = " + iNumQuestion + " AND programID = " + iNumProgram + "").FirstOrDefault(); return(View(newquestion)); }
public ActionResult Edit([Bind(Include = "questionID,question,answer,programID")] questions questions) { if (ModelState.IsValid) { //string anwser = Request.Form("answer"); db.Entry(questions).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("FandQ/" + questions.programID)); } return(View(questions)); }
public ActionResult Create([Bind(Include = "questionID,question,answer,programID")] questions questions) { if (ModelState.IsValid) { db.Question.Add(questions); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(questions)); }
public ActionResult Create([Bind(Include = "answer,programID,question,questionID")] questions questions) { if (ModelState.IsValid) { db.Question.Add(questions); db.Database.ExecuteSqlCommand("INSERT INTO questions (questionID, question, answer, programID) VALUES (" + questions.questionID + ", '" + questions.question + "', '" + questions.answer + "', " + questions.programID + ")"); db.SaveChanges(); return(RedirectToAction("FandQ/" + questions.programID)); } return(View(questions)); }
public IHttpActionResult Postquestions(questions questions) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.questions.Add(questions); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = questions.id_question }, questions)); }
/// <summary> /// Take all the questions created by the user and add the survey to the database /// </summary> private void buttonCreateSurvey_Click(object sender, EventArgs e) { //Check if the previous question or title has the correct inputs if (CheckInputs()) { return; } //If there are 0 questions the survey won't be created if (question_text_counter + question_option_counter == 0) { MessageBox.Show("Please create atleast one question."); return; } //Create the survey and add it to the database CreateSurvey(); b.AddSurvey(survey); //For each question, the 'for'cycle adds it to the database for (int i = 1; i < question_text_counter + question_option_counter + 1; i++) { questions question = new questions(); TextBox title = panelCreateSurvey.Controls.Find(i + "title", false).First() as TextBox; //If the question is a text answer, add it to the database if (title.Tag.ToString() == "text") { question.Surveys_id = b.GetSurveyIdBySurveyCode(survey.Survey_code); question.Question_name = title.Text; question.Input_type_id = 1; b.AddQuestion(question); } //If the question is a option choice, add it to the database along with its options else { question.Surveys_id = b.GetSurveyIdBySurveyCode(survey.Survey_code); question.Question_name = title.Text; question.Input_type_id = 2; b.AddQuestion(question); //Add the options to the database for (int j = 1; j < 4; j++) { option_choices option = new option_choices(); TextBox optionChoice = panelCreateSurvey.Controls.Find(i + "option" + j, false).First() as TextBox; option.Question_id = question.Id; option.Option_choices_name = optionChoice.Text; b.AddOptionChoice(option); } } } MessageBox.Show("Survey succesfully created!"); //Clear the panel ClearPanelCreateSurvey(); }
// GET: questions/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } questions questions = db.Question.Find(id); if (questions == null) { return(HttpNotFound()); } return(View(questions)); }
public IHttpActionResult Deletequestions(int id) { questions questions = db.questions.Find(id); if (questions == null) { return(NotFound()); } db.questions.Remove(questions); db.SaveChanges(); return(Ok(questions)); }
/// <summary> /// Checks if an option choice question has got any answers /// </summary> private bool HasAnswer(questions question, List <answers> answers) { List <option_choices> options = b.GetOptionsChoices(question); //If any of the answers has the same question option id as the questions options, that means that there is an answer foreach (var answer in answers) { if (answer.Question_option_id == options.ElementAt(0).Id || answer.Question_option_id == options.ElementAt(1).Id || answer.Question_option_id == options.ElementAt(2).Id) { return(true); } } return(false); }
private async void Testing() { test = await QD.GetItemsAsync(1); //MainListView.ItemsSource =await Data; Question.Text = test.Question; OptionA.Text = test.OptionA; OptionB.Text = test.OptionB; OptionC.Text = test.OptionC; OptionD.Text = test.OptionD; await DisplayAlert("MockTest", "Ready when you are...", "Start Test"); MainLayout.IsVisible = true; watch.Start(); await MainProgressBar.ProgressTo(1, 100000, Easing.Linear); }
private void loadTestButton_Click(object sender, EventArgs e) { string[] str = File.ReadAllLines("E:\\test.txt"); List <string> que1 = new List <string>(), ans1 = new List <string>(), ans2 = new List <string>(), ans3 = new List <string>(), ans4 = new List <string>(), rA = new List <string>(); foreach (string st in str) //Заполнение списка вопросов { if (st.IndexOf("que") == 0) { que1.Add(st.TrimStart(new char[] { 'q', 'u', 'e' })); } if (st.IndexOf("ans1") == 0) { ans1.Add(st.TrimStart(new char[] { 'a', 'n', 's', '1' })); } if (st.IndexOf("ans2") == 0) { ans2.Add(st.TrimStart(new char[] { 'a', 'n', 's', '2' })); } if (st.IndexOf("ans3") == 0) { ans3.Add(st.TrimStart(new char[] { 'a', 'n', 's', '3' })); } if (st.IndexOf("ans4") == 0) { ans4.Add(st.TrimStart(new char[] { 'a', 'n', 's', '4' })); } if (st.IndexOf("ra") == 0) { rA.Add(st.TrimStart(new char[] { 'r', 'a' })); } } que = new questions[que1.Count]; for (int i = 0; i < que1.Count; i++) //Заполнение класса вопроса { que[i] = new questions(que1[i], ans1[i], ans2[i], ans3[i], ans4[i], rA[i]); } interf(que[0]); enterAnsButton.Enabled = true; loadTestButton.Enabled = false; radioButtonAns1.Checked = true; }
private async void LoadNext() { test = await QD.GetItemsAsync(++i); await Task.Delay(500); Question.Text = test.Question; OptionA.Text = test.OptionA; OptionB.Text = test.OptionB; OptionC.Text = test.OptionC; OptionD.Text = test.OptionD; OptionAFrame.BackgroundColor = Color.Peru; OptionBFrame.BackgroundColor = Color.Peru; OptionCFrame.BackgroundColor = Color.Peru; OptionDFrame.BackgroundColor = Color.Peru; await Task.Delay(300); }
private async void LoadNext() { test = await QD.GetItemsAsync(++i); await Task.Delay(500); PlainView("csat" + paper + "/que" + i + ".html"); OptionA.Text = test.OptionA; OptionB.Text = test.OptionB; OptionC.Text = test.OptionC; OptionD.Text = test.OptionD; OptionAFrame.BackgroundColor = Color.Peru; OptionBFrame.BackgroundColor = Color.Peru; OptionCFrame.BackgroundColor = Color.Peru; OptionDFrame.BackgroundColor = Color.Peru; await Task.Delay(300); }
public IHttpActionResult Getquestions(int id) { questions questions = db.questions.Find(id); questionViewModel qvm = new questionViewModel(); if (questions == null) { return(NotFound()); } else { qvm.id_question = questions.id_question; qvm.idGestionnaire = questions.idGestionnaire; qvm.label = questions.label; return(Ok(qvm)); } }
public ActionResult followed_question(string userID) { if (!String.IsNullOrEmpty(userID)) { var key = "b14ca5898a4e4133bbce2ea2315a1916"; userID = DecryptString(key, userID); questions q_list = new questions(); category(); string connStr = ConfigurationManager.ConnectionStrings["QBDDBContex"].ConnectionString; SqlConnection con = new SqlConnection(connStr); SqlCommand cmd = new SqlCommand("select question.QuestionID,question.Question,question.answer_count,question.follow ,users.Name from question inner join save_question on question.QuestionID = save_question.QuestionID and save_question.UserID = @UserID inner join users on users.UserID = @UserID"); cmd.Parameters.Add("@UserID", SqlDbType.VarChar).Value = userID; cmd.Connection = con; con.Open(); SqlDataReader sdr = cmd.ExecuteReader(); List <questions> questions_list = new List <questions>(); if (sdr.HasRows) { while (sdr.Read()) { var questions = new questions(); questions.QuestionID = sdr["QuestionID"].ToString(); questions.Question = sdr["Question"].ToString(); questions.answer_count = sdr["answer_count"].ToString(); questions.follow = sdr["follow"].ToString(); questions.userName = sdr["Name"].ToString(); questions_list.Add(questions); } q_list.questions_list = questions_list; con.Close(); } return(View(q_list)); } return(RedirectToAction("Index", "Home")); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { type = Request.QueryString["type"]; string usid = Request.QueryString["id"]; userid = Convert.ToInt16(usid); //user(); bool pb = true; btn2.Visible = false; int x = 0; timerVar = 1; tpoints = "na"; ecPoints = "na"; ethPoints = "na"; pPoints = "na"; gr = 0; right.LoadXml("<test></test>"); wrong.LoadXml("<test></test>"); //Laddar in vårat xmldokument i xmldoc if (type == "a") { xmldoc.Load(Server.MapPath("/XmlLicenseTest.xml")); x = 25; testType = 1; } else { xmldoc.Load(Server.MapPath("/XmlUpdateTest.xml")); x = 15; testType = 0; } //Laddar endast in taggar i xmldoc2 som är identiska med XmlQuestions.xml xmldoc2.LoadXml("<categories></categories>"); //Skapar ny array och stoppar in variabler av typen int(minsta värde, högsta värde) int[] arrayQuestions = RandomNumbers(1, x, 4); //Hämtar frågor från orginaldokumentet och stoppar in detta i det nya foreach (int i in arrayQuestions) { XmlNode newnode = xmldoc2.ImportNode(xmldoc.SelectSingleNode("/categories/question[@id='" + i + "']"), false); string text = xmldoc.SelectSingleNode("/categories/question[@id='" + i + "']").FirstChild.InnerText; XmlNode parent = xmldoc2.SelectSingleNode("categories"); parent.AppendChild(newnode); parent = xmldoc2.SelectSingleNode("/categories/question[@id='" + i + "']"); XmlText txt = xmldoc2.CreateTextNode(text); parent.AppendChild(txt); XmlElement newel = xmldoc2.CreateElement("answer"); parent.AppendChild(newel); XmlNode tst = xmldoc2.SelectSingleNode("/categories/question[@id='" + i + "']"); string img = tst.Attributes["image"].Value; if (img == "true") { XmlNode newnode2 = xmldoc2.ImportNode(xmldoc.SelectSingleNode("/categories/question[@id='" + i + "']/image"), true); parent.AppendChild(newnode2); } newel = xmldoc2.CreateElement("useranswer"); parent.AppendChild(newel); //skicka arrayen vidare int[] arrayAnswers = RandomNumbers(1, 4, 2); questions q = new questions(); q.setId(i); q.setArr(arrayAnswers); listq.Add(q); ViewState.Add("questions", listq); foreach (int ix in arrayAnswers) { XmlNode newnode2 = xmldoc2.ImportNode(xmldoc.SelectSingleNode("/categories/question[@id='" + i + "']/answer/answer[@id='" + ix + "']"), true); XmlNode parent2 = xmldoc2.SelectSingleNode("categories/question[@id='" + i + "']/answer"); parent2.AppendChild(newnode2); } xmldoc2.Save(Server.MapPath("usertest.xml")); } //Lägger in alla question nodes i en XML lista XmlNodeList lst = xmldoc2.SelectNodes("categories/question"); //Loopar igenom xml listan 1st int count = 1; foreach (XmlNode node in lst) { string attributeID = node.Attributes["id"].Value; string attributeMulti = node.Attributes["multi"].Value; string img = node.Attributes["image"].Value; int i = Convert.ToInt16(attributeID); loadQuest(attributeID, attributeMulti, img, count, listq, pb); count++; xmldoc2.Save(Server.MapPath("usertest.xml")); } } else if (IsPostBack) { if (ViewState["points"] != null) { string s = (string)ViewState["points"]; tpoints = s; } if (ViewState["grade"] != null) { int a = (int)ViewState["grade"]; gr = a; } if (ViewState["pP"] != null) { pPoints = (string)ViewState["pP"]; } if(ViewState["ecP"] != null) { ecPoints = (string)ViewState["ecP"]; } if(ViewState["ehP"] != null) { ethPoints = (string)ViewState["ehP"]; } bool pb = false; List<questions> lista = new List<questions>(); ; timerVar = 2; btn1.Visible = false; btn2.Visible = true; xmldoc2.Load(Server.MapPath("usertest.xml")); XmlNodeList lst = xmldoc2.SelectNodes("categories/question"); //Loopar igenom xml listan 1st int count = 1; if (ViewState["questions"] != null) { lista = (List<questions>)ViewState["questions"]; } foreach (XmlNode node in lst) { string attributeID = node.Attributes["id"].Value; string attributeMulti = node.Attributes["multi"].Value; string img = node.Attributes["image"].Value; int i = Convert.ToInt16(attributeID); loadQuest(attributeID, attributeMulti, img, count, lista, pb); count++; } } }