//发送消息 protected void SendMessage(string msg, string rec_id, string time) { Messages m = new Messages(); MessagesDal d = new MessagesDal(); m.Msg_con = msg; if ((rec_id == null) || (rec_id == "")) { } else { m.Msg_rec = Convert.ToInt32(rec_id); } m.Msg_send = Convert.ToInt32(Session["userid"]); m.Msg_sendTime = Convert.ToDateTime(time); d.Insert(m); Response.Write("success"); }
//获取消息 //protected void GetMessage() //{ // MessagesDal dd = new MessagesDal(); // DataTable dt1 = dd.GetMessage(); // for (int i = 0; i < dt1.Rows.Count; i++) // { // if (Convert.ToString(Session["userid"]) == Convert.ToString(dt1.Rows[i]["Msg_send"])) // { // Response.Write(@"<li><p class='time'><span>"+ dt1.Rows[i]["Msg_sendTime"]+ "</span></p><div class='main'><img class='avatar' width='30' height='30' src='Images/2.png'><div class='text'>"+dt1.Rows[i]["Msg_con"]+"</div></div></li>"); // } // else // { // Response.Write(@"<li><p class='time'><span>" + dt1.Rows[i]["Msg_sendTime"] + "</span></p><div class='main self'><img class='avatar' width='30' height='30' src='Images/2.png'><div class='text'>" + dt1.Rows[i]["Msg_con"] + "</div></div></li>"); } // } //} //获取对应消息 protected void GetMessage(string rec_id) { MessagesDal dd = new MessagesDal(); DataTable dt1 = dd.GetMessage(rec_id, Convert.ToInt32(Session["userid"])); for (int i = 0; i < dt1.Rows.Count; i++) { DateTime date1 = Convert.ToDateTime(dt1.Rows[i]["Msg_sendTime"]); if (Convert.ToString(Session["userid"]) == Convert.ToString(dt1.Rows[i]["Msg_send"])) { Response.Write(@"<li><p class='time'><span>" + date1.TimeOfDay + "</span></p><div class='main'><img class='avatar' width='30' height='30' src='Images/2.png'><div class='text'>" + dt1.Rows[i]["Msg_con"] + "</div></div></li>"); } else { Response.Write(@"<li><p class='time'><span>" + dt1.Rows[i]["Msg_sendTime"] + "</span></p><div class='main self'><img class='avatar' width='30' height='30' src='Images/2.png'><div class='text'>" + dt1.Rows[i]["Msg_con"] + "</div><span class='chat-list-name'> " + dt1.Rows[i]["NickName"] + "</span></div></li>"); } } }