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