Exemplo n.º 1
0
        public ActionResult ShowQnByCode(string code)
        {
            if (!string.IsNullOrEmpty(code))
            {
                string sql = string.Format("SELECT id,title,introduction FROM questionnaire WHERE publish_code='{0}'", code);
                var    res = DB.GetResult(sql);
                if (res.Rows.Count > 0)
                {
                    string id = res.Rows[0][0].ToString();
                    try
                    {
                        int           qnid = Int32.Parse(id);
                        var           qnr  = res.Rows[0];
                        QuestionNaire qn   = new QuestionNaire();
                        qn.id           = qnid.ToString();
                        qn.title        = res.Rows[0]["title"].ToString();
                        qn.introduction = res.Rows[0]["introduction"].ToString().Replace("\r", "").Replace("\n", "<br>").Replace(" ", "&nbsp;").Replace("\t", "&emsp;");
                        qn.code         = code;
                        ViewBag.qn      = qn;

                        return(View("ShowQnWelcome"));
                    }
                    catch
                    {
                    }
                }
            }
            return(RedirectToAction("Message", "Home", new { id = "不存在此问卷。" }));
        }
        //public ActionResult Index()
        //{
        //    return View();
        //}

        //public ActionResult CheckQn()
        //{
        //    string uid = CheckIP.GetNetIP();
        //    string sql = "SELECT id,title,introduction,is_open,publish_code FROM questionnaire ORDER BY id DESC";
        //    var tb = DB.GetResult(sql);
        //    List<AnswerQn> qn = new List<AnswerQn>();
        //    for (int i = 0; i < tb.Rows.Count;i++ )
        //    {
        //        AnswerQn aqn = new AnswerQn();
        //        aqn.id = tb.Rows[i][0].ToString();
        //        aqn.title = tb.Rows[i][1].ToString();
        //        aqn.introduction = StringTruncat(tb.Rows[i][2].ToString());
        //        aqn.is_open = tb.Rows[i][3].ToString();
        //        aqn.publish_code = tb.Rows[i][4].ToString();
        //        sql = string.Format("SELECT answer.id FROM answer LEFT JOIN question  ON answer.belong_q=question.id WHERE belong_user='******' and question.belong_qn='{1}'", uid, aqn.id);
        //        if (DB.Exists(sql))
        //        {
        //            //is answer
        //            aqn.is_answer = "1";
        //        }
        //        else
        //        {
        //            aqn.is_answer = "0";
        //        }
        //        qn.Add(aqn);
        //    }
        //    ViewBag.questions = qn;
        //    return View();
        //}

        public ActionResult ShowQnByCode(string code)
        {
            if (!string.IsNullOrEmpty(code))
            {
                string sql = string.Format("SELECT id FROM questionnaire WHERE publish_code='{0}'", code);
                var    res = DB.GetResult(sql);
                if (res.Rows.Count > 0)
                {
                    string id = res.Rows[0][0].ToString();
                    try
                    {
                        int qnid = Int32.Parse(id);

                        ////限制每个ip限答一次
                        //string uid = CheckIP.GetIP();
                        //sql = string.Format("SELECT answer.id FROM answer LEFT JOIN question  ON answer.belong_q=question.id WHERE belong_user='******' and question.belong_qn='{1}'", uid, qnid);
                        //if (DB.Exists(sql))
                        //{
                        //    //此ip已经回答过此问题了。
                        //    return RedirectToAction("Message", "Home", new { id = "您已回答了本问卷,感谢您的参与!" });
                        //}


                        sql = string.Format("SELECT id,title,introduction FROM questionnaire WHERE id='{0}'", qnid);
                        var           qnr = DB.GetResult(sql).Rows[0];
                        QuestionNaire qn  = new QuestionNaire();
                        qn.id           = qnid.ToString();
                        qn.title        = qnr[1].ToString();
                        qn.introduction = qnr[2].ToString();
                        List <Question> qs = new List <Question>();
                        sql = string.Format("SELECT type,introduction,options,id,star_target FROM question WHERE belong_qn='{0}' ORDER BY id", qnid);
                        var qst = DB.GetResult(sql);
                        for (int i = 0; i < qst.Rows.Count; i++)
                        {
                            Question nq = new Question();
                            nq.type        = qst.Rows[i][0].ToString();
                            nq.title       = qst.Rows[i][1].ToString();
                            nq.options     = qst.Rows[i][2].ToString();
                            nq.id          = Int32.Parse(qst.Rows[i][3].ToString());
                            nq.star_target = qst.Rows[i]["star_target"].ToString();
                            qs.Add(nq);
                        }
                        qn.questions = qs;
                        ViewBag.qn   = qn;

                        return(View("ShowQn"));
                    }
                    catch
                    {
                    }
                }
            }
            return(RedirectToAction("Message", "Home", new { id = "不存在此问卷。" }));
        }
Exemplo n.º 3
0
        public ActionResult SaveQn(QuestionNaire qn)
        {
            if (string.IsNullOrEmpty(qn.id))
            {
                //new
                string code = getPublishCode(qn.title);
                string sql  = String.Format("INSERT INTO questionnaire(title,introduction,publish_code) VALUES('{0}','{1}','{2}')", qn.title, qn.introduction, code);
                DB.ExecuteSql(sql);
                sql   = String.Format("SELECT max(id) FROM questionnaire");
                qn.id = DB.GetResult(sql).Rows[0][0].ToString();

                //foreach (var q in qn.questions)
                //{
                //    sql = string.Format("INSERT INTO question(introduction,type,options,scores,belong_qn) VALUES('{0}','{1}','{2}','{3}','{4}')", q.introduction, q.type, q.options, q.scores, qn.id);
                //    DB.ExecuteSql(sql);
                //}
            }
            else
            {
                //update
                string sql = String.Format("UPDATE questionnaire SET title='{0}',introduction='{1}' WHERE id='{2}'", qn.title, qn.introduction, qn.id);
                DB.ExecuteSql(sql);

                ////删除以前的题目记录和答题结果
                //sql = string.Format("DELETE FROM answer WHERE belong_q in (SELECT id FROM question WHERE belong_qn='{0}')", qn.id);
                //DB.ExecuteSql(sql);
                //sql = String.Format("DELETE FROM question WHERE belong_qn='{0}'", qn.id);
                //DB.ExecuteSql(sql);

                //foreach (var q in qn.questions)
                //{
                //    sql = string.Format("INSERT INTO question(introduction,type,options,scores,belong_qn) VALUES('{0}','{1}','{2}','{3}','{4}')", q.introduction, q.type, q.options, q.scores, qn.id);
                //    DB.ExecuteSql(sql);
                //}
            }

            return(Content("Success"));
        }
Exemplo n.º 4
0
        public ActionResult AddQn(string id = "")
        {
            if (!string.IsNullOrWhiteSpace(id))
            {
                // 编辑问卷
                try
                {
                    int           qnid = Int32.Parse(id);
                    string        sql  = string.Format("SELECT * FROM questionnaire WHERE id='{0}'", qnid);
                    var           qnr  = DB.GetResult(sql).Rows[0];
                    QuestionNaire qn   = new QuestionNaire();
                    qn.id           = qnid.ToString();
                    qn.title        = qnr[1].ToString();
                    qn.introduction = qnr[2].ToString();
                    List <Question> qs = new List <Question>();
                    sql = string.Format("SELECT type,introduction,options,scores,age FROM question WHERE belong_qn='{0}' ORDER BY age,type", qnid);
                    var qst = DB.GetResult(sql);
                    for (int i = 0; i < qst.Rows.Count; i++)
                    {
                        Question nq = new Question();
                        nq.type         = qst.Rows[i]["type"].ToString();
                        nq.introduction = qst.Rows[i]["introduction"].ToString();
                        nq.options      = qst.Rows[i]["options"].ToString();
                        nq.scores       = qst.Rows[i]["scores"].ToString();
                        nq.age          = qst.Rows[i]["age"].ToString();
                        qs.Add(nq);
                    }
                    qn.questions = qs;
                    ViewBag.qn   = qn;
                }
                catch
                {
                }
            }

            return(View());
        }