Ejemplo n.º 1
0
        public List <UWProjectQ3.Clss> GetAllClasses()
        {
            conn.Open();

            try
            {
                List <Clss> AllClasses = new List <Clss>();
                using (SqlCommand cmd = new SqlCommand("SELECT * FROM " + ConfigurationManager.AppSettings["AllClasses"], conn))
                {
                    SqlDataReader sqlrdr = cmd.ExecuteReader();
                    while (sqlrdr.Read())
                    {
                        int      a  = (int)sqlrdr["ClassId"];
                        string   b  = sqlrdr["ClassName"].ToString();
                        DateTime c  = (DateTime)sqlrdr["ClassDate"];
                        String   d  = sqlrdr["ClassDescription"].ToString();
                        Clss     cl = new Clss(a, b, c, d);
                        AllClasses.Add(cl);
                    }
                }
                return(AllClasses);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error retrieving all available classes.");
                throw (ex);
            }
            finally
            {
                conn.Close();
                //conn.Dispose();
            }
        }
Ejemplo n.º 2
0
        public void GetUserClasses(User u)
        {
            conn.Open();

            try
            {
                using (SqlCommand cmd = new SqlCommand(ConfigurationManager.AppSettings["GetStudentClass"], conn))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@StudentId", u.StudentId);

                    SqlDataReader sqlrdr = cmd.ExecuteReader();
                    while (sqlrdr.Read())
                    {
                        int      stuId     = (int)sqlrdr["StudentId"];
                        string   StuName   = sqlrdr["StudentName"].ToString();
                        string   StuEmail  = sqlrdr["StudentEmail"].ToString();
                        int      ClassId   = (int)sqlrdr["ClassId"];
                        string   ClassName = sqlrdr["ClassName"].ToString();
                        DateTime ClassDt   = (DateTime)sqlrdr["ClassDate"];
                        string   ClassDesc = sqlrdr["ClassDescription"].ToString();
                        Clss     cl        = new Clss(ClassId, ClassName, ClassDt, ClassDesc);
                        u.RegisteredClasses.Add(ClassId, cl);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error retrieving all available classes.");
                throw (ex);
            }
            finally
            {
                conn.Close();
                conn.Dispose();
            }
        }