private void OnSelectionChangedExecute() { _stackPanel.Children.Clear(); if (SelectedYarnSpecification == null) { return; } IEnumerable <MerchantYarnPrice> yarnPrices = FabricModule.GetYarnPriceByYarnSpecificationNo(SelectedYarnSpecification.YarnSpecificationNo); //MerchantYarnPrices = new ObservableCollection<YarnPrice>(yarnPrices); MerchantYarnPrice merchantYarnPriceMax = yarnPrices.OrderByDescending(o => o.PiecePrice).FirstOrDefault(); MerchantYarnPrice merchantYarnPriceMin = yarnPrices.OrderBy(o => o.PiecePrice).FirstOrDefault(); MerchantYarnPrice merchantYarnPriceTime = yarnPrices.OrderByDescending(o => o.CreateDate).FirstOrDefault(); var merchantYarnPriceGroup = yarnPrices.GroupBy(g => g.YarnMerchant).ToDictionary(g => g.Key, g => g.ToList()); if (merchantYarnPriceMax != null || merchantYarnPriceMin != null || merchantYarnPriceTime != null) { CreateDataGrid(0, merchantYarnPriceMax, merchantYarnPriceMin, merchantYarnPriceTime, yarnPrices); foreach (var item in merchantYarnPriceGroup) { IEnumerable <MerchantYarnPrice> merchants = item.Value; CreateDataGrid(item.Key, merchants.OrderByDescending(o => o.PiecePrice).First(), merchants.OrderBy(o => o.PiecePrice).First(), merchants.OrderBy(o => o.CreateDate).First(), merchants); } } //RaisePropertyChanged("MerchantYarnPrices"); }
private void ButtonChangeYarn_Click(object sender, RoutedEventArgs e) { YarnSpecification yarnSpecification = DataGridYarnSpecification.SelectedItem as YarnSpecification; MerchantYarnPrice merchantYarnPrice = DataGridMerchantYarnPrice.SelectedItem as MerchantYarnPrice; SpecificationYarnPrice specificationYarnPrice = new SpecificationYarnPrice { YarnPriceNo = merchantYarnPrice.YarnPriceNo, Ingredient = yarnSpecification.Ingredient, Name = merchantYarnPrice.Name, Color = yarnSpecification.Color, YarnCount = yarnSpecification.YarnCount, YarnMerchant = merchantYarnPrice.YarnMerchant, Price = merchantYarnPrice.Price }; ChangeYarnExecute(specificationYarnPrice); }
private void CreateDataGrid(int yarnMerchentKey, MerchantYarnPrice max, MerchantYarnPrice min, MerchantYarnPrice late, IEnumerable <MerchantYarnPrice> merchantYarnPrices) { DataGrid dataGrid = new DataGrid { HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, AutoGenerateColumns = false, CanUserAddRows = false, Name = string.Concat("Group", yarnMerchentKey), Margin = new Thickness(5, 5, 5, 5) }; ControllerHelper.CreateDataGridTextColumn(dataGrid, "紗商", "Name", null); ControllerHelper.CreateDataGridTextColumn(dataGrid, "廠牌", "BrandName", null); ControllerHelper.CreateDataGridTextColumn(dataGrid, "單價", "Price", null); ControllerHelper.CreateDataGridTextColumn(dataGrid, "紗價", "PiecePrice", null); ControllerHelper.CreateDataGridTextColumn(dataGrid, "建立時間", "CreateDate", "{0:yy.MM.dd}"); dataGrid.ItemsSource = merchantYarnPrices; StackPanel stackPanel = new StackPanel(); #region 最大值 StackPanel stackPanelMax = new StackPanel { Background = new SolidColorBrush(Colors.LightYellow) }; Label labelMax = new Label { Content = string.Concat(" 最高價"), Background = new SolidColorBrush(Colors.LightGray) }; stackPanelMax.Children.Add(labelMax); Label labelMaxName = new Label { Content = string.Concat("紗商:", max.Name) }; stackPanelMax.Children.Add(labelMaxName); Label labelMaxBrandName = new Label { Content = string.Concat("廠牌:", max.BrandName) }; stackPanelMax.Children.Add(labelMaxBrandName); Label labelMaxPrice = new Label { Content = string.Concat("價格:", max.Price) }; stackPanelMax.Children.Add(labelMaxPrice); Label labelMaxDate = new Label { Content = string.Concat("建立時間:", max.CreateDate.ToShortDateString(), "\r\n", " ", max.CreateDate.ToLongTimeString()) }; stackPanelMax.Children.Add(labelMaxDate); stackPanel.Children.Add(stackPanelMax); #endregion #region 最小值 StackPanel stackPanelMin = new StackPanel { Background = new SolidColorBrush(Colors.LightBlue) }; Label labelMin = new Label { Content = string.Concat(" 最低價"), Background = new SolidColorBrush(Colors.LightGray) }; stackPanelMin.Children.Add(labelMin); Label labelMinName = new Label { Content = string.Concat("紗商:", min.Name) }; stackPanelMin.Children.Add(labelMinName); Label labelMinBrandName = new Label { Content = string.Concat("廠牌:", min.BrandName) }; stackPanelMin.Children.Add(labelMinBrandName); Label labelMinPrice = new Label { Content = string.Concat("價格:", min.Price) }; stackPanelMin.Children.Add(labelMinPrice); Label labelMinDate = new Label { Content = string.Concat("建立時間:", min.CreateDate.ToShortDateString(), "\r\n", " ", min.CreateDate.ToLongTimeString()) }; stackPanelMin.Children.Add(labelMinDate); stackPanel.Children.Add(stackPanelMin); #endregion #region 最新 StackPanel stackPanelLate = new StackPanel { Background = new SolidColorBrush(Colors.LightPink) }; Label labelLate = new Label { Content = string.Concat(" 最新"), Background = new SolidColorBrush(Colors.LightGray) }; stackPanelLate.Children.Add(labelLate); Label labellateName = new Label { Content = string.Concat("紗商:", late.Name) }; stackPanelLate.Children.Add(labellateName); Label labellateBrandName = new Label { Content = string.Concat("廠牌:", late.BrandName) }; stackPanelLate.Children.Add(labellateBrandName); Label labellatePrice = new Label { Content = string.Concat("價格:", late.Price) }; stackPanelLate.Children.Add(labellatePrice); Label labellateDate = new Label { Content = string.Concat("建立時間:", late.CreateDate.ToShortDateString(), "\r\n", " ", late.CreateDate.ToLongTimeString()) }; stackPanelLate.Children.Add(labellateDate); stackPanel.Children.Add(stackPanelLate); #endregion _stackPanel.Children.Add(dataGrid); _stackPanel.Children.Add(stackPanel); }