public MainViewModel() { try { productCommands = new ProductCommands(_connectionString); Products.AddRange(productCommands.GetList()); ProdCategoryCommands prodCategoryCommands = new ProdCategoryCommands(_connectionString); ProdCategories.AddRange(prodCategoryCommands.GetList()); LocationCommands locationCommands = new LocationCommands(_connectionString); Locations.AddRange(locationCommands.GetList()); LocCategoryCommands locCategoryCommands = new LocCategoryCommands(_connectionString); LocationCategories.AddRange(locCategoryCommands.GetList()); UnitCommands unitCommands = new UnitCommands(_connectionString); Units.AddRange(unitCommands.GetList()); UpdateAppStatus($"Database tables fetched.", Brushes.DarkGreen); } catch (Exception ex) { UpdateAppStatus($"Error on retrieving tables from SQL database:\n{ex.Message}", Brushes.Red); } GenerateTableProductsToDisplay(); InitializeAllPropertyFields(); Scheduler(); }
public void GenerateTableProductsToDisplay() { var prodcatDictionary = ProdCategories.ToDictionary(cat => cat.ProdCategoryId); var locDictionary = Locations.ToDictionary(loc => loc.LocationId); var locCatDictionary = LocationCategories.ToDictionary(locCat => locCat.LocCategoryId); var unitDictionary = Units.ToDictionary(u => u.UnitId); foreach (var product in Products) { ProductModelAllTablesMerged productModelAllTablesMerged = new ProductModelAllTablesMerged { ProductId = product.ProductId, ProductName = product.ProductName, Description = product.Description, ProdCategoryId = product.ProdCategoryId, LocationId = product.LocationId, GetInDate = product.GetInDate, BestBefore = product.BestBefore, Quantity = product.Quantity, UnitId = product.UnitId }; prodcatDictionary.TryGetValue(productModelAllTablesMerged.ProdCategoryId, out ProdCategoryModel prodcat); productModelAllTablesMerged.ProdCatName = prodcat.ProdCatName; locDictionary.TryGetValue(productModelAllTablesMerged.LocationId, out LocationModel loc); productModelAllTablesMerged.LocationName = loc.LocationName; locCatDictionary.TryGetValue(loc.LocCategoryId, out LocationCategoryModel locCat); productModelAllTablesMerged.LocCatName = locCat.LocCatName; productModelAllTablesMerged.LocCatId = locCat.LocCategoryId; unitDictionary.TryGetValue(productModelAllTablesMerged.UnitId, out UnitModel unit); productModelAllTablesMerged.UnitName = unit.UnitName; productModelAllTablesMerged.ColorSet = ColorDataBestBeforeColumn(productModelAllTablesMerged); ProductsAllTablesMerged.Add(productModelAllTablesMerged); //ToDo: notifyproperty? Is the gridview refreshed really? Test it! } }