TasksByStatusControl.xaml.cs 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Linq.Expressions;
  7. using System.Reflection;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using Comal.Classes;
  15. using InABox.Clients;
  16. using InABox.Core;
  17. using InABox.DynamicGrid;
  18. using InABox.WPF;
  19. using org.omg.CORBA;
  20. using Syncfusion.UI.Xaml.Kanban;
  21. using Color = System.Drawing.Color;
  22. namespace PRSDesktop
  23. {
  24. public class EmployeeModel
  25. {
  26. public EmployeeModel(Guid id, string name, Guid thumbnail, BitmapImage image)
  27. {
  28. ID = id;
  29. Name = name;
  30. Image = image;
  31. ThumbnailID = thumbnail;
  32. }
  33. public Guid ID { get; set; }
  34. public string Name { get; set; }
  35. public BitmapImage Image { get; set; }
  36. public Guid ThumbnailID { get; set; }
  37. }
  38. public class StatusTasksHeaderTimeConverter : IValueConverter
  39. {
  40. public static IEnumerable<TaskModel> Tasks { get; set; }
  41. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  42. {
  43. if (Tasks == null)
  44. return "0:00";
  45. var dataContext = value as ColumnTag;
  46. if (dataContext == null)
  47. return "0:00";
  48. var getter = dataContext.GetType().GetProperty("Column", BindingFlags.NonPublic | BindingFlags.Instance);
  49. if (getter == null)
  50. return "0:00";
  51. var column = (KanbanColumn)getter.GetValue(dataContext);
  52. if (column == null)
  53. return "0:00";
  54. double result = 0.0F;
  55. foreach (var kanban in Tasks.Where(x => Equals(x.Category, column.Categories)))
  56. result += kanban.EstimatedTime.TotalHours;
  57. return string.Format("{0:F2}", result);
  58. }
  59. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  60. {
  61. throw new NotImplementedException();
  62. }
  63. }
  64. public class BoolToVisibilityConverter : IValueConverter
  65. {
  66. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  67. {
  68. if (Equals(value, true))
  69. return Visibility.Visible;
  70. return Visibility.Collapsed;
  71. }
  72. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  73. {
  74. throw new NotImplementedException();
  75. }
  76. }
  77. /// <summary>
  78. /// Interaction logic for KanbanPanel.xaml
  79. /// </summary>
  80. public partial class TasksByStatusControl : UserControl, ITaskControl
  81. {
  82. private BitmapImage _attachimg = PRSDesktop.Resources.attachment.AsBitmapImage();
  83. private readonly ObservableCollection<EmployeeModel> _employeelist = new();
  84. private CoreTable _employees;
  85. public CoreTable _kanbans;
  86. private BitmapImage _lockimg = PRSDesktop.Resources.lock_sml.AsBitmapImage();
  87. private ObservableCollection<TaskModel> _models = new();
  88. private CoreTable _types;
  89. public List<string> CheckedKanbans = new();
  90. // CoreUtils.FullGuid => All Staff
  91. // Guid.Empty => Unallocated
  92. // Anything Else => Actual Staff Member
  93. private Guid EmployeeID = Guid.Empty;
  94. private Guid? MyID;
  95. private string MyName = "";
  96. private string searchtext = "";
  97. private Guid selectedtype = CoreUtils.FullGuid;
  98. public TasksByStatusControl()
  99. {
  100. InitializeComponent();
  101. }
  102. public string SectionName => "Tasks By Status";
  103. public DataModel DataModel(Selection selection)
  104. {
  105. var ids = SelectedModels().Select(x => Guid.Parse(x.ID)).ToArray();
  106. return new AutoDataModel<Kanban>(new Filter<Kanban>(x => x.ID).InList(ids));
  107. }
  108. private void ResizeColumns()
  109. {
  110. //if (!bResizeRequired)
  111. // return;
  112. using (var d = Dispatcher.DisableProcessing())
  113. {
  114. var CollapsedWidth = 50;
  115. var CollapsedColumns = 0;
  116. Array.ForEach(Kanban.Columns.ToArray(), x => { CollapsedColumns += x.IsExpanded ? 0 : 1; });
  117. if (Kanban.Columns.Count > 0 && CollapsedColumns != Kanban.Columns.Count)
  118. {
  119. var ColumnWidth = (Kanban.ActualWidth - CollapsedColumns * CollapsedWidth) / (Kanban.Columns.Count - CollapsedColumns) - 2;
  120. if (ColumnWidth != Kanban.ColumnWidth) Kanban.ColumnWidth = ColumnWidth;
  121. //bResizeRequired = false;
  122. }
  123. }
  124. }
  125. private void TaskMenu_Opened(object sender, RoutedEventArgs e)
  126. {
  127. Host.PopulateMenu(this, sender as ContextMenu);
  128. }
  129. private void Kanban_SizeChanged(object sender, SizeChangedEventArgs e)
  130. {
  131. Kanban.ColumnWidth = Kanban.ActualWidth / Kanban.Columns.Count - 1.0F;
  132. }
  133. private void Kanban_CardDragStart(object sender, KanbanDragStartEventArgs e)
  134. {
  135. var models = SelectedModels(e.SelectedCard.Content as TaskModel);
  136. if (models.Any(x => x.Locked))
  137. e.IsCancel = true;
  138. }
  139. private void Kanban_CardDragEnd(object sender, KanbanDragEndEventArgs e)
  140. {
  141. using (new WaitCursor())
  142. {
  143. var target = e.TargetColumn.Categories;
  144. var models = SelectedModels(e.SelectedCard.Content as TaskModel).Where(x => !Equals(x.Category, target)).ToArray();
  145. if (!models.Any())
  146. return;
  147. var kanbans = Host.LoadKanbans(models, new Columns<Kanban>(x => x.ID, x => x.Category));
  148. foreach (var kanban in kanbans)
  149. kanban.Category = target;
  150. new Client<Kanban>().Save(kanbans, string.Format("Task Status Updated to {0}", target), (o, err) => { });
  151. foreach (var model in models)
  152. {
  153. model.Checked = false;
  154. model.Category = target;
  155. }
  156. FilterKanbans();
  157. }
  158. }
  159. private void Search_KeyUp(object sender, KeyEventArgs e)
  160. {
  161. if (string.IsNullOrWhiteSpace(Search.Text) || e.Key == Key.Return)
  162. {
  163. searchtext = Search.Text;
  164. Refresh(true);
  165. }
  166. }
  167. private void TaskTypes_SelectionChanged(object sender, SelectionChangedEventArgs e)
  168. {
  169. if (!IsReady)
  170. return;
  171. if (e.AddedItems.Count > 0)
  172. {
  173. var item = (KeyValuePair<Guid, string>)e.AddedItems[0];
  174. selectedtype = item.Key;
  175. }
  176. else
  177. {
  178. selectedtype = CoreUtils.FullGuid;
  179. }
  180. Host.Settings.StatusSettings.SelectedType = selectedtype;
  181. Host.SaveSettings();
  182. ReloadKanbans();
  183. }
  184. private void IncludeCompleted_Checked(object sender, RoutedEventArgs e)
  185. {
  186. if (!IsReady)
  187. return;
  188. Host.Settings.StatusSettings.IncludeCompleted = IncludeCompleted.IsChecked.Value;
  189. Host.SaveSettings();
  190. SetupColumns();
  191. ReloadKanbans();
  192. }
  193. private void IncludeObserved_Checked(object sender, RoutedEventArgs e)
  194. {
  195. if (!IsReady)
  196. return;
  197. Host.Settings.StatusSettings.IncludeObserved = IncludeObserved.IsChecked.Value;
  198. Host.SaveSettings();
  199. ReloadKanbans();
  200. }
  201. private void IncludeLocked_Checked(object sender, RoutedEventArgs e)
  202. {
  203. if (!IsReady)
  204. return;
  205. Host.Settings.StatusSettings.IncludeLocked = IncludeLocked.IsChecked.Value;
  206. Host.SaveSettings();
  207. ReloadKanbans();
  208. }
  209. private void ViewType_SelectionChanged(object sender, SelectionChangedEventArgs e)
  210. {
  211. if (Kanban != null)
  212. Kanban.CardTemplate = ViewType.SelectedIndex > 0
  213. ? Resources["CompactKanban"] as DataTemplate
  214. : Resources["FullKanban"] as DataTemplate;
  215. if (IsReady)
  216. {
  217. Host.Settings.StatusSettings.CompactView = ViewType.SelectedIndex > 0;
  218. Host.SaveSettings();
  219. }
  220. }
  221. private static bool UpdatingEmployees = false;
  222. private void Employees_SelectionChanged(object sender, SelectionChangedEventArgs e)
  223. {
  224. if (UpdatingEmployees)
  225. return;
  226. if (e.AddedItems.Count == 0)
  227. {
  228. EmployeeID = Guid.Empty;
  229. }
  230. else
  231. {
  232. var model = _employeelist[Employees.SelectedIndex];
  233. EmployeeID = model.ID;
  234. }
  235. CheckedKanbans.Clear();
  236. if (IsReady)
  237. Refresh(true);
  238. }
  239. private void Export_Click(object sender, RoutedEventArgs e)
  240. {
  241. var form = new DynamicExportForm(typeof(Kanban), _kanbans.Columns.Select(x => x.ColumnName));
  242. if (form.ShowDialog() != true)
  243. return;
  244. var export = new Client<Kanban>().Query(
  245. GetKanbanFilter(),
  246. new Columns<Kanban>(form.Fields),
  247. LookupFactory.DefineSort<Kanban>()
  248. );
  249. var employee = "Tasks for All Staff";
  250. if (EmployeeID != CoreUtils.FullGuid)
  251. {
  252. if (EmployeeID == Guid.Empty)
  253. {
  254. employee = "Unallocated Tasks";
  255. }
  256. else
  257. {
  258. var model = _employeelist.FirstOrDefault(x => x.ID.Equals(EmployeeID));
  259. employee = model == null ? "Tasks for (Unknown)" : "Tasks for " + (model.ID == MyID ? MyName : model.Name);
  260. }
  261. }
  262. ExcelExporter.DoExport<Kanban>(
  263. export,
  264. string.Format(
  265. "{0} ({1:dd-MMM-yy})",
  266. employee,
  267. DateTime.Today
  268. )
  269. );
  270. }
  271. #region ITaskControl Support
  272. public bool IsReady { get; set; }
  273. public ITaskHost Host { get; set; }
  274. public KanbanView KanbanView => KanbanView.Status;
  275. public IEnumerable<TaskModel> SelectedModels(TaskModel sender = null)
  276. {
  277. var result = _models.Where(x => x.Checked).ToList();
  278. if (sender != null && !result.Contains(sender))
  279. result.Add(sender);
  280. return result;
  281. }
  282. #endregion
  283. #region Setup
  284. public void Setup()
  285. {
  286. SetupToolbar();
  287. SetupColumns();
  288. SetupData();
  289. SetupKanbanTypesLookup();
  290. SetupMyEmployee();
  291. SetupEmployeeList();
  292. }
  293. private void SetupMyEmployee()
  294. {
  295. var row = _employees.Rows.FirstOrDefault(r => r.Get<Employee, Guid>(c => c.UserLink.ID) == ClientFactory.UserGuid);
  296. if (row != null)
  297. {
  298. MyID = row.Get<Employee, Guid>(c => c.ID);
  299. MyName = row.Get<Employee, string>(x => x.Name);
  300. }
  301. }
  302. private void SetupEmployeeList()
  303. {
  304. IEnumerable<CoreRow> active = null;
  305. var anonymous = PRSDesktop.Resources.anonymous.AsBitmapImage();
  306. if (Security.IsAllowed<CanViewOthersTasks>())
  307. {
  308. active = _employees.Rows.Where(r =>
  309. r.Get<Employee, bool>(x => x.CanAllocateTasks) && (r.Get<Employee, DateTime>(x => x.FinishDate).IsEmpty() ||
  310. r.Get<Employee, DateTime>(x => x.FinishDate) > DateTime.Today));
  311. _employeelist.Add(new EmployeeModel(CoreUtils.FullGuid, "All Staff", Guid.Empty, PRSDesktop.Resources.everyone.AsBitmapImage()));
  312. _employeelist.Add(new EmployeeModel(Guid.Empty, "Unallocated", Guid.Empty, null));
  313. }
  314. else
  315. {
  316. active = _employees.Rows.Where(r => r.Get<Employee, Guid>(c => c.UserLink.ID).Equals(ClientFactory.UserGuid));
  317. }
  318. EmployeeModel selected = null;
  319. foreach (var row in active)
  320. {
  321. var id = row.Get<Employee, Guid>(x => x.ID);
  322. var userid = row.Get<Employee, Guid>(x => x.UserLink.ID);
  323. var thumbnailid = row.Get<Employee, Guid>(x => x.Thumbnail.ID);
  324. var name = userid.Equals(ClientFactory.UserGuid) ? "My Tasks" : row.Get<Employee, string>(x => x.Name);
  325. var model = new EmployeeModel(id, name, thumbnailid, anonymous);
  326. if (userid.Equals(ClientFactory.UserGuid))
  327. {
  328. _employeelist.Insert(0, model);
  329. selected = model;
  330. }
  331. else
  332. {
  333. _employeelist.Add(model);
  334. }
  335. }
  336. if (Security.IsAllowed<CanViewOthersTasks>())
  337. {
  338. EmployeeListColumn.Width = new GridLength(1.0F, GridUnitType.Auto);
  339. var thumbnails = active
  340. .Select(r => r.EntityLinkID<Employee, ImageDocumentLink>(x => x.Thumbnail) ?? Guid.Empty)
  341. .Where(x => x != Guid.Empty).ToArray();
  342. Employees.ItemsSource = _employeelist;
  343. Employees.SelectedItem = _employeelist.First();
  344. EmployeeID = _employeelist.First().ID;
  345. if (thumbnails.Any())
  346. new Client<Document>().Query(
  347. new Filter<Document>(x => x.ID).InList(thumbnails),
  348. new Columns<Document>(x => x.ID, x => x.Data),
  349. null,
  350. (data, error) =>
  351. {
  352. if (data != null)
  353. ProcessThumbnails(data);
  354. }
  355. );
  356. }
  357. else
  358. {
  359. EmployeeListColumn.Width = new GridLength(0.0F, GridUnitType.Pixel);
  360. Employees.ItemsSource = _employeelist;
  361. Employees.SelectedItem = _employeelist.First();
  362. EmployeeID = _employeelist.First().ID;
  363. }
  364. }
  365. private void ProcessThumbnails(CoreTable data)
  366. {
  367. Dispatcher.Invoke(() =>
  368. {
  369. foreach (var row in data.Rows)
  370. {
  371. var id = row.Get<Document, Guid>(x => x.ID);
  372. var model = _employeelist.FirstOrDefault(x => x.ThumbnailID.Equals(id));
  373. if (model != null)
  374. {
  375. model.Image = new BitmapImage();
  376. model.Image.LoadImage(row.Get<Document, byte[]>(x => x.Data));
  377. }
  378. }
  379. UpdatingEmployees = true;
  380. Employees.ItemsSource = null;
  381. Employees.ItemsSource = _employeelist;
  382. Employees.SelectedItem = _employeelist.First();
  383. EmployeeID = _employeelist.First().ID;
  384. UpdatingEmployees = false;
  385. });
  386. }
  387. private void SetupKanbanTypesLookup()
  388. {
  389. if (ClientFactory.IsSupported<KanbanType>())
  390. {
  391. var tasktypes = new Dictionary<Guid, string>
  392. {
  393. { CoreUtils.FullGuid, "All Types" },
  394. { Guid.Empty, "Unallocated Types" }
  395. };
  396. _types.IntoDictionary<KanbanType, Guid, string>(tasktypes, x => x.ID, row => row.Get<KanbanType, string>(x => x.Description));
  397. TaskTypes.ItemsSource = tasktypes;
  398. if (tasktypes.ContainsKey(Host.Settings.StatusSettings.SelectedType))
  399. TaskTypes.SelectedValue = Host.Settings.StatusSettings.SelectedType;
  400. else
  401. TaskTypes.SelectedValue = CoreUtils.FullGuid;
  402. TaskTypesLabel.Visibility = Visibility.Visible;
  403. TaskTypes.Visibility = Visibility.Visible;
  404. }
  405. else
  406. {
  407. TaskTypesLabel.Visibility = Visibility.Collapsed;
  408. TaskTypes.Visibility = Visibility.Collapsed;
  409. }
  410. }
  411. private void SetupToolbar()
  412. {
  413. IncludeCompleted.Visibility = Security.IsAllowed<CanHideTaskCompletedColumn>() ? Visibility.Visible : Visibility.Collapsed;
  414. IncludeCompleted.IsChecked = IncludeCompleted.Visibility == Visibility.Visible ? Host.Settings.StatusSettings.IncludeCompleted : true;
  415. IncludeObserved.IsChecked = Host.Settings.StatusSettings.IncludeObserved;
  416. ViewType.SelectedIndex = Host.Settings.StatusSettings.CompactView ? 1 : 0;
  417. }
  418. private void SetupColumns()
  419. {
  420. Kanban.Columns.Clear();
  421. var indicatorColorPalette = new IndicatorColorPalette();
  422. indicatorColorPalette.Add(new ColorMapping { Key = "Red", Color = Colors.LightSalmon });
  423. indicatorColorPalette.Add(new ColorMapping { Key = "Orange", Color = Colors.Orange });
  424. indicatorColorPalette.Add(new ColorMapping { Key = "Yellow", Color = Colors.LightYellow });
  425. indicatorColorPalette.Add(new ColorMapping { Key = "Green", Color = Colors.LightGreen });
  426. Kanban.IndicatorColorPalette = indicatorColorPalette;
  427. Kanban.Columns.Add(new KanbanColumn
  428. {
  429. Categories = "Open",
  430. Title = "To Do"
  431. });
  432. Kanban.Columns.Add(new KanbanColumn
  433. {
  434. Categories = "In Progress",
  435. Title = "In Progress"
  436. });
  437. Kanban.Columns.Add(new KanbanColumn
  438. {
  439. Categories = "Waiting",
  440. Title = "Waiting for Others"
  441. });
  442. if (Host.Settings.StatusSettings.IncludeCompleted)
  443. Kanban.Columns.Add(new KanbanColumn
  444. {
  445. Categories = "Complete",
  446. Title = "Completed"
  447. });
  448. Kanban.InvalidateVisual();
  449. foreach (var column in Kanban.Columns)
  450. {
  451. var menu = new ContextMenu();
  452. menu.Tag = column;
  453. var item = new MenuItem { Header = "New Task" };
  454. item.Click += CreateTask;
  455. menu.Items.Add(item);
  456. menu.Items.Add(new Separator());
  457. item = new MenuItem { Header = "Select All " + column.Title + " Tasks", Tag = column };
  458. item.Click += SelectAll_Click;
  459. menu.Items.Add(item);
  460. item = new MenuItem { Header = "Unselect All " + column.Title + " Tasks", Tag = column };
  461. item.Click += UnSelectAll_Click;
  462. menu.Items.Add(item);
  463. column.ContextMenu = menu;
  464. }
  465. Kanban.ColumnWidth = Kanban.ActualWidth / Kanban.Columns.Count - 1.0F;
  466. }
  467. private void SetupData()
  468. {
  469. var query = new MultiQuery();
  470. query.Add(
  471. null,
  472. new Columns<Employee>(x => x.ID, x => x.Name, x => x.Thumbnail.ID, x => x.CanAllocateTasks, x => x.Email, x => x.Mobile,
  473. x => x.FinishDate, x => x.UserLink.ID),
  474. new SortOrder<Employee>(x => x.Name)
  475. );
  476. if (ClientFactory.IsSupported<KanbanType>())
  477. query.Add(
  478. new Filter<KanbanType>(x => x.Hidden).IsEqualTo(false),
  479. new Columns<KanbanType>(x => x.ID, x => x.Description),
  480. new SortOrder<KanbanType>(x => x.Description)
  481. );
  482. query.Query();
  483. _employees = query.Get<Employee>();
  484. _types = ClientFactory.IsSupported<KanbanType>()
  485. ? query.Get<KanbanType>()
  486. : null;
  487. }
  488. #endregion
  489. #region Refresh / Reload
  490. private Filter<T> GetSearchFilter<T>(Expression<Func<T, object>> expression) where T : Entity, new()
  491. {
  492. Filter<T> result = null;
  493. var comps = searchtext.Trim().Split(' ');
  494. foreach (var comp in comps)
  495. result = result == null ? new Filter<T>(expression).Contains(comp) : result.And(expression).Contains(comp);
  496. return result;
  497. }
  498. private Filter<KanbanSubscriber> GetKanbanSubscriberFilter()
  499. {
  500. var filter = new Filter<KanbanSubscriber>(x => x.Kanban.Closed).IsEqualTo(DateTime.MinValue);
  501. if (Host.JobID != Guid.Empty)
  502. filter = filter.And(x => x.Kanban.JobLink.ID).IsEqualTo(Host.JobID);
  503. // All Tasks (EmployeeID.HasValue == false) or Unallocated (EmployeeID = Guid.Empty) are retrieved directly from the Kanban Table
  504. // so if we are here, we can assume that we are pulling subscriber data
  505. var empfilter = new Filter<KanbanSubscriber>(x => x.Employee.ID).IsEqualTo(EmployeeID);
  506. filter.Ands.Add(empfilter);
  507. if (EmployeeID != MyID)
  508. filter = filter.And(x => x.Kanban.Private).IsEqualTo(false);
  509. //if (!includeobserved)
  510. // filter = filter.And(new Filter<KanbanSubscriber>(x => x.Assignee).IsEqualTo(true).Or(x => x.Manager).IsEqualTo(true));
  511. //if (!includecompleted)
  512. // filter = filter.And(x => x.Kanban.Completed).IsEqualTo(DateTime.MinValue);
  513. //if (selectedtype != CoreUtils.FullGuid)
  514. // filter = filter.And(x => x.Kanban.Type.ID).IsEqualTo(selectedtype);
  515. if (!string.IsNullOrWhiteSpace(searchtext))
  516. {
  517. var search = GetSearchFilter<KanbanSubscriber>(x => x.Kanban.JobLink.Name);
  518. search.Ors.Add(GetSearchFilter<KanbanSubscriber>(x => x.Kanban.JobLink.JobNumber));
  519. search.Ors.Add(GetSearchFilter<KanbanSubscriber>(x => x.Kanban.Summary));
  520. search.Ors.Add(GetSearchFilter<KanbanSubscriber>(x => x.Kanban.Title));
  521. search.Ors.Add(GetSearchFilter<KanbanSubscriber>(x => x.Kanban.ManagerLink.Name));
  522. search.Ors.Add(GetSearchFilter<KanbanSubscriber>(x => x.Kanban.EmployeeLink.Name));
  523. if (int.TryParse(searchtext.Trim(), out var tasknumber))
  524. search.Ors.Add(new Filter<KanbanSubscriber>(x => x.Kanban.Number).IsEqualTo(tasknumber));
  525. filter.Ands.Add(search);
  526. }
  527. return filter;
  528. }
  529. private Filter<Kanban> GetKanbanFilter()
  530. {
  531. var filter = new Filter<Kanban>(x => x.Closed).IsEqualTo(DateTime.MinValue);
  532. if (Host.JobID != Guid.Empty)
  533. filter = filter.And(x => x.JobLink.ID).IsEqualTo(Host.JobID);
  534. if (EmployeeID != CoreUtils.FullGuid)
  535. {
  536. if (EmployeeID != Guid.Empty)
  537. {
  538. var empfilter = new Filter<Kanban>(x => x.EmployeeLink.ID).IsEqualTo(EmployeeID).Or(x => x.ManagerLink.ID).IsEqualTo(EmployeeID);
  539. filter.Ands.Add(empfilter);
  540. }
  541. else
  542. {
  543. filter = filter.And(x => x.EmployeeLink.ID).IsEqualTo(EmployeeID);
  544. }
  545. }
  546. if (EmployeeID != MyID)
  547. filter = filter.And(x => x.Private).IsEqualTo(false);
  548. //if (!includecompleted)
  549. // filter = filter.And(x => x.Completed).IsEqualTo(DateTime.MinValue);
  550. //if (selectedtype != CoreUtils.FullGuid)
  551. // filter = filter.And(x => x.Type.ID).IsEqualTo(selectedtype);
  552. return filter;
  553. }
  554. public void Refresh(bool resetselection)
  555. {
  556. Application.Current.Dispatcher.Invoke(() => { Mouse.OverrideCursor = Cursors.Wait; });
  557. if (EmployeeID != CoreUtils.FullGuid && EmployeeID != Guid.Empty)
  558. {
  559. _kanbans = new Client<KanbanSubscriber>().Query(
  560. GetKanbanSubscriberFilter(),
  561. new Columns<KanbanSubscriber>
  562. (
  563. x => x.Kanban.ID,
  564. x => x.Kanban.DueDate,
  565. x => x.Kanban.Completed,
  566. //x => x.Kanban.Description,
  567. x => x.Kanban.Summary,
  568. x => x.Kanban.Category,
  569. x => x.Kanban.EmployeeLink.ID,
  570. x => x.Kanban.ManagerLink.ID,
  571. x => x.Kanban.Notes,
  572. x => x.Kanban.Title,
  573. x => x.Kanban.JobLink.ID,
  574. x => x.Kanban.JobLink.JobNumber,
  575. x => x.Kanban.JobLink.Name,
  576. x => x.Kanban.Type.ID,
  577. x => x.Kanban.Type.Code,
  578. x => x.Kanban.Number,
  579. x => x.Kanban.Attachments,
  580. x => x.Kanban.Locked
  581. ),
  582. new SortOrder<KanbanSubscriber>(x => x.Kanban.DueDate) { Direction = SortDirection.Ascending }
  583. );
  584. foreach (var column in _kanbans.Columns)
  585. column.ColumnName = column.ColumnName.Replace("Kanban.", "");
  586. }
  587. else
  588. {
  589. _kanbans = new Client<Kanban>().Query(
  590. GetKanbanFilter(),
  591. new Columns<Kanban>
  592. (
  593. x => x.ID,
  594. x => x.DueDate,
  595. x => x.Completed,
  596. //x => x.Description,
  597. x => x.Summary,
  598. x => x.Category,
  599. x => x.EmployeeLink.ID,
  600. x => x.ManagerLink.ID,
  601. x => x.Notes,
  602. x => x.Title,
  603. x => x.JobLink.ID,
  604. x => x.JobLink.JobNumber,
  605. x => x.JobLink.Name,
  606. x => x.Type.ID,
  607. x => x.Type.Code,
  608. x => x.Number,
  609. x => x.Attachments,
  610. x => x.Locked
  611. ),
  612. new SortOrder<Kanban>(x => x.DueDate) { Direction = SortDirection.Ascending }
  613. );
  614. }
  615. ReloadKanbans();
  616. Application.Current.Dispatcher.Invoke(() => { Mouse.OverrideCursor = null; });
  617. }
  618. private void ReloadKanbans()
  619. {
  620. //SetupColumns();
  621. //ResizeColumns();
  622. _models = new ObservableCollection<TaskModel>();
  623. foreach (var row in _kanbans.Rows)
  624. try
  625. {
  626. var empid = row.Get<IKanban, Guid>(e => e.EmployeeLink.ID);
  627. var mgrid = row.EntityLinkID<IKanban, EmployeeLink>(x => x.ManagerLink) ?? Guid.Empty;
  628. var completed = row.Get<IKanban, DateTime>(e => e.Completed);
  629. var locked = row.Get<IKanban, bool>(e => e.Locked);
  630. var type = row.Get<IKanban, Guid>(e => e.Type.ID);
  631. var category = row.Get<IKanban, string>(x => x.Category);
  632. if (string.IsNullOrWhiteSpace(category))
  633. category = "Open";
  634. var bLockedOK = Host.Settings.StatusSettings.IncludeLocked || locked == false;
  635. var bObserveOK = EmployeeID == CoreUtils.FullGuid || Host.Settings.StatusSettings.IncludeObserved || empid == EmployeeID || mgrid == EmployeeID;
  636. var bCompleteOK = Host.Settings.StatusSettings.IncludeCompleted || completed.IsEmpty();
  637. var bTypeOK = selectedtype == CoreUtils.FullGuid || type == selectedtype;
  638. if (bLockedOK && bCompleteOK && bObserveOK && bTypeOK)
  639. {
  640. var model = new TaskModel();
  641. var EmployeeEntry = _employeelist.Where(x => x.ID.Equals(empid)).FirstOrDefault();
  642. var empimg = EmployeeEntry?.Image;
  643. var ManagerEntry = _employeelist.Where(x => x.ID.Equals(mgrid)).FirstOrDefault();
  644. //var description = row.Get<IKanban, String>(x => x.Summary);
  645. //if (String.IsNullOrWhiteSpace(description))
  646. // description = String.Join("\r\n", row.Get<IKanban, String[]>(x => x.Notes)).Split(new String[] { "===============" }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
  647. //if (String.IsNullOrWhiteSpace(description))
  648. // description = CoreUtils.StripHTML(row.Get<IKanban, String>(x => x.Description));
  649. //if (String.IsNullOrWhiteSpace(description))
  650. // description = "";
  651. var job = row.Get<IKanban, string>(x => x.JobLink.JobNumber);
  652. model.Title = row.Get<IKanban, string>(x => x.Title);
  653. model.ID = row.Get<IKanban, Guid>(x => x.ID).ToString();
  654. model.Description = row.Get<IKanban, string>(x => x.Summary) ?? "";
  655. model.Category = category;
  656. var color = EmployeeID == Guid.Empty || empid == EmployeeID || EmployeeID == CoreUtils.FullGuid
  657. ? TaskModel.KanbanColor(
  658. row.Get<IKanban, DateTime>(x => x.DueDate),
  659. row.Get<IKanban, DateTime>(x => x.Completed))
  660. : mgrid == EmployeeID
  661. ? Color.Silver
  662. : Color.Plum;
  663. if (row.Get<IKanban, bool>(x => x.Locked))
  664. color = color.MixColors(0.5F, Color.White);
  665. model.ColorKey = ImageUtils.ColorToString(color);
  666. model.Image = empimg;
  667. model.ImageURL = null;
  668. model.Attachments = row.Get<IKanban, int>(x => x.Attachments) > 0; // ? _attachimg : null;
  669. model.DueDate = row.Get<IKanban, DateTime>(x => x.DueDate);
  670. model.CompletedDate = row.Get<IKanban, DateTime>(x => x.Completed);
  671. model.Locked = row.Get<IKanban, bool>(x => x.Locked); // ? _lockimg : null;
  672. var notes = new List<List<string>> { new() };
  673. foreach (var line in row.Get<IKanban, string[]>(x => x.Notes))
  674. {
  675. if (line == "===================================")
  676. {
  677. notes.Add(new());
  678. }
  679. else
  680. {
  681. notes.Last().Add(line);
  682. }
  683. }
  684. model.Notes = string.Join("\n===================================\n", notes.Reverse<List<string>>().Select(x => string.Join('\n', x)));
  685. model.EmployeeID = empid;
  686. model.ManagerID = mgrid;
  687. var sEmp = "";
  688. if (empid != EmployeeID)
  689. {
  690. if (!Entity.IsEntityLinkValid<IKanban, EmployeeLink>(x => x.EmployeeLink, row))
  691. {
  692. sEmp = "Unallocated";
  693. }
  694. else
  695. {
  696. var tuple = _employeelist.FirstOrDefault(x => x.ID.Equals(empid));
  697. sEmp = tuple != null ? tuple.ID == MyID ? MyName : tuple.Name : "";
  698. }
  699. }
  700. var sMgr = "";
  701. if (mgrid != EmployeeID)
  702. if (mgrid != Guid.Empty)
  703. {
  704. var tuple = _employeelist.FirstOrDefault(x => x.ID.Equals(mgrid));
  705. sMgr = tuple != null ? tuple.ID == MyID ? MyName : tuple.Name : "";
  706. }
  707. if (!string.IsNullOrEmpty(sEmp))
  708. {
  709. if (!string.IsNullOrWhiteSpace(sMgr) && !string.Equals(sMgr, sEmp))
  710. model.AssignedTo = string.Format("Assigned to {0} by {1}", sEmp, sMgr);
  711. else
  712. model.AssignedTo = string.Format("Assigned to {0} ", sEmp);
  713. }
  714. else
  715. {
  716. if (!string.IsNullOrWhiteSpace(sMgr))
  717. model.AssignedTo = string.Format("Allocated by {0} ", sMgr);
  718. }
  719. //model.AssignedTo = String.Format("M: {0} / E: {1}", sMgr, sEmp);
  720. model.JobID = row.Get<IKanban, Guid>(x => x.JobLink.ID);
  721. model.JobNumber = row.Get<IKanban, string>(x => x.JobLink.JobNumber);
  722. if (string.IsNullOrWhiteSpace(model.JobNumber))
  723. model.JobNumber = "";
  724. model.JobName = row.Get<IKanban, string>(x => x.JobLink.Name);
  725. model.Checked = CheckedKanbans.Contains(row.Get<IKanban, Guid>(x => x.ID).ToString());
  726. model.Type = new KanbanType
  727. {
  728. ID = row.Get<IKanban, Guid>(x => x.Type.ID),
  729. Code = row.Get<IKanban, string>(x => x.Type.Code)
  730. };
  731. model.Number = row.Get<IKanban, int>(x => x.Number);
  732. _models.Add(model);
  733. }
  734. }
  735. catch (Exception e)
  736. {
  737. Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
  738. }
  739. StatusTasksHeaderTimeConverter.Tasks = _models;
  740. FilterKanbans();
  741. }
  742. private void FilterKanbans()
  743. {
  744. Kanban.ItemsSource = _models
  745. .Where(x => x.Search(Search.Text.Split()))
  746. .OrderBy(x => x.EmployeeID == EmployeeID ? 0 : 1).ThenBy(x => x.DueDate);
  747. ;
  748. }
  749. #endregion
  750. #region Kanban Selection Stuff
  751. private void SelectColumn(KanbanColumn column, bool selected)
  752. {
  753. CheckedKanbans.Clear();
  754. if (selected)
  755. {
  756. CheckedKanbans.AddRange(_models.Where(x => Equals(x.Category, column.Categories)).Select(x => x.ID));
  757. foreach (var model in _models)
  758. model.Checked = Equals(model.Category, column.Categories);
  759. }
  760. FilterKanbans();
  761. }
  762. private void UnSelectAll_Click(object sender, RoutedEventArgs e)
  763. {
  764. var column = ((MenuItem)sender).Tag as KanbanColumn;
  765. SelectColumn(column, false);
  766. }
  767. private void SelectAll_Click(object sender, RoutedEventArgs e)
  768. {
  769. var column = ((MenuItem)sender).Tag as KanbanColumn;
  770. SelectColumn(column, true);
  771. }
  772. //private IEnumerable<Guid> GetSelectedKanbanIDs(String currentid)
  773. //{
  774. // List<Guid> result = new List<Guid>();
  775. // if (!CheckedKanbans.Contains(currentid))
  776. // result.Add(Guid.Parse(currentid));
  777. // CheckedKanbans.ForEach((id) => result.Add(Guid.Parse(id)));
  778. // return result;
  779. //}
  780. //private Kanban[] GetSelectedKanbans(String currentid)
  781. //{
  782. // var ids = GetSelectedKanbanIDs(currentid);
  783. // return Host.LoadKanbans(ids).ToArray();
  784. //}
  785. private void CheckBox_Checked(object sender, RoutedEventArgs e)
  786. {
  787. var task = ((CheckBox)sender).Tag as TaskModel;
  788. if (task == null)
  789. return;
  790. if (CheckedKanbans.Contains(task.ID))
  791. CheckedKanbans.Remove(task.ID);
  792. else
  793. CheckedKanbans.Add(task.ID);
  794. }
  795. #endregion
  796. #region Context Menu Actions
  797. private void CreateTask(object sender, RoutedEventArgs e)
  798. {
  799. CreateKanban();
  800. }
  801. private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  802. {
  803. if (e.ClickCount > 1)
  804. {
  805. var task = ((Border)sender).Tag as TaskModel;
  806. DoEdit(task);
  807. e.Handled = true;
  808. }
  809. }
  810. private void EditTask_Click(object sender, RoutedEventArgs e)
  811. {
  812. var task = ((MenuItem)e.Source).Tag as TaskModel;
  813. DoEdit(task);
  814. e.Handled = true;
  815. }
  816. //private void CreateSetout_Click(object sender, RoutedEventArgs e)
  817. //{
  818. // MenuItem menu = sender as MenuItem;
  819. // TaskModel task = menu.Tag as TaskModel;
  820. // if (task.JobID.Equals(Guid.Empty))
  821. // {
  822. // MessageBox.Show("Please link this task to a job before creating a setout!");
  823. // return;
  824. // }
  825. // if (MessageBox.Show("This will convert this task into a Setout.\n\nDo you wish to continue?", "Confirmation", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
  826. // return;
  827. // ManufacturingTemplate template = new Client<ManufacturingTemplate>().Load(new Filter<ManufacturingTemplate>(x => x.Code).IsEqualTo("PRS")).FirstOrDefault();
  828. // if (template == null)
  829. // {
  830. // MessageBox.Show("[Pressing] Template does not exist!");
  831. // return;
  832. // }
  833. // String setoutnumber = "";
  834. // Progress.ShowModal("Creating Setout", (progress) =>
  835. // {
  836. // MultiQuery query = new MultiQuery();
  837. // query.Add<ManufacturingTemplateStage>(
  838. // new Filter<ManufacturingTemplateStage>(x => x.Template.ID).IsEqualTo(template.ID),
  839. // null,
  840. // new SortOrder<ManufacturingTemplateStage>(x => x.Sequence)
  841. // );
  842. // query.Add<Kanban>(
  843. // new Filter<Kanban>(x => x.ID).IsEqualTo(task.ID),
  844. // null,
  845. // null
  846. // );
  847. // query.Query();
  848. // ManufacturingTemplateStage[] tstages = query.Get<ManufacturingTemplateStage>().Rows.Select(x => x.ToObject<ManufacturingTemplateStage>()).ToArray();
  849. // Kanban kanban = query.Get<Kanban>().Rows.FirstOrDefault()?.ToObject<Kanban>();
  850. // progress.Report("Creating Setouts");
  851. // CoreTable setouts = new Client<Setout>().Query(
  852. // new Filter<Setout>(x => x.JobLink.ID).IsEqualTo(kanban.JobLink.ID),
  853. // new Columns<Setout>(x => x.JobLink.JobNumber, x => x.Number),
  854. // null
  855. // );
  856. // int ireq = 0;
  857. // String sreq = "";
  858. // while (true)
  859. // {
  860. // ireq++;
  861. // sreq = String.Format("{0}-{1:yyMMdd}-{2}", kanban.JobLink.JobNumber, DateTime.Now, ireq);
  862. // if (!setouts.Rows.Any(r => sreq.Equals(r.Get<Setout, String>(c => c.Number))))
  863. // break;
  864. // }
  865. // Setout setout = new Setout();
  866. // setout.Number = sreq;
  867. // setout.JobLink.ID = kanban.JobLink.ID; // = new Client<Job>().Load(new Filter<Job>(x => x.ID).IsEqualTo(kanban.JobLink.ID)).FirstOrDefault();
  868. // setout.Reference = kanban.Title;
  869. // var notes = kanban.Notes.ToList();
  870. // var description = kanban.Summary;
  871. // if (String.IsNullOrWhiteSpace(description))
  872. // description = CoreUtils.StripHTML(kanban.Description);
  873. // if (!String.IsNullOrWhiteSpace(description))
  874. // notes.Insert(0, description);
  875. // setout.Description = String.Join("\n==========================================\n", notes);
  876. // new Client<Setout>().Save(setout, "Created from Task");
  877. // setoutnumber = setout.Number;
  878. // progress.Report("Creating Manufacturing Packet");
  879. // ManufacturingPacket packet = new ManufacturingPacket()
  880. // {
  881. // Group = template.Factory.Name,
  882. // Serial = template.Code,
  883. // Title = kanban.Title,
  884. // Quantity = 1,
  885. // BarcodeQty = 1,
  886. // DueDate = kanban.DueDate
  887. // };
  888. // packet.SetoutLink.ID = setout.ID;
  889. // //packet.JobLink.ID = setout.JobLink.ID;
  890. // packet.ManufacturingTemplateLink.ID = template.ID;
  891. // packet.ManufacturingTemplateLink.Code = template.Code;
  892. // new Client<ManufacturingPacket>().Save(packet, "Created from Task");
  893. // List<ManufacturingPacketStage> pstages = new List<ManufacturingPacketStage>();
  894. // foreach (var tstage in tstages)
  895. // {
  896. // var pstage = new ManufacturingPacketStage()
  897. // {
  898. // Time = tstage.Time,
  899. // Sequence = tstage.Sequence,
  900. // SequenceType = tstage.SequenceType,
  901. // Started = DateTime.MinValue,
  902. // PercentageComplete = 0.0F,
  903. // Completed = DateTime.MinValue,
  904. // QualityChecks = tstage.QualityChecks,
  905. // QualityStatus = QualityStatus.NotChecked,
  906. // QualityNotes = "",
  907. // };
  908. // pstage.Parent.ID = packet.ID;
  909. // pstage.ManufacturingSectionLink.ID = tstage.Section.ID;
  910. // pstage.ManufacturingSectionLink.Name = tstage.Section.Name;
  911. // pstages.Add(pstage);
  912. // }
  913. // new Client<ManufacturingPacketStage>().Save(pstages, "Created from Task", (_, __) => { });
  914. // progress.Report("Processing Documents");
  915. // List<SetoutDocument> _setoutdocuments = new List<SetoutDocument>();
  916. // List<KanbanDocument> _kanbandocuments = new List<KanbanDocument>();
  917. // KanbanDocument[] docrefs = new Client<KanbanDocument>().Load(new Filter<KanbanDocument>(x => x.EntityLink.ID).IsEqualTo(kanban.ID));
  918. // foreach (var docref in docrefs)
  919. // {
  920. // Guid docid = ProcessSetoutDocument(docref);
  921. // var newdoc = new SetoutDocument();
  922. // newdoc.EntityLink.ID = setout.ID;
  923. // newdoc.DocumentLink.ID = docid;
  924. // _setoutdocuments.Add(newdoc);
  925. // if (docid != docref.DocumentLink.ID)
  926. // {
  927. // docref.DocumentLink.ID = docid;
  928. // _kanbandocuments.Add(docref);
  929. // }
  930. // }
  931. // new Client<SetoutDocument>().Save(_setoutdocuments, "Converted from Task", (_, __) => { });
  932. // new Client<KanbanDocument>().Save(_kanbandocuments, "Converted to PDF", (_, __) => { });
  933. // SetoutKanban link = new SetoutKanban();
  934. // link.Entity.ID = setout.ID;
  935. // link.Kanban.ID = kanban.ID;
  936. // new Client<SetoutKanban>().Save(link, "Converting Task -> Setout", (_, __) => { });
  937. // progress.Report("Updating Task");
  938. // kanban.Title = kanban.Title + " (" + setoutnumber + ")";
  939. // kanban.Locked = true;
  940. // new Client<Kanban>().Save(kanban, "Converting Kanban to Setout");
  941. // });
  942. // MessageBox.Show(String.Format("Created Setout {0}", setoutnumber));
  943. // Refresh();
  944. //}
  945. //private Guid ProcessSetoutDocument(KanbanDocument docref)
  946. //{
  947. // Guid result = docref.DocumentLink.ID;
  948. // String ext = System.IO.Path.GetExtension(docref.DocumentLink.FileName).ToLower();
  949. // if (ext.EndsWith("txt"))
  950. // {
  951. // var doc = new Client<Document>().Load(new Filter<Document>(x => x.ID).IsEqualTo(docref.DocumentLink.ID)).FirstOrDefault();
  952. // PdfDocument pdf = new PdfDocument();
  953. // PdfPage page = pdf.Pages.Add();
  954. // PdfGraphics graphics = page.Graphics;
  955. // PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12);
  956. // String text = System.Text.Encoding.UTF8.GetString(doc.Data);
  957. // graphics.DrawString(text, font, PdfBrushes.Black, new PointF(0, 0));
  958. // MemoryStream ms = new MemoryStream();
  959. // pdf.Save(ms);
  960. // pdf.Close(true);
  961. // byte[] data = ms.ToArray();
  962. // var newdoc = new Document()
  963. // {
  964. // Data = data,
  965. // FileName = System.IO.Path.ChangeExtension(docref.DocumentLink.FileName, "pdf"),
  966. // CRC = CoreUtils.CalculateCRC(data),
  967. // TimeStamp = DateTime.Now,
  968. // };
  969. // new Client<Document>().Save(newdoc, "Converted from Text");
  970. // return newdoc.ID;
  971. // }
  972. // else if (ext.EndsWith("png") || ext.EndsWith("bmp") || ext.EndsWith("jpg") || ext.EndsWith("jpeg"))
  973. // {
  974. // var doc = new Client<Document>().Load(new Filter<Document>(x => x.ID).IsEqualTo(docref.DocumentLink.ID)).FirstOrDefault();
  975. // PdfBitmap image = new PdfBitmap(new MemoryStream(doc.Data));
  976. // PdfDocument pdf = new PdfDocument();
  977. // pdf.PageSettings.Orientation = image.Height > image.Width ? PdfPageOrientation.Portrait : PdfPageOrientation.Landscape;
  978. // pdf.PageSettings.Size = new SizeF(image.Width, image.Height);
  979. // PdfPage page = pdf.Pages.Add();
  980. // PdfGraphics graphics = page.Graphics;
  981. // graphics.DrawImage(image, 0.0F, 0.0F);
  982. // MemoryStream ms = new MemoryStream();
  983. // pdf.Save(ms);
  984. // pdf.Close(true);
  985. // byte[] data = ms.ToArray();
  986. // var newdoc = new Document()
  987. // {
  988. // Data = data,
  989. // FileName = System.IO.Path.ChangeExtension(docref.DocumentLink.FileName, "pdf"),
  990. // CRC = CoreUtils.CalculateCRC(data),
  991. // TimeStamp = DateTime.Now,
  992. // };
  993. // new Client<Document>().Save(newdoc, "Converted from Image");
  994. // return newdoc.ID;
  995. // }
  996. // return result;
  997. //}
  998. //private void CreateRequisition_Click(object sender, RoutedEventArgs e)
  999. //{
  1000. // MenuItem menu = sender as MenuItem;
  1001. // TaskModel task = menu.Tag as TaskModel;
  1002. // if (task.JobID.Equals(Guid.Empty))
  1003. // {
  1004. // MessageBox.Show("Please link this task to a job before creating a requisition!");
  1005. // return;
  1006. // }
  1007. // if (MessageBox.Show("This will convert this task into a Requisition.\n\nDo you wish to continue?", "Confirmation", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
  1008. // return;
  1009. // int requinumber = 0;
  1010. // Progress.ShowModal("Creating Requisition", (progress) =>
  1011. // {
  1012. // Kanban kanban = new Client<Kanban>().Load(new Filter<Kanban>(x => x.ID).IsEqualTo(task.ID)).FirstOrDefault();
  1013. // Requisition requi = new Requisition();
  1014. // requi.JobLink.ID = kanban.JobLink.ID;
  1015. // requi.RequestedBy.ID = kanban.ManagerLink.ID;
  1016. // requi.Employee.ID = Guid.Empty;
  1017. // requi.Title = kanban.Title;
  1018. // requi.Request = String.IsNullOrWhiteSpace(kanban.Summary)
  1019. // ? String.IsNullOrWhiteSpace(kanban.Summary)
  1020. // ? String.Join("\n", kanban.Notes)
  1021. // : CoreUtils.StripHTML(kanban.Description)
  1022. // : kanban.Summary;
  1023. // requi.Notes = kanban.Notes;
  1024. // requi.Due = kanban.DueDate;
  1025. // new Client<Requisition>().Save(requi, "Created from Task");
  1026. // requinumber = requi.Number;
  1027. // progress.Report("Updating Documents");
  1028. // List<RequisitionDocument> _documents = new List<RequisitionDocument>();
  1029. // KanbanDocument[] documents = new Client<KanbanDocument>().Load(new Filter<KanbanDocument>(x => x.EntityLink.ID).IsEqualTo(kanban.ID));
  1030. // foreach (var document in documents)
  1031. // {
  1032. // var newdoc = new RequisitionDocument();
  1033. // newdoc.EntityLink.ID = requi.ID;
  1034. // newdoc.DocumentLink.ID = document.DocumentLink.ID;
  1035. // _documents.Add(newdoc);
  1036. // }
  1037. // new Client<RequisitionDocument>().Save(_documents, "Converted from Task", (_, __) => { });
  1038. // RequisitionKanban link = new RequisitionKanban();
  1039. // link.Entity.ID = requi.ID;
  1040. // link.Kanban.ID = kanban.ID;
  1041. // new Client<RequisitionKanban>().Save(link, "Converting Task -> Requisition", (_, __) => { });
  1042. // progress.Report("Updating Task");
  1043. // kanban.Category = "Open";
  1044. // kanban.Completed = DateTime.MinValue;
  1045. // kanban.Locked = true;
  1046. // kanban.Title = kanban.Title + " (Requi #" + requi.Number.ToString() + ")";
  1047. // new Client<Kanban>().Save(kanban, "Converted to Requisition", (_, __) => { });
  1048. // });
  1049. // MessageBox.Show(String.Format("Created Requisition {0}", requinumber));
  1050. // Refresh();
  1051. //}
  1052. //private void CreatePurchaseOrder_Click(object sender, RoutedEventArgs e)
  1053. //{
  1054. // MenuItem menu = sender as MenuItem;
  1055. // TaskModel task = menu.Tag as TaskModel;
  1056. // if (MessageBox.Show("This will convert this task into a Purchase Order.\n\nDo you wish to continue?", "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
  1057. // {
  1058. // String ponumber = "";
  1059. // Progress.ShowModal("Creating Purchase Order", (progress) =>
  1060. // {
  1061. // Kanban kanban = new Client<Kanban>().Load(new Filter<Kanban>(x => x.ID).IsEqualTo(task.ID)).FirstOrDefault();
  1062. // PurchaseOrder order = new PurchaseOrder();
  1063. // order.Notes = kanban.Summary;
  1064. // order.RaisedBy.ID = kanban.EmployeeLink.ID;
  1065. // new Client<PurchaseOrder>().Save(order, "Created from Task Screen");
  1066. // ponumber = order.PONumber;
  1067. // progress.Report("Updating Documents");
  1068. // List<PurchaseOrderDocument> docs = new List<PurchaseOrderDocument>();
  1069. // var taskdocs = new Client<KanbanDocument>().Load(new Filter<KanbanDocument>(x => x.EntityLink.ID).IsEqualTo(Guid.Parse(task.ID)));
  1070. // foreach (var taskdoc in taskdocs)
  1071. // {
  1072. // PurchaseOrderDocument doc = new PurchaseOrderDocument();
  1073. // doc.DocumentLink.ID = taskdoc.DocumentLink.ID;
  1074. // doc.EntityLink.ID = order.ID;
  1075. // docs.Add(doc);
  1076. // }
  1077. // new Client<PurchaseOrderDocument>().Save(docs, "", (_, __) => { });
  1078. // progress.Report("Creating Links");
  1079. // PurchaseOrderKanban link = new PurchaseOrderKanban();
  1080. // link.Entity.ID = order.ID;
  1081. // link.Kanban.ID = kanban.ID;
  1082. // new Client<PurchaseOrderKanban>().Save(link, "Converting Task -> Purchase Order", (_, __) => { });
  1083. // progress.Report("Updating Task");
  1084. // kanban.Category = "Open";
  1085. // kanban.Completed = DateTime.MinValue;
  1086. // kanban.Locked = true;
  1087. // kanban.Title = "(PO#" + order.PONumber.ToString() + ") " + kanban.Title;
  1088. // new Client<Kanban>().Save(kanban, "Converted to Purchase Order", (_, __) => { });
  1089. // });
  1090. // MessageBox.Show(String.Format("Created Purchase Order {0}", ponumber));
  1091. // Refresh();
  1092. // }
  1093. //}
  1094. //private void CreateDelivery_Click(object sender, RoutedEventArgs e)
  1095. //{
  1096. // MenuItem menu = sender as MenuItem;
  1097. // TaskModel task = menu.Tag as TaskModel;
  1098. // if (MessageBox.Show("This will convert this task into a Delivery.\n\nDo you wish to continue?", "Confirmation", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
  1099. // return;
  1100. // int deliverynumber = 0;
  1101. // Progress.ShowModal("Creating Delivery", (progress) =>
  1102. // {
  1103. // Kanban kanban = new Client<Kanban>().Query(new Filter<Kanban>(x => x.ID).IsEqualTo(task.ID)).Rows.FirstOrDefault()?.ToObject<Kanban>();
  1104. // Delivery delivery = new Delivery();
  1105. // delivery.Due = kanban.DueDate;
  1106. // delivery.Job.ID = kanban.JobLink.ID;
  1107. // delivery.Job.Synchronise(kanban.JobLink);
  1108. // delivery.Notes = kanban.Summary;
  1109. // delivery.Employee.ID = kanban.ManagerLink.ID;
  1110. // delivery.Employee.Synchronise(kanban.ManagerLink);
  1111. // new Client<Delivery>().Save(delivery, "Created From Task");
  1112. // deliverynumber = delivery.Number;
  1113. // progress.Report("Updating Documents");
  1114. // List<DeliveryDocument> docs = new List<DeliveryDocument>();
  1115. // var taskdocs = new Client<KanbanDocument>().Load(new Filter<KanbanDocument>(x => x.EntityLink.ID).IsEqualTo(Guid.Parse(task.ID)));
  1116. // foreach (var taskdoc in taskdocs)
  1117. // {
  1118. // DeliveryDocument doc = new DeliveryDocument();
  1119. // doc.DocumentLink.ID = taskdoc.DocumentLink.ID;
  1120. // doc.EntityLink.ID = delivery.ID;
  1121. // docs.Add(doc);
  1122. // }
  1123. // new Client<DeliveryDocument>().Save(docs, "", (_, __) => { });
  1124. // progress.Report("Creating Links");
  1125. // DeliveryKanban link = new DeliveryKanban();
  1126. // link.Entity.ID = delivery.ID;
  1127. // link.Kanban.ID = kanban.ID;
  1128. // new Client<DeliveryKanban>().Save(link, "Converting Task -> Delivery", (_, __) => { });
  1129. // progress.Report("Updating Task");
  1130. // kanban.Category = "Open";
  1131. // kanban.Completed = DateTime.MinValue;
  1132. // kanban.Locked = true;
  1133. // kanban.Title = "(Del#" + delivery.Number.ToString() + ") " + kanban.Title;
  1134. // new Client<Kanban>().Save(kanban, "Converted to Delivery", (_, __) => { });
  1135. // });
  1136. // MessageBox.Show(String.Format("Created Delivery {0}", deliverynumber));
  1137. // Refresh();
  1138. //}
  1139. //private void CloseTask_Click(object sender, RoutedEventArgs e)
  1140. //{
  1141. // if (MessageBox.Show("Are you sure you want to remove the selected tasks from the list?", "Confirm removal", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
  1142. // return;
  1143. // Progress.ShowModal("Closing Kanbans", (progress) =>
  1144. // {
  1145. // TaskModel task = ((MenuItem)e.Source).Tag as TaskModel;
  1146. // Kanban[] kanbans = GetSelectedKanbans(task.ID);
  1147. // for (int i = 0; i < kanbans.Length; i++)
  1148. // {
  1149. // Kanban kanban = kanbans[i];
  1150. // kanban.Closed = DateTime.Now;
  1151. // }
  1152. // new Client<Kanban>().Save(kanbans, "Kanban Marked as Closed");
  1153. // CheckedKanbans.Clear();
  1154. // });
  1155. // Refresh();
  1156. //}
  1157. //private void EmailTask_Click(object sender, RoutedEventArgs e)
  1158. //{
  1159. // MenuItem menu = sender as MenuItem;
  1160. // TaskModel task = menu.Tag as TaskModel;
  1161. // Kanban kanban = new Client<Kanban>().Load(new Filter<Kanban>(x => x.ID).IsEqualTo(task.ID)).FirstOrDefault();
  1162. // List<String> to = new List<string>();
  1163. // String from = "";
  1164. // String salutation = "";
  1165. // if (MyID.HasValue)
  1166. // {
  1167. // CoreRow me = _employees.Rows.FirstOrDefault(r => r.Get<Employee, Guid>(c => c.ID).Equals(MyID));
  1168. // if (me != null)
  1169. // from = me.Get<Employee, String>(c => c.Name).Split(' ').FirstOrDefault();
  1170. // if (kanban.EmployeeLink.ID != MyID.Value)
  1171. // {
  1172. // CoreRow emp = _employees.Rows.FirstOrDefault(r => r.Get<Employee, Guid>(c => c.ID).Equals(kanban.EmployeeLink.ID));
  1173. // if (emp != null)
  1174. // {
  1175. // String email = emp.Get<Employee, String>(c => c.Email);
  1176. // if (!string.IsNullOrEmpty(email))
  1177. // {
  1178. // to.Add(email);
  1179. // String name = emp.Get<Employee, String>(c => c.Name).Split(' ').FirstOrDefault();
  1180. // salutation = salutation + (String.IsNullOrEmpty(salutation) ? "Hi " : " and ") + name;
  1181. // }
  1182. // }
  1183. // }
  1184. // if (kanban.ManagerLink.ID != MyID.Value)
  1185. // {
  1186. // CoreRow emp = _employees.Rows.FirstOrDefault(r => r.Get<Employee, Guid>(c => c.ID).Equals(kanban.ManagerLink.ID));
  1187. // if (emp != null)
  1188. // {
  1189. // String email = emp.Get<Employee, String>(c => c.Email);
  1190. // if (!string.IsNullOrEmpty(email))
  1191. // {
  1192. // to.Add(email);
  1193. // String name = emp.Get<Employee, String>(c => c.Name).Split(' ').FirstOrDefault();
  1194. // salutation = salutation + (String.IsNullOrEmpty(salutation) ? "Hi " : " and ") + name;
  1195. // }
  1196. // }
  1197. // }
  1198. // }
  1199. // Outlook.Application outlookApp = new Outlook.Application();
  1200. // Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
  1201. // mailItem.Subject = "PRS Task: " + kanban.Title;
  1202. // mailItem.To = String.Join("; ", to);
  1203. // mailItem.HTMLBody = String.Format("{0},<br><br>Please see the above task in PRS.<br><br>Regards,<br><br>{1}<br><br><b><u>Task Description:</u></b><br><i>{2}</i><br><br><b><u>Additional Notes:</u></b><br>{3}", salutation, from, CoreUtils.StripHTML(kanban.Description), String.Join("\r\n", kanban.Notes));
  1204. // //mailItem.Attachments.Add(filename, Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
  1205. // mailItem.Display(false);
  1206. //}
  1207. //private void CompleteTask_Click(object sender, RoutedEventArgs e)
  1208. //{
  1209. // if (MessageBox.Show("Are you sure you want to mark the selected tasks as complete?", "Confirm Completion", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
  1210. // return;
  1211. // TaskModel task = ((MenuItem)e.Source).Tag as TaskModel;
  1212. // Progress.ShowModal("Completing Task", (progress) =>
  1213. // {
  1214. // Kanban[] kanbans = GetSelectedKanbans(task.ID);
  1215. // for (int i = 0; i < kanbans.Length; i++)
  1216. // {
  1217. // Kanban kanban = kanbans[i];
  1218. // kanban.Completed = DateTime.Now;
  1219. // kanban.Category = "Complete";
  1220. // }
  1221. // new Client<Kanban>().Save(kanbans, "Kanban Marked as Completed");
  1222. // CheckedKanbans.Clear();
  1223. // });
  1224. // Refresh();
  1225. //}
  1226. #endregion
  1227. #region Kanban Creation / Editing
  1228. public void CreateKanban()
  1229. {
  1230. var result = Host.CreateKanban(
  1231. kanban =>
  1232. {
  1233. kanban.EmployeeLink.ID = EmployeeID != CoreUtils.FullGuid ? EmployeeID : MyID.Value;
  1234. kanban.ManagerLink.ID = MyID.Value;
  1235. kanban.ManagerLink.UserLink.ID = ClientFactory.UserGuid;
  1236. });
  1237. if (result != null)
  1238. Refresh(true);
  1239. }
  1240. private void DoEdit(TaskModel task)
  1241. {
  1242. if (task == null)
  1243. return;
  1244. var result = Host.EditReferences(new[] { task });
  1245. if (result)
  1246. Refresh(true);
  1247. }
  1248. #endregion
  1249. }
  1250. }