DynamicIssuesEditor.xaml.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using InABox.Wpf;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Input;
  8. using InABox.Clients;
  9. using InABox.Core;
  10. namespace InABox.DynamicGrid
  11. {
  12. /// <summary>
  13. /// Interaction logic for ProductIssuesWindow.xaml
  14. /// </summary>
  15. public partial class DynamicIssuesEditor : ThemableWindow
  16. {
  17. private readonly IIssues[] _items;
  18. private readonly List<string> notes = new();
  19. public DynamicIssuesEditor(IIssues[] issues, bool allowclear = false)
  20. {
  21. _items = issues;
  22. InitializeComponent();
  23. ReloadHistory();
  24. ClearIssues.Visibility = allowclear ? Visibility.Visible : Visibility.Collapsed;
  25. }
  26. private void ReloadHistory()
  27. {
  28. var issues = _items.Select(x => x.Issues).Where(x => !string.IsNullOrWhiteSpace(x)).Distinct().ToArray();
  29. var history = new List<string>();
  30. if (issues.Length == 1)
  31. history.Add(issues[0]);
  32. else if (issues.Length > 1)
  33. history.Add("(Multiple Issues Noted)");
  34. if (issues.Length > 0 && notes.Any())
  35. history.Add("=========================================");
  36. if (notes.Any())
  37. history.AddRange(notes);
  38. History.Text = string.Join("\n", history);
  39. }
  40. private void ClearIssues_Click(object sender, RoutedEventArgs e)
  41. {
  42. if (MessageBox.Show("Are you sure you wish to clear these notes?", "Confirm Clear", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
  43. return;
  44. foreach (var item in _items)
  45. item.Issues = "";
  46. DialogResult = true;
  47. }
  48. private void OK_Click(object sender, RoutedEventArgs e)
  49. {
  50. if (!notes.Any())
  51. {
  52. DialogResult = false;
  53. }
  54. else
  55. {
  56. foreach (var item in _items)
  57. item.Issues = (string.IsNullOrWhiteSpace(item.Issues) ? "" : item.Issues + "\n") + string.Format(
  58. "{0:dd MMM yy hh\\:mm\\:ss} {1} {2}",
  59. DateTime.Now, ClientFactory.UserID, string.Join("\n", notes));
  60. DialogResult = true;
  61. }
  62. }
  63. private void Cancel_Click(object sender, RoutedEventArgs e)
  64. {
  65. DialogResult = false;
  66. }
  67. private void AddNote_Click(object sender, RoutedEventArgs e)
  68. {
  69. DoAddNote();
  70. }
  71. private void DoAddNote()
  72. {
  73. notes.Add(NewNote.Text);
  74. NewNote.Text = "";
  75. NewNote.Focus();
  76. ReloadHistory();
  77. }
  78. private void NewNote_TextChanged(object sender, TextChangedEventArgs e)
  79. {
  80. AddNote.IsEnabled = !string.IsNullOrWhiteSpace(NewNote.Text);
  81. }
  82. private void AddNote_PreviewKeyDown(object sender, KeyEventArgs e)
  83. {
  84. if (e.Key == Key.Enter || e.Key == Key.Return)
  85. DoAddNote();
  86. }
  87. }
  88. }