/// <summary> /// 增加一条数据 /// </summary> public int Add(BCW.HB.Model.ChatMe model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_ChatMe("); strSql.Append("ChatID,UserID,State,jointime,score)"); strSql.Append(" values ("); strSql.Append("@ChatID,@UserID,@State,@jointime,@score)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@ChatID", SqlDbType.Int, 4), new SqlParameter("@UserID", SqlDbType.Int, 4), new SqlParameter("@State", SqlDbType.Int, 4), new SqlParameter("@jointime", SqlDbType.DateTime), new SqlParameter("@score", SqlDbType.Decimal, 9) }; parameters[0].Value = model.ChatID; parameters[1].Value = model.UserID; parameters[2].Value = model.State; parameters[3].Value = model.jointime; parameters[4].Value = model.score; object obj = SqlHelper.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public BCW.HB.Model.ChatMe GetModel(int ID, int uid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,ChatID,UserID,State,jointime,score from tb_ChatMe "); strSql.Append(" where ChatID=@ChatID and UserID=@uid "); SqlParameter[] parameters = { new SqlParameter("@ChatID", SqlDbType.Int, 4), new SqlParameter("@uid", SqlDbType.Int, 4) }; parameters[0].Value = ID; parameters[1].Value = uid; BCW.HB.Model.ChatMe model = new BCW.HB.Model.ChatMe(); DataSet ds = SqlHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public BCW.HB.Model.ChatMe DataRowToModel(DataRow row) { BCW.HB.Model.ChatMe model = new BCW.HB.Model.ChatMe(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["ChatID"] != null && row["ChatID"].ToString() != "") { model.ChatID = int.Parse(row["ChatID"].ToString()); } if (row["UserID"] != null && row["UserID"].ToString() != "") { model.UserID = int.Parse(row["UserID"].ToString()); } if (row["State"] != null && row["State"].ToString() != "") { model.State = int.Parse(row["State"].ToString()); } if (row["jointime"] != null && row["jointime"].ToString() != "") { model.jointime = DateTime.Parse(row["jointime"].ToString()); } if (row["score"] != null && row["score"].ToString() != "") { model.score = decimal.Parse(row["score"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(BCW.HB.Model.ChatMe model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_ChatMe set "); strSql.Append("ChatID=@ChatID,"); strSql.Append("UserID=@UserID,"); strSql.Append("State=@State,"); strSql.Append("jointime=@jointime,"); strSql.Append("score=@score"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ChatID", SqlDbType.Int, 4), new SqlParameter("@UserID", SqlDbType.Int, 4), new SqlParameter("@State", SqlDbType.Int, 4), new SqlParameter("@jointime", SqlDbType.DateTime), new SqlParameter("@score", SqlDbType.Decimal, 9), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.ChatID; parameters[1].Value = model.UserID; parameters[2].Value = model.State; parameters[3].Value = model.jointime; parameters[4].Value = model.score; parameters[5].Value = model.ID; int rows = SqlHelper.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }