DFAddTaskControl.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using Comal.Classes;
  2. using InABox.Clients;
  3. using InABox.DynamicGrid;
  4. using PRSClasses;
  5. using Syncfusion.Windows.Shared;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using Button = System.Windows.Controls.Button;
  14. using MessageBox = System.Windows.MessageBox;
  15. using TextBox = System.Windows.Controls.TextBox;
  16. namespace PRS.Shared
  17. {
  18. public class DFAddTaskControl : DynamicFormFieldControl<DFLayoutAddTaskField, DFLayoutAddTaskFieldProperties, int?>
  19. {
  20. private IntegerTextBox Number = null!; // Late-initialisation
  21. private Button Button = null!; // Late-initialisation
  22. protected override FrameworkElement Create()
  23. {
  24. var panel = new DockPanel();
  25. Button = new Button
  26. {
  27. Content = "Create Task",
  28. Padding = new Thickness(5),
  29. IsEnabled = FormDesignGrid.IsEditing
  30. };
  31. Button.Click += Button_Click;
  32. Number = new IntegerTextBox
  33. {
  34. IsEnabled = false,
  35. VerticalAlignment = VerticalAlignment.Stretch,
  36. Margin = new Thickness(0, 0, 5, 0)
  37. };
  38. Button.SetValue(DockPanel.DockProperty, Dock.Right);
  39. Number.SetValue(DockPanel.DockProperty, Dock.Left);
  40. panel.Children.Add(Button);
  41. panel.Children.Add(Number);
  42. return panel;
  43. }
  44. private void Button_Click(object sender, RoutedEventArgs e)
  45. {
  46. var kanban = new Kanban();
  47. kanban.Type.ID = Field.Properties.TaskType.ID;
  48. var grid = DynamicGridUtils.CreateDynamicGrid(typeof(DynamicDataGrid<>), typeof(Kanban)) as DynamicDataGrid<Kanban>;
  49. if (grid!.EditItems(new[] { kanban }))
  50. {
  51. new Client<Kanban>().Save(kanban, $"Created by form variable '{Field.Name}'");
  52. Number.Value = kanban.Number;
  53. Button.IsEnabled = false;
  54. }
  55. }
  56. public override int? GetValue()
  57. {
  58. return Number.Value.HasValue ? Convert.ToInt32(Number.Value.Value) : null;
  59. }
  60. public override void SetValue(int? value)
  61. {
  62. Number.Value = value;
  63. Button.IsEnabled = FormDesignGrid.IsEditing && value == null;
  64. }
  65. protected override bool IsEmpty() => GetValue() == null;
  66. }
  67. }