MarkTreeItemUserControl.xaml.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. using ivf_tl_CustomControls;
  2. using ivf_tl_Entity.Entity;
  3. using ivf_tl_Entity.Entity.Mark;
  4. using ivf_tl_Entity.Enums;
  5. using ivf_tl_Manage.Converts;
  6. using ivf_tl_Manage.Win;
  7. using ivf_tl_Service.HttpProvider;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Data;
  16. using System.Windows.Documents;
  17. using System.Windows.Input;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Imaging;
  20. using System.Windows.Navigation;
  21. using System.Windows.Shapes;
  22. namespace ivf_tl_Manage.UserControls
  23. {
  24. /// <summary>
  25. /// MarkTreeItemUserControl.xaml 的交互逻辑
  26. /// </summary>
  27. public partial class MarkTreeItemUserControl : UserControl
  28. {
  29. public event Func<MarkEntity, string, bool> MarkOperEvent;
  30. public event Action<MarkEntity> ExpandedEvent;
  31. public MarkTreeItemUserControl()
  32. {
  33. InitializeComponent();
  34. }
  35. private void Del_Click(object sender, RoutedEventArgs e)
  36. {
  37. try
  38. {
  39. MarkOperEvent?.Invoke(MarkSource, "del");
  40. }
  41. catch (Exception ex)
  42. {
  43. ExLog(ex, "Del_Click");
  44. new ToastWindow(AppData.Instance.MainWindow, 1920, 65, false).Show();
  45. }
  46. }
  47. private void Add_Click(object sender, RoutedEventArgs e)
  48. {
  49. try
  50. {
  51. if (MarkOperEvent?.Invoke(MarkSource, "add") == true) if (!MarkSource.IsExpanded) ex();
  52. }
  53. catch (Exception ex)
  54. {
  55. ExLog(ex, "Add_Click");
  56. new ToastWindow(AppData.Instance.MainWindow, 1920, 65, false).Show();
  57. }
  58. }
  59. private void Edit_Click(object sender, RoutedEventArgs e)
  60. {
  61. try
  62. {
  63. MarkOperEvent?.Invoke(MarkSource, "edit");
  64. }
  65. catch (Exception ex)
  66. {
  67. ExLog(ex, "Edit_Click");
  68. new ToastWindow(AppData.Instance.MainWindow, 1920, 65, false).Show();
  69. }
  70. }
  71. private void CheckBox_Checked(object sender, RoutedEventArgs e)
  72. {
  73. try
  74. {
  75. if (!(sender is CheckBox source)) return;
  76. if (!source.IsLoaded) return;
  77. var pro = AppData.Instance.GetMarkSettingProvider();
  78. string error = pro.UpdateMarkDefeatApi(MarkSource.id, MarkSource.parentId, MarkSource.defaultValue);
  79. if (!string.IsNullOrEmpty(error))
  80. {
  81. //new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, $"操作失败:{error}").Show();
  82. new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, $"{KeyToStringConvert.GetLanguageStringByKey("0286")}:{error}").Show();
  83. return;
  84. }
  85. if (MarkSource.ParentMark == null) return;
  86. foreach (var item in MarkSource.ParentMark.children)
  87. {
  88. if (item.id == MarkSource.id) continue;
  89. item.defaultValue = 0;
  90. }
  91. }
  92. catch (Exception ex)
  93. {
  94. ExLog(ex, "CheckBox_Checked");
  95. new ToastWindow(AppData.Instance.MainWindow, 1920, 65, false).Show();
  96. }
  97. }
  98. private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
  99. {
  100. try
  101. {
  102. if (!(sender is CheckBox source)) return;
  103. if (!source.IsLoaded) return;
  104. var pro = AppData.Instance.GetMarkSettingProvider();
  105. string error = pro.UpdateMarkDefeatApi(MarkSource.id, MarkSource.parentId, MarkSource.defaultValue);
  106. if (!string.IsNullOrEmpty(error))
  107. {
  108. //new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, $"操作失败:{error}").Show();
  109. new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, $"{KeyToStringConvert.GetLanguageStringByKey("0286")}:{error}").Show();
  110. return;
  111. }
  112. }
  113. catch (Exception ex)
  114. {
  115. ExLog(ex, "CheckBox_Unchecked");
  116. new ToastWindow(AppData.Instance.MainWindow, 1920, 65, false).Show();
  117. }
  118. }
  119. public MarkEntity MarkSource
  120. {
  121. get { return (MarkEntity)GetValue(MarkSourceProperty); }
  122. set { SetValue(MarkSourceProperty, value); }
  123. }
  124. // Using a DependencyProperty as the backing store for MarkSource. This enables animation, styling, binding, etc...
  125. public static readonly DependencyProperty MarkSourceProperty =
  126. DependencyProperty.Register("MarkSource", typeof(MarkEntity), typeof(MarkTreeItemUserControl), new PropertyMetadata(new MarkEntity()));
  127. public Brush RectangleFill
  128. {
  129. get { return (Brush)GetValue(RectangleFillProperty); }
  130. set { SetValue(RectangleFillProperty, value); }
  131. }
  132. // Using a DependencyProperty as the backing store for RectangleFill. This enables animation, styling, binding, etc...
  133. public static readonly DependencyProperty RectangleFillProperty =
  134. DependencyProperty.Register("RectangleFill", typeof(Brush), typeof(MarkTreeItemUserControl), new PropertyMetadata(new SolidColorBrush((Color)ColorConverter.ConvertFromString("#EAEAEA"))));
  135. private void StackPanel_MouseUp(object sender, MouseButtonEventArgs e)
  136. {
  137. ex();
  138. }
  139. public void ex()
  140. {
  141. if (MarkSource.IsExpanded)
  142. {
  143. MarkSource.IsExpanded = false;
  144. ExpandedEvent?.Invoke(MarkSource);
  145. switch (MarkSource.level)
  146. {
  147. case 1:
  148. this.expand_Image1.Width = 10;
  149. this.expand_Image1.Height = 20;
  150. this.expand_Image1.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/unfoldMark.png", UriKind.Absolute));
  151. break;
  152. case 2:
  153. this.expand_Image2.Width = 10;
  154. this.expand_Image2.Height = 20;
  155. this.expand_Image2.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/unfoldMark.png", UriKind.Absolute));
  156. break;
  157. default:
  158. this.expand_Image3.Width = 10;
  159. this.expand_Image3.Height = 20;
  160. this.expand_Image3.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/unfoldMark.png", UriKind.RelativeOrAbsolute));
  161. break;
  162. }
  163. }
  164. else
  165. {
  166. MarkSource.IsExpanded = true;
  167. ExpandedEvent?.Invoke(MarkSource);
  168. switch (MarkSource.level)
  169. {
  170. case 1:
  171. this.expand_Image1.Width = 20;
  172. this.expand_Image1.Height = 10;
  173. this.expand_Image1.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/foldMark.png", UriKind.RelativeOrAbsolute));
  174. break;
  175. case 2:
  176. this.expand_Image2.Width = 20;
  177. this.expand_Image2.Height = 10;
  178. this.expand_Image2.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/foldMark.png", UriKind.RelativeOrAbsolute));
  179. break;
  180. default:
  181. this.expand_Image3.Width = 20;
  182. this.expand_Image3.Height = 10;
  183. this.expand_Image3.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/foldMark.png", UriKind.RelativeOrAbsolute));
  184. break;
  185. }
  186. }
  187. }
  188. private void ExLog(Exception ex, string name)
  189. {
  190. AppData.Instance.LogService.ExceptionLog(ex, $"MarkTreeItemUserControl.{name}", LogEnum.RunException);
  191. }
  192. private void ErrorLog(string message, LogEnum logType)
  193. {
  194. AppData.Instance.LogService.TLLog($"MarkTreeItemUserControl.{message}", logType);
  195. }
  196. }
  197. }