예제 #1
0
        public JsonResult getQuestions()
        {
            var userVote = (TB_UserVote)Session["UserVote"];

            ListVote      lv       = new ListVote();
            List <string> lsresult = new List <string>();

            int order = lv.getOrderQuestion(DBConnect.open(), userVote.votationid);

            TB_Votation_Questions _Questions = new TB_Votation_Questions();

            _Questions.votationId = userVote.votationid;
            _Questions.order      = order;


            TB_Votation_Questions qRequest = lv.getquestions(DBConnect.open(), _Questions);
            List <TB_Votation_Questions_Answer> lstanswer = lv.getAnswer(DBConnect.opentwo(), qRequest.id);

            lsresult.Add(qRequest.question);

            for (int e = 0; e < lstanswer.Count; e++)
            {
                lsresult.Add(lstanswer[e].answer.ToString());
            }

            return(Json(lsresult, JsonRequestBehavior.AllowGet));
        }
        public List <TB_Votation_Questions> getQuestionVotation(OleDbConnection db, int idVotation)
        {
            DataSet ds = new DataSet();

            try
            {
                OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM TB_Votation_Questions WHERE VotationId = " + idVotation, db);
                da.Fill(ds);
                db.Close();
                DataTable dt = ds.Tables[0];
                foreach (DataRow rows in dt.Rows)
                {
                    TB_Votation_Questions questions = new TB_Votation_Questions(
                        int.Parse(rows["Id"].ToString()),
                        int.Parse(rows["VotationId"].ToString()),
                        int.Parse(rows["Order"].ToString()),
                        rows["Question"].ToString());

                    lstquestion.Add(questions);
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(lstquestion);
        }
예제 #3
0
        public JsonResult CreateVote(TB_Vote v)
        {
            var user = (TB_UserVote)Session["UserVote"];

            int order = lv.getOrderQuestion(DBConnect.open(), user.votationid);

            TB_Votation_Questions _Questions = new TB_Votation_Questions();

            _Questions.votationId = user.votationid;
            _Questions.order      = order;


            TB_Votation_Questions qRequest = lv.getquestions(DBConnect.open(), _Questions);

            Utils u = new Utils();

            v.userVoteid = user.id;
            v.votationid = user.votationid;
            v.mac        = getipUser();
            v.questionid = qRequest.id;
            TB_Vote_Data vdata  = new TB_Vote_Data();
            string       result = vdata.addVote(v, DBConnect.open());

            return(Json(result));
        }
예제 #4
0
        public JsonResult nextQuestion(int i, int type, int id)
        {
            int ix = 0;

            if (Session["nextQ"] != null)
            {
                ix = (int)Session["nextQ"];
                int x = 0;
                if (type == 1)
                {
                    x = ix += i;
                }
                else if (type == 2)
                {
                    x = ix -= i;
                }
                else if (type == 0)
                {
                    x = 1;
                }
                Session["nextQ"] = x;
            }
            else
            {
                Session["nextQ"] = i;
                ix = 1;
            }
            List <string> lsresult = new List <string>();

            TB_Votation_Questions _Questions = new TB_Votation_Questions();

            _Questions.votationId = id;
            _Questions.order      = ix;

            TB_Votation_Questions qRequest = lv.getquestions(DBConnect.open(), _Questions);
            List <TB_Votation_Questions_Answer> lstanswer = lv.getAnswer(DBConnect.open(), qRequest.id);

            lsresult.Add(qRequest.question);

            for (int e = 0; e < lstanswer.Count; e++)
            {
                lsresult.Add(lstanswer[e].answer.ToString());
            }
            Session["votationid"] = id;
            Session["order"]      = ix;
            Session["questionid"] = qRequest.id;


            return(Json(lsresult, JsonRequestBehavior.AllowGet));
        }
        public JsonResult Report(string key)
        {
            string[] colors  = new string[9];
            string[] graphic = new string[] { };
            string[] options = new string[9];

            int      idf = int.Parse(key);
            ListVote lv  = new ListVote();

            List <ResultOptions> lstro = lv.getOptions(DBConnect.open(), idf);


            int order = lv.getOrderQuestion(DBConnect.open(), idf);

            TB_Votation_Questions _Questions = new TB_Votation_Questions();

            _Questions.votationId = idf;
            _Questions.order      = order;


            TB_Votation_Questions qRequest = lv.getquestions(DBConnect.open(), _Questions);
            List <TB_Vote>        votes    = lv.getListVote("max", idf, qRequest.id, DBConnect.open());

            List <TB_Votation_Questions_Answer> lstanswer = lv.getAnswer(DBConnect.open(), qRequest.id);

            graphic = new string[] { qRequest.question, lstro[0].graphic, lstro[0].height.ToString(), lstro[0].width.ToString(), lstro[0].imagefondo, lstro[0].visible };

            /*
             *          for (int i = 0; i < lstro.Count; i++)
             *          {
             *              colors[i] = lstro[i].color;
             *              options[i] = lstro[i].option;
             *          }
             */
            for (int i = 0; i < lstanswer.Count; i++)
            {
                colors[i]  = lstro[i].color;
                options[i] = lstanswer[i].answer;
            }
            ResultVote rv  = lv.getVote(votes);
            ResultVote rv2 = new ResultVote();

            string[] value   = GetCountOptions(rv, rv2);
            var      Tablero = new[] { graphic, colors, options, value };

            return(Json(Tablero, JsonRequestBehavior.AllowGet));
        }
예제 #6
0
        public int insertQuestions(TB_Votation_Questions tvq, OleDbConnection db)
        {
            int result = 0;

            try
            {
                string       sql = @"INSERT INTO TB_Votation_Questions(VotationId,[Order],Question) VALUES (" + tvq.votationId + "," + tvq.order + ",'" + tvq.question + "')";
                OleDbCommand cmd = new OleDbCommand(sql, db);
                cmd.ExecuteNonQuery();
                cmd.CommandText = "SELECT @@IDENTITY";
                result          = (int)cmd.ExecuteScalar();
                db.Close();
            }
            catch (Exception)
            {
                throw;
            }


            return(result);
        }
예제 #7
0
        public TB_Votation_Questions getquestions(OleDbConnection db, TB_Votation_Questions q)
        {
            DataSet ds = new DataSet();
            TB_Votation_Questions questions = new TB_Votation_Questions();

            try
            {
                OleDbDataAdapter da = new OleDbDataAdapter("SELECT TOP 1 ID,QUESTION FROM TB_VOTATION_QUESTIONS WHERE VOTATIONID =" + q.votationId + " AND [ORDER] =" + q.order, db);
                da.Fill(ds);
                db.Close();
                DataTable dt = ds.Tables[0];
                foreach (DataRow rows in dt.Rows)
                {
                    questions.id       = int.Parse(rows["ID"].ToString());
                    questions.question = rows["question"].ToString();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(questions);
        }
 public TB_Votation_Questions getquestions(OleDbConnection db, TB_Votation_Questions q)
 {
     return(dl.getquestions(db, q));
 }
예제 #9
0
 public int addQuestions(TB_Votation_Questions tvq, OleDbConnection db)
 {
     return(_Votation.insertQuestions(tvq, 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"));
            }
        }