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