DynamicFormWindow.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using InABox.Core;
  2. using InABox.Wpf;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Forms;
  10. using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
  11. namespace InABox.DynamicGrid
  12. {
  13. public abstract class DynamicFormWindow : ThemableWindow
  14. {
  15. protected abstract DynamicFormDesignGrid Grid { get; }
  16. private DFLayoutType _type;
  17. public DFLayoutType Type
  18. {
  19. get => _type;
  20. set
  21. {
  22. _type = value;
  23. Width = _type == DFLayoutType.Mobile ? 600 : 1000;
  24. Height = 800;
  25. }
  26. }
  27. public DFLayout Form
  28. {
  29. get => Grid.Form;
  30. set => Grid.Form = value;
  31. }
  32. public DigitalFormVariable[] Variables
  33. {
  34. get => Grid.Variables;
  35. set => Grid.Variables = value;
  36. }
  37. /// <summary>
  38. /// Renders the form; after this is called, any changes to properties triggers a refresh.
  39. /// </summary>
  40. public void Initialize()
  41. {
  42. Grid.Initialize();
  43. }
  44. public void LoadLayout(DigitalFormLayout layout, DigitalFormVariable[] variables)
  45. {
  46. Variables = variables;
  47. var f = new DFLayout();
  48. if (!string.IsNullOrWhiteSpace(layout.Layout))
  49. {
  50. f.LoadLayout(layout.Layout);
  51. }
  52. else
  53. {
  54. f = new DFLayout();
  55. f.RowHeights.Add("Auto");
  56. f.ColumnWidths.AddRange(new[] { "*", "Auto" });
  57. }
  58. f.LoadVariables(variables);
  59. Form = f;
  60. }
  61. /*public static T LoadDigitalForm<T>(Guid id) where T : Entity, IPersistent, IRemotable, IDigitalFormInstance, new()
  62. {
  63. var result = new Client<T>().Query(
  64. new Filter<T>(x => x.ID).IsEqualTo(id),
  65. new Columns<T>(
  66. x => x.ID,
  67. x => x.Form.ID,
  68. x => x.Form.Description,
  69. x => x.FormCompleted,
  70. x => x.FormCompletedBy.ID,
  71. x => x.FormCompletedBy.UserID,
  72. x => x.FormData
  73. )
  74. ).Rows.FirstOrDefault()?.ToObject<T>();
  75. return result;
  76. }*/
  77. }
  78. }