利用ListBox做消息群发

前段时间利用listbox控件做了一个消息群发,单个发送功能
前台页面:
<form id="form1" runat="server">
  <div class="tilte_z">当前位置:发送消息</div>
  <div>
    <table width="100%" border="0" cellpadding="6" cellspacing="1" id="content">
      <tr class="top">
        <td width=103 height=20 align="right" valign="top" class="padding_zy"> 收件人:</td>
        <td align=left valign="top" class="padding_zy" style="width: 505px">&nbsp;&nbsp;
          <table style="position: relative" align="left">
            <tr>
              <td class="padding_zy" style="width: 100px"> 部门:
                <asp:DropDownList ID="DllBuMen" runat="server" Width="103px"
                        AutoPostBack="True" onselectedindexchanged="DllBuMen_SelectedIndexChanged" > </asp:DropDownList>
              </td>
              <td>&nbsp;</td>
              <td><span class="padding_zy" style="width: 100px">已选人员</span></td>
            </tr>
            <tr>
              <td rowspan="4" class="padding_zy" style="width: 100px;"><asp:ListBox ID="ListLeftPerson" runat="server" Height="101px" Width="306px" SelectionMode="Multiple"></asp:ListBox></td>
              <td class="padding_zy" style="width: 37px;"><asp:ImageButton ID="BtnRight1" runat="server" ImageUrl="images/sel1.gif" OnClick="BtnRight1_Click"
                                 /></td>
              <td rowspan="4" class="padding_zy" style="width: 100px; height: 72px;"><asp:ListBox ID="ListRightPerson" runat="server" Height="101px" Width="306px" SelectionMode="Multiple"></asp:ListBox></td>
            </tr>
            <tr>
              <td class="padding_zy" style="width: 37px;"><asp:ImageButton ID="BtnLeft1" runat="server" ImageUrl="images/sel2.gif" OnClick="BtnLeft1_Click"
                                  /></td>
            </tr>
            <tr>
              <td class="padding_zy" style="width: 37px;"><asp:ImageButton ID="BtnRight2" runat="server" ImageUrl="images/sel3.gif" OnClick="BtnRight2_Click"
                                  /></td>
            </tr>
            <tr>
              <td class="padding_zy" style="width: 37px;"><asp:ImageButton ID="BtnLeft2" runat="server" ImageUrl="images/sel4.gif" OnClick="BtnLeft2_Click"
                                  /></td>
            </tr>
          </table></td>
      </tr>
      <tr>
        <td width="103" height="33" align="right" valign="top" bgcolor="#FFFFFF" class="padding_zy" >消息主题:</td>
        <td width="1085" valign="top" bgcolor="#FFFFFF" class="padding_zy" ><input name="txTitle" type="text" id="txTitle" style="width:492px;" runat="server" />
          &nbsp;</td>
      </tr>
      <tr>
        <td width="103" height="33" align="right" valign="top" bgcolor="#FFFFFF" class="padding_zy"  >消息内容:</td>
        <td width="1085" valign="top" bgcolor="#FFFFFF" class="padding_zy" ><textarea name="txContent" rows="900000" cols="20"  id="txContent"  style="height:220px;width:510px;" runat="server"></textarea></td>
      </tr>
      <tr>
        <td height="33" colspan="2" align="right" bgcolor="#FFFFFF" class="padding_zy" > 
          <div style="text-align:center;">
            <asp:Button CssClass="btns"  ID="btnSend" runat="server" Text="立即发送" οnclick="btnSend_Click"  />
            <asp:Button CssClass="btns"  ID="btnreset" runat="server" Text="重置"  οnclick="btnreset_Click"  />
          </div></td>
      </tr>
    </table>
  </div>
</form>

后台代码:
 protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindBuMen();
                BindPerson();
            }

        }
        List<string> list = new List<string>();
        /// <summary>
        /// 立即发送
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSend_Click(object sender, EventArgs e)
        {
            //接收标题
            string title = this.txTitle.Value.Trim();
            //取消息内容
            string xiaoxiContent = this.txContent.Value.Trim();
            //取接收人,
           string jieshouren = this.ListRightPerson.SelectedValue;
           if (title == null || title == "")
            {
                Response.Write("<script>alert('标题不能为空!')</script>");
                this.txTitle.Focus();
                return;
            }
            else if (xiaoxiContent == null || xiaoxiContent == "")
            {
                Response.Write("<script>alert('消息内容不能为空!')</script>");
                return;
            }
            else
            {
                //调用发消息的方法
                Poucan.BLL.AdminMessage bll = new Poucan.BLL.AdminMessage();
                Poucan.Model.AdminMessage model = new Poucan.Model.AdminMessage();
                model.Message = txContent.Value.Trim();
                model.messageTitle = txTitle.Value.Trim();
                model.addtime = DateTime.Now;
                model.Operator = PageBase.getUsersName();   //获得当前登录人
             

                for (int j = 0; j < this.ListRightPerson.Items.Count; j++)
                {
  
                  jieshouren = this.ListRightPerson.Items[j].Value;
                   model.Sort = "10";//系统消息
                   model.Status = "未读";
                   model.Customer = jieshouren;
                   list.Add(bll.strAdd(model));
                }
             
                if (DbHelperSQL.ExecuteSqlTran(list) > 0)
                {
                    Response.Write("<script>alert('发送成功!');window.location='XiaoXiDetail.aspx'</script>");
                }
                else
                {
                    Response.Write("<script>alert('发送失败!')</script>");

                }
            }
        
        }

        /// <summary>
        /// 绑定部门
        /// </summary>
        private void BindBuMen()
        {
            this.DllBuMen.DataSource = XiaoXiManager.GetDept();
            DllBuMen.DataValueField = "deptid";
            DllBuMen.DataTextField = "deptname";
            DllBuMen.DataBind();
            DllBuMen.Items.Insert(0, new ListItem("--请选择部门--", "0"));
        }

        /// <summary>
        /// 获取所有的人员加载到listbox中去
        /// </summary>
        private void BindPerson()
        {
            this.ListLeftPerson.DataSource = XiaoXiManager.GetAllUsers();
            ListLeftPerson.DataTextField = "userID";
            ListLeftPerson.DataTextField = "loginid";
            ListLeftPerson.DataBind();

        }

        /// <summary>
        /// 根据不同部门选择显示不同部门下面的人员
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void DllBuMen_SelectedIndexChanged(object sender, EventArgs e)
        {
            string Dutyid = DllBuMen.SelectedItem.Value.ToString();
            ListLeftPerson.DataSource = XiaoXiManager.GetLoginIDByDeptID(Dutyid);
            ListLeftPerson.DataTextField = "loginid";
            ListLeftPerson.DataValueField = "loginid";
            ListLeftPerson.DataBind();

        }

        /// <summary>
        /// 点击左边的人员到右边
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnRight1_Click(object sender, ImageClickEventArgs e)
        {

            ListLeftPerson.SelectionMode = ListSelectionMode.Multiple;
            ArrayList arrRight = new ArrayList();
            foreach (ListItem item in this.ListLeftPerson.Items) //按类型listitem读取listbox中选定项
            {
                if (item.Selected) //判断是否选中
                {
                    arrRight.Add(item);
                }
            }

            //右边添加
            foreach (ListItem item in arrRight)
            {
                this.ListRightPerson.Items.Add(item);
              
            }

        }
        /// <summary>
        /// 点击右边的人员移除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnLeft1_Click(object sender, ImageClickEventArgs e)
        {
            ListRightPerson.Items.Clear();
            ListRightPerson.SelectionMode = ListSelectionMode.Multiple;

        }
        /// <summary>
        /// 点击左边的所有人员到右边:实现全选操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnRight2_Click(object sender, ImageClickEventArgs e)
        {
          
            foreach (ListItem item in ListLeftPerson.Items)
            {
                if (!ListRightPerson.Items.Contains(item))
                    ListRightPerson.Items.Add(item);
            }
        }


        /// <summary>
        ///清除所有
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnLeft2_Click(object sender, ImageClickEventArgs e)
        {
            ListRightPerson.Items.Clear();
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值