/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.CMS_ActionLog model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into CMS_ActionLog("); strSql.Append("Name,Description,Time,Type)"); strSql.Append(" values ("); strSql.Append("@Name,@Description,@Time,@Type)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Name", SqlDbType.VarChar, 50), new SqlParameter("@Description", SqlDbType.VarChar, 100), new SqlParameter("@Time", SqlDbType.VarChar, 50), new SqlParameter("@Type", SqlDbType.VarChar, 50) }; parameters[0].Value = model.Name; parameters[1].Value = model.Description; parameters[2].Value = model.Time; parameters[3].Value = model.Type; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.CMS_ActionLog model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update CMS_ActionLog set "); strSql.Append("Name=@Name,"); strSql.Append("Description=@Description,"); strSql.Append("Time=@Time,"); strSql.Append("Type=@Type"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Name", SqlDbType.VarChar, 50), new SqlParameter("@Description", SqlDbType.VarChar, 100), new SqlParameter("@Time", SqlDbType.VarChar, 50), new SqlParameter("@Type", SqlDbType.VarChar, 50), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.Name; parameters[1].Value = model.Description; parameters[2].Value = model.Time; parameters[3].Value = model.Type; parameters[4].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.CMS_ActionLog GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,Name,Description,Time,Type from CMS_ActionLog "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; Maticsoft.Model.CMS_ActionLog model = new Maticsoft.Model.CMS_ActionLog(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Id"].ToString() != "") { model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString()); } model.Name = ds.Tables[0].Rows[0]["Name"].ToString(); model.Description = ds.Tables[0].Rows[0]["Description"].ToString(); model.Time = ds.Tables[0].Rows[0]["Time"].ToString(); model.Type = ds.Tables[0].Rows[0]["Type"].ToString(); return(model); } else { return(null); } }