コード例 #1
0
ファイル: Quiz.cs プロジェクト: pyteach/Learnsite
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(LearnSite.Model.Quiz model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Quiz(");
            strSql.Append("Qtype,Question,Qanswer,Qanalyze,Qscore,Qclass,Qselect)");
            strSql.Append(" values (");
            strSql.Append("@Qtype,@Question,@Qanswer,@Qanalyze,@Qscore,@Qclass,@Qselect)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Qtype",    SqlDbType.Int,       4),
                new SqlParameter("@Question", SqlDbType.NText),
                new SqlParameter("@Qanswer",  SqlDbType.NVarChar, 50),
                new SqlParameter("@Qanalyze", SqlDbType.NVarChar, 50),
                new SqlParameter("@Qscore",   SqlDbType.Int,       4),
                new SqlParameter("@Qclass",   SqlDbType.NVarChar, 50),
                new SqlParameter("@Qselect",  SqlDbType.Bit, 1)
            };
            parameters[0].Value = model.Qtype;
            parameters[1].Value = model.Question;
            parameters[2].Value = model.Qanswer;
            parameters[3].Value = model.Qanalyze;
            parameters[4].Value = model.Qscore;
            parameters[5].Value = model.Qclass;
            parameters[6].Value = model.Qselect;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(1);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
コード例 #2
0
ファイル: Quiz.cs プロジェクト: pyteach/Learnsite
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(LearnSite.Model.Quiz model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Quiz set ");
            strSql.Append("Qtype=@Qtype,");
            strSql.Append("Question=@Question,");
            strSql.Append("Qanswer=@Qanswer,");
            strSql.Append("Qanalyze=@Qanalyze,");
            strSql.Append("Qscore=@Qscore,");
            strSql.Append("Qclass=@Qclass,");
            strSql.Append("Qselect=@Qselect");
            strSql.Append(" where Qid=@Qid ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Qid",      SqlDbType.Int,       4),
                new SqlParameter("@Qtype",    SqlDbType.Int,       4),
                new SqlParameter("@Question", SqlDbType.NText),
                new SqlParameter("@Qanswer",  SqlDbType.NVarChar, 50),
                new SqlParameter("@Qanalyze", SqlDbType.NVarChar, 50),
                new SqlParameter("@Qscore",   SqlDbType.Int,       4),
                new SqlParameter("@Qclass",   SqlDbType.NVarChar, 50),
                new SqlParameter("@Qselect",  SqlDbType.Bit, 1)
            };

            parameters[0].Value = model.Qid;
            parameters[1].Value = model.Qtype;
            parameters[2].Value = model.Question;
            parameters[3].Value = model.Qanswer;
            parameters[4].Value = model.Qanalyze;
            parameters[5].Value = model.Qscore;
            parameters[6].Value = model.Qclass;
            parameters[7].Value = model.Qselect;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
コード例 #3
0
        /// <summary>
        /// 从上传的试题包xml中导入试题到数据库
        /// </summary>
        /// <returns></returns>
        public static string XmltoQuiz(FileUpload fud)
        {
            string msg = "";

            if (Uploadxml(fud))
            {
                string xmlFile = QuizStorage() + "Quiz.xml";
                if (File.Exists(xmlFile))
                {
                    DataSet ds = new DataSet();
                    ds.ReadXml(xmlFile);
                    DataTable dt = ds.Tables["Quiz"];
                    if (dt != null)
                    {
                        int count = dt.Rows.Count;
                        if (count > 0)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                LearnSite.Model.Quiz model = new LearnSite.Model.Quiz();
                                if (dt.Rows[i]["Qid"].ToString() != "")
                                {
                                    model.Qid = int.Parse(dt.Rows[i]["Qid"].ToString());
                                }
                                if (dt.Rows[i]["Qtype"].ToString() != "")
                                {
                                    model.Qtype = int.Parse(dt.Rows[i]["Qtype"].ToString());
                                }
                                model.Question = dt.Rows[i]["Question"].ToString();
                                model.Qanswer  = dt.Rows[i]["Qanswer"].ToString();
                                model.Qanalyze = dt.Rows[i]["Qanalyze"].ToString();
                                if (dt.Rows[i]["Qscore"].ToString() != "")
                                {
                                    model.Qscore = int.Parse(dt.Rows[i]["Qscore"].ToString());
                                }
                                model.Qclass = dt.Rows[i]["Qclass"].ToString();
                                if (dt.Rows[i]["Qselect"].ToString() != "")
                                {
                                    if ((dt.Rows[i]["Qselect"].ToString() == "1") || (dt.Rows[i]["Qselect"].ToString().ToLower() == "true"))
                                    {
                                        model.Qselect = true;
                                    }
                                    else
                                    {
                                        model.Qselect = false;
                                    }
                                }
                                LearnSite.BLL.Quiz bll = new LearnSite.BLL.Quiz();
                                bll.Add(model);
                            }
                            msg = "成功导入" + count.ToString() + "条试题!";
                            File.Delete(xmlFile);//删除上传文件
                            ds.Dispose();
                        }
                        else
                        {
                            msg = "试题包为空!";
                        }
                    }
                    else
                    {
                        msg = "试题包不正确!";
                    }
                }
                else
                {
                    msg = "试题包不存在!";
                }
            }
            else
            {
                msg = "试题包格式不正确!";
            }
            return(msg);
        }
コード例 #4
0
ファイル: Quizbag.cs プロジェクト: dalinhuang/learnsite
 /// <summary>
 /// 从上传的试题包xml中导入试题到数据库
 /// </summary>
 /// <returns></returns>
 public static string XmltoQuiz(FileUpload fud)
 {
     string msg = "";
     if (Uploadxml(fud))
     {
         string xmlFile = QuizStorage() + "Quiz.xml";
         if (File.Exists(xmlFile))
         {
             DataSet ds = new DataSet();
             ds.ReadXml(xmlFile);
             DataTable dt = ds.Tables["Quiz"];
             if (dt != null)
             {
                 int count = dt.Rows.Count;
                 if (count > 0)
                 {
                     for (int i = 0; i < count; i++)
                     {
                         LearnSite.Model.Quiz model = new LearnSite.Model.Quiz();
                         if (dt.Rows[i]["Qid"].ToString() != "")
                         {
                             model.Qid = int.Parse(dt.Rows[i]["Qid"].ToString());
                         }
                         if (dt.Rows[i]["Qtype"].ToString() != "")
                         {
                             model.Qtype = int.Parse(dt.Rows[i]["Qtype"].ToString());
                         }
                         model.Question = dt.Rows[i]["Question"].ToString();
                         model.Qanswer = dt.Rows[i]["Qanswer"].ToString();
                         model.Qanalyze = dt.Rows[i]["Qanalyze"].ToString();
                         if (dt.Rows[i]["Qscore"].ToString() != "")
                         {
                             model.Qscore = int.Parse(dt.Rows[i]["Qscore"].ToString());
                         }
                         LearnSite.BLL.Quiz bll = new LearnSite.BLL.Quiz();
                         bll.Add(model);
                     }
                     msg = "成功导入" + count.ToString() + "条试题!";
                     File.Delete(xmlFile);//删除上传文件
                     ds.Dispose();
                 }
                 else
                 {
                     msg = "试题包为空!";
                 }
             }
             else
             {
                 msg = "试题包不正确!";
             }
         }
         else
         {
             msg = "试题包不存在!";
         }
     }
     else
     {
         msg = "试题包格式不正确!";
     }
     return msg;
 }
コード例 #5
0
ファイル: Quiz.cs プロジェクト: pyteach/Learnsite
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public LearnSite.Model.Quiz GetModel(int Qid)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Qid,Qtype,Question,Qanswer,Qanalyze,Qscore,Qclass,Qselect,Qright,Qwrong,Qaccuracy from Quiz ");
            strSql.Append(" where Qid=@Qid ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Qid", SqlDbType.Int, 4)
            };
            parameters[0].Value = Qid;

            LearnSite.Model.Quiz model = new LearnSite.Model.Quiz();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Qid"].ToString() != "")
                {
                    model.Qid = int.Parse(ds.Tables[0].Rows[0]["Qid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Qtype"].ToString() != "")
                {
                    model.Qtype = int.Parse(ds.Tables[0].Rows[0]["Qtype"].ToString());
                }
                model.Question = ds.Tables[0].Rows[0]["Question"].ToString();
                model.Qanswer  = ds.Tables[0].Rows[0]["Qanswer"].ToString();
                model.Qanalyze = ds.Tables[0].Rows[0]["Qanalyze"].ToString();
                if (ds.Tables[0].Rows[0]["Qscore"].ToString() != "")
                {
                    model.Qscore = int.Parse(ds.Tables[0].Rows[0]["Qscore"].ToString());
                }
                model.Qclass = ds.Tables[0].Rows[0]["Qclass"].ToString();
                if (ds.Tables[0].Rows[0]["Qselect"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["Qselect"].ToString() == "1") || (ds.Tables[0].Rows[0]["Qselect"].ToString().ToLower() == "true"))
                    {
                        model.Qselect = true;
                    }
                    else
                    {
                        model.Qselect = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["Qright"].ToString() != "")
                {
                    model.Qright = int.Parse(ds.Tables[0].Rows[0]["Qright"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Qwrong"].ToString() != "")
                {
                    model.Qwrong = int.Parse(ds.Tables[0].Rows[0]["Qwrong"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Qaccuracy"].ToString() != "")
                {
                    model.Qaccuracy = int.Parse(ds.Tables[0].Rows[0]["Qaccuracy"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
コード例 #6
0
ファイル: Quiz.cs プロジェクト: dalinhuang/learnsite
        /// <summary>
        /// �õ�һ������ʵ��
        /// </summary>
        public LearnSite.Model.Quiz GetModel(int Qid)
        {
            StringBuilder strSql=new StringBuilder();
            strSql.Append("select  top 1 Qid,Qtype,Question,Qanswer,Qanalyze,Qscore from Quiz ");
            strSql.Append(" where Qid=@Qid ");
            SqlParameter[] parameters = {
                    new SqlParameter("@Qid", SqlDbType.Int,4)};
            parameters[0].Value = Qid;

            LearnSite.Model.Quiz model=new LearnSite.Model.Quiz();
            DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
            if(ds.Tables[0].Rows.Count>0)
            {
                if(ds.Tables[0].Rows[0]["Qid"].ToString()!="")
                {
                    model.Qid=int.Parse(ds.Tables[0].Rows[0]["Qid"].ToString());
                }
                if(ds.Tables[0].Rows[0]["Qtype"].ToString()!="")
                {
                    model.Qtype=int.Parse(ds.Tables[0].Rows[0]["Qtype"].ToString());
                }
                model.Question=ds.Tables[0].Rows[0]["Question"].ToString();
                model.Qanswer=ds.Tables[0].Rows[0]["Qanswer"].ToString();
                model.Qanalyze=ds.Tables[0].Rows[0]["Qanalyze"].ToString();
                if(ds.Tables[0].Rows[0]["Qscore"].ToString()!="")
                {
                    model.Qscore=int.Parse(ds.Tables[0].Rows[0]["Qscore"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }