protected void Button1_Click(object sender, EventArgs e) { if (this.TextArea1.InnerText == "") this.Label1.Text = "不能发空微博"; else { MsgInfo msgInfo = new MsgInfo(); string msg = this.TextArea1.InnerText; msgInfo.Content = msg; msgInfo.UserID = Int32.Parse(HttpContext.Current.User.Identity.Name); msgInfo.Type = 1; msgInfo.CommentedCount = 0; msgInfo.CommentCount = 0; msgInfo.TransferCount = 0; msgInfo.CommentedCount = 0; msgInfo.Time = DateTime.Now; int i = MsgBLL.Insert(msgInfo); this.Label1.Text = i.ToString(); this.TextArea1.InnerText = ""; } }
public static bool Check(MsgInfo msgInfo) { return true; }
/// <summary> /// 往MsgInfo表内添加新记录 /// </summary> /// <param name="entity">MsgInfo实体对象</param> /// <returns>添加记录索引值</returns> public static int Insert(MsgInfo entity) { return MsgDAL.Insert(entity); }
/// <summary> /// 更新MsgInfo表记录 /// </summary> /// <param name="entity">MsgInfo实体对象</param> public void Update(MsgInfo entity) { MsgDAL.Update(entity); }
/// <summary> /// 生成MsgInfo实体对象 /// </summary> private static MsgInfo CreateMsgInfo(IDataReader rdr) { MsgInfo myMsgInfo = new MsgInfo(); myMsgInfo.UserID = DBConvert.GetInt32(rdr, "UserID"); myMsgInfo.Content = DBConvert.GetString(rdr, "Content"); myMsgInfo.Type = DBConvert.GetByte(rdr, "Type"); myMsgInfo.CommentedCount = DBConvert.GetInt32(rdr, "CommentedCount"); myMsgInfo.CommentCount = DBConvert.GetInt32(rdr, "CommentCount"); myMsgInfo.TransferedCount = DBConvert.GetInt32(rdr, "TransferedCount"); myMsgInfo.TransferCount = DBConvert.GetInt32(rdr, "TransferCount"); myMsgInfo.Time = DBConvert.GetDateTime(rdr, "Time"); return myMsgInfo; }
/// <summary> /// 更新MsgInfo表记录 /// </summary> /// <param name="msgInfo">MsgInfo实体对象</param> public static void Update(MsgInfo msgInfo) { //创建Database对象 Database db = DatabaseFactory.CreateDatabase(); //创建DbCommand对象 DbCommand dbCommand = db.GetSqlStringCommand(@"UPDATE MsgInfo SET Content = @Content, Type = @Type, CommentedCount = @CommentedCount, CommentCount = @CommentCount, TransferedCount = @TransferedCount, TransferCount = @TransferCount, Time = @Time WHERE UserID=@UserID"); //添加输入输出参数 db.AddInParameter(dbCommand, "@UserID", DbType.Int32, msgInfo.UserID); db.AddInParameter(dbCommand, "@Content", DbType.String, msgInfo.Content); db.AddInParameter(dbCommand, "@Type", DbType.Byte, msgInfo.Type); db.AddInParameter(dbCommand, "@CommentedCount", DbType.Int32, msgInfo.CommentedCount); db.AddInParameter(dbCommand, "@CommentCount", DbType.Int32, msgInfo.CommentCount); db.AddInParameter(dbCommand, "@TransferedCount", DbType.Int32, msgInfo.TransferedCount); db.AddInParameter(dbCommand, "@TransferCount", DbType.Int32, msgInfo.TransferCount); db.AddInParameter(dbCommand, "@Time", DbType.DateTime, msgInfo.Time); db.ExecuteNonQuery(dbCommand); }
/// <summary> /// 往MsgInfo表内添加新记录 /// </summary> /// <param name="msgInfo">MsgInfo实体对象</param> /// <returns>添加记录索引值</returns> public static int Insert(MsgInfo msgInfo) { //创建Database对象 Database db = DatabaseFactory.CreateDatabase(); //创建DbCommand对象 DbCommand dbCommand = db.GetSqlStringCommand(@"INSERT INTO MsgInfo(UserID,Content,Type,CommentedCount,CommentCount,TransferedCount,TransferCount,Time) VALUES(@UserID,@Content,@Type,@CommentedCount,@CommentCount,@TransferedCount,@TransferCount,@Time) SELECT SCOPE_IDENTITY()"); //添加输入输出参数 db.AddInParameter(dbCommand, "@UserID", DbType.Int32, msgInfo.UserID); db.AddInParameter(dbCommand, "@Content", DbType.String, msgInfo.Content); db.AddInParameter(dbCommand, "@Type", DbType.Byte, msgInfo.Type); db.AddInParameter(dbCommand, "@CommentedCount", DbType.Int32, msgInfo.CommentedCount); db.AddInParameter(dbCommand, "@CommentCount", DbType.Int32, msgInfo.CommentCount); db.AddInParameter(dbCommand, "@TransferedCount", DbType.Int32, msgInfo.TransferedCount); db.AddInParameter(dbCommand, "@TransferCount", DbType.Int32, msgInfo.TransferCount); db.AddInParameter(dbCommand, "@Time", DbType.DateTime, msgInfo.Time); //返回新添加记录索引 return int.Parse("0" + db.ExecuteScalar(dbCommand)); //db.ExecuteNonQuery(dbCommand); }