示例#1
0
 // Returns all products from a given category
 //public static List<Product> MasterProductList //Returns All Products
 //{
 //    get
 //    {
 //        if (masterProductList == null)
 //        {
 //            masterProductList = new List<Product>();
 //            DataTable dt = DB.GetProductTable();
 //            foreach (DataRow row in dt.Rows)
 //            {
 //                Product P = new Product((int)row["ProductID"], (string)row["ProductName"], (int)row["CategoryID"], (string)row["QuantityPerUnit"], (decimal)row["UnitPrice"], (int)(short)row["UnitsInStock"], (string)row["PictureFileName"]);
 //                masterProductList.Add(P);
 //            }
 //        }
 //        return masterProductList;
 //    }
 //}
 public static List<Product> CategoryProductList(int CategoryID)
 {
     if (categoryList == null)
     {
         categoryList = new List<Product>();
         DataTable dt = DB.GetProductTable(CategoryID);
         foreach (DataRow row in dt.Rows)
         {
             Product P = new Product((int)row["ProductID"], (string)row["ProductName"], (int)row["CategoryID"], (string)row["QuantityPerUnit"], (decimal)row["UnitPrice"], (int)(short)row["UnitsInStock"], row["PictureFileName"] == DBNull.Value ? null : (string)row["PictureFileName"]);
             categoryList.Add(P);
         }
     }
     else if (categoryList[0].CategoryID != CategoryID)
     {
         categoryList = new List<Product>();
         DataTable dt = DB.GetProductTable(CategoryID);
         foreach (DataRow row in dt.Rows)
         {
             Product P = new Product((int)row["ProductID"], (string)row["ProductName"], (int)row["CategoryID"], (string)row["QuantityPerUnit"], (decimal)row["UnitPrice"], (int)(short)row["UnitsInStock"], row["PictureFileName"] == DBNull.Value ? null : (string)row["PictureFileName"]);
             categoryList.Add(P);
         }
     }
     return categoryList;
 }
示例#2
0
 public static List<Product> GetSearchItems(string SearchTerm)
 {
     List<Product> SearchResults = new List<Product>();
     DataTable RawSearch = DB.GetProduct(SearchTerm);
     foreach (DataRow row in RawSearch.Rows)
     {
         Product P = new Product((int)row["ProductID"], (string)row["ProductName"], (int)row["CategoryID"], (string)row["QuantityPerUnit"], (decimal)row["UnitPrice"], (int)(short)row["UnitsInStock"], row["PictureFileName"] == DBNull.Value ? null : (string)row["PictureFileName"]);
         SearchResults.Add(P);
     }
     return SearchResults;
 }
示例#3
0
 public static Product GetProduct(int ProductID)
 {
     Product P;
     //get from db
     DataRow dr = DBLoveleenJames.DB.GetProduct(ProductID);
     string filename = dr["PictureFileName"] == DBNull.Value ? null : (string)dr["PictureFileName"];
     P = new Product(ProductID, (string)dr["ProductName"], (int)dr["CategoryID"], (string)dr["QuantityPerUnit"], (decimal)dr["UnitPrice"], (int)(short)dr["UnitsInStock"], filename);
     return P;
 }