public List<Maticsoft.Model.Shop.Products.ProductAttribute> DataTableToList(DataTable dt) { List<Maticsoft.Model.Shop.Products.ProductAttribute> list = new List<Maticsoft.Model.Shop.Products.ProductAttribute>(); int count = dt.Rows.Count; if (count > 0) { for (int i = 0; i < count; i++) { Maticsoft.Model.Shop.Products.ProductAttribute item = new Maticsoft.Model.Shop.Products.ProductAttribute(); if ((dt.Rows[i]["ProductId"] != null) && (dt.Rows[i]["ProductId"].ToString() != "")) { item.ProductId = long.Parse(dt.Rows[i]["ProductId"].ToString()); } if ((dt.Rows[i]["AttributeId"] != null) && (dt.Rows[i]["AttributeId"].ToString() != "")) { item.AttributeId = long.Parse(dt.Rows[i]["AttributeId"].ToString()); } if ((dt.Rows[i]["ValueId"] != null) && (dt.Rows[i]["ValueId"].ToString() != "")) { item.ValueId = int.Parse(dt.Rows[i]["ValueId"].ToString()); } list.Add(item); } } return list; }
public Maticsoft.Model.Shop.Products.ProductAttribute GetModel(long ProductId, long AttributeId, int ValueId) { StringBuilder builder = new StringBuilder(); builder.Append("SELECT TOP 1 ProductId,AttributeId,ValueId FROM Shop_ProductAttributes "); builder.Append(" WHERE ProductId=@ProductId and AttributeId=@AttributeId and ValueId=@ValueId "); SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@ProductId", SqlDbType.BigInt, 8), new SqlParameter("@AttributeId", SqlDbType.BigInt, 8), new SqlParameter("@ValueId", SqlDbType.Int, 4) }; cmdParms[0].Value = ProductId; cmdParms[1].Value = AttributeId; cmdParms[2].Value = ValueId; Maticsoft.Model.Shop.Products.ProductAttribute attribute = new Maticsoft.Model.Shop.Products.ProductAttribute(); DataSet set = DbHelperSQL.Query(builder.ToString(), cmdParms); if (set.Tables[0].Rows.Count <= 0) { return null; } if ((set.Tables[0].Rows[0]["ProductId"] != null) && (set.Tables[0].Rows[0]["ProductId"].ToString() != "")) { attribute.ProductId = long.Parse(set.Tables[0].Rows[0]["ProductId"].ToString()); } if ((set.Tables[0].Rows[0]["AttributeId"] != null) && (set.Tables[0].Rows[0]["AttributeId"].ToString() != "")) { attribute.AttributeId = long.Parse(set.Tables[0].Rows[0]["AttributeId"].ToString()); } if ((set.Tables[0].Rows[0]["ValueId"] != null) && (set.Tables[0].Rows[0]["ValueId"].ToString() != "")) { attribute.ValueId = int.Parse(set.Tables[0].Rows[0]["ValueId"].ToString()); } return attribute; }