//private Building Update(Building obj) //{ // obj.ValidationErrors.Clear(); // try // { // Building objOld_ = Get(obj.ObjId); // if (obj.ObjVersion != objOld_.ObjVersion) // { // throw new Exception("object has been changed by another user"); // } // else // { // obj.ObjVersion = ++objOld_.ObjVersion; // } // String query = " UPDATE building_tab SET " + // " ObjVersion=" + obj.ObjVersion + "," + // " BuildingName='" + obj.BuildingName + "'" + // " WHERE ObjId=" + obj.ObjId; // if (ExcuteStatement(query)) // { // return obj; // } // else // { // obj.ValidationErrors.Add("Error While updating.."); // return obj; // } // } // catch (Exception ex) // { // throw; // } //} public DataTable GetAllSessions() { DataTable dt = new DataTable(); dt.Columns.Add("ObjId"); dt.Columns.Add("Session_Id"); dt.Columns.Add("Tag"); dt.Columns.Add("Subject_Name"); dt.Columns.Add("Subject_Code"); dt.Columns.Add("Student_Count"); dt.Columns.Add("Group_Id"); dt.Columns.Add("Lecturer"); dt.Columns.Add("Duration"); //string query = "SELECT st.ObjId,st.studentCount,st.duration,st.RefTagId,st.RefSubjectId,st.RefGroupId,st.RefSubGroupId ,tt.TagName,s.Name,s.Code,lt.Name LecturerName,semt.year,semt.semester,p.programmeName,sgt.GroupNo,'' SubGroupNo FROM session_tab st,session_lecturer_tab slt,lecturer_tab lt,subject_tab s,tag_tab tt,student_group_tab sgt,semester_tab semt,programme_tab p WHERE st.ObjId=slt.RefSessionId and st.RefSubjectId=s.ObjId and slt.RefLecturerId=lt.ObjId and st.RefTagId=tt.ObjId and st.RefGroupId=sgt.ObjId and sgt.RefSemesterId=semt.ObjId and sgt.RefProgrammeId=p.ObjId and UPPER(tt.TagName)<>'PRACTICAL' Union SELECT st.ObjId,st.studentCount,st.duration,st.RefTagId,st.RefSubjectId,st.RefGroupId,st.RefSubGroupId ,tt.Tagname,s.name,s.code,lt.Name,semt.year,semt.semester,p.programmeName,sgt.GroupNo,ssgt.SubGroupNo FROM session_tab st,session_lecturer_tab slt,lecturer_tab lt,subject_tab s,tag_tab tt,student_group_tab sgt,student_sub_group_tab ssgt,semester_tab semt,programme_tab p WHERE st.ObjId=slt.RefSessionId and st.RefSubjectId=s.ObjId and slt.RefLecturerId=lt.ObjId and st.RefTagId=tt.ObjId and st.RefSubGroupId=ssgt.ObjId and sgt.RefSemesterId=semt.ObjId and sgt.RefProgrammeId=p.ObjId and sgt.ObjId=ssgt.RefGroupId and UPPER(tt.TagName) ='PRACTICAL'"; string query = "SELECT st.ObjId,st.studentCount,st.duration,st.RefTagId,st.RefSubjectId,st.RefGroupId,st.RefSubGroupId ,tt.TagName,s.Name,s.Code,semt.year,semt.semester,p.programmeName,sgt.GroupNo,'' SubGroupNo FROM session_tab st,session_lecturer_tab slt,subject_tab s,tag_tab tt,student_group_tab sgt,semester_tab semt,programme_tab p WHERE st.ObjId=slt.RefSessionId and st.RefSubjectId=s.ObjId and st.RefTagId=tt.ObjId and st.RefGroupId=sgt.ObjId and sgt.RefSemesterId=semt.ObjId and sgt.RefProgrammeId=p.ObjId and UPPER(tt.TagName)<>'PRACTICAL' Union SELECT st.ObjId,st.studentCount,st.duration,st.RefTagId,st.RefSubjectId,st.RefGroupId,st.RefSubGroupId ,tt.Tagname,s.name,s.code,semt.year,semt.semester,p.programmeName,sgt.GroupNo,ssgt.SubGroupNo FROM session_tab st,session_lecturer_tab slt,subject_tab s,tag_tab tt,student_group_tab sgt,student_sub_group_tab ssgt,semester_tab semt,programme_tab p WHERE st.ObjId=slt.RefSessionId and st.RefSubjectId=s.ObjId and st.RefTagId=tt.ObjId and st.RefSubGroupId=ssgt.ObjId and sgt.RefSemesterId=semt.ObjId and sgt.RefProgrammeId=p.ObjId and sgt.ObjId=ssgt.RefGroupId and UPPER(tt.TagName) ='PRACTICAL'"; DataRow row; if (this.OpenConnection() == true) { //Create Command MySqlCommand cmd = new MySqlCommand(query, connection); MySqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { row = dt.NewRow(); row["ObjId"] = int.Parse(dataReader["ObjId"].ToString()); row["Session_Id"] = int.Parse(dataReader["ObjId"].ToString()); row["Tag"] = dataReader["TagName"].ToString(); row["Subject_Name"] = dataReader["Name"].ToString(); row["Subject_Code"] = dataReader["Code"].ToString(); if (dataReader["TagName"].ToString().ToUpper().Equals("PRACTICAL")) { row["Group_Id"] = "Y" + dataReader["Year"].ToString() + ".S" + dataReader["Semester"].ToString() + "." + dataReader["ProgrammeName"].ToString() + "." + dataReader["GroupNo"].ToString() + "." + dataReader["SubGroupNo"].ToString(); } else { row["Group_Id"] = "Y" + dataReader["Year"].ToString() + ".S" + dataReader["Semester"].ToString() + "." + dataReader["ProgrammeName"].ToString() + "." + dataReader["GroupNo"].ToString(); } DataTable dtLecturers = new SessionLecturerAPI().Main_View(int.Parse(dataReader["ObjId"].ToString())); String lecturersLst = ""; foreach (DataRow item in dtLecturers.Rows) { lecturersLst = lecturersLst + item["Name"].ToString() + ";"; } row["Lecturer"] = lecturersLst; row["Student_Count"] = dataReader["StudentCount"].ToString(); row["Duration"] = double.Parse(dataReader["Duration"].ToString()); dt.Rows.Add(row); } //close Data Reader dataReader.Close(); //close Connection this.CloseConnection(); //return list to be displayed return(dt); } else { return(dt); } }
private SessionType Validate(SessionType obj) { List <int> CommonLst = new List <int>(); List <int> temp = new List <int>(); if (obj.ConType == "P") { for (int i = 0; i < obj.SessionLst.Count; i++) { List <SessionLecturer> lecLst = new SessionLecturerAPI().GetAll(obj.SessionLst[i].ObjId); for (int j = 0; j < lecLst.Count; j++) { CommonLst.Add(lecLst[j].RefLecturerId); } } if (CommonLst.Count != CommonLst.Distinct().ToList().Count) { obj.ValidationErrors.Add("Same lecturer(s) cannot be appeared in parallel sessions"); return(obj); } CommonLst.Clear(); //group validation for (int i = 0; i < obj.SessionLst.Count; i++) { if (obj.SessionLst[i].Tag == "PRACTICAL") { CommonLst.Add(obj.SessionLst[i].RefSubGroupId); } else { List <StudentSubGroup> sgLst = new StudentSubGroupAPI().GetSubGoups(obj.SessionLst[i].RefGroupId); foreach (StudentSubGroup item in sgLst) { CommonLst.Add(item.ObjId); } } } if (CommonLst.Count != CommonLst.Distinct().ToList().Count) { obj.ValidationErrors.Add("Cannot have common Student Group/Sub Group in parallel sessions"); return(obj); } CommonLst.Clear(); for (int i = 0; i < obj.SessionLst.Count; i++) { temp = GetConnectedSessions(obj.SessionLst[i].ObjId, "C"); for (int j = 0; j < temp.Count; j++) { CommonLst.Add(temp[j]); } } if (CommonLst.Count != CommonLst.Distinct().ToList().Count) { obj.ValidationErrors.Add("Sessions already incuded with another consecutive session"); return(obj); } CommonLst.Clear(); for (int i = 0; i < obj.SessionLst.Count; i++) { temp = GetConnectedSessions(obj.SessionLst[i].ObjId, "O"); for (int j = 0; j < temp.Count; j++) { CommonLst.Add(temp[j]); } } if (CommonLst.Count != CommonLst.Distinct().ToList().Count) { obj.ValidationErrors.Add("Sessions already incuded with another non overlaping session"); return(obj); } return(obj); } else { for (int i = 0; i < obj.SessionLst.Count; i++) { if (obj.ConType == "C") { temp = GetConnectedSessions(obj.SessionLst[i].ObjId, "P"); } else if (obj.ConType == "P") { temp = GetConnectedSessions(obj.SessionLst[i].ObjId, "C"); } else if (obj.ConType == "O") { temp = GetConnectedSessions(obj.SessionLst[i].ObjId, "P"); } for (int j = 0; j < temp.Count; j++) { CommonLst.Add(temp[j]); } } if (CommonLst.Count != CommonLst.Distinct().ToList().Count) { String info = ""; if (obj.ConType == "C") { info = "Sessions already incuded with another parallel session"; } else if (obj.ConType == "P") { info = "Sessions already incuded with another consecutive session"; } else if (obj.ConType == "O") { info = "Sessions already incuded with another non overlaping session"; } obj.ValidationErrors.Add(info); return(obj); } else { return(obj); } } }