Esempio n. 1
0
        public Child GetChild(Person p)
        {
            comm = new SqlCommand();
            comm.CommandText = "SELECT * FROM Child WHERE pid=(@pid)";
            comm.Parameters.AddWithValue("pid", p.Id);
            dbCon = new DbConnection();
            comm.Connection = dbCon.GetConnection();
            comm.Connection.Open();

            comm.CommandType = CommandType.Text;
            SqlDataReader dr = comm.ExecuteReader();

            if (dr.Read() && dr.HasRows)
            {
                Child child = new Child();
                child.Email = p.Email;
                child.Id = p.Id;
                child.Name = p.Name;
                child.Password = p.Password;
                child.Phone = p.Phone;
                child.UserName = p.UserName;
                child.UserType = p.UserType;
                child.Grade = dr["grade"].ToString();
                return child;
            }
            else
            {
                comm.Connection.Close();
                return null;
            }
        }
Esempio n. 2
0
        public Object GetPerson(Person p)
        {
            comm = new SqlCommand();
            comm.CommandText = "SELECT * FROM Person WHERE pid=(@personId)";
            comm.Parameters.AddWithValue("personId", p.Id);
            dbCon = new DbConnection();
            comm.Connection = dbCon.GetConnection();
            comm.Connection.Open();

            comm.CommandType = CommandType.Text;
            SqlDataReader dr = comm.ExecuteReader();

            if (dr.Read() && dr.HasRows)
            {
                Person pers = new Person();
                pers.UserType = Convert.ToInt32(dr["userType"]);

                if (pers.UserType == 1)
                {
                    Teacher teacher = new Teacher();
                    teacher.Id = Convert.ToInt32(dr["pid"]);
                    teacher.Name = dr["name"].ToString();
                    teacher.Email = dr["email"].ToString();
                    teacher.Phone = dr["phone"].ToString();
                    teacher.Subject = dr["subject"].ToString();

                    comm.Connection.Close();
                    return teacher;
                }
                else
                {
                    Child child = new Child();
                    child.Id = Convert.ToInt32(dr["pid"]);
                    child.Name = dr["name"].ToString();
                    child.Email = dr["email"].ToString();
                    child.Phone = dr["phone"].ToString();
                    child.Grade = dr["grade"].ToString();

                    comm.Connection.Close();
                    return child;
                }
            }
            else
            {
                comm.Connection.Close();
                return null;
            }
        }
Esempio n. 3
0
        public List<Homework> GetAllHomeworksByChildId(int childId)
        {
            List<Homework> hwList = new List<Homework>();

            try
            {
                comm = new SqlCommand();
                comm.CommandText = "SELECT * FROM Homework WHERE childId = " + childId;

                dbCon = new DbConnection();
                comm.Connection = dbCon.GetConnection();
                comm.Connection.Open();

                comm.CommandType = CommandType.Text;
                SqlDataReader dr = comm.ExecuteReader();

                while (dr.Read())
                {
                    Homework hw = new Homework();
                    hw.DiskName = dr["diskName"].ToString();
                    hw.Date = Convert.ToDateTime(dr["date"]);
                    Child child = new Child();
                    child.Id = Convert.ToInt32(dr["childId"]);
                    hw.Child = child;

                    hwList.Add(hw);
                    }
            }
            catch (Exception)
            {
                throw;
            }

            finally
            {
                comm.Connection.Close();
            }

            return hwList;
        }
Esempio n. 4
0
        public ListForObjects GetAllHomeworksById(int assignmentId)
        {
            ListForObjects homeworkList = new ListForObjects();
            try
            {
                comm = new SqlCommand();
                comm.CommandText = "SELECT * FROM Homework WHERE assignmentId = " + assignmentId;

                dbCon = new DbConnection();
                comm.Connection = dbCon.GetConnection();
                comm.Connection.Open();

                comm.CommandType = CommandType.Text;
                SqlDataReader dr = comm.ExecuteReader();

                while (dr.Read())
                {
                    Homework h = new Homework();
                    h.Id = Convert.ToInt32(dr["hid"]);
                    Assignment a = new Assignment();
                    a.Id = Convert.ToInt32(dr["assignmentId"]);
                    h.Assignment = a;
                    Child c = new Child();
                    c.Id = Convert.ToInt32(dr["childId"]);
                    h.Child = c;
                    h.Date = Convert.ToDateTime(dr["date"]);
                    h.DiskName = Convert.ToString(dr["diskName"]);
                    homeworkList.AddObj(h);
                }

            }
            catch (Exception)
            {

                throw;
            }

            finally
            {
                comm.Connection.Close();
            }
            return homeworkList;
        }
Esempio n. 5
0
        public Homework GetHomeworkById(int id)
        {
            try
            {
                comm = new SqlCommand();
                comm.CommandText = "SELECT * FROM Homework WHERE hid = " + id;

                dbCon = new DbConnection();
                comm.Connection = dbCon.GetConnection();
                comm.Connection.Open();

                comm.CommandType = CommandType.Text;
                SqlDataReader dr = comm.ExecuteReader();

                while (dr.Read())
                {
                    Homework h = new Homework();
                    h.Id = Convert.ToInt32(dr["hid"]);
                    Assignment a = new Assignment();
                    a.Id = Convert.ToInt32(dr["aid"]);
                    h.Assignment = a;
                    Child c = new Child();
                    c.Id = Convert.ToInt32(dr["childId"]);
                    h.Child = c;
                    h.Date = Convert.ToDateTime(dr["date"]);
                    h.DiskName = Convert.ToString(dr["diskName"]);
                    return h;
                }

            }
            catch (Exception)
            {

                throw;
            }

            finally
            {
                comm.Connection.Close();
            }
            return null;
        }