DynamicFormWindow.cs 2.3 KB

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