⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scoreservice.cs

📁 在线考试系统完整版源码(C#&Access) 该考试系统为一同学毕业设计
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using ExamModel.Auto_Generated_Code;

namespace ExamDAL.Auto_Generated_Code
{
    public static class ScoreService
    {
        public static int AddScore(Score score)
        {

             string sql = "insert into [Score] (UID,PaperID,FrontScore,BackScore,TotleScore,RightRate,ExamTime) values (" + score.UID.UID + "," + score.PaperID.PaperId + "," + score.FrontScore + "," + score.BackScore + "," + score.TotleScore + ",'" + score.RightRate + "','" + score.ExamTime + "')";
             return DBHelp.ExecuteCommand(sql);
        }
        //查所有的科目 返回DataSet
        public static DataSet GetScoreList()
        {
            string sql = "select * from Score";
            return DBHelp.GetDataSet(sql);
        }
        //
        public static IList<Score> GetAllScore()
        {
            List<Score> list = new List<Score>();
            string oleDbString = "select * from Score";
            using (DataSet ds = DBHelp.GetDataSet(oleDbString))
            {
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    Score score = new Score();
                    score.ScoreID = (int)row["ScoreID"];
                    score.UID = UserServices.GetUserByuserId((string)row["UID"]);
                    score.PaperID = PaperService.GetPaperById((int)row["PaperID"]);
                    score.FrontScore = (int)row["FrontScore"];
                    score.BackScore = (int)row["BackScore"];
                    score.TotleScore = (int)row["TotleScore"];
                    score.RightRate = (string)row["RightRate"];
                    score.ExamTime =(string)row["ExamTime"];
                    list.Add(score);
                }
                return list;
            }
        }
        //通过ID获得对象
        public static Score GetScoreById(int id)
        {
            string sql = "select * from Score where ScoreID=@id";
            int courseId;
            try
            {
                OleDbDataReader reader = DBHelp.GetReader(sql, new OleDbParameter("@id", id));
                if (reader.Read())
                {
                    Score score = new Score();
                    score.ScoreID = (int)reader["ScoreID"];
                    score.UID = UserServices.GetUserByuserId((string)reader["UID"]);
                    score.PaperID = PaperService.GetPaperById((int)reader["PaperID"]);
                    score.FrontScore = (int)reader["FrontScore"];
                    score.BackScore = (int)reader["BackScore"];
                    score.TotleScore = (int)reader["TotleScore"];
                    score.RightRate = (string)reader["RightRate"];
                    score.ExamTime = (string)reader["ExamTime"];
                    return score;


           
                }
                else
                {
                    reader.Close();
                    return null;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;

            }
        }

        //更新分数
        public static bool UpdateMark(Score score)
        {
            try
            {
                string sql1 = "update Score set BackScore=" + score.BackScore + ",TotleScore=" + score.TotleScore + " where ScoreID=" + score.ScoreID;
                DBHelp.ExecuteCommand(sql1);
                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
        //通过ID删除用户信息
        public static void DelScoreByid(int ScoreID)
        {
            string sql = "Delete from Score where ScoreID=" + ScoreID;
            try
            {
                DBHelp.ExecuteCommand(sql);
                AnswerServices.DelAnswerByscoreid(ScoreID);

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
        //通过uid返回score对象
        public static Score GetScoreByuid(string uid)
        {
            string sql = "select * from Score where UID='" + uid + "'";
            try
            {
                OleDbDataReader reader = DBHelp.GetReader(sql);
                if (reader.Read())
                {
                    Score score = new Score();
                    score.ScoreID = (int)reader["ScoreID"];
                    score.UID = UserServices.GetUserByuserId((string)reader["UID"]);
                    score.PaperID = PaperService.GetPaperById((int)reader["PaperID"]);
                    score.FrontScore = (int)reader["FrontScore"];
                    score.BackScore = (int)reader["BackScore"];
                    score.TotleScore = (int)reader["TotleScore"];
                    score.RightRate = (string)reader["RightRate"];
                    score.ExamTime = (string)reader["ExamTime"];
                    return score;



                }
                else
                {
                    reader.Close();
                    return null;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;

            }
        }
        
        ////通过uid and papername返回Score对象
        public static Score GetScoreByuidPaperid(string uid, string papername)
        {
            Paper paper = PaperService.GetPaperByName(papername);
            string sql = "select * from Score where UID='" + uid + "' and PaperID=" + paper.PaperId;
            try
            {
                OleDbDataReader reader = DBHelp.GetReader(sql);
                if (reader.Read())
                {
                    Score score = new Score();
                    score.ScoreID = (int)reader["ScoreID"];
                    score.UID = UserServices.GetUserByuserId((string)reader["UID"]);
                    score.PaperID = PaperService.GetPaperById((int)reader["PaperID"]);
                    score.FrontScore = (int)reader["FrontScore"];
                    score.BackScore = (int)reader["BackScore"];
                    score.TotleScore = (int)reader["TotleScore"];
                    score.RightRate = (string)reader["RightRate"];
                    score.ExamTime = (string)reader["ExamTime"];
                    return score;



                }
                else
                {
                    reader.Close();
                    return null;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;

            }
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -