protected void BtnSubmit_Click(object sender, EventArgs e) { errormsg.Text = ""; try { CY.GFive.Core.Business.Note message = new CY.GFive.Core.Business.Note(); CY.GFive.Core.Business.NoteRange usermessage; if (MessageTitle.Text.Trim() == "") { errormsg.Text = "公告标题不能为空"; return; } if (string.IsNullOrEmpty(MessageContent.Value.Trim()) || MessageContent.Value.Trim().Length > 100000) { errormsg.Text = "内容不可以为空,长度只能为1到100000"; return; } message.NoteTitle = MessageTitle.Text.Trim(); message.NoteContent = Server.HtmlEncode(MessageContent.Value.Trim()); message.NoteDate = System.DateTime.Now; CY.GFive.Core.Business.StaffInfo st = GetUser(); if (st != null) { message.PulisherKey = st.Id; if (st.Moudle != null) message.PulishModule = st.Moudle.Id; } if (ddl_IsPub.SelectedValue == "") { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "error", "<script>alert('是否为公告不能为空!')</script>"); return; } if (ddl_IsPub.SelectedValue == "1" || ddl_IsPub.SelectedValue == "2") { if (ddl_IsFront.SelectedValue == "3") { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "error", "<script>alert('请选择是否在前台显示!')</script>"); return; } } message.NoteType = int.Parse(ddl_IsPub.SelectedValue); if (ddl_IsFront.SelectedValue == "1") { message.IsFront = true; } else { message.IsFront = false; } message.Save(); if (ddl_IsPub.SelectedValue.Equals("0")) { if (tb_UserIDs.Text.Trim().Equals("")) { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "AddFailed!", "<script>alert('消息发送对象不能为空!');</script>"); return; } string[] userIdList = tb_UserIDs.Text.Split(','); foreach (string item in userIdList) { usermessage = new CY.GFive.Core.Business.NoteRange(); usermessage.ReciverKey = int.Parse(item); usermessage.NoteKey = message.Id; usermessage.Save(); } } else if (ddl_IsPub.SelectedValue.Equals("2")) { if (tb_DepartCodes.Text.Trim().Equals("")) { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "AddFailed!", "<script>alert('消息发送对象不能为空!');</script>"); return; } string[] dCodeList = tb_DepartCodes.Text.Split(','); foreach (string item in dCodeList) { usermessage = new CY.GFive.Core.Business.NoteRange(); usermessage.ModuleKey = item; usermessage.NoteKey = message.Id; usermessage.Save(); } } else { IList<CY.GFive.Core.Business.StaffInfo> userlist = CY.GFive.Core.Business.StaffInfo.GetAllStaffInfo(); foreach (CY.GFive.Core.Business.StaffInfo u in userlist) { usermessage = new CY.GFive.Core.Business.NoteRange(); usermessage.ReciverKey = u.Id; usermessage.NoteKey = message.Id; usermessage.Save(); } } Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "短信息成功保存!", "<script>alert('保存成功!');</script>"); } catch (Exception ex) { errormsg.Text = ex.Message; } }
protected void btnSend_Click(object sender, EventArgs e) { tabid.Value = "1"; CheckBox cb; try { IList<string> teachercodelist = new List<string>(); for (int i = 0; i < gvteachercourse.Rows.Count; i++) { cb = (CheckBox)gvteachercourse.Rows[i].FindControl("chkSelect"); if (cb.Checked) { string teachername = gvteachercourse.DataKeys[i].Value.ToString().Trim(); string teachercode = gvteachercourse.Rows[i].Cells[2].Text; bool isexit = false; for (int k = 0; k < teachercodelist.Count; k++) { if (teachercodelist[k] == teachercode) { isexit = true; break; } } if (!isexit) { teachercodelist.Add(teachercode); CY.GFive.Core.Business.Note note = new CY.GFive.Core.Business.Note(); CY.GFive.Core.Business.NoteRange noterange = new CY.GFive.Core.Business.NoteRange(); string content = "" + teachername + "老师:\n\r"; content += " 您好,您本学期的课表如下:\n\r"; content += "<table border=\"1\" align=\"center\"><tr><td>课程</td><td>上课时间</td><td>教室</td><td>班级</td></tr>"; CY.GFive.Core.Business.StaffInfo teacher = CY.GFive.Core.Business.StaffInfo.GetInstance(teachercode); int teacherid = teacher.Id; IList<CY.GFive.Core.Business.CurriculmArrange> curriculmArrangelist = CY.GFive.Core.Business.CurriculmArrange.GetCurriculmArrangeByTeacherCodeAndTime(teachercode, year.ToString(), term); for (int j = 0; j < curriculmArrangelist.Count; j++) { teachercodelist.Add(curriculmArrangelist[j].TeacherCode); CY.GFive.Core.Business.ClassRoom classroom = CY.GFive.Core.Business.ClassRoom.SelectByCode(curriculmArrangelist[j].ClassRoomCode); string classroomaddress = classroom.Name; CY.GFive.Core.Business.Course course = CY.GFive.Core.Business.Course.GetByCode(curriculmArrangelist[j].CourseCode); string cousename = course.Name; CY.GFive.Core.Business.ClassInfo classinfo = CY.GFive.Core.Business.ClassInfo.GetByCode(curriculmArrangelist[j].ClassCode); string classcode = classinfo.ClassName; int coursetime = curriculmArrangelist[j].CourseTime; content += "<tr><td>" + cousename + "</td><td>" + creatcouseday(coursetime) + "</td><td>" + classroomaddress + "</td><td>" + classcode + "</td></tr>"; //content += "上课时间:" + creatcouseday(coursetime) + "" + creatcoursehour(coursetime) + " 地点:" + classroomaddress + " 课程:" + cousename + " 班级:" + classcode + "\n\r"; } content += "</table>"; content += "请打印或者保存好本消息!"; note.NoteTitle = "本学期课表"; note.NoteContent = content; note.NoteDate = System.DateTime.Now; note.NoteTimes = 0; note.Save(); noterange.NoteKey = note.Id; noterange.ReciverKey = teacherid; noterange.NoteState = 0; noterange.Save(); } } } Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('发送成功!');window.location.href='NoticeTeacher.aspx';</script>"); } catch (Exception ex) { //lbError.Text = ex.Message; //lbError.Visible = true; } }
protected void BtnModify_Click(object sender, EventArgs e) { errormsg.Text = ""; try { int id; if (int.TryParse(Request.QueryString["id"], out id)) { CY.GFive.Core.Business.Note message = CY.GFive.Core.Business.Note.Load(id); CY.GFive.Core.Business.NoteRange usermessage; if (message != null) { if (MessageTitle.Text.Trim() == "") { errormsg.Text = "公告标题不能为空"; return; } message.NoteTitle = MessageTitle.Text.Trim(); message.NoteContent = Server.HtmlEncode(MessageContent.Value); message.NoteType = int.Parse(ddl_IsPub.SelectedValue.ToString()); CY.GFive.Core.Business.StaffInfo st = GetUser(); if (st != null) { message.PulisherKey = st.Id;//Session["ManagerCode"].ToString(); if (st.Moudle != null) message.PulishModule = st.Moudle.Id;// message.User.Moudle.Id; } if (!(ddl_IsPub.SelectedValue.Equals("2"))) { if (tb_DepartCodes.Text != "") { IList<string> dList = tb_DepartCodes.Text.Split(',').ToList(); for (int d = 0; d < dList.Count(); d++) { if (!dList[d].Equals("")) { usermessage = CY.GFive.Core.Business.NoteRange.GetNoteRangeByNoteAndModule(id, dList[d].ToString()); if (usermessage != null) { usermessage.DeleteOnSave(); usermessage.Save(); } } } } string[] previousUserList = preUserList.Split(','); List<string> modifiedUserList = new List<string>(); if (ddl_IsPub.SelectedValue.Trim() == "0") { modifiedUserList = tb_UserIDs.Text.Split(',').ToList(); } else { IList<CY.GFive.Core.Business.StaffInfo> userslist = CY.GFive.Core.Business.StaffInfo.GetAllStaffInfo(); foreach (CY.GFive.Core.Business.StaffInfo u in userslist) { modifiedUserList.Add(u.Id.ToString()); } } List<string> intersectUserList = modifiedUserList.Intersect(previousUserList).ToList(); List<string> userListToDelete = previousUserList.Except(intersectUserList).ToList(); List<string> userListToAdd = modifiedUserList.Except(intersectUserList).ToList(); for (int i = 0; i < userListToDelete.Count(); i++) { if (!userListToDelete[i].Equals("")) { usermessage = CY.GFive.Core.Business.NoteRange.GetNoteRangeByNoteAndReciver(id, int.Parse(userListToDelete[i])); if (usermessage != null) { usermessage.DeleteOnSave(); usermessage.Save(); } } } for (int j = 0; j < userListToAdd.Count(); j++) { if (!userListToAdd[j].Equals("")) { usermessage = new CY.GFive.Core.Business.NoteRange();// { User_ID = int.Parse(userListToAdd[j]), Message_ID = id, UserMessage_State = 0 }; usermessage.ReciverKey = int.Parse(userListToAdd[j]); usermessage.NoteKey = id; usermessage.Save(); } } } else { if (tb_UserIDs.Text != "") { IList<string> uList = tb_UserIDs.Text.Split(',').ToList(); for (int u = 0; u < uList.Count(); u++) { if (!uList[u].Equals("")) { usermessage = CY.GFive.Core.Business.NoteRange.GetNoteRangeByNoteAndReciver(id, int.Parse(uList[u])); if (usermessage != null) { usermessage.DeleteOnSave(); usermessage.Save(); } } } } string[] previousDepartList = preDepartList.Split(','); List<string> modifiedDepartList = new List<string>(); modifiedDepartList = tb_DepartCodes.Text.Split(',').ToList(); List<string> intersectDepartList = modifiedDepartList.Intersect(previousDepartList).ToList(); List<string> departListToDelete = previousDepartList.Except(intersectDepartList).ToList(); List<string> departListToAdd = modifiedDepartList.Except(intersectDepartList).ToList(); for (int i = 0; i < departListToDelete.Count(); i++) { if (!departListToDelete[i].Equals("")) { usermessage = CY.GFive.Core.Business.NoteRange.GetNoteRangeByNoteAndModule(id, departListToDelete[i].ToString()); if (usermessage != null) { usermessage.DeleteOnSave(); usermessage.Save(); } } } for (int j = 0; j < departListToAdd.Count(); j++) { if (!departListToAdd[j].Equals("")) { usermessage = new CY.GFive.Core.Business.NoteRange();// { User_ID = int.Parse(userListToAdd[j]), Message_ID = id, UserMessage_State = 0 }; usermessage.ModuleKey = departListToAdd[j].ToString(); usermessage.NoteKey = id; usermessage.Save(); } } } if (ddl_IsFront.SelectedValue == "1") { message.IsFront = true; } else { message.IsFront = false; } message.Save(); Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "短信息更新删除!", "<script>alert('保存成功!');window.location.href='MessageDetail.aspx?id=" + id + "'</script>"); } else { errormsg.Text = "参数出错,该条信息可能已经被删除!"; } } else { errormsg.Text = "参数错误!"; } } catch (Exception ex) { errormsg.Text = ex.Message; } }