Exemple #1
0
        public JsonResult Practice_example(long pqid)
        {
            var dbq  = db.paper_ques.Find(pqid);
            var back = dbq.question.qbase_chapter.background;

            DataSet[] res = null;
            if (back.db == "Kingbase")
            {
                var kingbaseconn = new KingbaseConn();
                res = kingbaseconn.ShowBackGround(back.name);
                kingbaseconn.Dispose();
            }
            else if (back.db == "Mysql")
            {
                var mysqlconn = new MysqlConn();
                res = mysqlconn.ShowBackGround(back.name);
                mysqlconn.Dispose();
            }
            else if (back.db == "MSSQL")
            {
                var mssqlconn = new MSSQLConn();
                res = mssqlconn.ShowBackGround(back.name);
                mssqlconn.Dispose();
            }
            else
            {
                res = new DataSet[0];
            }
            int count = res.Count();
            var tname = new List <string>();
            var datas = new List <object[]>();

            string[][] colnames = new string[count][];
            for (int i = 0; i < count; i++)
            {
                var ds       = res[i];
                var colcount = ds.Tables[0].Columns.Count;
                tname.Add(ds.DataSetName);
                colnames[i] = new string[colcount];
                int j = 0;
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    colnames[i][j] = new string(col.ColumnName.ToCharArray());
                    //colnames[i][j] += $"({col.GetType().ToString()})";
                    j++;
                }
                var data = ds.Tables[0].Rows[0].ItemArray;
                datas.Add(data);
            }
            var json = new {
                count,
                tname,
                datas,
                colnames
            };

            return(Json(json, JsonRequestBehavior.AllowGet));
        }
Exemple #2
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));
        }
Exemple #3
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));
        }