MeetingPanel.xaml.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Input;
  8. using System.Windows.Media.Imaging;
  9. using Comal.Classes;
  10. using InABox.Clients;
  11. using InABox.Core;
  12. using InABox.DynamicGrid;
  13. using InABox.Wpf;
  14. using java.text;
  15. using Syncfusion.Windows.Controls;
  16. namespace PRSDesktop
  17. {
  18. public partial class MeetingPanel : UserControl, IPanel<Meeting>
  19. {
  20. private DynamicGrid<MeetingItem> MeetingItemGrid = new DynamicDataGrid<MeetingItem>();
  21. public MeetingPanel()
  22. {
  23. InitializeComponent();
  24. MeetingItemGrid.OnEditorValueChanged += MeetingItemGrid_OnEditorValueChanged;
  25. MeetingItemGrid.OnCustomiseEditor += MeetingItemGrid_OnCustomiseEditor;
  26. }
  27. #region IPanel
  28. public void Setup()
  29. {
  30. foreach (var column in MeetingModel.Columns.Items)
  31. MeetingGrid.AddHiddenColumn(column.Property);
  32. MeetingGrid.Refresh(true, false);
  33. MeetingAssignments.Refresh(true, false);
  34. MeetingItemDocuments.Refresh(true, false);
  35. MeetingItemTasks.Refresh(true, false);
  36. MeetingTasks.Refresh(true, false);
  37. MeetingDocuments.Refresh(true, false);
  38. }
  39. public void Shutdown()
  40. {
  41. }
  42. public void Refresh()
  43. {
  44. MeetingGrid.Refresh(false, true);
  45. }
  46. public string SectionName => "Meetings";
  47. public DataModel DataModel(Selection selection)
  48. {
  49. return new AutoDataModel<Meeting>(null);
  50. }
  51. public event DataModelUpdateEvent? OnUpdateDataModel;
  52. public bool IsReady { get; set; }
  53. public void CreateToolbarButtons(IPanelHost host)
  54. {
  55. }
  56. public Dictionary<string, object[]> Selected()
  57. {
  58. return new Dictionary<string, object[]>();
  59. }
  60. public void Heartbeat(TimeSpan time)
  61. {
  62. }
  63. #endregion
  64. private bool _meetingSelected = false;
  65. private TimeSpan _meetingstart = TimeSpan.Zero;
  66. private TimeSpan _meetingduration = TimeSpan.Zero;
  67. private TimeSpan _meetingfinish = TimeSpan.Zero;
  68. private bool _meetingitemSelected = false;
  69. private void Meetings_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
  70. {
  71. CoreRow? row = e.Rows?.FirstOrDefault();
  72. _meetingSelected = row != null;
  73. var meeting = row?.ToObject<Meeting>() ?? new Meeting();
  74. _meetingstart = meeting.Time.Start;
  75. _meetingduration = meeting.Time.Duration;
  76. _meetingfinish = meeting.Time.Finish;
  77. MeetingGrid.InitialiseEditorForm(MeetingDetailsForm, new Meeting[] { meeting });
  78. _meetingitemSelected = false;
  79. MeetingItemGrid.InitialiseEditorForm(MeetingItemDetailsForm, new MeetingItem[] { new MeetingItem() });
  80. var model = new MeetingModel(row);
  81. MeetingItems.Model = model;
  82. MeetingItems.Refresh();
  83. MeetingAssignments.Model = model;
  84. MeetingAssignments.Refresh(false,true);
  85. MeetingItemTasks.MeetingID = meeting.ID;
  86. MeetingTasks.Model = model;
  87. MeetingTasks.Refresh(false, true);
  88. MeetingDocuments.Model = model;
  89. MeetingDocuments.Refresh(false, true);
  90. }
  91. private void MeetingDetailsForm_OnBeforeLoad(IDynamicEditorForm form)
  92. {
  93. form.ReadOnly = !_meetingSelected;
  94. }
  95. private void Meetings_OnCustomiseEditor(IDynamicEditorForm sender, Meeting[]? items, DynamicGridColumn column, BaseEditor editor)
  96. {
  97. if (String.Equals(column.ColumnName, "Time"))
  98. editor.Editable = sender.ReadOnly ? Editable.Disabled : Editable.Enabled;
  99. }
  100. private Dictionary<string, object?> Meetings_OnEditorValueChanged(object sender, string name, object value)
  101. {
  102. var item = MeetingDetailsForm.Items.FirstOrDefault();
  103. if (item is Meeting meeting)
  104. {
  105. if (String.Equals(name, "Time.Start") && TimeSpan.Equals(meeting.Time.Start, _meetingstart))
  106. return new Dictionary<string, object?>();
  107. if (String.Equals(name, "Time.Duration") && TimeSpan.Equals(meeting.Time.Duration, _meetingduration))
  108. return new Dictionary<string, object?>();
  109. if (String.Equals(name, "Time.Finish") && TimeSpan.Equals(meeting.Time.Finish, _meetingfinish))
  110. return new Dictionary<string, object?>();
  111. new Client<Meeting>().Save(meeting, "");
  112. var row = MeetingGrid.SelectedRows[0];
  113. MeetingGrid.Data.LoadRow(row, meeting);
  114. MeetingGrid.InvalidateRow(row);
  115. _meetingstart = meeting.Time.Start;
  116. _meetingduration = meeting.Time.Duration;
  117. _meetingfinish = meeting.Time.Finish;
  118. }
  119. return new Dictionary<string, object?>();
  120. }
  121. private void MeetingItemGrid_OnSelectItem(DynamicTreeNode node)
  122. {
  123. _meetingitemSelected = node != null;
  124. MeetingItemDocuments.MeetingItemID = node != null ? node.ID : Guid.Empty;
  125. MeetingItemDocuments.Refresh(false, true);
  126. MeetingItemTasks.MeetingItemID = node != null ? node.ID : Guid.Empty;
  127. MeetingItemTasks.Refresh(false, true);
  128. var row = node != null
  129. ? MeetingItems.Data?.Rows.FirstOrDefault(r => r.Get<MeetingItem, Guid>(x => x.ID) == node.ID)
  130. : null;
  131. var meetingitem = row != null ? row.ToObject<MeetingItem>() : new MeetingItem();
  132. MeetingItemGrid.InitialiseEditorForm(MeetingItemDetailsForm, new MeetingItem[] { meetingitem });
  133. }
  134. private void MeetingItemDetailsForm_OnBeforeLoad(IDynamicEditorForm form)
  135. {
  136. form.ReadOnly = !_meetingSelected || !_meetingitemSelected;
  137. }
  138. private void MeetingItemGrid_OnCustomiseEditor(IDynamicEditorForm sender, MeetingItem[] items, DynamicGridColumn column, BaseEditor editor)
  139. {
  140. }
  141. private Dictionary<string, object?> MeetingItemGrid_OnEditorValueChanged(object sender, string name, object value)
  142. {
  143. var item = MeetingItemDetailsForm.Items.FirstOrDefault();
  144. if(item is MeetingItem meetingitem)
  145. {
  146. new Client<MeetingItem>().Save(meetingitem, "");
  147. var row = MeetingItems.Data.Rows.FirstOrDefault(r => r.Get<MeetingItem, Guid>(c => c.ID) == meetingitem.ID);
  148. MeetingItems.Data.LoadRow(row, meetingitem);
  149. var node = MeetingItems.Nodes[meetingitem.ID];
  150. node.Description = meetingitem.Title;
  151. }
  152. return new Dictionary<string, object?>();
  153. }
  154. private void MeetingItemTasks_OnOnChanged(IDynamicGrid sender)
  155. {
  156. MeetingTasks.Refresh(false, true);
  157. }
  158. #region MeetingItemDocuments
  159. private void MeetingItemDocuments_OnChanged(IDynamicGrid sender)
  160. {
  161. MeetingDocuments.Refresh(false, true);
  162. }
  163. private void MeetingDocumentPreview_OnSizeChanged(object sender, SizeChangedEventArgs e)
  164. {
  165. }
  166. private void MeetingDocuments_OnOnSelectItem(object sender, DynamicGridSelectionEventArgs e)
  167. {
  168. var doc = e.Rows?.FirstOrDefault()?.ToObject<MeetingItemDocument>();
  169. if (doc == null)
  170. {
  171. DocumentSplitPanel.Detail = null;
  172. return;
  173. }
  174. IDocumentEditor editor = null;
  175. var extension = Path.GetExtension(doc.DocumentLink.FileName).ToLower();
  176. if (extension.Equals(".pdf"))
  177. {
  178. var pdf = new PDFEditorControl();
  179. //pdf.PrintAllowed = PrintAllowed;
  180. pdf.SaveAllowed = false;
  181. pdf.ButtonsVisible = false;
  182. pdf.Watermark = "";
  183. editor = pdf;
  184. }
  185. else if (extension.Equals(".png") || extension.Equals(".bmp") || extension.Equals(".jpg") || extension.Equals(".jpeg"))
  186. {
  187. editor = new ImageEditorControl();
  188. }
  189. else if (extension.Equals(".xls") || extension.Equals(".xlsx") )
  190. {
  191. editor = new SpreadsheetEditorControl();
  192. }
  193. else if (extension.Equals(".doc") || extension.Equals(".docx") || extension.Equals(".rtf") || extension.Equals(".html") || extension.Equals(".htm") || extension.Equals(".txt"))
  194. {
  195. editor = new RTFEditorControl();
  196. }
  197. if (editor != null)
  198. {
  199. DocumentSplitPanel.Detail = editor as FrameworkElement;
  200. editor.Document = doc;
  201. }
  202. else
  203. {
  204. DocumentSplitPanel.Detail = null;
  205. }
  206. }
  207. #endregion
  208. private void Meetings_OnCustomiseEditor(IDynamicEditorForm sender, Meeting items, DynamicGridColumn column, BaseEditor editor)
  209. {
  210. }
  211. }
  212. }