| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- using ivf_tl_CustomControls;
- using ivf_tl_Entity.Entity;
- using ivf_tl_Entity.Entity.Mark;
- using ivf_tl_Entity.Enums;
- using ivf_tl_Manage.Converts;
- using ivf_tl_Manage.Win;
- using ivf_tl_Service.HttpProvider;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace ivf_tl_Manage.UserControls
- {
- /// <summary>
- /// MarkTreeItemUserControl.xaml 的交互逻辑
- /// </summary>
- public partial class MarkTreeItemUserControl : UserControl
- {
- public event Func<MarkEntity, string, bool> MarkOperEvent;
- public event Action<MarkEntity> ExpandedEvent;
- public MarkTreeItemUserControl()
- {
- InitializeComponent();
- }
- private void Del_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- MarkOperEvent?.Invoke(MarkSource, "del");
- }
- catch (Exception ex)
- {
- ExLog(ex, "Del_Click");
- new ToastWindow(AppData.Instance.MainWindow, 1920, 65, false).Show();
- }
- }
- private void Add_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (MarkOperEvent?.Invoke(MarkSource, "add") == true) if (!MarkSource.IsExpanded) ex();
- }
- catch (Exception ex)
- {
- ExLog(ex, "Add_Click");
- new ToastWindow(AppData.Instance.MainWindow, 1920, 65, false).Show();
- }
- }
- private void Edit_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- MarkOperEvent?.Invoke(MarkSource, "edit");
- }
- catch (Exception ex)
- {
- ExLog(ex, "Edit_Click");
- new ToastWindow(AppData.Instance.MainWindow, 1920, 65, false).Show();
- }
- }
- private void CheckBox_Checked(object sender, RoutedEventArgs e)
- {
- try
- {
- if (!(sender is CheckBox source)) return;
- if (!source.IsLoaded) return;
- var pro = AppData.Instance.GetMarkSettingProvider();
- string error = pro.UpdateMarkDefeatApi(MarkSource.id, MarkSource.parentId, MarkSource.defaultValue);
- if (!string.IsNullOrEmpty(error))
- {
- //new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, $"操作失败:{error}").Show();
- new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, $"{KeyToStringConvert.GetLanguageStringByKey("0286")}:{error}").Show();
- return;
- }
- if (MarkSource.ParentMark == null) return;
- foreach (var item in MarkSource.ParentMark.children)
- {
- if (item.id == MarkSource.id) continue;
- item.defaultValue = 0;
- }
- }
- catch (Exception ex)
- {
- ExLog(ex, "CheckBox_Checked");
- new ToastWindow(AppData.Instance.MainWindow, 1920, 65, false).Show();
- }
- }
- private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
- {
- try
- {
- if (!(sender is CheckBox source)) return;
- if (!source.IsLoaded) return;
- var pro = AppData.Instance.GetMarkSettingProvider();
- string error = pro.UpdateMarkDefeatApi(MarkSource.id, MarkSource.parentId, MarkSource.defaultValue);
- if (!string.IsNullOrEmpty(error))
- {
- //new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, $"操作失败:{error}").Show();
- new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, $"{KeyToStringConvert.GetLanguageStringByKey("0286")}:{error}").Show();
- return;
- }
- }
- catch (Exception ex)
- {
- ExLog(ex, "CheckBox_Unchecked");
- new ToastWindow(AppData.Instance.MainWindow, 1920, 65, false).Show();
- }
- }
- public MarkEntity MarkSource
- {
- get { return (MarkEntity)GetValue(MarkSourceProperty); }
- set { SetValue(MarkSourceProperty, value); }
- }
- // Using a DependencyProperty as the backing store for MarkSource. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty MarkSourceProperty =
- DependencyProperty.Register("MarkSource", typeof(MarkEntity), typeof(MarkTreeItemUserControl), new PropertyMetadata(new MarkEntity()));
- public Brush RectangleFill
- {
- get { return (Brush)GetValue(RectangleFillProperty); }
- set { SetValue(RectangleFillProperty, value); }
- }
- // Using a DependencyProperty as the backing store for RectangleFill. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty RectangleFillProperty =
- DependencyProperty.Register("RectangleFill", typeof(Brush), typeof(MarkTreeItemUserControl), new PropertyMetadata(new SolidColorBrush((Color)ColorConverter.ConvertFromString("#EAEAEA"))));
- private void StackPanel_MouseUp(object sender, MouseButtonEventArgs e)
- {
- ex();
- }
- public void ex()
- {
- if (MarkSource.IsExpanded)
- {
- MarkSource.IsExpanded = false;
- ExpandedEvent?.Invoke(MarkSource);
- switch (MarkSource.level)
- {
- case 1:
- this.expand_Image1.Width = 10;
- this.expand_Image1.Height = 20;
- this.expand_Image1.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/unfoldMark.png", UriKind.Absolute));
- break;
- case 2:
- this.expand_Image2.Width = 10;
- this.expand_Image2.Height = 20;
- this.expand_Image2.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/unfoldMark.png", UriKind.Absolute));
- break;
- default:
- this.expand_Image3.Width = 10;
- this.expand_Image3.Height = 20;
- this.expand_Image3.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/unfoldMark.png", UriKind.RelativeOrAbsolute));
- break;
- }
- }
- else
- {
- MarkSource.IsExpanded = true;
- ExpandedEvent?.Invoke(MarkSource);
- switch (MarkSource.level)
- {
- case 1:
- this.expand_Image1.Width = 20;
- this.expand_Image1.Height = 10;
- this.expand_Image1.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/foldMark.png", UriKind.RelativeOrAbsolute));
- break;
- case 2:
- this.expand_Image2.Width = 20;
- this.expand_Image2.Height = 10;
- this.expand_Image2.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/foldMark.png", UriKind.RelativeOrAbsolute));
- break;
- default:
- this.expand_Image3.Width = 20;
- this.expand_Image3.Height = 10;
- this.expand_Image3.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/foldMark.png", UriKind.RelativeOrAbsolute));
- break;
- }
- }
- }
- private void ExLog(Exception ex, string name)
- {
- AppData.Instance.LogService.ExceptionLog(ex, $"MarkTreeItemUserControl.{name}", LogEnum.RunException);
- }
- private void ErrorLog(string message, LogEnum logType)
- {
- AppData.Instance.LogService.TLLog($"MarkTreeItemUserControl.{message}", logType);
- }
-
- }
- }
|