Exemple #1
0
        public List <Score> getScore(string Condition)
        {
            string       sql;
            DataTable    tb     = null;
            List <Score> scores = new List <Score>();

            if (Condition == null || Condition.Equals(""))
            {
                sql = "SELECT * FROM score";
                tb  = MysqlHelper.ExecuteDataTable(sql);
                if (tb.Rows.Count > 0)
                {
                    foreach (DataRow dr in tb.Rows)
                    {
                        Score score = new Score();
                        score.Id = dr["ID"].ToString();
                        int userId = Int32.Parse(dr["UserId"].ToString());
                        //score.User = (new UserDBHelper()).getUser(userId, (short)RoleType.studentCheckbox);
                        score.SubOne = float.Parse(dr["SubOne"].ToString());
                        score.SubTwo = float.Parse(dr["SubTwo"].ToString());
                        score.Score1 = float.Parse(dr["Score"].ToString());
                        score.Date   = DateTime.Parse(dr["date"].ToString());
                        scores.Add(score);
                    }
                }
            }
            else
            {
                UserDBHelper db    = new UserDBHelper();
                List <User>  users = db.getUser(Condition, RoleType.studentCheckbox);
                foreach (User user in users)
                {
                    MySqlParameter[] pars = null;
                    sql = "SELECT * FROM score WHERE UserId = @Param1";
                    MySqlParameter p1 = new MySqlParameter("@Param1", MySqlDbType.String);
                    p1.Value = user.Id;
                    pars     = new MySqlParameter[] { p1 };
                    tb       = MysqlHelper.ExecuteDataTable(sql, pars);
                    if (tb.Rows.Count > 0)
                    {
                        foreach (DataRow dr in tb.Rows)
                        {
                            Score score = new Score();
                            score.Id     = dr["ID"].ToString();
                            score.User   = user;
                            score.SubOne = float.Parse(dr["SubOne"].ToString());
                            score.SubTwo = float.Parse(dr["SubTwo"].ToString());
                            score.Score1 = float.Parse(dr["Score"].ToString());
                            score.Date   = DateTime.Parse(dr["date"].ToString());
                            scores.Add(score);
                        }
                    }
                }
            }
            MysqlHelper.CloseConn();
            return(scores);
        }