/// <summary> /// 增加一条数据 /// </summary> public int Add(Hi.Model.BD_GoodsCustoms model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into [BD_GoodsCustoms]("); strSql.Append("[CompID],[Value],[ts],[modifyuser])"); strSql.Append(" values ("); strSql.Append("@CompID,@Value,@ts,@modifyuser)"); strSql.Append(";select @@Identity"); SqlParameter[] parameters = { new SqlParameter("@CompID", SqlDbType.Int), new SqlParameter("@Value", SqlDbType.VarChar, 50), new SqlParameter("@ts", SqlDbType.DateTime), new SqlParameter("@modifyuser", SqlDbType.Int) }; parameters[0].Value = model.CompID; if (model.Value != null) { parameters[1].Value = model.Value; } else { parameters[1].Value = DBNull.Value; } parameters[2].Value = model.ts; parameters[3].Value = model.modifyuser; return(SqlHelper.GetInt(SqlHelper.GetSingle(SqlHelper.LocalSqlServer, strSql.ToString(), parameters))); }
/// <summary> /// 由一行数据得到一个实体 /// </summary> private Hi.Model.BD_GoodsCustoms GetModel(DataRow r) { Hi.Model.BD_GoodsCustoms model = new Hi.Model.BD_GoodsCustoms(); model.ID = SqlHelper.GetInt(r["ID"]); model.CompID = SqlHelper.GetInt(r["CompID"]); model.Value = SqlHelper.GetString(r["Value"]); model.ts = SqlHelper.GetDateTime(r["ts"]); model.dr = SqlHelper.GetInt(r["dr"]); model.modifyuser = SqlHelper.GetInt(r["modifyuser"]); return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Hi.Model.BD_GoodsCustoms model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update [BD_GoodsCustoms] set "); strSql.Append("[CompID]=@CompID,"); strSql.Append("[Value]=@Value,"); strSql.Append("[ts]=@ts,"); strSql.Append("[dr]=@dr,"); strSql.Append("[modifyuser]=@modifyuser"); strSql.Append(" where [ID]=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int), new SqlParameter("@CompID", SqlDbType.Int), new SqlParameter("@Value", SqlDbType.VarChar, 50), new SqlParameter("@ts", SqlDbType.DateTime), new SqlParameter("@dr", SqlDbType.SmallInt), new SqlParameter("@modifyuser", SqlDbType.Int) }; parameters[0].Value = model.ID; parameters[1].Value = model.CompID; if (model.Value != null) { parameters[2].Value = model.Value; } else { parameters[2].Value = DBNull.Value; } parameters[3].Value = model.ts; parameters[4].Value = model.dr; parameters[5].Value = model.modifyuser; return(SqlHelper.ExecuteSql(SqlHelper.LocalSqlServer, strSql.ToString(), parameters) > 0); }