/// <summary> /// 得到一个对象实体 /// </summary> public Matisoft.Model.Comment DataRowToModel(DataRow row) { Matisoft.Model.Comment model=new Matisoft.Model.Comment(); if (row != null) { if(row["id"]!=null && row["id"].ToString()!="") { model.id=int.Parse(row["id"].ToString()); } if(row["Contents"]!=null) { model.Contents=row["Contents"].ToString(); } if(row["CustomerID"]!=null && row["CustomerID"].ToString()!="") { model.CustomerID=int.Parse(row["CustomerID"].ToString()); } if(row["CommentState"]!=null && row["CommentState"].ToString()!="") { model.CommentState=int.Parse(row["CommentState"].ToString()); } if(row["TimeDate"]!=null && row["TimeDate"].ToString()!="") { model.TimeDate=DateTime.Parse(row["TimeDate"].ToString()); } } return model; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Matisoft.Model.Comment model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Comment set "); strSql.Append("Contents=@Contents,"); strSql.Append("CustomerID=@CustomerID,"); strSql.Append("CommentState=@CommentState,"); strSql.Append("TimeDate=@TimeDate"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@Contents", SqlDbType.NVarChar, 200), new SqlParameter("@CustomerID", SqlDbType.Int, 4), new SqlParameter("@CommentState", SqlDbType.Int, 4), new SqlParameter("@TimeDate", SqlDbType.DateTime), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.Contents; parameters[1].Value = model.CustomerID; parameters[2].Value = model.CommentState; parameters[3].Value = model.TimeDate; parameters[4].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Matisoft.Model.Comment model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Comment("); strSql.Append("Contents,CustomerID,CommentState,TimeDate)"); strSql.Append(" values ("); strSql.Append("@Contents,@CustomerID,@CommentState,@TimeDate)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Contents", SqlDbType.NVarChar, 200), new SqlParameter("@CustomerID", SqlDbType.Int, 4), new SqlParameter("@CommentState", SqlDbType.Int, 4), new SqlParameter("@TimeDate", SqlDbType.DateTime) }; parameters[0].Value = model.Contents; parameters[1].Value = model.CustomerID; parameters[2].Value = model.CommentState; parameters[3].Value = model.TimeDate; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Matisoft.Model.Comment DataRowToModel(DataRow row) { Matisoft.Model.Comment model = new Matisoft.Model.Comment(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["Contents"] != null) { model.Contents = row["Contents"].ToString(); } if (row["CustomerID"] != null && row["CustomerID"].ToString() != "") { model.CustomerID = int.Parse(row["CustomerID"].ToString()); } if (row["CommentState"] != null && row["CommentState"].ToString() != "") { model.CommentState = int.Parse(row["CommentState"].ToString()); } if (row["TimeDate"] != null && row["TimeDate"].ToString() != "") { model.TimeDate = DateTime.Parse(row["TimeDate"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Matisoft.Model.Comment GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,Contents,CustomerID,CommentState,TimeDate from Comment "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Matisoft.Model.Comment model = new Matisoft.Model.Comment(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Matisoft.Model.Comment GetModel(int id) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 id,Contents,CustomerID,CommentState,TimeDate from Comment "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4) }; parameters[0].Value = id; Matisoft.Model.Comment model=new Matisoft.Model.Comment(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }