private int SortParent(PostParent parent1, PostParent parent2) { string parent1_string = ""; parent1_string += parent1.IsParentRead ? "00000" : "11111"; parent1_string += !string.IsNullOrEmpty(parent1.account) ? "00000" : "11111"; parent1_string += parent1.className.PadLeft(10, '0'); parent1_string += parent1.seatNo.PadLeft(10, '0'); parent1_string += parent1.StudentName.PadLeft(10, '0'); string parent2_string = ""; parent2_string += parent2.IsParentRead ? "00000" : "11111"; parent2_string += !string.IsNullOrEmpty(parent2.account) ? "00000" : "11111"; parent2_string += parent2.className.PadLeft(10, '0'); parent2_string += parent2.seatNo.PadLeft(10, '0'); parent2_string += parent2.StudentName.PadLeft(10, '0'); return(parent1_string.CompareTo(parent2_string)); }
/// <summary> /// 設定已讀數 & 發送數 /// </summary> private void SetSendCount(List <string> noticeIDList, List <MessageLogRecord> messageList) { //取得學生記錄 StudentDic = GetStudent(messageList); totalCount = DataManager.TotalCount(); foreach (MessageLogRecord _record in messageList) { if (_record.studentList.Count > 0) { //建立學生基本資料 foreach (string stud_id in _record.studentList) { if (StudentDic.ContainsKey(stud_id)) { StudRecord stud = StudentDic[stud_id]; if (!_record.CheckStudentReadDic.ContainsKey(stud_id)) { _record.CheckStudentReadDic.Add(stud_id, new PostStudent(stud)); } } } //取得學生讀取記錄 StringBuilder sb_sql = new StringBuilder(); sb_sql.Append("select ref_notice_id,ref_student_id,ref_parent_id,time from $ischool.1campus.notice_log notice_log "); sb_sql.Append(string.Format("where ref_notice_id='{0}' ", _record.notice_id)); sb_sql.Append(string.Format("and ref_student_id in ('{0}') ", string.Join("','", _record.studentList))); //家長是空值 , 老師是空值 sb_sql.Append("and ref_parent_id is null and ref_teacher_id is null"); DataTable dt = tool._Q.Select(sb_sql.ToString()); foreach (DataRow row in dt.Rows) { string ref_student_id = "" + row["ref_student_id"]; if (_record.CheckStudentReadDic.ContainsKey(ref_student_id)) { _record.CheckStudentReadDic[ref_student_id].IsStudentRead = true; string time = "" + row["time"]; _record.CheckStudentReadDic[ref_student_id].IsStudentReadTime = time; } } } //需有家長才取得家長讀取記錄 if (_record.parentList.Count > 0) { //取得目前學生所關連之家長個人資料 StringBuilder sb_sParent_sql = new StringBuilder(); sb_sParent_sql.Append(string.Format("select * from student_parent where id in ('{0}')", string.Join("','", _record.parentList))); DataTable dtsParent = tool._Q.Select(sb_sParent_sql.ToString()); foreach (DataRow row in dtsParent.Rows) { string ref_student_id = "" + row["ref_student_id"]; if (!_record.CheckParentReadDic.ContainsKey(ref_student_id)) { _record.CheckParentReadDic.Add(ref_student_id, new Dictionary <string, PostParent>()); } if (StudentDic.ContainsKey(ref_student_id)) { PostParent parent = new PostParent(row, StudentDic[ref_student_id]); _record.CheckParentReadDic[ref_student_id].Add(parent.parent_id, parent); } } //取得家長讀取記錄 StringBuilder sb_parent_sql = new StringBuilder(); sb_parent_sql.Append("select ref_notice_id,ref_student_id,ref_parent_id,time from $ischool.1campus.notice_log notice_log "); sb_parent_sql.Append(string.Format("where notice_log.ref_notice_id='{0}' ", _record.notice_id)); sb_parent_sql.Append(string.Format("and notice_log.ref_parent_id in ('{0}') ", string.Join("','", _record.parentList))); sb_parent_sql.Append("and ref_parent_id is not null and ref_teacher_id is null "); sb_parent_sql.Append("order by time"); DataTable dt_parent = tool._Q.Select(sb_parent_sql.ToString()); foreach (DataRow row in dt_parent.Rows) { string ref_parent_id = "" + row["ref_parent_id"]; string ref_student_id = "" + row["ref_student_id"]; string time = "" + row["time"]; if (_record.CheckParentReadDic.ContainsKey(ref_student_id)) { if (_record.CheckParentReadDic[ref_student_id].ContainsKey(ref_parent_id)) { _record.CheckParentReadDic[ref_student_id][ref_parent_id].IsParentRead = true; if (string.IsNullOrEmpty(_record.CheckParentReadDic[ref_student_id][ref_parent_id].IsParentReadTime)) { _record.CheckParentReadDic[ref_student_id][ref_parent_id].IsParentReadTime = time; } } } } } } }