public static List <ProductStatistic> GetHotProduct(int currentPage) { try { SqlConnection con = DatabaseFactory.GetConnection(DatabaseFactory.SQL_TYPE_MSSQL).GetConnection(); List <ProductStatistic> listProductReturn = new List <ProductStatistic>(); SqlCommand command = new SqlCommand(); command.Connection = con; command.CommandText = "Statistics_hotproduct"; command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@number", currentPage); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { ProductStatistic product = new ProductStatistic(reader.GetInt32(2)); product.ProductName = reader.GetString(0); product.ProductId = reader.GetInt32(1); listProductReturn.Add(product); } reader.Close(); return(listProductReturn); } catch (Exception ex) { throw new Exception("Current page isnt exit, please check again !!!!! "); } }
private void SetContexts(int productID) { try { DisplayedProduct = databaseHandler.GetProduct(productID); ProductStats = databaseHandler.GetProductSalesDetails(productID); } catch (NullReferenceException e) { Console.WriteLine(e.Message); } nameGrid.DataContext = DisplayedProduct; carDetailsGrid.DataContext = DisplayedProduct; productDetailsGrid.DataContext = DisplayedProduct; if (!(ProductStats.AmountSold == 0)) { statisticsGrid.IsEnabled = true; statisticsGrid.DataContext = ProductStats; } else { statisticsGrid.IsEnabled = false; } if (DisplayedProduct.Quantity == 0) { updateAvailabilityButton.IsEnabled = false; } else { updateAvailabilityButton.IsEnabled = true; } }