public int SubmitHomework(Homework hw) { try { cmd = new SqlCommand(); cmd.CommandText = "INSERT INTO Homework(childId, assignmentId, date, diskName) VALUES(@childId, @assignmentId, @date, @diskName)"; cmd.Parameters.AddWithValue("childId", hw.Child.Id); cmd.Parameters.AddWithValue("assignmentId", hw.Assignment.Id); cmd.Parameters.AddWithValue("date", hw.Date); cmd.Parameters.AddWithValue("diskName", hw.DiskName); dbCon = new DbConnection(); cmd.Connection = dbCon.GetConnection(); cmd.Connection.Open(); cmd.CommandType = CommandType.Text; result = cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { cmd.Connection.Close(); } return result; }
public int SubmitHomework(int childId, int assignmentId, DateTime date, string diskName) { Homework hw = new Homework(); hw.Child = new Person(childId); hw.Assignment = new Assignment(assignmentId); hw.Date = date; hw.DiskName = diskName; hwDb = new HomeworkDb(); return hwDb.SubmitHomework(hw); }
public int SubmitHomework(int childId, int assignmentId, DateTime date, string diskName) { UserCtrl userCtrl = new UserCtrl(); Homework hw = new Homework(); hw.Child = (Child)userCtrl.GetPerson(childId); hw.Assignment = new Assignment(assignmentId); hw.Date = date; hw.DiskName = diskName; HomeworkDb hwDb = new HomeworkDb(); return hwDb.SubmitHomework(hw); }
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 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; }
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; }
private Homework BuildHomework(SqlDataReader dr) { Homework hw = null; try { hw = new Homework(); hw.Id = Convert.ToInt32(dr["hid"]); hw.Child = new Person(Convert.ToInt32(dr["childId"])); hw.Assignment = new Assignment(Convert.ToInt32(dr["assignmentId"])); hw.Date = Convert.ToDateTime(dr["date"]); hw.DiskName = (dr["diskName"].ToString()); } catch { throw; } return hw; }