public List <TB_Votation_Questions_Answer> getQuestionAnswer(OleDbConnection db, int idQuestion) { DataSet ds = new DataSet(); try { OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM TB_Votation_Questions_Answer WHERE QuestionId = " + idQuestion, db); da.Fill(ds); db.Close(); DataTable dt = ds.Tables[0]; foreach (DataRow rows in dt.Rows) { TB_Votation_Questions_Answer answer = new TB_Votation_Questions_Answer( int.Parse(rows["Id"].ToString()), int.Parse(rows["QuestionId"].ToString()), rows["Answer"].ToString()); lstanswer.Add(answer); } } catch (Exception) { throw; } return(lstanswer); }
public string insertAnswer(TB_Votation_Questions_Answer tva, OleDbConnection db) { string result = ""; try { string sql = @"INSERT INTO TB_Votation_Questions_Answer(QuestionId,Answer) VALUES (" + tva.questionId + ",'" + tva.answer + "')"; OleDbCommand cmd = new OleDbCommand(sql, db); cmd.ExecuteNonQuery(); db.Close(); result = "VOTACIÒN INICIADA"; } catch (Exception) { throw; } return(result); }
public List <TB_Votation_Questions_Answer> getAnswer(OleDbConnection db, int Qid) { DataSet ds = new DataSet(); List <TB_Votation_Questions_Answer> lstAnswer = new List <TB_Votation_Questions_Answer>(); try { OleDbDataAdapter da = new OleDbDataAdapter("SELECT ANSWER FROM TB_VOTATION_QUESTIONS_answer WHERE QuestionId =" + Qid, db); da.Fill(ds); db.Close(); DataTable dt = ds.Tables[0]; foreach (DataRow rows in dt.Rows) { TB_Votation_Questions_Answer answer = new TB_Votation_Questions_Answer(); answer.answer = rows["ANSWER"].ToString(); lstAnswer.Add(answer); } } catch (Exception) { throw; } return(lstAnswer); }
public string addAnswer(TB_Votation_Questions_Answer tva, OleDbConnection db) { return(_Votation.insertAnswer(tva, db)); }
public ActionResult UploadFile() { int idVotation = int.Parse(Request.Form[0].ToString()); string fullpath = ""; if (Request.Files.Count > 0 && idVotation > 0) { try { HttpFileCollectionBase files = Request.Files; //for (int i = 0; i < files.Count; i++) // { HttpPostedFileBase file = files[0]; string fname; var req = Request.Browser.Browser.ToUpper(); if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER") { string[] testfiles = file.FileName.Split(new char[] { '\\' }); fname = testfiles[testfiles.Length - 1]; } else { //fname = file.FileName; string filen = Request.Files.AllKeys[0].ToString(); string path = Path.Combine(HttpRuntime.AppDomainAppPath, "Resource\\Upload\\Question\\"); fullpath = Path.Combine(path, filen); file.SaveAs(fullpath); } using (var reader = new StreamReader(fullpath, Encoding.Default, true)) { while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = line.Split(';'); if (!values[0].Contains("Orden")) { TB_Votation_Questions questions = new TB_Votation_Questions(); questions.order = int.Parse(values[0].ToString()); questions.votationId = idVotation; questions.question = values[1].ToString(); int idQuestion = TB_vota.addQuestions(questions, DBConnect.open()); TB_Votation_Questions_Answer answer = new TB_Votation_Questions_Answer(); answer.questionId = idQuestion; for (int e = 2; e <= values.Length - 1; e++) { if (values[e].ToString() != "") { answer.answer = values[e].ToString(); TB_vota.addAnswer(answer, DBConnect.open()); } } } } } System.IO.File.Delete(fullpath); } // } catch (System.Exception ex) { return(Json("Error is " + ex.Message)); } return(Json("File Uploaded")); } else { return(Json("No files selected")); } }