Exemplo n.º 1
0
        public Tuple <double, string> Judge_sql(question q, background back, string ans)
        {
            string username = (string)Session["account"];

            ans = ans.ToUpper();
            if (ans == "")
            {
                return(new Tuple <double, string>(0, "空字符"));
            }
            if (ans.Last() == ';')
            {
                ans = ans.Remove(ans.Length - 1);
            }
            string back_name = back.name;
            var    res       = new Tuple <string, bool>("暂不支持该数据库", false);

            if (back.db == "Kingbase")
            {
                KingbaseConn conn = new KingbaseConn();
                res = conn.JudgeSql(username, q, ans, back_name);
                conn.Dispose();
            }
            else if (back.db == "Mysql")
            {
                MysqlConn conn = new MysqlConn(username);
                res = conn.JudgeSql($"Student_{username}", q, ans, back_name);
                conn.Dispose();
            }
            else if (back.db == "MSSQL")
            {
                MSSQLConn conn = new MSSQLConn(username);
                res = conn.JudgeSql($"Student_{username}", q, ans, back_name);
                conn.Dispose();
            }
            double score = 0;
            string exc   = "";

            if (res.Item2 == true)
            {
                score = q.totvalue;
                exc   = "congratulations!!";
                score = 10;
            }
            else
            {
                ans += "&exit";
                exc  = res.Item1;
                var Dic  = Server.MapPath("/flex");
                var path = Server.MapPath($"/flex/exe/question{q.id}.exe");
                score = double.Parse(tf.RunFlex(path, ans, Dic, username));
            }
            return(new Tuple <double, string>(score, exc));
        }
Exemplo n.º 2
0
        public JsonResult Sub_Ans(string ans, long pqid, long cost, string ecid)
        {
            ans = ans.Replace("\r\n", " ");
            ans = ans.Replace("###", "select");
            ans = ans.Replace("!!!", "delete");
            long   id        = (long)Session["id"];
            string account   = (string)Session["account"];
            long   ec_id     = long.Parse(ecid);
            string username  = (string)Session["account"];
            var    dbq       = db.paper_ques.Find(pqid);
            var    q         = dbq.question;
            var    back      = q.qbase_chapter.background;
            string back_name = back.name;
            var    log       = new stu_ans_log();
            var    res       = new Tuple <string, bool>("", false);

            if (back.db == "Kingbase")
            {
                KingbaseConn conn = new KingbaseConn();
                res = conn.JudgeSql(username, q, ans, back_name);
                conn.Dispose();
            }
            else if (back.db == "Mysql")
            {
                MysqlConn conn = new MysqlConn(username);
                res = conn.JudgeSql($"Student_{username}", q, ans, back_name);
                conn.Dispose();
            }
            else if (back.db == "MSSQL")
            {
                MSSQLConn conn = new MSSQLConn(username);
                res = conn.JudgeSql($"Student_{username}", q, ans, back_name);
                conn.Dispose();
            }
            log.ans        = ans;
            log.paper_ques = dbq;
            log.stu_info   = db.stu_info.Find(id);
            log.wronginfo  = res.Item1;
            log.cost       = new TimeSpan(cost);
            log.exam_class = db.exam_class.Find(ec_id);
            Save_Ans(ans, pqid, res.Item2);
            db.stu_ans_log.Add(log);
            db.SaveChanges();
            var json = new {
                message = res.Item1,
                judge   = res.Item2
            };

            return(Json(json, JsonRequestBehavior.AllowGet));
        }