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
{
///
/// MarkTreeItemUserControl.xaml 的交互逻辑
///
public partial class MarkTreeItemUserControl : UserControl
{
public event Func MarkOperEvent;
public event Action 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);
}
}
}