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); }
public ListForObjects GetAllAssignmentsByTeacherId(int teacherId) { ListForObjects al = new ListForObjects(); try { comm = new SqlCommand(); comm.CommandText = "SELECT * FROM Assignment WHERE pid = " + teacherId; dbCon = new DbConnection(); comm.Connection = dbCon.GetConnection(); comm.Connection.Open(); comm.CommandType = CommandType.Text; SqlDataReader dr = comm.ExecuteReader(); while (dr.Read()) { Assignment a = new Assignment(); a.Id = Convert.ToInt32(dr["aid"]); a.exercise = Convert.ToString(dr["exercise"]); a.date = Convert.ToDateTime(dr["date"]); a.deadline = Convert.ToDateTime(dr["deadLine"]); a.subject = Convert.ToString(dr["subject"]); Teacher t = new Teacher(); t.Id = Convert.ToInt32(dr["pid"]); a.teacher = t; a.title = Convert.ToString(dr["title"]); al.AddObj(a); } } catch (Exception) { throw; } finally { comm.Connection.Close(); } return(al); }