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