FactoryLostTimeChooser.xaml.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. using Comal.Classes;
  4. using InABox.Clients;
  5. using InABox.Core;
  6. using InABox.Wpf;
  7. namespace PRSDesktop
  8. {
  9. /// <summary>
  10. /// Interaction logic for FactoryLostTimeChooser.xaml
  11. /// </summary>
  12. public partial class FactoryLostTimeChooser : ThemableWindow
  13. {
  14. public FactoryLostTimeChooser()
  15. {
  16. InitializeComponent();
  17. new Client<ManufacturingLostTime>().Query(
  18. LookupFactory.DefineFilter<ManufacturingLostTime>(),
  19. null, //LookupFactory.DefineColumns<ManufacturingLostTime>(),
  20. LookupFactory.DefineSort<ManufacturingLostTime>(),
  21. CoreRange.All,
  22. (o, e) => { Dispatcher.Invoke(() => { LoadLostTime(o); }); });
  23. }
  24. public ManufacturingLostTime SelectedLostTime { get; set; }
  25. private void LoadLostTime(CoreTable losttime)
  26. {
  27. foreach (var row in losttime.Rows)
  28. {
  29. LostTime.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
  30. var label = new Label
  31. {
  32. Content = row.Get<ManufacturingLostTime, string>(x => x.Description), Margin = new Thickness(10),
  33. VerticalContentAlignment = VerticalAlignment.Center
  34. };
  35. label.SetValue(Grid.RowProperty, LostTime.RowDefinitions.Count - 1);
  36. label.SetValue(Grid.ColumnProperty, 0);
  37. LostTime.Children.Add(label);
  38. var button = new Button { Content = "Select", Margin = new Thickness(10, 0, 10, 20), MinWidth = 100, MinHeight = 50 };
  39. button.Tag = row.ToObject<ManufacturingLostTime>();
  40. button.Click += Button_Click;
  41. button.SetValue(Grid.RowProperty, LostTime.RowDefinitions.Count - 1);
  42. button.SetValue(Grid.ColumnProperty, 1);
  43. LostTime.Children.Add(button);
  44. }
  45. }
  46. private void Button_Click(object sender, RoutedEventArgs e)
  47. {
  48. SelectedLostTime = (sender as Button).Tag as ManufacturingLostTime;
  49. DialogResult = true;
  50. Close();
  51. }
  52. }
  53. }