/// <summary> /// 获取48小时内联系过的用户 /// </summary> /// <param name="UserID"></param> /// <returns></returns> public Cms.Model.XT_ChatLog[] GetUserList() { ArrayList list = new ArrayList(); string username = ""; DataTable dt = DbHelperSQL.Query("select * from wx_info").Tables[0]; if (dt.Rows.Count > 0) { username = dt.Rows[0]["wxid"].ToString(); } SqlDataReader rd = DbHelperSQL.ExecuteReader("select distinct sendusername from xt_chatlog where createtime > GETDATE() - 2 and createtime < GETDATE() and sendusername!='" + username + "' "); try { while (rd.Read()) { Cms.Model.XT_ChatLog cl = new Cms.Model.XT_ChatLog(); cl.SendUserName = rd["sendusername"].ToString(); list.Add(cl); } } catch { throw; } finally { rd.Close(); rd.Dispose(); } return((Cms.Model.XT_ChatLog[])list.ToArray(typeof(Cms.Model.XT_ChatLog))); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Cms.Model.XT_ChatLog model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update XT_ChatLog set "); strSql.Append("FromUserName=@FromUserName,"); strSql.Append("Worker=@Worker,"); strSql.Append("ToUserName=@ToUserName,"); strSql.Append("SendUserName=@SendUserName,"); strSql.Append("OperCode=@OperCode,"); strSql.Append("Time=@Time,"); strSql.Append("MsgContent=@MsgContent,"); strSql.Append("Remark=@Remark,"); strSql.Append("CreateTime=@CreateTime"); strSql.Append(" where Chatid=@Chatid"); SqlParameter[] parameters = { new SqlParameter("@FromUserName", SqlDbType.NVarChar, 100), new SqlParameter("@Worker", SqlDbType.NVarChar, 100), new SqlParameter("@ToUserName", SqlDbType.NVarChar, 100), new SqlParameter("@SendUserName", SqlDbType.NVarChar, 100), new SqlParameter("@OperCode", SqlDbType.NVarChar, 10), new SqlParameter("@Time", SqlDbType.NVarChar, 100), new SqlParameter("@MsgContent", SqlDbType.Text), new SqlParameter("@Remark", SqlDbType.NVarChar, 200), new SqlParameter("@CreateTime", SqlDbType.DateTime, 3), new SqlParameter("@Chatid", SqlDbType.Int, 4) }; parameters[0].Value = model.FromUserName; parameters[1].Value = model.Worker; parameters[2].Value = model.ToUserName; parameters[3].Value = model.SendUserName; parameters[4].Value = model.OperCode; parameters[5].Value = model.Time; parameters[6].Value = model.MsgContent; parameters[7].Value = model.Remark; parameters[8].Value = model.CreateTime; parameters[9].Value = model.Chatid; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Cms.Model.XT_ChatLog DataRowToModel(DataRow row) { Cms.Model.XT_ChatLog model = new Cms.Model.XT_ChatLog(); if (row != null) { if (row["Chatid"] != null && row["Chatid"].ToString() != "") { model.Chatid = int.Parse(row["Chatid"].ToString()); } if (row["FromUserName"] != null) { model.FromUserName = row["FromUserName"].ToString(); } if (row["Worker"] != null) { model.Worker = row["Worker"].ToString(); } if (row["ToUserName"] != null) { model.ToUserName = row["ToUserName"].ToString(); } if (row["SendUserName"] != null) { model.SendUserName = row["SendUserName"].ToString(); } if (row["OperCode"] != null) { model.OperCode = row["OperCode"].ToString(); } if (row["Time"] != null) { model.Time = row["Time"].ToString(); } if (row["MsgContent"] != null) { model.MsgContent = row["MsgContent"].ToString(); } if (row["Remark"] != null) { model.Remark = row["Remark"].ToString(); } if (row["CreateTime"] != null && row["CreateTime"].ToString() != "") { model.CreateTime = DateTime.Parse(row["CreateTime"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Cms.Model.XT_ChatLog model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into XT_ChatLog("); strSql.Append("FromUserName,Worker,ToUserName,SendUserName,OperCode,Time,MsgContent,Remark,CreateTime)"); strSql.Append(" values ("); strSql.Append("@FromUserName,@Worker,@ToUserName,@SendUserName,@OperCode,@Time,@MsgContent,@Remark,@CreateTime)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@FromUserName", SqlDbType.NVarChar, 100), new SqlParameter("@Worker", SqlDbType.NVarChar, 100), new SqlParameter("@ToUserName", SqlDbType.NVarChar, 100), new SqlParameter("@SendUserName", SqlDbType.NVarChar, 100), new SqlParameter("@OperCode", SqlDbType.NVarChar, 10), new SqlParameter("@Time", SqlDbType.NVarChar, 100), new SqlParameter("@MsgContent", SqlDbType.Text), new SqlParameter("@Remark", SqlDbType.NVarChar, 200), new SqlParameter("@CreateTime", SqlDbType.DateTime, 3) }; parameters[0].Value = model.FromUserName; parameters[1].Value = model.Worker; parameters[2].Value = model.ToUserName; parameters[3].Value = model.SendUserName; parameters[4].Value = model.OperCode; parameters[5].Value = model.Time; parameters[6].Value = model.MsgContent; parameters[7].Value = model.Remark; parameters[8].Value = model.CreateTime; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 根据用户获取聊天记录 /// </summary> /// <returns></returns> public Cms.Model.XT_ChatLog[] GetChatLogList(string FromUserName, string SendUserName) { ArrayList list = new ArrayList(); SqlParameter[] parameters = { new SqlParameter("@FromUserName", SqlDbType.NVarChar, 100), new SqlParameter("@SendUserName", SqlDbType.NVarChar, 100) }; parameters[0].Value = FromUserName; parameters[1].Value = SendUserName; SqlDataReader rd = DbHelperSQL.ExecuteReader("select chatid, FromUserName, worker, ToUserName,SendUserName,opercode, time, MsgContent, remark, createtime from xt_chatlog where FromUserName=@FromUserName and (SendUserName=@SendUserName or SendUserName=@FromUserName) and ToUserName=@SendUserName order by createtime asc", parameters); try { while (rd.Read()) { Cms.Model.XT_ChatLog cl = new Cms.Model.XT_ChatLog(); cl.SendUserName = rd["SendUserName"].ToString(); cl.ToUserName = rd["ToUserName"].ToString(); cl.MsgContent = rd["MsgContent"].ToString(); cl.CreateTime = Convert.ToDateTime(rd["createtime"]); list.Add(cl); } } catch { throw; } finally { rd.Close(); rd.Dispose(); } return((Cms.Model.XT_ChatLog[])list.ToArray(typeof(Cms.Model.XT_ChatLog))); }
/// <summary> /// 得到一个对象实体 /// </summary> public Cms.Model.XT_ChatLog GetModel(int Chatid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Chatid,FromUserName,Worker,ToUserName,SendUserName,OperCode,Time,MsgContent,Remark,CreateTime from XT_ChatLog "); strSql.Append(" where Chatid=@Chatid"); SqlParameter[] parameters = { new SqlParameter("@Chatid", SqlDbType.Int, 4) }; parameters[0].Value = Chatid; Cms.Model.XT_ChatLog model = new Cms.Model.XT_ChatLog(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }