FactoryLostTimeChooser.xaml.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. (o, e) => { Dispatcher.Invoke(() => { LoadLostTime(o); }); });
  22. }
  23. public ManufacturingLostTime SelectedLostTime { get; set; }
  24. private void LoadLostTime(CoreTable losttime)
  25. {
  26. foreach (var row in losttime.Rows)
  27. {
  28. LostTime.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
  29. var label = new Label
  30. {
  31. Content = row.Get<ManufacturingLostTime, string>(x => x.Description), Margin = new Thickness(10),
  32. VerticalContentAlignment = VerticalAlignment.Center
  33. };
  34. label.SetValue(Grid.RowProperty, LostTime.RowDefinitions.Count - 1);
  35. label.SetValue(Grid.ColumnProperty, 0);
  36. LostTime.Children.Add(label);
  37. var button = new Button { Content = "Select", Margin = new Thickness(10, 0, 10, 20), MinWidth = 100, MinHeight = 50 };
  38. button.Tag = row.ToObject<ManufacturingLostTime>();
  39. button.Click += Button_Click;
  40. button.SetValue(Grid.RowProperty, LostTime.RowDefinitions.Count - 1);
  41. button.SetValue(Grid.ColumnProperty, 1);
  42. LostTime.Children.Add(button);
  43. }
  44. }
  45. private void Button_Click(object sender, RoutedEventArgs e)
  46. {
  47. SelectedLostTime = (sender as Button).Tag as ManufacturingLostTime;
  48. DialogResult = true;
  49. Close();
  50. }
  51. }
  52. }