<%@ Page Title="" Language="C#" MasterPageFile="~/Manager.Master" CodeBehind="ManagerSendMessage.aspx.cs" Inherits="TeacherFiles.ManagerSendMessage" EnableEventValidation="false"%>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolderContent" runat="server">
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
var lstboxAllTeachersID = "#"+'<%=lstboxAllTeachers.ClientID%>';
var lstboxSelectdTeachersID="#"+'<%=lstboxSelectdTeachers.ClientID%>';
var imabtnSendMessageID="#"+'<%=imabtnSendMessage.ClientID%>';
var hiddenFileID="#"+'<%=HiddenField1.ClientID%>';
$('fieldset ul li img').click(function(){
var options;
var remove;
// 把选择项追加给对方
if($(this).attr("alt")=="arrowAdd")
{
options= $(lstboxAllTeachersID+" option:selected");
remove=options.remove();
remove.appendTo(lstboxSelectdTeachersID);
}
// 把选择项退回给对方
if($(this).attr("alt")=="arrowDelete")
{
options=$(lstboxSelectdTeachersID+" option:selected");
remove=options.remove();
remove.appendTo(lstboxAllTeachersID);
}
// 把全部追加给对方
if($(this).attr("alt")=="selectAll")
{
options=$(lstboxAllTeachersID+' option');
remove=options.remove();
remove.appendTo(lstboxSelectdTeachersID);
}
// 把全部项退回给对方
if($(this).attr("alt")=="Reset")
{
options=$(lstboxSelectdTeachersID+' option');
remove=options.remove();
remove.appendTo(lstboxAllTeachersID);
}
});
// 获取教师工号
function getSeletedTeacherNum()
{
var lstStaffs = document.getElementById('<%=lstboxSelectdTeachers.ClientID%>');
var strStaffs = "";
for (var i = 0; i < lstStaffs.options.length; i++) {
strStaffs +=lstStaffs.options[i].value+",";
}
$(hiddenFileID).val(strStaffs);
}
// 当点击发送按钮
$(imabtnSendMessageID).click(function(){
getSeletedTeacherNum()
});
});
</script>
<form>
<fieldset class="fieldset">
<legend class="legend">选择需要得到通知的教师</legend>
<ul>
<li>
<span>
<asp:ListBox ID="lstboxAllTeachers" runat="server"
CssClass="listbox"></asp:ListBox>
</span>
<img src="images/ArrowAdd.jpg" alt="arrowAdd" class="imagarrowAdd" />
<img src="images/ArrowDelete.jpg" alt="arrowDelete" class="imagarrowDelete" />
<span><asp:ListBox ID="lstboxSelectdTeachers" runat="server"
CssClass="listbox"></asp:ListBox></span>
<asp:HiddenField ID="HiddenField1" runat="server"/>
</li>
<li>
<span>
<img src="images/selectAll.jpg" alt="selectAll" />
</span>
<span>
<img src="images/Reset.jpg" alt="Reset" />
</span>
</li>
</ul>
</fieldset>
<br />
<fieldset class="fieldset">
<legend class="legend">需要发送的消息</legend>
<ul>
<li>
<asp:TextBox ID="txtContent" runat="server" TextMode="MultiLine" Width="380px"
Height="180px" CssClass="txtbox"></asp:TextBox>
</li>
<li>
<span>
<asp:ImageButton ID="imabtnSendMessage" runat="server"
ImageUrl="~/images/SendMessage.jpg" onclick="imabtnSendMessage_Click"/>
</span>
<span>
<asp:ImageButton ID="imagbtnResetContent" runat="server"
ImageUrl="~/images/Reset.jpg" onclick="imagbtnResetContenet_Click"/>
</span>
</li>
</ul>
</fieldset>
</asp:Content>
后台
public partial class ManagerSendMessage : BasePage
{
ITeacher newIteacher = new TeacherService();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindListBoxAllTeachers();
}
}
public void BindListBoxAllTeachers()
{
this.lstboxAllTeachers.DataSource = newIteacher.ReadAllTeacher();
this.lstboxAllTeachers.DataTextField = "TeacherName";
this.lstboxAllTeachers.DataValueField = "TeacherNum";
this.lstboxAllTeachers.DataBind();
}
List<string> AllSelectedTeahcerNum = new List<string>();
// 得到选择的教师工号
public void SendSelectedTeahcerMessage(string[] singleNums)
{
for (int i = 0; i < singleNums.Count()-1; i++)
{
newIteacher.InsertReceiveMessage(singleNums[i].ToString(), this.txtContent.Text);
PageExtension.Alert(this, "发布成功!");
}
}
// 发送通知消息给选定的教师,
protected void imabtnSendMessage_Click(object sender, ImageClickEventArgs e)
{
string AllTheNum = this.HiddenField1.Value;
string[] singleNums = AllTheNum.Split(',');
SendSelectedTeahcerMessage(singleNums);
}
// 重置发送内容
protected void imagbtnResetContenet_Click(object sender, ImageClickEventArgs e)
{
this.txtContent.Text = "";
}
}