//���뿼�Գɼ� public static bool InsertScore(Scores score, string PaperName, string userId, int paperId) { if (SeclctCheck(userId, paperId)) { using (SqlConnection con = DBHelp.GetConnection()) { string sql = @"insert into Score (UserID,PaperID,Score,ExamTime,JudgeTime) select @UserID, PaperID, @Score, @ExamTime, @JudgeTime from Paper where PaperName = '" + PaperName + "'"; SqlParameter[] para = new SqlParameter[] { new SqlParameter("@UserId",score.UserID), new SqlParameter("@PaperID",score.PaperID), new SqlParameter("@Score",score.Score), new SqlParameter("@ExamTime",score.ExamTime), new SqlParameter("@JudgeTime",score.JudgeTime) }; int i = DBHelp.ExecuteCommand(sql, para); if (i > 0) { return true; } else { return false; } } } return false; }
public static bool InsertScores(Scores scores, string PaperName,string userId, int paperId) { if (UserService.InsertScore(scores, PaperName, userId, paperId)) { return true; } else { return false; } }
public List<Scores> SelectAll() { using (SqlConnection conn = DBHelp.GetConnection()) { string sql = @"select ID,Score.UserID,PaperID,Score,ExamTime,JudgeTime,Users.UserName from Score,Users where Score.UserID=Users.UserID"; SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = sql; conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); List<Scores> list = new List<Scores>(); while (dr.Read()) { Users user = new Users(); Scores scores = new Scores(); scores.ID = Convert.ToInt32(dr["ID"]); scores.UserID = dr["UserID"].ToString(); user.UserName = dr["UserName"].ToString(); scores.UserName = user.UserName; scores.PaperID = Convert.ToInt32(dr["PaperID"]); scores.Score = Convert.ToInt32(dr["Score"]); scores.ExamTime = Convert.ToDateTime(dr["ExamTime"]); scores.JudgeTime = Convert.ToDateTime(dr["JudgeTime"]); list.Add(scores); } dr.Close(); conn.Close(); return list; } }
public List<Scores> SelectUserScores(string userID) { using (SqlConnection conn = DBHelp.GetConnection()) { string sql = @"select * from Score where Score.userID = '" + userID + "'"; SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = sql; conn.Open(); SqlDataReader sdr = cmd.ExecuteReader(); List<Scores> list = new List<Scores>(); while (sdr.Read()) { Scores score = new Scores(); score.ID= Convert.ToInt32(sdr["ID"]); score.PaperID = Convert.ToInt32(sdr["PaperID"]); score.Score = Convert.ToInt32(sdr["Score"]); score.ExamTime = Convert.ToDateTime(sdr["ExamTime"]); score.JudgeTime = Convert.ToDateTime(sdr["JudgeTime"]); score.UserID = sdr["UserID"].ToString(); score.UserName = SelectUserName(score.UserID); list.Add(score); } sdr.Close(); conn.Close(); return list; } }