using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using WeighBusiness.BL; using WeighBusiness.BO; namespace CowOutputClient { /// /// Interaction logic for SelectedProductWindow.xaml /// public partial class SelectedProductWindow : Window { private List catalogsDetails = new List(); List detailIds = new List(); bool? useSequenceWindow = null; public SelectedProductWindow() { InitializeComponent(); } private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { DragMove(); } private void Window_Loaded(object sender, RoutedEventArgs e) { BindProductCatalogs(); } private void BindProductCatalogs() { ProductCatalogPanel.Children.Clear(); var catalogs = ProductCatalogBL.GetProductCatalogs(); catalogsDetails = ProductCatalogBL.GetProductCatalogDetails(); if (catalogs.Count() > 0) { foreach (var catalog in catalogs) { var txtCatalog = new TextBlock() { Text = catalog.Name, FontSize = 20, TextWrapping = TextWrapping.Wrap, TextAlignment = TextAlignment.Center }; txtCatalog.Tag = catalog; txtCatalog.MouseDown += (object sende, MouseButtonEventArgs args) => { if (ProductCatalogPanel.Children != null && ProductCatalogPanel.Children.Count > 0) { foreach (var item in ProductCatalogPanel.Children) { var bor = item as Border; if (bor != null) { var block = bor.Child as TextBlock; if (block != null) { block.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#fff")); block.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#000")); } } } } txtCatalog.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#3598fe")); txtCatalog.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#fff")); var result = (ProductCatalog)txtCatalog.Tag; BindProductCatalogsDetails(result.ProductCatalog_ID); }; var border = new Border(); border.BorderThickness = new Thickness(1, 1, 1, 1); border.BorderBrush = Brushes.Black; border.Child = txtCatalog; border.Margin = new Thickness(10, 10, 0, 0); ProductCatalogPanel.Children.Add(border); } } } private void BindProductCatalogsDetails(long productCatalog_ID) { CatalogDetails.Children.Clear(); if (catalogsDetails.Count() > 0) { var details = catalogsDetails.Where(x => x.ProductCatalog_ID == productCatalog_ID); foreach (var catalog in details) { var txtCatalog = new TextBlock() { Text = catalog.Goods_Name, FontSize = 15, TextWrapping = TextWrapping.Wrap, TextAlignment = TextAlignment.Center }; txtCatalog.Tag = catalog; if (catalog.IsSelected) { txtCatalog.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#3598fe")); txtCatalog.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#fff")); } txtCatalog.MouseDown += (object sende, MouseButtonEventArgs args) => { var cata = txtCatalog.Tag as ProCataGoods; if (!cata.IsSelected) { txtCatalog.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#3598fe")); txtCatalog.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#fff")); cata.IsSelected = true; } else { cata.IsSelected = false; txtCatalog.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#fff")); txtCatalog.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#000")); } }; var border = new Border(); border.BorderThickness = new Thickness(1, 1, 1, 1); border.BorderBrush = Brushes.Black; border.Child = txtCatalog; border.Margin = new Thickness(8, 8, 0, 0); CatalogDetails.Children.Add(border); } } } private void btnClose_Click_1(object sender, RoutedEventArgs e) { this.DialogResult = useSequenceWindow == true ? true : false; } private void btnSave_Click_1(object sender, RoutedEventArgs e) { ProductCatalogBL.UpdateProductCatalogDetails(catalogsDetails.Where(x => x.IsSelected)); this.DialogResult = true; } private void btnSequence_Click_1(object sender, RoutedEventArgs e) { useSequenceWindow = new ProductCatalogSequenceWindow().ShowDialog(); if (useSequenceWindow == true) { BindProductCatalogs(); } } } }