From 96ae279d1f3cf1565de0e6f5b90d0fe2fb814fad Mon Sep 17 00:00:00 2001
From: YangCheng <235160615@qq.com>
Date: Thu, 2 Dec 2021 16:59:21 +0800
Subject: [PATCH 01/53] 2021-12-2
---
Vampirewal.Core/AssemblyInfo.cs | 1 +
.../Components/ViewModelLocatorBase.cs | 44 ++++++++-
.../SimpleMVVM/VampirewalApplication.cs | 2 +-
.../WpfTheme/Behavior/DataGridBehavior.cs | 90 +++++++++++++++++++
Vampirewal.Core/WpfTheme/CoreTheme.xaml | 1 +
.../DataGrid/DataGridStyles.xaml | 25 ++++++
6 files changed, 159 insertions(+), 4 deletions(-)
create mode 100644 Vampirewal.Core/WpfTheme/Behavior/DataGridBehavior.cs
create mode 100644 Vampirewal.Core/WpfTheme/CustomControl/DataGrid/DataGridStyles.xaml
diff --git a/Vampirewal.Core/AssemblyInfo.cs b/Vampirewal.Core/AssemblyInfo.cs
index 6a3bf3f..7248cbf 100644
--- a/Vampirewal.Core/AssemblyInfo.cs
+++ b/Vampirewal.Core/AssemblyInfo.cs
@@ -20,6 +20,7 @@ using System.Windows.Markup;
[assembly: XmlnsDefinitionAttribute("Vampirewal.UcView", "Vampirewal.Core.WpfTheme.UcView")]
[assembly: XmlnsDefinitionAttribute("Vampirewal.CustomControl", "Vampirewal.Core.WpfTheme.CustomControl")]
[assembly: XmlnsDefinitionAttribute("Vampirewal.SimpleMVVM", "Vampirewal.Core.SimpleMVVM")]
+[assembly: XmlnsDefinitionAttribute("Vampirewal.Behaviors", "Vampirewal.Core.WpfTheme.Behaviors")]
// 将 ComVisible 设置为 false 会使此程序集中的类型对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,请将该类型的 ComVisible
// 属性设置为 true。
diff --git a/Vampirewal.Core/Components/ViewModelLocatorBase.cs b/Vampirewal.Core/Components/ViewModelLocatorBase.cs
index 5b28058..3b884c7 100644
--- a/Vampirewal.Core/Components/ViewModelLocatorBase.cs
+++ b/Vampirewal.Core/Components/ViewModelLocatorBase.cs
@@ -32,20 +32,40 @@ namespace Vampirewal.Core.Components
public ViewModelLocatorBase()
{
//构造函数
+ InitRegisterService();
InitLocator();
+ InitRegisterViewModel();
+ }
+
+ ///
+ /// 初始化Locator,继承该基类后,重写即可,无需再将注册写进构造函数(第2步执行)
+ ///
+ public virtual void InitLocator()
+ {
+
+ }
+
+ ///
+ /// 初始化注册服务(第1步执行)
+ /// 不能移除base的内容
+ ///
+ public virtual void InitRegisterService()
+ {
CustomIoC.Instance.Register();
CustomIoC.Instance.Register();
CustomIoC.Instance.Register();
-
}
///
- /// 初始化Locator,继承该基类后,重写即可,无需再将注册写进构造函数
+ /// 初始化注册VM(第3步执行)
///
- public virtual void InitLocator()
+ public virtual void InitRegisterViewModel()
{
}
+
+
+
}
///
@@ -58,7 +78,9 @@ namespace Vampirewal.Core.Components
///
public ViewModelLocatorBaseEmpty()
{
+ InitRegisterService();
InitLocator();
+ InitRegisterViewModel();
}
///
@@ -68,5 +90,21 @@ namespace Vampirewal.Core.Components
{
}
+
+ ///
+ /// 初始化注册服务
+ ///
+ public virtual void InitRegisterService()
+ {
+
+ }
+
+ ///
+ /// 初始化注册VM
+ ///
+ public virtual void InitRegisterViewModel()
+ {
+
+ }
}
}
diff --git a/Vampirewal.Core/SimpleMVVM/VampirewalApplication.cs b/Vampirewal.Core/SimpleMVVM/VampirewalApplication.cs
index cacb820..c2f2224 100644
--- a/Vampirewal.Core/SimpleMVVM/VampirewalApplication.cs
+++ b/Vampirewal.Core/SimpleMVVM/VampirewalApplication.cs
@@ -24,7 +24,7 @@ using Vampirewal.Core.Interface;
namespace Vampirewal.Core.SimpleMVVM
{
///
- ///
+ /// Vampirewal版本的Application
///
public class VampirewalApplication: Application
{
diff --git a/Vampirewal.Core/WpfTheme/Behavior/DataGridBehavior.cs b/Vampirewal.Core/WpfTheme/Behavior/DataGridBehavior.cs
new file mode 100644
index 0000000..ed826cb
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/Behavior/DataGridBehavior.cs
@@ -0,0 +1,90 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:DataGridBehavior
+// 创 建 者:杨程
+// 创建时间:2021/12/2 15:06:45
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using Microsoft.Xaml.Behaviors;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+
+namespace Vampirewal.Core.WpfTheme.Behaviors
+{
+ public class DataGridBehavior
+ {
+ public DataGridBehavior()
+ {
+ //构造函数
+ }
+
+ #region 属性
+
+ #endregion
+
+ #region 公共方法
+
+ #endregion
+
+ #region 私有方法
+
+ #endregion
+
+ #region 命令
+
+ #endregion
+ }
+
+ public class DataGridGroupByBehavior : Behavior
+ {
+ ///
+ /// 绑定分组名称
+ ///
+ public string SetGroupByProrName { get; set; }
+
+ protected override void OnAttached()
+ {
+ if (string.IsNullOrEmpty(SetGroupByProrName))
+ {
+ return;
+ }
+
+ base.OnAttached();
+ base.AssociatedObject.LoadingRow += AssociatedObject_LoadingRow; ;
+ }
+
+ private void AssociatedObject_LoadingRow(object sender, DataGridRowEventArgs e)
+ {
+ base.AssociatedObject.LoadingRow -= AssociatedObject_LoadingRow;
+
+ var res = new ResourceDictionary() { Source = new Uri("pack://application:,,,/Vampirewal.Core;component/WpfTheme/CoreTheme.xaml", UriKind.RelativeOrAbsolute) };
+
+ DataGrid dataGrid = sender as DataGrid;
+
+ foreach (var item in dataGrid.ItemsSource)
+ {
+ dataGrid.GroupStyle.Add(new GroupStyle()
+ {
+ ContainerStyle = res["GroupHeaderStyle"] as Style
+ });
+
+ }
+
+ ICollectionView vw = CollectionViewSource.GetDefaultView(dataGrid.ItemsSource);
+ vw.GroupDescriptions.Add(new PropertyGroupDescription(SetGroupByProrName));
+ }
+ }
+}
diff --git a/Vampirewal.Core/WpfTheme/CoreTheme.xaml b/Vampirewal.Core/WpfTheme/CoreTheme.xaml
index 386c61b..15ed170 100644
--- a/Vampirewal.Core/WpfTheme/CoreTheme.xaml
+++ b/Vampirewal.Core/WpfTheme/CoreTheme.xaml
@@ -7,6 +7,7 @@
+
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/DataGrid/DataGridStyles.xaml b/Vampirewal.Core/WpfTheme/CustomControl/DataGrid/DataGridStyles.xaml
new file mode 100644
index 0000000..3ad3118
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/CustomControl/DataGrid/DataGridStyles.xaml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
--
Gitee
From 4e0646dbd2984e502f4de5a693026b5ab9e22815 Mon Sep 17 00:00:00 2001
From: YangCheng <235160615@qq.com>
Date: Thu, 2 Dec 2021 18:05:28 +0800
Subject: [PATCH 02/53] 2021-12-2-2
---
Vampirewal.Core/Vampirewal.Core.csproj | 2 +-
.../WpfTheme/Behavior/DataGridBehavior.cs | 12 +++++++++++-
.../CustomControl/DataGrid/DataGridStyles.xaml | 2 +-
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/Vampirewal.Core/Vampirewal.Core.csproj b/Vampirewal.Core/Vampirewal.Core.csproj
index 2a23258..70ad846 100644
--- a/Vampirewal.Core/Vampirewal.Core.csproj
+++ b/Vampirewal.Core/Vampirewal.Core.csproj
@@ -6,7 +6,7 @@
vampirewal
该Core类库详细介绍请查看:https://blog.csdn.net/weixin_42806176/article/details/120705323
true
- 1.0.1.3
+ 1.0.1.5
true
https://blog.csdn.net/weixin_42806176/article/details/120705323
Vampirewal-Logo.png
diff --git a/Vampirewal.Core/WpfTheme/Behavior/DataGridBehavior.cs b/Vampirewal.Core/WpfTheme/Behavior/DataGridBehavior.cs
index ed826cb..b7810c2 100644
--- a/Vampirewal.Core/WpfTheme/Behavior/DataGridBehavior.cs
+++ b/Vampirewal.Core/WpfTheme/Behavior/DataGridBehavior.cs
@@ -13,6 +13,7 @@
using Microsoft.Xaml.Behaviors;
using System;
+using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
@@ -84,7 +85,16 @@ namespace Vampirewal.Core.WpfTheme.Behaviors
}
ICollectionView vw = CollectionViewSource.GetDefaultView(dataGrid.ItemsSource);
- vw.GroupDescriptions.Add(new PropertyGroupDescription(SetGroupByProrName));
+
+ var cur = SetGroupByProrName.Split("-").ToList();
+
+ foreach (var item in cur)
+ {
+ vw.GroupDescriptions.Add(new PropertyGroupDescription(item));
+ }
+
}
+
+
}
}
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/DataGrid/DataGridStyles.xaml b/Vampirewal.Core/WpfTheme/CustomControl/DataGrid/DataGridStyles.xaml
index 3ad3118..371bd33 100644
--- a/Vampirewal.Core/WpfTheme/CustomControl/DataGrid/DataGridStyles.xaml
+++ b/Vampirewal.Core/WpfTheme/CustomControl/DataGrid/DataGridStyles.xaml
@@ -5,7 +5,7 @@
+
+
\ No newline at end of file
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/SearchControl/SearchControl.cs b/Vampirewal.Core/WpfTheme/CustomControl/SearchControl/SearchControl.cs
new file mode 100644
index 0000000..5f582a2
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/CustomControl/SearchControl/SearchControl.cs
@@ -0,0 +1,123 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:SreachControl
+// 创 建 者:杨程
+// 创建时间:2021/12/21 10:26:27
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+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.Input;
+
+namespace Vampirewal.Core.WpfTheme.CustomControl
+{
+ public class SearchControl:TextBox
+ {
+ private ResourceDictionary res
+ {
+ get
+ {
+ return new ResourceDictionary() { Source = new Uri("pack://application:,,,/Vampirewal.Core;component/WpfTheme/CoreTheme.xaml", UriKind.RelativeOrAbsolute) };
+ }
+ }
+
+ public SearchControl()
+ {
+ //构造函数
+
+ var BaseStyle = res["SearchControlStyle"] as Style;
+
+ this.Style = BaseStyle;
+ }
+
+ private TextBox SearchText { get; set; }
+ private Button SearchButton { get; set; }
+ public override void OnApplyTemplate()
+ {
+ base.OnApplyTemplate();
+ SearchText=this.Template.FindName("SearchText",this) as TextBox;
+
+ if (SearchTextStyle!=null)
+ {
+ SearchText.Style = SearchTextStyle;
+ }
+
+ SearchButton = this.Template.FindName("SearchButton", this) as Button;
+
+ if (SearchButtonStyle != null)
+ {
+ SearchButton.Style = SearchButtonStyle;
+ }
+ }
+
+ #region 属性
+
+ #endregion
+
+ #region 公共方法
+
+ #endregion
+
+ #region 私有方法
+
+ #endregion
+
+ #region 命令
+
+ #endregion
+
+ #region 依赖属性
+
+ public ICommand SearchCommand
+ {
+ get { return (ICommand)GetValue(SearchCommandProperty); }
+ set { SetValue(SearchCommandProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for SreachCommand. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty SearchCommandProperty =
+ DependencyProperty.Register("SearchCommand", typeof(ICommand), typeof(SearchControl), new PropertyMetadata(null));
+
+
+
+
+ public Style SearchTextStyle
+ {
+ get { return (Style)GetValue(SearchTextStyleProperty); }
+ set { SetValue(SearchTextStyleProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for SreachTextStyle. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty SearchTextStyleProperty =
+ DependencyProperty.Register("SearchTextStyle", typeof(Style), typeof(SearchControl), new PropertyMetadata(null));
+
+
+
+
+ public Style SearchButtonStyle
+ {
+ get { return (Style)GetValue(SearchButtonStyleProperty); }
+ set { SetValue(SearchButtonStyleProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for SearchButtonStyle. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty SearchButtonStyleProperty =
+ DependencyProperty.Register("SearchButtonStyle", typeof(Style), typeof(SearchControl), new PropertyMetadata(null));
+
+
+
+
+ #endregion
+ }
+}
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/SearchControl/SearchControlStyle.xaml b/Vampirewal.Core/WpfTheme/CustomControl/SearchControl/SearchControlStyle.xaml
new file mode 100644
index 0000000..7a685fa
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/CustomControl/SearchControl/SearchControlStyle.xaml
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Vampirewal.Core/WpfTheme/WindowStyle/NotifyDefultView.xaml b/Vampirewal.Core/WpfTheme/WindowStyle/NotifyDefultView.xaml
new file mode 100644
index 0000000..f20b715
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/WindowStyle/NotifyDefultView.xaml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 该页为默认展示页面,请自行替换!
+
+
+
+
+
diff --git a/Vampirewal.Core/WpfTheme/WindowStyle/NotifyDefultView.xaml.cs b/Vampirewal.Core/WpfTheme/WindowStyle/NotifyDefultView.xaml.cs
new file mode 100644
index 0000000..5d17d15
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/WindowStyle/NotifyDefultView.xaml.cs
@@ -0,0 +1,28 @@
+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 Vampirewal.Core.WpfTheme.WindowStyle
+{
+ ///
+ /// NotifyDefultView.xaml 的交互逻辑
+ ///
+ public partial class NotifyDefultView : UserControl
+ {
+ public NotifyDefultView()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/Vampirewal.Core/WpfTheme/WindowStyle/NotifyWindow.xaml b/Vampirewal.Core/WpfTheme/WindowStyle/NotifyWindow.xaml
new file mode 100644
index 0000000..df98a01
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/WindowStyle/NotifyWindow.xaml
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Vampirewal.Core/WpfTheme/WindowStyle/NotifyWindow.xaml.cs b/Vampirewal.Core/WpfTheme/WindowStyle/NotifyWindow.xaml.cs
new file mode 100644
index 0000000..f875eef
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/WindowStyle/NotifyWindow.xaml.cs
@@ -0,0 +1,229 @@
+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.Animation;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+using System.Windows.Threading;
+
+namespace Vampirewal.Core.WpfTheme.WindowStyle
+{
+ ///
+ /// NotifyWindow.xaml 的交互逻辑
+ ///
+ public partial class NotifyWindow : WindowBase
+ {
+
+
+ public NotifyWindow(NotifyWindowSetting _setting)
+ {
+ InitializeComponent();
+ Setting = _setting;
+ SetValue(_setting);
+ this.Loaded += NotifyWindow_Loaded;
+ }
+
+
+ private NotifyWindowSetting Setting { get; set; }
+
+ private void NotifyWindow_Loaded(object sender, RoutedEventArgs e)
+ {
+
+
+ var animation = new DoubleAnimation
+ {
+ Duration = new Duration(TimeSpan.FromSeconds(0.5)),
+ To = SystemParameters.WorkArea.Bottom - this.Height,
+ };
+ this.BeginAnimation(TopProperty, animation);
+
+ Left = SystemParameters.WorkArea.Right - this.Width-10;
+ Top = SystemParameters.WorkArea.Bottom;
+ }
+
+ private void SetValue(NotifyWindowSetting Setting)
+ {
+ Width = Setting.WindowWidth;
+ Height = Setting.WindowHeight;
+
+ if (Setting.UiView!=null)
+ {
+ UcView.Content = Setting.UiView;
+
+ Setting.UiView.Width = double.NaN;
+ Setting.UiView.Height = double.NaN;
+ }
+ else
+ {
+ NotifyDefultView notifyDefultView = new NotifyDefultView();
+ UcView.Content = notifyDefultView;
+ }
+
+
+
+ if (!string.IsNullOrEmpty(Setting.NotifyTitle))
+ {
+ this.Title = Setting.NotifyTitle;
+ }
+
+
+ if (!string.IsNullOrEmpty(Setting.Background))
+ {
+ this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(Setting.Background));
+ }
+ else
+ {
+ this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#2F3437"));
+ }
+
+ if (!string.IsNullOrEmpty(Setting.Foreground))
+ {
+ this.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(Setting.Foreground));
+ }
+ else
+ {
+ this.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#EBEBEB"));
+ }
+
+ if (!string.IsNullOrEmpty(Setting.WindowBorderBrush))
+ {
+ this.BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(Setting.WindowBorderBrush));
+ }
+ else
+ {
+ this.BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#3F4447"));
+ }
+
+ this.TitleFontSize = Setting.TitleFontSize;
+
+ if (Setting.DelayCloseTime>0)
+ {
+ DispatcherTimer timer=new DispatcherTimer();
+ timer.Interval = new TimeSpan(0, 0, Setting.DelayCloseTime);
+ timer.Tick += (s, e) =>
+ {
+
+ while(Setting.DelayCloseTime > 0)
+ {
+ Setting.DelayCloseTime--;
+ }
+
+ if (Setting.DelayCloseTime==0)
+ {
+ var animation = new DoubleAnimation
+ {
+ Duration = new Duration(TimeSpan.FromSeconds(0.3)),
+ To = SystemParameters.WorkArea.Bottom,
+ };
+ animation.Completed += (ss, ee) =>
+ {
+ this.Close();
+ };
+ this.BeginAnimation(TopProperty, animation);
+ }
+ };
+
+ timer.IsEnabled = true;
+ timer.Start();
+ }
+ }
+
+ protected override void TopTitle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
+ {
+
+ }
+
+ private void CloseButton_Click(object sender, RoutedEventArgs e)
+ {
+ var animation = new DoubleAnimation
+ {
+ Duration = new Duration(TimeSpan.FromSeconds(0.3)),
+ To = SystemParameters.WorkArea.Bottom,
+ };
+ animation.Completed += (ss, ee) =>
+ {
+ this.Close();
+ };
+ this.BeginAnimation(TopProperty, animation);
+
+
+ }
+ }
+
+ ///
+ /// Notify窗体配置
+ ///
+ public class NotifyWindowSetting
+ {
+ ///
+ /// Notify窗体标题
+ ///
+ public string NotifyTitle { get; set; } = "系统通知";
+ ///
+ /// 显示窗体
+ ///
+ public FrameworkElement UiView { get; set; }
+
+ ///
+ /// 窗体宽度
+ ///
+ public double WindowWidth { get; set; } = 300d;
+
+ ///
+ /// 窗体高度
+ ///
+ public double WindowHeight { get; set; } = 450d;
+
+ ///
+ /// 窗体背景色
+ ///
+ public string Background { get; set; } = "#2F3437";
+
+ ///
+ /// 窗体前景色
+ ///
+ public string Foreground { get; set; } = "#EBEBEB";
+
+ ///
+ /// 标题文字大小
+ ///
+ public int TitleFontSize { get; set; } = 12;
+
+ ///
+ /// 窗体边框颜色
+ ///
+ public string WindowBorderBrush { get; set; } = "#3F4447";
+
+ private int _DelayCloseTime =0;
+ ///
+ /// 延迟关闭时间(默认以秒计算)
+ /// 默认等于0,大于0即认为开启延迟关闭
+ ///
+ public int DelayCloseTime
+ {
+ get
+ {
+ if (_DelayCloseTime<0)
+ {
+ _DelayCloseTime = 0;
+ }
+
+ return _DelayCloseTime;
+ }
+ set
+ {
+ _DelayCloseTime = value;
+ }
+ }
+
+
+ }
+}
diff --git a/Vampirewal.Core/WpfTheme/WindowStyle/WindowBase.cs b/Vampirewal.Core/WpfTheme/WindowStyle/WindowBase.cs
index c3ecfe9..3777967 100644
--- a/Vampirewal.Core/WpfTheme/WindowStyle/WindowBase.cs
+++ b/Vampirewal.Core/WpfTheme/WindowStyle/WindowBase.cs
@@ -147,7 +147,12 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
//this.ResizeMode = ResizeMode.CanResize;
}
- private void TopTitle_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
+ ///
+ /// 自定义窗体标题栏鼠标左键按下事件(可重写)
+ ///
+ ///
+ ///
+ protected virtual void TopTitle_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
this.DragMove();
}
@@ -263,6 +268,22 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
DependencyProperty.Register("IsShowMaxButton", typeof(bool), typeof(WindowBase), new PropertyMetadata(true));
#endregion
+ #region 是否显示关闭按钮
+
+
+ public bool IsShowCloseButton
+ {
+ get { return (bool)GetValue(IsShowCloseButtonProperty); }
+ set { SetValue(IsShowCloseButtonProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for IsShowCloseButton. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty IsShowCloseButtonProperty =
+ DependencyProperty.Register("IsShowCloseButton", typeof(bool), typeof(WindowBase), new PropertyMetadata(true));
+
+
+ #endregion
+
#region 是否显示边框阴影
@@ -278,7 +299,7 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
//private static void IsShowDropShadowEffectPropertyChangeCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e)
//{
-
+
//}
diff --git a/Vampirewal.Core/WpfTheme/WindowStyle/WindowStyles.xaml b/Vampirewal.Core/WpfTheme/WindowStyle/WindowStyles.xaml
index f486913..09f91f8 100644
--- a/Vampirewal.Core/WpfTheme/WindowStyle/WindowStyles.xaml
+++ b/Vampirewal.Core/WpfTheme/WindowStyle/WindowStyles.xaml
@@ -1,55 +1,55 @@
-
+
-
-
-
+
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
\ No newline at end of file
diff --git a/test/App.xaml.cs b/test/App.xaml.cs
index abe05cc..bf38382 100644
--- a/test/App.xaml.cs
+++ b/test/App.xaml.cs
@@ -28,7 +28,7 @@ namespace test
//}
//RegisterMessenger();
-
+
OpenWinodw("test.MainWindow1");
diff --git a/test/MainViewModel.cs b/test/MainViewModel.cs
index 2ba3775..bd5cc52 100644
--- a/test/MainViewModel.cs
+++ b/test/MainViewModel.cs
@@ -13,21 +13,24 @@
using System;
using System.Collections.Generic;
+using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Vampirewal.Core.Interface;
+using Vampirewal.Core.Models;
using Vampirewal.Core.SimpleMVVM;
+using Vampirewal.Core.SimpleMVVM.Attributes;
using Vampirewal.Core.WpfTheme.WindowStyle;
namespace test
{
- public class MainViewModel:ViewModelBase
+ public class MainViewModel:BaseCRUDVM
{
private IDialogMessage Dialog { get; set; }
- public MainViewModel(IDialogMessage dialog,IAppConfig appConfig)
+ public MainViewModel(IDialogMessage dialog,IAppConfig appConfig):base()
{
appConfig.ConfigPath = $"{AppDomain.CurrentDomain.BaseDirectory}UpdateConfig";
appConfig.ConfigName = "UpdateConfig.json";
@@ -38,9 +41,19 @@ namespace test
Dialog = dialog;
//log.DebugLog("测试", "MainView");
+ Entity.hahas.Add("asd");
+ Entity.hahas.Add("asd");
+ Entity.hahas.Add("asd");
+ Entity.hahas.Add("asd");
+
+ GetAllEquip();
+ }
+
+ public override void InitData()
+ {
+ Equips = new ObservableCollection();
}
-
#region 属性
private string _OldStr;
@@ -59,6 +72,9 @@ namespace test
set { _NewStr = value; DoNotify(); }
}
+ public ObservableCollection Equips { get; set; }
+
+ public List orderbys { get; set; }=new List() { "Province", "City" };
#endregion
#region 公共方法
@@ -66,28 +82,73 @@ namespace test
#endregion
#region 私有方法
-
+ private void GetAllEquip()
+ {
+ //测试
+ for (int i = 0; i < 30; i++)
+ {
+ Equips.Add(new Equip()
+ {
+ EquipName = $"S{i}",
+ Province = "四川省",
+ City = "成都市"
+ });
+ }
+
+ for (int i = 0; i < 45; i++)
+ {
+ Equips.Add(new Equip()
+ {
+ EquipName = $"S{i}",
+ Province = "四川省",
+ City = "南充市"
+ });
+ }
+
+ for (int i = 0; i < 55; i++)
+ {
+ Equips.Add(new Equip()
+ {
+ EquipName = $"Y{i}",
+ Province = "云南省",
+ City = "昆明市"
+ });
+ }
+
+
+ }
#endregion
#region 命令
public RelayCommand OpenDialogWindowCommand => new RelayCommand(() =>
{
- FrameworkElement testview = Messenger.Default.Send("GetView", "test.test_NewPage");
+ //FrameworkElement testview = Messenger.Default.Send("GetView", "test.test_NewPage");
+
+ //Dialog.OpenDialogWindow(new DialogWindowSetting()
+ //{
+ // UiView = testview,
+ // WindowWidth = 1500,
+ // WindowHeight = 600,
+ // IconStr = "",
+ // IsShowMaxButton = true,
+ // IsShowMinButton = true,
+ // TitleFontSize = 20,
+ // PassData = "test",
+ // IsOpenWindowSize = true
+ //});
+
+ //Dialog.OpenVampirewalFolderBrowserDialog();
- Dialog.OpenDialogWindow(new DialogWindowSetting()
+ FrameworkElement testview = Messenger.Default.Send("GetView", "test.NotifyTestUserControl");
+
+ Dialog.OpenNotifyWindow(new NotifyWindowSetting()
{
- UiView = testview,
- WindowWidth = 1500,
- WindowHeight = 600,
- IconStr = "",
- IsShowMaxButton = true,
- IsShowMinButton = true,
- TitleFontSize = 20,
- PassData = "test",
- IsOpenWindowSize = true
+ //UiView= testview,
+ //WindowWidth =300,
+ //WindowHeight =450,
+ DelayCloseTime=5,
+ NotifyTitle="测试通知"
});
-
- //Dialog.OpenVampirewalFolderBrowserDialog();
});
@@ -95,16 +156,72 @@ namespace test
{
//byte[] byteArray = System.Text.Encoding.Default.GetBytes(OldStr);
- int aa= Convert.ToInt32(OldStr, 16);
+ //int aa= Convert.ToInt32(OldStr, 16);
+
+ //NewStr = aa.ToString();
+
+ Entity.hahas.Add("asd");
- NewStr = aa.ToString();
});
public RelayCommand TextChangedCommand => new RelayCommand(() =>
{
- Config.Save();
+ var aaa = Entity.hahas;
+
+ //Config.Save();
+ });
+
+
+ public RelayCommand SearchCommand => new RelayCommand((s) =>
+ {
+
});
#endregion
}
+
+ public class TestModel:TopBaseModel
+ {
+
+ public string haha { get; set; }=String.Empty;
+
+
+ public List hahas { get; set;} = new List();
+
+ private string _haha2;
+
+ public string haha2
+ {
+ get { return _haha2; }
+ set { _haha2 = value;DoNotify(); }
+ }
+
+ }
+
+
+ public class Equip : TopBaseModel
+ {
+ ///
+ /// 设备名称
+ ///
+ public string EquipName { get; set; }
+
+
+
+
+ ///
+ /// 设备是否在线
+ ///
+ public bool IsOnline { get; set; }
+
+ ///
+ /// 所在省
+ ///
+ public string Province { get; set; }
+
+ ///
+ /// 所在市
+ ///
+ public string City { get; set; }
+ }
}
diff --git a/test/MainWindow.xaml b/test/MainWindow.xaml
index f500bd8..3c3ab10 100644
--- a/test/MainWindow.xaml
+++ b/test/MainWindow.xaml
@@ -7,8 +7,11 @@
xmlns:corewindow="Vampirewal.Windows"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
Title="MainWindow"
- Width="800" xmlns:VB="clr-namespace:Vampirewal.Core.WpfTheme.Behaviors;assembly=Vampirewal.Core"
+ Width="800"
+ xmlns:VB="clr-namespace:Vampirewal.Core.WpfTheme.Behaviors;assembly=Vampirewal.Core"
Height="450"
+ xmlns:VAttach="clr-namespace:Vampirewal.Core.WpfTheme.Attach;assembly=Vampirewal.Core"
+ xmlns:VBeh="clr-namespace:Vampirewal.Core.WpfTheme.Behaviors;assembly=Vampirewal.Core"
Background="#2F3437"
BorderBrush="#373C3F"
DataContext="{Binding Source={StaticResource Locator}, Path=MainViewModel}"
@@ -20,28 +23,30 @@
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+ -->
-
-
+ Style="{StaticResource DefaultTextBox}" />-->
+
+
+
diff --git a/test/NotifyTestUserControl.xaml b/test/NotifyTestUserControl.xaml
new file mode 100644
index 0000000..574db3a
--- /dev/null
+++ b/test/NotifyTestUserControl.xaml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/test/NotifyTestUserControl.xaml.cs b/test/NotifyTestUserControl.xaml.cs
new file mode 100644
index 0000000..5cc1284
--- /dev/null
+++ b/test/NotifyTestUserControl.xaml.cs
@@ -0,0 +1,28 @@
+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 test
+{
+ ///
+ /// NotifyTestUserControl.xaml 的交互逻辑
+ ///
+ public partial class NotifyTestUserControl : UserControl
+ {
+ public NotifyTestUserControl()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/test/TestAddorEditView.xaml b/test/TestAddorEditView.xaml
index 6ba1273..ec7dc87 100644
--- a/test/TestAddorEditView.xaml
+++ b/test/TestAddorEditView.xaml
@@ -7,7 +7,7 @@
mc:Ignorable="d" DataContext="{Binding Source={StaticResource Locator},Path=TestAddorEditViewModel}"
d:DesignHeight="450" d:DesignWidth="800">
-
+
diff --git a/test/ViewModelLocator.cs b/test/ViewModelLocator.cs
index 5b5aa5c..a802715 100644
--- a/test/ViewModelLocator.cs
+++ b/test/ViewModelLocator.cs
@@ -26,12 +26,16 @@ namespace test
{
public override void InitLocator()
{
- //CustomIoC.Instance.Register();
- //CustomIoC.Instance.Register();
+ CustomIoC.Instance.Register();
+ CustomIoC.Instance.Register();
CustomIoC.Instance.Register();
CustomIoC.Instance.Register();
CustomIoC.Instance.Register();
+
+ //WindowsManager.RegisterWindow();
+
+ //WindowsManager.StartFirstWindow("test.MainWindow1");
}
--
Gitee
From d86e31fefab956bd0ae85ce714e5bf3e1f40d428 Mon Sep 17 00:00:00 2001
From: YangCheng <235160615@qq.com>
Date: Sat, 29 Jan 2022 14:06:15 +0800
Subject: [PATCH 04/53] =?UTF-8?q?2022-1-29=202.0=E5=B0=86=E5=81=9C?=
=?UTF-8?q?=E6=AD=A2=E6=9B=B4=E6=96=B0=E4=BA=86=EF=BC=8C=E5=90=8E=E7=BB=AD?=
=?UTF-8?q?=E5=B0=86EFCORE=E6=9B=B4=E6=94=B9=E4=B8=BASqlSugar?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Components/VampirewalUpdate.cs | 48 +++++++++++++++
Vampirewal.Core/DBContexts/DBContextBase.cs | 2 +-
Vampirewal.Core/Vampirewal.Core.csproj | 2 +-
Vampirewal.Core/WpfTheme/CoreTheme.xaml | 14 ++++-
.../CustomControl/NumTextBox/NumTextBox.cs | 45 ++++++++++++++
.../NumTextBox/NumTextBoxStyle.xaml | 60 +++++++++++++++++++
.../WpfTheme/WindowStyle/NotifyWindow.xaml | 2 +-
.../WpfTheme/WindowStyle/NotifyWindow.xaml.cs | 14 ++++-
test/MainViewModel.cs | 47 ++++++++-------
test/MainWindow.xaml | 8 ++-
test/NotifyTestUserControl.xaml | 4 +-
test/NotifyTestUserControl.xaml.cs | 18 ++++++
test/TestAddorEditViewModel.cs | 2 +-
test/ViewModelLocator.cs | 7 +++
14 files changed, 238 insertions(+), 35 deletions(-)
create mode 100644 Vampirewal.Core/Components/VampirewalUpdate.cs
create mode 100644 Vampirewal.Core/WpfTheme/CustomControl/NumTextBox/NumTextBox.cs
create mode 100644 Vampirewal.Core/WpfTheme/CustomControl/NumTextBox/NumTextBoxStyle.xaml
diff --git a/Vampirewal.Core/Components/VampirewalUpdate.cs b/Vampirewal.Core/Components/VampirewalUpdate.cs
new file mode 100644
index 0000000..999e754
--- /dev/null
+++ b/Vampirewal.Core/Components/VampirewalUpdate.cs
@@ -0,0 +1,48 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:VampirewalUpdate
+// 创 建 者:杨程
+// 创建时间:2022/1/17 15:53:26
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Vampirewal.Core.Components
+{
+ ///
+ /// 自动更新组件
+ ///
+ public class VampirewalUpdate
+ {
+ public VampirewalUpdate()
+ {
+ //构造函数
+ }
+
+ #region 属性
+
+ #endregion
+
+ #region 公共方法
+
+ #endregion
+
+ #region 私有方法
+
+ #endregion
+
+ #region 命令
+
+ #endregion
+ }
+}
diff --git a/Vampirewal.Core/DBContexts/DBContextBase.cs b/Vampirewal.Core/DBContexts/DBContextBase.cs
index eb9d3ff..37e9180 100644
--- a/Vampirewal.Core/DBContexts/DBContextBase.cs
+++ b/Vampirewal.Core/DBContexts/DBContextBase.cs
@@ -321,7 +321,7 @@ namespace Vampirewal.Core.DBContexts
}
}
- public DataTable Run(string sql, CommandType commandType, params object[] paras)
+ public virtual DataTable Run(string sql, CommandType commandType, params object[] paras)
{
DataTable table = new DataTable();
switch (this.DBType)
diff --git a/Vampirewal.Core/Vampirewal.Core.csproj b/Vampirewal.Core/Vampirewal.Core.csproj
index 685d2f5..8621d1a 100644
--- a/Vampirewal.Core/Vampirewal.Core.csproj
+++ b/Vampirewal.Core/Vampirewal.Core.csproj
@@ -6,7 +6,7 @@
vampirewal
该Core类库详细介绍请查看:https://blog.csdn.net/weixin_42806176/article/details/120705323
true
- 1.0.1.6
+ 1.0.1.7
true
https://blog.csdn.net/weixin_42806176/article/details/120705323
Vampirewal-Logo.png
diff --git a/Vampirewal.Core/WpfTheme/CoreTheme.xaml b/Vampirewal.Core/WpfTheme/CoreTheme.xaml
index c1d64b2..0f2e455 100644
--- a/Vampirewal.Core/WpfTheme/CoreTheme.xaml
+++ b/Vampirewal.Core/WpfTheme/CoreTheme.xaml
@@ -10,6 +10,7 @@
+
@@ -45,8 +46,9 @@
-
-
+
+
@@ -82,6 +84,14 @@
+
+
+
+
+
+
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/NumTextBox/NumTextBox.cs b/Vampirewal.Core/WpfTheme/CustomControl/NumTextBox/NumTextBox.cs
new file mode 100644
index 0000000..6e81f7c
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/CustomControl/NumTextBox/NumTextBox.cs
@@ -0,0 +1,45 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:NumTextBox
+// 创 建 者:杨程
+// 创建时间:2022/1/10 17:23:35
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+
+namespace Vampirewal.Core.WpfTheme.CustomControl
+{
+ public class NumTextBox:TextBox
+ {
+ private ResourceDictionary res
+ {
+ get
+ {
+ return new ResourceDictionary() { Source = new Uri("pack://application:,,,/Vampirewal.Core;component/WpfTheme/CoreTheme.xaml", UriKind.RelativeOrAbsolute) };
+ }
+ }
+
+ public NumTextBox()
+ {
+ //构造函数
+
+ var BaseStyle = res["NumTextBoxStyle"] as Style;
+
+ this.Style = BaseStyle;
+ }
+
+
+ }
+}
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/NumTextBox/NumTextBoxStyle.xaml b/Vampirewal.Core/WpfTheme/CustomControl/NumTextBox/NumTextBoxStyle.xaml
new file mode 100644
index 0000000..a84372b
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/CustomControl/NumTextBox/NumTextBoxStyle.xaml
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Vampirewal.Core/WpfTheme/WindowStyle/NotifyWindow.xaml b/Vampirewal.Core/WpfTheme/WindowStyle/NotifyWindow.xaml
index df98a01..5f7204a 100644
--- a/Vampirewal.Core/WpfTheme/WindowStyle/NotifyWindow.xaml
+++ b/Vampirewal.Core/WpfTheme/WindowStyle/NotifyWindow.xaml
@@ -6,7 +6,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Vampirewal.Core.WpfTheme.WindowStyle"
mc:Ignorable="d"
- IsShowCloseButton="False"
+ IsShowCloseButton="False"
IsShowMaxButton="False"
IsShowMinButton="False"
ShowInTaskbar="False"
diff --git a/Vampirewal.Core/WpfTheme/WindowStyle/NotifyWindow.xaml.cs b/Vampirewal.Core/WpfTheme/WindowStyle/NotifyWindow.xaml.cs
index f875eef..38a2834 100644
--- a/Vampirewal.Core/WpfTheme/WindowStyle/NotifyWindow.xaml.cs
+++ b/Vampirewal.Core/WpfTheme/WindowStyle/NotifyWindow.xaml.cs
@@ -13,6 +13,7 @@ using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
+using Vampirewal.Core.SimpleMVVM;
namespace Vampirewal.Core.WpfTheme.WindowStyle
{
@@ -60,6 +61,14 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
Setting.UiView.Width = double.NaN;
Setting.UiView.Height = double.NaN;
+
+ var vm = Setting.UiView.DataContext as ViewModelBase;
+
+ if ( vm !=null)
+ {
+
+ vm.PassData(Setting.PassData);
+ }
}
else
{
@@ -224,6 +233,9 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
}
}
-
+ ///
+ /// 需要传输的数据
+ ///
+ public object PassData { get; set; }
}
}
diff --git a/test/MainViewModel.cs b/test/MainViewModel.cs
index bd5cc52..8e06955 100644
--- a/test/MainViewModel.cs
+++ b/test/MainViewModel.cs
@@ -122,33 +122,34 @@ namespace test
#region 命令
public RelayCommand OpenDialogWindowCommand => new RelayCommand(() =>
{
- //FrameworkElement testview = Messenger.Default.Send("GetView", "test.test_NewPage");
+ FrameworkElement testview = Messenger.Default.Send("GetView", "test.test_NewPage");
- //Dialog.OpenDialogWindow(new DialogWindowSetting()
- //{
- // UiView = testview,
- // WindowWidth = 1500,
- // WindowHeight = 600,
- // IconStr = "",
- // IsShowMaxButton = true,
- // IsShowMinButton = true,
- // TitleFontSize = 20,
- // PassData = "test",
- // IsOpenWindowSize = true
- //});
+ Dialog.OpenDialogWindow(new DialogWindowSetting()
+ {
+ UiView = testview,
+ WindowWidth = 1500,
+ WindowHeight = 600,
+ IconStr = "",
+ IsShowMaxButton = true,
+ IsShowMinButton = true,
+ TitleFontSize = 20,
+ PassData = "test",
+ IsOpenWindowSize = true
+ });
//Dialog.OpenVampirewalFolderBrowserDialog();
- FrameworkElement testview = Messenger.Default.Send("GetView", "test.NotifyTestUserControl");
+ //FrameworkElement testview = Messenger.Default.Send("GetView", "test.NotifyTestUserControl");
- Dialog.OpenNotifyWindow(new NotifyWindowSetting()
- {
- //UiView= testview,
- //WindowWidth =300,
- //WindowHeight =450,
- DelayCloseTime=5,
- NotifyTitle="测试通知"
- });
+ //Dialog.OpenNotifyWindow(new NotifyWindowSetting()
+ //{
+ // UiView = testview,
+ // //WindowWidth =300,
+ // //WindowHeight =450,
+ // DelayCloseTime =0,
+ // NotifyTitle="测试通知",
+ // PassData="Passdata"
+ //});
});
@@ -168,7 +169,7 @@ namespace test
public RelayCommand TextChangedCommand => new RelayCommand(() =>
{
var aaa = Entity.hahas;
-
+
//Config.Save();
});
diff --git a/test/MainWindow.xaml b/test/MainWindow.xaml
index 3c3ab10..008f846 100644
--- a/test/MainWindow.xaml
+++ b/test/MainWindow.xaml
@@ -65,12 +65,14 @@
-
+
+
-
+
- -->
+
+
+
diff --git a/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml b/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml
index 88f415e..fab3808 100644
--- a/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml
+++ b/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml
@@ -9,13 +9,12 @@
Title="{Binding Title}"
Width="800"
Height="450"
- Background="#2F3437"
+ Background="#2F3437"
Foreground="#EBEBEB"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d">
-
diff --git a/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml.cs b/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml.cs
index d0af798..c15f392 100644
--- a/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml.cs
+++ b/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml.cs
@@ -100,12 +100,13 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
if (Setting.CloseWindowCommand!=null)
{
this.CloseWindowCommand = Setting.CloseWindowCommand;
+ this.CloseWindowCommandParameter = Setting.CloseWindowCommandParameter;
}
}
protected override void CloseWin_Click(object sender, RoutedEventArgs e)
{
- CloseWindowCommand?.Execute(null);
+ CloseWindowCommand?.Execute(CloseWindowCommandParameter);
base.CloseWin_Click(sender, e);
}
@@ -125,6 +126,21 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
DependencyProperty.Register("CloseWindowCommand", typeof(ICommand), typeof(ShowDialogWindow), new PropertyMetadata(null));
+
+ ///
+ /// 弹窗关闭的命令传参
+ ///
+ public object CloseWindowCommandParameter
+ {
+ get { return (object)GetValue(CloseWindowCommandParameterProperty); }
+ set { SetValue(CloseWindowCommandParameterProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for CloseWindowCommandParameter. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty CloseWindowCommandParameterProperty =
+ DependencyProperty.Register("CloseWindowCommandParameter", typeof(object), typeof(ShowDialogWindow), new PropertyMetadata(null));
+
+
}
///
@@ -197,5 +213,10 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
/// 弹窗关闭的命令
///
public ICommand CloseWindowCommand { get; set; }
+
+ ///
+ /// 弹窗关闭的命令传参
+ ///
+ public object CloseWindowCommandParameter { get; set; }
}
}
--
Gitee
From ff556e71765d310d3c4450f01fe29bc82a12bc40 Mon Sep 17 00:00:00 2001
From: YangCheng <235160615@qq.com>
Date: Tue, 1 Mar 2022 16:33:10 +0800
Subject: [PATCH 11/53] 2022-3-1
---
Vampirewal.Core.FlowEngine/Model/Work.cs | 26 ++
.../Vampirewal.Core.FlowEngine.csproj | 11 +
.../HttpWebClientHelper.cs | 106 ++++++++
.../Model/AbilitiesModel.cs | 34 +++
.../Model/DocDetail.cs | 37 +++
.../Model/DocDetailData.cs | 134 ++++++++++
Vampirewal.Core.YuQueHelper/Model/Topic.cs | 92 +++++++
.../Model/TopicInfo.cs | 32 +++
.../Model/TopicTree.cs | 32 +++
.../Vampirewal.Core.YuQueHelper.csproj | 11 +
Vampirewal.Core.YuQueHelper/YuQueClient.cs | 246 ++++++++++++++++++
Vampirewal.Core/Extensions/EntityExtension.cs | 2 +-
.../Extensions/ITreeDataExtension.cs | 6 +-
Vampirewal.Core/Extensions/TypeExtension.cs | 2 +-
Vampirewal.Core/Interface/IBaseCRUDVM.cs | 2 +-
Vampirewal.Core/Interface/IBaseListVM.cs | 4 +-
Vampirewal.Core/Interface/ITreeData.cs | 2 +-
Vampirewal.Core/Models/BaseModel.cs | 28 +-
Vampirewal.Core/Models/FileAttachment.cs | 5 +-
Vampirewal.Core/Models/FrameworkDomain.cs | 5 +-
Vampirewal.Core/Models/FrameworkRole.cs | 6 +-
Vampirewal.Core/Models/FrameworkUserBase.cs | 5 +-
Vampirewal.Core/Models/FrameworkUserRole.cs | 5 +-
Vampirewal.Core/Models/TopBaseModel.cs | 238 ++++++++---------
Vampirewal.Core/Models/TopModel.cs | 37 +++
Vampirewal.Core/Models/TreeBaseModel.cs | 130 ++++-----
Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs | 2 +-
Vampirewal.Core/SimpleMVVM/ViewModelBase.cs | 4 +-
Vampirewal.Core/Tools/HttpClientHelper.cs | 1 +
Vampirewal.Core/Tools/Utils.cs | 6 +-
YC.Core.sln | 18 +-
test/MainViewModel.cs | 72 ++++-
test/test.csproj | 2 +
33 files changed, 1106 insertions(+), 237 deletions(-)
create mode 100644 Vampirewal.Core.FlowEngine/Model/Work.cs
create mode 100644 Vampirewal.Core.FlowEngine/Vampirewal.Core.FlowEngine.csproj
create mode 100644 Vampirewal.Core.YuQueHelper/HttpWebClientHelper.cs
create mode 100644 Vampirewal.Core.YuQueHelper/Model/AbilitiesModel.cs
create mode 100644 Vampirewal.Core.YuQueHelper/Model/DocDetail.cs
create mode 100644 Vampirewal.Core.YuQueHelper/Model/DocDetailData.cs
create mode 100644 Vampirewal.Core.YuQueHelper/Model/Topic.cs
create mode 100644 Vampirewal.Core.YuQueHelper/Model/TopicInfo.cs
create mode 100644 Vampirewal.Core.YuQueHelper/Model/TopicTree.cs
create mode 100644 Vampirewal.Core.YuQueHelper/Vampirewal.Core.YuQueHelper.csproj
create mode 100644 Vampirewal.Core.YuQueHelper/YuQueClient.cs
diff --git a/Vampirewal.Core.FlowEngine/Model/Work.cs b/Vampirewal.Core.FlowEngine/Model/Work.cs
new file mode 100644
index 0000000..6714f3c
--- /dev/null
+++ b/Vampirewal.Core.FlowEngine/Model/Work.cs
@@ -0,0 +1,26 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:Work
+// 创 建 者:杨程
+// 创建时间:2022/2/21 20:49:55
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Vampirewal.Core.FlowEngine.Model
+{
+ public class Work
+ {
+ public string WorkId { get; set; }
+ }
+}
diff --git a/Vampirewal.Core.FlowEngine/Vampirewal.Core.FlowEngine.csproj b/Vampirewal.Core.FlowEngine/Vampirewal.Core.FlowEngine.csproj
new file mode 100644
index 0000000..0a2124e
--- /dev/null
+++ b/Vampirewal.Core.FlowEngine/Vampirewal.Core.FlowEngine.csproj
@@ -0,0 +1,11 @@
+
+
+
+ net5.0-windows
+
+
+
+
+
+
+
diff --git a/Vampirewal.Core.YuQueHelper/HttpWebClientHelper.cs b/Vampirewal.Core.YuQueHelper/HttpWebClientHelper.cs
new file mode 100644
index 0000000..32b7363
--- /dev/null
+++ b/Vampirewal.Core.YuQueHelper/HttpWebClientHelper.cs
@@ -0,0 +1,106 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:HttpWebClientHelper
+// 创 建 者:杨程
+// 创建时间:2022/2/23 14:28:39
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.Threading.Tasks;
+using System.Web;
+
+namespace Vampirewal.Core.YuQueHelper
+{
+ internal static class HttpWebClientHelper
+ {
+ ///
+ /// get请求
+ ///
+ /// 请求地址
+ /// 语雀个人设置的token
+ /// 语雀需要收集的用户标识
+ /// 请求到的数据
+ public static string HttpGet(string url, string token, string userAgent = "netCoreSdk")
+ {
+ HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
+
+ request.Headers.Add("User-Agent", HttpUtility.UrlEncode(userAgent));
+ request.Headers.Add("X-Auth-Token", HttpUtility.UrlEncode(token));
+
+ using HttpWebResponse response = (HttpWebResponse)request.GetResponse();
+ using StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
+
+ return reader.ReadToEnd();
+ }
+
+ ///
+ /// get请求
+ ///
+ /// 请求地址
+ /// 语雀个人设置的token
+ /// 语雀需要收集的用户标识
+ /// 请求到的数据
+ public static async Task HttpGetAsync(string url, string token, string userAgent = "netCoreSdk")
+ {
+ HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
+
+ request.Headers.Add("User-Agent", HttpUtility.UrlEncode(userAgent));
+ request.Headers.Add("X-Auth-Token", HttpUtility.UrlEncode(token));
+
+ using HttpWebResponse response = (HttpWebResponse)request.GetResponse();
+ using StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
+
+ return await reader.ReadToEndAsync();
+ }
+
+ public static string HttpPost(string data,string url, string token, string userAgent = "netCoreSdk")
+ {
+ HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
+ request.Method = "POST";
+
+ //string retval = null;
+
+
+ request.Headers.Add("User-Agent", HttpUtility.UrlEncode(userAgent));
+ request.Headers.Add("X-Auth-Token", HttpUtility.UrlEncode(token));
+ request.Headers.Add("Content-Type", "application/json");
+
+ var bytes = System.Text.UTF8Encoding.UTF8.GetBytes(data);
+
+ using (var stream = request.GetRequestStream())
+ {
+ stream.Write(bytes, 0, bytes.Length);
+ }
+
+ using (var response = (HttpWebResponse)request.GetResponse())
+ {
+ using (var reader = new System.IO.StreamReader(response.GetResponseStream()))
+ {
+ return reader.ReadToEnd();
+ }
+ }
+
+ //HttpWebResponse response = (HttpWebResponse)request.GetResponse();//获取服务器返回的结果
+ //Stream getStream = response.GetResponseStream();
+ //StreamReader streamreader = new StreamReader(getStream);
+ //String result = streamreader.ReadToEnd();
+
+ //return result;
+
+
+ //using HttpWebResponse response = (HttpWebResponse)request.GetResponse();
+ //using StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
+ }
+ }
+}
diff --git a/Vampirewal.Core.YuQueHelper/Model/AbilitiesModel.cs b/Vampirewal.Core.YuQueHelper/Model/AbilitiesModel.cs
new file mode 100644
index 0000000..5ef5057
--- /dev/null
+++ b/Vampirewal.Core.YuQueHelper/Model/AbilitiesModel.cs
@@ -0,0 +1,34 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:AbilitiesModel
+// 创 建 者:杨程
+// 创建时间:2022/2/23 15:22:20
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Vampirewal.Core.YuQueHelper.Model
+{
+ public class AbilitiesModel
+ {
+ ///
+ /// 是否有权限修改
+ ///
+ public bool Update { get; set; }
+
+ ///
+ /// 是否有权限销毁
+ ///
+ public bool Destroy { get; set; }
+ }
+}
diff --git a/Vampirewal.Core.YuQueHelper/Model/DocDetail.cs b/Vampirewal.Core.YuQueHelper/Model/DocDetail.cs
new file mode 100644
index 0000000..178f480
--- /dev/null
+++ b/Vampirewal.Core.YuQueHelper/Model/DocDetail.cs
@@ -0,0 +1,37 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:DocDetail
+// 创 建 者:杨程
+// 创建时间:2022/2/23 15:22:44
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Vampirewal.Core.YuQueHelper.Model
+{
+ ///
+ /// 语雀文档详情
+ ///
+ public class DocDetail
+ {
+ ///
+ /// 文章详情的数据
+ ///
+ public DocDetailData Data { get; set; }
+
+ ///
+ /// 拥有的权限
+ ///
+ public AbilitiesModel Abilities { get; set; }
+ }
+}
diff --git a/Vampirewal.Core.YuQueHelper/Model/DocDetailData.cs b/Vampirewal.Core.YuQueHelper/Model/DocDetailData.cs
new file mode 100644
index 0000000..e3d5cac
--- /dev/null
+++ b/Vampirewal.Core.YuQueHelper/Model/DocDetailData.cs
@@ -0,0 +1,134 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:DocDetailData
+// 创 建 者:杨程
+// 创建时间:2022/2/23 15:23:06
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Vampirewal.Core.YuQueHelper.Model
+{
+ ///
+ /// 文章详情的数据
+ ///
+ public class DocDetailData
+ {
+ ///
+ /// 文档编号
+ ///
+ public string Id { get; set; }
+
+ ///
+ /// 文档路径
+ ///
+ public string slug { get; set; }
+
+ ///
+ /// 标题
+ ///
+ public string title { get; set; }
+
+ ///
+ /// 仓库编号就是repoid
+ ///
+ public string Book_Id { get; set; }
+
+ ///
+ /// 仓库信息
+ ///
+ public object Book { get; set; }
+
+ ///
+ /// 用户/团队编号
+ ///
+ public string User_Id { get; set; }
+
+ ///
+ /// 用户/团队信息
+ ///
+ public object User { get; set; }
+
+ ///
+ /// 表述了正文的格式[lake,markdown]
+ ///
+ public string format { get; set; }
+
+ ///
+ /// 正文 Markdown 源代码
+ ///
+ public string body { get; set; }
+
+ ///
+ /// 草稿 Markdown 源代码
+ ///
+ public string Body_Draft { get; set; }
+
+ ///
+ /// 转换过后的正文 HTML
+ ///
+ public string Body_Html { get; set; }
+
+ ///
+ /// 语雀 lake 格式的文档内容
+ ///
+ public string Body_Lake { get; set; }
+
+ ///
+ /// 文档创建人 User Id
+ ///
+ public string Creator_Id { get; set; }
+
+ ///
+ /// 公开级别 [0 - 私密, 1 - 公开]
+ ///
+ [JsonProperty("public")]
+ public int Public { get; set; }
+
+ ///
+ /// 状态 [0 - 草稿, 1 - 发布]
+ ///
+ public int Status { get; set; }
+
+ ///
+ /// 赞数量
+ ///
+ public int Likes_Count { get; set; }
+
+ ///
+ /// 评论数量
+ ///
+ public int Comments_Count { get; set; }
+
+ ///
+ /// 文档内容更新时间
+ ///
+ public DateTime Content_Updated_At { get; set; }
+
+ ///
+ /// 删除时间,未删除为 null
+ ///
+ public DateTime? Deleted_At { get; set; }
+
+ ///
+ /// 创建时间
+ ///
+ public DateTime Created_At { get; set; }
+
+ ///
+ /// 更新时间
+ ///
+ public DateTime Updated_At { get; set; }
+ }
+}
diff --git a/Vampirewal.Core.YuQueHelper/Model/Topic.cs b/Vampirewal.Core.YuQueHelper/Model/Topic.cs
new file mode 100644
index 0000000..f2305df
--- /dev/null
+++ b/Vampirewal.Core.YuQueHelper/Model/Topic.cs
@@ -0,0 +1,92 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:Topic
+// 创 建 者:杨程
+// 创建时间:2022/2/23 15:23:34
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Vampirewal.Core.YuQueHelper.Model
+{
+ ///
+ /// 目录
+ ///
+ public class Topic
+ {
+ ///
+ /// 节点类型
+ ///
+ public string Type { get; set; }
+
+ ///
+ /// 节点名称
+ ///
+ public string Title { get; set; }
+
+ ///
+ /// 节点唯一 id
+ ///
+ public string Uuid { get; set; }
+
+ ///
+ /// 链接或文档 slug
+ ///
+ public string Url { get; set; }
+
+ ///
+ /// 上一个节点 uuid
+ ///
+ public string Prev_Uuid { get; set; }
+
+ ///
+ /// 下一个节点 uuid
+ ///
+ public string Sibling_uuid { get; set; }
+
+ ///
+ /// 第一个子节点 uuid
+ ///
+ public string Child_uuid { get; set; }
+
+ ///
+ /// 父亲节点 uuid
+ ///
+ public string Parent_uuid { get; set; }
+
+ ///
+ /// 仅文档类型节点,doc id
+ ///
+ public string Doc_id { get; set; }
+
+ ///
+ /// 节点层级
+ ///
+ public int Level { get; set; }
+
+ ///
+ /// 节点id
+ ///
+ public string Id { get; set; }
+
+ ///
+ /// 链接是否在新窗口打开,0 在当前页面打开,1 在新窗口打开
+ ///
+ public int Open_window { get; set; }
+
+ ///
+ /// 节点是否可见,0 不可见,1 可见
+ ///
+ public int Visible { get; set; }
+ }
+}
diff --git a/Vampirewal.Core.YuQueHelper/Model/TopicInfo.cs b/Vampirewal.Core.YuQueHelper/Model/TopicInfo.cs
new file mode 100644
index 0000000..12fb745
--- /dev/null
+++ b/Vampirewal.Core.YuQueHelper/Model/TopicInfo.cs
@@ -0,0 +1,32 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:TopicInfo
+// 创 建 者:杨程
+// 创建时间:2022/2/23 15:24:00
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Vampirewal.Core.YuQueHelper.Model
+{
+ ///
+ /// 目录信息
+ ///
+ public class TopicInfo
+ {
+ ///
+ /// 目录
+ ///
+ public List Data { get; set; }
+ }
+}
diff --git a/Vampirewal.Core.YuQueHelper/Model/TopicTree.cs b/Vampirewal.Core.YuQueHelper/Model/TopicTree.cs
new file mode 100644
index 0000000..b20f973
--- /dev/null
+++ b/Vampirewal.Core.YuQueHelper/Model/TopicTree.cs
@@ -0,0 +1,32 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:TopicTree
+// 创 建 者:杨程
+// 创建时间:2022/2/23 15:24:22
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Vampirewal.Core.YuQueHelper.Model
+{
+ ///
+ /// 目录树形结构的输出对象
+ ///
+ public class TopicTree : Topic
+ {
+ ///
+ /// 树结构的子集
+ ///
+ public List Child { get; set; }
+ }
+}
diff --git a/Vampirewal.Core.YuQueHelper/Vampirewal.Core.YuQueHelper.csproj b/Vampirewal.Core.YuQueHelper/Vampirewal.Core.YuQueHelper.csproj
new file mode 100644
index 0000000..47c5a70
--- /dev/null
+++ b/Vampirewal.Core.YuQueHelper/Vampirewal.Core.YuQueHelper.csproj
@@ -0,0 +1,11 @@
+
+
+
+ net5.0
+
+
+
+
+
+
+
diff --git a/Vampirewal.Core.YuQueHelper/YuQueClient.cs b/Vampirewal.Core.YuQueHelper/YuQueClient.cs
new file mode 100644
index 0000000..dec07a8
--- /dev/null
+++ b/Vampirewal.Core.YuQueHelper/YuQueClient.cs
@@ -0,0 +1,246 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:YuQueClient
+// 创 建 者:杨程
+// 创建时间:2022/2/23 15:15:18
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Vampirewal.Core.YuQueHelper.Model;
+
+namespace Vampirewal.Core.YuQueHelper
+{
+ public interface IYuQueClient
+ {
+ ///
+ /// 语雀个人设置的Token
+ ///
+ string Token { get; }
+
+ ///
+ /// 语雀收集的用户标识
+ ///
+ string UserAgent { get; }
+
+ ///
+ /// 语雀基础的api域名
+ ///
+ string baseUrl { get; }
+
+ List DocRepos { get; }
+
+ ///
+ /// 添加知识库名称
+ ///
+ ///
+ void AddDocRepos(string DocReposName);
+
+ ///
+ /// 批量添加知识库名称
+ ///
+ ///
+ void AddRangeDocRepos(List DocReposNames);
+ ///
+ /// 设置基础配置
+ ///
+ /// 语雀个人设置的skd
+ /// 语雀收集的用户标识
+ void SetConfig(string token, string userAgent = "Vampirewal.Core");
+
+ ///
+ /// 获取单篇文档的详细信息
+ ///
+ /// 文档所属的知识库 如:https://www.yuque.com/yuque/developer/repo 中的【yuque/developer】
+ /// 文档的路径 如:https://www.yuque.com/yuque/developer/repo 中的【repo】
+ /// 文档的详细信息
+ DocDetail GetDocDetail(string docRepo, string slug);
+
+
+ ///
+ /// 新增1条文档
+ ///
+ /// 文档所属的知识库 如:https://www.yuque.com/yuque/developer/repo 中的【yuque/developer】
+ /// Json数据
+ string PostDocDetail(string docRepo, string data);
+
+
+ ///
+ /// 获取知识库下的目录
+ ///
+ /// 文档所属的知识库 如:https://www.yuque.com/yuque/developer/repo 中的【yuque/developer】
+ /// 目录信息
+ List GetRepoTopic(string docRepo);
+
+ ///
+ /// 获取知识库下的目录(树结构)
+ ///
+ /// 文档所属的知识库 如:https://www.yuque.com/yuque/developer/repo 中的【yuque/developer】
+ /// 目录信息
+ List GetRepoTopicTree(string docRepo);
+ }
+
+ public sealed class YuQueClient: IYuQueClient
+ {
+ ///
+ /// 语雀个人设置的skd
+ ///
+ public string Token { get;private set; }
+
+ ///
+ /// 语雀收集的用户标识
+ ///
+ public string UserAgent { get;private set; }
+
+ ///
+ /// 语雀基础的api域名
+ ///
+ public string baseUrl { get; private set; } = "https://www.yuque.com/api/v2/";
+
+ ///
+ /// 设置基础配置
+ ///
+ /// 语雀个人设置的skd
+ /// 语雀收集的用户标识
+ public void SetConfig(string token, string userAgent = "Vampirewal.Core")
+ {
+ Token = token;
+ UserAgent = userAgent;
+ }
+
+
+
+ #region 知识库
+ ///
+ /// 知识库列表
+ ///
+ public List DocRepos { get; private set; }
+ ///
+ /// 添加知识库名称
+ ///
+ ///
+ public void AddDocRepos(string DocReposName)
+ {
+ DocRepos.Add(DocReposName);
+ }
+
+ ///
+ /// 批量添加知识库名称
+ ///
+ ///
+ public void AddRangeDocRepos(List DocReposNames)
+ {
+ DocRepos.AddRange(DocReposNames);
+ }
+ #endregion
+
+
+ ///
+ /// 获取单篇文档的详细信息
+ ///
+ /// 文档所属的知识库 如:https://www.yuque.com/yuque/developer/repo 中的【yuque/developer】
+ /// 文档的路径 如:https://www.yuque.com/yuque/developer/repo 中的【repo】
+ /// 文档的详细信息
+ public DocDetail GetDocDetail(string docRepo, string slug)
+ {
+ string jsonStr = HttpWebClientHelper.HttpGet($"{baseUrl}repos/{docRepo}/docs/{slug}", Token, UserAgent);
+ return JsonConvert.DeserializeObject(jsonStr);
+ }
+
+ ///
+ /// 新增1条文档
+ ///
+ /// 文档所属的知识库 如:https://www.yuque.com/yuque/developer/repo 中的【yuque/developer】
+ /// Json数据
+ public string PostDocDetail(string docRepo,string data)
+ {
+ return HttpWebClientHelper.HttpPost(data, $"{baseUrl}repos/{docRepo}/docs", Token, UserAgent);
+ }
+
+ ///
+ /// 获取知识库下的目录
+ ///
+ /// 文档所属的知识库 如:https://www.yuque.com/yuque/developer/repo 中的【yuque/developer】
+ /// 目录信息
+ public List GetRepoTopic(string docRepo)
+ {
+ string jsonStr = HttpWebClientHelper.HttpGet($"{baseUrl}repos/{docRepo}/toc", Token, UserAgent);
+ return JsonConvert.DeserializeObject(jsonStr).Data;
+ }
+
+ ///
+ /// 获取知识库下的目录(树结构)
+ ///
+ /// 文档所属的知识库 如:https://www.yuque.com/yuque/developer/repo 中的【yuque/developer】
+ /// 目录信息
+ public List GetRepoTopicTree(string docRepo)
+ {
+ string jsonStr = HttpWebClientHelper.HttpGet($"{baseUrl}repos/{docRepo}/toc", Token, UserAgent);
+ List topicList = JsonConvert.DeserializeObject(jsonStr).Data;
+ List result = new List();
+ var firstList = topicList.Where(x => x.Level == 0);//第一级
+ return ProcessTree(firstList, topicList);
+ }
+
+ ///
+ /// 递归处理树结构
+ ///
+ ///
+ ///
+ ///
+ private List ProcessTree(IEnumerable child, List allList)
+ {
+ List result = new List();
+
+ foreach (Topic item in child)
+ {
+ TopicTree topicTree = item.ToEntity();
+ var childList = allList.Where(x => x.Parent_uuid == item.Uuid);
+ if (childList.Count() > 0)
+ {
+ topicTree.Child = ProcessTree(childList, allList);
+ }
+ result.Add(topicTree);
+ }
+
+ return result;
+ }
+
+ }
+
+ internal static class TopicExtension
+ {
+ internal static TopicTree ToEntity(this Topic topic)
+ {
+ TopicTree result = new TopicTree
+ {
+ Child = new List(),
+ Child_uuid = topic.Child_uuid,
+ Doc_id = topic.Doc_id,
+ Id = topic.Id,
+ Level = topic.Level,
+ Open_window = topic.Open_window,
+ Parent_uuid = topic.Parent_uuid,
+ Prev_Uuid = topic.Prev_Uuid,
+ Sibling_uuid = topic.Sibling_uuid,
+ Title = topic.Title,
+ Type = topic.Type,
+ Url = topic.Url,
+ Uuid = topic.Uuid,
+ Visible = topic.Visible
+ };
+
+ return result;
+ }
+ }
+}
diff --git a/Vampirewal.Core/Extensions/EntityExtension.cs b/Vampirewal.Core/Extensions/EntityExtension.cs
index 1dfc1f0..910ca17 100644
--- a/Vampirewal.Core/Extensions/EntityExtension.cs
+++ b/Vampirewal.Core/Extensions/EntityExtension.cs
@@ -28,7 +28,7 @@ namespace Vampirewal.Core.Extensions
///
public static class EntityExtension
{
- public static void test(this T entity) where T:TopBaseModel
+ public static void test(this T entity) where T:TopModel
{
Type type = typeof(T);
diff --git a/Vampirewal.Core/Extensions/ITreeDataExtension.cs b/Vampirewal.Core/Extensions/ITreeDataExtension.cs
index b68878b..a18a739 100644
--- a/Vampirewal.Core/Extensions/ITreeDataExtension.cs
+++ b/Vampirewal.Core/Extensions/ITreeDataExtension.cs
@@ -33,7 +33,7 @@ namespace Vampirewal.Core.Extensions
/// 树形结构实例
/// 排序字段,可为空
/// 树形结构列表,包含所有子节点
- public static List GetAllChildren(this T self, Func order = null) where T : TopBaseModel, ITreeData
+ public static List GetAllChildren(this T self, Func order = null) where T : TopModel, ITreeData
{
List rv = new List();
var children = self.Children;
@@ -55,7 +55,7 @@ namespace Vampirewal.Core.Extensions
}
public static int GetLevel(this T self)
- where T : TopBaseModel, ITreeData
+ where T : TopModel, ITreeData
{
int level = 0;
while (self.Parent != null)
@@ -105,7 +105,7 @@ namespace Vampirewal.Core.Extensions
/// 排序字段,可以为空
/// 返回标准列表,所有节点都在同一级上
public static List FlatTree(this List self, Func order = null)
- where T : TopBaseModel, ITreeData
+ where T : TopModel, ITreeData
{
List rv = new List();
if (order != null)
diff --git a/Vampirewal.Core/Extensions/TypeExtension.cs b/Vampirewal.Core/Extensions/TypeExtension.cs
index e4e535c..2d2f3d7 100644
--- a/Vampirewal.Core/Extensions/TypeExtension.cs
+++ b/Vampirewal.Core/Extensions/TypeExtension.cs
@@ -214,7 +214,7 @@ namespace Vampirewal.Core.Extensions
var notmapped = pro.GetCustomAttribute();
if (notmapped == null &&
pro.PropertyType.IsList() == false &&
- pro.PropertyType.IsSubclassOf(typeof(TopBaseModel)) == false &&
+ pro.PropertyType.IsSubclassOf(typeof(TopModel)) == false &&
skipFields.Contains(key) == false
)
{
diff --git a/Vampirewal.Core/Interface/IBaseCRUDVM.cs b/Vampirewal.Core/Interface/IBaseCRUDVM.cs
index 36cac8f..659db2b 100644
--- a/Vampirewal.Core/Interface/IBaseCRUDVM.cs
+++ b/Vampirewal.Core/Interface/IBaseCRUDVM.cs
@@ -24,7 +24,7 @@ namespace Vampirewal.Core.Interface
///
/// 单表增删改查VM的接口
///
- public interface IBaseCRUDVM where T : TopBaseModel, new()
+ public interface IBaseCRUDVM where T : TopModel, new()
{
///
/// 实体类
diff --git a/Vampirewal.Core/Interface/IBaseListVM.cs b/Vampirewal.Core/Interface/IBaseListVM.cs
index 52b3f7b..c333286 100644
--- a/Vampirewal.Core/Interface/IBaseListVM.cs
+++ b/Vampirewal.Core/Interface/IBaseListVM.cs
@@ -27,7 +27,7 @@ namespace Vampirewal.Core.Interface
/// ListVM接口
///
public interface IBaseListVM
- where T : TopBaseModel
+ where T : TopModel
where S : ISearcher
{
@@ -143,7 +143,7 @@ namespace Vampirewal.Core.Interface
///
/// ReplaceWhere
///
- Expression> ReplaceWhere { get; set; }
+ Expression> ReplaceWhere { get; set; }
///
/// SetFullRowColor
diff --git a/Vampirewal.Core/Interface/ITreeData.cs b/Vampirewal.Core/Interface/ITreeData.cs
index efaad16..91452bc 100644
--- a/Vampirewal.Core/Interface/ITreeData.cs
+++ b/Vampirewal.Core/Interface/ITreeData.cs
@@ -36,7 +36,7 @@ namespace Vampirewal.Core.Interface
/// 泛型树形结构model接口
///
/// 父节点类型,父节点应该和实现本接口的类是同一个类,否则没有意义
- public interface ITreeData : ITreeData where T : TopBaseModel
+ public interface ITreeData : ITreeData where T : TopModel
{
///
/// 通过实现这个函数获得所有的子节点数据
diff --git a/Vampirewal.Core/Models/BaseModel.cs b/Vampirewal.Core/Models/BaseModel.cs
index 94050bd..62f94a2 100644
--- a/Vampirewal.Core/Models/BaseModel.cs
+++ b/Vampirewal.Core/Models/BaseModel.cs
@@ -1,15 +1,15 @@
-#region << 文 件 说 明 >>
-/*----------------------------------------------------------------
-// 文件名称:BaseModel
-// 创 建 者:杨程
-// 创建时间:2021/9/15 10:54:24
-// 文件版本:V1.0.0
-// ===============================================================
-// 功能描述:
-//
-//
-//----------------------------------------------------------------*/
-#endregion
+//#region << 文 件 说 明 >>
+///*----------------------------------------------------------------
+//// 文件名称:BaseModel
+//// 创 建 者:杨程
+//// 创建时间:2021/9/15 10:54:24
+//// 文件版本:V1.0.0
+//// ===============================================================
+//// 功能描述:
+////
+////
+////----------------------------------------------------------------*/
+//#endregion
using System;
using System.Collections.Generic;
@@ -38,7 +38,7 @@ namespace Vampirewal.Core.Models
///
/// 需要继承
///
- public abstract class BaseModel : TopBaseModel, IBaseModel
+ public abstract class BaseModel : TopModel, IBaseModel
{
private DateTime? _UpdateTime;
///
@@ -52,7 +52,7 @@ namespace Vampirewal.Core.Models
DoNotify();
}
}
-
+
private string _UpdateBy;
///
/// 更新人
diff --git a/Vampirewal.Core/Models/FileAttachment.cs b/Vampirewal.Core/Models/FileAttachment.cs
index cd25267..43df143 100644
--- a/Vampirewal.Core/Models/FileAttachment.cs
+++ b/Vampirewal.Core/Models/FileAttachment.cs
@@ -19,14 +19,15 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
+using SqlSugar;
namespace Vampirewal.Core.Models
{
///
/// FileAttachment
///
- [Table("FileAttachments")]
- public class FileAttachment : BaseModel
+ [SugarTable("FileAttachments")]
+ public class FileAttachment : BillBaseModel
{
[Display(Name = "FileName")]
diff --git a/Vampirewal.Core/Models/FrameworkDomain.cs b/Vampirewal.Core/Models/FrameworkDomain.cs
index 8b36c45..7ee9598 100644
--- a/Vampirewal.Core/Models/FrameworkDomain.cs
+++ b/Vampirewal.Core/Models/FrameworkDomain.cs
@@ -11,6 +11,7 @@
//----------------------------------------------------------------*/
#endregion
+using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
@@ -24,8 +25,8 @@ namespace Vampirewal.Core.Models
///
/// 连接域
///
- [Table("FrameworkDomains")]
- public class FrameworkDomain:BaseModel
+ [SugarTable("FrameworkDomains")]
+ public class FrameworkDomain:BillBaseModel
{
[StringLength(50, ErrorMessage = "长度最长50!")]
[Display(Name = "DomainName")]
diff --git a/Vampirewal.Core/Models/FrameworkRole.cs b/Vampirewal.Core/Models/FrameworkRole.cs
index 4458383..d5f83b4 100644
--- a/Vampirewal.Core/Models/FrameworkRole.cs
+++ b/Vampirewal.Core/Models/FrameworkRole.cs
@@ -19,14 +19,15 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
+using SqlSugar;
namespace Vampirewal.Core.Models
{
///
/// 角色表
///
- [Table("FrameworkRoles")]
- public class FrameworkRole : BaseModel
+ [SugarTable("FrameworkRoles")]
+ public class FrameworkRole : TopModel
{
///
/// 角色ID
@@ -35,6 +36,7 @@ namespace Vampirewal.Core.Models
[Required(ErrorMessage = "Validate.{0}required")]
[RegularExpression("^[0-9]*$", ErrorMessage = "Validate.{0}number")]
[StringLength(100, ErrorMessage = "Validate.{0}stringmax{1}")]
+ [SugarColumn()]
public string RoleCode { get; set; }
///
diff --git a/Vampirewal.Core/Models/FrameworkUserBase.cs b/Vampirewal.Core/Models/FrameworkUserBase.cs
index 73c351d..206e772 100644
--- a/Vampirewal.Core/Models/FrameworkUserBase.cs
+++ b/Vampirewal.Core/Models/FrameworkUserBase.cs
@@ -11,6 +11,7 @@
//----------------------------------------------------------------*/
#endregion
+using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
@@ -26,8 +27,8 @@ namespace Vampirewal.Core.Models
///
/// 系统人员基类
///
- [Table("FrameworkUserBase")]
- public class FrameworkUserBase : TopBaseModel
+ [SugarTable("FrameworkUserBase")]
+ public class FrameworkUserBase : BillBaseModel
{
///
/// 工号
diff --git a/Vampirewal.Core/Models/FrameworkUserRole.cs b/Vampirewal.Core/Models/FrameworkUserRole.cs
index d1c2dd0..db26d93 100644
--- a/Vampirewal.Core/Models/FrameworkUserRole.cs
+++ b/Vampirewal.Core/Models/FrameworkUserRole.cs
@@ -19,14 +19,15 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
+using SqlSugar;
namespace Vampirewal.Core.Models
{
///
/// 用户角色关联表
///
- [Table("FrameworkUserRoles")]
- public class FrameworkUserRole : BaseModel
+ [SugarTable("FrameworkUserRoles")]
+ public class FrameworkUserRole : TopModel
{
///
/// 用户ID
diff --git a/Vampirewal.Core/Models/TopBaseModel.cs b/Vampirewal.Core/Models/TopBaseModel.cs
index f78f40a..295ade2 100644
--- a/Vampirewal.Core/Models/TopBaseModel.cs
+++ b/Vampirewal.Core/Models/TopBaseModel.cs
@@ -1,132 +1,132 @@
-#region << 文 件 说 明 >>
-/*----------------------------------------------------------------
-// 文件名称:TopBaseModel
-// 创 建 者:杨程
-// 创建时间:2021/8/12 15:38:12
-// 文件版本:V1.0.0
-// ===============================================================
-// 功能描述:
-//
-//
-//----------------------------------------------------------------*/
-#endregion
+//#region << 文 件 说 明 >>
+///*----------------------------------------------------------------
+//// 文件名称:TopBaseModel
+//// 创 建 者:杨程
+//// 创建时间:2021/8/12 15:38:12
+//// 文件版本:V1.0.0
+//// ===============================================================
+//// 功能描述:
+////
+////
+////----------------------------------------------------------------*/
+//#endregion
-using System;
-using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations;
-using System.ComponentModel.DataAnnotations.Schema;
-using System.Linq;
-using System.Text;
-using System.Text.Json.Serialization;
-using System.Threading.Tasks;
-using Vampirewal.Core.Extensions;
-using Vampirewal.Core.SimpleMVVM;
+//using System;
+//using System.Collections.Generic;
+//using System.ComponentModel.DataAnnotations;
+//using System.ComponentModel.DataAnnotations.Schema;
+//using System.Linq;
+//using System.Text;
+//using System.Text.Json.Serialization;
+//using System.Threading.Tasks;
+//using Vampirewal.Core.Extensions;
+//using Vampirewal.Core.SimpleMVVM;
-namespace Vampirewal.Core.Models
-{
- ///
- /// model基类
- ///
- public class TopBaseModel:NotifyBase
- {
+//namespace Vampirewal.Core.Models
+//{
+// ///
+// /// model基类
+// ///
+// public class TopBaseModel:NotifyBase
+// {
- #region 属性
- private string _id;
+// #region 属性
+// private string _id;
- ///
- /// Id
- ///
- [Key]
- public string ID
- {
- get
- {
- if (string.IsNullOrEmpty(_id))
- {
- _id = Guid.NewGuid().ToString();
- }
- return _id;
- }
- set
- {
- _id = value;
- DoNotify();
- }
- }
+// ///
+// /// Id
+// ///
+// [Key]
+// public string ID
+// {
+// get
+// {
+// if (string.IsNullOrEmpty(_id))
+// {
+// _id = Guid.NewGuid().ToString();
+// }
+// return _id;
+// }
+// set
+// {
+// _id = value;
+// DoNotify();
+// }
+// }
- private DateTime? _CreateTime;
- ///
- /// 创建时间
- ///
- [Column("CreateTime")]
- public DateTime? CreateTime
- {
- get
- {
- if (_CreateTime == null)
- {
- _CreateTime = DateTime.Now;
- }
- return _CreateTime;
- }
- set
- {
- _CreateTime = value;
- DoNotify();
- }
- }
+// private DateTime? _CreateTime;
+// ///
+// /// 创建时间
+// ///
+// [Column("CreateTime")]
+// public DateTime? CreateTime
+// {
+// get
+// {
+// if (_CreateTime == null)
+// {
+// _CreateTime = DateTime.Now;
+// }
+// return _CreateTime;
+// }
+// set
+// {
+// _CreateTime = value;
+// DoNotify();
+// }
+// }
- private string _CreateBy;
- ///
- /// 创建人
- ///
- [Column("CreateBy")]
- public string CreateBy
- {
- get { return _CreateBy; }
- set { _CreateBy = value;DoNotify(); }
- }
+// private string _CreateBy;
+// ///
+// /// 创建人
+// ///
+// [Column("CreateBy")]
+// public string CreateBy
+// {
+// get { return _CreateBy; }
+// set { _CreateBy = value;DoNotify(); }
+// }
- private bool _Check;
- ///
- /// 是否选中
- /// 标识当前行数据是否被选中
- ///
- [NotMapped]
- [JsonIgnore]
- public bool Checked { get=> _Check; set { _Check = value;DoNotify(); } }
- #endregion
+// private bool _Check;
+// ///
+// /// 是否选中
+// /// 标识当前行数据是否被选中
+// ///
+// [NotMapped]
+// [JsonIgnore]
+// public bool Checked { get=> _Check; set { _Check = value;DoNotify(); } }
+// #endregion
- #region 公共方法
- ///
- /// 获取当前model的ID
- ///
- ///
- public object GetID()
- {
- var idpro = this.GetType().GetProperties().Where(x => x.Name.ToLower() == "id").FirstOrDefault();
- var id = idpro.GetValue(this);
- return id;
- }
+// #region 公共方法
+// ///
+// /// 获取当前model的ID
+// ///
+// ///
+// public object GetID()
+// {
+// var idpro = this.GetType().GetProperties().Where(x => x.Name.ToLower() == "id").FirstOrDefault();
+// var id = idpro.GetValue(this);
+// return id;
+// }
- ///
- /// 获取父ID
- ///
- ///
- public object GetParentID()
- {
- var idpro = this.GetType().GetSingleProperty("ParentId");
- var id = idpro.GetValue(this) ?? "";
- return id;
- }
- #endregion
+// ///
+// /// 获取父ID
+// ///
+// ///
+// public object GetParentID()
+// {
+// var idpro = this.GetType().GetSingleProperty("ParentId");
+// var id = idpro.GetValue(this) ?? "";
+// return id;
+// }
+// #endregion
- #region 私有方法
+// #region 私有方法
- #endregion
+// #endregion
- #region 命令
+// #region 命令
- #endregion
- }
-}
+// #endregion
+// }
+//}
diff --git a/Vampirewal.Core/Models/TopModel.cs b/Vampirewal.Core/Models/TopModel.cs
index a5d2ba4..dab7c21 100644
--- a/Vampirewal.Core/Models/TopModel.cs
+++ b/Vampirewal.Core/Models/TopModel.cs
@@ -20,6 +20,7 @@ using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Vampirewal.Core.Components;
+using Vampirewal.Core.Extensions;
using Vampirewal.Core.SimpleMVVM;
namespace Vampirewal.Core.Models
@@ -39,5 +40,41 @@ namespace Vampirewal.Core.Models
[SugarColumn(IsIgnore =true)]
[JsonIgnore]
public bool Checked { get => _Check; set { _Check = value; DoNotify(); } }
+
+
+ #region 公共方法
+ ///
+ /// 获取当前model的BillID
+ ///
+ ///
+ public object GetBillID()
+ {
+ var idpro = this.GetType().GetProperties().Where(x => x.Name.ToLower() == "BILLID").FirstOrDefault();
+ var id = idpro.GetValue(this);
+ return id;
+ }
+
+ ///
+ /// 获取当前model的DtlId
+ ///
+ ///
+ public object GetDtlId()
+ {
+ var idpro = this.GetType().GetProperties().Where(x => x.Name.ToLower() == "DTLID").FirstOrDefault();
+ var id = idpro.GetValue(this);
+ return id;
+ }
+
+ ///
+ /// 获取父ID
+ ///
+ ///
+ public object GetParentID()
+ {
+ var idpro = this.GetType().GetSingleProperty("ParentId");
+ var id = idpro.GetValue(this) ?? "";
+ return id;
+ }
+ #endregion
}
}
diff --git a/Vampirewal.Core/Models/TreeBaseModel.cs b/Vampirewal.Core/Models/TreeBaseModel.cs
index e3bcc14..3961ddf 100644
--- a/Vampirewal.Core/Models/TreeBaseModel.cs
+++ b/Vampirewal.Core/Models/TreeBaseModel.cs
@@ -1,70 +1,70 @@
-#region << 文 件 说 明 >>
-/*----------------------------------------------------------------
-// 文件名称:TreeBaseModel
-// 创 建 者:杨程
-// 创建时间:2021/8/12 15:44:47
-// 文件版本:V1.0.0
-// ===============================================================
-// 功能描述:
-//
-//
-//----------------------------------------------------------------*/
-#endregion
+//#region << 文 件 说 明 >>
+///*----------------------------------------------------------------
+//// 文件名称:TreeBaseModel
+//// 创 建 者:杨程
+//// 创建时间:2021/8/12 15:44:47
+//// 文件版本:V1.0.0
+//// ===============================================================
+//// 功能描述:
+////
+////
+////----------------------------------------------------------------*/
+//#endregion
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.ComponentModel.DataAnnotations;
-using System.ComponentModel.DataAnnotations.Schema;
-using System.Linq;
-using System.Text;
-using System.Text.Json.Serialization;
-using System.Threading.Tasks;
+//using System;
+//using System.Collections.Generic;
+//using System.Collections.ObjectModel;
+//using System.ComponentModel.DataAnnotations;
+//using System.ComponentModel.DataAnnotations.Schema;
+//using System.Linq;
+//using System.Text;
+//using System.Text.Json.Serialization;
+//using System.Threading.Tasks;
-namespace Vampirewal.Core.Models
-{
- ///
- /// 树形model基类
- ///
- /// 需要使用到树形的model
- public class TreeBaseModel : TopBaseModel
- {
- ///
- /// 构造函数
- ///
- public TreeBaseModel()
- {
- Childs = new ObservableCollection();
- }
+//namespace Vampirewal.Core.Models
+//{
+// ///
+// /// 树形model基类
+// ///
+// /// 需要使用到树形的model
+// public class TreeBaseModel : TopBaseModel
+// {
+// ///
+// /// 构造函数
+// ///
+// public TreeBaseModel()
+// {
+// Childs = new ObservableCollection();
+// }
- private string _ParentId;
- ///
- /// 父ID
- ///
- public string ParentId { get => _ParentId; set { _ParentId = value; DoNotify(); } }
- ///
- /// 父类
- ///
- //[JsonIgnore]
- //public T Parent { get; set; }
+// private string _ParentId;
+// ///
+// /// 父ID
+// ///
+// public string ParentId { get => _ParentId; set { _ParentId = value; DoNotify(); } }
+// ///
+// /// 父类
+// ///
+// //[JsonIgnore]
+// //public T Parent { get; set; }
- ///
- /// 子集
- ///
- [InverseProperty("Parent")]
- [NotMapped]
- public ObservableCollection Childs { get; set; }
+// ///
+// /// 子集
+// ///
+// [InverseProperty("Parent")]
+// [NotMapped]
+// public ObservableCollection Childs { get; set; }
- ///
- /// 是否存在子项
- ///
- [NotMapped]
- public bool HasChildren
- {
- get
- {
- return Childs?.Any() == true;
- }
- }
- }
-}
+// ///
+// /// 是否存在子项
+// ///
+// [NotMapped]
+// public bool HasChildren
+// {
+// get
+// {
+// return Childs?.Any() == true;
+// }
+// }
+// }
+//}
diff --git a/Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs b/Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs
index 6c1402f..1317140 100644
--- a/Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs
+++ b/Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs
@@ -102,7 +102,7 @@ namespace Vampirewal.Core.SimpleMVVM
/// 搜索语句
public virtual ISugarQueryable GetSearchQuery()
{
- return DC.Client.Queryable().OrderBy(o=>o.BillId);
+ return DC.Client.Queryable().Select().OrderBy(o=>o.BillId);
}
#region 分页相关
diff --git a/Vampirewal.Core/SimpleMVVM/ViewModelBase.cs b/Vampirewal.Core/SimpleMVVM/ViewModelBase.cs
index 01261af..f54eda7 100644
--- a/Vampirewal.Core/SimpleMVVM/ViewModelBase.cs
+++ b/Vampirewal.Core/SimpleMVVM/ViewModelBase.cs
@@ -143,10 +143,12 @@ namespace Vampirewal.Core.SimpleMVVM
this.View?.Dispatcher.Invoke(action);
}
+
+ private string _Title = "未命名窗体";
///
/// 标题
///
- public string Title { get; set; } = "未命名窗体";
+ public string Title { get=> _Title; set { _Title = value;DoNotify(); } }
///
/// 当窗体是DialogShow的方式打开的时候,可以通过重写这个方法,将值传回主窗体
diff --git a/Vampirewal.Core/Tools/HttpClientHelper.cs b/Vampirewal.Core/Tools/HttpClientHelper.cs
index dd223a3..e706c38 100644
--- a/Vampirewal.Core/Tools/HttpClientHelper.cs
+++ b/Vampirewal.Core/Tools/HttpClientHelper.cs
@@ -21,6 +21,7 @@ using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
+using System.Reflection.Metadata;
namespace Vampirewal.Core.Tools
{
diff --git a/Vampirewal.Core/Tools/Utils.cs b/Vampirewal.Core/Tools/Utils.cs
index 622d3e0..5658822 100644
--- a/Vampirewal.Core/Tools/Utils.cs
+++ b/Vampirewal.Core/Tools/Utils.cs
@@ -124,7 +124,7 @@ namespace Vampirewal.Core
return fieldName == null ? "" : fieldName.Replace(".", "_").Replace("[", "_").Replace("]", "_");
}
- public static void CheckDifference(IEnumerable oldList, IEnumerable newList, out IEnumerable ToRemove, out IEnumerable ToAdd) where T : TopBaseModel
+ public static void CheckDifference(IEnumerable oldList, IEnumerable newList, out IEnumerable ToRemove, out IEnumerable ToAdd) where T : TopModel
{
List tempToRemove = new List();
List tempToAdd = new List();
@@ -135,7 +135,7 @@ namespace Vampirewal.Core
bool exist = false;
foreach (var newItem in newList)
{
- if (oldItem.GetID().ToString() == newItem.GetID().ToString())
+ if (oldItem.GetBillID().ToString() == newItem.GetBillID().ToString())
{
exist = true;
break;
@@ -151,7 +151,7 @@ namespace Vampirewal.Core
bool exist = false;
foreach (var oldItem in oldList)
{
- if (newItem.GetID().ToString() == oldItem.GetID().ToString())
+ if (newItem.GetBillID().ToString() == oldItem.GetBillID().ToString())
{
exist = true;
break;
diff --git a/YC.Core.sln b/YC.Core.sln
index dc6d47b..4bd74a2 100644
--- a/YC.Core.sln
+++ b/YC.Core.sln
@@ -1,13 +1,17 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-VisualStudioVersion = 16.0.31229.75
+# Visual Studio Version 17
+VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vampirewal.Core", "Vampirewal.Core\Vampirewal.Core.csproj", "{F8ECA7C6-2E83-44BE-9B6E-D09E189FD3CC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YC.WPF.Theme", "YC.WPF.Theme\YC.WPF.Theme.csproj", "{8B832967-AD6A-4094-A299-FE5F9991AE83}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test\test.csproj", "{B622E036-C59A-4E28-8F68-AFC5392D0410}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "test", "test\test.csproj", "{B622E036-C59A-4E28-8F68-AFC5392D0410}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vampirewal.Core.FlowEngine", "Vampirewal.Core.FlowEngine\Vampirewal.Core.FlowEngine.csproj", "{B0CAFD0E-6AE7-4822-987D-EC2D130180BC}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vampirewal.Core.YuQueHelper", "Vampirewal.Core.YuQueHelper\Vampirewal.Core.YuQueHelper.csproj", "{1C734B76-1190-4765-9CFA-9D8AA30F7A5B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -27,6 +31,14 @@ Global
{B622E036-C59A-4E28-8F68-AFC5392D0410}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B622E036-C59A-4E28-8F68-AFC5392D0410}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B622E036-C59A-4E28-8F68-AFC5392D0410}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B0CAFD0E-6AE7-4822-987D-EC2D130180BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B0CAFD0E-6AE7-4822-987D-EC2D130180BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B0CAFD0E-6AE7-4822-987D-EC2D130180BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B0CAFD0E-6AE7-4822-987D-EC2D130180BC}.Release|Any CPU.Build.0 = Release|Any CPU
+ {1C734B76-1190-4765-9CFA-9D8AA30F7A5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {1C734B76-1190-4765-9CFA-9D8AA30F7A5B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {1C734B76-1190-4765-9CFA-9D8AA30F7A5B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {1C734B76-1190-4765-9CFA-9D8AA30F7A5B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/test/MainViewModel.cs b/test/MainViewModel.cs
index e57c5ec..e716189 100644
--- a/test/MainViewModel.cs
+++ b/test/MainViewModel.cs
@@ -11,6 +11,7 @@
//----------------------------------------------------------------*/
#endregion
+using Newtonsoft.Json;
using NPOI.SS.Formula.Functions;
using SqlSugar;
using System;
@@ -29,7 +30,10 @@ using Vampirewal.Core.Interface;
using Vampirewal.Core.Models;
using Vampirewal.Core.SimpleMVVM;
using Vampirewal.Core.SimpleMVVM.Attributes;
+using Vampirewal.Core.Tools;
using Vampirewal.Core.WpfTheme.WindowStyle;
+using Vampirewal.Core.YuQueHelper;
+using Vampirewal.Core.YuQueHelper.Model;
namespace test
{
@@ -189,18 +193,7 @@ namespace test
public class MainViewModel2 : BillVM
{
- ~MainViewModel2()
- {
- if (SystemDataContext.GetInstance().loggers.Count>0)
- {
- foreach (var item in SystemDataContext.GetInstance().loggers)
- {
- DC.AddEntity(item);
- }
- }
- }
-
-
+
//private ILogger Log { get; set; }
public MainViewModel2(IDataContext dc, IAppConfig config,ILogger log) : base(dc, config)
{
@@ -258,6 +251,55 @@ namespace test
//DoUpdate();
//Entity.BillName = "qdqdqdqdtgggg";
//DoAddAsync();
+
+
+ //YuQueClient yuQueClient = new YuQueClient("rs5tCCeXhfVlDRQQunpdBA3TYe3fwcgIixWIIRvS", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11");
+ IYuQueClient yuQueClient = new YuQueClient();
+
+ yuQueClient.SetConfig("rs5tCCeXhfVlDRQQunpdBA3TYe3fwcgIixWIIRvS");
+
+ DocDetailData topic = new DocDetailData()
+ {
+ title = "haha1223",
+ slug = RandomHelper.GetRandomString(6),
+ Public = 1,
+ format = "lake",
+ body = "hahahahaha_test"
+ };
+
+ string data = JsonConvert.SerializeObject(topic);
+
+
+ yuQueClient.PostDocDetail("vampirewal/vampirewal.core", data);
+
+
+
+ //List topics = yuQueClient.GetRepoTopic("vampirewal/vampirewal.core");
+
+ DocDetail docDetail = yuQueClient.GetDocDetail("vampirewal/vampirewal.core", "bgc7wf");
+
+ #region 获取知识库目录
+
+ var topics = yuQueClient.GetRepoTopic("vampirewal/vampirewal.core");
+ //Console.WriteLine(topics.Count);
+
+ #endregion
+
+ #region 获取知识库目录树形结构
+
+ var topicTrees = yuQueClient.GetRepoTopicTree("vampirewal/vampirewal.core");
+ //Console.WriteLine(topicTrees.Count);
+
+ #endregion
+
+ #region 获取文档详情
+ //var detail = yuQueClient.GetDocDetail("vampirewal/vampirewal.core", "doc");
+ //Console.WriteLine(detail.Data.Title);
+ #endregion
+
+
+
+ //List topics2 =gettopic("vampirewal/vampirewal.core");
}
public override void BillVmInitData()
@@ -269,6 +311,12 @@ namespace test
}
+ //public List gettopic(string aaa)
+ //{
+ // string value = HttpHelper.HttpGet($"https://www.yuque.com/api/v2/repos/{aaa}", "rs5tCCeXhfVlDRQQunpdBA3TYe3fwcgIixWIIRvS", "netCoreSdk");
+ // return JsonConvert.DeserializeObject(value)!.Data;
+ //}
+
public override void InitData()
{
GetById("9c7d6d6c-145f-48a3-b185-3b9ba6366d10");
diff --git a/test/test.csproj b/test/test.csproj
index 65c2d02..23ccccd 100644
--- a/test/test.csproj
+++ b/test/test.csproj
@@ -16,9 +16,11 @@
+
+
--
Gitee
From ee01307c9bcbd72f929db3fe9166c28754a17248 Mon Sep 17 00:00:00 2001
From: YangCheng <235160615@qq.com>
Date: Thu, 3 Mar 2022 14:42:23 +0800
Subject: [PATCH 12/53] 2022-3-3
---
.../VampirewalExportExcelService.cs | 180 ++++++++++++------
.../Interface/IExportExcelService.cs | 46 -----
.../Interface/IOperationExcelService.cs | 67 +++++++
Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs | 2 +-
Vampirewal.Core/Tools/ListExtension.cs | 80 ++++----
Vampirewal.Core/Vampirewal.Core.csproj | 2 +-
test/MainViewModel.cs | 6 +-
test/ViewModelLocator.cs | 2 +-
8 files changed, 236 insertions(+), 149 deletions(-)
delete mode 100644 Vampirewal.Core/Interface/IExportExcelService.cs
create mode 100644 Vampirewal.Core/Interface/IOperationExcelService.cs
diff --git a/Vampirewal.Core/Components/VampirewalExportExcelService.cs b/Vampirewal.Core/Components/VampirewalExportExcelService.cs
index 910c850..0fb115d 100644
--- a/Vampirewal.Core/Components/VampirewalExportExcelService.cs
+++ b/Vampirewal.Core/Components/VampirewalExportExcelService.cs
@@ -11,75 +11,33 @@
//----------------------------------------------------------------*/
#endregion
-using Microsoft.Win32;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.Data;
-using System.Diagnostics;
using System.IO;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
using Vampirewal.Core.Interface;
using Vampirewal.Core.Models;
using Vampirewal.Core.Tools;
namespace Vampirewal.Core.Components
{
-
+
///
- /// Vampirewal导出Excel服务
+ /// Vampirewal操作Excel服务
///
- public sealed class VampirewalExportExcelService : IExportExcelService
+ public sealed class VampirewalOperationExcelService : IOperationExcelService
{
- ///
- /// 构造函数
- ///
- public VampirewalExportExcelService()
- {
- //构造函数
- }
-
- #region 属性
- ///
- /// 保存Excel文件名
- ///
- public string SaveFileName { get; private set; }
- ///
- /// Excel文件保存地址
- ///
- public string SaveFilePath { get; private set; }
-
- ///
- /// Excel类型
- ///
- public ExcelType excelType { get; private set; }
- #endregion
-
- ///
- /// 设置
- ///
- /// 设置保存文件的文件名
- /// 设置保存文件的路径
- /// 设置excel类型
- public void Setting(string saveFileName, string saveFilePath, ExcelType type)
- {
- SaveFileName = saveFileName;
- SaveFilePath = saveFilePath;
- excelType = type;
- }
-
///
/// 执行导出
///
/// 实体类型
/// 导出数据源
///
- public void ExportDataToExcel(List EntityList) where T : TopModel, new()
+ public void ExportDataToExcel(List EntityList,string SaveFilePath, ExcelType excelType) where T : TopModel, new()
{
try
{
@@ -88,26 +46,28 @@ namespace Vampirewal.Core.Components
throw new Exception("导出Excel文件的数据源不能为空!");
}
+ Type type = typeof(T);
+
if (string.IsNullOrEmpty(SaveFilePath))
{
- throw new Exception("导出Excel文件的保存路径不能为空!");
- }
- if (string.IsNullOrEmpty(SaveFileName))
- {
- throw new Exception("导出Excel文件的文件名称不能为空!");
+ SaveFilePath=AppDomain.CurrentDomain.BaseDirectory;
}
+ //if (string.IsNullOrEmpty(SaveFileName))
+ //{
+ // throw new Exception("导出Excel文件的文件名称不能为空!");
+ //}
var dt = EntityList.ToDataTable();
switch (excelType)
{
case ExcelType.xlsx:
- var sfn = SaveFileName + ".xlsx";
+ var sfn = type.Name + ".xlsx";
SaveFilePath += sfn;
break;
case ExcelType.xls:
- var sfn2 = SaveFileName + ".xlsx";
+ var sfn2 = type.Name + ".xlsx";
SaveFilePath += sfn2;
break;
@@ -132,7 +92,8 @@ namespace Vampirewal.Core.Components
{
return;
}
- ISheet sheet = string.IsNullOrEmpty(SaveFileName) ? workbook.CreateSheet("Sheet1") : workbook.CreateSheet(SaveFileName);
+ //ISheet sheet = string.IsNullOrEmpty(SaveFileName) ? workbook.CreateSheet("Sheet1") : workbook.CreateSheet(SaveFileName);
+ ISheet sheet = workbook.CreateSheet(type.Name);
//读取标题
@@ -180,7 +141,116 @@ namespace Vampirewal.Core.Components
}
- }
+ ///
+ /// 将excel中的数据导入到DataTable中
+ ///
+ /// /// 表名
+ /// 第一行是否是DataTable的列名
+ /// 文件完整路径
+ /// 返回的DataTable
+ public DataTable ExcelToDataTable(string sheetName, bool isFirstRowColumn, string FileFullPath)
+ {
+ //if (string.IsNullOrEmpty(sheetName))
+ //{
+ // throw new ArgumentNullException(sheetName);
+ //}
+ if (string.IsNullOrEmpty(FileFullPath))
+ {
+ throw new ArgumentNullException(FileFullPath);
+ }
+ var data = new DataTable();
+ IWorkbook workbook = null;
+ FileStream fs = null;
+ try
+ {
+ fs = new FileStream(FileFullPath, FileMode.Open, FileAccess.Read);
+ if (FileFullPath.IndexOf(".xlsx", StringComparison.Ordinal) > 0)
+ {
+ workbook = new XSSFWorkbook(fs);
+ }
+ else if (FileFullPath.IndexOf(".xls", StringComparison.Ordinal) > 0)
+ {
+ workbook = new HSSFWorkbook(fs);
+ }
+
+ ISheet sheet = null;
+ if (workbook != null)
+ {
+ //如果没有找到指定的sheetName对应的sheet,则尝试获取第一个sheet
+ sheet = workbook.GetSheet(sheetName) ?? workbook.GetSheetAt(0);
+ }
+ if (sheet == null) return data;
+ var firstRow = sheet.GetRow(0);
+ //一行最后一个cell的编号 即总的列数
+ int cellCount = firstRow.LastCellNum;
+ int startRow;
+ if (isFirstRowColumn)
+ {
+ for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
+ {
+ var cell = firstRow.GetCell(i);
+ var cellValue = cell.StringCellValue;
+ if (cellValue == null) continue;
+ var column = new DataColumn(cellValue);
+ data.Columns.Add(column);
+ }
+ startRow = sheet.FirstRowNum + 1;
+ }
+ else
+ {
+ startRow = sheet.FirstRowNum;
+ }
+ //最后一列的标号
+ var rowCount = sheet.LastRowNum;
+ for (var i = startRow; i <= rowCount; ++i)
+ {
+ var row = sheet.GetRow(i);
+ //没有数据的行默认是null
+ if (row == null) continue;
+ var dataRow = data.NewRow();
+ for (int j = row.FirstCellNum; j < cellCount; ++j)
+ {
+ //同理,没有数据的单元格都默认是null
+ if (row.GetCell(j) != null)
+ dataRow[j] = row.GetCell(j).ToString();
+ }
+ data.Rows.Add(dataRow);
+ }
+
+ return data;
+ }
+ catch (IOException ioex)
+ {
+ throw new IOException(ioex.Message);
+ }
+ catch (Exception ex)
+ {
+ throw new Exception(ex.Message);
+ }
+ finally
+ {
+ if (fs != null)
+ {
+ fs.Close();
+ }
+ }
+ }
+
+
+ ///
+ /// 导入EXCEL文件转成List
+ ///
+ ///
+ /// 第一行是否是DataTable的列名
+ /// 文件完整路径
+ ///
+ public List ExcelToList(bool isFirstRowColumn, string FileFullPath)
+ {
+ Type type = typeof(T);
+
+ return ExcelToDataTable(type.Name, isFirstRowColumn, FileFullPath).ToList();
+ }
+ }
}
diff --git a/Vampirewal.Core/Interface/IExportExcelService.cs b/Vampirewal.Core/Interface/IExportExcelService.cs
deleted file mode 100644
index bda2f13..0000000
--- a/Vampirewal.Core/Interface/IExportExcelService.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Vampirewal.Core.Models;
-
-namespace Vampirewal.Core.Interface
-{
- ///
- /// 导出Excel服务接口
- ///
- ///
- public interface IExportExcelService
- {
-
- ///
- /// 保存Excel文件名
- ///
- string SaveFileName { get; }
-
- ///
- /// Excel文件保存地址
- ///
- string SaveFilePath { get; }
-
- ///
- /// Excel类型
- ///
- ExcelType excelType { get; }
-
- ///
- /// 设置
- ///
- /// 设置保存文件的文件名
- /// 设置保存文件的路径
- /// 设置excel类型
- void Setting(string saveFileName, string saveFilePath, ExcelType type);
-
- ///
- /// 执行导出
- ///
- /// 设置数据源
- void ExportDataToExcel(List EntityList) where T : TopModel, new();
- }
-}
diff --git a/Vampirewal.Core/Interface/IOperationExcelService.cs b/Vampirewal.Core/Interface/IOperationExcelService.cs
new file mode 100644
index 0000000..f705b0e
--- /dev/null
+++ b/Vampirewal.Core/Interface/IOperationExcelService.cs
@@ -0,0 +1,67 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Vampirewal.Core.Models;
+
+namespace Vampirewal.Core.Interface
+{
+ ///
+ /// 操作Excel服务接口
+ ///
+ ///
+ public interface IOperationExcelService
+ {
+
+ /////
+ ///// 保存Excel文件名
+ /////
+ //string SaveFileName { get; }
+
+ /////
+ ///// Excel文件保存地址
+ /////
+ //string SaveFilePath { get; }
+
+ /////
+ ///// Excel类型
+ /////
+ //ExcelType excelType { get; }
+
+ /////
+ ///// 设置
+ /////
+ ///// 设置保存文件的文件名
+ ///// 设置保存文件的路径
+ ///// 设置excel类型
+ //void Setting(string saveFileName, string saveFilePath, ExcelType type);
+
+ ///
+ /// 执行导出
+ ///
+ /// 实体类型
+ /// 导出数据源
+ ///
+ public void ExportDataToExcel(List EntityList, string SaveFilePath, ExcelType excelType) where T : TopModel, new();
+
+ ///
+ /// 将excel中的数据导入到DataTable中
+ ///
+ /// /// 表名
+ /// 第一行是否是DataTable的列名
+ /// 文件完整路径
+ /// 返回的DataTable
+ DataTable ExcelToDataTable(string sheetName, bool isFirstRowColumn, string FileFullPath);
+
+ ///
+ /// 导入EXCEL文件转成List
+ ///
+ ///
+ /// 第一行是否是DataTable的列名
+ /// 文件完整路径
+ ///
+ List ExcelToList(bool isFirstRowColumn, string FileFullPath);
+ }
+}
diff --git a/Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs b/Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs
index 1317140..140bfc7 100644
--- a/Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs
+++ b/Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs
@@ -43,7 +43,7 @@ namespace Vampirewal.Core.SimpleMVVM
///
/// 导出excel服务
///
- protected IExportExcelService ExportExcelService { get; set; }
+ protected IOperationExcelService ExportExcelService { get; set; }
///
diff --git a/Vampirewal.Core/Tools/ListExtension.cs b/Vampirewal.Core/Tools/ListExtension.cs
index 020f6cf..3968204 100644
--- a/Vampirewal.Core/Tools/ListExtension.cs
+++ b/Vampirewal.Core/Tools/ListExtension.cs
@@ -63,48 +63,44 @@ namespace Vampirewal.Core.Tools
return OutSource;
}
- ///
- /// 将List转换成DataTable
- ///
- ///
- ///
- ///
- //public static DataTable ToDataTable(this List data)
- //{
- // PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T));
-
- // var Clone = properties;
-
-
-
- // foreach (var property in Clone)
- // {
- // if (property)
- // {
-
- // }
- // }
-
- // DataTable dt = new DataTable();
- // for (int i = 0; i < properties.Count; i++)
- // {
- // PropertyDescriptor property = properties[i];
-
- // var aa= property.PropertyType.GetCustomAttributes(typeof(SugarColumn), false).FirstOrDefault();
-
- // dt.Columns.Add(property.Name, property.PropertyType);
- // }
- // object[] values = new object[properties.Count];
- // foreach (T item in data)
- // {
- // for (int i = 0; i < values.Length; i++)
- // {
- // values[i] = properties[i].GetValue(item);
- // }
- // dt.Rows.Add(values);
- // }
- // return dt;
- //}
+ public static List ToList(this DataTable dt)
+ {
+ var list = new List();
+ var plist = new List(typeof(T).GetProperties());
+ foreach (DataRow item in dt.Rows)
+ {
+ T s = Activator.CreateInstance();
+ for (int i = 0; i < dt.Columns.Count; i++)
+ {
+ PropertyInfo info = plist.Find(p => p.Name == dt.Columns[i].ColumnName);
+ if (info != null)
+ {
+ try
+ {
+ if (!Convert.IsDBNull(item[i]))
+ {
+ object v = null;
+ if (info.PropertyType.ToString().Contains("System.Nullable"))
+ {
+ v = Convert.ChangeType(item[i], Nullable.GetUnderlyingType(info.PropertyType));
+ }
+ else
+ {
+ v = Convert.ChangeType(item[i], info.PropertyType);
+ }
+ info.SetValue(s, v, null);
+ }
+ }
+ catch (Exception ex)
+ {
+ throw new Exception("字段[" + info.Name + "]转换出错," + ex.Message);
+ }
+ }
+ }
+ list.Add(s);
+ }
+ return list;
+ }
///
/// Convert a List{T} to a DataTable.
diff --git a/Vampirewal.Core/Vampirewal.Core.csproj b/Vampirewal.Core/Vampirewal.Core.csproj
index df1957d..bf3843a 100644
--- a/Vampirewal.Core/Vampirewal.Core.csproj
+++ b/Vampirewal.Core/Vampirewal.Core.csproj
@@ -7,7 +7,7 @@
该Core类库详细介绍请查看:https://blog.csdn.net/weixin_42806176/article/details/120705323
(2.X开始的ORM使用SqlSugar,1.X使用的EFCore)
true
- 2.0.0.2
+ 2.0.0.3
true
https://blog.csdn.net/weixin_42806176/article/details/120705323
Vampirewal-Logo.png
diff --git a/test/MainViewModel.cs b/test/MainViewModel.cs
index e716189..33d661b 100644
--- a/test/MainViewModel.cs
+++ b/test/MainViewModel.cs
@@ -360,10 +360,10 @@ namespace test
public class ListVMTest : BillListBaseVM
{
- public ListVMTest(IDataContext dc, IAppConfig config,IDialogMessage dialog,IExportExcelService exportExcel) : base(dc, config, dialog)
+ public ListVMTest(IDataContext dc, IAppConfig config,IDialogMessage dialog,IOperationExcelService exportExcel) : base(dc, config, dialog)
{
ExportExcelService = exportExcel;
- ExportExcelService.Setting("test", AppDomain.CurrentDomain.BaseDirectory, ExcelType.xlsx);
+ //ExportExcelService.Setting("test", AppDomain.CurrentDomain.BaseDirectory, ExcelType.xlsx);
ExecuteShowDialogWindowCommand(new TestBillModel_SearchModel());
@@ -399,7 +399,7 @@ namespace test
public override void ExecuteBeforeCloseDialogWindowCommand()
{
//Config.Save();
- ExportExcelService.ExportDataToExcel(EntityList.ToList());
+ ExportExcelService.ExportDataToExcel(EntityList.ToList(),AppDomain.CurrentDomain.BaseDirectory, ExcelType.xlsx);
}
}
diff --git a/test/ViewModelLocator.cs b/test/ViewModelLocator.cs
index ec1c8cd..5e7845c 100644
--- a/test/ViewModelLocator.cs
+++ b/test/ViewModelLocator.cs
@@ -32,7 +32,7 @@ namespace test
CustomIoC.Instance.Register();
CustomIoC.Instance.Register();
- CustomIoC.Instance.Register();
+ CustomIoC.Instance.Register();
base.InitRegisterService();
}
--
Gitee
From a424d3183bf4bbbc78e8358d55f817b35b49539b Mon Sep 17 00:00:00 2001
From: YangCheng <235160615@qq.com>
Date: Sat, 12 Mar 2022 18:15:38 +0800
Subject: [PATCH 13/53] 2022-3-12
---
Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs | 12 +-
Vampirewal.Core/SimpleMVVM/NotifyBase.cs | 21 ++
Vampirewal.Core/Vampirewal.Core.csproj | 2 +-
.../RadarChartControl/RadarChart.cs | 189 ++++++++++++++++++
.../WpfTheme/UcView/AddOrEditUcViewBase.cs | 21 +-
.../WpfTheme/UcView/UcViewStyles.xaml | 2 +-
.../WpfTheme/WindowStyle/MainWindowBase.cs | 10 +-
.../WpfTheme/WindowStyle/WindowBase.cs | 34 ++++
.../WpfTheme/WindowStyle/WindowStyles.xaml | 2 +
test/MainViewModel.cs | 126 +++++++++---
test/MainWindow.xaml | 73 +------
test/TestAddorEditView.xaml | 6 +-
test/ViewModelLocator.cs | 4 +-
13 files changed, 374 insertions(+), 128 deletions(-)
create mode 100644 Vampirewal.Core/WpfTheme/CustomControl/RadarChartControl/RadarChart.cs
diff --git a/Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs b/Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs
index 140bfc7..89a1b91 100644
--- a/Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs
+++ b/Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs
@@ -190,9 +190,9 @@ namespace Vampirewal.Core.SimpleMVVM
}
///
- /// ★调用之后给EntityList进行赋值★
- /// 1、如果使用SqlSugar进行取值的话,直接赋值Queryable即可
- /// 2、如果使用其他方式给EntityList赋值,这个方法可重写,也可以自己写方法给EntityList赋值
+ /// ★调用之后给进行赋值★
+ /// 1、如果使用进行取值的话,直接赋值即可
+ /// 2、如果使用其他方式给赋值,这个方法可重写,也可以自己写方法给赋值
///
protected virtual void GetList()
{
@@ -202,7 +202,11 @@ namespace Vampirewal.Core.SimpleMVVM
var baseQuery = GetSearchQuery();
- var list = DC.Client.Queryable(baseQuery).ToPageList(Page, Limit);
+ int total = 0;
+
+ var list = DC.Client.Queryable(baseQuery).ToPageList(Page, Limit,ref total);
+
+ PageCount = total;
foreach (var item in list)
{
diff --git a/Vampirewal.Core/SimpleMVVM/NotifyBase.cs b/Vampirewal.Core/SimpleMVVM/NotifyBase.cs
index 31c0f90..ae08fb8 100644
--- a/Vampirewal.Core/SimpleMVVM/NotifyBase.cs
+++ b/Vampirewal.Core/SimpleMVVM/NotifyBase.cs
@@ -53,5 +53,26 @@ namespace Vampirewal.Core.SimpleMVVM
field = value;
DoNotify(propName);
}
+
+ ///
+ /// 带的属性变化通知
+ ///
+ ///
+ ///
+ ///
+ /// 属性变化的时候执行的方法
+ ///
+ public void ActionSet(ref T field, T value,Action OnChanged=null, [CallerMemberName] string propName = "")
+ {
+ if (EqualityComparer.Default.Equals(field, value))
+ {
+ return;
+ }
+
+
+ field = value;
+ OnChanged?.Invoke(value);
+ DoNotify(propName);
+ }
}
}
diff --git a/Vampirewal.Core/Vampirewal.Core.csproj b/Vampirewal.Core/Vampirewal.Core.csproj
index bf3843a..60dca37 100644
--- a/Vampirewal.Core/Vampirewal.Core.csproj
+++ b/Vampirewal.Core/Vampirewal.Core.csproj
@@ -7,7 +7,7 @@
该Core类库详细介绍请查看:https://blog.csdn.net/weixin_42806176/article/details/120705323
(2.X开始的ORM使用SqlSugar,1.X使用的EFCore)
true
- 2.0.0.3
+ 2.0.0.8
true
https://blog.csdn.net/weixin_42806176/article/details/120705323
Vampirewal-Logo.png
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/RadarChartControl/RadarChart.cs b/Vampirewal.Core/WpfTheme/CustomControl/RadarChartControl/RadarChart.cs
new file mode 100644
index 0000000..afa2cc2
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/CustomControl/RadarChartControl/RadarChart.cs
@@ -0,0 +1,189 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:RadarChart
+// 创 建 者:杨程
+// 创建时间:2022/3/11 14:53:16
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+using System.Windows.Shapes;
+using Vampirewal.Core.SimpleMVVM;
+
+namespace Vampirewal.Core.WpfTheme.CustomControl
+{
+ ///
+ /// 雷达图控件
+ ///
+ public class RadarChart : Control
+ {
+
+ public ObservableCollection RadarArray
+ {
+ get { return (ObservableCollection)GetValue(RadarArrayProperty); }
+ set { SetValue(RadarArrayProperty, value); }
+ }
+
+ public static readonly DependencyProperty RadarArrayProperty =
+ DependencyProperty.Register("RadarArray", typeof(ObservableCollection), typeof(RadarChart), new PropertyMetadata(null));
+
+
+
+
+
+ public Brush RadarChartTitleForeground
+ {
+ get { return (Brush)GetValue(RadarChartTitleForegroundProperty); }
+ set { SetValue(RadarChartTitleForegroundProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for RadarChartTitleForeground. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty RadarChartTitleForegroundProperty =
+ DependencyProperty.Register("RadarChartTitleForeground", typeof(Brush), typeof(RadarChart), new PropertyMetadata(Brushes.Black));
+
+
+
+
+ static RadarChart()
+ {
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(RadarChart), new FrameworkPropertyMetadata(typeof(RadarChart)));
+ }
+ protected override void OnRender(DrawingContext drawingContext)
+ {
+ DrawPoints(150, drawingContext, true);
+ DrawPoints(100, drawingContext);
+ DrawPoints(50, drawingContext);
+
+ var myPen = new Pen
+ {
+ Thickness = 4,
+ Brush = Brushes.DodgerBlue
+ };
+ myPen.Freeze();
+ StreamGeometry streamGeometry = new StreamGeometry();
+ using (StreamGeometryContext geometryContext = streamGeometry.Open())
+ {
+ var h = this.ActualHeight / 2;
+ var w = this.ActualWidth / 2;
+ PointCollection points = new PointCollection();
+ foreach (var item in RadarArray)
+ {
+ var ss = new Point((item.PointValue.X - w) / 100 * item.ValueMax + w, (item.PointValue.Y - h) / 100 * item.ValueMax + h);
+ points.Add(ss);
+ }
+ geometryContext.BeginFigure(points[points.Count - 1], true, true);
+ geometryContext.PolyLineTo(points, true, true);
+ }
+ streamGeometry.Freeze();
+ SolidColorBrush rectBrush = new SolidColorBrush(Colors.LightSkyBlue);
+ rectBrush.Opacity = 0.5;
+ drawingContext.DrawGeometry(rectBrush, myPen, streamGeometry);
+ }
+ void DrawPoints(int circleRadius, DrawingContext drawingContext, bool isDrawText = false)
+ {
+ var myPen = new Pen
+ {
+ Thickness = 2,
+ Brush = Brushes.Gainsboro
+ };
+ myPen.Freeze();
+ StreamGeometry streamGeometry = new StreamGeometry();
+ using (StreamGeometryContext geometryContext = streamGeometry.Open())
+ {
+ var h = this.ActualHeight / 2;
+ var w = this.ActualWidth / 2;
+ PointCollection points = null;
+ if (isDrawText)
+ points = GetPolygonPoint(new Point(w, h), circleRadius, RadarArray.Count, drawingContext);
+ else
+ points = GetPolygonPoint(new Point(w, h), circleRadius, RadarArray.Count);
+ geometryContext.BeginFigure(points[points.Count - 1], true, true);
+ geometryContext.PolyLineTo(points, true, true);
+ }
+ streamGeometry.Freeze();
+ drawingContext.DrawGeometry(null, myPen, streamGeometry);
+ }
+ private PointCollection GetPolygonPoint(Point center, double r, int polygonBound, DrawingContext drawingContext = null)
+ {
+ double g = 18;
+ double perangle = 360 / polygonBound;
+ double pi = Math.PI;
+ List values = new List();
+ for (int i = 0; i < polygonBound; i++)
+ {
+ Point p2 = new Point(r * Math.Cos(g * pi / 180) + center.X, r * Math.Sin(g * pi / 180) + center.Y);
+ if (drawingContext != null)
+ {
+ FormattedText formattedText = new FormattedText(
+ RadarArray[i].Text,
+ CultureInfo.CurrentCulture,
+ FlowDirection.LeftToRight,
+ new Typeface(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Thin, FontStretches.Normal),
+ 20.001D, RadarChartTitleForeground,1.25d)
+ {
+ MaxLineCount = 1,
+ TextAlignment = TextAlignment.Justify,
+ Trimming = TextTrimming.CharacterEllipsis
+ };
+ RadarArray[i].PointValue = p2;
+ if (p2.Y > center.Y && p2.X < center.X)
+ drawingContext.DrawText(formattedText, new Point(p2.X - formattedText.Width - 5, p2.Y - formattedText.Height / 2));
+ else if (p2.Y < center.Y && p2.X > center.X)
+ drawingContext.DrawText(formattedText, new Point(p2.X, p2.Y - formattedText.Height));
+ else if (p2.Y < center.Y && p2.X < center.X)
+ drawingContext.DrawText(formattedText, new Point(p2.X - formattedText.Width - 5, p2.Y - formattedText.Height));
+ else if (p2.Y < center.Y && p2.X == center.X)
+ drawingContext.DrawText(formattedText, new Point(p2.X - formattedText.Width, p2.Y - formattedText.Height));
+ else
+ drawingContext.DrawText(formattedText, new Point(p2.X, p2.Y));
+ }
+ values.Add(p2);
+ g += perangle;
+ }
+ PointCollection pcollect = new PointCollection(values);
+ return pcollect;
+ }
+ }
+
+ public class RadarModel : NotifyBase
+ {
+ public string Text { get; set; }
+
+ private int _valueMax;
+
+ public int ValueMax
+ {
+ get { return _valueMax; }
+ set
+ {
+ _valueMax = value;
+ DoNotify();
+ }
+ }
+ private Point _pointValue;
+
+ public Point PointValue
+ {
+ get { return _pointValue; }
+ set
+ {
+ _pointValue = value;
+ DoNotify();
+ }
+ }
+ }
+}
diff --git a/Vampirewal.Core/WpfTheme/UcView/AddOrEditUcViewBase.cs b/Vampirewal.Core/WpfTheme/UcView/AddOrEditUcViewBase.cs
index 81e5840..c49dd1d 100644
--- a/Vampirewal.Core/WpfTheme/UcView/AddOrEditUcViewBase.cs
+++ b/Vampirewal.Core/WpfTheme/UcView/AddOrEditUcViewBase.cs
@@ -57,6 +57,7 @@ namespace Vampirewal.Core.WpfTheme.UcView
base.OnApplyTemplate();
var BottomCustomArea = this.Template.FindName("BottomItems", this) as StackPanel;
+ var Bottoms=this.Template.FindName("Bottom",this) as RowDefinition;
if (BottomBtnItems.Count > 0)
{
@@ -66,23 +67,13 @@ namespace Vampirewal.Core.WpfTheme.UcView
BottomCustomArea.Children.Add(item);
}
}
+ else
+ {
+ Bottoms.Height = new GridLength(0);
+ }
}
- #region 属性
-
- #endregion
-
- #region 公共方法
-
- #endregion
-
- #region 私有方法
-
- #endregion
-
- #region 命令
-
- #endregion
+
#region 依赖属性
diff --git a/Vampirewal.Core/WpfTheme/UcView/UcViewStyles.xaml b/Vampirewal.Core/WpfTheme/UcView/UcViewStyles.xaml
index 8a80a65..78b9c27 100644
--- a/Vampirewal.Core/WpfTheme/UcView/UcViewStyles.xaml
+++ b/Vampirewal.Core/WpfTheme/UcView/UcViewStyles.xaml
@@ -12,7 +12,7 @@
-
+
///
///
- protected virtual void CloseButton_Click(object sender, RoutedEventArgs e)
- {
- WindowsManager.CloseWindow(this);
- //this.Close();
- }
+ //protected virtual void CloseButton_Click(object sender, RoutedEventArgs e)
+ //{
+ // WindowsManager.CloseWindow(this);
+ // //this.Close();
+ //}
protected override void OnStyleChanged(Style oldStyle, Style newStyle)
{
diff --git a/Vampirewal.Core/WpfTheme/WindowStyle/WindowBase.cs b/Vampirewal.Core/WpfTheme/WindowStyle/WindowBase.cs
index 3777967..bb22ffc 100644
--- a/Vampirewal.Core/WpfTheme/WindowStyle/WindowBase.cs
+++ b/Vampirewal.Core/WpfTheme/WindowStyle/WindowBase.cs
@@ -21,6 +21,7 @@ using System.Windows.Controls.Primitives;
using System.Windows.Controls;
using System.Windows.Shell;
using Vampirewal.Core.SimpleMVVM;
+using System.Windows.Input;
namespace Vampirewal.Core.WpfTheme.WindowStyle
{
@@ -180,6 +181,8 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
///
protected virtual void CloseWin_Click(object sender, RoutedEventArgs e)
{
+ CloseWindowCommand?.Execute(CloseWindowCommandParameter);
+
WindowsManager.CloseWindow(this);
//this.Close();
}
@@ -303,6 +306,37 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
//}
+ #endregion
+
+ #region 关闭窗体触发事件
+
+ ///
+ /// 关闭窗体触发命令
+ ///
+ public ICommand CloseWindowCommand
+ {
+ get { return (ICommand)GetValue(CloseWindowCommandProperty); }
+ set { SetValue(CloseWindowCommandProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for CloseWindowCommand. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty CloseWindowCommandProperty =
+ DependencyProperty.Register("CloseWindowCommand", typeof(ICommand), typeof(WindowBase), new PropertyMetadata(null));
+
+
+
+
+ public object CloseWindowCommandParameter
+ {
+ get { return (object)GetValue(CloseWindowCommandParameterProperty); }
+ set { SetValue(CloseWindowCommandParameterProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for CloseWindowCommandParameter. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty CloseWindowCommandParameterProperty =
+ DependencyProperty.Register("CloseWindowCommandParameter", typeof(object), typeof(WindowBase), new PropertyMetadata(null));
+
+
#endregion
#endregion
diff --git a/Vampirewal.Core/WpfTheme/WindowStyle/WindowStyles.xaml b/Vampirewal.Core/WpfTheme/WindowStyle/WindowStyles.xaml
index 09f91f8..254f5f6 100644
--- a/Vampirewal.Core/WpfTheme/WindowStyle/WindowStyles.xaml
+++ b/Vampirewal.Core/WpfTheme/WindowStyle/WindowStyles.xaml
@@ -192,6 +192,7 @@
+
+
+
+
\ No newline at end of file
diff --git a/YC.WPF.Theme/FrameworkControl/CustomWinodw/MainWindowBase.cs b/YC.WPF.Theme/FrameworkControl/CustomWinodw/MainWindowBase.cs
new file mode 100644
index 0000000..7355851
--- /dev/null
+++ b/YC.WPF.Theme/FrameworkControl/CustomWinodw/MainWindowBase.cs
@@ -0,0 +1,181 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:MainWindow
+// 创 建 者:杨程
+// 创建时间:2021/11/3 17:20:09
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+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.Controls.Primitives;
+using System.Windows.Shell;
+using Vampirewal.Core.SimpleMVVM;
+
+namespace Vampirewal.Core.WPF.Theme.FrameworkControl.CustomWindow
+{
+ ///
+ /// 适用于主窗体的页面
+ ///
+ public class MainWindowBase : WindowBase
+ {
+ private ColumnDefinition leftcontent { get; set; }
+
+ ///
+ /// 记录最右位置
+ ///
+ private GridLength _lastLength;
+
+ public UIElement LeftContent { get; set; }
+
+ public List MainAreas { get; set; } = new List();
+
+ ///
+ /// 拖动条样式
+ ///
+ public ControlTemplate GridSplitterStyle { get; set; }
+
+ static MainWindowBase()
+ {
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(MainWindowBase), new FrameworkPropertyMetadata(typeof(MainWindowBase)));
+ }
+
+ ///
+ /// 构造函数
+ ///
+ public MainWindowBase()
+ {
+ var BaseStyle = res["MainWindow"] as Style;
+
+ this.Style = BaseStyle;
+ }
+
+ public override void OnApplyTemplate()
+ {
+ base.OnApplyTemplate();
+ //var aaa = base.Resources["WindowBase"] as Style;//如果前端添加引用之后,可以使用这个方法
+
+ #region 顶部模块
+ var MainArea = this.Template.FindName("MainAreaMenu", this) as StackPanel;
+
+ if (MainAreas.Count > 0)
+ {
+ foreach (var item in MainAreas)
+ {
+ MainArea.Children.Add(item);
+ }
+ }
+ else
+ {
+ MainAreaHeight = 0;
+ }
+ #endregion
+
+
+
+ #region 拖动条设置
+ var GS = this.Template.FindName("gs", this) as GridSplitter;
+
+ GS.MouseDoubleClick += GS_MouseDoubleClick;
+
+ _lastLength = new GridLength(LeftMenuMaxWidth, GridUnitType.Star);
+
+
+ #region 自定义GridSplitter模版
+ if (GridSplitterStyle != null)
+ {
+ if (GridSplitterStyle.TargetType == typeof(GridSplitter))
+ {
+ GS.Template = GridSplitterStyle;
+ }
+ }
+ #endregion
+
+ #endregion
+
+
+
+ #region 左侧菜单栏
+
+ leftcontent = this.Template.FindName("leftcontent", this) as ColumnDefinition;
+
+ if (LeftContent == null)
+ {
+ leftcontent.Width = new GridLength(0, GridUnitType.Star);
+ GS.Visibility = Visibility.Collapsed;
+ }
+ #endregion
+ }
+
+ private void GS_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
+ {
+ if (leftcontent != null)
+ {
+ if (leftcontent.Width.Value > 0)
+ {
+ leftcontent.Width = new GridLength(0, GridUnitType.Star);
+ }
+ else
+ {
+ leftcontent.Width = _lastLength;
+ }
+ }
+ }
+
+ ///
+ /// 关闭窗体(可重写,需保留base.CloseWin_Click)
+ ///
+ ///
+ ///
+ //protected virtual void CloseButton_Click(object sender, RoutedEventArgs e)
+ //{
+ // WindowsManager.CloseWindow(this);
+ // //this.Close();
+ //}
+
+ protected override void OnStyleChanged(Style oldStyle, Style newStyle)
+ {
+ base.OnStyleChanged(oldStyle, newStyle);
+ }
+
+
+ #region 依赖属性
+
+
+ #region 左侧菜单栏最大宽度
+ public int LeftMenuMaxWidth
+ {
+ get { return (int)GetValue(LeftMenuMaxWidthProperty); }
+ set { SetValue(LeftMenuMaxWidthProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for LeftMenuMaxWidth. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty LeftMenuMaxWidthProperty =
+ DependencyProperty.Register("LeftMenuMaxWidth", typeof(int), typeof(MainWindowBase), new PropertyMetadata(230));
+ #endregion
+
+ #region 顶部模块区域高度
+ public int MainAreaHeight
+ {
+ get { return (int)GetValue(MainAreaHeightProperty); }
+ set { SetValue(MainAreaHeightProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for MainAreaHeight. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty MainAreaHeightProperty =
+ DependencyProperty.Register("MainAreaHeight", typeof(int), typeof(MainWindowBase), new PropertyMetadata(80));
+ #endregion
+
+ #endregion
+ }
+}
diff --git a/YC.WPF.Theme/FrameworkControl/CustomWinodw/NotifyDefultView.xaml b/YC.WPF.Theme/FrameworkControl/CustomWinodw/NotifyDefultView.xaml
new file mode 100644
index 0000000..2050055
--- /dev/null
+++ b/YC.WPF.Theme/FrameworkControl/CustomWinodw/NotifyDefultView.xaml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 该页为默认展示页面,请自行替换!
+
+
+
+
+
diff --git a/YC.WPF.Theme/Style/ControlStyle/WindowStyle/testWindow.xaml.cs b/YC.WPF.Theme/FrameworkControl/CustomWinodw/NotifyDefultView.xaml.cs
similarity index 70%
rename from YC.WPF.Theme/Style/ControlStyle/WindowStyle/testWindow.xaml.cs
rename to YC.WPF.Theme/FrameworkControl/CustomWinodw/NotifyDefultView.xaml.cs
index ff37a7e..73998a1 100644
--- a/YC.WPF.Theme/Style/ControlStyle/WindowStyle/testWindow.xaml.cs
+++ b/YC.WPF.Theme/FrameworkControl/CustomWinodw/NotifyDefultView.xaml.cs
@@ -13,14 +13,14 @@ using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
-namespace YC.WPF.Theme.Style.ControlStyle.WindowStyle
+namespace Vampirewal.Core.WPF.Theme.FrameworkControl.CustomWindow
{
///
- /// testWindow.xaml 的交互逻辑
+ /// NotifyDefultView.xaml 的交互逻辑
///
- public partial class testWindow : UserControl
+ public partial class NotifyDefultView : UserControl
{
- public testWindow()
+ public NotifyDefultView()
{
InitializeComponent();
}
diff --git a/YC.WPF.Theme/FrameworkControl/CustomWinodw/NotifyWindow.xaml b/YC.WPF.Theme/FrameworkControl/CustomWinodw/NotifyWindow.xaml
new file mode 100644
index 0000000..154fc76
--- /dev/null
+++ b/YC.WPF.Theme/FrameworkControl/CustomWinodw/NotifyWindow.xaml
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/YC.WPF.Theme/FrameworkControl/CustomWinodw/NotifyWindow.xaml.cs b/YC.WPF.Theme/FrameworkControl/CustomWinodw/NotifyWindow.xaml.cs
new file mode 100644
index 0000000..60e32c5
--- /dev/null
+++ b/YC.WPF.Theme/FrameworkControl/CustomWinodw/NotifyWindow.xaml.cs
@@ -0,0 +1,241 @@
+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.Animation;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+using System.Windows.Threading;
+using Vampirewal.Core.SimpleMVVM;
+
+namespace Vampirewal.Core.WPF.Theme.FrameworkControl.CustomWindow
+{
+ ///
+ /// NotifyWindow.xaml 的交互逻辑
+ ///
+ public partial class NotifyWindow : WindowBase
+ {
+
+
+ public NotifyWindow(NotifyWindowSetting _setting)
+ {
+ InitializeComponent();
+ Setting = _setting;
+ SetValue(_setting);
+ this.Loaded += NotifyWindow_Loaded;
+ }
+
+
+ private NotifyWindowSetting Setting { get; set; }
+
+ private void NotifyWindow_Loaded(object sender, RoutedEventArgs e)
+ {
+
+
+ var animation = new DoubleAnimation
+ {
+ Duration = new Duration(TimeSpan.FromSeconds(0.5)),
+ To = SystemParameters.WorkArea.Bottom - this.Height,
+ };
+ this.BeginAnimation(TopProperty, animation);
+
+ Left = SystemParameters.WorkArea.Right - this.Width-10;
+ Top = SystemParameters.WorkArea.Bottom;
+ }
+
+ private void SetValue(NotifyWindowSetting Setting)
+ {
+ Width = Setting.WindowWidth;
+ Height = Setting.WindowHeight;
+
+ if (Setting.UiView!=null)
+ {
+ UcView.Content = Setting.UiView;
+
+ Setting.UiView.Width = double.NaN;
+ Setting.UiView.Height = double.NaN;
+
+ var vm = Setting.UiView.DataContext as ViewModelBase;
+
+ if ( vm !=null)
+ {
+
+ vm.PassData(Setting.PassData);
+ }
+ }
+ else
+ {
+ NotifyDefultView notifyDefultView = new NotifyDefultView();
+ UcView.Content = notifyDefultView;
+ }
+
+
+
+ if (!string.IsNullOrEmpty(Setting.NotifyTitle))
+ {
+ this.Title = Setting.NotifyTitle;
+ }
+
+
+ if (!string.IsNullOrEmpty(Setting.Background))
+ {
+ this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(Setting.Background));
+ }
+ else
+ {
+ this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#2F3437"));
+ }
+
+ if (!string.IsNullOrEmpty(Setting.Foreground))
+ {
+ this.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(Setting.Foreground));
+ }
+ else
+ {
+ this.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#EBEBEB"));
+ }
+
+ if (!string.IsNullOrEmpty(Setting.WindowBorderBrush))
+ {
+ this.BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(Setting.WindowBorderBrush));
+ }
+ else
+ {
+ this.BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#3F4447"));
+ }
+
+ this.TitleFontSize = Setting.TitleFontSize;
+
+ if (Setting.DelayCloseTime>0)
+ {
+ DispatcherTimer timer=new DispatcherTimer();
+ timer.Interval = new TimeSpan(0, 0, Setting.DelayCloseTime);
+ timer.Tick += (s, e) =>
+ {
+
+ while(Setting.DelayCloseTime > 0)
+ {
+ Setting.DelayCloseTime--;
+ }
+
+ if (Setting.DelayCloseTime==0)
+ {
+ var animation = new DoubleAnimation
+ {
+ Duration = new Duration(TimeSpan.FromSeconds(0.3)),
+ To = SystemParameters.WorkArea.Bottom,
+ };
+ animation.Completed += (ss, ee) =>
+ {
+ this.Close();
+ };
+ this.BeginAnimation(TopProperty, animation);
+ }
+ };
+
+ timer.IsEnabled = true;
+ timer.Start();
+ }
+ }
+
+ protected override void TopTitle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
+ {
+
+ }
+
+ private void CloseButton_Click(object sender, RoutedEventArgs e)
+ {
+ var animation = new DoubleAnimation
+ {
+ Duration = new Duration(TimeSpan.FromSeconds(0.3)),
+ To = SystemParameters.WorkArea.Bottom,
+ };
+ animation.Completed += (ss, ee) =>
+ {
+ this.Close();
+ };
+ this.BeginAnimation(TopProperty, animation);
+
+
+ }
+ }
+
+ ///
+ /// Notify窗体配置
+ ///
+ public class NotifyWindowSetting
+ {
+ ///
+ /// Notify窗体标题
+ ///
+ public string NotifyTitle { get; set; } = "系统通知";
+ ///
+ /// 显示窗体
+ ///
+ public FrameworkElement UiView { get; set; }
+
+ ///
+ /// 窗体宽度
+ ///
+ public double WindowWidth { get; set; } = 300d;
+
+ ///
+ /// 窗体高度
+ ///
+ public double WindowHeight { get; set; } = 450d;
+
+ ///
+ /// 窗体背景色
+ ///
+ public string Background { get; set; } = "#2F3437";
+
+ ///
+ /// 窗体前景色
+ ///
+ public string Foreground { get; set; } = "#EBEBEB";
+
+ ///
+ /// 标题文字大小
+ ///
+ public int TitleFontSize { get; set; } = 12;
+
+ ///
+ /// 窗体边框颜色
+ ///
+ public string WindowBorderBrush { get; set; } = "#3F4447";
+
+ private int _DelayCloseTime =0;
+ ///
+ /// 延迟关闭时间(默认以秒计算)
+ /// 默认等于0,大于0即认为开启延迟关闭
+ ///
+ public int DelayCloseTime
+ {
+ get
+ {
+ if (_DelayCloseTime<0)
+ {
+ _DelayCloseTime = 0;
+ }
+
+ return _DelayCloseTime;
+ }
+ set
+ {
+ _DelayCloseTime = value;
+ }
+ }
+
+ ///
+ /// 需要传输的数据
+ ///
+ public object PassData { get; set; }
+ }
+}
diff --git a/YC.WPF.Theme/Style/CutomControl/DialogWindow/PopupWindow.xaml b/YC.WPF.Theme/FrameworkControl/CustomWinodw/PopupWindow.xaml
similarity index 94%
rename from YC.WPF.Theme/Style/CutomControl/DialogWindow/PopupWindow.xaml
rename to YC.WPF.Theme/FrameworkControl/CustomWinodw/PopupWindow.xaml
index d092e8b..ca3e67a 100644
--- a/YC.WPF.Theme/Style/CutomControl/DialogWindow/PopupWindow.xaml
+++ b/YC.WPF.Theme/FrameworkControl/CustomWinodw/PopupWindow.xaml
@@ -1,9 +1,8 @@
-
/// PopupWindow.xaml 的交互逻辑
///
public partial class PopupWindow : Window, INotifyPropertyChanged
- {
+ {
#region Notify
public event PropertyChangedEventHandler PropertyChanged;
diff --git a/YC.WPF.Theme/Style/ControlStyle/WindowStyle/testWindow.xaml b/YC.WPF.Theme/FrameworkControl/CustomWinodw/ShowDialogWindow.xaml
similarity index 37%
rename from YC.WPF.Theme/Style/ControlStyle/WindowStyle/testWindow.xaml
rename to YC.WPF.Theme/FrameworkControl/CustomWinodw/ShowDialogWindow.xaml
index d9bb197..fc4bdd0 100644
--- a/YC.WPF.Theme/Style/ControlStyle/WindowStyle/testWindow.xaml
+++ b/YC.WPF.Theme/FrameworkControl/CustomWinodw/ShowDialogWindow.xaml
@@ -1,15 +1,20 @@
-
-
-
+
+
+
-
+
diff --git a/YC.WPF.Theme/FrameworkControl/CustomWinodw/ShowDialogWindow.xaml.cs b/YC.WPF.Theme/FrameworkControl/CustomWinodw/ShowDialogWindow.xaml.cs
new file mode 100644
index 0000000..c1279f3
--- /dev/null
+++ b/YC.WPF.Theme/FrameworkControl/CustomWinodw/ShowDialogWindow.xaml.cs
@@ -0,0 +1,222 @@
+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.Shapes;
+using Vampirewal.Core.SimpleMVVM;
+
+namespace Vampirewal.Core.WPF.Theme.FrameworkControl.CustomWindow
+{
+ ///
+ /// ShowDialogWindow.xaml 的交互逻辑
+ ///
+ public partial class ShowDialogWindow : WindowBase
+ {
+ ///
+ /// 构造函数
+ ///
+ ///
+ public ShowDialogWindow(DialogWindowSetting Setting)
+ {
+ if (Setting.UiView==null)
+ {
+ throw new Exception("DialogWindow窗体页面不能为null");
+ }
+
+ InitializeComponent();
+ SetValue(Setting);
+ }
+
+ private void SetValue(DialogWindowSetting Setting)
+ {
+ Width = Setting.WindowWidth;
+ Height = Setting.WindowHeight;
+
+
+ UcView.Content = Setting.UiView;
+
+
+ Setting.UiView.Width = double.NaN;
+ Setting.UiView.Height = double.NaN;
+
+
+ this.DataContext = Setting.UiView.DataContext;
+ ViewModelBase vm = Setting.UiView.DataContext as ViewModelBase;
+ vm.View = this;
+
+ vm.PassData(Setting.PassData);
+
+ if (!string.IsNullOrEmpty(Setting.IconStr))
+ {
+ this.Icon = new BitmapImage(new Uri(Setting.IconStr));
+ this.ShowInTaskbar = true;
+ }
+ else
+ {
+ this.ShowInTaskbar = false;
+ }
+
+ this.IsShowMaxButton = Setting.IsShowMaxButton;
+ this.IsShowMinButton = Setting.IsShowMinButton;
+ this.IsOpenWindowSize = Setting.IsOpenWindowSize;
+
+ if (!string.IsNullOrEmpty(Setting.Background))
+ {
+ this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(Setting.Background));
+ }
+ else
+ {
+ this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#2F3437"));
+ }
+
+ if (!string.IsNullOrEmpty(Setting.Foreground))
+ {
+ this.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(Setting.Foreground));
+ }
+ else
+ {
+ this.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#EBEBEB"));
+ }
+
+ if (!string.IsNullOrEmpty(Setting.WindowBorderBrush))
+ {
+ this.BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(Setting.WindowBorderBrush));
+ }
+ else
+ {
+ this.BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#3F4447"));
+ }
+
+ this.TitleFontSize = Setting.TitleFontSize;
+
+ if (Setting.CloseWindowCommand!=null)
+ {
+ this.CloseWindowCommand = Setting.CloseWindowCommand;
+ this.CloseWindowCommandParameter = Setting.CloseWindowCommandParameter;
+ }
+ }
+
+ protected override void CloseWin_Click(object sender, RoutedEventArgs e)
+ {
+ CloseWindowCommand?.Execute(CloseWindowCommandParameter);
+
+ base.CloseWin_Click(sender, e);
+ }
+
+
+ ///
+ /// 弹窗关闭的命令
+ ///
+ public ICommand CloseWindowCommand
+ {
+ get { return (ICommand)GetValue(CloseWindowCommandProperty); }
+ set { SetValue(CloseWindowCommandProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for CloseWindowCommand. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty CloseWindowCommandProperty =
+ DependencyProperty.Register("CloseWindowCommand", typeof(ICommand), typeof(ShowDialogWindow), new PropertyMetadata(null));
+
+
+
+ ///
+ /// 弹窗关闭的命令传参
+ ///
+ public object CloseWindowCommandParameter
+ {
+ get { return (object)GetValue(CloseWindowCommandParameterProperty); }
+ set { SetValue(CloseWindowCommandParameterProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for CloseWindowCommandParameter. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty CloseWindowCommandParameterProperty =
+ DependencyProperty.Register("CloseWindowCommandParameter", typeof(object), typeof(ShowDialogWindow), new PropertyMetadata(null));
+
+
+ }
+
+ ///
+ /// 弹窗window设置
+ ///
+ public class DialogWindowSetting
+ {
+
+ ///
+ /// 窗体宽度
+ ///
+ public double WindowWidth { get; set; } = 800d;
+
+ ///
+ /// 窗体高度
+ ///
+ public double WindowHeight { get; set; } = 450d;
+
+ ///
+ /// 显示窗体
+ ///
+ public FrameworkElement UiView { get; set; }
+
+ ///
+ /// 窗体Icon
+ ///
+ public string IconStr { get; set; } = "";
+
+ ///
+ /// 是否开启窗体最大化按钮
+ ///
+ public bool IsShowMaxButton { get; set; } = true;
+
+ ///
+ /// 是否开启窗体最小化按钮
+ ///
+ public bool IsShowMinButton { get; set; } = false;
+
+ ///
+ /// 窗体背景色
+ ///
+ public string Background { get; set; } = "#2F3437";
+
+ ///
+ /// 窗体前景色
+ ///
+ public string Foreground { get; set; } = "#EBEBEB";
+
+ ///
+ /// 标题文字大小
+ ///
+ public int TitleFontSize { get; set; } = 12;
+
+ ///
+ /// 需要传递的数据
+ ///
+ public object PassData { get; set; } = null;
+
+ ///
+ /// 窗体边框颜色
+ ///
+ public string WindowBorderBrush { get; set; } = "#3F4447";
+
+ ///
+ /// 是否开启窗体自定义调整大小
+ ///
+ public bool IsOpenWindowSize { get; set; } = false;
+
+ ///
+ /// 弹窗关闭的命令
+ ///
+ public ICommand CloseWindowCommand { get; set; }
+
+ ///
+ /// 弹窗关闭的命令传参
+ ///
+ public object CloseWindowCommandParameter { get; set; }
+ }
+}
diff --git a/YC.WPF.Theme/FrameworkControl/CustomWinodw/VampirewalFolderBrowserDialog.xaml b/YC.WPF.Theme/FrameworkControl/CustomWinodw/VampirewalFolderBrowserDialog.xaml
new file mode 100644
index 0000000..e4220df
--- /dev/null
+++ b/YC.WPF.Theme/FrameworkControl/CustomWinodw/VampirewalFolderBrowserDialog.xaml
@@ -0,0 +1,122 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/YC.WPF.Theme/Style/ControlStyle/WindowStyle/SelectFolderView.xaml.cs b/YC.WPF.Theme/FrameworkControl/CustomWinodw/VampirewalFolderBrowserDialog.xaml.cs
similarity index 34%
rename from YC.WPF.Theme/Style/ControlStyle/WindowStyle/SelectFolderView.xaml.cs
rename to YC.WPF.Theme/FrameworkControl/CustomWinodw/VampirewalFolderBrowserDialog.xaml.cs
index 6240ddb..7c37bfb 100644
--- a/YC.WPF.Theme/Style/ControlStyle/WindowStyle/SelectFolderView.xaml.cs
+++ b/YC.WPF.Theme/FrameworkControl/CustomWinodw/VampirewalFolderBrowserDialog.xaml.cs
@@ -11,42 +11,46 @@ using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
-using YC.WPF.Theme.Style.Windows;
-namespace YC.WPF.Theme
+namespace Vampirewal.Core.WPF.Theme.FrameworkControl.CustomWindow
{
///
- /// SelectFolderView.xaml 的交互逻辑
+ /// VampirewalFolderBrowserDialog.xaml 的交互逻辑
///
- public partial class SelectFolderView : BaseWindow
+ public partial class VampirewalFolderBrowserDialog : WindowBase
{
- public SelectFolderView()
+ #region 属性
+ ///
+ /// 文件夹完整路径
+ ///
+ public string FullPath { get; set; }
+ #endregion
+
+ public VampirewalFolderBrowserDialog()
{
InitializeComponent();
+ this.Loaded += VampirewalFolderBrowserDialog_Loaded;
}
+ private void VampirewalFolderBrowserDialog_Loaded(object sender, RoutedEventArgs e)
+ {
+
+ }
- }
- ///
- /// 文件项类型
- ///
- internal enum MetroFolderBrowserControlModelType
- {
- ///
- /// 文件夹
- ///
- Directory,
- ///
- /// 桌面
- ///
- Desktop,
- ///
- /// 计算机
- ///
- Computer,
- ///
- /// 磁盘驱动器
- ///
- Disk,
+
+
+ private void SelectFolderBtn_Click(object sender, RoutedEventArgs e)
+ {
+ this.DialogResult = true;
+
+ FullPath = "aaaa";
+ base.CloseWin_Click(null, null);
+ }
+
+ private void QuXiaoBtn_Click(object sender, RoutedEventArgs e)
+ {
+ this.DialogResult = false;
+ base.CloseWin_Click(null, null);
+ }
}
}
diff --git a/YC.WPF.Theme/Style/Windows/BaseWindow.cs b/YC.WPF.Theme/FrameworkControl/CustomWinodw/WindowBase.cs
similarity index 52%
rename from YC.WPF.Theme/Style/Windows/BaseWindow.cs
rename to YC.WPF.Theme/FrameworkControl/CustomWinodw/WindowBase.cs
index c7b52fb..e8a4ebb 100644
--- a/YC.WPF.Theme/Style/Windows/BaseWindow.cs
+++ b/YC.WPF.Theme/FrameworkControl/CustomWinodw/WindowBase.cs
@@ -1,8 +1,8 @@
#region << 文 件 说 明 >>
/*----------------------------------------------------------------
-// 文件名称:BaseWindow
+// 文件名称:WindowBase
// 创 建 者:杨程
-// 创建时间:2021/8/20 12:30:20
+// 创建时间:2021/10/11 14:00:27
// 文件版本:V1.0.0
// ===============================================================
// 功能描述:
@@ -14,21 +14,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
-using System.Windows.Controls;
using System.Windows.Controls.Primitives;
-using System.Windows.Input;
+using System.Windows.Controls;
using System.Windows.Shell;
using Vampirewal.Core.SimpleMVVM;
+using System.Windows.Input;
-namespace YC.WPF.Theme.Style.Windows
+namespace Vampirewal.Core.WPF.Theme.FrameworkControl.CustomWindow
{
- public class BaseWindow:Window
+ ///
+ /// 自定义窗体基类
+ ///
+ public class WindowBase:Window
{
- private Button CloseButton;
+ private Button CloseButton { get; set; }
private Button MinButton;
public UIElement MainContent { get; set; }
@@ -42,44 +44,73 @@ namespace YC.WPF.Theme.Style.Windows
/// 底部自定义内容区域
///
public List BottomCustomAreas { get; set; } = new List();
- static BaseWindow()
+
+ /////
+ ///// 数据上下文
+ /////
+ //public virtual ViewModelBase DataSource { get; set; }
+
+ ///
+ /// 窗体ID
+ ///
+ public Guid ViewId { get; set; }
+
+ protected ResourceDictionary res
{
- DefaultStyleKeyProperty.OverrideMetadata(typeof(BaseWindow), new FrameworkPropertyMetadata(typeof(BaseWindow)));
+ get
+ {
+ return new ResourceDictionary() { Source = new Uri("pack://application:,,,/Vampirewal.Core.WPF.Theme;component/Theme.xaml", UriKind.RelativeOrAbsolute) };
+ }
+ }
-
+ static WindowBase()
+ {
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(WindowBase), new FrameworkPropertyMetadata(typeof(WindowBase)));
}
- public BaseWindow()
+ ///
+ /// 构造函数
+ ///
+ public WindowBase()
{
- this.Loaded += BaseWindow_Loaded;
+ this.Loaded += Window_Loaded;
WindowStartupLocation = WindowStartupLocation.CenterScreen;
+
+ ViewId = Guid.NewGuid();
+
+ var BaseStyle = res["WindowBase"] as Style;
+
+ this.Style = BaseStyle;
+
+
}
- private void BaseWindow_Loaded(object sender, RoutedEventArgs e)
+ protected virtual void Window_Loaded(object sender, RoutedEventArgs e)
{
ViewModelBase vm = this.DataContext as ViewModelBase;
- if (vm!=null)
+ if (vm != null)
{
vm.View = this;
- WindowsManager.GetInstance().RegisterWindow(this);
+ //WindowsManager.RegisterWindow(this);
}
}
protected override void OnInitialized(EventArgs e)
{
-
base.OnInitialized(e);
+
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
+ //var aaa = base.Resources["WindowBase"] as Style;//如果前端添加引用之后,可以使用这个方法
CloseButton = this.Template.FindName("btn_CloseWindow", this) as Button;
var MaxWin = this.Template.FindName("btn_MaxWindow", this) as ToggleButton;
MinButton = this.Template.FindName("btn_MinWindow", this) as Button;
- if (CloseButton != null&&MaxWin!=null&& MinButton != null)
+ if (CloseButton != null && MaxWin != null && MinButton != null)
{
CloseButton.Click += CloseWin_Click;
@@ -93,9 +124,9 @@ namespace YC.WPF.Theme.Style.Windows
TopTitle.MouseLeftButtonDown += TopTitle_MouseLeftButtonDown;
var border = this.Template.FindName("border", this) as Border;
- border.Margin = new Thickness(10);
- border.MaxHeight= SystemParameters.WorkArea.Height-5;
- border.MaxWidth= SystemParameters.WorkArea.Width-5;
+ border.Margin = new Thickness(1);
+ border.MaxHeight = SystemParameters.WorkArea.Height - 5;
+ border.MaxWidth = SystemParameters.WorkArea.Width - 5;
var TopLayoutBtns = this.Template.FindName("TopCustomButtons", this) as StackPanel;
foreach (var item in TopCustomButtons)
@@ -105,7 +136,7 @@ namespace YC.WPF.Theme.Style.Windows
var BottomCustomArea = this.Template.FindName("BottomCustomArea", this) as StackPanel;
//BottomCustomArea.Height = 0;
- if (BottomCustomAreas.Count>0)
+ if (BottomCustomAreas.Count > 0)
{
//BottomCustomArea.Height = 50;
foreach (var item in BottomCustomAreas)
@@ -113,11 +144,16 @@ namespace YC.WPF.Theme.Style.Windows
BottomCustomArea.Children.Add(item);
}
}
-
+ //this.ResizeMode = ResizeMode.CanResize;
}
- private void TopTitle_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
+ ///
+ /// 自定义窗体标题栏鼠标左键按下事件(可重写)
+ ///
+ ///
+ ///
+ protected virtual void TopTitle_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
this.DragMove();
}
@@ -138,9 +174,17 @@ namespace YC.WPF.Theme.Style.Windows
this.WindowState = WindowState.Maximized;
}
- private void CloseWin_Click(object sender, RoutedEventArgs e)
+ ///
+ /// 关闭窗体(可重写,需保留base.CloseWin_Click)
+ ///
+ ///
+ ///
+ protected virtual void CloseWin_Click(object sender, RoutedEventArgs e)
{
- this.Close();
+ CloseWindowCommand?.Execute(CloseWindowCommandParameter);
+
+ WindowsManager.GetInstance().CloseWindow(this);
+ //this.Close();
}
//protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
//{
@@ -165,7 +209,7 @@ namespace YC.WPF.Theme.Style.Windows
///
// Using a DependencyProperty as the backing store for TitleFontSize. This enables animation, styling, binding, etc...
public static readonly DependencyProperty TitleFontSizeProperty =
- DependencyProperty.Register("TitleFontSize", typeof(int), typeof(BaseWindow), new PropertyMetadata(12));
+ DependencyProperty.Register("TitleFontSize", typeof(int), typeof(WindowBase), new PropertyMetadata(12));
#endregion
#region 是否启用窗体调整
@@ -177,28 +221,28 @@ namespace YC.WPF.Theme.Style.Windows
// Using a DependencyProperty as the backing store for IsOpenWindowSize. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsOpenWindowSizeProperty =
- DependencyProperty.Register("IsOpenWindowSize", typeof(bool), typeof(BaseWindow), new PropertyMetadata(false, IsOpenWindowSizePropertyChangeCallBack));
+ DependencyProperty.Register("IsOpenWindowSize", typeof(bool), typeof(WindowBase), new PropertyMetadata(false, IsOpenWindowSizePropertyChangeCallBack));
- private static void IsOpenWindowSizePropertyChangeCallBack(DependencyObject d,DependencyPropertyChangedEventArgs e)
+ private static void IsOpenWindowSizePropertyChangeCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
bool value = Convert.ToBoolean(e.NewValue);
if (value)
{
Window w = (Window)d;
w.WindowStartupLocation = WindowStartupLocation.CenterScreen;
- w.MaxHeight= SystemParameters.MaximizedPrimaryScreenHeight;
- w.MaxWidth= SystemParameters.MaximizedPrimaryScreenWidth;
+ w.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
+ w.MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth;
w.WindowState = WindowState.Normal;
WindowChrome chrome = new WindowChrome();
chrome.CornerRadius = new CornerRadius(5);
- chrome.GlassFrameThickness = new Thickness(1,0,1,1);
+ chrome.GlassFrameThickness = new Thickness(1, 0, 1, 1);
chrome.UseAeroCaptionButtons = false;
chrome.NonClientFrameEdges = NonClientFrameEdges.None;
chrome.CaptionHeight = 2;
WindowChrome.SetWindowChrome(w, chrome);
-
+
}
}
#endregion
@@ -212,11 +256,9 @@ namespace YC.WPF.Theme.Style.Windows
// Using a DependencyProperty as the backing store for IsShowMinButton. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsShowMinButtonProperty =
- DependencyProperty.Register("IsShowMinButton", typeof(bool), typeof(BaseWindow), new PropertyMetadata(true));
+ DependencyProperty.Register("IsShowMinButton", typeof(bool), typeof(WindowBase), new PropertyMetadata(true));
#endregion
-
-
#region 是否显示最大化按钮
public bool IsShowMaxButton
{
@@ -226,13 +268,78 @@ namespace YC.WPF.Theme.Style.Windows
// Using a DependencyProperty as the backing store for IsShowMaxButton. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsShowMaxButtonProperty =
- DependencyProperty.Register("IsShowMaxButton", typeof(bool), typeof(BaseWindow), new PropertyMetadata(true));
+ DependencyProperty.Register("IsShowMaxButton", typeof(bool), typeof(WindowBase), new PropertyMetadata(true));
+ #endregion
+
+ #region 是否显示关闭按钮
+
+
+ public bool IsShowCloseButton
+ {
+ get { return (bool)GetValue(IsShowCloseButtonProperty); }
+ set { SetValue(IsShowCloseButtonProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for IsShowCloseButton. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty IsShowCloseButtonProperty =
+ DependencyProperty.Register("IsShowCloseButton", typeof(bool), typeof(WindowBase), new PropertyMetadata(true));
+
+
+ #endregion
+
+ #region 是否显示边框阴影
+
+
+ //public bool IsShowDropShadowEffect
+ //{
+ // get { return (bool)GetValue(IsShowDropShadowEffectProperty); }
+ // set { SetValue(IsShowDropShadowEffectProperty, value); }
+ //}
+
+ //// Using a DependencyProperty as the backing store for IsShowDropShadowEffect. This enables animation, styling, binding, etc...
+ //public static readonly DependencyProperty IsShowDropShadowEffectProperty =
+ // DependencyProperty.Register("IsShowDropShadowEffect", typeof(bool), typeof(WindowBase), new PropertyMetadata(false, IsShowDropShadowEffectPropertyChangeCallBack));
+
+ //private static void IsShowDropShadowEffectPropertyChangeCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ //{
+
+ //}
+
+
#endregion
+ #region 关闭窗体触发事件
+
+ ///
+ /// 关闭窗体触发命令
+ ///
+ public ICommand CloseWindowCommand
+ {
+ get { return (ICommand)GetValue(CloseWindowCommandProperty); }
+ set { SetValue(CloseWindowCommandProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for CloseWindowCommand. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty CloseWindowCommandProperty =
+ DependencyProperty.Register("CloseWindowCommand", typeof(ICommand), typeof(WindowBase), new PropertyMetadata(null));
+
+
+
+
+ public object CloseWindowCommandParameter
+ {
+ get { return (object)GetValue(CloseWindowCommandParameterProperty); }
+ set { SetValue(CloseWindowCommandParameterProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for CloseWindowCommandParameter. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty CloseWindowCommandParameterProperty =
+ DependencyProperty.Register("CloseWindowCommandParameter", typeof(object), typeof(WindowBase), new PropertyMetadata(null));
#endregion
+ #endregion
}
}
diff --git a/YC.WPF.Theme/FrameworkControl/CustomWinodw/WindowStyles.xaml b/YC.WPF.Theme/FrameworkControl/CustomWinodw/WindowStyles.xaml
new file mode 100644
index 0000000..ee6180d
--- /dev/null
+++ b/YC.WPF.Theme/FrameworkControl/CustomWinodw/WindowStyles.xaml
@@ -0,0 +1,442 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/YC.WPF.Theme/Style/BaseColor.xaml b/YC.WPF.Theme/Style/BaseColor.xaml
deleted file mode 100644
index a913fa8..0000000
--- a/YC.WPF.Theme/Style/BaseColor.xaml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/YC.WPF.Theme/Style/ControlStyle/ButtonStyle/ButtonStyles.xaml b/YC.WPF.Theme/Style/ControlStyle/ButtonStyle/ButtonStyles.xaml
deleted file mode 100644
index b41e5c3..0000000
--- a/YC.WPF.Theme/Style/ControlStyle/ButtonStyle/ButtonStyles.xaml
+++ /dev/null
@@ -1,559 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/YC.WPF.Theme/Style/ControlStyle/ButtonStyle/LinkButtonStyle.xaml b/YC.WPF.Theme/Style/ControlStyle/ButtonStyle/LinkButtonStyle.xaml
deleted file mode 100644
index f9a0bc1..0000000
--- a/YC.WPF.Theme/Style/ControlStyle/ButtonStyle/LinkButtonStyle.xaml
+++ /dev/null
@@ -1,59 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/YC.WPF.Theme/Style/ControlStyle/Carousel/CarouselStyles.xaml b/YC.WPF.Theme/Style/ControlStyle/Carousel/CarouselStyles.xaml
deleted file mode 100644
index 3064a11..0000000
--- a/YC.WPF.Theme/Style/ControlStyle/Carousel/CarouselStyles.xaml
+++ /dev/null
@@ -1,36 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/YC.WPF.Theme/Style/ControlStyle/ComboBox/ComboBoxStyles.xaml b/YC.WPF.Theme/Style/ControlStyle/ComboBox/ComboBoxStyles.xaml
deleted file mode 100644
index 20605f2..0000000
--- a/YC.WPF.Theme/Style/ControlStyle/ComboBox/ComboBoxStyles.xaml
+++ /dev/null
@@ -1,342 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/YC.WPF.Theme/Style/ControlStyle/GroupPanelStyle/GroupPanelStyles.xaml b/YC.WPF.Theme/Style/ControlStyle/GroupPanelStyle/GroupPanelStyles.xaml
deleted file mode 100644
index 148229e..0000000
--- a/YC.WPF.Theme/Style/ControlStyle/GroupPanelStyle/GroupPanelStyles.xaml
+++ /dev/null
@@ -1,124 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/YC.WPF.Theme/Style/ControlStyle/ScrollBarStyle/ScrollBarStyles.xaml b/YC.WPF.Theme/Style/ControlStyle/ScrollBarStyle/ScrollBarStyles.xaml
deleted file mode 100644
index 20a0490..0000000
--- a/YC.WPF.Theme/Style/ControlStyle/ScrollBarStyle/ScrollBarStyles.xaml
+++ /dev/null
@@ -1,264 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/YC.WPF.Theme/Style/ControlStyle/TabControlStyle/TabControlStyles.xaml b/YC.WPF.Theme/Style/ControlStyle/TabControlStyle/TabControlStyles.xaml
deleted file mode 100644
index 49b3fac..0000000
--- a/YC.WPF.Theme/Style/ControlStyle/TabControlStyle/TabControlStyles.xaml
+++ /dev/null
@@ -1,109 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/YC.WPF.Theme/Style/ControlStyle/TextBlockStyle/TextBlockStyles.xaml b/YC.WPF.Theme/Style/ControlStyle/TextBlockStyle/TextBlockStyles.xaml
deleted file mode 100644
index 05ab1a7..0000000
--- a/YC.WPF.Theme/Style/ControlStyle/TextBlockStyle/TextBlockStyles.xaml
+++ /dev/null
@@ -1,51 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/YC.WPF.Theme/Style/ControlStyle/TextBoxStyle/TextBoxStyles.xaml b/YC.WPF.Theme/Style/ControlStyle/TextBoxStyle/TextBoxStyles.xaml
deleted file mode 100644
index 8cfb418..0000000
--- a/YC.WPF.Theme/Style/ControlStyle/TextBoxStyle/TextBoxStyles.xaml
+++ /dev/null
@@ -1,160 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/YC.WPF.Theme/Style/ControlStyle/TitleContent/TitleContents.xaml b/YC.WPF.Theme/Style/ControlStyle/TitleContent/TitleContents.xaml
deleted file mode 100644
index 89cb0ab..0000000
--- a/YC.WPF.Theme/Style/ControlStyle/TitleContent/TitleContents.xaml
+++ /dev/null
@@ -1,44 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/YC.WPF.Theme/Style/ControlStyle/TreeViewStyle/TreeViewStyles.xaml b/YC.WPF.Theme/Style/ControlStyle/TreeViewStyle/TreeViewStyles.xaml
deleted file mode 100644
index dda98a9..0000000
--- a/YC.WPF.Theme/Style/ControlStyle/TreeViewStyle/TreeViewStyles.xaml
+++ /dev/null
@@ -1,135 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/YC.WPF.Theme/Style/ControlStyle/WindowStyle/ContaninerWindow.xaml b/YC.WPF.Theme/Style/ControlStyle/WindowStyle/ContaninerWindow.xaml
deleted file mode 100644
index ef95aa9..0000000
--- a/YC.WPF.Theme/Style/ControlStyle/WindowStyle/ContaninerWindow.xaml
+++ /dev/null
@@ -1,64 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/YC.WPF.Theme/Style/ControlStyle/WindowStyle/SelectFolderView.xaml b/YC.WPF.Theme/Style/ControlStyle/WindowStyle/SelectFolderView.xaml
deleted file mode 100644
index 81d54df..0000000
--- a/YC.WPF.Theme/Style/ControlStyle/WindowStyle/SelectFolderView.xaml
+++ /dev/null
@@ -1,48 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/YC.WPF.Theme/Style/ControlStyle/WindowStyle/WindowMdi.xaml b/YC.WPF.Theme/Style/ControlStyle/WindowStyle/WindowMdi.xaml
deleted file mode 100644
index eaae6f4..0000000
--- a/YC.WPF.Theme/Style/ControlStyle/WindowStyle/WindowMdi.xaml
+++ /dev/null
@@ -1,36 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/YC.WPF.Theme/Style/ControlStyle/WindowStyle/WindowStyle.xaml b/YC.WPF.Theme/Style/ControlStyle/WindowStyle/WindowStyle.xaml
deleted file mode 100644
index 7838d62..0000000
--- a/YC.WPF.Theme/Style/ControlStyle/WindowStyle/WindowStyle.xaml
+++ /dev/null
@@ -1,321 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/YC.WPF.Theme/Style/CutomControl/Button/LinkButton.cs b/YC.WPF.Theme/Style/CutomControl/Button/LinkButton.cs
deleted file mode 100644
index d197c7d..0000000
--- a/YC.WPF.Theme/Style/CutomControl/Button/LinkButton.cs
+++ /dev/null
@@ -1,103 +0,0 @@
-#region << 文 件 说 明 >>
-/*----------------------------------------------------------------
-// 文件名称:LinkButton
-// 创 建 者:杨程
-// 创建时间:2021/8/25 14:48:11
-// 文件版本:V1.0.0
-// ===============================================================
-// 功能描述:
-//
-//
-//----------------------------------------------------------------*/
-#endregion
-
-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.Controls.Primitives;
-using System.Windows.Media.Animation;
-using YC.WPF.Theme.Style.Windows;
-
-namespace YC.WPF.Theme.Style.CutomControl
-{
- ///
- /// 带下划线的按钮
- ///
- public class LinkButton: Button
- {
- static LinkButton()
- {
- DefaultStyleKeyProperty.OverrideMetadata(typeof(LinkButton), new FrameworkPropertyMetadata(typeof(LinkButton)));
- }
-
- public LinkButton()
- {
- //构造函数
-
- }
-
- public override void OnApplyTemplate()
- {
- var progressBar = this.Template.FindName("progressBar", this) as ProgressBar;
-
- //var template = this.Template.FindName("template", this) as ControlTemplate;
-
- //template.Triggers.Add(aa);
-
- Trigger trigger = new Trigger()
- {
- Property=IsOpenLinkAnimationProperty,
- Value=true
- };
-
- BeginStoryboard begin = new BeginStoryboard();
-
- Storyboard storyboard = new Storyboard();
-
-
-
- DoubleAnimation doubleAnimation = new DoubleAnimation()
- {
- From = 0,
- To = 100,
- Duration = new Duration(TimeSpan.FromSeconds(0.2))
- };
-
- progressBar.BeginAnimation(ProgressBar.ValueProperty, doubleAnimation);
-
- trigger.EnterActions.Add(begin);
- }
-
-
-
- #region 是否开启Link动画
- public bool IsOpenLinkAnimation
- {
- get { return (bool)GetValue(IsOpenLinkAnimationProperty); }
- set { SetValue(IsOpenLinkAnimationProperty, value); }
- }
-
- // Using a DependencyProperty as the backing store for IsOpenLinkAnimation. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty IsOpenLinkAnimationProperty =
- DependencyProperty.Register("IsOpenLinkAnimation", typeof(bool), typeof(LinkButton), new PropertyMetadata(false));
- #endregion
-
- #region 鼠标移动上去的颜色
- public string MoveInColor
- {
- get { return (string)GetValue(MoveInColorProperty); }
- set { SetValue(MoveInColorProperty, value); }
- }
-
- // Using a DependencyProperty as the backing store for MoveInColor. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty MoveInColorProperty =
- DependencyProperty.Register("MoveInColor", typeof(string), typeof(LinkButton), new PropertyMetadata("#fffffb"));
- #endregion
-
-
- }
-}
diff --git a/YC.WPF.Theme/Style/CutomControl/Carousel/Carousel.cs b/YC.WPF.Theme/Style/CutomControl/Carousel/Carousel.cs
deleted file mode 100644
index d867d75..0000000
--- a/YC.WPF.Theme/Style/CutomControl/Carousel/Carousel.cs
+++ /dev/null
@@ -1,1420 +0,0 @@
-#region << 文 件 说 明 >>
-/*----------------------------------------------------------------
-// 文件名称:Carousel
-// 创 建 者:杨程
-// 创建时间:2021/8/30 16:37:38
-// 文件版本:V1.0.0
-// ===============================================================
-// 功能描述:
-//
-//
-//----------------------------------------------------------------*/
-#endregion
-
-
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Collections.Specialized;
-using System.ComponentModel;
-using System.Linq;
-using System.Timers;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Markup;
-using System.Windows.Media;
-using System.Windows.Media.Animation;
-
-namespace YC.WPF.Theme.Style.CutomControl
-{
- internal enum CarouselLoacation
- {
- Left,
- Right,
- Center
- }
-
- internal enum CarouselZIndex
- {
- Left = 20,
- Center = 30,
- Right = 20,
- LeftMask = 40,
- RightMask = 40
- }
-
- [DefaultProperty("Children")]
- [ContentProperty("Children")]
- [Localizability(LocalizationCategory.None, Readability = Readability.Unreadable)]
- [TemplatePart(Name = Part_ContentDockName, Type = typeof(Canvas))]
- [TemplatePart(Name = Part_ButtonDockName, Type = typeof(StackPanel))]
- public class Carousel : Control, IAddChild
- {
- private const string Part_ContentDockName = "PART_ContentDock";
- private const string Part_ButtonDockName = "PART_ButtonDock";
- static Carousel()
- {
- DefaultStyleKeyProperty.OverrideMetadata(typeof(Carousel), new FrameworkPropertyMetadata(typeof(Carousel)));
- }
-
- public Carousel()
- {
- //_uiElementCollection = new List
public partial class App : VampirewalApplication
{
- public override IAppConfig Config()
+ protected override IAppConfig Config()
{
return VIoC.GetInstance().GetInstance();
}
-
+
//public override Assembly CurrentAssembly()
//{
// return Assembly.GetExecutingAssembly();
//}
- public override string FirstWindowName()
+ protected override string FirstWindowName()
{
return "test.MainWindow1";
}
@@ -39,15 +39,15 @@ namespace test
protected override void OnStartup(StartupEventArgs e)
{
-
-
-
- VIoC.GetInstance().RegisterAll();
+
+
+
+
//config.Save();
base.OnStartup(e);
-
+
string aa = Messenger.Default.Send("aatest");
}
diff --git a/test/test.View.csproj b/test/test.View.csproj
index fdf19fb..80e47b7 100644
--- a/test/test.View.csproj
+++ b/test/test.View.csproj
@@ -18,12 +18,13 @@
-
+
+
--
Gitee
From cf91864f3621330b64bd28357c74972a8ca9c883 Mon Sep 17 00:00:00 2001
From: YangCheng <235160615@qq.com>
Date: Sat, 11 Jun 2022 09:50:26 +0800
Subject: [PATCH 21/53] 2022-6-11
---
Test.Console/Test.Console.csproj | 3 +-
.../VampirewalExportExcelService.cs | 10 +-
Vampirewal.Core.VContainer/VIoC.cs | 11 +
.../ExportExcelPropertyAttribute.cs | 56 --
.../Components/VampirewalConfig.cs | 30 +
.../VampirewalExportExcelService.cs | 256 ------
Vampirewal.Core/Helper/PropertyHelper.cs | 84 +-
Vampirewal.Core/Interface/IDataContext.cs | 2 +-
.../Interface/IOperationExcelService.cs | 67 --
Vampirewal.Core/IoC/VampirewalIoC.cs | 413 ++++++++++
Vampirewal.Core/Models/BillBaseModel.cs | 2 +-
Vampirewal.Core/Models/DetailBaseModel.cs | 4 +-
Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs | 10 +-
Vampirewal.Core/SimpleMVVM/BillVM.cs | 4 +-
.../SimpleMVVM/VampirewalApplication.cs | 24 +-
Vampirewal.Core/SimpleMVVM/WindowsManager.cs | 40 +-
Vampirewal.Core/Tools/ListExtension.cs | 214 ++---
Vampirewal.Core/Tools/Utils.cs | 80 +-
Vampirewal.Core/Vampirewal.Core.csproj | 44 +-
Vampirewal.Core/WpfTheme/UcView/UcViewBase.cs | 28 +-
.../WindowStyle/ShowDialogWindow.xaml | 2 +-
.../WindowStyle/ShowDialogWindow.xaml.cs | 21 +-
.../WpfTheme/WindowStyle/WindowBase.cs | 38 +-
.../TextBox/TextBoxAttach.cs | 168 ++++
YC.WPF.Theme/Behaviors/DataGridBehavior.cs | 2 +-
.../Converter/DataContextConverter.cs | 44 ++
.../DataGrid/DataGridStyles.xaml | 25 +
.../CustomControl/NumTextBox/NumTextBox.cs | 45 ++
.../NumTextBox/NumTextBoxStyle.xaml | 61 ++
.../CustomControl/Pagination/VPagination.cs | 716 +++++++++++++++++
.../Pagination/VPaginationStyles.xaml | 154 ++++
.../RadarChartControl/RadarChart.cs | 204 +++++
.../RadarChartControl/RadarControl.xaml | 15 +
.../RadarChartControl/RadarControl.xaml.cs | 737 ++++++++++++++++++
.../SearchControl/SearchControl.cs | 123 +++
.../SearchControl/SearchControlStyle.xaml | 48 ++
.../CustomControl/TextBox/TextBoxStyles.xaml | 160 ++++
.../TitleContent/TitleContent.cs | 163 ++++
.../TitleContent/TitleContents.xaml | 44 ++
.../TreeView/TreeViewStyles.xaml | 9 +
.../CustomWinodw/WindowBase.cs | 32 +-
YC.WPF.Theme/Theme.xaml | 18 +-
YC.WPF.Theme/Vampirewal.Core.WPF.Theme.csproj | 56 +-
test.View2/aaView.xaml | 19 +-
test.View2/aaView.xaml.cs | 21 +-
test.View2/aaViewModel.cs | 10 +-
test.View2/test.View2.csproj | 1 -
test.ViewModel/Class1.cs | 64 --
test.ViewModel/MainViewModel.cs | 62 +-
test.ViewModel/ViewModelLocator.cs | 30 +-
test.ViewModel/test.ViewModel.csproj | 2 +-
test.ViewModel/test_NewPageViewModel.cs | 5 +-
test/App.xaml.cs | 26 +-
test/MainWindow.xaml | 1 -
test/MainWindow.xaml.cs | 20 +-
test/test.View.csproj | 1 +
56 files changed, 3714 insertions(+), 815 deletions(-)
delete mode 100644 Vampirewal.Core/Attributes/ExportExcelPropertyAttribute.cs
delete mode 100644 Vampirewal.Core/Components/VampirewalExportExcelService.cs
delete mode 100644 Vampirewal.Core/Interface/IOperationExcelService.cs
create mode 100644 Vampirewal.Core/IoC/VampirewalIoC.cs
create mode 100644 YC.WPF.Theme/AdditionalAttributes/TextBox/TextBoxAttach.cs
create mode 100644 YC.WPF.Theme/Converter/DataContextConverter.cs
create mode 100644 YC.WPF.Theme/CustomControl/DataGrid/DataGridStyles.xaml
create mode 100644 YC.WPF.Theme/CustomControl/NumTextBox/NumTextBox.cs
create mode 100644 YC.WPF.Theme/CustomControl/NumTextBox/NumTextBoxStyle.xaml
create mode 100644 YC.WPF.Theme/CustomControl/Pagination/VPagination.cs
create mode 100644 YC.WPF.Theme/CustomControl/Pagination/VPaginationStyles.xaml
create mode 100644 YC.WPF.Theme/CustomControl/RadarChartControl/RadarChart.cs
create mode 100644 YC.WPF.Theme/CustomControl/RadarChartControl/RadarControl.xaml
create mode 100644 YC.WPF.Theme/CustomControl/RadarChartControl/RadarControl.xaml.cs
create mode 100644 YC.WPF.Theme/CustomControl/SearchControl/SearchControl.cs
create mode 100644 YC.WPF.Theme/CustomControl/SearchControl/SearchControlStyle.xaml
create mode 100644 YC.WPF.Theme/CustomControl/TextBox/TextBoxStyles.xaml
create mode 100644 YC.WPF.Theme/CustomControl/TitleContent/TitleContent.cs
create mode 100644 YC.WPF.Theme/CustomControl/TitleContent/TitleContents.xaml
create mode 100644 YC.WPF.Theme/CustomControl/TreeView/TreeViewStyles.xaml
delete mode 100644 test.ViewModel/Class1.cs
diff --git a/Test.Console/Test.Console.csproj b/Test.Console/Test.Console.csproj
index e24c595..b687340 100644
--- a/Test.Console/Test.Console.csproj
+++ b/Test.Console/Test.Console.csproj
@@ -1,4 +1,4 @@
-
+
Exe
@@ -7,6 +7,7 @@
+
diff --git a/Vampirewal.Core.OperationExcelService/VampirewalExportExcelService.cs b/Vampirewal.Core.OperationExcelService/VampirewalExportExcelService.cs
index 6a4cf7e..49cad2f 100644
--- a/Vampirewal.Core.OperationExcelService/VampirewalExportExcelService.cs
+++ b/Vampirewal.Core.OperationExcelService/VampirewalExportExcelService.cs
@@ -43,7 +43,7 @@ namespace Vampirewal.Core.OperationExcelService
/// 实体类型
/// 导出数据源
///
- public void ExportDataToExcel(List EntityList,string SaveFilePath, ExcelType excelType) where T : class, new()
+ public void ExportDataToExcel(List EntityList, string SaveFilePath, ExcelType excelType) where T : class, new()
{
try
{
@@ -56,7 +56,7 @@ namespace Vampirewal.Core.OperationExcelService
if (string.IsNullOrEmpty(SaveFilePath))
{
- SaveFilePath=AppDomain.CurrentDomain.BaseDirectory;
+ SaveFilePath = AppDomain.CurrentDomain.BaseDirectory;
}
//if (string.IsNullOrEmpty(SaveFileName))
//{
@@ -99,7 +99,7 @@ namespace Vampirewal.Core.OperationExcelService
return;
}
//ISheet sheet = string.IsNullOrEmpty(SaveFileName) ? workbook.CreateSheet("Sheet1") : workbook.CreateSheet(SaveFileName);
- ISheet sheet = workbook.CreateSheet(type.Name);
+ ISheet sheet = workbook.CreateSheet(type.Name);
//读取标题
@@ -263,7 +263,7 @@ namespace Vampirewal.Core.OperationExcelService
/// List转DataTable
/// 仅适用于导出excel的数据,且对应实体类的属性上有特性
///
- private DataTable ToDataTable( List items)
+ private DataTable ToDataTable(List items)
{
var tb = new DataTable(typeof(T).Name);
@@ -306,7 +306,7 @@ namespace Vampirewal.Core.OperationExcelService
///
///
///
- private List DataTableToList( DataTable dt)
+ private List DataTableToList(DataTable dt)
{
var list = new List();
var plist = new List(typeof(T).GetProperties());
diff --git a/Vampirewal.Core.VContainer/VIoC.cs b/Vampirewal.Core.VContainer/VIoC.cs
index 91de5d1..40b1854 100644
--- a/Vampirewal.Core.VContainer/VIoC.cs
+++ b/Vampirewal.Core.VContainer/VIoC.cs
@@ -292,6 +292,17 @@ namespace Vampirewal.Core.VContainer
return type;
}
+
+ ///
+ /// 指定返回类型和类名获取实例
+ ///
+ ///
+ ///
+ ///
+ public T GetInstance(string ClassName)
+ {
+ return (T)this.GetInstance(ClassName);
+ }
#endregion
#region 内部方法
diff --git a/Vampirewal.Core/Attributes/ExportExcelPropertyAttribute.cs b/Vampirewal.Core/Attributes/ExportExcelPropertyAttribute.cs
deleted file mode 100644
index ab9cc3d..0000000
--- a/Vampirewal.Core/Attributes/ExportExcelPropertyAttribute.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-#region << 文 件 说 明 >>
-/*----------------------------------------------------------------
-// 文件名称:ExportExcelPropertyAttribute
-// 创 建 者:杨程
-// 创建时间:2022/2/11 19:16:22
-// 文件版本:V1.0.0
-// ===============================================================
-// 功能描述:
-//
-//
-//----------------------------------------------------------------*/
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Vampirewal.Core.Attributes
-{
- ///
- /// 是否能导出Excel
- ///
- [AttributeUsage(AttributeTargets.Property)]
- public class ExportExcelAttribute : Attribute
- {
- ///
- /// 是否能
- ///
- public bool IsCanExport { get; set; }
-
- ///
- /// 属性导出中文名
- ///
- public string PropertyChineseName { get; set; }
-
- ///
- /// 中文名对应的属性名称
- ///
- public string PropertyName { get; set; }
-
- ///
- /// 构造函数
- ///
- /// 属性导出中文名
- /// 中文名对应的属性名称
- /// 是否能导出
- public ExportExcelAttribute(string propertyChineseName, string propertyName, bool isCanExport = true)
- {
- IsCanExport = isCanExport;
- PropertyChineseName = propertyChineseName;
- PropertyName = propertyName;
- }
- }
-}
diff --git a/Vampirewal.Core/Components/VampirewalConfig.cs b/Vampirewal.Core/Components/VampirewalConfig.cs
index 58da0c2..51398fb 100644
--- a/Vampirewal.Core/Components/VampirewalConfig.cs
+++ b/Vampirewal.Core/Components/VampirewalConfig.cs
@@ -15,8 +15,11 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
+using NetTaste;
using Newtonsoft.Json;
using Vampirewal.Core.AppConfig;
using Vampirewal.Core.Interface;
@@ -248,6 +251,8 @@ namespace Vampirewal.Core.Components
{
var Config = JsonConvert.DeserializeObject(JsonHelper.Readjson(configFile));
SetValue(Config);
+
+ ExcuteLoadAssembly(isLoad);
}
else
{
@@ -317,6 +322,31 @@ namespace Vampirewal.Core.Components
LoadAppConfig();
}
}
+
+ bool isLoad = false;
+ private void ExcuteLoadAssembly(bool _isLoaded)
+ {
+ if (!_isLoaded&&ViewModulesPath.Count > 0)
+ {
+ ViewModulesPath.ForEach(f =>
+ {
+ try
+ {
+ Assembly ass = Assembly.LoadFile(f);
+
+ }
+ catch
+ {
+ //ErrorStr.Add($"无法加载该dll-{f}");
+ throw new Exception($"无法加载该DLL-{f}");
+ }
+ });
+
+ isLoad = true;
+ }
+
+
+ }
#endregion
}
}
diff --git a/Vampirewal.Core/Components/VampirewalExportExcelService.cs b/Vampirewal.Core/Components/VampirewalExportExcelService.cs
deleted file mode 100644
index c87cd94..0000000
--- a/Vampirewal.Core/Components/VampirewalExportExcelService.cs
+++ /dev/null
@@ -1,256 +0,0 @@
-#region << 文 件 说 明 >>
-/*----------------------------------------------------------------
-// 文件名称:VampirewalExportExcelService
-// 创 建 者:杨程
-// 创建时间:2022/2/11 9:56:59
-// 文件版本:V1.0.0
-// ===============================================================
-// 功能描述:
-//
-//
-//----------------------------------------------------------------*/
-#endregion
-
-using NPOI.HSSF.UserModel;
-using NPOI.SS.UserModel;
-using NPOI.XSSF.UserModel;
-using System;
-using System.Collections.Generic;
-using System.Data;
-using System.IO;
-using System.Linq;
-using Vampirewal.Core.Interface;
-using Vampirewal.Core.Models;
-using Vampirewal.Core.Tools;
-
-namespace Vampirewal.Core.Components
-{
-
- ///
- /// Vampirewal操作Excel服务
- ///
- public sealed class VampirewalOperationExcelService : IOperationExcelService
- {
- ///
- /// 执行导出
- ///
- /// 实体类型
- /// 导出数据源
- ///
- public void ExportDataToExcel(List EntityList,string SaveFilePath, ExcelType excelType) where T : class, new()
- {
- try
- {
- if (EntityList == null)
- {
- throw new Exception("导出Excel文件的数据源不能为空!");
- }
-
- Type type = typeof(T);
-
- if (string.IsNullOrEmpty(SaveFilePath))
- {
- SaveFilePath=AppDomain.CurrentDomain.BaseDirectory;
- }
- //if (string.IsNullOrEmpty(SaveFileName))
- //{
- // throw new Exception("导出Excel文件的文件名称不能为空!");
- //}
-
- var dt = EntityList.ToDataTable();
-
- switch (excelType)
- {
- case ExcelType.xlsx:
- var sfn = type.Name + ".xlsx";
-
- SaveFilePath += sfn;
- break;
- case ExcelType.xls:
- var sfn2 = type.Name + ".xlsx";
-
- SaveFilePath += sfn2;
- break;
- }
-
- //NPOI
- IWorkbook workbook;
- string FileExt = Path.GetExtension(SaveFilePath).ToLower();
- if (FileExt == ".xlsx")
- {
- workbook = new XSSFWorkbook();
- }
- else if (FileExt == ".xls")
- {
- workbook = new HSSFWorkbook();
- }
- else
- {
- workbook = null;
- }
- if (workbook == null)
- {
- return;
- }
- //ISheet sheet = string.IsNullOrEmpty(SaveFileName) ? workbook.CreateSheet("Sheet1") : workbook.CreateSheet(SaveFileName);
- ISheet sheet = workbook.CreateSheet(type.Name);
-
-
- //读取标题
- IRow rowHeader = sheet.CreateRow(0);
- for (int i = 0; i < dt.Columns.Count; i++)
- {
- ICell cell = rowHeader.CreateCell(i);
- cell.SetCellValue(dt.Columns[i].ColumnName);
- }
-
- //读取数据
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- IRow rowData = sheet.CreateRow(i + 1);
- for (int j = 0; j < dt.Columns.Count; j++)
- {
- ICell cell = rowData.CreateCell(j);
- cell.SetCellValue(dt.Rows[i][j].ToString());
- }
- }
-
- //转为字节数组
- MemoryStream stream = new MemoryStream();
- workbook.Write(stream);
- var buf = stream.ToArray();
-
- //保存为Excel文件
- using (FileStream fs = new FileStream(SaveFilePath, FileMode.Create, FileAccess.Write))
- {
- fs.Write(buf, 0, buf.Length);
- fs.Flush();
- fs.Close();
- }
-
-
- }
- catch (Exception ex)
- {
- throw;
- }
- finally
- {
-
- }
-
-
- }
-
-
- ///
- /// 将excel中的数据导入到DataTable中
- ///
- /// 表名
- /// 第一行是否是DataTable的列名
- /// 文件完整路径
- /// 返回的DataTable
- public DataTable ExcelToDataTable(string sheetName, bool isFirstRowColumn, string FileFullPath)
- {
- //if (string.IsNullOrEmpty(sheetName))
- //{
- // throw new ArgumentNullException(sheetName);
- //}
- if (string.IsNullOrEmpty(FileFullPath))
- {
- throw new ArgumentNullException(FileFullPath);
- }
- var data = new DataTable();
- IWorkbook workbook = null;
- FileStream fs = null;
- try
- {
- fs = new FileStream(FileFullPath, FileMode.Open, FileAccess.Read);
- if (FileFullPath.IndexOf(".xlsx", StringComparison.Ordinal) > 0)
- {
- workbook = new XSSFWorkbook(fs);
- }
- else if (FileFullPath.IndexOf(".xls", StringComparison.Ordinal) > 0)
- {
- workbook = new HSSFWorkbook(fs);
- }
-
- ISheet sheet = null;
- if (workbook != null)
- {
- //如果没有找到指定的sheetName对应的sheet,则尝试获取第一个sheet
- sheet = workbook.GetSheet(sheetName) ?? workbook.GetSheetAt(0);
- }
- if (sheet == null) return data;
- var firstRow = sheet.GetRow(0);
- //一行最后一个cell的编号 即总的列数
- int cellCount = firstRow.LastCellNum;
- int startRow;
- if (isFirstRowColumn)
- {
- for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
- {
- var cell = firstRow.GetCell(i);
- var cellValue = cell.StringCellValue;
- if (cellValue == null) continue;
- var column = new DataColumn(cellValue);
- data.Columns.Add(column);
- }
- startRow = sheet.FirstRowNum + 1;
- }
- else
- {
- startRow = sheet.FirstRowNum;
- }
- //最后一列的标号
- var rowCount = sheet.LastRowNum;
- for (var i = startRow; i <= rowCount; ++i)
- {
- var row = sheet.GetRow(i);
- //没有数据的行默认是null
- if (row == null) continue;
- var dataRow = data.NewRow();
- for (int j = row.FirstCellNum; j < cellCount; ++j)
- {
- //同理,没有数据的单元格都默认是null
- if (row.GetCell(j) != null)
- dataRow[j] = row.GetCell(j).ToString();
- }
- data.Rows.Add(dataRow);
- }
-
- return data;
- }
- catch (IOException ioex)
- {
- throw new IOException(ioex.Message);
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- finally
- {
- if (fs != null)
- {
- fs.Close();
- }
- }
- }
-
-
- ///
- /// 导入EXCEL文件转成List
- ///
- ///
- /// 第一行是否是DataTable的列名
- /// 文件完整路径
- ///
- public List ExcelToList(bool isFirstRowColumn, string FileFullPath)
- {
- Type type = typeof(T);
-
- return ExcelToDataTable(type.Name, isFirstRowColumn, FileFullPath).ToList();
- }
- }
-}
diff --git a/Vampirewal.Core/Helper/PropertyHelper.cs b/Vampirewal.Core/Helper/PropertyHelper.cs
index ac5305c..2e2abb2 100644
--- a/Vampirewal.Core/Helper/PropertyHelper.cs
+++ b/Vampirewal.Core/Helper/PropertyHelper.cs
@@ -24,7 +24,7 @@ using System.Threading.Tasks;
using Microsoft.Extensions.Primitives;
using System.Windows.Controls;
using Vampirewal.Core.Extensions;
-using Microsoft.Extensions.Localization;
+//using Microsoft.Extensions.Localization; Microsoft.Extensions.Localization.Abstractions
namespace Vampirewal.Core.Helper
{
@@ -175,47 +175,47 @@ namespace Vampirewal.Core.Helper
return rv;
}
- ///
- /// 获取属性显示名称
- ///
- /// 属性信息
- ///
- /// 属性名称
- public static string GetPropertyDisplayName(this MemberInfo pi, IStringLocalizer local = null)
- {
- string rv = "";
- if (pi.GetCustomAttributes(typeof(DisplayAttribute), false).FirstOrDefault() is DisplayAttribute dis && !string.IsNullOrEmpty(dis.Name))
- {
- rv = dis.Name;
- if (local == null)
- {
- //if (CoreProgram._localizer != null)
- //{
- // rv = CoreProgram._localizer[rv];
- //}
- }
- else
- {
- rv = local[rv];
- }
- }
- else
- {
- rv = pi.Name;
- }
- return rv;
- }
-
- ///
- /// 获取属性显示名称
- ///
- /// 属性表达式
- ///
- /// 属性显示名称
- public static string GetPropertyDisplayName(this Expression expression, IStringLocalizer local = null)
- {
- return GetPropertyDisplayName(expression.GetPropertyInfo(), local);
- }
+ /////
+ ///// 获取属性显示名称
+ /////
+ ///// 属性信息
+ /////
+ ///// 属性名称
+ //public static string GetPropertyDisplayName(this MemberInfo pi, IStringLocalizer local = null)
+ //{
+ // string rv = "";
+ // if (pi.GetCustomAttributes(typeof(DisplayAttribute), false).FirstOrDefault() is DisplayAttribute dis && !string.IsNullOrEmpty(dis.Name))
+ // {
+ // rv = dis.Name;
+ // if (local == null)
+ // {
+ // //if (CoreProgram._localizer != null)
+ // //{
+ // // rv = CoreProgram._localizer[rv];
+ // //}
+ // }
+ // else
+ // {
+ // rv = local[rv];
+ // }
+ // }
+ // else
+ // {
+ // rv = pi.Name;
+ // }
+ // return rv;
+ //}
+
+ /////
+ ///// 获取属性显示名称
+ /////
+ ///// 属性表达式
+ /////
+ ///// 属性显示名称
+ //public static string GetPropertyDisplayName(this Expression expression, IStringLocalizer local = null)
+ //{
+ // return GetPropertyDisplayName(expression.GetPropertyInfo(), local);
+ //}
///
diff --git a/Vampirewal.Core/Interface/IDataContext.cs b/Vampirewal.Core/Interface/IDataContext.cs
index 411568a..971a39e 100644
--- a/Vampirewal.Core/Interface/IDataContext.cs
+++ b/Vampirewal.Core/Interface/IDataContext.cs
@@ -1,4 +1,4 @@
-using NPOI.POIFS.FileSystem;
+//using NPOI.POIFS.FileSystem;
using SqlSugar;
using System;
using System.Collections.Generic;
diff --git a/Vampirewal.Core/Interface/IOperationExcelService.cs b/Vampirewal.Core/Interface/IOperationExcelService.cs
deleted file mode 100644
index 108c897..0000000
--- a/Vampirewal.Core/Interface/IOperationExcelService.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Data;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Vampirewal.Core.Models;
-
-namespace Vampirewal.Core.Interface
-{
- ///
- /// 操作Excel服务接口
- ///
- ///
- public interface IOperationExcelService
- {
-
- /////
- ///// 保存Excel文件名
- /////
- //string SaveFileName { get; }
-
- /////
- ///// Excel文件保存地址
- /////
- //string SaveFilePath { get; }
-
- /////
- ///// Excel类型
- /////
- //ExcelType excelType { get; }
-
- /////
- ///// 设置
- /////
- ///// 设置保存文件的文件名
- ///// 设置保存文件的路径
- ///// 设置excel类型
- //void Setting(string saveFileName, string saveFilePath, ExcelType type);
-
- ///
- /// 执行导出
- ///
- /// 实体类型
- /// 导出数据源
- ///
- public void ExportDataToExcel(List EntityList, string SaveFilePath, ExcelType excelType) where T : class, new();
-
- ///
- /// 将excel中的数据导入到DataTable中
- ///
- /// /// 表名
- /// 第一行是否是DataTable的列名
- /// 文件完整路径
- /// 返回的DataTable
- DataTable ExcelToDataTable(string sheetName, bool isFirstRowColumn, string FileFullPath);
-
- ///
- /// 导入EXCEL文件转成List
- ///
- ///
- /// 第一行是否是DataTable的列名
- /// 文件完整路径
- ///
- List ExcelToList(bool isFirstRowColumn, string FileFullPath);
- }
-}
diff --git a/Vampirewal.Core/IoC/VampirewalIoC.cs b/Vampirewal.Core/IoC/VampirewalIoC.cs
new file mode 100644
index 0000000..a76a7e8
--- /dev/null
+++ b/Vampirewal.Core/IoC/VampirewalIoC.cs
@@ -0,0 +1,413 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:VampirewalIoC
+// 创 建 人:YangCheng
+// 创建时间:2022/6/10 15:44:03
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Vampirewal.Core.IoC
+{
+ ///
+ /// 注册类型
+ ///
+ public enum RegisterType
+ {
+ ///
+ /// 窗体
+ ///
+ Window,
+ ///
+ /// 页面
+ ///
+ View,
+ ///
+ /// VM
+ ///
+ ViewModel,
+ ///
+ /// 服务
+ ///
+ Service
+ }
+
+ ///
+ /// 注册进IoC
+ ///
+ [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
+ public class VampirewalIoCRegisterAttribute : Attribute
+ {
+ ///
+ /// 使用typeof(接口)
+ ///
+ public Type ServiceType { get; set; }
+
+ public string Token { get; set; }
+ public RegisterType RegisterType { get; set; }
+ ///
+ /// 是否注册单例模式(仅Way为OnlyClass有效)
+ ///
+ public bool IsSingleton { get; set; }
+
+ public VampirewalIoCRegisterAttribute(string token,RegisterType registerType,bool isSingleton=false)
+ {
+ Token = token;
+ RegisterType = registerType;
+ IsSingleton = isSingleton;
+ }
+ }
+
+ ///
+ ///
+ ///
+ public class VampirewalIoCGetInstanceAttribute : Attribute
+ {
+ public string Token { get; set; }
+ public VampirewalIoCGetInstanceAttribute(string token="")
+ {
+ Token = token;
+ }
+ }
+
+ ///
+ ///
+ ///
+ public class VampirewalIoC:BaseSingleton
+ {
+ Dictionary RegisteredServices { get; set; } = new Dictionary();
+ Dictionary instances { get; set; } = new Dictionary();
+
+ #region 注册
+ ///
+ /// 注册所有标记了特性的类
+ ///
+ public void RegisterAll()
+ {
+ /*
+ * 注意事项:
+ * 1、如果是WPF使用的话,建议把ViewModelLocator放在VM类库中
+ * 2、然后再调用这个,才能在初始化的时候,找到VM这个类库,然后加载里面的ViewModel,不然的话,找不到VM这个程序集,会无法加载ViewModel
+ */
+
+ var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()).Where(w => w.GetCustomAttribute() != null).ToArray();
+
+ foreach (var v in types)
+ {
+ var Attribute = v.GetCustomAttribute();
+
+ if (Attribute != null)
+ {
+ if ( Attribute.RegisterType==RegisterType.ViewModel)
+ {
+ if (Attribute.IsSingleton)
+ {
+ ConstructorInfo[] infoCollection = GatherConstructors(v);
+ this.instances.Add(v, ConstructService(v, infoCollection));
+ }
+ else
+ {
+ this.RegisteredServices.Add(v, v);
+ }
+ }
+ else if (Attribute.RegisterType == RegisterType.Service)
+ {
+ this.RegisteredServices.Add(Attribute.ServiceType, v);
+ }
+ else if(Attribute.RegisterType == RegisterType.Window || Attribute.RegisterType == RegisterType.View )
+ {
+ this.RegisteredServices.Add(v, v);
+ }
+ }
+
+ }
+ }
+
+
+ ///
+ /// 注册
+ ///
+ /// 接口
+ /// 实现
+ public void Register() where TInterface : class where TClass : class
+ {
+ if (!this.RegisteredServices.ContainsKey(typeof(TInterface)))
+ this.RegisteredServices.Add(typeof(TInterface), typeof(TClass));
+ else
+ throw new ArgumentException($"重复的Key值:{typeof(TInterface).Name}");
+ }
+
+ ///
+ /// 注册
+ ///
+ /// 接口
+ /// 实现
+ public void RegisterSingleton() where TInterface : class where TClass : class
+ {
+ if (!this.instances.ContainsKey(typeof(TInterface)))
+ {
+ ConstructorInfo[] infoCollection = GatherConstructors(typeof(TClass));
+ this.instances.Add(typeof(TInterface), ConstructService(typeof(TClass), infoCollection));
+ }
+
+ else
+ throw new ArgumentException($"重复的Key值:{typeof(TInterface).Name}");
+ }
+
+ ///
+ /// 注册
+ ///
+ ///
+ public void Register()
+ {
+ if (!this.RegisteredServices.ContainsKey(typeof(TClass)))
+ this.RegisteredServices.Add(typeof(TClass), typeof(TClass));
+ else
+ throw new ArgumentException($"重复的Key值:{typeof(TClass).Name}");
+ }
+
+ ///
+ /// 注册
+ ///
+ ///
+ ///
+ ///
+ public void Register(TClass @class)
+ {
+ if (!this.RegisteredServices.ContainsKey(typeof(TClass)))
+ this.RegisteredServices.Add(typeof(TClass), typeof(TClass));
+ else
+ throw new ArgumentException($"重复的Key值:{typeof(TClass).Name}");
+ }
+
+ ///
+ /// 注册单例模式
+ ///
+ ///
+ public void RegisterSingleton()
+ {
+ if (!this.instances.ContainsKey(typeof(TClass)))
+ {
+ ConstructorInfo[] infoCollection = GatherConstructors(typeof(TClass));
+ this.instances.Add(typeof(TClass), ConstructService(typeof(TClass), infoCollection));
+ }
+
+
+ else
+ throw new ArgumentException($"重复的Key值:{typeof(TClass).Name}");
+ }
+
+ ///
+ /// 注册单例模式
+ ///
+ ///
+ ///
+ public void RegisterSingleton(TClass instance) where TClass : class
+ {
+ if (!this.instances.ContainsKey(typeof(TClass)))
+ this.instances.Add(typeof(TClass), instance);
+ else
+ throw new ArgumentException($"重复的Key值:{typeof(TClass).Name}");
+ }
+ #endregion
+
+
+
+ #region 获取实例
+ ///
+ /// 获取实例
+ ///
+ /// 类型
+ ///
+ public T GetInstance() where T : class
+ {
+ return (T)this.GetInstance(typeof(T));
+ }
+
+ ///
+ /// 获取实例
+ ///
+ ///
+ ///
+ ///
+ public object GetInstance(Type type)
+ {
+
+ if (instances.TryGetValue(type, out object value))
+ {
+ return value;
+ }
+
+ if (RegisteredServices.TryGetValue(type, out Type implementation))
+ {
+ ConstructorInfo[] infoCollection = GatherConstructors(implementation);
+ return ConstructService(implementation, infoCollection);
+ }
+ throw new ArgumentException($"没有注册实现给定类型的服务: {type.ToString()}");
+ }
+
+ ///
+ /// 通过类名获取实例
+ ///
+ ///
+ ///
+ public object GetInstance(string token)
+ {
+ Type type = null;
+
+ type = instances.Keys.FirstOrDefault(f => f.Name == token);
+
+ if (type == null)
+ {
+ type = RegisteredServices.Keys.FirstOrDefault(f => f.Name == token);
+ }
+
+ if (type != null)
+ {
+ return GetInstance(type);
+ }
+
+ return type;
+ }
+
+ ///
+ /// 指定返回类型和类名获取实例
+ ///
+ ///
+ ///
+ ///
+ public T GetInstance(string ClassName)
+ {
+ return (T)this.GetInstance(ClassName);
+ }
+ #endregion
+
+ #region 内部方法
+ ///
+ /// 处理注入
+ ///
+ ///
+ ///
+ ///
+ ///
+ private object ConstructService(Type implementation, ConstructorInfo[] infoCollection)
+ {
+ for (int i = 0; i < infoCollection.Length; i++)
+ {
+ ConstructorInfo constructorInfo = infoCollection[i];
+ ParameterInfo[] parameters = constructorInfo.GetParameters();
+
+ if (parameters.Length == 0)
+ {
+ var obj = Activator.CreateInstance(implementation);
+
+ CheckPropertyDI(implementation, obj);
+ return obj;
+ }
+
+ try
+ {
+ List paramInstances = ResolveParameters(parameters);
+
+ var obj = Activator.CreateInstance(implementation, paramInstances.ToArray());
+
+ CheckPropertyDI(implementation, obj);
+ return obj;
+ }
+ catch
+ {
+ if (i < infoCollection.Length - 1)
+ {
+ continue;
+ }
+
+ throw;
+ }
+ }
+
+ throw new ArgumentException($"无法解决服务问题 {implementation.FullName}");
+ }
+
+ ///
+ /// 获取构造函数及构造函数的数量
+ ///
+ ///
+ ///
+ ///
+ private static ConstructorInfo[] GatherConstructors(Type implementation)
+ {
+ ConstructorInfo[] infoCollection = implementation.GetConstructors();
+
+ if (infoCollection.Length <= 0)
+ {
+ throw new ArgumentException($"在这个类型上没有找到公共构造函数: {implementation.FullName}");
+ }
+
+ return infoCollection;
+ }
+
+ ///
+ /// 获取这个构造函数里的参数并实例化出来
+ ///
+ ///
+ ///
+ private List ResolveParameters(ParameterInfo[] parameters)
+ {
+ var paramInstances = new List();
+ foreach (var par in parameters)
+ {
+ var paramType = par.ParameterType;
+ var instance = this.GetInstance(paramType);
+ paramInstances.Add(instance);
+ }
+
+ return paramInstances;
+ }
+
+ ///
+ /// 属性注入
+ ///
+ ///
+ ///
+ private void CheckPropertyDI(Type type, object obj)
+ {
+ var Properties = type.GetProperties().Where(w => w.GetCustomAttribute() != null).ToArray();
+
+ foreach (var item in Properties)
+ {
+ var Attribute = item.GetCustomAttribute();
+
+ if (!string.IsNullOrEmpty(Attribute.Token))
+ {
+ var entity = GetInstance(Attribute.Token);
+ item.SetValue(obj, entity);
+
+ continue;
+ }
+
+ Type cur;
+
+ cur = instances.Keys.FirstOrDefault(f => f.Name == item.PropertyType.Name);
+
+ if (cur == null)
+ {
+ cur = RegisteredServices.Keys.FirstOrDefault(f => f.Name == item.PropertyType.Name);
+ }
+
+ item.SetValue(obj, GetInstance(cur));
+ }
+ }
+ #endregion
+ }
+}
diff --git a/Vampirewal.Core/Models/BillBaseModel.cs b/Vampirewal.Core/Models/BillBaseModel.cs
index cfca4be..88bd6fa 100644
--- a/Vampirewal.Core/Models/BillBaseModel.cs
+++ b/Vampirewal.Core/Models/BillBaseModel.cs
@@ -38,7 +38,7 @@ namespace Vampirewal.Core.Models
/// Id
///
[SugarColumn(IsPrimaryKey = true,IsNullable =false, ColumnDescription = "主键")]
- [ExportExcel(propertyChineseName: "单据ID", propertyName: "BillId",IsCanExport =true)]
+ //[ExportExcel(propertyChineseName: "单据ID", propertyName: "BillId",IsCanExport =true)]
public string BillId
{
get
diff --git a/Vampirewal.Core/Models/DetailBaseModel.cs b/Vampirewal.Core/Models/DetailBaseModel.cs
index e06cd45..daa9c50 100644
--- a/Vampirewal.Core/Models/DetailBaseModel.cs
+++ b/Vampirewal.Core/Models/DetailBaseModel.cs
@@ -37,7 +37,7 @@ namespace Vampirewal.Core.Models
/// 明细ID
///
[SugarColumn(IsPrimaryKey =true,IsNullable =false, ColumnDescription = "主键")]
- [ExportExcel(propertyChineseName: "明细ID", propertyName: "DtlId", IsCanExport = true)]
+ //[ExportExcel(propertyChineseName: "明细ID", propertyName: "DtlId", IsCanExport = true)]
public string DtlId
{
get
@@ -61,7 +61,7 @@ namespace Vampirewal.Core.Models
/// 关联单据Id
///
[SugarColumn( IsNullable = false)]
- [ExportExcel(propertyChineseName: "单据ID", propertyName: "BillId", IsCanExport = true)]
+ //[ExportExcel(propertyChineseName: "单据ID", propertyName: "BillId", IsCanExport = true)]
public string BillId
{
get
diff --git a/Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs b/Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs
index be69e8d..a39aceb 100644
--- a/Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs
+++ b/Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs
@@ -11,7 +11,7 @@
//----------------------------------------------------------------*/
#endregion
-using NPOI.SS.Formula.Functions;
+//using NPOI.SS.Formula.Functions;
using SqlSugar;
using System;
using System.Collections.Generic;
@@ -41,10 +41,10 @@ namespace Vampirewal.Core.SimpleMVVM
/// 弹窗服务
///
protected IDialogMessage Dialog { get; set; }
- ///
- /// 导出excel服务
- ///
- protected IOperationExcelService ExportExcelService { get; set; }
+ /////
+ ///// 导出excel服务
+ /////
+ //protected IOperationExcelService ExportExcelService { get; set; }
///
diff --git a/Vampirewal.Core/SimpleMVVM/BillVM.cs b/Vampirewal.Core/SimpleMVVM/BillVM.cs
index c83cd5c..74529b1 100644
--- a/Vampirewal.Core/SimpleMVVM/BillVM.cs
+++ b/Vampirewal.Core/SimpleMVVM/BillVM.cs
@@ -11,8 +11,8 @@
//----------------------------------------------------------------*/
#endregion
-using NPOI.POIFS.NIO;
-using NPOI.SS.Formula.Functions;
+//using NPOI.POIFS.NIO;
+//using NPOI.SS.Formula.Functions;
using SqlSugar;
using System;
using System.Collections.Generic;
diff --git a/Vampirewal.Core/SimpleMVVM/VampirewalApplication.cs b/Vampirewal.Core/SimpleMVVM/VampirewalApplication.cs
index 64a4a04..d78b549 100644
--- a/Vampirewal.Core/SimpleMVVM/VampirewalApplication.cs
+++ b/Vampirewal.Core/SimpleMVVM/VampirewalApplication.cs
@@ -20,6 +20,7 @@ using System.Threading.Tasks;
using System.Windows;
using Vampirewal.Core.Components;
using Vampirewal.Core.Interface;
+using Vampirewal.Core.IoC;
namespace Vampirewal.Core.SimpleMVVM
{
@@ -40,16 +41,17 @@ namespace Vampirewal.Core.SimpleMVVM
if (string.IsNullOrEmpty(FirstWindowName()))
{
- throw new Exception("未设置 初始化系统首先打开的窗体名称 !");
+ throw new Exception("未设置 初始化系统首先打开的窗体 !");
}
else
{
#region 2022-6-9 add
-
-
- #endregion
+ //WindowsManager.GetInstance().RegisterAllWindows();
+ VampirewalIoC.GetInstance().RegisterAll();
+ Messenger.Default.RegistAll();
- WindowsManager.GetInstance().OpenWindow(FirstWindowName());
+ #endregion
+ VampirewalIoC.GetInstance().GetInstance(FirstWindowName()).Show();
}
this.DispatcherUnhandledException += GlobalExceptions;
@@ -85,12 +87,12 @@ namespace Vampirewal.Core.SimpleMVVM
///
protected abstract string FirstWindowName();
- ///
- /// 获取配置(必须是)
- /// 主要是获取,加载其他模块的dll
- ///
- ///
- protected abstract IAppConfig Config();
+ /////
+ ///// 获取配置(必须是)
+ ///// 主要是获取,加载其他模块的dll
+ /////
+ /////
+ //protected abstract IAppConfig Config();
#region 2022-6-9 注释
/////
diff --git a/Vampirewal.Core/SimpleMVVM/WindowsManager.cs b/Vampirewal.Core/SimpleMVVM/WindowsManager.cs
index 0024a7b..65d7956 100644
--- a/Vampirewal.Core/SimpleMVVM/WindowsManager.cs
+++ b/Vampirewal.Core/SimpleMVVM/WindowsManager.cs
@@ -368,28 +368,28 @@ namespace Vampirewal.Core.SimpleMVVM
///
public void RegisterAllWindows()
{
- if (AssemblyPaths.Count>0)
- {
- List ErrorStr = new List();
-
- AssemblyPaths.ForEach(f =>
- {
- try
- {
- Assembly ass = Assembly.LoadFile(f);
- }
- catch
- {
- ErrorStr.Add($"无法加载该dll-{f}");
- }
+ //if (AssemblyPaths.Count>0)
+ //{
+ // List ErrorStr = new List();
+
+ // AssemblyPaths.ForEach(f =>
+ // {
+ // try
+ // {
+ // Assembly ass = Assembly.LoadFile(f);
+ // }
+ // catch
+ // {
+ // ErrorStr.Add($"无法加载该dll-{f}");
+ // }
- });
+ // });
- if (ErrorStr.Count>0)
- {
- throw new Exception(string.Join(",", ErrorStr));
- }
- }
+ // if (ErrorStr.Count>0)
+ // {
+ // throw new Exception(string.Join(",", ErrorStr));
+ // }
+ //}
var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()).Where(w => w.GetCustomAttribute() != null).ToArray();
diff --git a/Vampirewal.Core/Tools/ListExtension.cs b/Vampirewal.Core/Tools/ListExtension.cs
index 8304c70..4d35178 100644
--- a/Vampirewal.Core/Tools/ListExtension.cs
+++ b/Vampirewal.Core/Tools/ListExtension.cs
@@ -63,126 +63,126 @@ namespace Vampirewal.Core.Tools
return OutSource;
}
- ///
- /// DataTable转List
- /// 仅适用于excel导入的数据,且对应实体类的属性上有特性
- ///
- ///
- ///
- ///
- ///
- public static List ToList(this DataTable dt)
- {
- var list = new List();
- var plist = new List(typeof(T).GetProperties());
- foreach (DataRow item in dt.Rows)
- {
- if (item.ItemArray[0] is DBNull)
- continue;
-
- T s = Activator.CreateInstance();
- for (int i = 0; i < dt.Columns.Count; i++)
- {
- //PropertyInfo info = plist.Find(p => p.Name == dt.Columns[i].ColumnName);
-
- PropertyInfo info = null;
-
- foreach (var Prop in plist)
- {
- var customAttributes = Prop.GetCustomAttributes(typeof(ExportExcelAttribute), false).ToList();
-
- foreach (var attribute in customAttributes)
- {
- if (attribute is ExportExcelAttribute export)
- {
- if (export.PropertyChineseName == dt.Columns[i].ColumnName)
- {
- info = Prop;
- continue;
- }
- }
- }
-
- if (info != null)
- {
- continue;
- }
- }
-
- if (info != null)
- {
- try
- {
- if (!Convert.IsDBNull(item[i]))
- {
- object v = null;
- if (info.PropertyType.ToString().Contains("System.Nullable"))
- {
- v = Convert.ChangeType(item[i], Nullable.GetUnderlyingType(info.PropertyType));
- }
- else if (info.PropertyType.IsEnum)
- {
- //int enumInt = Convert.ToInt32(item[i]);
-
- v = Enum.Parse(info.PropertyType, item[i].ToString());
- }
- else
- {
- v = Convert.ChangeType(item[i], info.PropertyType);
- }
-
- info.SetValue(s, v, null);
- }
- }
- catch (Exception ex)
- {
- throw new Exception("字段[" + info.Name + "]转换出错," + ex.Message);
- }
- }
- }
- list.Add(s);
- }
- return list;
- }
+ /////
+ ///// DataTable转List
+ ///// 仅适用于excel导入的数据,且对应实体类的属性上有特性
+ /////
+ /////
+ /////
+ /////
+ /////
+ //public static List ToList(this DataTable dt)
+ //{
+ // var list = new List();
+ // var plist = new List(typeof(T).GetProperties());
+ // foreach (DataRow item in dt.Rows)
+ // {
+ // if (item.ItemArray[0] is DBNull)
+ // continue;
+
+ // T s = Activator.CreateInstance();
+ // for (int i = 0; i < dt.Columns.Count; i++)
+ // {
+ // //PropertyInfo info = plist.Find(p => p.Name == dt.Columns[i].ColumnName);
+
+ // PropertyInfo info = null;
+
+ // foreach (var Prop in plist)
+ // {
+ // var customAttributes = Prop.GetCustomAttributes(typeof(ExportExcelAttribute), false).ToList();
+
+ // foreach (var attribute in customAttributes)
+ // {
+ // if (attribute is ExportExcelAttribute export)
+ // {
+ // if (export.PropertyChineseName == dt.Columns[i].ColumnName)
+ // {
+ // info = Prop;
+ // continue;
+ // }
+ // }
+ // }
+
+ // if (info != null)
+ // {
+ // continue;
+ // }
+ // }
+
+ // if (info != null)
+ // {
+ // try
+ // {
+ // if (!Convert.IsDBNull(item[i]))
+ // {
+ // object v = null;
+ // if (info.PropertyType.ToString().Contains("System.Nullable"))
+ // {
+ // v = Convert.ChangeType(item[i], Nullable.GetUnderlyingType(info.PropertyType));
+ // }
+ // else if (info.PropertyType.IsEnum)
+ // {
+ // //int enumInt = Convert.ToInt32(item[i]);
+
+ // v = Enum.Parse(info.PropertyType, item[i].ToString());
+ // }
+ // else
+ // {
+ // v = Convert.ChangeType(item[i], info.PropertyType);
+ // }
+
+ // info.SetValue(s, v, null);
+ // }
+ // }
+ // catch (Exception ex)
+ // {
+ // throw new Exception("字段[" + info.Name + "]转换出错," + ex.Message);
+ // }
+ // }
+ // }
+ // list.Add(s);
+ // }
+ // return list;
+ //}
///
/// List转DataTable
/// 仅适用于导出excel的数据,且对应实体类的属性上有特性
///
- public static DataTable ToDataTable(this List items)
- {
- var tb = new DataTable(typeof(T).Name);
+ //public static DataTable ToDataTable(this List items)
+ //{
+ // var tb = new DataTable(typeof(T).Name);
- PropertyInfo[] props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
+ // PropertyInfo[] props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
- var clone = props.Clone();
- var cur = new List();
+ // var clone = props.Clone();
+ // var cur = new List();
- foreach (var item in clone as PropertyInfo[])
- {
- var export= item.GetCustomAttribute();
+ // foreach (var item in clone as PropertyInfo[])
+ // {
+ // var export= item.GetCustomAttribute();
- if (export!=null&&export.IsCanExport)
- {
- tb.Columns.Add(export.PropertyChineseName, item.PropertyType);
- cur.Add(item);
- }
- }
+ // if (export!=null&&export.IsCanExport)
+ // {
+ // tb.Columns.Add(export.PropertyChineseName, item.PropertyType);
+ // cur.Add(item);
+ // }
+ // }
- foreach (T item in items)
- {
- var values = new object[cur.Count];
+ // foreach (T item in items)
+ // {
+ // var values = new object[cur.Count];
- for (int i = 0; i < cur.Count; i++)
- {
- values[i] = cur[i].GetValue(item, null);
- }
+ // for (int i = 0; i < cur.Count; i++)
+ // {
+ // values[i] = cur[i].GetValue(item, null);
+ // }
- tb.Rows.Add(values);
- }
+ // tb.Rows.Add(values);
+ // }
- return tb;
- }
+ // return tb;
+ //}
///
/// Determine of specified type is nullable
diff --git a/Vampirewal.Core/Tools/Utils.cs b/Vampirewal.Core/Tools/Utils.cs
index 5658822..a8f2d68 100644
--- a/Vampirewal.Core/Tools/Utils.cs
+++ b/Vampirewal.Core/Tools/Utils.cs
@@ -26,7 +26,7 @@ using System.Threading.Tasks;
//using Microsoft.Extensions.Caching.Distributed;
using Vampirewal.Core.Interface;
using Vampirewal.Core.Models;
-using NPOI.HSSF.Util;
+//using NPOI.HSSF.Util;
namespace Vampirewal.Core
{
@@ -166,49 +166,49 @@ namespace Vampirewal.Core
ToAdd = tempToAdd.AsEnumerable();
}
- public static short GetExcelColor(string color)
- {
- var colors = typeof(HSSFColor).GetNestedTypes().ToList();
- foreach (var col in colors)
- {
- var pro = col.GetField("hexString");
- if (pro == null)
- {
- continue;
- }
- var hex = pro.GetValue(null);
- var rgb = hex.ToString().Split(':');
- for (int i = 0; i < rgb.Length; i++)
- {
- if (rgb[i].Length > 2)
- {
- rgb[i] = rgb[i].Substring(0, 2);
- }
- }
- int r = Convert.ToInt16(rgb[0], 16);
- int g = Convert.ToInt16(rgb[1], 16);
- int b = Convert.ToInt16(rgb[2], 16);
+ //public static short GetExcelColor(string color)
+ //{
+ // var colors = typeof(HSSFColor).GetNestedTypes().ToList();
+ // foreach (var col in colors)
+ // {
+ // var pro = col.GetField("hexString");
+ // if (pro == null)
+ // {
+ // continue;
+ // }
+ // var hex = pro.GetValue(null);
+ // var rgb = hex.ToString().Split(':');
+ // for (int i = 0; i < rgb.Length; i++)
+ // {
+ // if (rgb[i].Length > 2)
+ // {
+ // rgb[i] = rgb[i].Substring(0, 2);
+ // }
+ // }
+ // int r = Convert.ToInt16(rgb[0], 16);
+ // int g = Convert.ToInt16(rgb[1], 16);
+ // int b = Convert.ToInt16(rgb[2], 16);
- if (color.Length == 8)
- {
- color = color.Substring(2);
- }
- string c1 = color.Substring(0, 2);
- string c2 = color.Substring(2, 2);
- string c3 = color.Substring(4, 2);
+ // if (color.Length == 8)
+ // {
+ // color = color.Substring(2);
+ // }
+ // string c1 = color.Substring(0, 2);
+ // string c2 = color.Substring(2, 2);
+ // string c3 = color.Substring(4, 2);
- int r1 = Convert.ToInt16(c1, 16);
- int g1 = Convert.ToInt16(c2, 16);
- int b1 = Convert.ToInt16(c3, 16);
+ // int r1 = Convert.ToInt16(c1, 16);
+ // int g1 = Convert.ToInt16(c2, 16);
+ // int b1 = Convert.ToInt16(c3, 16);
- if (r == r1 && g == g1 && b == b1)
- {
- return (short)col.GetField("index").GetValue(null);
- }
- }
- return HSSFColor.COLOR_NORMAL;
- }
+ // if (r == r1 && g == g1 && b == b1)
+ // {
+ // return (short)col.GetField("index").GetValue(null);
+ // }
+ // }
+ // return HSSFColor.COLOR_NORMAL;
+ //}
/////
///// 获取Bool类型的下拉框
diff --git a/Vampirewal.Core/Vampirewal.Core.csproj b/Vampirewal.Core/Vampirewal.Core.csproj
index 9990567..a4ec6c4 100644
--- a/Vampirewal.Core/Vampirewal.Core.csproj
+++ b/Vampirewal.Core/Vampirewal.Core.csproj
@@ -24,6 +24,12 @@
embedded
+
+
+
+
+
+
@@ -31,6 +37,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
True
@@ -45,27 +74,14 @@
-
-
-
- $(DefaultXamlRuntime)
- Designer
-
-
- $(DefaultXamlRuntime)
- Designer
-
-
- $(DefaultXamlRuntime)
- Designer
-
+
diff --git a/Vampirewal.Core/WpfTheme/UcView/UcViewBase.cs b/Vampirewal.Core/WpfTheme/UcView/UcViewBase.cs
index 34b8d39..5140a74 100644
--- a/Vampirewal.Core/WpfTheme/UcView/UcViewBase.cs
+++ b/Vampirewal.Core/WpfTheme/UcView/UcViewBase.cs
@@ -18,6 +18,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
+using Vampirewal.Core.SimpleMVVM;
using Vampirewal.Core.WpfTheme.WindowStyle;
namespace Vampirewal.Core.WpfTheme.UcView
@@ -32,6 +33,26 @@ namespace Vampirewal.Core.WpfTheme.UcView
public UcViewBase()
{
//构造函数
+
+ this.IsVisibleChanged += UcViewBase_IsVisibleChanged;
+ this.Loaded += UcViewBase_Loaded;
+ }
+
+ protected virtual void UcViewBase_Loaded(object sender, RoutedEventArgs e)
+ {
+
+ }
+
+ private void UcViewBase_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
+ {
+ if ((bool)e.NewValue)
+ {
+ if (DataSource != null)
+ {
+ DataSource.View = Window.GetWindow(this);
+ SetValue(FrameworkElement.DataContextProperty, DataSource);
+ }
+ }
}
#region 属性
@@ -56,9 +77,14 @@ namespace Vampirewal.Core.WpfTheme.UcView
return new ResourceDictionary() { Source = new Uri("pack://application:,,,/Vampirewal.Core;component/WpfTheme/CoreTheme.xaml", UriKind.RelativeOrAbsolute) };
}
}
+
+ ///
+ /// 数据上下文
+ ///
+ public virtual ViewModelBase DataSource { get; set; }
#endregion
-
+
#region 依赖属性
diff --git a/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml b/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml
index fab3808..263c133 100644
--- a/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml
+++ b/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml
@@ -9,7 +9,7 @@
Title="{Binding Title}"
Width="800"
Height="450"
- Background="#2F3437"
+ Background="#2F3437"
Foreground="#EBEBEB"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d">
diff --git a/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml.cs b/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml.cs
index c15f392..e571cbd 100644
--- a/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml.cs
+++ b/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml.cs
@@ -12,6 +12,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Vampirewal.Core.SimpleMVVM;
+using Vampirewal.Core.WpfTheme.UcView;
namespace Vampirewal.Core.WpfTheme.WindowStyle
{
@@ -42,16 +43,26 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
UcView.Content = Setting.UiView;
-
+
+ var UcBase = Setting.UiView as UcViewBase;
Setting.UiView.Width = double.NaN;
Setting.UiView.Height = double.NaN;
-
- this.DataContext = Setting.UiView.DataContext;
+ if (UcBase.DataContext==null)
+ {
+ this.DataContext = UcBase.DataSource;
+ this.DataSource= UcBase.DataSource;
+ UcBase.DataContext= UcBase.DataSource;
+ }
+ else
+ {
+ this.DataContext = Setting.UiView.DataContext;
+ }
+
ViewModelBase vm = Setting.UiView.DataContext as ViewModelBase;
- vm.View = this;
-
+ //vm.View = this;
+
vm.PassData(Setting.PassData);
if (!string.IsNullOrEmpty(Setting.IconStr))
diff --git a/Vampirewal.Core/WpfTheme/WindowStyle/WindowBase.cs b/Vampirewal.Core/WpfTheme/WindowStyle/WindowBase.cs
index 485e930..49853f5 100644
--- a/Vampirewal.Core/WpfTheme/WindowStyle/WindowBase.cs
+++ b/Vampirewal.Core/WpfTheme/WindowStyle/WindowBase.cs
@@ -45,10 +45,10 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
///
public List BottomCustomAreas { get; set; } = new List();
- /////
- ///// 数据上下文
- /////
- //public virtual ViewModelBase DataSource { get; set; }
+ ///
+ /// 数据上下文
+ ///
+ public virtual ViewModelBase DataSource { get; set; }
///
/// 窗体ID
@@ -82,19 +82,33 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
this.Style = BaseStyle;
-
+ this.IsVisibleChanged += WindowBase_IsVisibleChanged;
}
- protected virtual void Window_Loaded(object sender, RoutedEventArgs e)
+ private void WindowBase_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
- ViewModelBase vm = this.DataContext as ViewModelBase;
- if (vm != null)
+ if ((bool)e.NewValue)
{
- vm.View = this;
- //WindowsManager.RegisterWindow(this);
+ if (DataSource != null)
+ {
+ DataSource.View = Window.GetWindow(this);
+ SetValue(FrameworkElement.DataContextProperty, DataSource);
+ }
+
+
}
}
+ protected virtual void Window_Loaded(object sender, RoutedEventArgs e)
+ {
+ //ViewModelBase vm = this.DataContext as ViewModelBase;
+ //if (vm != null)
+ //{
+ // vm.View = this;
+
+ //}
+ }
+
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
@@ -183,8 +197,8 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
{
CloseWindowCommand?.Execute(CloseWindowCommandParameter);
- WindowsManager.GetInstance().CloseWindow(this);
- //this.Close();
+ //WindowsManager.GetInstance().CloseWindow(this);
+ this.Close();
}
//protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
//{
diff --git a/YC.WPF.Theme/AdditionalAttributes/TextBox/TextBoxAttach.cs b/YC.WPF.Theme/AdditionalAttributes/TextBox/TextBoxAttach.cs
new file mode 100644
index 0000000..db2a3c6
--- /dev/null
+++ b/YC.WPF.Theme/AdditionalAttributes/TextBox/TextBoxAttach.cs
@@ -0,0 +1,168 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:TextBoxAttach
+// 创 建 者:杨程
+// 创建时间:2021/10/14 10:22:07
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+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.Media;
+
+namespace Vampirewal.Core.WPF.Theme.AdditionalAttributes
+{
+ ///
+ /// 文本框附加属性
+ ///
+ public class TextBoxAttach : DependencyObject
+ {
+ #region FocusBorderBrush 焦点边框色,输入控件
+
+ public static readonly DependencyProperty FocusBorderBrushProperty = DependencyProperty.RegisterAttached(
+ "FocusBorderBrush", typeof(Brush), typeof(TextBoxAttach), new FrameworkPropertyMetadata(null));
+ public static void SetFocusBorderBrush(DependencyObject element, Brush value)
+ {
+ element.SetValue(FocusBorderBrushProperty, value);
+ }
+ public static Brush GetFocusBorderBrush(DependencyObject element)
+ {
+ return (Brush)element.GetValue(FocusBorderBrushProperty);
+ }
+
+ #endregion
+
+ #region MouseOverBorderBrush 鼠标进入边框色,输入控件
+
+ public static readonly DependencyProperty MouseOverBorderBrushProperty =
+ DependencyProperty.RegisterAttached("MouseOverBorderBrush", typeof(Brush), typeof(TextBoxAttach),
+ new FrameworkPropertyMetadata(Brushes.Transparent,
+ FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits));
+
+ ///
+ /// Sets the brush used to draw the mouse over brush.
+ ///
+ public static void SetMouseOverBorderBrush(DependencyObject obj, Brush value)
+ {
+ obj.SetValue(MouseOverBorderBrushProperty, value);
+ }
+
+ ///
+ /// Gets the brush used to draw the mouse over brush.
+ ///
+ [AttachedPropertyBrowsableForType(typeof(TextBox))]
+ [AttachedPropertyBrowsableForType(typeof(CheckBox))]
+ [AttachedPropertyBrowsableForType(typeof(RadioButton))]
+ [AttachedPropertyBrowsableForType(typeof(DatePicker))]
+ [AttachedPropertyBrowsableForType(typeof(ComboBox))]
+ [AttachedPropertyBrowsableForType(typeof(RichTextBox))]
+ public static Brush GetMouseOverBorderBrush(DependencyObject obj)
+ {
+ return (Brush)obj.GetValue(MouseOverBorderBrushProperty);
+ }
+
+ #endregion
+
+ #region AttachContentProperty 附加组件模板
+ ///
+ /// 附加组件模板
+ ///
+ public static readonly DependencyProperty AttachContentProperty = DependencyProperty.RegisterAttached(
+ "AttachContent", typeof(ControlTemplate), typeof(TextBoxAttach), new FrameworkPropertyMetadata(null));
+
+ public static ControlTemplate GetAttachContent(DependencyObject d)
+ {
+ return (ControlTemplate)d.GetValue(AttachContentProperty);
+ }
+
+ public static void SetAttachContent(DependencyObject obj, ControlTemplate value)
+ {
+ obj.SetValue(AttachContentProperty, value);
+ }
+ #endregion
+
+ #region WatermarkProperty 水印
+ ///
+ /// 水印
+ ///
+ public static readonly DependencyProperty WatermarkProperty = DependencyProperty.RegisterAttached(
+ "Watermark", typeof(string), typeof(TextBoxAttach), new FrameworkPropertyMetadata(""));
+
+ public static string GetWatermark(DependencyObject d)
+ {
+ return (string)d.GetValue(WatermarkProperty);
+ }
+
+ public static void SetWatermark(DependencyObject obj, string value)
+ {
+ obj.SetValue(WatermarkProperty, value);
+ }
+ #endregion
+
+ #region CornerRadiusProperty Border圆角
+ ///
+ /// Border圆角
+ ///
+ public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.RegisterAttached(
+ "CornerRadius", typeof(CornerRadius), typeof(TextBoxAttach), new FrameworkPropertyMetadata(null));
+
+ public static CornerRadius GetCornerRadius(DependencyObject d)
+ {
+ return (CornerRadius)d.GetValue(CornerRadiusProperty);
+ }
+
+ public static void SetCornerRadius(DependencyObject obj, CornerRadius value)
+ {
+ obj.SetValue(CornerRadiusProperty, value);
+ }
+ #endregion
+
+ #region LabelProperty TextBox的头部Label
+ ///
+ /// TextBox的头部Label
+ ///
+ public static readonly DependencyProperty LabelProperty = DependencyProperty.RegisterAttached(
+ "Label", typeof(string), typeof(TextBoxAttach), new FrameworkPropertyMetadata(null));
+
+ [AttachedPropertyBrowsableForType(typeof(TextBox))]
+ public static string GetLabel(DependencyObject d)
+ {
+ return (string)d.GetValue(LabelProperty);
+ }
+
+ public static void SetLabel(DependencyObject obj, string value)
+ {
+ obj.SetValue(LabelProperty, value);
+ }
+ #endregion
+
+ #region LabelTemplateProperty TextBox的头部Label模板
+ ///
+ /// TextBox的头部Label模板
+ ///
+ public static readonly DependencyProperty LabelTemplateProperty = DependencyProperty.RegisterAttached(
+ "LabelTemplate", typeof(ControlTemplate), typeof(TextBoxAttach), new FrameworkPropertyMetadata(null));
+
+ [AttachedPropertyBrowsableForType(typeof(TextBox))]
+ public static ControlTemplate GetLabelTemplate(DependencyObject d)
+ {
+ return (ControlTemplate)d.GetValue(LabelTemplateProperty);
+ }
+
+ public static void SetLabelTemplate(DependencyObject obj, ControlTemplate value)
+ {
+ obj.SetValue(LabelTemplateProperty, value);
+ }
+ #endregion
+ }
+}
diff --git a/YC.WPF.Theme/Behaviors/DataGridBehavior.cs b/YC.WPF.Theme/Behaviors/DataGridBehavior.cs
index 0f08b6e..d0ba499 100644
--- a/YC.WPF.Theme/Behaviors/DataGridBehavior.cs
+++ b/YC.WPF.Theme/Behaviors/DataGridBehavior.cs
@@ -24,7 +24,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
-using Vampirewal.Core.WpfTheme.CustomControl;
+using Vampirewal.Core.WPF.Theme.CustomControl;
namespace Vampirewal.Core.WPF.Theme.Behaviors
{
diff --git a/YC.WPF.Theme/Converter/DataContextConverter.cs b/YC.WPF.Theme/Converter/DataContextConverter.cs
new file mode 100644
index 0000000..d6faa36
--- /dev/null
+++ b/YC.WPF.Theme/Converter/DataContextConverter.cs
@@ -0,0 +1,44 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:DataContextConverter
+// 创 建 人:YangCheng
+// 创建时间:2022/5/23 15:23:05
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Data;
+
+namespace Vampirewal.Core.WpfTheme.Converter
+{
+ ///
+ ///
+ ///
+ public class DataContextConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value == null)
+ return default;
+
+ string VmName = parameter.ToString();
+
+ return "";
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/YC.WPF.Theme/CustomControl/DataGrid/DataGridStyles.xaml b/YC.WPF.Theme/CustomControl/DataGrid/DataGridStyles.xaml
new file mode 100644
index 0000000..371bd33
--- /dev/null
+++ b/YC.WPF.Theme/CustomControl/DataGrid/DataGridStyles.xaml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/YC.WPF.Theme/CustomControl/NumTextBox/NumTextBox.cs b/YC.WPF.Theme/CustomControl/NumTextBox/NumTextBox.cs
new file mode 100644
index 0000000..b8e94a3
--- /dev/null
+++ b/YC.WPF.Theme/CustomControl/NumTextBox/NumTextBox.cs
@@ -0,0 +1,45 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:NumTextBox
+// 创 建 者:杨程
+// 创建时间:2022/1/10 17:23:35
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+
+namespace Vampirewal.Core.WPF.Theme.CustomControl
+{
+ public class NumTextBox:TextBox
+ {
+ private ResourceDictionary res
+ {
+ get
+ {
+ return new ResourceDictionary() { Source = new Uri("pack://application:,,,/Vampirewal.Core;component/WpfTheme/CoreTheme.xaml", UriKind.RelativeOrAbsolute) };
+ }
+ }
+
+ public NumTextBox()
+ {
+ //构造函数
+
+ var BaseStyle = res["NumTextBoxStyle"] as Style;
+
+ this.Style = BaseStyle;
+ }
+
+
+ }
+}
diff --git a/YC.WPF.Theme/CustomControl/NumTextBox/NumTextBoxStyle.xaml b/YC.WPF.Theme/CustomControl/NumTextBox/NumTextBoxStyle.xaml
new file mode 100644
index 0000000..920cb36
--- /dev/null
+++ b/YC.WPF.Theme/CustomControl/NumTextBox/NumTextBoxStyle.xaml
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/YC.WPF.Theme/CustomControl/Pagination/VPagination.cs b/YC.WPF.Theme/CustomControl/Pagination/VPagination.cs
new file mode 100644
index 0000000..0231e41
--- /dev/null
+++ b/YC.WPF.Theme/CustomControl/Pagination/VPagination.cs
@@ -0,0 +1,716 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:VPagination
+// 创 建 者:杨程
+// 创建时间:2021/12/8 9:50:21
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Media;
+using System.Windows;
+using System.Windows.Controls;
+using System.ComponentModel;
+using Vampirewal.Core.WpfTheme.WindowStyle;
+
+namespace Vampirewal.Core.WPF.Theme.CustomControl
+{
+ [TemplatePart(Name = "PART_ComboBox", Type = typeof(ComboBox))]
+ [TemplatePart(Name = "PART_ButtonFirstPage", Type = typeof(Button))]
+ [TemplatePart(Name = "PART_ButtonPrePage", Type = typeof(Button))]
+ [TemplatePart(Name = "PART_ListBoxPages", Type = typeof(ListBox))]
+ [TemplatePart(Name = "PART_ButtonNextPage", Type = typeof(Button))]
+ [TemplatePart(Name = "PART_ButtonLastPage", Type = typeof(Button))]
+ [TemplatePart(Name = "PART_PageInfo", Type = typeof(Panel))]
+ public class VPagination:Control
+ {
+ public static event PropertyChangedEventHandler PropertyChanged;
+
+ #region 是否显示每页数据量选择控件
+ ///
+ /// 是否显示每页数据量选择控件
+ ///
+ public bool IsShowPageDataCountSelector
+ {
+ get { return (bool)GetValue(IsShowPageDataCountSelectorProperty); }
+ set { SetValue(IsShowPageDataCountSelectorProperty, value); }
+ }
+
+ ///
+ /// 是否显示每页数据量选择控件
+ ///
+ public static readonly DependencyProperty IsShowPageDataCountSelectorProperty =
+ DependencyProperty.Register("IsShowPageDataCountSelector", typeof(bool), typeof(VPagination), new PropertyMetadata(true, null));
+ #endregion
+
+ #region 可选择的每页显示的数据条数集合
+ ///
+ /// 可选择的每页显示的数据条数集合
+ ///
+ public ObservableCollection PageDataCountCollection
+ {
+ get { return (ObservableCollection)GetValue(PageDataCountCollectionProperty); }
+ set { SetValue(PageDataCountCollectionProperty, value); }
+ }
+
+ ///
+ /// 可选择的每页显示的数据条数集合
+ ///
+ public static readonly DependencyProperty PageDataCountCollectionProperty = DependencyProperty.Register("PageDataCountCollection", typeof(ObservableCollection), typeof(VPagination),
+ new PropertyMetadata(new ObservableCollection { 20, 30, 50 }, null));
+ #endregion
+
+ #region 每页最多显示的数据条数
+ ///
+ /// 每页最多显示的数据条数
+ ///
+ public int PageDataCount
+ {
+ get { return (int)GetValue(PageDataCountProperty); }
+ set { SetValue(PageDataCountProperty, value); }
+ }
+ ///
+ /// 每页最多显示的数据条数
+ ///
+ public static readonly DependencyProperty PageDataCountProperty = DependencyProperty.Register("PageDataCount", typeof(int), typeof(VPagination),
+ new PropertyMetadata(20, OnPageDataCountPropertyChanged));
+
+ ///
+ /// 每页显示的最大数据量发生改变时的回调方法
+ ///
+ ///
+ ///
+ private static void OnPageDataCountPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ VPagination pagination = d as VPagination;
+ if (pagination == null)
+ {
+ return;
+ }
+
+ pagination.InitData();
+ }
+ #endregion
+
+ #region 当前显示的可供选择的分页号集合
+ ///
+ /// 当前显示的可供选择的分页号集合
+ ///
+ public ObservableCollection ShowingPageNumberCollection
+ {
+ get { return (ObservableCollection)GetValue(ShowingPageNumberCollectionProperty); }
+ set { SetValue(ShowingPageNumberCollectionProperty, value); }
+ }
+ ///
+ /// 当前显示的可供选择的分页号集合
+ ///
+ public static readonly DependencyProperty ShowingPageNumberCollectionProperty = DependencyProperty.Register("ShowingPageNumberCollection", typeof(ObservableCollection), typeof(VPagination),
+ new PropertyMetadata(null, null));
+ #endregion
+
+ #region 当前选择的页数
+ ///
+ /// 当前选择的页数
+ ///
+ public int CurrentPageNumber
+ {
+ get { return (int)GetValue(CurrentPageNumberProperty); }
+ set { SetValue(CurrentPageNumberProperty, value); }
+ }
+ ///
+ /// 当前选择的页数
+ ///
+ public static readonly DependencyProperty CurrentPageNumberProperty = DependencyProperty.Register("CurrentPageNumber", typeof(int), typeof(VPagination),
+ new PropertyMetadata(1, OnCurrentPageNumberChanged));
+
+ ///
+ /// 当前选择的页数发生改变时的回调方法
+ ///
+ ///
+ ///
+ private static void OnCurrentPageNumberChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ VPagination pagination = d as VPagination;
+ if (pagination == null)
+ {
+ return;
+ }
+
+ if (pagination._lstShowingPage != null)
+ {
+ pagination._lstShowingPage.SelectedItem = e.NewValue;
+ }
+
+ pagination.SetBtnEnable();
+ //PropertyChanged(d, new PropertyChangedEventArgs(e.Property.Name));
+ PropertyChanged?.Invoke(d, new PropertyChangedEventArgs(e.Property.Name));
+ }
+ #endregion
+
+ #region 是否显示分页信息
+ ///
+ /// 是否显示分页信息
+ ///
+ public bool IsShowPageInfo
+ {
+ get { return (bool)GetValue(IsShowPageInfoProperty); }
+ set { SetValue(IsShowPageInfoProperty, value); }
+ }
+ ///
+ /// 是否显示分页信息
+ ///
+ public static readonly DependencyProperty IsShowPageInfoProperty = DependencyProperty.Register("IsShowPageInfo", typeof(bool), typeof(VPagination),
+ new PropertyMetadata(true, null));
+ #endregion
+
+ #region 总的数据量
+ ///
+ /// 总的数据量
+ ///
+ public int TotalDataCount
+ {
+ get { return (int)GetValue(TotalDataCountProperty); }
+ set { SetValue(TotalDataCountProperty, value); }
+ }
+ ///
+ /// 总的数据量
+ ///
+ public static readonly DependencyProperty TotalDataCountProperty = DependencyProperty.Register("TotalDataCount", typeof(int), typeof(VPagination),
+ new PropertyMetadata(0, null));
+ #endregion
+
+ #region 当前页显示的数据条数
+ ///
+ /// 当前页显示的数据条数
+ ///
+ public int CurrentPageDataCount
+ {
+ get { return (int)GetValue(CurrentPageDataCountProperty); }
+ set { SetValue(CurrentPageDataCountProperty, value); }
+ }
+ ///
+ /// 当前页显示的数据条数
+ ///
+ public static readonly DependencyProperty CurrentPageDataCountProperty = DependencyProperty.Register("CurrentPageDataCount", typeof(int), typeof(VPagination),
+ new PropertyMetadata(0, null));
+ #endregion
+
+ #region 总页数
+ ///
+ /// 总页数
+ ///
+ public int TotalPageCount
+ {
+ get { return (int)GetValue(TotalPageCountProperty); }
+ set { SetValue(TotalPageCountProperty, value); }
+ }
+ ///
+ /// 总页数
+ ///
+ public static readonly DependencyProperty TotalPageCountProperty = DependencyProperty.Register("TotalPageCount", typeof(int), typeof(VPagination),
+ new PropertyMetadata(1, null));
+ #endregion
+
+ #region 当前显示页的数据起始编号
+ ///
+ /// 当前显示页的数据起始编号
+ ///
+ public int ShowingPageDataStartNumber
+ {
+ get { return (int)GetValue(ShowingPageDataStartNumberProperty); }
+ set { SetValue(ShowingPageDataStartNumberProperty, value); }
+ }
+ ///
+ /// 当前显示页的数据起始编号
+ ///
+ public static readonly DependencyProperty ShowingPageDataStartNumberProperty = DependencyProperty.Register("ShowingPageDataStartNumber", typeof(int), typeof(VPagination),
+ new PropertyMetadata(0, null));
+ #endregion
+
+ #region 当前显示页的数据结束编号
+ ///
+ /// 当前显示页的数据结束编号
+ ///
+ public int ShowingPageDataEndNumber
+ {
+ get { return (int)GetValue(ShowingPageDataEndNumberProperty); }
+ set { SetValue(ShowingPageDataEndNumberProperty, value); }
+ }
+ ///
+ /// 当前显示页的数据结束编号
+ ///
+ public static readonly DependencyProperty ShowingPageDataEndNumberProperty = DependencyProperty.Register("ShowingPageDataEndNumber", typeof(int), typeof(VPagination),
+ new PropertyMetadata(0, null));
+ #endregion
+
+ #region 显示的可选择页的最大数量
+ ///
+ /// 显示的可选择页的最大数量
+ ///
+ public int MaxShownPageCount
+ {
+ get { return (int)GetValue(MaxShownPageCountProperty); }
+ set { SetValue(MaxShownPageCountProperty, value); }
+ }
+ ///
+ /// 显示的可选择页的最大数量
+ ///
+ public static readonly DependencyProperty MaxShownPageCountProperty = DependencyProperty.Register("MaxShownPageCount", typeof(int), typeof(VPagination),
+ new PropertyMetadata(7, null));
+ #endregion
+
+ #region 选中页的背景色
+ ///
+ /// 选中页的背景色
+ ///
+ public Brush SelectedPageBackground
+ {
+ get { return (Brush)GetValue(MaxShownPageCountProperty); }
+ set { SetValue(MaxShownPageCountProperty, value); }
+ }
+ ///
+ /// 选中页的背景色
+ ///
+ public static readonly DependencyProperty SelectedPageBackgroundProperty = DependencyProperty.Register("SelectedPageBackground", typeof(Brush), typeof(VPagination),
+ new PropertyMetadata(new SolidColorBrush(Colors.Red), null));
+ #endregion
+
+ #region 未选择的页码的背景色
+ ///
+ /// 未选择的页码的背景色
+ ///
+ public Brush PageSelectorBackground
+ {
+ get { return (Brush)GetValue(PageSelectorBackgroundProperty); }
+ set { SetValue(PageSelectorBackgroundProperty, value); }
+ }
+ ///
+ /// 未选择的页码的背景色
+ ///
+ public static readonly DependencyProperty PageSelectorBackgroundProperty = DependencyProperty.Register("PageSelectorBackground", typeof(Brush), typeof(VPagination),
+ new PropertyMetadata(null, null));
+ #endregion
+
+ //private ResourceDictionary res
+ //{
+ // get
+ // {
+ // return new ResourceDictionary() { Source = new Uri("pack://application:,,,/Vampirewal.Core;component/WpfTheme/CoreTheme.xaml", UriKind.RelativeOrAbsolute) };
+ // }
+ //}
+
+ public override void OnApplyTemplate()
+ {
+ base.OnApplyTemplate();
+
+ //var VPaginationStyle = res["VPaginationStyle"] as Style;
+
+ //this.Style = VPaginationStyle;
+
+ //初始化控件
+ InitControls();
+
+ //初始化数据
+ ShowingPageNumberCollection = new ObservableCollection();
+ InitData();
+ }
+
+ private ComboBox _cbbPageDataCount { get; set; }
+
+ private ListBox _lstShowingPage { get; set; }
+
+ private Button _btnFirstPage { get; set; }
+
+ private Button _btnPrePage { get; set; }
+
+ private Button _btnNextPage { get; set; }
+
+ private Button _btnLastPage { get; set; }
+
+ private bool _isIgnoreListBoxSelectionChanged { get; set; }
+
+ private static object _lock = new object();
+
+ public VPagination()
+ {
+
+ }
+
+ static VPagination()
+ {
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(VPagination), new FrameworkPropertyMetadata(typeof(VPagination)));
+ }
+
+ ///
+ /// 初始化控件
+ ///
+ private void InitControls()
+ {
+
+ _cbbPageDataCount = this.Template.FindName("PART_ComboBox", this) as ComboBox;
+ if (_cbbPageDataCount != null)
+ {
+ _cbbPageDataCount.SelectionChanged += _cbbPageDataCount_SelectionChanged;
+ }
+
+ _lstShowingPage = GetTemplateChild("PART_ListBoxPages") as ListBox;
+ if (_lstShowingPage != null)
+ {
+ _lstShowingPage.SelectionChanged += _lstShowingPage_SelectionChanged;
+ }
+
+ _btnFirstPage = GetTemplateChild("PART_ButtonFirstPage") as Button;
+ if (_btnFirstPage != null)
+ {
+ _btnFirstPage.Click += _btnFirstPage_Click;
+ }
+
+ _btnPrePage = GetTemplateChild("PART_ButtonPrePage") as Button;
+ if (_btnPrePage != null)
+ {
+ _btnPrePage.Click += _btnPrePage_Click;
+ }
+
+ _btnNextPage = GetTemplateChild("PART_ButtonNextPage") as Button;
+ if (_btnNextPage != null)
+ {
+ _btnNextPage.Click += _btnNextPage_Click;
+ }
+
+ _btnLastPage = GetTemplateChild("PART_ButtonLastPage") as Button;
+ if (_btnLastPage != null)
+ {
+ _btnLastPage.Click += _btnLastPage_Click;
+ }
+ }
+
+ ///
+ /// 初始化数据
+ ///
+ private void InitData()
+ {
+ try
+ {
+ _isIgnoreListBoxSelectionChanged = true;
+ if (PageDataCount > 0)
+ {
+ //根据总的数据量和每页最大显示的数据量计算总的页数
+ if (TotalDataCount % PageDataCount > 0)
+ {
+ TotalPageCount = TotalDataCount / PageDataCount + 1;
+ }
+ else
+ {
+ TotalPageCount = TotalDataCount / PageDataCount;
+ }
+
+ //将可选择页码加入到数据绑定集合中
+ if (ShowingPageNumberCollection != null)
+ {
+ lock (_lock)
+ {
+ ShowingPageNumberCollection.Clear();
+ int addPageCount = MaxShownPageCount;
+ if (TotalPageCount < MaxShownPageCount)
+ {
+ addPageCount = TotalPageCount;
+ }
+
+ for (int i = 1; i <= addPageCount; i++)
+ {
+ ShowingPageNumberCollection.Add(i);
+ }
+ }
+ }
+
+ //初始化选中页
+ if (_lstShowingPage != null)
+ {
+ _lstShowingPage.SelectedIndex = 0;
+ CurrentPageNumber = 1;
+ }
+
+ //更新分页数据信息
+ UpdateShowingPageInfo();
+ }
+
+ SetBtnEnable();
+ }
+ finally
+ {
+ _isIgnoreListBoxSelectionChanged = false;
+ }
+ }
+
+ private void _cbbPageDataCount_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ ComboBox cbb = sender as ComboBox;
+ if (cbb == null || cbb.SelectedItem == null)
+ {
+ return;
+ }
+
+ string selectedCountString = cbb.SelectedItem.ToString();
+ if (!int.TryParse(selectedCountString, out int selectedDataCount))
+ {
+ return;
+ }
+
+ PageDataCount = selectedDataCount;
+ InitData();
+ }
+ private void _lstShowingPage_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ if (_isIgnoreListBoxSelectionChanged)
+ {
+ return;
+ }
+
+ try
+ {
+ _isIgnoreListBoxSelectionChanged = true;
+
+ ListBox lst = sender as ListBox;
+ if (lst == null || lst.SelectedItem == null)
+ {
+ return;
+ }
+
+ string selectedPageString = lst.SelectedItem.ToString();
+ if (!int.TryParse(selectedPageString, out int selectedPageNumber))
+ {
+ return;
+ }
+
+ //总页数小于最大可显示页数表明无论选中的页数为何,均不需要改动页码集合中的数据,此时直接返回
+ if (TotalPageCount <= MaxShownPageCount)
+ {
+ CurrentPageNumber = selectedPageNumber;
+ UpdateShowingPageInfo();
+ return;
+ }
+
+ //计算为保持选中项居中而需要向右移动的次数 比较中间位置与选中项的下标
+ int moveCount = MaxShownPageCount / 2 - _lstShowingPage.SelectedIndex;
+ int startPageNumber = ShowingPageNumberCollection.First();
+ if (moveCount > 0) //向右移动
+ {
+ int realMoveCount = moveCount;
+ if (ShowingPageNumberCollection.First() - 1 < moveCount)
+ {
+ realMoveCount = ShowingPageNumberCollection.First() - 1;
+ }
+
+ startPageNumber = ShowingPageNumberCollection.First() - realMoveCount;
+ }
+ else if (moveCount < 0) //向左移动
+ {
+ int realMoveCount = -moveCount;
+ if (TotalPageCount - ShowingPageNumberCollection.Last() < realMoveCount)
+ {
+ realMoveCount = TotalPageCount - ShowingPageNumberCollection.Last();
+ }
+
+ startPageNumber = ShowingPageNumberCollection.First() + realMoveCount;
+ }
+
+ lock (_lock)
+ {
+ ShowingPageNumberCollection.Clear();
+ for (int i = 0; i < MaxShownPageCount; i++)
+ {
+ ShowingPageNumberCollection.Add(startPageNumber + i);
+ }
+ }
+
+ int selectedItemIndex = ShowingPageNumberCollection.IndexOf(selectedPageNumber);
+ _lstShowingPage.SelectedIndex = selectedItemIndex;
+
+ CurrentPageNumber = selectedPageNumber;
+ UpdateShowingPageInfo();
+ }
+ finally
+ {
+ _isIgnoreListBoxSelectionChanged = false;
+ }
+ }
+ ///
+ /// 跳转到首页
+ ///
+ ///
+ ///
+ private void _btnFirstPage_Click(object sender, RoutedEventArgs e)
+ {
+ if (_lstShowingPage == null
+ || ShowingPageNumberCollection == null
+ || ShowingPageNumberCollection.Count == 0)
+ {
+ return;
+ }
+
+ if (ShowingPageNumberCollection[0] != 1)
+ {
+ try
+ {
+ _isIgnoreListBoxSelectionChanged = true;
+ lock (_lock)
+ {
+ ShowingPageNumberCollection.Clear();
+ for (int i = 1; i <= MaxShownPageCount; i++)
+ {
+ ShowingPageNumberCollection.Add(i);
+ }
+ }
+ }
+ finally
+ {
+ _isIgnoreListBoxSelectionChanged = false;
+ }
+ }
+
+ _lstShowingPage.SelectedIndex = 0;
+ }
+ ///
+ /// 跳转到尾页
+ ///
+ ///
+ ///
+ private void _btnLastPage_Click(object sender, RoutedEventArgs e)
+ {
+ if (_lstShowingPage == null
+ || ShowingPageNumberCollection == null
+ || ShowingPageNumberCollection.Count == 0)
+ {
+ return;
+ }
+
+ if (ShowingPageNumberCollection.Last() != TotalPageCount)
+ {
+ try
+ {
+ _isIgnoreListBoxSelectionChanged = true;
+ lock (_lock)
+ {
+ ShowingPageNumberCollection.Clear();
+ for (int i = 0; i < MaxShownPageCount; i++)
+ {
+ ShowingPageNumberCollection.Add(TotalPageCount - MaxShownPageCount + i + 1);
+ }
+ }
+ }
+ finally
+ {
+ _isIgnoreListBoxSelectionChanged = false;
+ }
+ }
+
+ _lstShowingPage.SelectedIndex = _lstShowingPage.Items.Count - 1;
+ }
+ ///
+ /// 跳转到前一页
+ ///
+ ///
+ ///
+ private void _btnPrePage_Click(object sender, RoutedEventArgs e)
+ {
+ if (_lstShowingPage == null
+ || ShowingPageNumberCollection == null
+ || ShowingPageNumberCollection.Count == 0)
+ {
+ return;
+ }
+
+ if (_lstShowingPage.SelectedIndex > 0)
+ {
+ _lstShowingPage.SelectedIndex--;
+ }
+ }
+ ///
+ /// 跳转到后一条
+ ///
+ ///
+ ///
+ private void _btnNextPage_Click(object sender, RoutedEventArgs e)
+ {
+ if (_lstShowingPage == null
+ || ShowingPageNumberCollection == null
+ || ShowingPageNumberCollection.Count == 0)
+ {
+ return;
+ }
+
+ if (_lstShowingPage.SelectedIndex < MaxShownPageCount - 1)
+ {
+ _lstShowingPage.SelectedIndex++;
+ }
+ }
+
+ private void UpdateShowingPageInfo()
+ {
+ if (TotalPageCount == 0)
+ {
+ ShowingPageDataStartNumber = 0;
+ ShowingPageDataEndNumber = 0;
+ }
+ else if (CurrentPageNumber < TotalPageCount)
+ {
+ ShowingPageDataStartNumber = (CurrentPageNumber - 1) * PageDataCount + 1;
+ ShowingPageDataEndNumber = CurrentPageNumber * PageDataCount;
+ }
+ else if (CurrentPageNumber == TotalPageCount)
+ {
+ ShowingPageDataStartNumber = (CurrentPageNumber - 1) * PageDataCount + 1;
+ ShowingPageDataEndNumber = TotalDataCount;
+ }
+ }
+
+ ///
+ /// 设置按钮的可用性
+ ///
+ private void SetBtnEnable()
+ {
+ if (_btnFirstPage == null || _btnPrePage == null
+ || _btnNextPage == null || _btnLastPage == null)
+ {
+ return;
+ }
+
+ _btnPrePage.IsEnabled = true;
+ _btnNextPage.IsEnabled = true;
+ _btnFirstPage.IsEnabled = true;
+ _btnLastPage.IsEnabled = true;
+
+ if (ShowingPageNumberCollection == null || ShowingPageNumberCollection.Count == 0)//集合为空或者无数据,则所有按钮不可用
+ {
+ _btnPrePage.IsEnabled = false;
+ _btnNextPage.IsEnabled = false;
+ _btnFirstPage.IsEnabled = false;
+ _btnLastPage.IsEnabled = false;
+ }
+ else
+ {
+ if (CurrentPageNumber == 1)
+ {
+ _btnFirstPage.IsEnabled = false;
+ _btnPrePage.IsEnabled = false;
+ }
+
+ if (CurrentPageNumber == TotalPageCount)
+ {
+ _btnNextPage.IsEnabled = false;
+ _btnLastPage.IsEnabled = false;
+ }
+ }
+ }
+ }
+}
diff --git a/YC.WPF.Theme/CustomControl/Pagination/VPaginationStyles.xaml b/YC.WPF.Theme/CustomControl/Pagination/VPaginationStyles.xaml
new file mode 100644
index 0000000..a7b775f
--- /dev/null
+++ b/YC.WPF.Theme/CustomControl/Pagination/VPaginationStyles.xaml
@@ -0,0 +1,154 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/YC.WPF.Theme/CustomControl/RadarChartControl/RadarChart.cs b/YC.WPF.Theme/CustomControl/RadarChartControl/RadarChart.cs
new file mode 100644
index 0000000..80b0229
--- /dev/null
+++ b/YC.WPF.Theme/CustomControl/RadarChartControl/RadarChart.cs
@@ -0,0 +1,204 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:RadarChart
+// 创 建 者:杨程
+// 创建时间:2022/3/11 14:53:16
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+using System.Windows.Shapes;
+using Vampirewal.Core.SimpleMVVM;
+
+namespace Vampirewal.Core.WPF.Theme.CustomControl
+{
+ ///
+ /// 雷达图控件
+ ///
+ //public class RadarChart : Control
+ //{
+
+ // public ObservableCollection RadarArray
+ // {
+ // get { return (ObservableCollection)GetValue(RadarArrayProperty); }
+ // set { SetValue(RadarArrayProperty, value); }
+ // }
+
+ // public static readonly DependencyProperty RadarArrayProperty =
+ // DependencyProperty.Register("RadarArray", typeof(ObservableCollection), typeof(RadarChart), new PropertyMetadata(null));
+
+
+
+
+
+ // public Brush RadarChartTitleForeground
+ // {
+ // get { return (Brush)GetValue(RadarChartTitleForegroundProperty); }
+ // set { SetValue(RadarChartTitleForegroundProperty, value); }
+ // }
+
+ // // Using a DependencyProperty as the backing store for RadarChartTitleForeground. This enables animation, styling, binding, etc...
+ // public static readonly DependencyProperty RadarChartTitleForegroundProperty =
+ // DependencyProperty.Register("RadarChartTitleForeground", typeof(Brush), typeof(RadarChart), new PropertyMetadata(Brushes.Black));
+
+
+
+ // ///
+ // /// 雷达图大小
+ // ///
+ // public int RadarSize
+ // {
+ // get { return (int)GetValue(RadarSizeProperty); }
+ // set { SetValue(RadarSizeProperty, value); }
+ // }
+
+ // // Using a DependencyProperty as the backing store for RadarSize. This enables animation, styling, binding, etc...
+ // public static readonly DependencyProperty RadarSizeProperty =
+ // DependencyProperty.Register("RadarSize", typeof(int), typeof(RadarChart), new PropertyMetadata(10));
+
+
+
+ // static RadarChart()
+ // {
+ // DefaultStyleKeyProperty.OverrideMetadata(typeof(RadarChart), new FrameworkPropertyMetadata(typeof(RadarChart)));
+ // }
+ // protected override void OnRender(DrawingContext drawingContext)
+ // {
+ // DrawPoints(RadarSize*3, drawingContext, true);
+ // DrawPoints(RadarSize*2, drawingContext);
+ // DrawPoints(RadarSize, drawingContext);
+
+ // var myPen = new Pen
+ // {
+ // Thickness = 4,
+ // Brush = Brushes.DodgerBlue
+ // };
+ // myPen.Freeze();
+ // StreamGeometry streamGeometry = new StreamGeometry();
+ // using (StreamGeometryContext geometryContext = streamGeometry.Open())
+ // {
+ // var h = this.ActualHeight / 2;
+ // var w = this.ActualWidth / 2;
+ // PointCollection points = new PointCollection();
+ // foreach (var item in RadarArray)
+ // {
+ // var ss = new Point((item.PointValue.X - w) / 100 * item.ValueMax + w, (item.PointValue.Y - h) / 100 * item.ValueMax + h);
+ // points.Add(ss);
+ // }
+ // geometryContext.BeginFigure(points[points.Count - 1], true, true);
+ // geometryContext.PolyLineTo(points, true, true);
+ // }
+
+ // streamGeometry.Freeze();
+ // SolidColorBrush rectBrush = new SolidColorBrush(Colors.LightSkyBlue);
+ // rectBrush.Opacity = 0.5;
+ // drawingContext.DrawGeometry(rectBrush, myPen, streamGeometry);
+ // }
+ // void DrawPoints(int circleRadius, DrawingContext drawingContext, bool isDrawText = false)
+ // {
+ // var myPen = new Pen
+ // {
+ // Thickness = 2,
+ // Brush = Brushes.Gainsboro
+ // };
+ // myPen.Freeze();
+ // StreamGeometry streamGeometry = new StreamGeometry();
+ // using (StreamGeometryContext geometryContext = streamGeometry.Open())
+ // {
+ // var h = this.ActualHeight / 2;
+ // var w = this.ActualWidth / 2;
+ // PointCollection points = null;
+ // if (isDrawText)
+ // points = GetPolygonPoint(new Point(w, h), circleRadius, RadarArray.Count, drawingContext);
+ // else
+ // points = GetPolygonPoint(new Point(w, h), circleRadius, RadarArray.Count);
+ // geometryContext.BeginFigure(points[points.Count - 1], true, true);
+ // geometryContext.PolyLineTo(points, true, true);
+ // }
+ // streamGeometry.Freeze();
+ // drawingContext.DrawGeometry(null, myPen, streamGeometry);
+ // }
+ // private PointCollection GetPolygonPoint(Point center, double r, int polygonBound, DrawingContext drawingContext = null)
+ // {
+ // double g = 18;
+ // double perangle = 360 / polygonBound;
+ // double pi = Math.PI;
+ // List values = new List();
+ // for (int i = 0; i < polygonBound; i++)
+ // {
+ // Point p2 = new Point(r * Math.Cos(g * pi / 180) + center.X, r * Math.Sin(g * pi / 180) + center.Y);
+ // if (drawingContext != null)
+ // {
+ // FormattedText formattedText = new FormattedText(
+ // RadarArray[i].Text,
+ // CultureInfo.CurrentCulture,
+ // FlowDirection.LeftToRight,
+ // new Typeface(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Thin, FontStretches.Normal),
+ // 20.001D, RadarChartTitleForeground,1.25d)
+ // {
+ // MaxLineCount = 1,
+ // TextAlignment = TextAlignment.Justify,
+ // Trimming = TextTrimming.CharacterEllipsis
+ // };
+ // RadarArray[i].PointValue = p2;
+ // if (p2.Y > center.Y && p2.X < center.X)
+ // drawingContext.DrawText(formattedText, new Point(p2.X - formattedText.Width - 5, p2.Y - formattedText.Height / 2));
+ // else if (p2.Y < center.Y && p2.X > center.X)
+ // drawingContext.DrawText(formattedText, new Point(p2.X, p2.Y - formattedText.Height));
+ // else if (p2.Y < center.Y && p2.X < center.X)
+ // drawingContext.DrawText(formattedText, new Point(p2.X - formattedText.Width - 5, p2.Y - formattedText.Height));
+ // else if (p2.Y < center.Y && p2.X == center.X)
+ // drawingContext.DrawText(formattedText, new Point(p2.X - formattedText.Width, p2.Y - formattedText.Height));
+ // else
+ // drawingContext.DrawText(formattedText, new Point(p2.X, p2.Y));
+ // }
+ // values.Add(p2);
+ // g += perangle;
+ // }
+ // PointCollection pcollect = new PointCollection(values);
+ // return pcollect;
+ // }
+ //}
+
+ //public class RadarModel : NotifyBase
+ //{
+ // public string Text { get; set; }
+
+ // private int _valueMax;
+
+ // public int ValueMax
+ // {
+ // get { return _valueMax; }
+ // set
+ // {
+ // _valueMax = value;
+ // DoNotify();
+ // }
+ // }
+ // private Point _pointValue;
+
+ // public Point PointValue
+ // {
+ // get { return _pointValue; }
+ // set
+ // {
+ // _pointValue = value;
+ // DoNotify();
+ // }
+ // }
+ //}
+}
diff --git a/YC.WPF.Theme/CustomControl/RadarChartControl/RadarControl.xaml b/YC.WPF.Theme/CustomControl/RadarChartControl/RadarControl.xaml
new file mode 100644
index 0000000..1ce285e
--- /dev/null
+++ b/YC.WPF.Theme/CustomControl/RadarChartControl/RadarControl.xaml
@@ -0,0 +1,15 @@
+
+
+
+
+
diff --git a/YC.WPF.Theme/CustomControl/RadarChartControl/RadarControl.xaml.cs b/YC.WPF.Theme/CustomControl/RadarChartControl/RadarControl.xaml.cs
new file mode 100644
index 0000000..9e71085
--- /dev/null
+++ b/YC.WPF.Theme/CustomControl/RadarChartControl/RadarControl.xaml.cs
@@ -0,0 +1,737 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Collections.Specialized;
+using System.ComponentModel;
+using System.Globalization;
+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.Animation;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace Vampirewal.Core.WPF.Theme.CustomControl
+{
+ ///
+ /// 使用说明:
+ /// 1、
+ ///
+ public partial class RadarControl : UserControl
+ {
+ public RadarControl()
+ {
+ InitializeComponent();
+ }
+
+ #region 属性
+
+ ///
+ /// 数值区域填充色
+ ///
+ public Brush AreaBrush
+ {
+ get { return (Brush)GetValue(AreaBrushProperty); }
+ set { SetValue(AreaBrushProperty, value); }
+ }
+
+ public static readonly DependencyProperty AreaBrushProperty = DependencyProperty.Register("AreaBrush", typeof(Brush),
+ typeof(RadarControl), new PropertyMetadata(Brushes.Black));
+
+ ///
+ /// 数值区域点填充色
+ ///
+ public Brush AreaPointBrush
+ {
+ get { return (Brush)GetValue(AreaPointBrushProperty); }
+ set { SetValue(AreaPointBrushProperty, value); }
+ }
+
+ public static readonly DependencyProperty AreaPointBrushProperty = DependencyProperty.Register("AreaPointBrush", typeof(Brush),
+ typeof(RadarControl), new PropertyMetadata(Brushes.Black));
+
+ ///
+ /// 雷达网格线填充充色
+ ///
+ public Brush RadarNetBrush
+ {
+ get { return (Brush)GetValue(RadarNetBrushProperty); }
+ set { SetValue(RadarNetBrushProperty, value); }
+ }
+
+ public static readonly DependencyProperty RadarNetBrushProperty = DependencyProperty.Register("RadarNetBrush", typeof(Brush),
+ typeof(RadarControl), new PropertyMetadata(Brushes.Black));
+
+ ///
+ /// 雷达网格线宽度
+ ///
+ public double RadarNetThickness
+ {
+ get { return (double)GetValue(RadarNetThicknessProperty); }
+ set { SetValue(RadarNetThicknessProperty, value); }
+ }
+
+ public static readonly DependencyProperty RadarNetThicknessProperty = DependencyProperty.Register("RadarNetThickness", typeof(double),
+ typeof(RadarControl), new PropertyMetadata(1.0));
+
+ ///
+ /// 数值点高宽度,0为不显示
+ ///
+ public double AreaPointSize
+ {
+ get { return (double)GetValue(AreaPointSizeProperty); }
+ set { SetValue(AreaPointSizeProperty, value); }
+ }
+
+ public static readonly DependencyProperty AreaPointSizeProperty = DependencyProperty.Register("AreaPointSize", typeof(double),
+ typeof(RadarControl), new PropertyMetadata(10.0));
+
+ ///
+ /// 纬线数量
+ ///
+ public int LatitudeCount
+ {
+ get { return (int)GetValue(LatitudeCountProperty); }
+ set { SetValue(LatitudeCountProperty, value); }
+ }
+
+ public static readonly DependencyProperty LatitudeCountProperty = DependencyProperty.Register("LatitudeCount", typeof(int),
+ typeof(RadarControl), new PropertyMetadata(5));
+
+ ///
+ /// 网格图停靠间距
+ ///
+ public int RadarNetMargin
+ {
+ get { return (int)GetValue(RadarNetMarginProperty); }
+ set { SetValue(RadarNetMarginProperty, value); }
+ }
+
+ public static readonly DependencyProperty RadarNetMarginProperty = DependencyProperty.Register("RadarNetMargin", typeof(int),
+ typeof(RadarControl), new PropertyMetadata(50));
+
+ ///
+ /// 显示值标注
+ ///
+ public bool ShowValuesLabel
+ {
+ get { return (bool)GetValue(ShowValuesLabelProperty); }
+ set { SetValue(ShowValuesLabelProperty, value); }
+ }
+
+ public static readonly DependencyProperty ShowValuesLabelProperty = DependencyProperty.Register("ShowValuesLabel", typeof(bool),
+ typeof(RadarControl), new PropertyMetadata(true));
+
+ ///
+ /// 显示组标签
+ ///
+ public bool ShowGroupsLabel
+ {
+ get { return (bool)GetValue(ShowGroupsLabelProperty); }
+ set { SetValue(ShowGroupsLabelProperty, value); }
+ }
+
+ public static readonly DependencyProperty ShowGroupsLabelProperty = DependencyProperty.Register("ShowGroupsLabel", typeof(bool),
+ typeof(RadarControl), new PropertyMetadata(true));
+
+ ///
+ /// 是否为多重绘图模式(默认否)
+ ///
+ public bool MoreGraphics
+ {
+ get { return (bool)GetValue(MoreGraphicsProperty); }
+ set { SetValue(MoreGraphicsProperty, value); }
+ }
+
+ public static readonly DependencyProperty MoreGraphicsProperty = DependencyProperty.Register("MoreGraphics", typeof(bool),
+ typeof(RadarControl), new PropertyMetadata(false));
+
+ ///
+ /// 分隔角度
+ ///
+ private double Angle
+ {
+ get
+ {
+ int count = MoreGraphics ? MoreDatas[0].Count : Datas.Count;
+ double angle = 360 / count;
+ return angle;
+ }
+ }
+
+ ///
+ /// 数据
+ ///
+ [Bindable(true)]
+ public ObservableCollection Datas
+ {
+ get { return (ObservableCollection)GetValue(DatasProperty); }
+ set { SetValue(DatasProperty, value); }
+ }
+
+ public static readonly DependencyProperty DatasProperty = DependencyProperty.Register("Datas", typeof(ObservableCollection),
+ typeof(RadarControl), new PropertyMetadata(new ObservableCollection(), DataChangedCallBack));
+
+ private static void DataChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ //var NewData=e.NewValue as ObservableCollection;
+ //if (NewData != null)
+ //{
+ // RadarControl rc=d as RadarControl;
+
+ // rc.InitalData();
+ //}
+
+ RadarControl control = d as RadarControl;
+ if (control != null)
+ {
+ control.DataCollectionChanged();
+ }
+ }
+
+ public void DataCollectionChanged()
+ {
+ if (Datas is INotifyCollectionChanged)
+ {
+ (Datas as INotifyCollectionChanged).CollectionChanged -= DataCollectionChanged_CollectionChanged;
+ (Datas as INotifyCollectionChanged).CollectionChanged += DataCollectionChanged_CollectionChanged;
+ }
+ }
+
+ private void DataCollectionChanged_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
+ {
+ //try
+ //{
+ // switch (e.Action)
+ // {
+ // case NotifyCollectionChangedAction.Add:
+
+ // foreach (var item in e.NewItems)
+ // {
+
+ // }
+
+ // break;
+ // case NotifyCollectionChangedAction.Remove:
+ // break;
+
+ // }
+
+
+ //}
+ //catch (Exception)
+ //{
+
+ // throw;
+ //}
+
+ InitalData();
+ }
+
+ ///
+ /// 多元数据
+ ///
+ [Bindable(true)]
+ public ObservableCollection[] MoreDatas
+ {
+ get { return (ObservableCollection[])GetValue(MoreDatasProperty); }
+ set { SetValue(MoreDatasProperty, value); }
+ }
+
+ public static readonly DependencyProperty MoreDatasProperty = DependencyProperty.Register("MoreDatas", typeof(ObservableCollection[]),
+ typeof(RadarControl), new PropertyMetadata(new ObservableCollection[2]));
+
+ ///
+ /// 多元数据画笔
+ ///
+ public List RadarNetBrushes
+ {
+ get { return (List)GetValue(RadarNetBrushesProperty); }
+ set { SetValue(RadarNetBrushesProperty, value); }
+ }
+
+ public static readonly DependencyProperty RadarNetBrushesProperty = DependencyProperty.Register("RadarNetBrushes", typeof(List),
+ typeof(RadarControl), new PropertyMetadata(new List()));
+
+ ///
+ /// 当前绘制大区域
+ ///
+ private double MaxSize
+ {
+ get
+ {
+ var par = this.Parent as FrameworkElement;
+ return par.ActualHeight > par.ActualWidth ? par.ActualWidth : par.ActualHeight;
+ }
+ }
+
+ #endregion 属性
+
+ private void RadarControl_SizeChanged(object sender, SizeChangedEventArgs e)
+ {
+ if (!MoreGraphics)
+ InitalData();
+ else
+ InitalMoreData();
+
+ }
+
+ ///
+ /// 设置标注
+ ///
+ ///
+ ///
+ ///
+ private void SetLabel(RadarObj obj, Point location, bool isGroupLabel)
+ {
+ //计算偏移量
+ bool x = true;
+ bool y = true;
+
+ if (location.X < 0)
+ x = false;
+ if (location.Y < 0)
+ y = false;
+
+ TextBlock txb = new TextBlock() { Text = isGroupLabel ? obj.Name : obj.DataValue.ToString(), Foreground = this.Foreground, FontSize = this.FontSize };
+ Size s = ControlSizeUtils.GetTextAreaSize(txb.Text, this.FontSize);
+ CanvasPanel.Children.Add(txb);
+ if (location.X > -5 && location.X < 5)
+ Canvas.SetLeft(txb, location.X - (s.Width / 2));
+ else
+ Canvas.SetLeft(txb, location.X + (x ? 0 : -(s.Width)));
+
+ if (location.Y > -5 && location.Y < 5)
+ Canvas.SetTop(txb, location.Y - (s.Height / 2));
+ else
+ Canvas.SetTop(txb, location.Y + (y ? 0 : -(s.Height)));
+ }
+
+ ///
+ /// 设置数据显示
+ ///
+ private void InitalData()
+ {
+ CanvasPanel.Children.Clear();
+ if (Datas != null && Datas.Count > 0)
+ {
+ this.CanvasPanel.Width = this.CanvasPanel.Height = 0;
+
+ //计算比例尺
+ var scale = ((MaxSize / 2) - RadarNetMargin) / Datas.Max(i => i.DataValue);
+
+ //计算实际半径
+ for (int i = 0; i < Datas.Count; i++)
+ {
+ Datas[i].DataRaidus = Datas[i].DataValue * scale;
+ }
+
+ //获取最大数值
+ double maxData = Datas.Max(i => i.DataRaidus);
+
+ //计算纬线间距半径
+ double length = maxData / LatitudeCount;
+
+ for (int index = 1; index < LatitudeCount + 1; index++)
+ {
+ //多边形半径
+ var r = length * index;
+ Polygon polygonBorder = new Polygon() { Fill = Brushes.Transparent, Stroke = RadarNetBrush, StrokeThickness = RadarNetThickness };
+ //绘制多边形
+ for (int currentIndex = 0; currentIndex < Datas.Count; currentIndex++)
+ {
+ double angle = ((Angle * currentIndex + 90) / 360) * 2 * Math.PI;
+ polygonBorder.Points.Add(new Point(r * Math.Cos(angle), r * Math.Sin(angle)));
+ }
+ CanvasPanel.Children.Add(polygonBorder);
+ }
+
+ //数值区域多边形
+ Polygon polygonArea = new Polygon() { Fill = AreaBrush, Opacity = 0.5, Stroke = AreaPointBrush, StrokeThickness = 5 };
+
+ //经线长度
+ var maxRadius = LatitudeCount * length;
+
+ List ellipselst = new List();
+ Dictionary valuesLabelLocations = new Dictionary();
+ Dictionary groupLabelLocations = new Dictionary();
+
+ //绘制数据多边形
+ for (int Index = 0; Index < Datas.Count; Index++)
+ {
+ //计算角度
+ double angle = ((Angle * Index + 90) / 360) * 2 * Math.PI;
+ //计算距离值
+ var cou = Datas[Index].DataRaidus / length; //计算倍距
+ var rac = Datas[Index].DataRaidus % length;//计算余距
+ double Radius = cou * length + rac;
+
+ //超过最大半径则设置为最大半径
+ if (Radius > maxRadius)
+ {
+ Radius = maxRadius;
+ }
+ Point pt = new Point(Radius * Math.Cos(angle), Radius * Math.Sin(angle));
+ polygonArea.Points.Add(pt);
+ valuesLabelLocations.Add(Datas[Index], new Point((Radius) * Math.Cos(angle), (Radius) * Math.Sin(angle)));//记录点位标注标识
+ //设置数值点,如果数值点尺寸大于0则绘制
+ if (AreaPointSize > 0)
+ {
+ var ellipse = new Ellipse() { Width = AreaPointSize, Height = AreaPointSize, Fill = AreaPointBrush };
+ //var ellipse = new Ellipse() { Width = AreaPointSize, Height = AreaPointSize, Fill = Datas[Index].Fill }; AreaPointBrush
+ Canvas.SetLeft(ellipse, pt.X - (AreaPointSize / 2));
+ Canvas.SetTop(ellipse, pt.Y - (AreaPointSize / 2));
+ ellipselst.Add(ellipse);
+ }
+
+ Point ptMax = new Point(maxRadius * Math.Cos(angle), maxRadius * Math.Sin(angle));
+
+ //记录组点位标注标识
+ groupLabelLocations.Add(Datas[Index], new Point((maxRadius + 20) * Math.Cos(angle), (maxRadius + 20) * Math.Sin(angle)));
+
+ //绘制经线
+ Path pth = new Path() { Stroke = RadarNetBrush, StrokeThickness = RadarNetThickness };
+ // Path pth = new Path() { Stroke = Datas[Index].Stroke, StrokeThickness = RadarNetThickness };
+ pth.Data = (Geometry)new GeometryConverter().ConvertFromString(String.Format("M0,0 {0},{1}", ptMax.X.ToString(), ptMax.Y.ToString()));
+ CanvasPanel.Children.Add(pth);
+ }
+ CanvasPanel.Children.Add(polygonArea);
+
+ //绘点
+ foreach (var elc in ellipselst)
+ CanvasPanel.Children.Add(elc);
+
+ //标注值标签
+ if (ShowValuesLabel)
+ {
+ foreach (var item in valuesLabelLocations)
+ {
+ SetLabel(item.Key, item.Value, false);
+ }
+ }
+ //标注组标签
+ if (ShowGroupsLabel)
+ {
+ foreach (var item in groupLabelLocations)
+ SetLabel(item.Key, item.Value, true);
+ }
+ this.SizeChanged -= RadarControl_SizeChanged;
+ this.SizeChanged += RadarControl_SizeChanged;
+ }
+ }
+
+ ///
+ /// 设置数据显示
+ ///
+ private void InitalMoreData()
+ {
+ CanvasPanel.Children.Clear();
+ if (this.MoreDatas != null && MoreDatas.Length > 0)
+ {
+ this.CanvasPanel.Width = this.CanvasPanel.Height = 0;
+
+ //计算比例尺
+ var max = 0.00;
+ foreach (var item in MoreDatas)
+ if (item.Max(i => i.DataValue) > max)
+ max = item.Max(i => i.DataValue);
+ var scale = ((MaxSize / 2) - RadarNetMargin) / max;
+
+ //计算实际半径
+ for (int index = 0; index < MoreDatas.Length; index++)
+ for (int i = 0; i < MoreDatas[index].Count; i++)
+ MoreDatas[index][i].DataRaidus = MoreDatas[index][i].DataValue * scale;
+
+
+ //获取最大数值
+ double maxData = 0.000;
+ foreach (var item in MoreDatas)
+ if (item.Max(i => i.DataRaidus) > maxData)
+ maxData = item.Max(i => i.DataRaidus);
+
+ //计算纬线间距半径
+ double length = maxData / LatitudeCount;
+
+ for (int index = 1; index < LatitudeCount + 1; index++)
+ {
+ //多边形半径
+ var r = length * index;//RadarNetBrush
+ Polygon polygonBorder = new Polygon() { Fill = Brushes.Transparent, Stroke = RadarNetBrush, StrokeThickness = RadarNetThickness };
+ //绘制多边形
+ for (int currentIndex = 0; currentIndex < MoreDatas[0].Count; currentIndex++)
+ {
+ double angle = ((Angle * currentIndex + 90) / 360) * 2 * Math.PI;
+ polygonBorder.Points.Add(new Point(r * Math.Cos(angle), r * Math.Sin(angle)));
+ }
+ CanvasPanel.Children.Add(polygonBorder);
+ }
+
+ //数值区域多边形
+ List polygonAreaList = new List();
+ for (int index = 0; index < this.MoreDatas.Length; index++)
+ polygonAreaList.Add(new Polygon() { Fill = RadarNetBrushes[index], Opacity = 0.5, Stroke = Brushes.LightGreen, StrokeThickness = 3 });
+
+ //经线长度
+ var maxRadius = LatitudeCount * length;
+
+ List ellipselst = new List();
+ Dictionary valuesLabelLocations = new Dictionary();
+ Dictionary groupLabelLocations = new Dictionary();
+
+
+ //绘制数据多边形
+ for (int Index = 0; Index < MoreDatas[0].Count; Index++)
+ {
+ //计算角度
+ double angle = ((Angle * Index + 90) / 360) * 2 * Math.PI;
+
+ //逐步生成每类数据的各组实际数据:例如A、B、C、D的交通数据数据
+ for (int dataIndex = 0; dataIndex < MoreDatas.Length; dataIndex++)
+ {
+ //计算距离值
+ var cou = MoreDatas[dataIndex][Index].DataRaidus / length; //计算倍距
+ var rac = MoreDatas[dataIndex][Index].DataRaidus % length;//计算余距
+ double Radius = cou * length + rac;
+
+ //超过最大半径则设置为最大半径
+ if (Radius > maxRadius)
+ {
+ Radius = maxRadius;
+ }
+ Point pt = new Point(Radius * Math.Cos(angle), Radius * Math.Sin(angle));
+ polygonAreaList[dataIndex].Points.Add(pt);
+ //valuesLabelLocations.Add(Datas[Index], new Point((Radius) * Math.Cos(angle), (Radius) * Math.Sin(angle)));//记录点位标注标识
+ //设置数值点,如果数值点尺寸大于0则绘制
+ if (AreaPointSize > 0)
+ {
+ var ellipse = new Ellipse() { Width = AreaPointSize / 2, Height = AreaPointSize / 2, Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(ChartColorPool.ColorStrings[Index])) };
+ Canvas.SetLeft(ellipse, pt.X - (AreaPointSize / 4));
+ Canvas.SetTop(ellipse, pt.Y - (AreaPointSize / 4));
+ ellipselst.Add(ellipse);
+ }
+ }
+ Point ptMax = new Point(maxRadius * Math.Cos(angle), maxRadius * Math.Sin(angle));
+
+ //记录组点位标注标识
+ groupLabelLocations.Add(MoreDatas[0][Index], new Point((maxRadius + 20) * Math.Cos(angle), (maxRadius + 20) * Math.Sin(angle)));
+
+ //绘制经线 RadarNetBrush
+ Path pth = new Path() { Stroke = RadarNetBrush, StrokeThickness = RadarNetThickness };
+ pth.Data = (Geometry)new GeometryConverter().ConvertFromString(String.Format("M0,0 {0},{1}", ptMax.X.ToString(), ptMax.Y.ToString()));
+ CanvasPanel.Children.Add(pth);
+ }
+ foreach (var polygonArea in polygonAreaList)
+ CanvasPanel.Children.Add(polygonArea);
+
+ //绘点
+ foreach (var elc in ellipselst)
+ CanvasPanel.Children.Add(elc);
+
+ //标注组标签
+ if (ShowGroupsLabel)
+ {
+ foreach (var item in groupLabelLocations)
+ SetLabel(item.Key, item.Value, true);
+ }
+ this.SizeChanged -= RadarControl_SizeChanged;
+ this.SizeChanged += RadarControl_SizeChanged;
+ }
+ }
+
+ public void InitalControl()
+ {
+ }
+
+ ///
+ /// 加载数据
+ ///
+ ///
+ public void SetData(object dataobj)
+ {
+ if (!MoreGraphics)
+ {
+ this.Datas = (dataobj) as ObservableCollection;
+ this.InitalData();
+ }
+ else
+ {
+ this.MoreDatas = (dataobj) as ObservableCollection[];
+ InitalMoreData();
+ }
+
+ }
+
+ private Brush _stroke = Brushes.Yellow;
+
+ ///
+ /// Series stroke
+ ///
+ public Brush Stroke
+ {
+ get
+ {
+ return _stroke;
+ }
+ set
+ {
+ _stroke = value;
+ }
+ }
+
+ private Brush _fill = Brushes.Yellow;
+
+ ///
+ /// Series Fill
+ ///
+ public Brush Fill
+ {
+ get
+ {
+ return _fill;
+ }
+ set
+ {
+ _fill = value;
+ }
+ }
+ }
+
+ public class RadarObj
+ {
+ public string Name { get; set; }
+
+ public int DataValue { get; set; }
+
+ public double DataRaidus { get; set; }
+ }
+
+
+
+ ///
+ /// 计算指定字符串占用的高宽
+ ///
+ public class ControlSizeUtils
+ {
+
+ private static Size MeasureTextSize(string text, Typeface typeface, double fontSize)
+ {
+ var ft = new FormattedText(text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, fontSize, Brushes.Black);
+ return new Size(ft.Width, ft.Height);
+ }
+
+ ///
+ /// 衡量字符尺寸
+ ///
+ ///
+ public static Size GetTextAreaSize(string text, double fontsize)
+ {
+ FontFamily fontFamily; FontStyle fontStyle; FontWeight fontWeight; FontStretch fontStretch;
+ fontFamily = new FontFamily("微软雅黑"); fontStyle = FontStyles.Normal;
+ fontWeight = FontWeights.Normal;
+ fontStretch = FontStretches.Normal;
+ double fontSize = fontsize;
+ if (text == null)
+ return new Size(0, 0);
+
+ Typeface typeface = new Typeface(fontFamily, fontStyle, fontWeight, fontStretch);
+ GlyphTypeface gt;
+
+ if (!typeface.TryGetGlyphTypeface(out gt))
+ return MeasureTextSize(text, typeface, fontSize);
+
+ double totalWidth = 0;
+ double totalHeight = 0;
+
+ // 替换换行符
+ var array = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
+
+ foreach (var splitted in array)
+ {
+ double lineWidth = 0;
+ double lineHeight = 0;
+
+ // 计算每行的宽度和高度
+ for (int n = 0; n < splitted.Length; n++)
+ {
+ try
+ {
+ ushort glyphIndex = gt.CharacterToGlyphMap[splitted[n]];
+ double width = gt.AdvanceWidths[glyphIndex] * fontSize;
+ double height = gt.AdvanceHeights[glyphIndex] * fontSize;
+ lineHeight = Math.Max(totalHeight, height);
+ lineWidth += width;
+ }
+ catch (Exception exp)
+ {
+ lineWidth += fontSize;
+ }
+ }
+ totalWidth = Math.Max(totalWidth, lineWidth);
+ totalHeight = Math.Max(totalHeight, lineHeight);
+ }
+ if (totalWidth < 5)
+ totalWidth = 5;
+ return new Size(totalWidth, totalHeight);
+ }
+ }
+
+ ///
+ /// 颜色池
+ ///
+ public static class ChartColorPool
+ {
+ public static List ColorStrings { get; set; } = new List() {
+ "#FF09F7D7",
+ "#FF97F18E",
+ "#FFF1ADAD",
+ "#FFF44336",
+ "#FFE91E63",
+ "#FF9C27B0",
+ "#FF673AB7",
+ "#FF3F51B5",
+ "#FF2196F3",
+ "#FF03A9F4",
+ "#FF00BCD4",
+ "#FF009688",
+ "#FF4CAF50",
+ "#FF8BC34A",
+ "#FFCDDC39",
+ "#FFFFEB3B",
+ "#FFFFC107",
+ "#FFFF9800",
+ "#FFFF5722",
+ "#FF795548",
+ "#FF9E9E9E",
+ "#FF607D8B",
+ "#32CD32",
+ "#FFFF00",
+ "#32CD32",
+ "#FFFF00",
+ "#21B6BA",
+ "#D84E67",
+ "#B44ED6",
+ "#0092FF",
+ "#E6FF0D",
+ "#21B962",
+ "#FF0000", //[32]Red-纯红
+ "#00BFFF" , //[33]DeepSkyBlue-深天蓝
+ "#0099D7",//浅蓝
+ "#FF9B4D", //橙色
+ "#00F8A4", //浅绿
+ "#FFEF53", //黄色
+ "#EB7274", //粉色
+ "#8B95AD", //浅灰
+ "#00DFDE", //浅蓝
+ "#C19EDC", //浅紫
+ "#62474C"//褐色
+ };
+ }
+
+}
diff --git a/YC.WPF.Theme/CustomControl/SearchControl/SearchControl.cs b/YC.WPF.Theme/CustomControl/SearchControl/SearchControl.cs
new file mode 100644
index 0000000..4958602
--- /dev/null
+++ b/YC.WPF.Theme/CustomControl/SearchControl/SearchControl.cs
@@ -0,0 +1,123 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:SreachControl
+// 创 建 者:杨程
+// 创建时间:2021/12/21 10:26:27
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+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.Input;
+
+namespace Vampirewal.Core.WPF.Theme.CustomControl
+{
+ public class SearchControl:TextBox
+ {
+ private ResourceDictionary res
+ {
+ get
+ {
+ return new ResourceDictionary() { Source = new Uri("pack://application:,,,/Vampirewal.Core;component/WpfTheme/CoreTheme.xaml", UriKind.RelativeOrAbsolute) };
+ }
+ }
+
+ public SearchControl()
+ {
+ //构造函数
+
+ var BaseStyle = res["SearchControlStyle"] as Style;
+
+ this.Style = BaseStyle;
+ }
+
+ private TextBox SearchText { get; set; }
+ private Button SearchButton { get; set; }
+ public override void OnApplyTemplate()
+ {
+ base.OnApplyTemplate();
+ SearchText=this.Template.FindName("SearchText",this) as TextBox;
+
+ if (SearchTextStyle!=null)
+ {
+ SearchText.Style = SearchTextStyle;
+ }
+
+ SearchButton = this.Template.FindName("SearchButton", this) as Button;
+
+ if (SearchButtonStyle != null)
+ {
+ SearchButton.Style = SearchButtonStyle;
+ }
+ }
+
+ #region 属性
+
+ #endregion
+
+ #region 公共方法
+
+ #endregion
+
+ #region 私有方法
+
+ #endregion
+
+ #region 命令
+
+ #endregion
+
+ #region 依赖属性
+
+ public ICommand SearchCommand
+ {
+ get { return (ICommand)GetValue(SearchCommandProperty); }
+ set { SetValue(SearchCommandProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for SreachCommand. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty SearchCommandProperty =
+ DependencyProperty.Register("SearchCommand", typeof(ICommand), typeof(SearchControl), new PropertyMetadata(null));
+
+
+
+
+ public Style SearchTextStyle
+ {
+ get { return (Style)GetValue(SearchTextStyleProperty); }
+ set { SetValue(SearchTextStyleProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for SreachTextStyle. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty SearchTextStyleProperty =
+ DependencyProperty.Register("SearchTextStyle", typeof(Style), typeof(SearchControl), new PropertyMetadata(null));
+
+
+
+
+ public Style SearchButtonStyle
+ {
+ get { return (Style)GetValue(SearchButtonStyleProperty); }
+ set { SetValue(SearchButtonStyleProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for SearchButtonStyle. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty SearchButtonStyleProperty =
+ DependencyProperty.Register("SearchButtonStyle", typeof(Style), typeof(SearchControl), new PropertyMetadata(null));
+
+
+
+
+ #endregion
+ }
+}
diff --git a/YC.WPF.Theme/CustomControl/SearchControl/SearchControlStyle.xaml b/YC.WPF.Theme/CustomControl/SearchControl/SearchControlStyle.xaml
new file mode 100644
index 0000000..9a8e7b4
--- /dev/null
+++ b/YC.WPF.Theme/CustomControl/SearchControl/SearchControlStyle.xaml
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/YC.WPF.Theme/CustomControl/TextBox/TextBoxStyles.xaml b/YC.WPF.Theme/CustomControl/TextBox/TextBoxStyles.xaml
new file mode 100644
index 0000000..a6738cf
--- /dev/null
+++ b/YC.WPF.Theme/CustomControl/TextBox/TextBoxStyles.xaml
@@ -0,0 +1,160 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/YC.WPF.Theme/CustomControl/TitleContent/TitleContent.cs b/YC.WPF.Theme/CustomControl/TitleContent/TitleContent.cs
new file mode 100644
index 0000000..8eed02b
--- /dev/null
+++ b/YC.WPF.Theme/CustomControl/TitleContent/TitleContent.cs
@@ -0,0 +1,163 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:TitleContent
+// 创 建 者:杨程
+// 创建时间:2021/10/14 9:33:10
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+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.Media;
+
+namespace Vampirewal.Core.WPF.Theme.CustomControl
+{
+ ///
+ /// 带标题的内容控件
+ ///
+ public class TitleContent : ContentControl
+ {
+ static TitleContent()
+ {
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(TitleContent), new FrameworkPropertyMetadata(typeof(TitleContent)));
+ }
+
+ private ResourceDictionary res
+ {
+ get
+ {
+ return new ResourceDictionary() { Source = new Uri("pack://application:,,,/Vampirewal.Core;component/WpfTheme/CoreTheme.xaml", UriKind.RelativeOrAbsolute) };
+ }
+ }
+
+ public TitleContent()
+ {
+ //构造函数
+ var TitleContentStyle = res["TitleContentStyle"] as Style;
+
+ this.Style = TitleContentStyle;
+ }
+
+
+ public override void OnApplyTemplate()
+ {
+ base.OnApplyTemplate();
+
+ //var title = this.Template.FindName("Title", this) as TextBlock;
+ //title.Text = Title;
+ //if (TitleWidth > 0)
+ //{
+ // //title.Width = TitleWidth;
+ // Binding widthBind = new Binding("TitleWidth");
+ // widthBind.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor);
+ // widthBind.RelativeSource.AncestorType = typeof(TitleContent);
+ // title.SetBinding(TextBlock.WidthProperty, widthBind);
+ //}
+ }
+
+
+
+ public string Title
+ {
+ get { return (string)GetValue(TitleProperty); }
+ set { SetValue(TitleProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for Title. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty TitleProperty =
+ DependencyProperty.Register("Title", typeof(string), typeof(TitleContent), new PropertyMetadata(""));
+
+ private static void TitlePropertyCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ if (d is TitleContent && e.NewValue != null)
+ {
+ var control = d as TitleContent;
+ control.SetValue(TitleContent.TitleProperty, e.NewValue);
+ }
+ }
+
+
+ public double TitleWidth
+ {
+ get { return (double)GetValue(TitleWidthProperty); }
+ set { SetValue(TitleWidthProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for TitleWidth. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty TitleWidthProperty =
+ DependencyProperty.Register("TitleWidth", typeof(double), typeof(TitleContent), new PropertyMetadata(0d));
+
+ private static void TitleWidthCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ if (d is TitleContent && e.NewValue != null)
+ {
+ var control = d as TitleContent;
+ control.SetValue(TitleContent.TitleWidthProperty, e.NewValue);
+ }
+ }
+
+ public VerticalAlignment TitleVerticalAlignment
+ {
+ get { return (VerticalAlignment)GetValue(MyPropertyProperty); }
+ set { SetValue(MyPropertyProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for TitleVerticalAlignment. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty MyPropertyProperty =
+ DependencyProperty.Register("TitleVerticalAlignment", typeof(VerticalAlignment), typeof(TitleContent), new PropertyMetadata(VerticalAlignment.Center));
+
+
+
+ public Thickness TitlePadding
+ {
+ get { return (Thickness)GetValue(TitlePaddingProperty); }
+ set { SetValue(TitlePaddingProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for TitlePadding. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty TitlePaddingProperty =
+ DependencyProperty.Register("TitlePadding", typeof(Thickness), typeof(TitleContent), new PropertyMetadata(new Thickness(0, 0, 10, 0)));
+
+
+
+
+ public Brush TitleForeground
+ {
+ get { return (Brush)GetValue(TitleForegroundProperty); }
+ set { SetValue(TitleForegroundProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for TitleForeground. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty TitleForegroundProperty =
+ DependencyProperty.Register("TitleForeground", typeof(Brush), typeof(TitleContent), new PropertyMetadata(Brushes.Black));
+
+
+
+
+ #region 属性
+
+ #endregion
+
+ #region 公共方法
+
+ #endregion
+
+ #region 私有方法
+
+ #endregion
+
+ #region 命令
+
+ #endregion
+ }
+}
diff --git a/YC.WPF.Theme/CustomControl/TitleContent/TitleContents.xaml b/YC.WPF.Theme/CustomControl/TitleContent/TitleContents.xaml
new file mode 100644
index 0000000..e8a4b8e
--- /dev/null
+++ b/YC.WPF.Theme/CustomControl/TitleContent/TitleContents.xaml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/YC.WPF.Theme/CustomControl/TreeView/TreeViewStyles.xaml b/YC.WPF.Theme/CustomControl/TreeView/TreeViewStyles.xaml
new file mode 100644
index 0000000..e4d5f0a
--- /dev/null
+++ b/YC.WPF.Theme/CustomControl/TreeView/TreeViewStyles.xaml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/YC.WPF.Theme/FrameworkControl/CustomWinodw/WindowBase.cs b/YC.WPF.Theme/FrameworkControl/CustomWinodw/WindowBase.cs
index e8a4ebb..6718abf 100644
--- a/YC.WPF.Theme/FrameworkControl/CustomWinodw/WindowBase.cs
+++ b/YC.WPF.Theme/FrameworkControl/CustomWinodw/WindowBase.cs
@@ -45,10 +45,10 @@ namespace Vampirewal.Core.WPF.Theme.FrameworkControl.CustomWindow
///
public List BottomCustomAreas { get; set; } = new List();
- /////
- ///// 数据上下文
- /////
- //public virtual ViewModelBase DataSource { get; set; }
+ ///
+ /// 数据上下文
+ ///
+ public virtual ViewModelBase DataSource { get; set; }
///
/// 窗体ID
@@ -82,19 +82,26 @@ namespace Vampirewal.Core.WPF.Theme.FrameworkControl.CustomWindow
this.Style = BaseStyle;
-
+ this.IsVisibleChanged += WindowBase_IsVisibleChanged;
}
- protected virtual void Window_Loaded(object sender, RoutedEventArgs e)
+ private void WindowBase_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
- ViewModelBase vm = this.DataContext as ViewModelBase;
- if (vm != null)
+ if ((bool)e.NewValue)
{
- vm.View = this;
- //WindowsManager.RegisterWindow(this);
+ if (DataSource != null)
+ {
+ DataSource.View = Window.GetWindow(this);
+ SetValue(FrameworkElement.DataContextProperty, DataSource);
+ }
}
}
+ protected virtual void Window_Loaded(object sender, RoutedEventArgs e)
+ {
+
+ }
+
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
@@ -183,8 +190,9 @@ namespace Vampirewal.Core.WPF.Theme.FrameworkControl.CustomWindow
{
CloseWindowCommand?.Execute(CloseWindowCommandParameter);
- WindowsManager.GetInstance().CloseWindow(this);
- //this.Close();
+ //WindowsManager.GetInstance().CloseWindow(this);
+ this.Close();
+ GC.Collect();
}
//protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
//{
diff --git a/YC.WPF.Theme/Theme.xaml b/YC.WPF.Theme/Theme.xaml
index 42e578a..4f77b32 100644
--- a/YC.WPF.Theme/Theme.xaml
+++ b/YC.WPF.Theme/Theme.xaml
@@ -3,7 +3,7 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/CalendarControl/Calendar.xaml.cs b/Vampirewal.Core/WpfTheme/CustomControl/CalendarControl/Calendar.xaml.cs
new file mode 100644
index 0000000..91f4c42
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/CustomControl/CalendarControl/Calendar.xaml.cs
@@ -0,0 +1,46 @@
+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 Vampirewal.Core.WpfTheme.CustomControl
+{
+ ///
+ /// Calendar.xaml 的交互逻辑
+ ///
+ public partial class Calendar : UserControl
+ {
+ public Calendar()
+ {
+ InitializeComponent();
+ }
+
+ #region 依赖属性
+
+
+ #endregion
+
+ public DateTime CurrentDateTime { get; set; } = DateTime.Today;
+
+
+ private void UserControl_Loaded(object sender, RoutedEventArgs e)
+ {
+ YearMonthTitle.Text = CurrentDateTime.ToString("yyyy年MM月");
+ }
+
+ private void ShangYiNianBtn_Click(object sender, RoutedEventArgs e)
+ {
+ CurrentDateTime = CurrentDateTime.AddYears(-1);
+ }
+ }
+}
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/EditPage/EditContainer.cs b/Vampirewal.Core/WpfTheme/CustomControl/EditPage/EditContainer.cs
new file mode 100644
index 0000000..69d33a2
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/CustomControl/EditPage/EditContainer.cs
@@ -0,0 +1,362 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:EditContainer
+// 创 建 人:YangCheng
+// 创建时间:2022/6/30 16:27:07
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+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.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+
+namespace Vampirewal.Core.WpfTheme.CustomControl
+{
+ ///
+ ///
+ ///
+ public class EditContainer:ListBox
+ {
+ private class LocationInfo
+ {
+ public double SettingsItemLocation { get; set; }
+
+ public double SettingsContainerLocation { get; set; }
+
+ public RadioButton SettingsRb { get; set; }
+ }
+
+ #region Properties
+
+ ///
+ /// 属性项目标注,KeyValuePair:key对应容器坐标,value选择项目坐标
+ ///
+ private Dictionary _dicSettingsItemContainerPoint;
+ ///
+ /// 设置选项定位名
+ ///
+ private string _locationName;
+ private Border _cursor;
+ private ItemsPresenter _itemP;
+ private bool sbRunning;
+ ///
+ /// 内容项Y轴的偏移量
+ ///
+ private double _tmpYOffset;
+ ///
+ /// 最后一项高度偏移高度
+ ///
+ private double _lastItemHeightOffset;
+
+ #region 动画元素
+ private EasingDoubleKeyFrame _settingsLocationEasing;
+ private Storyboard _settingsLocation;
+ private Storyboard _mouseWheelMove;
+ private EasingDoubleKeyFrame _mouseWheelMoveEasing;
+ private Storyboard _location;
+ private EasingDoubleKeyFrame _locationEasing;
+ #endregion
+
+ #endregion
+
+ public EditContainer()
+ {
+ //构造函数
+ Loaded += EditContainer_Loaded;
+ }
+
+ private void EditContainer_Loaded(object sender, System.Windows.RoutedEventArgs e)
+ {
+ Loaded -= EditContainer_Loaded;
+ _dicSettingsItemContainerPoint = new Dictionary();
+ _mouseWheelMove = CreateSettingsItemStoryboard(0);
+ _location = CreateSettingsItemStoryboard(0);
+ _settingsLocation = CreateStoryboard(0);
+
+ if (_mouseWheelMove.Children.First() is DoubleAnimationUsingKeyFrames key &&
+ key.KeyFrames[0] is EasingDoubleKeyFrame eas &&
+ _location.Children.First() is DoubleAnimationUsingKeyFrames lKey &&
+ lKey.KeyFrames[0] is EasingDoubleKeyFrame lEas &&
+ _settingsLocation.Children.First() is DoubleAnimationUsingKeyFrames sKey &&
+ sKey.KeyFrames[0] is EasingDoubleKeyFrame sEas &&
+ Template.FindName("itemsP", this) is ItemsPresenter ip &&
+ Template.FindName("br_Cursor", this) is Border br &&
+ Template.FindName("editItemsContainer", this) is StackPanel sp &&
+ Template.Resources["RbTabStyle"] is Style rbStyle &&
+ Template.FindName("sv", this) is Grid sv)
+ {
+ _itemP = ip;
+ _itemP.SizeChanged += Can_SizeChanged;
+ _cursor = br;
+ eas.KeyTime = TimeSpan.Parse("0:0:0");
+ _mouseWheelMoveEasing = eas;
+ _locationEasing = lEas;
+ _settingsLocationEasing = sEas;
+ _location.Completed += _sb2_Completed;
+
+ for (int i = 0; i < ItemContainerGenerator.Items.Count; i++)
+ {
+ var editItem = ItemContainerGenerator.ContainerFromIndex(i) as EditItem;
+ editItem.Width = sv.ActualWidth;
+ var rbTmp = CreateTitle(rbStyle, editItem);
+ sp.Children.Add(rbTmp);
+ }
+ sv.AddHandler(Grid.PreviewMouseWheelEvent, new MouseWheelEventHandler(Sv_PreviewMouseWheel));
+ sv.SizeChanged += Sv_SizeChanged;
+ //if (!string.IsNullOrEmpty(_locationName))
+ // RunStoryboard(_locationName);
+ }
+ }
+
+ private void Can_SizeChanged(object sender, SizeChangedEventArgs e)
+ {
+ if (Template.FindName("editItemsContainer", this) is StackPanel sp &&
+ Template.Resources["RbTabStyle"] is Style rbStyle &&
+ Template.FindName("sv", this) is Grid sv)
+ {
+ sp.Children.Clear();
+ _dicSettingsItemContainerPoint.Clear();
+ for (int i = 0; i < ItemContainerGenerator.Items.Count; i++)
+ {
+ var editItem = ItemContainerGenerator.ContainerFromIndex(i) as EditItem;
+ editItem.Width = sv.ActualWidth;
+ var rbTmp = CreateTitle(rbStyle, editItem);
+ sp.Children.Add(rbTmp);
+ sp.UpdateLayout();
+ _dicSettingsItemContainerPoint.Add(rbTmp.Tag.ToString(), new LocationInfo()
+ {
+ SettingsContainerLocation = 0 - editItem.TranslatePoint(new Point(0, 0), sp).Y,
+ SettingsItemLocation = rbTmp.TranslatePoint(new Point(0, 0), sp).Y,
+ SettingsRb = rbTmp
+ });
+ _lastItemHeightOffset = editItem.ActualHeight - this.ActualHeight;
+ }
+ }
+ }
+
+ private void Sv_SizeChanged(object sender, SizeChangedEventArgs e)
+ {
+ for (int i = 0; i < ItemContainerGenerator.Items.Count; i++)
+ {
+ var editItem = ItemContainerGenerator.ContainerFromIndex(i) as EditItem;
+ editItem.Width = e.NewSize.Width;
+ }
+ }
+
+ private void Sv_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
+ {
+ if (!sbRunning)
+ {
+ if (e.Delta > 0 && _tmpYOffset <= 0)
+ {
+ _tmpYOffset = (_tmpYOffset + 48) > 0 ? 0 : _tmpYOffset + 48;
+ }
+ else if (e.Delta < 0 && _tmpYOffset >= _dicSettingsItemContainerPoint.Last().Value.SettingsContainerLocation)
+ {
+ _tmpYOffset = (_tmpYOffset - 48) <= _dicSettingsItemContainerPoint.Last().Value.SettingsContainerLocation ? _dicSettingsItemContainerPoint.Last().Value.SettingsContainerLocation : _tmpYOffset - 48;
+ }
+ if (_tmpYOffset <= 0)
+ {
+ var top = _dicSettingsItemContainerPoint.Last(t => t.Value.SettingsContainerLocation >= _tmpYOffset - 96);
+ if (_settingsLocationEasing.Value != top.Value.SettingsItemLocation)
+ {
+ _settingsLocationEasing.Value = top.Value.SettingsItemLocation;
+ top.Value.SettingsRb.IsChecked = true;
+ _settingsLocation.Begin(_cursor);
+ }
+ _mouseWheelMoveEasing.Value = _tmpYOffset;
+ _mouseWheelMove.Begin(_itemP);
+ }
+ }
+ e.Handled = true;
+ }
+ private void RunStoryboard(string settingsItemName)
+ {
+ _settingsLocationEasing.Value = _dicSettingsItemContainerPoint[settingsItemName].SettingsItemLocation;
+ _settingsLocation.Begin(_cursor);
+
+ _tmpYOffset = _dicSettingsItemContainerPoint[settingsItemName].SettingsContainerLocation;
+ _locationEasing.Value = _tmpYOffset;
+ _dicSettingsItemContainerPoint[settingsItemName].SettingsRb.IsChecked = true;
+ sbRunning = true;
+ _location.Begin(_itemP);
+ }
+
+ private void _sb2_Completed(object sender, EventArgs e)
+ {
+ sbRunning = false;
+ }
+
+
+ #region Tools
+
+ private RadioButton CreateTitle(Style rbStyle, EditItem item)
+ {
+ RadioButton rb = new RadioButton();
+ rb.Tag = Guid.NewGuid().ToString();
+ Binding bind = new Binding("Visibility");
+ bind.Source = item;
+ rb.SetBinding(RadioButton.VisibilityProperty, bind);
+ rb.GroupName = "EditPageGroup";
+ rb.Style = rbStyle;
+ rb.Content = item.HeaderText;
+ rb.Click += StackPanel_Checked;
+ return rb;
+ }
+
+ private void StackPanel_Checked(object sender, RoutedEventArgs e)
+ {
+ if (e.OriginalSource is RadioButton btn)
+ {
+ RunStoryboard(btn.Tag.ToString());
+ }
+ }
+
+ #region 动画创建
+ private Storyboard CreateStoryboard(double y)
+ {
+ Storyboard sb = new Storyboard();
+ DoubleAnimationUsingKeyFrames keyFrames = new DoubleAnimationUsingKeyFrames();
+ EasingDoubleKeyFrame doubleKeyFrame = new EasingDoubleKeyFrame();
+ doubleKeyFrame.KeyTime = TimeSpan.Parse("0:0:0.7");
+ doubleKeyFrame.Value = y;
+ BackEase effect = new BackEase();
+ effect.EasingMode = EasingMode.EaseOut;
+ effect.Amplitude = 0.4;
+ doubleKeyFrame.EasingFunction = effect;
+ keyFrames.KeyFrames.Add(doubleKeyFrame);
+ Storyboard.SetTargetProperty(keyFrames, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)"));
+ Storyboard.SetTarget(keyFrames, _cursor);
+ sb.Children.Add(keyFrames);
+ return sb;
+ }
+ private Storyboard CreateSettingsItemStoryboard(double y)
+ {
+ Storyboard sb = new Storyboard();
+ DoubleAnimationUsingKeyFrames keyFrames = new DoubleAnimationUsingKeyFrames();
+ EasingDoubleKeyFrame doubleKeyFrame = new EasingDoubleKeyFrame();
+ doubleKeyFrame.KeyTime = TimeSpan.Parse("0:0:0.5");
+ doubleKeyFrame.Value = y;
+ BackEase effect = new BackEase();
+ effect.EasingMode = EasingMode.EaseInOut;
+ effect.Amplitude = 0.2;
+ doubleKeyFrame.EasingFunction = effect;
+ keyFrames.KeyFrames.Add(doubleKeyFrame);
+ Storyboard.SetTargetProperty(keyFrames, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)"));
+ Storyboard.SetTarget(keyFrames, _itemP);
+ sb.Children.Add(keyFrames);
+ return sb;
+ }
+ #endregion
+
+ #endregion
+
+ static EditContainer()
+ {
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(EditContainer), new FrameworkPropertyMetadata(typeof(EditContainer)));
+ }
+
+ protected override bool IsItemItsOwnContainerOverride(object item)
+ {
+ return item is EditItem;
+ }
+
+ protected override DependencyObject GetContainerForItemOverride()
+ {
+ return new EditItem();
+ }
+
+
+ #region 依赖属性
+
+ #region 左侧
+
+ ///
+ /// 左侧背景色
+ ///
+ public Brush LeftBackground
+ {
+ get { return (Brush)GetValue(LeftBackgroundProperty); }
+ set { SetValue(LeftBackgroundProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for LeftBackground. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty LeftBackgroundProperty =
+ DependencyProperty.Register("LeftBackground", typeof(Brush), typeof(EditContainer), new PropertyMetadata(Brushes.WhiteSmoke));
+
+
+
+ ///
+ /// 左侧前景色
+ ///
+ public Brush LeftForeground
+ {
+ get { return (Brush)GetValue(LeftForegroundProperty); }
+ set { SetValue(LeftForegroundProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for LeftForeground. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty LeftForegroundProperty =
+ DependencyProperty.Register("LeftForeground", typeof(Brush), typeof(EditContainer), new PropertyMetadata(Brushes.Black));
+
+
+
+
+ public Brush MouseOverColor
+ {
+ get { return (Brush)GetValue(MouseOverColorProperty); }
+ set { SetValue(MouseOverColorProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for MouseOverColor. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty MouseOverColorProperty =
+ DependencyProperty.Register("MouseOverColor", typeof(Brush), typeof(EditContainer), new PropertyMetadata(Brushes.Chocolate));
+
+
+
+
+ public Brush CheckedColor
+ {
+ get { return (Brush)GetValue(CheckedColorProperty); }
+ set { SetValue(CheckedColorProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for CheckedColor. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty CheckedColorProperty =
+ DependencyProperty.Register("CheckedColor", typeof(Brush), typeof(EditContainer), new PropertyMetadata(Brushes.Chocolate));
+
+
+ #endregion
+
+ #region 中间
+
+
+ public Brush ContainerBackground
+ {
+ get { return (Brush)GetValue(ContainerBackgroundProperty); }
+ set { SetValue(ContainerBackgroundProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for ContainerBackground. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty ContainerBackgroundProperty =
+ DependencyProperty.Register("ContainerBackground", typeof(Brush), typeof(EditContainer), new PropertyMetadata(Brushes.White));
+
+
+ #endregion
+
+ #endregion
+ }
+}
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/EditPage/EditContaninerStyle.xaml b/Vampirewal.Core/WpfTheme/CustomControl/EditPage/EditContaninerStyle.xaml
new file mode 100644
index 0000000..e17a556
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/CustomControl/EditPage/EditContaninerStyle.xaml
@@ -0,0 +1,251 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/EditPage/EditItem.cs b/Vampirewal.Core/WpfTheme/CustomControl/EditPage/EditItem.cs
new file mode 100644
index 0000000..1b49eb7
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/CustomControl/EditPage/EditItem.cs
@@ -0,0 +1,82 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:EditItem
+// 创 建 人:YangCheng
+// 创建时间:2022/6/30 16:34:59
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+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.Input;
+using System.Windows.Media;
+
+namespace Vampirewal.Core.WpfTheme.CustomControl
+{
+ ///
+ ///
+ ///
+ public class EditItem : ListBoxItem
+ {
+ public string HeaderText { get; set; }
+
+ static EditItem()
+ {
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(EditItem), new FrameworkPropertyMetadata(typeof(EditItem)));
+ }
+
+ public override void OnApplyTemplate()
+ {
+ base.OnApplyTemplate();
+ if (Template.FindName("tb_Header", this) is TextBlock tb)
+ {
+ tb.Text = HeaderText;
+ }
+ }
+
+ //屏蔽选中跳转效果
+ protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
+ {
+ e.Handled = true;
+ }
+
+ #region 依赖属性
+
+
+ public Brush IconColor
+ {
+ get { return (Brush)GetValue(IconColorProperty); }
+ set { SetValue(IconColorProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for IconColor. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty IconColorProperty =
+ DependencyProperty.Register("IconColor", typeof(Brush), typeof(EditItem), new PropertyMetadata(Brushes.CadetBlue));
+
+
+
+
+ public Brush TitleColor
+ {
+ get { return (Brush)GetValue(TitleColorProperty); }
+ set { SetValue(TitleColorProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for TitleColor. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty TitleColorProperty =
+ DependencyProperty.Register("TitleColor", typeof(Brush), typeof(EditItem), new PropertyMetadata(Brushes.DarkBlue));
+
+
+ #endregion
+ }
+}
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/LoadingContainer/LoadingContainer.cs b/Vampirewal.Core/WpfTheme/CustomControl/LoadingContainer/LoadingContainer.cs
new file mode 100644
index 0000000..1eb4743
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/CustomControl/LoadingContainer/LoadingContainer.cs
@@ -0,0 +1,112 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:LoadingContainer
+// 创 建 人:YangCheng
+// 创建时间:2022/6/30 17:20:46
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Controls;
+using System.Windows.Media.Animation;
+using System.Windows;
+
+namespace Vampirewal.Core.WpfTheme.CustomControl
+{
+ ///
+ ///
+ ///
+ public class LoadingContainer : ContentControl
+ {
+
+
+ public LoadingContainer()
+ {
+ //构造函数
+ }
+
+ private Storyboard _sbOnloading;
+ private Border _maskContainer;
+
+ static LoadingContainer()
+ {
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(LoadingContainer), new FrameworkPropertyMetadata(typeof(LoadingContainer)));
+ }
+
+ public override void OnApplyTemplate()
+ {
+ base.OnApplyTemplate();
+ if (Template.Resources["OnLoading"] is Storyboard sb
+ && Template.FindName("MaskDG", this) is Border gd)
+ {
+ _sbOnloading = sb;
+ _maskContainer = gd;
+ _maskContainer.Visibility = Visibility.Hidden;
+ }
+ }
+
+ #region Properties
+
+ public string LoadingTips
+ {
+ get { return (string)GetValue(LoadingTipsProperty); }
+ set { SetValue(LoadingTipsProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for LoadingTips. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty LoadingTipsProperty =
+ DependencyProperty.Register("LoadingTips", typeof(string), typeof(LoadingContainer), new PropertyMetadata("加载中,请稍等"));
+
+ public bool OnLoading
+ {
+ get { return (bool)GetValue(OnLoadingProperty); }
+ set { SetValue(OnLoadingProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for OnLoading. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty OnLoadingProperty =
+ DependencyProperty.Register("OnLoading", typeof(bool), typeof(LoadingContainer), new PropertyMetadata(OnloadingCallback));
+
+ private static void OnloadingCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ if (d is LoadingContainer fl)
+ {
+ if (e.NewValue.Equals(true))
+ fl.StartupOnLoading();
+ else
+ fl.StopOnLoading();
+ }
+ }
+
+ #endregion
+
+ #region Tools
+ private void StartupOnLoading()
+ {
+ if (_sbOnloading != null)
+ {
+ _maskContainer.Visibility = Visibility.Visible;
+ _sbOnloading.Begin(_maskContainer);
+ }
+ }
+
+ private void StopOnLoading()
+ {
+ if (_sbOnloading != null)
+ {
+ _sbOnloading.Stop(_maskContainer);
+ _maskContainer.Visibility = Visibility.Hidden;
+ }
+ }
+ #endregion
+ }
+}
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/LoadingContainer/LoadingContainerStyle.xaml b/Vampirewal.Core/WpfTheme/CustomControl/LoadingContainer/LoadingContainerStyle.xaml
new file mode 100644
index 0000000..25438b4
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/CustomControl/LoadingContainer/LoadingContainerStyle.xaml
@@ -0,0 +1,541 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Vampirewal.Core/WpfTheme/WindowStyle/MainWindowBase.cs b/Vampirewal.Core/WpfTheme/WindowStyle/MainWindowBase.cs
index 9812fe4..1a5e34e 100644
--- a/Vampirewal.Core/WpfTheme/WindowStyle/MainWindowBase.cs
+++ b/Vampirewal.Core/WpfTheme/WindowStyle/MainWindowBase.cs
@@ -58,6 +58,20 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
var BaseStyle = res["MainWindow"] as Style;
this.Style = BaseStyle;
+
+ this.IsVisibleChanged += MainWindowBase_IsVisibleChanged;
+ }
+
+ private void MainWindowBase_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
+ {
+ if ((bool)e.NewValue)
+ {
+ if (DataSource != null)
+ {
+ DataSource.View = Window.GetWindow(this);
+ SetValue(FrameworkElement.DataContextProperty, DataSource);
+ }
+ }
}
public override void OnApplyTemplate()
@@ -176,6 +190,10 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
DependencyProperty.Register("MainAreaHeight", typeof(int), typeof(MainWindowBase), new PropertyMetadata(80));
#endregion
+
+
+
+
#endregion
}
}
diff --git a/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml.cs b/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml.cs
index e571cbd..a458a99 100644
--- a/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml.cs
+++ b/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml.cs
@@ -19,7 +19,7 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
///
/// ShowDialogWindow.xaml 的交互逻辑
///
- public partial class ShowDialogWindow : WindowBase
+ public partial class ShowDialogWindow : Vampirewal.Core.WpfTheme.WindowStyle.WindowBase
{
///
/// 构造函数
@@ -58,10 +58,14 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
else
{
this.DataContext = Setting.UiView.DataContext;
+
}
ViewModelBase vm = Setting.UiView.DataContext as ViewModelBase;
+ vm.ViewId = this.ViewId;
//vm.View = this;
+ if(vm.View==null)
+ vm.View = UcBase;
vm.PassData(Setting.PassData);
diff --git a/Vampirewal.Core/WpfTheme/WindowStyle/WindowBase.cs b/Vampirewal.Core/WpfTheme/WindowStyle/WindowBase.cs
index 49853f5..89a971e 100644
--- a/Vampirewal.Core/WpfTheme/WindowStyle/WindowBase.cs
+++ b/Vampirewal.Core/WpfTheme/WindowStyle/WindowBase.cs
@@ -87,16 +87,16 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
private void WindowBase_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
- if ((bool)e.NewValue)
- {
- if (DataSource != null)
- {
- DataSource.View = Window.GetWindow(this);
- SetValue(FrameworkElement.DataContextProperty, DataSource);
- }
+ //if ((bool)e.NewValue)
+ //{
+ // if (DataSource != null)
+ // {
+ // DataSource.View = Window.GetWindow(this);
+ // SetValue(FrameworkElement.DataContextProperty, DataSource);
+ // }
- }
+ //}
}
protected virtual void Window_Loaded(object sender, RoutedEventArgs e)
diff --git a/YC.Core.sln b/YC.Core.sln
index bd60475..ecaa04e 100644
--- a/YC.Core.sln
+++ b/YC.Core.sln
@@ -25,7 +25,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test.Console", "Test.Consol
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "test.View2", "test.View2\test.View2.csproj", "{E2EFCFE0-FECA-485D-A60D-3480A81906FB}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vampirewal.Core.OperationExcelService", "Vampirewal.Core.OperationExcelService\Vampirewal.Core.OperationExcelService.csproj", "{898CEEAD-8595-4CD7-A05F-2C40AC0DB640}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vampirewal.Core.OperationExcelService", "Vampirewal.Core.OperationExcelService\Vampirewal.Core.OperationExcelService.csproj", "{898CEEAD-8595-4CD7-A05F-2C40AC0DB640}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vampirewal.Core.HttpClientService", "Vampirewal.Core.HttpClientService\Vampirewal.Core.HttpClientService.csproj", "{4DE48346-5142-46EB-8AA9-168C7C96728A}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Components", "Components", "{D70678FD-58AC-4EFF-B995-F27A6F15AF4B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -77,15 +81,24 @@ Global
{898CEEAD-8595-4CD7-A05F-2C40AC0DB640}.Debug|Any CPU.Build.0 = Debug|Any CPU
{898CEEAD-8595-4CD7-A05F-2C40AC0DB640}.Release|Any CPU.ActiveCfg = Release|Any CPU
{898CEEAD-8595-4CD7-A05F-2C40AC0DB640}.Release|Any CPU.Build.0 = Release|Any CPU
+ {4DE48346-5142-46EB-8AA9-168C7C96728A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {4DE48346-5142-46EB-8AA9-168C7C96728A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4DE48346-5142-46EB-8AA9-168C7C96728A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {4DE48346-5142-46EB-8AA9-168C7C96728A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{B622E036-C59A-4E28-8F68-AFC5392D0410} = {DFE920C8-C41C-4596-86AF-BAF20E305BDC}
+ {B0CAFD0E-6AE7-4822-987D-EC2D130180BC} = {D70678FD-58AC-4EFF-B995-F27A6F15AF4B}
+ {1C734B76-1190-4765-9CFA-9D8AA30F7A5B} = {D70678FD-58AC-4EFF-B995-F27A6F15AF4B}
{62C0421C-BB07-4426-83CE-8544E09C5B70} = {DFE920C8-C41C-4596-86AF-BAF20E305BDC}
+ {1753A047-A48F-4361-B47B-0D02EECD3D36} = {D70678FD-58AC-4EFF-B995-F27A6F15AF4B}
{3DC097DC-5236-4B09-B9FC-3E9393D179A0} = {DFE920C8-C41C-4596-86AF-BAF20E305BDC}
{E2EFCFE0-FECA-485D-A60D-3480A81906FB} = {DFE920C8-C41C-4596-86AF-BAF20E305BDC}
+ {898CEEAD-8595-4CD7-A05F-2C40AC0DB640} = {D70678FD-58AC-4EFF-B995-F27A6F15AF4B}
+ {4DE48346-5142-46EB-8AA9-168C7C96728A} = {D70678FD-58AC-4EFF-B995-F27A6F15AF4B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F95EFBE7-9DF8-4104-AFCC-ADE3D80BD902}
diff --git a/test.View2/aaView.xaml b/test.View2/aaView.xaml
index 55b21d4..e239de7 100644
--- a/test.View2/aaView.xaml
+++ b/test.View2/aaView.xaml
@@ -20,7 +20,7 @@
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test.View2/aaViewModel.cs b/test.View2/aaViewModel.cs
index 8401f1c..ef973fb 100644
--- a/test.View2/aaViewModel.cs
+++ b/test.View2/aaViewModel.cs
@@ -11,12 +11,14 @@
//----------------------------------------------------------------*/
#endregion
+using HandyControl.Controls;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Vampirewal.Core.Interface;
using Vampirewal.Core.IoC;
using Vampirewal.Core.SimpleMVVM;
//using Vampirewal.Core.VContainer;
@@ -29,29 +31,31 @@ namespace test.View2
[VampirewalIoCRegister("aaViewModel", RegisterType.ViewModel)]
public class aaViewModel:ViewModelBase
{
- public aaViewModel()
+ private IDialogMessage Dialog { get; set; }
+ public aaViewModel(IDialogMessage dialog)
{
+ Dialog = dialog;
//构造函数
aatests = new ObservableCollection();
- for (int i = 0; i < 10; i++)
- {
-
- var aaa = new aatest()
- {
- aaName = $"a{i}"
- };
- if (i < 5)
- {
- aaa.sort = 1;
- }
- else
- {
- aaa.sort = 2;
- }
-
- aatests.Add(aaa);
- }
+ //for (int i = 0; i < 10; i++)
+ //{
+
+ // var aaa = new aatest()
+ // {
+ // aaName = $"a{i}"
+ // };
+ // if (i < 5)
+ // {
+ // aaa.sort = 1;
+ // }
+ // else
+ // {
+ // aaa.sort = 2;
+ // }
+
+ // aatests.Add(aaa);
+ //}
}
public override object GetResult()
@@ -72,7 +76,17 @@ namespace test.View2
#endregion
#region Command命令
+ public RelayCommand aaCommand => new RelayCommand(() =>
+ {
+ Dialog.ShowPopupWindow("hahaa",WindowsManager.GetInstance().GetDialogWindow(ViewId), Vampirewal.Core.WpfTheme.WindowStyle.MessageType.Successful);
+ //CloseView();
+ });
+
+ protected override void CloseView()
+ {
+ WindowsManager.GetInstance().CloseDialogWindow(ViewId);
+ }
#endregion
}
diff --git a/test.ViewModel/MainViewModel.cs b/test.ViewModel/MainViewModel.cs
index 1fa607a..12a6c7f 100644
--- a/test.ViewModel/MainViewModel.cs
+++ b/test.ViewModel/MainViewModel.cs
@@ -29,6 +29,7 @@ using Vampirewal.Core.Attributes;
//using Vampirewal.Core.VContainer;
using Vampirewal.Core.IoC;
using Vampirewal.Core.OperationExcelService;
+using System.Threading.Tasks;
namespace test
{
@@ -377,9 +378,12 @@ namespace test
public RelayCommand CloseWindowCommand => new RelayCommand((o) =>
{
- var aaa = View;
+ //var aaa = View;
+
});
+
+
//测试能力图
public ObservableCollection RadarModels { get; set; }
@@ -418,7 +422,22 @@ namespace test
CloseWindowCommand = CloseWindowCommand,
CloseWindowCommandParameter = "aaa"
});
+ //IsOnLoading = !IsOnLoading;
+
+ //Task.Delay(2000);
+
+
+ //IsOnLoading = false;
});
+
+ private bool _IsOnLoading=false;
+
+ public bool IsOnLoading
+ {
+ get { return _IsOnLoading; }
+ set { _IsOnLoading = value; DoNotify(); }
+ }
+
}
diff --git a/test.ViewModel/ViewModelLocator.cs b/test.ViewModel/ViewModelLocator.cs
index 9c6a430..c81f23a 100644
--- a/test.ViewModel/ViewModelLocator.cs
+++ b/test.ViewModel/ViewModelLocator.cs
@@ -59,7 +59,7 @@ namespace test.ViewModel
public override void InitRegisterViewModel()
{
-
+ //VampirewalIoC.GetInstance().Register("MainViewModel2", RegisterType.ViewModel);
//WindowsManager.GetInstance().SetViewModulePath(VIoC.GetInstance().GetInstance().ViewModulesPath);
diff --git a/test/App.xaml b/test/App.xaml
index 82d255a..2f8acd5 100644
--- a/test/App.xaml
+++ b/test/App.xaml
@@ -14,8 +14,8 @@
-
-
+
diff --git a/test/App.xaml.cs b/test/App.xaml.cs
index f203e8c..7b65b35 100644
--- a/test/App.xaml.cs
+++ b/test/App.xaml.cs
@@ -37,5 +37,10 @@ namespace test
//string aa = Messenger.Default.Send("aatest");
}
+ protected override void GlobalExceptions(object sender, DispatcherUnhandledExceptionEventArgs e)
+ {
+ e.Handled = true;
+ }
+
}
}
diff --git a/test/MainWindow.xaml b/test/MainWindow.xaml
index b7c71e3..be0ce68 100644
--- a/test/MainWindow.xaml
+++ b/test/MainWindow.xaml
@@ -72,7 +72,7 @@
BorderBrush="Gray"
Datas="{Binding RadarModels}" />
-->
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/MainWindow.xaml.cs b/test/MainWindow.xaml.cs
index 709afc1..8b16b9a 100644
--- a/test/MainWindow.xaml.cs
+++ b/test/MainWindow.xaml.cs
@@ -23,15 +23,14 @@ namespace test
///
/// Interaction logic for MainWindow.xaml
///
- //[RegisterWindow("test.MainWindow1", RegisterWindowType.Window)]
- [VampirewalIoCRegister("MainWindow1", RegisterType.Window,false)]
+ [VampirewalIoCRegister("MainWindow1", RegisterType.Window)]
public partial class MainWindow1 : MainWindowBase
{
public MainWindow1()
{
InitializeComponent();
- InitData();
- SizeChanged += MainWindow1_SizeChanged;
+ //InitData();
+ //SizeChanged += MainWindow1_SizeChanged;
}
@@ -49,69 +48,69 @@ namespace test
}
}
- private void MainWindow1_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- MyGrid.Children.Clear();
- GridTool.Draw(MyGrid);
- DrawCircle(MyGrid);
- DrawPath(MyGrid);
- }
-
- private readonly Polyline _line = new Polyline();
- //private readonly Polygon polygon = new Polygon;
- private readonly PointCollection _collection = new PointCollection();
- private readonly Random _random = new Random();
-
- private void ButtonPath_OnClick(object sender, RoutedEventArgs e)
- {
- _collection.Add(new Point(_random.Next(1, (int)ActualWidth), _random.Next(1, (int)ActualHeight)));
- MyGrid.Children.Clear();
- GridTool.Draw(MyGrid);
- DrawPath(MyGrid);
- }
-
- private void DrawPath(Panel panel)
- {
- _line.Points = _collection;
- _line.Stroke = new SolidColorBrush(Colors.Black);
- _line.StrokeThickness = 1;
- panel.Children.Add(_line);
- }
-
- private void DrawCircle(Panel panel)
- {
- double currentSize = 20d;
-
- var Rectangle = new Rectangle()
- {
- Width = currentSize,
- Height = currentSize,
- Fill = Brushes.Red
- };
+ //private void MainWindow1_SizeChanged(object sender, SizeChangedEventArgs e)
+ //{
+ // MyGrid.Children.Clear();
+ // GridTool.Draw(MyGrid);
+ // DrawCircle(MyGrid);
+ // DrawPath(MyGrid);
+ //}
+
+ //private readonly Polyline _line = new Polyline();
+ ////private readonly Polygon polygon = new Polygon;
+ //private readonly PointCollection _collection = new PointCollection();
+ //private readonly Random _random = new Random();
+
+ //private void ButtonPath_OnClick(object sender, RoutedEventArgs e)
+ //{
+ // _collection.Add(new Point(_random.Next(1, (int)ActualWidth), _random.Next(1, (int)ActualHeight)));
+ // MyGrid.Children.Clear();
+ // GridTool.Draw(MyGrid);
+ // DrawPath(MyGrid);
+ //}
+
+ //private void DrawPath(Panel panel)
+ //{
+ // _line.Points = _collection;
+ // _line.Stroke = new SolidColorBrush(Colors.Black);
+ // _line.StrokeThickness = 1;
+ // panel.Children.Add(_line);
+ //}
+
+ //private void DrawCircle(Panel panel)
+ //{
+ // double currentSize = 20d;
+
+ // var Rectangle = new Rectangle()
+ // {
+ // Width = currentSize,
+ // Height = currentSize,
+ // Fill = Brushes.Red
+ // };
- var translateTransform = new TranslateTransform(20, 20);
- Rectangle.RenderTransform = translateTransform;
-
- panel.Children.Add(Rectangle);
- }
-
- private void ButtonDrawCircle_OnClick(object sender, RoutedEventArgs e)
- {
- MyGrid.Children.Clear();
- //GridTool.DrawCircle(MyGrid);
- }
-
-
- private void InitData()
- {
- _collection.Add(new Point(30, 30));
- _collection.Add(new Point(50, 50));
- //_collection.Add(new Point(60, 40));
- //_collection.Add(new Point(80, 120));
- //_collection.Add(new Point(120, 140));
- //_collection.Add(new Point(200, 180));
- }
+ // var translateTransform = new TranslateTransform(20, 20);
+ // Rectangle.RenderTransform = translateTransform;
+
+ // panel.Children.Add(Rectangle);
+ //}
+
+ //private void ButtonDrawCircle_OnClick(object sender, RoutedEventArgs e)
+ //{
+ // MyGrid.Children.Clear();
+ // //GridTool.DrawCircle(MyGrid);
+ //}
+
+
+ //private void InitData()
+ //{
+ // _collection.Add(new Point(30, 30));
+ // _collection.Add(new Point(50, 50));
+ // //_collection.Add(new Point(60, 40));
+ // //_collection.Add(new Point(80, 120));
+ // //_collection.Add(new Point(120, 140));
+ // //_collection.Add(new Point(200, 180));
+ //}
}
diff --git a/test/TestAddorEditView.xaml b/test/TestAddorEditView.xaml
index 14d079c..5fa17f4 100644
--- a/test/TestAddorEditView.xaml
+++ b/test/TestAddorEditView.xaml
@@ -10,7 +10,7 @@
-
+
+
--
Gitee
From 71bf2af78eb67c0a777b0f0548e1b729b52f6e6d Mon Sep 17 00:00:00 2001
From: YangCheng <235160615@qq.com>
Date: Fri, 15 Jul 2022 10:35:50 +0800
Subject: [PATCH 24/53] 123
---
Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs | 4 ++--
Vampirewal.Core/SimpleMVVM/WindowsManager.cs | 5 ++++
.../WindowStyle/ShowDialogWindow.xaml.cs | 23 +++++++++++--------
test.View2/aaViewModel.cs | 4 ++--
test.ViewModel/MainViewModel.cs | 5 ++--
5 files changed, 24 insertions(+), 17 deletions(-)
diff --git a/Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs b/Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs
index 1cab816..2e63db8 100644
--- a/Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs
+++ b/Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs
@@ -164,7 +164,7 @@ namespace Vampirewal.Core.SimpleMVVM
IsShowMinButton = true,
IsOpenWindowSize = false,
TitleFontSize = 15,
- CloseWindowCommand = new RelayCommand(ExecuteBeforeCloseDialogWindowCommand)
+ CloseDialogWindowCallBackCommand = new RelayCommand(ExecuteBeforeCloseDialogWindowCommand)
};
}
}
@@ -335,7 +335,7 @@ namespace Vampirewal.Core.SimpleMVVM
///
/// 弹窗关闭窗口的时候,先执行这个方法,然后关闭
///
- public virtual void ExecuteBeforeCloseDialogWindowCommand()
+ public virtual void ExecuteBeforeCloseDialogWindowCommand(object obj)
{
}
diff --git a/Vampirewal.Core/SimpleMVVM/WindowsManager.cs b/Vampirewal.Core/SimpleMVVM/WindowsManager.cs
index f1f2130..16c0d4c 100644
--- a/Vampirewal.Core/SimpleMVVM/WindowsManager.cs
+++ b/Vampirewal.Core/SimpleMVVM/WindowsManager.cs
@@ -19,6 +19,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
+using Vampirewal.Core.WpfTheme.WindowStyle;
namespace Vampirewal.Core.SimpleMVVM
{
@@ -535,6 +536,10 @@ namespace Vampirewal.Core.SimpleMVVM
{
if (DialogWindowDic.TryGetValue(ViewId,out Window window))
{
+ var DialogWindow = window as ShowDialogWindow;
+ var vm = DialogWindow.DataContext as ViewModelBase;
+ DialogWindow.CloseDialogWindowCallBackCommand?.Execute(vm.GetResult());
+
window.Close();
DialogWindowDic.Remove(ViewId);
}
diff --git a/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml.cs b/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml.cs
index a458a99..ac549b5 100644
--- a/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml.cs
+++ b/Vampirewal.Core/WpfTheme/WindowStyle/ShowDialogWindow.xaml.cs
@@ -112,16 +112,18 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
this.TitleFontSize = Setting.TitleFontSize;
- if (Setting.CloseWindowCommand!=null)
+ if (Setting.CloseDialogWindowCallBackCommand!=null)
{
- this.CloseWindowCommand = Setting.CloseWindowCommand;
- this.CloseWindowCommandParameter = Setting.CloseWindowCommandParameter;
+ this.CloseDialogWindowCallBackCommand = Setting.CloseDialogWindowCallBackCommand;
+ this.CloseWindowCommandParameter = Setting.CloseDialogWindowCallBackCommandParameter;
}
}
protected override void CloseWin_Click(object sender, RoutedEventArgs e)
{
- CloseWindowCommand?.Execute(CloseWindowCommandParameter);
+
+
+ CloseDialogWindowCallBackCommand?.Execute(CloseWindowCommandParameter);
base.CloseWin_Click(sender, e);
}
@@ -130,14 +132,14 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
///
/// 弹窗关闭的命令
///
- public ICommand CloseWindowCommand
+ public ICommand CloseDialogWindowCallBackCommand
{
- get { return (ICommand)GetValue(CloseWindowCommandProperty); }
- set { SetValue(CloseWindowCommandProperty, value); }
+ get { return (ICommand)GetValue(CloseDialogWindowCallBackProperty); }
+ set { SetValue(CloseDialogWindowCallBackProperty, value); }
}
// Using a DependencyProperty as the backing store for CloseWindowCommand. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty CloseWindowCommandProperty =
+ public static readonly DependencyProperty CloseDialogWindowCallBackProperty =
DependencyProperty.Register("CloseWindowCommand", typeof(ICommand), typeof(ShowDialogWindow), new PropertyMetadata(null));
@@ -226,12 +228,13 @@ namespace Vampirewal.Core.WpfTheme.WindowStyle
///
/// 弹窗关闭的命令
+ /// 可在弹出窗体的方法中写入需返回的值
///
- public ICommand CloseWindowCommand { get; set; }
+ public ICommand CloseDialogWindowCallBackCommand { get; set; }
///
/// 弹窗关闭的命令传参
///
- public object CloseWindowCommandParameter { get; set; }
+ public object CloseDialogWindowCallBackCommandParameter { get; set; }
}
}
diff --git a/test.View2/aaViewModel.cs b/test.View2/aaViewModel.cs
index ef973fb..6d5231c 100644
--- a/test.View2/aaViewModel.cs
+++ b/test.View2/aaViewModel.cs
@@ -78,9 +78,9 @@ namespace test.View2
#region Command命令
public RelayCommand aaCommand => new RelayCommand(() =>
{
- Dialog.ShowPopupWindow("hahaa",WindowsManager.GetInstance().GetDialogWindow(ViewId), Vampirewal.Core.WpfTheme.WindowStyle.MessageType.Successful);
+ //Dialog.ShowPopupWindow("hahaa",WindowsManager.GetInstance().GetDialogWindow(ViewId), Vampirewal.Core.WpfTheme.WindowStyle.MessageType.Successful);
- //CloseView();
+ CloseView();
});
protected override void CloseView()
diff --git a/test.ViewModel/MainViewModel.cs b/test.ViewModel/MainViewModel.cs
index 12a6c7f..5dfb2dc 100644
--- a/test.ViewModel/MainViewModel.cs
+++ b/test.ViewModel/MainViewModel.cs
@@ -419,8 +419,7 @@ namespace test
UiView = VampirewalIoC.GetInstance().GetInstance("aaView"),
//PassData = RadarModels,
//IconStr = @"pack://application:,,,/test;component/Vampirewal-Logo.png"
- CloseWindowCommand = CloseWindowCommand,
- CloseWindowCommandParameter = "aaa"
+ CloseDialogWindowCallBackCommand = CloseWindowCommand,
});
//IsOnLoading = !IsOnLoading;
@@ -488,7 +487,7 @@ namespace test
return Messenger.Default.Send("GetView", "test.test_NewPage");
}
- public override void ExecuteBeforeCloseDialogWindowCommand()
+ public override void ExecuteBeforeCloseDialogWindowCommand(object obj)
{
//Config.Save();
ExportExcelService.ExportDataToExcel(EntityList.ToList(), AppDomain.CurrentDomain.BaseDirectory, Vampirewal.Core.OperationExcelService.ExcelType.xlsx);
--
Gitee
From 89e280d2cb40a4b1043de9dd9f807eb40972e29c Mon Sep 17 00:00:00 2001
From: vampirewal <235160615@qq.com>
Date: Thu, 15 Sep 2022 09:35:25 +0800
Subject: [PATCH 25/53] 11
---
Vampirewal.Core.FolwEngine.Test/Program.cs | 6 +-
.../IHttpClientService.cs | 3 +-
.../DBContexts/VampirewalDbBase.cs | 4 +-
Vampirewal.Core/Interface/IAppConfig.cs | 5 +
Vampirewal.Core/Interface/IDataContext.cs | 4 +-
Vampirewal.Core/Models/FrameworkUserBase.cs | 3 +-
Vampirewal.Core/SimpleMVVM/WindowsManager.cs | 31 +-
Vampirewal.Core/Tools/TuoMinHelper.cs | 174 ++++++++
Vampirewal.Core/Tools/Utils.cs | 80 +++-
Vampirewal.Core/Vampirewal.Core.csproj | 9 +-
.../Converter/LevelToIndentConverter.cs | 58 +++
.../CustomControl/TreeGrid/ITreeModel.cs | 38 ++
.../TreeGrid/ObservableCollectionAdv.cs | 59 +++
.../CustomControl/TreeGrid/RowExpander.cs | 34 ++
.../CustomControl/TreeGrid/TreeGridStyle.xaml | 75 ++++
.../CustomControl/TreeGrid/TreeList.cs | 260 ++++++++++++
.../CustomControl/TreeGrid/TreeListItem.cs | 121 ++++++
.../CustomControl/TreeGrid/TreeNode.cs | 391 ++++++++++++++++++
test/MainWindow.xaml | 3 +
test/test.View.csproj | 1 -
20 files changed, 1335 insertions(+), 24 deletions(-)
create mode 100644 Vampirewal.Core/Tools/TuoMinHelper.cs
create mode 100644 Vampirewal.Core/WpfTheme/Converter/LevelToIndentConverter.cs
create mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/ITreeModel.cs
create mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/ObservableCollectionAdv.cs
create mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/RowExpander.cs
create mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/TreeGridStyle.xaml
create mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/TreeList.cs
create mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/TreeListItem.cs
create mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/TreeNode.cs
diff --git a/Vampirewal.Core.FolwEngine.Test/Program.cs b/Vampirewal.Core.FolwEngine.Test/Program.cs
index 79f754c..463fedf 100644
--- a/Vampirewal.Core.FolwEngine.Test/Program.cs
+++ b/Vampirewal.Core.FolwEngine.Test/Program.cs
@@ -38,9 +38,9 @@ public class HelloWorldWorkflow : IWorkflow
public void Build(IWorkflowBuilder builder)
{
- builder
- .StartWith()
- .Then();
+ //builder
+ // .StartWith().
+ // .Then();
}
}
diff --git a/Vampirewal.Core.HttpClientService/IHttpClientService.cs b/Vampirewal.Core.HttpClientService/IHttpClientService.cs
index 191e526..0ed3a18 100644
--- a/Vampirewal.Core.HttpClientService/IHttpClientService.cs
+++ b/Vampirewal.Core.HttpClientService/IHttpClientService.cs
@@ -151,7 +151,7 @@ namespace Vampirewal.Core.HttpClientService
#endregion
- private IHttpClientFactory _httpClientFactory { get; set; }
+ protected IHttpClientFactory _httpClientFactory { get; set; }
#region GET请求
///
@@ -179,6 +179,7 @@ namespace Vampirewal.Core.HttpClientService
}
}
+
var response = _httpClient.GetAsync(url).Result;
if (response.IsSuccessStatusCode)
diff --git a/Vampirewal.Core/DBContexts/VampirewalDbBase.cs b/Vampirewal.Core/DBContexts/VampirewalDbBase.cs
index fb7defc..8111b3d 100644
--- a/Vampirewal.Core/DBContexts/VampirewalDbBase.cs
+++ b/Vampirewal.Core/DBContexts/VampirewalDbBase.cs
@@ -57,7 +57,7 @@ namespace Vampirewal.Core.DBContexts
}
- Client = new SqlSugarClient(dbConnectConfigList);
+ Client = new SqlSugarScope(dbConnectConfigList);
//SQL执行完
Client.Aop.OnLogExecuted = OnLogExecuted;
@@ -165,7 +165,7 @@ namespace Vampirewal.Core.DBContexts
///
/// 数据库连接对象
///
- public SqlSugarClient Client { get; set; }
+ public SqlSugarScope Client { get; set; }
///
/// 新增Entity
diff --git a/Vampirewal.Core/Interface/IAppConfig.cs b/Vampirewal.Core/Interface/IAppConfig.cs
index 1035adc..22243f3 100644
--- a/Vampirewal.Core/Interface/IAppConfig.cs
+++ b/Vampirewal.Core/Interface/IAppConfig.cs
@@ -108,6 +108,11 @@ namespace Vampirewal.Core.Interface
/// 视图View模块dll路径
///
List ViewModulesPath { get; set; }
+
+ ///
+ /// 连接域设置
+ ///
+ List Domains { get; set; }
///
/// 配置文件路径
///
diff --git a/Vampirewal.Core/Interface/IDataContext.cs b/Vampirewal.Core/Interface/IDataContext.cs
index 971a39e..6b17453 100644
--- a/Vampirewal.Core/Interface/IDataContext.cs
+++ b/Vampirewal.Core/Interface/IDataContext.cs
@@ -17,9 +17,9 @@ namespace Vampirewal.Core.Interface
public interface IDataContext
{
///
- ///
+ /// 连接客户端
///
- SqlSugarClient Client { get; set; }
+ SqlSugarScope Client { get; set; }
diff --git a/Vampirewal.Core/Models/FrameworkUserBase.cs b/Vampirewal.Core/Models/FrameworkUserBase.cs
index 206e772..064dd83 100644
--- a/Vampirewal.Core/Models/FrameworkUserBase.cs
+++ b/Vampirewal.Core/Models/FrameworkUserBase.cs
@@ -34,7 +34,7 @@ namespace Vampirewal.Core.Models
/// 工号
///
[Display(Name = "工号")]
- [StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
+ [StringLength(50, ErrorMessage = "字段长度超过50!")]
public string ITCode { get; set; }
///
@@ -56,6 +56,7 @@ namespace Vampirewal.Core.Models
/// 角色
///
[Display(Name = "角色")]
+ [SugarColumn(IsIgnore =true)]
public List UserRoles { get; set; }
//[Display(Name = "Group")]
diff --git a/Vampirewal.Core/SimpleMVVM/WindowsManager.cs b/Vampirewal.Core/SimpleMVVM/WindowsManager.cs
index 16c0d4c..8c49a12 100644
--- a/Vampirewal.Core/SimpleMVVM/WindowsManager.cs
+++ b/Vampirewal.Core/SimpleMVVM/WindowsManager.cs
@@ -521,12 +521,13 @@ namespace Vampirewal.Core.SimpleMVVM
///
///
///
- public void RegisterDialogWindow(Guid ViewId, Window window)
+ public bool RegisterDialogWindow(Guid ViewId, Window window)
{
- if (!DialogWindowDic.ContainsKey(ViewId))
- {
- DialogWindowDic.Add(ViewId, window);
- }
+ //if (!DialogWindowDic.ContainsKey(ViewId))
+ //{
+ // DialogWindowDic.Add(ViewId, window);
+ //}
+ return DialogWindowDic.TryAdd(ViewId, window);
}
///
/// 关闭DialogWindow窗体
@@ -536,12 +537,22 @@ namespace Vampirewal.Core.SimpleMVVM
{
if (DialogWindowDic.TryGetValue(ViewId,out Window window))
{
- var DialogWindow = window as ShowDialogWindow;
- var vm = DialogWindow.DataContext as ViewModelBase;
- DialogWindow.CloseDialogWindowCallBackCommand?.Execute(vm.GetResult());
+ try
+ {
+ var DialogWindow = window as ShowDialogWindow;
+ var vm = DialogWindow.DataContext as ViewModelBase;
+ DialogWindow.CloseDialogWindowCallBackCommand?.Execute(vm.GetResult());
+ }
+ catch (Exception ex)
+ {
- window.Close();
- DialogWindowDic.Remove(ViewId);
+ throw ex;
+ }
+ finally
+ {
+ window.Close();
+ DialogWindowDic.Remove(ViewId);
+ }
}
}
diff --git a/Vampirewal.Core/Tools/TuoMinHelper.cs b/Vampirewal.Core/Tools/TuoMinHelper.cs
new file mode 100644
index 0000000..ae920cd
--- /dev/null
+++ b/Vampirewal.Core/Tools/TuoMinHelper.cs
@@ -0,0 +1,174 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:TuoMinHelper
+// 创 建 人:YangCheng
+// 创建时间:2022/8/4 17:49:20
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Vampirewal.Core.Tools
+{
+ ///
+ /// 文本脱敏助手
+ ///
+ public class TuoMinHelper
+ {
+ ///
+ /// 隐藏敏感信息
+ ///
+ /// 信息实体
+ /// 左边保留的字符数
+ /// 右边保留的字符数
+ /// 当长度异常时,是否显示左边
+ /// true
显示左边,false
显示右边
+ ///
+ ///
+ public static string HideSensitiveInfo(string info, int left, int right, bool basedOnLeft = true)
+ {
+ if (String.IsNullOrEmpty(info))
+ {
+ return "";
+ }
+ StringBuilder sbText = new StringBuilder();
+ int hiddenCharCount = info.Length - left - right;
+ if (hiddenCharCount > 0)
+ {
+ string prefix = info.Substring(0, left), suffix = info.Substring(info.Length - right);
+ sbText.Append(prefix);
+ for (int i = 0; i < hiddenCharCount; i++)
+ {
+ sbText.Append("*");
+ }
+ sbText.Append(suffix);
+ }
+ else
+ {
+ if (basedOnLeft)
+ {
+ if (info.Length > left && left > 0)
+ {
+ sbText.Append(info.Substring(0, left) + "****");
+ }
+ else
+ {
+ sbText.Append(info.Substring(0, 1) + "****");
+ }
+ }
+ else
+ {
+ if (info.Length > right && right > 0)
+ {
+ sbText.Append("****" + info.Substring(info.Length - right));
+ }
+ else
+ {
+ sbText.Append("****" + info.Substring(info.Length - 1));
+ }
+ }
+ }
+ return sbText.ToString();
+ }
+
+ ///
+ /// 隐藏敏感信息
+ ///
+ /// 信息实体
+ /// 左边保留的字符数
+ /// 右边保留的字符数
+ /// 当长度异常时,是否显示左边
+ /// true
显示左边,false
显示右边
+ ///
+ public static string HideSensitiveInfo1(string info, int left, int right, bool basedOnLeft = true)
+ {
+ if (String.IsNullOrEmpty(info))
+ {
+ return "";
+ }
+ StringBuilder sbText = new StringBuilder();
+ int hiddenCharCount = info.Length - left - right;
+ if (hiddenCharCount > 0)
+ {
+ string prefix = info.Substring(0, left), suffix = info.Substring(info.Length - right);
+ sbText.Append(prefix);
+ sbText.Append("****");
+ sbText.Append(suffix);
+ }
+ else
+ {
+ if (basedOnLeft)
+ {
+ if (info.Length > left && left > 0)
+ {
+ sbText.Append(info.Substring(0, left) + "****");
+ }
+ else
+ {
+ sbText.Append(info.Substring(0, 1) + "****");
+ }
+ }
+ else
+ {
+ if (info.Length > right && right > 0)
+ {
+ sbText.Append("****" + info.Substring(info.Length - right));
+ }
+ else
+ {
+ sbText.Append("****" + info.Substring(info.Length - 1));
+ }
+ }
+ }
+ return sbText.ToString();
+ }
+
+ ///
+ /// 隐藏敏感信息
+ ///
+ /// 信息
+ /// 信息总长与左子串(或右子串)的比例
+ /// 当长度异常时,是否显示左边,默认true,默认显示左边
+ /// true
显示左边,false
显示右边
+ ///
+ public static string HideSensitiveInfo(string info, int sublen = 3, bool basedOnLeft = true)
+ {
+ if (String.IsNullOrEmpty(info))
+ {
+ return "";
+ }
+ if (sublen <= 1)
+ {
+ sublen = 3;
+ }
+ int subLength = info.Length / sublen;
+ if (subLength > 0 && info.Length > (subLength * 2))
+ {
+ string prefix = info.Substring(0, subLength), suffix = info.Substring(info.Length - subLength);
+ return prefix + "****" + suffix;
+ }
+ else
+ {
+ if (basedOnLeft)
+ {
+ string prefix = subLength > 0 ? info.Substring(0, subLength) : info.Substring(0, 1);
+ return prefix + "****";
+ }
+ else
+ {
+ string suffix = subLength > 0 ? info.Substring(info.Length - subLength) : info.Substring(info.Length - 1);
+ return "****" + suffix;
+ }
+ }
+ }
+ }
+}
diff --git a/Vampirewal.Core/Tools/Utils.cs b/Vampirewal.Core/Tools/Utils.cs
index a8f2d68..68468dd 100644
--- a/Vampirewal.Core/Tools/Utils.cs
+++ b/Vampirewal.Core/Tools/Utils.cs
@@ -26,6 +26,7 @@ using System.Threading.Tasks;
//using Microsoft.Extensions.Caching.Distributed;
using Vampirewal.Core.Interface;
using Vampirewal.Core.Models;
+using System.Text.Json;
//using NPOI.HSSF.Util;
namespace Vampirewal.Core
@@ -124,6 +125,15 @@ namespace Vampirewal.Core
return fieldName == null ? "" : fieldName.Replace(".", "_").Replace("[", "_").Replace("]", "_");
}
+
+ ///
+ /// 验证不同项
+ ///
+ ///
+ /// 旧列表
+ /// 新列表
+ /// 需移除的
+ /// 需新增的
public static void CheckDifference(IEnumerable oldList, IEnumerable newList, out IEnumerable ToRemove, out IEnumerable ToAdd) where T : TopModel
{
List tempToRemove = new List();
@@ -327,7 +337,7 @@ namespace Vampirewal.Core
}
///
- ///
+ /// 删除文件
///
///
public static void DeleteFile(string path)
@@ -339,7 +349,7 @@ namespace Vampirewal.Core
catch { }
}
- #region 格式化文本 add by wuwh 2014.6.12
+ #region 格式化文本
///
/// 格式化文本
///
@@ -397,7 +407,7 @@ namespace Vampirewal.Core
}
#endregion
- #region 格式化代码 edit by wuwh
+ #region 格式化代码
///
/// 格式化代码
///
@@ -790,5 +800,69 @@ namespace Vampirewal.Core
return false;
}
}
+
+ #region model转换
+
+ ///
+ /// 模型转换
+ ///
+ /// 被转换的类型
+ /// 转换成的类型
+ /// 被转换的model
+ ///
+ public OutT ModelConverter(InT model)
+ {
+ Type InType = typeof(InT);
+ InT inTModel = model;
+
+ Type OutType = typeof(OutT);
+ OutT outTModel = (OutT)Activator.CreateInstance(OutType);
+
+ //通过反射去遍历属性
+ foreach (PropertyInfo inProperty in InType.GetProperties())
+ {
+ foreach (PropertyInfo OutProperty in OutType.GetProperties())
+ {
+ if (inProperty.Name == OutProperty.Name && inProperty.PropertyType == OutProperty.PropertyType)
+ {
+ OutProperty.SetValue(outTModel, inProperty.GetValue(inTModel));
+ }
+ }
+ }
+
+ return outTModel;
+ }
+
+ ///
+ /// 模型转换
+ ///
+ /// 被转换的类型
+ /// 转换成的类型
+ /// 需要转换的json
+ ///
+ public OutT ModelConverter(string json)
+ {
+ Type InType = typeof(InT);
+ InT inTModel = JsonSerializer.Deserialize(json);
+
+ Type OutType = typeof(OutT);
+ OutT outTModel = (OutT)Activator.CreateInstance(OutType);
+
+ //通过反射去遍历属性
+ foreach (PropertyInfo inProperty in InType.GetProperties())
+ {
+ foreach (PropertyInfo OutProperty in OutType.GetProperties())
+ {
+ if (inProperty.Name == OutProperty.Name && inProperty.PropertyType == OutProperty.PropertyType)
+ {
+ OutProperty.SetValue(outTModel, inProperty.GetValue(inTModel));
+ }
+ }
+ }
+
+ return outTModel;
+ }
+
+ #endregion
}
}
diff --git a/Vampirewal.Core/Vampirewal.Core.csproj b/Vampirewal.Core/Vampirewal.Core.csproj
index 03a183f..c46975f 100644
--- a/Vampirewal.Core/Vampirewal.Core.csproj
+++ b/Vampirewal.Core/Vampirewal.Core.csproj
@@ -7,7 +7,7 @@
该Core类库详细介绍请查看:https://blog.csdn.net/weixin_42806176/article/details/120705323
(2.X开始的ORM使用SqlSugar,1.X使用的EFCore)
true
- 2.1.1.5
+ 2.1.1.8
true
https://blog.csdn.net/weixin_42806176/article/details/120705323
Vampirewal-Logo.png
@@ -43,6 +43,7 @@
+
@@ -53,6 +54,12 @@
+
+
+
+
+
+
diff --git a/Vampirewal.Core/WpfTheme/Converter/LevelToIndentConverter.cs b/Vampirewal.Core/WpfTheme/Converter/LevelToIndentConverter.cs
new file mode 100644
index 0000000..be1bea5
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/Converter/LevelToIndentConverter.cs
@@ -0,0 +1,58 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:LevelToIndentConverter
+// 创 建 人:YangCheng
+// 创建时间:2022/8/10 19:02:45
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Data;
+
+namespace Vampirewal.Core.WpfTheme.Converter
+{
+ ///
+ ///
+ ///
+ public class LevelToIndentConverter : IValueConverter
+ {
+ private const double IndentSize = 19.0;
+
+ public object Convert(object o, Type type, object parameter, CultureInfo culture)
+ {
+ return new Thickness((int)o * IndentSize, 0, 0, 0);
+ }
+
+ public object ConvertBack(object o, Type type, object parameter, CultureInfo culture)
+ {
+ throw new NotSupportedException();
+ }
+ }
+
+ public class CanExpandConverter : IValueConverter
+ {
+ public object Convert(object o, Type type, object parameter, CultureInfo culture)
+ {
+ if ((bool)o)
+ return Visibility.Visible;
+ else
+ return Visibility.Hidden;
+ }
+
+ public object ConvertBack(object o, Type type, object parameter, CultureInfo culture)
+ {
+ throw new NotSupportedException();
+ }
+ }
+}
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/ITreeModel.cs b/Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/ITreeModel.cs
new file mode 100644
index 0000000..e3e830f
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/ITreeModel.cs
@@ -0,0 +1,38 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:ITreeModel
+// 创 建 人:YangCheng
+// 创建时间:2022/8/10 19:03:45
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Vampirewal.Core.WpfTheme.CustomControl.TreeGrid
+{
+ ///
+ ///
+ ///
+ public interface ITreeModel
+ {
+ ///
+ /// Get list of children of the specified parent
+ ///
+ IEnumerable GetChildren(object parent);
+
+ ///
+ /// returns wheather specified parent has any children or not.
+ ///
+ bool HasChildren(object parent);
+ }
+}
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/ObservableCollectionAdv.cs b/Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/ObservableCollectionAdv.cs
new file mode 100644
index 0000000..c2f6180
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/ObservableCollectionAdv.cs
@@ -0,0 +1,59 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:ObservableCollectionAdv
+// 创 建 人:YangCheng
+// 创建时间:2022/8/10 19:07:27
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Collections.Specialized;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Vampirewal.Core.WpfTheme.CustomControl.TreeGrid
+{
+ ///
+ ///
+ ///
+ public class ObservableCollectionAdv : ObservableCollection
+ {
+ public void RemoveRange(int index, int count)
+ {
+ this.CheckReentrancy();
+ var items = this.Items as List;
+ items.RemoveRange(index, count);
+ OnReset();
+ }
+
+ public void InsertRange(int index, IEnumerable collection)
+ {
+ this.CheckReentrancy();
+ var items = this.Items as List;
+ items.InsertRange(index, collection);
+ OnReset();
+ }
+
+ private void OnReset()
+ {
+ OnPropertyChanged("Count");
+ OnPropertyChanged("Item[]");
+ OnCollectionChanged(new NotifyCollectionChangedEventArgs(
+ NotifyCollectionChangedAction.Reset));
+ }
+
+ private void OnPropertyChanged(string propertyName)
+ {
+ OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
+ }
+ }
+}
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/RowExpander.cs b/Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/RowExpander.cs
new file mode 100644
index 0000000..a36cf07
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/RowExpander.cs
@@ -0,0 +1,34 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:RowExpander
+// 创 建 人:YangCheng
+// 创建时间:2022/8/10 19:04:07
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Controls;
+using System.Windows;
+
+namespace Vampirewal.Core.WpfTheme.CustomControl.TreeGrid
+{
+ ///
+ ///
+ ///
+ public class RowExpander : Control
+ {
+ static RowExpander()
+ {
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(RowExpander), new FrameworkPropertyMetadata(typeof(RowExpander)));
+ }
+ }
+}
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/TreeGridStyle.xaml b/Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/TreeGridStyle.xaml
new file mode 100644
index 0000000..6c2f8ab
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/TreeGridStyle.xaml
@@ -0,0 +1,75 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/TreeList.cs b/Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/TreeList.cs
new file mode 100644
index 0000000..7623133
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/TreeList.cs
@@ -0,0 +1,260 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:TreeList
+// 创 建 人:YangCheng
+// 创建时间:2022/8/10 19:04:28
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Collections.Specialized;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Controls.Primitives;
+
+namespace Vampirewal.Core.WpfTheme.CustomControl.TreeGrid
+{
+ ///
+ ///
+ ///
+ public class TreeList : ListView
+ {
+
+
+
+ public IEnumerable TreeSource
+ {
+ get { return (IEnumerable)GetValue(TreeSourceProperty); }
+ set { SetValue(TreeSourceProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty TreeSourceProperty =
+ DependencyProperty.Register("TreeSource", typeof(IEnumerable), typeof(TreeList), new PropertyMetadata(null, TreeSourceChangedCallback));
+
+ private static void TreeSourceChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ TreeList list = (TreeList)d;
+
+ foreach (var item in list.TreeSource)
+ {
+
+ }
+ }
+
+
+
+
+ #region Properties
+
+ ///
+ /// Internal collection of rows representing visible nodes, actually displayed in the ListView
+ ///
+ internal ObservableCollectionAdv Rows
+ {
+ get;
+ private set;
+ }
+
+
+ private ITreeModel _model;
+ public ITreeModel Model
+ {
+ get { return _model; }
+ set
+ {
+ if (_model != value)
+ {
+ _model = value;
+ _root.Children.Clear();
+ Rows.Clear();
+ CreateChildrenNodes(_root);
+ }
+ }
+ }
+
+ private TreeNode _root;
+ internal TreeNode Root
+ {
+ get { return _root; }
+ }
+
+ public ReadOnlyCollection Nodes
+ {
+ get { return Root.Nodes; }
+ }
+
+ internal TreeNode PendingFocusNode
+ {
+ get;
+ set;
+ }
+
+ public ICollection SelectedNodes
+ {
+ get
+ {
+ return SelectedItems.Cast().ToArray();
+ }
+ }
+
+ public TreeNode SelectedNode
+ {
+ get
+ {
+ if (SelectedItems.Count > 0)
+ return SelectedItems[0] as TreeNode;
+ else
+ return null;
+ }
+ }
+ #endregion
+
+ public TreeList()
+ {
+ Rows = new ObservableCollectionAdv();
+ _root = new TreeNode(this, null);
+ _root.IsExpanded = true;
+ ItemsSource = Rows;
+ ItemContainerGenerator.StatusChanged += ItemContainerGeneratorStatusChanged;
+ }
+
+ void ItemContainerGeneratorStatusChanged(object sender, EventArgs e)
+ {
+ if (ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated && PendingFocusNode != null)
+ {
+ var item = ItemContainerGenerator.ContainerFromItem(PendingFocusNode) as TreeListItem;
+ if (item != null)
+ item.Focus();
+ PendingFocusNode = null;
+ }
+ }
+
+ protected override DependencyObject GetContainerForItemOverride()
+ {
+ return new TreeListItem();
+ }
+
+ protected override bool IsItemItsOwnContainerOverride(object item)
+ {
+ return item is TreeListItem;
+ }
+
+ protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
+ {
+ var ti = element as TreeListItem;
+ var node = item as TreeNode;
+ if (ti != null && node != null)
+ {
+ ti.Node = item as TreeNode;
+ base.PrepareContainerForItemOverride(element, node.Tag);
+ }
+ }
+
+ internal void SetIsExpanded(TreeNode node, bool value)
+ {
+ if (value)
+ {
+ if (!node.IsExpandedOnce)
+ {
+ node.IsExpandedOnce = true;
+ node.AssignIsExpanded(value);
+ CreateChildrenNodes(node);
+ }
+ else
+ {
+ node.AssignIsExpanded(value);
+ CreateChildrenRows(node);
+ }
+ }
+ else
+ {
+ DropChildrenRows(node, false);
+ node.AssignIsExpanded(value);
+ }
+ }
+
+ internal void CreateChildrenNodes(TreeNode node)
+ {
+ var children = GetChildren(node);
+ if (children != null)
+ {
+ int rowIndex = Rows.IndexOf(node);
+ node.ChildrenSource = children as INotifyCollectionChanged;
+ foreach (object obj in children)
+ {
+ TreeNode child = new TreeNode(this, obj);
+ child.HasChildren = HasChildren(child);
+ node.Children.Add(child);
+ }
+ Rows.InsertRange(rowIndex + 1, node.Children.ToArray());
+ }
+ }
+
+ private void CreateChildrenRows(TreeNode node)
+ {
+ int index = Rows.IndexOf(node);
+ if (index >= 0 || node == _root) // ignore invisible nodes
+ {
+ var nodes = node.AllVisibleChildren.ToArray();
+ Rows.InsertRange(index + 1, nodes);
+ }
+ }
+
+ internal void DropChildrenRows(TreeNode node, bool removeParent)
+ {
+ int start = Rows.IndexOf(node);
+ if (start >= 0 || node == _root) // ignore invisible nodes
+ {
+ int count = node.VisibleChildrenCount;
+ if (removeParent)
+ count++;
+ else
+ start++;
+ Rows.RemoveRange(start, count);
+ }
+ }
+
+ private IEnumerable GetChildren(TreeNode parent)
+ {
+ if (Model != null)
+ return Model.GetChildren(parent.Tag);
+ else
+ return null;
+ }
+
+ private bool HasChildren(TreeNode parent)
+ {
+ if (parent == Root)
+ return true;
+ else if (Model != null)
+ return Model.HasChildren(parent.Tag);
+ else
+ return false;
+ }
+
+ internal void InsertNewNode(TreeNode parent, object tag, int rowIndex, int index)
+ {
+ TreeNode node = new TreeNode(this, tag);
+ if (index >= 0 && index < parent.Children.Count)
+ parent.Children.Insert(index, node);
+ else
+ {
+ index = parent.Children.Count;
+ parent.Children.Add(node);
+ }
+ Rows.Insert(rowIndex + index + 1, node);
+ }
+ }
+}
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/TreeListItem.cs b/Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/TreeListItem.cs
new file mode 100644
index 0000000..e3dc46b
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/TreeListItem.cs
@@ -0,0 +1,121 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:TreeListItem
+// 创 建 人:YangCheng
+// 创建时间:2022/8/10 19:05:05
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Controls;
+using System.Windows.Input;
+
+namespace Vampirewal.Core.WpfTheme.CustomControl.TreeGrid
+{
+ ///
+ ///
+ ///
+ public class TreeListItem : ListViewItem, INotifyPropertyChanged
+ {
+ #region Properties
+
+ private TreeNode _node;
+ public TreeNode Node
+ {
+ get { return _node; }
+ internal set
+ {
+ _node = value;
+ OnPropertyChanged("Node");
+ }
+ }
+
+ #endregion
+
+ public TreeListItem()
+ {
+ }
+
+ protected override void OnKeyDown(KeyEventArgs e)
+ {
+ if (Node != null)
+ {
+ switch (e.Key)
+ {
+ case Key.Right:
+ e.Handled = true;
+ if (!Node.IsExpanded)
+ {
+ Node.IsExpanded = true;
+ ChangeFocus(Node);
+ }
+ else if (Node.Children.Count > 0)
+ ChangeFocus(Node.Children[0]);
+ break;
+
+ case Key.Left:
+
+ e.Handled = true;
+ if (Node.IsExpanded && Node.IsExpandable)
+ {
+ Node.IsExpanded = false;
+ ChangeFocus(Node);
+ }
+ else
+ ChangeFocus(Node.Parent);
+ break;
+
+ case Key.Subtract:
+ e.Handled = true;
+ Node.IsExpanded = false;
+ ChangeFocus(Node);
+ break;
+
+ case Key.Add:
+ e.Handled = true;
+ Node.IsExpanded = true;
+ ChangeFocus(Node);
+ break;
+ }
+ }
+
+ if (!e.Handled)
+ base.OnKeyDown(e);
+ }
+
+ private void ChangeFocus(TreeNode node)
+ {
+ var tree = node.Tree;
+ if (tree != null)
+ {
+ var item = tree.ItemContainerGenerator.ContainerFromItem(node) as TreeListItem;
+ if (item != null)
+ item.Focus();
+ else
+ tree.PendingFocusNode = node;
+ }
+ }
+
+ #region INotifyPropertyChanged Members
+
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ private void OnPropertyChanged(string name)
+ {
+ if (PropertyChanged != null)
+ PropertyChanged(this, new PropertyChangedEventArgs(name));
+ }
+
+ #endregion
+ }
+}
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/TreeNode.cs b/Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/TreeNode.cs
new file mode 100644
index 0000000..62d0e2c
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/TreeNode.cs
@@ -0,0 +1,391 @@
+#region << 文 件 说 明 >>
+/*----------------------------------------------------------------
+// 文件名称:TreeNode
+// 创 建 人:YangCheng
+// 创建时间:2022/8/10 19:05:35
+// 文件版本:V1.0.0
+// ===============================================================
+// 功能描述:
+//
+//
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Collections.Specialized;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Vampirewal.Core.WpfTheme.CustomControl.TreeGrid
+{
+ ///
+ ///
+ ///
+ public sealed class TreeNode : INotifyPropertyChanged
+ {
+ #region NodeCollection
+ private class NodeCollection : Collection
+ {
+ private TreeNode _owner;
+
+ public NodeCollection(TreeNode owner)
+ {
+ _owner = owner;
+ }
+
+ protected override void ClearItems()
+ {
+ while (this.Count != 0)
+ this.RemoveAt(this.Count - 1);
+ }
+
+ protected override void InsertItem(int index, TreeNode item)
+ {
+ if (item == null)
+ throw new ArgumentNullException("item");
+
+ if (item.Parent != _owner)
+ {
+ if (item.Parent != null)
+ item.Parent.Children.Remove(item);
+ item._parent = _owner;
+ item._index = index;
+ for (int i = index; i < Count; i++)
+ this[i]._index++;
+ base.InsertItem(index, item);
+ }
+ }
+
+ protected override void RemoveItem(int index)
+ {
+ TreeNode item = this[index];
+ item._parent = null;
+ item._index = -1;
+ for (int i = index + 1; i < Count; i++)
+ this[i]._index--;
+ base.RemoveItem(index);
+ }
+
+ protected override void SetItem(int index, TreeNode item)
+ {
+ if (item == null)
+ throw new ArgumentNullException("item");
+ RemoveAt(index);
+ InsertItem(index, item);
+ }
+ }
+ #endregion
+
+ #region INotifyPropertyChanged Members
+
+ public event PropertyChangedEventHandler PropertyChanged;
+ private void OnPropertyChanged(string name)
+ {
+ if (PropertyChanged != null)
+ PropertyChanged(this, new PropertyChangedEventArgs(name));
+ }
+
+ #endregion
+
+ #region Properties
+
+ private TreeList _tree;
+ internal TreeList Tree
+ {
+ get { return _tree; }
+ }
+
+ private INotifyCollectionChanged _childrenSource;
+ internal INotifyCollectionChanged ChildrenSource
+ {
+ get { return _childrenSource; }
+ set
+ {
+ if (_childrenSource != null)
+ _childrenSource.CollectionChanged -= ChildrenChanged;
+
+ _childrenSource = value;
+
+ if (_childrenSource != null)
+ _childrenSource.CollectionChanged += ChildrenChanged;
+ }
+ }
+
+ private int _index = -1;
+ public int Index
+ {
+ get
+ {
+ return _index;
+ }
+ }
+
+ ///
+ /// Returns true if all parent nodes of this node are expanded.
+ ///
+ internal bool IsVisible
+ {
+ get
+ {
+ TreeNode node = _parent;
+ while (node != null)
+ {
+ if (!node.IsExpanded)
+ return false;
+ node = node.Parent;
+ }
+ return true;
+ }
+ }
+
+ public bool IsExpandedOnce
+ {
+ get;
+ internal set;
+ }
+
+ public bool HasChildren
+ {
+ get;
+ internal set;
+ }
+
+ private bool _isExpanded;
+ public bool IsExpanded
+ {
+ get { return _isExpanded; }
+ set
+ {
+ if (value != IsExpanded)
+ {
+ Tree.SetIsExpanded(this, value);
+ OnPropertyChanged("IsExpanded");
+ OnPropertyChanged("IsExpandable");
+ }
+ }
+ }
+
+ internal void AssignIsExpanded(bool value)
+ {
+ _isExpanded = value;
+ }
+
+ public bool IsExpandable
+ {
+ get
+ {
+ return (HasChildren && !IsExpandedOnce) || Nodes.Count > 0;
+ }
+ }
+
+ private bool _isSelected;
+ public bool IsSelected
+ {
+ get { return _isSelected; }
+ set
+ {
+ if (value != _isSelected)
+ {
+ _isSelected = value;
+ OnPropertyChanged("IsSelected");
+ }
+ }
+ }
+
+
+ private TreeNode _parent;
+ public TreeNode Parent
+ {
+ get { return _parent; }
+ }
+
+ public int Level
+ {
+ get
+ {
+ if (_parent == null)
+ return -1;
+ else
+ return _parent.Level + 1;
+ }
+ }
+
+ public TreeNode PreviousNode
+ {
+ get
+ {
+ if (_parent != null)
+ {
+ int index = Index;
+ if (index > 0)
+ return _parent.Nodes[index - 1];
+ }
+ return null;
+ }
+ }
+
+ public TreeNode NextNode
+ {
+ get
+ {
+ if (_parent != null)
+ {
+ int index = Index;
+ if (index < _parent.Nodes.Count - 1)
+ return _parent.Nodes[index + 1];
+ }
+ return null;
+ }
+ }
+
+ internal TreeNode BottomNode
+ {
+ get
+ {
+ TreeNode parent = this.Parent;
+ if (parent != null)
+ {
+ if (parent.NextNode != null)
+ return parent.NextNode;
+ else
+ return parent.BottomNode;
+ }
+ return null;
+ }
+ }
+
+ internal TreeNode NextVisibleNode
+ {
+ get
+ {
+ if (IsExpanded && Nodes.Count > 0)
+ return Nodes[0];
+ else
+ {
+ TreeNode nn = NextNode;
+ if (nn != null)
+ return nn;
+ else
+ return BottomNode;
+ }
+ }
+ }
+
+ public int VisibleChildrenCount
+ {
+ get
+ {
+ return AllVisibleChildren.Count();
+ }
+ }
+
+ public IEnumerable AllVisibleChildren
+ {
+ get
+ {
+ int level = this.Level;
+ TreeNode node = this;
+ while (true)
+ {
+ node = node.NextVisibleNode;
+ if (node != null && node.Level > level)
+ yield return node;
+ else
+ break;
+ }
+ }
+ }
+
+ private object _tag;
+ public object Tag
+ {
+ get { return _tag; }
+ }
+
+ private Collection _children;
+ internal Collection Children
+ {
+ get { return _children; }
+ }
+
+ private ReadOnlyCollection _nodes;
+ public ReadOnlyCollection Nodes
+ {
+ get { return _nodes; }
+ }
+
+ #endregion
+
+ internal TreeNode(TreeList tree, object tag)
+ {
+ if (tree == null)
+ throw new ArgumentNullException("tree");
+
+ _tree = tree;
+ _children = new NodeCollection(this);
+ _nodes = new ReadOnlyCollection(_children);
+ _tag = tag;
+ }
+
+ public override string ToString()
+ {
+ if (Tag != null)
+ return Tag.ToString();
+ else
+ return base.ToString();
+ }
+
+ void ChildrenChanged(object sender, NotifyCollectionChangedEventArgs e)
+ {
+ switch (e.Action)
+ {
+ case NotifyCollectionChangedAction.Add:
+ if (e.NewItems != null)
+ {
+ int index = e.NewStartingIndex;
+ int rowIndex = Tree.Rows.IndexOf(this);
+ foreach (object obj in e.NewItems)
+ {
+ Tree.InsertNewNode(this, obj, rowIndex, index);
+ index++;
+ }
+ }
+ break;
+
+ case NotifyCollectionChangedAction.Remove:
+ if (Children.Count > e.OldStartingIndex)
+ RemoveChildAt(e.OldStartingIndex);
+ break;
+
+ case NotifyCollectionChangedAction.Move:
+ case NotifyCollectionChangedAction.Replace:
+ case NotifyCollectionChangedAction.Reset:
+ while (Children.Count > 0)
+ RemoveChildAt(0);
+ Tree.CreateChildrenNodes(this);
+ break;
+ }
+ HasChildren = Children.Count > 0;
+ OnPropertyChanged("IsExpandable");
+ }
+
+ private void RemoveChildAt(int index)
+ {
+ var child = Children[index];
+ Tree.DropChildrenRows(child, true);
+ ClearChildrenSource(child);
+ Children.RemoveAt(index);
+ }
+
+ private void ClearChildrenSource(TreeNode node)
+ {
+ node.ChildrenSource = null;
+ foreach (var n in node.Children)
+ ClearChildrenSource(n);
+ }
+ }
+}
diff --git a/test/MainWindow.xaml b/test/MainWindow.xaml
index be0ce68..2fbf49f 100644
--- a/test/MainWindow.xaml
+++ b/test/MainWindow.xaml
@@ -31,6 +31,9 @@
+
+
+
diff --git a/test/test.View.csproj b/test/test.View.csproj
index 5b4fe2a..01462d9 100644
--- a/test/test.View.csproj
+++ b/test/test.View.csproj
@@ -24,7 +24,6 @@
-
--
Gitee
From 27b01f8111255fe9abaa6e5e5410dd2466011ac7 Mon Sep 17 00:00:00 2001
From: YangCheng <235160615@qq.com>
Date: Mon, 31 Oct 2022 17:18:13 +0800
Subject: [PATCH 26/53] 123
---
Test.Console/Program.cs | 253 +++++++++--
Test.Console/Test.Console.csproj | 5 +-
Vampirewal.Core.Mapper/IVampirewalMapper.cs | 34 ++
Vampirewal.Core.Mapper/MapperManager.cs | 429 ++++++++++++++++++
.../Vampirewal.Core.Mapper.csproj | 9 +
.../VampirewalMapperAttribute.cs | 65 +++
Vampirewal.Core/Extensions/EntityExtension.cs | 43 ++
Vampirewal.Core/Tools/Utils.cs | 3 +-
Vampirewal.Core/Vampirewal.Core.csproj | 2 +-
YC.Core.sln | 9 +-
10 files changed, 798 insertions(+), 54 deletions(-)
create mode 100644 Vampirewal.Core.Mapper/IVampirewalMapper.cs
create mode 100644 Vampirewal.Core.Mapper/MapperManager.cs
create mode 100644 Vampirewal.Core.Mapper/Vampirewal.Core.Mapper.csproj
create mode 100644 Vampirewal.Core.Mapper/VampirewalMapperAttribute.cs
diff --git a/Test.Console/Program.cs b/Test.Console/Program.cs
index aebf72e..dd90f37 100644
--- a/Test.Console/Program.cs
+++ b/Test.Console/Program.cs
@@ -1,68 +1,227 @@
using System;
using System.Linq;
using System.Reflection;
-using Vampirewal.Core.VContainer;
+using Vampirewal.Core.Mapper;
-namespace Test.Console
-{
-
+namespace Test.Console;
- public class Program
- {
- static void Main(string[] args)
- {
- //VIoC.GetInstance().Register();
- //VIoC.GetInstance().RegisterSingleton< Test2>();
- //VIoC.GetInstance().Register();
- //var container = VIoC.GetInstance().GetInstance();
+public class Program
+{
+ static void Main(string[] args)
+ {
+ //MapperManager.RegisterAll();
- VIoC.GetInstance().RegisterAll();
+ testclass testclass1 = new testclass()
+ {
+ Id=1234567890123456789,
+ Study=2,
+ Supplement="aaaaaaaaaaaaaaaaa",
+ MarryState=1,
+ Birthday=DateTime.Now,
+ CarHouse=1,
+ Constellation=1,
+ Gender=1,
+ Height="123",
+ Interests="sssssssssssssssssssssss",
+ MarryPlan="aaaaaaaaaaaaaaaaaaa",
+ MemberName="aaa",
+ NewPosition="asd",
+ OldPosition="qwe",
+ PhoneNum="123456789",
+ Professional="qwewert",
+ Weight="22",
+ YearMoney=789
+ };
- var aaa= VIoC.GetInstance().GetInstance();
+ var target1 = testclass1.SimpleMap();
- var abc = VIoC.GetInstance().GetInstance("Test3");
- }
+ var target2= Mapper.Map(testclass1);
}
+}
- public interface ITest
- {
- string ClassName { get; set; }
- }
- [VIocRegister(RegisterType.Service,ServiceType =typeof(ITest))]
- public class Test : ITest
- {
- public string ClassName { get; set; }
- }
+public class testclass : IVampirewalMapper
+{
+
- public interface ITest2
+ public Type MapperTargetType()
{
- string ClassName { get; set; }
+ return typeof(testclassDTO);
}
- [VIocRegister(RegisterType.OnlyClass, ServiceType = typeof(ITest2))]
- public class Test2 : ITest2
- {
- public string ClassName { get; set; }
- }
+ public virtual long Id { get; set; }
+ ///
+ /// 会员姓名
+ ///
+ public virtual string MemberName { get; set; }
- [VIocRegister( RegisterType.OnlyClass)]
- public class Test3
- {
- //ITest AAA { get; set; }
- //public Test3(ITest aaa)
- //{
- // AAA = aaa;
- //}
+ ///
+ /// 会员生日
+ ///
+ public virtual DateTime Birthday { get; set; }
- //[VIoCGetInstance( RegisterType.OnlyClass, "Test2")]
- [VIoCGetInstance( RegisterType.OnlyClass)]
- public Test2 Test10000 { get; set; }
+ ///
+ /// 性别
+ ///
+ public virtual int Gender { get; set; }
- public Test3()
- {
+ ///
+ /// 身高
+ ///
+ public virtual string Height { get; set; }
- }
- }
+ ///
+ /// 体重
+ ///
+ public virtual string Weight { get; set; }
+
+ ///
+ /// 星座
+ ///
+ public virtual int Constellation { get; set; }
+
+ ///
+ /// 籍贯
+ ///
+ public virtual string OldPosition { get; set; }
+
+ ///
+ /// 当前工作或生活地区
+ ///
+ public virtual string NewPosition { get; set; }
+
+ ///
+ /// 学历
+ ///
+ public virtual int Study { get; set; }
+
+ ///
+ /// 职业职位
+ ///
+ public virtual string Professional { get; set; }
+
+ ///
+ /// 年收入
+ ///
+ public virtual int YearMoney { get; set; }
+
+ ///
+ /// 婚姻状态
+ ///
+ public virtual int MarryState { get; set; }
+
+ ///
+ /// 车房情况
+ ///
+ public virtual int CarHouse { get; set; }
+
+ ///
+ /// 兴趣爱好
+ ///
+ public virtual string Interests { get; set; }
+
+ ///
+ /// 补充说明
+ ///
+ public virtual string Supplement { get; set; }
+
+ ///
+ /// 婚姻计划
+ ///
+ public virtual string MarryPlan { get; set; }
+
+ ///
+ /// 手机号码
+ ///
+ public virtual string PhoneNum { get; set; }
+}
+
+public class testclassDTO
+{
+ public virtual long Id { get; set; }
+ ///
+ /// 会员姓名
+ ///
+ public virtual string MemberName { get; set; }
+
+ ///
+ /// 会员生日
+ ///
+ public virtual DateTime Birthday { get; set; }
+
+ ///
+ /// 性别
+ ///
+ public virtual int Gender { get; set; }
+
+ ///
+ /// 身高
+ ///
+ public virtual string Height { get; set; }
+
+ ///
+ /// 体重
+ ///
+ public virtual string Weight { get; set; }
+
+ ///
+ /// 星座
+ ///
+ public virtual int Constellation { get; set; }
+
+ ///
+ /// 籍贯
+ ///
+ public virtual string OldPosition { get; set; }
+
+ ///
+ /// 当前工作或生活地区
+ ///
+ public virtual string NewPosition { get; set; }
+
+ ///
+ /// 学历
+ ///
+ public virtual int Study { get; set; }
+
+ ///
+ /// 职业职位
+ ///
+ public virtual string Professional { get; set; }
+
+ ///
+ /// 年收入
+ ///
+ public virtual int YearMoney { get; set; }
+
+ ///
+ /// 婚姻状态
+ ///
+ public virtual int MarryState { get; set; }
+
+ ///
+ /// 车房情况
+ ///
+ public virtual int CarHouse { get; set; }
+
+ ///
+ /// 兴趣爱好
+ ///
+ public virtual string Interests { get; set; }
+
+ ///
+ /// 补充说明
+ ///
+ public virtual string Supplement { get; set; }
+
+ ///
+ /// 婚姻计划
+ ///
+ public virtual string MarryPlan { get; set; }
+
+ ///
+ /// 手机号码
+ ///
+ public virtual string PhoneNum { get; set; }
}
diff --git a/Test.Console/Test.Console.csproj b/Test.Console/Test.Console.csproj
index b687340..085c627 100644
--- a/Test.Console/Test.Console.csproj
+++ b/Test.Console/Test.Console.csproj
@@ -2,12 +2,11 @@
Exe
- net5.0
+ net6.0
-
-
+
diff --git a/Vampirewal.Core.Mapper/IVampirewalMapper.cs b/Vampirewal.Core.Mapper/IVampirewalMapper.cs
new file mode 100644
index 0000000..bb60aa3
--- /dev/null
+++ b/Vampirewal.Core.Mapper/IVampirewalMapper.cs
@@ -0,0 +1,34 @@
+
+#region 文件信息
+/*----------------------------------------------------------------
+//
+// 文件名称:
+// 文件功能描述:
+// 设计要求:
+//
+// 文 件 名: IVampirewalMapper
+// 创建者: 杨程
+// 创建日期: 2022/10/24 17:22:31
+
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+
+
+namespace Vampirewal.Core.Mapper;
+
+///
+///
+///
+public interface IVampirewalMapper
+{
+
+
+ Type MapperTargetType();
+}
diff --git a/Vampirewal.Core.Mapper/MapperManager.cs b/Vampirewal.Core.Mapper/MapperManager.cs
new file mode 100644
index 0000000..3a645e5
--- /dev/null
+++ b/Vampirewal.Core.Mapper/MapperManager.cs
@@ -0,0 +1,429 @@
+
+#region 文件信息
+/*----------------------------------------------------------------
+//
+// 文件名称:
+// 文件功能描述:
+// 设计要求:
+//
+// 文 件 名: MapperManager
+// 创建者: 杨程
+// 创建日期: 2022/10/24 16:59:55
+
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using static System.Linq.Expressions.Expression;
+
+
+
+namespace Vampirewal.Core.Mapper;
+
+///
+/// 映射管理器
+///
+public static class MapperManager
+{
+
+
+ static Dictionary MapperDic = new Dictionary();
+
+ #region 注册(Register)
+ public static void RegisterAll()
+ {
+ /*
+ * 注意事项:
+ * 1、如果是WPF使用的话,建议把ViewModelLocator放在VM类库中
+ * 2、然后再调用这个,才能在初始化的时候,找到VM这个类库,然后加载里面的ViewModel,不然的话,找不到VM这个程序集,会无法加载ViewModel
+ */
+
+
+
+ var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()).Where(w => w.GetInterface("IVampirewalMapper") != null).ToList();
+
+
+
+ foreach (var v in types)
+ {
+ var aaa = Activator.CreateInstance(v) as IVampirewalMapper;
+
+ var target = aaa.MapperTargetType();
+
+ MapperDic.Add(v, target);
+ }
+ }
+ #endregion
+
+ #region 属性
+
+ #endregion
+
+ #region 公共方法
+
+ public static TTarget Map(Tsource source) where Tsource : class, new() where TTarget : class, new()
+ {
+ //MapperDic.TryGetValue(typeof(Tsource), out Type target);
+
+ var result = Activator.CreateInstance(typeof(TTarget));
+
+ var SourceProps = typeof(Tsource).GetProperties();
+ var TargetProps = typeof(TTarget).GetProperties();
+
+ foreach (var prop1 in SourceProps)
+ {
+ foreach (var prop2 in TargetProps)
+ {
+ if (prop2.PropertyType.IsValueType || prop2.PropertyType.Name.StartsWith("String"))
+ {
+ if (prop1.Name == prop2.Name)
+ {
+ try
+ {
+ object value = prop1.GetValue(source, null);
+ var prop = typeof(TTarget).GetProperty(prop1.Name);
+ if (prop != null && prop.CanWrite && !(value is DBNull))
+ {
+ prop.SetValue(result, value, null);
+ }
+ }
+ catch (Exception)
+ {
+
+ throw;
+ }
+ }
+ }
+ }
+ }
+
+ return (TTarget)result;
+ }
+
+ public static object Map(TSource source)
+ {
+
+ if (MapperDic.TryGetValue(typeof(TSource), out Type target))
+ {
+ var result = Activator.CreateInstance(target);
+
+ var SourceProps = typeof(TSource).GetProperties();
+ var TargetProps = target.GetProperties();
+
+ foreach (var prop1 in SourceProps)
+ {
+ foreach (var prop2 in TargetProps)
+ {
+ if (prop2.PropertyType.IsValueType || prop2.PropertyType.Name.StartsWith("String"))
+ {
+ if (prop1.Name == prop2.Name)
+ {
+ try
+ {
+ object value = prop1.GetValue(source, null);
+ var prop = target.GetProperty(prop1.Name);
+ if (prop != null && prop.CanWrite && !(value is DBNull))
+ {
+ prop.SetValue(result, value, null);
+ }
+ }
+ catch (Exception)
+ {
+
+ throw;
+ }
+ }
+ }
+ }
+ }
+
+ return result;
+ }
+ else
+ {
+ throw new Exception("未注册目标类型");
+ }
+
+
+ }
+
+ ///
+ /// 简单映射
+ ///
+ /// 目标类型
+ ///
+ ///
+ public static TTarget SimpleMap(this object source)
+ {
+ var result = Activator.CreateInstance(typeof(TTarget));
+
+ var SourceProps = source.GetType().GetProperties();
+ var TargetProps = typeof(TTarget).GetProperties();
+
+ foreach (var prop1 in SourceProps)
+ {
+ foreach (var prop2 in TargetProps)
+ {
+ if (prop2.PropertyType.IsValueType || prop2.PropertyType.Name.StartsWith("String"))
+ {
+ if (prop1.Name == prop2.Name)
+ {
+ try
+ {
+ object value = prop1.GetValue(source, null);
+ var prop = typeof(TTarget).GetProperty(prop1.Name);
+ if (prop != null && prop.CanWrite && !(value is DBNull))
+ {
+ prop.SetValue(result, value, null);
+ }
+ }
+ catch (Exception ex)
+ {
+
+ throw ex;
+ }
+ }
+ }
+ }
+ }
+
+ return (TTarget)result;
+ }
+
+ #endregion
+
+ #region 私有方法
+
+ #endregion
+
+ #region Command命令
+
+ #endregion
+}
+
+
+public static class Mapper where TSource : class where TTarget : class
+{
+ public readonly static Func MapFunc = GetMapFunc();
+
+ public readonly static Action MapAction = GetMapAction();
+
+ ///
+ /// 将对象TSource转换为TTarget
+ ///
+ ///
+ ///
+ public static TTarget Map(TSource source) => MapFunc(source);
+
+ public static List MapList(IEnumerable sources) => sources.Select(MapFunc).ToList();
+
+
+
+ ///
+ /// 将对象TSource的值赋给给TTarget
+ ///
+ ///
+ ///
+ public static void Map(TSource source, TTarget target) => MapAction(source, target);
+
+ private static Func GetMapFunc()
+ {
+ var sourceType = typeof(TSource);
+ var targetType = typeof(TTarget);
+ //Func委托传入变量
+ var parameter = Parameter(sourceType, "p");
+
+ var memberBindings = new List();
+ var targetTypes = targetType.GetProperties().Where(x => x.PropertyType.IsPublic && x.CanWrite);
+ foreach (var targetItem in targetTypes)
+ {
+ var sourceItem = sourceType.GetProperty(targetItem.Name);
+
+ //判断实体的读写权限
+ if (sourceItem == null || !sourceItem.CanRead || sourceItem.PropertyType.IsNotPublic)
+ continue;
+
+ //标注NotMapped特性的属性忽略转换
+ if (sourceItem.GetCustomAttribute() != null)
+ continue;
+
+ var sourceProperty = Property(parameter, sourceItem);
+
+ //当非值类型且类型不相同时
+ if (!sourceItem.PropertyType.IsValueType && sourceItem.PropertyType != targetItem.PropertyType)
+ {
+ //判断都是(非泛型)class
+ if (sourceItem.PropertyType.IsClass && targetItem.PropertyType.IsClass &&
+ !sourceItem.PropertyType.IsGenericType && !targetItem.PropertyType.IsGenericType)
+ {
+ var expression = GetClassExpression(sourceProperty, sourceItem.PropertyType, targetItem.PropertyType);
+ memberBindings.Add(Bind(targetItem, expression));
+ }
+
+ //集合数组类型的转换
+ if (typeof(IEnumerable).IsAssignableFrom(sourceItem.PropertyType) && typeof(IEnumerable).IsAssignableFrom(targetItem.PropertyType))
+ {
+ var expression = GetListExpression(sourceProperty, sourceItem.PropertyType, targetItem.PropertyType);
+ memberBindings.Add(Bind(targetItem, expression));
+ }
+
+ continue;
+ }
+
+ if (targetItem.PropertyType != sourceItem.PropertyType)
+ continue;
+
+ memberBindings.Add(Bind(targetItem, sourceProperty));
+ }
+
+ //创建一个if条件表达式
+ var test = NotEqual(parameter, Constant(null, sourceType));// p==null;
+ var ifTrue = MemberInit(New(targetType), memberBindings);
+ var condition = Condition(test, ifTrue, Constant(null, targetType));
+
+ var lambda = Lambda>(condition, parameter);
+ return lambda.Compile();
+ }
+
+ ///
+ /// 类型是clas时赋值
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ private static Expression GetClassExpression(Expression sourceProperty, Type sourceType, Type targetType)
+ {
+ //条件p.Item!=null
+ var testItem = NotEqual(sourceProperty, Constant(null, sourceType));
+
+ //构造回调 Mapper.Map()
+ var mapperType = typeof(Mapper<,>).MakeGenericType(sourceType, targetType);
+ var iftrue = Call(mapperType.GetMethod(nameof(Map), new[] { sourceType }), sourceProperty);
+
+ var conditionItem = Condition(testItem, iftrue, Constant(null, targetType));
+
+ return conditionItem;
+ }
+
+ ///
+ /// 类型为集合时赋值
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ private static Expression GetListExpression(Expression sourceProperty, Type sourceType, Type targetType)
+ {
+ //条件p.Item!=null
+ var testItem = NotEqual(sourceProperty, Constant(null, sourceType));
+
+ //构造回调 Mapper.MapList()
+ var sourceArg = sourceType.IsArray ? sourceType.GetElementType() : sourceType.GetGenericArguments()[0];
+ var targetArg = targetType.IsArray ? targetType.GetElementType() : targetType.GetGenericArguments()[0];
+ var mapperType = typeof(Mapper<,>).MakeGenericType(sourceArg, targetArg);
+
+ var mapperExecMap = Call(mapperType.GetMethod(nameof(MapList), new[] { sourceType }), sourceProperty);
+
+ Expression iftrue;
+ if (targetType == mapperExecMap.Type)
+ {
+ iftrue = mapperExecMap;
+ }
+ else if (targetType.IsArray)//数组类型调用ToArray()方法
+ {
+ iftrue = Call(mapperExecMap, mapperExecMap.Type.GetMethod("ToArray"));
+ }
+ else if (typeof(IDictionary).IsAssignableFrom(targetType))
+ {
+ iftrue = Constant(null, targetType);//字典类型不转换
+ }
+ else
+ {
+ iftrue = Convert(mapperExecMap, targetType);
+ }
+
+ var conditionItem = Condition(testItem, iftrue, Constant(null, targetType));
+
+ return conditionItem;
+ }
+
+ private static Action GetMapAction()
+ {
+ var sourceType = typeof(TSource);
+ var targetType = typeof(TTarget);
+ //Func委托传入变量
+ var sourceParameter = Parameter(sourceType, "p");
+
+ var targetParameter = Parameter(targetType, "t");
+
+ //创建一个表达式集合
+ var expressions = new List();
+
+ var targetTypes = targetType.GetProperties().Where(x => x.PropertyType.IsPublic && x.CanWrite);
+ foreach (var targetItem in targetTypes)
+ {
+ var sourceItem = sourceType.GetProperty(targetItem.Name);
+
+ //判断实体的读写权限
+ if (sourceItem == null || !sourceItem.CanRead || sourceItem.PropertyType.IsNotPublic)
+ continue;
+
+ //标注NotMapped特性的属性忽略转换
+ if (sourceItem.GetCustomAttribute() != null)
+ continue;
+
+ var sourceProperty = Property(sourceParameter, sourceItem);
+ var targetProperty = Property(targetParameter, targetItem);
+
+ //当非值类型且类型不相同时
+ if (!sourceItem.PropertyType.IsValueType && sourceItem.PropertyType != targetItem.PropertyType)
+ {
+ //判断都是(非泛型)class
+ if (sourceItem.PropertyType.IsClass && targetItem.PropertyType.IsClass &&
+ !sourceItem.PropertyType.IsGenericType && !targetItem.PropertyType.IsGenericType)
+ {
+ var expression = GetClassExpression(sourceProperty, sourceItem.PropertyType, targetItem.PropertyType);
+ expressions.Add(Assign(targetProperty, expression));
+ }
+
+ //集合数组类型的转换
+ if (typeof(IEnumerable).IsAssignableFrom(sourceItem.PropertyType) && typeof(IEnumerable).IsAssignableFrom(targetItem.PropertyType))
+ {
+ var expression = GetListExpression(sourceProperty, sourceItem.PropertyType, targetItem.PropertyType);
+ expressions.Add(Assign(targetProperty, expression));
+ }
+
+ continue;
+ }
+
+ if (targetItem.PropertyType != sourceItem.PropertyType)
+ continue;
+
+
+ expressions.Add(Assign(targetProperty, sourceProperty));
+ }
+
+ //当Target!=null判断source是否为空
+ var testSource = NotEqual(sourceParameter, Constant(null, sourceType));
+ var ifTrueSource = Block(expressions);
+ var conditionSource = IfThen(testSource, ifTrueSource);
+
+ //判断target是否为空
+ var testTarget = NotEqual(targetParameter, Constant(null, targetType));
+ var conditionTarget = IfThen(testTarget, conditionSource);
+
+ var lambda = Lambda>(conditionTarget, sourceParameter, targetParameter);
+ return lambda.Compile();
+ }
+}
diff --git a/Vampirewal.Core.Mapper/Vampirewal.Core.Mapper.csproj b/Vampirewal.Core.Mapper/Vampirewal.Core.Mapper.csproj
new file mode 100644
index 0000000..132c02c
--- /dev/null
+++ b/Vampirewal.Core.Mapper/Vampirewal.Core.Mapper.csproj
@@ -0,0 +1,9 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
diff --git a/Vampirewal.Core.Mapper/VampirewalMapperAttribute.cs b/Vampirewal.Core.Mapper/VampirewalMapperAttribute.cs
new file mode 100644
index 0000000..ba88394
--- /dev/null
+++ b/Vampirewal.Core.Mapper/VampirewalMapperAttribute.cs
@@ -0,0 +1,65 @@
+
+#region 文件信息
+/*----------------------------------------------------------------
+//
+// 文件名称:
+// 文件功能描述:
+// 设计要求:
+//
+// 文 件 名: VampirewalMapperAttribute
+// 创建者: 杨程
+// 创建日期: 2022/10/24 17:15:39
+
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+
+
+namespace Vampirewal.Core.Mapper
+{
+ ///
+ /// 类型映射特性
+ ///
+ [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
+ public class VampirewalMapperAttribute: Attribute
+ {
+ ///
+ ///
+ ///
+ public VampirewalMapperAttribute(Type target)
+ {
+ //构造函数
+ Target=target;
+ }
+
+
+
+ #region 属性
+ ///
+ /// 目标类型
+ ///
+ public Type Target { get; set; }
+ #endregion
+
+ #region 公共方法
+
+ #endregion
+
+ #region 私有方法
+
+ #endregion
+
+ #region Command命令
+
+ #endregion
+ }
+
+
+
+}
diff --git a/Vampirewal.Core/Extensions/EntityExtension.cs b/Vampirewal.Core/Extensions/EntityExtension.cs
index 910ca17..f0137c0 100644
--- a/Vampirewal.Core/Extensions/EntityExtension.cs
+++ b/Vampirewal.Core/Extensions/EntityExtension.cs
@@ -38,5 +38,48 @@ namespace Vampirewal.Core.Extensions
type.GetAllProperties().ForEach(f => { f.GetCustomAttribute(typeof(RequiredAttribute)); });
}
+
+ ///
+ /// 简单映射
+ ///
+ /// 目标类型
+ ///
+ ///
+ public static TTarget SimpleMap(this object source)
+ {
+ var result = Activator.CreateInstance(typeof(TTarget));
+
+ var SourceProps = source.GetType().GetProperties();
+ var TargetProps = typeof(TTarget).GetProperties();
+
+ foreach (var prop1 in SourceProps)
+ {
+ foreach (var prop2 in TargetProps)
+ {
+ if (prop2.PropertyType.IsValueType || prop2.PropertyType.Name.StartsWith("String"))
+ {
+ if (prop1.Name == prop2.Name)
+ {
+ try
+ {
+ object value = prop1.GetValue(source, null);
+ var prop = typeof(TTarget).GetProperty(prop1.Name);
+ if (prop != null && prop.CanWrite && !(value is DBNull))
+ {
+ prop.SetValue(result, value, null);
+ }
+ }
+ catch (Exception ex)
+ {
+
+ throw ex;
+ }
+ }
+ }
+ }
+ }
+
+ return (TTarget)result;
+ }
}
}
diff --git a/Vampirewal.Core/Tools/Utils.cs b/Vampirewal.Core/Tools/Utils.cs
index 68468dd..8dd2342 100644
--- a/Vampirewal.Core/Tools/Utils.cs
+++ b/Vampirewal.Core/Tools/Utils.cs
@@ -806,7 +806,6 @@ namespace Vampirewal.Core
///
/// 模型转换
///
- /// 被转换的类型
/// 转换成的类型
/// 被转换的model
///
@@ -840,7 +839,7 @@ namespace Vampirewal.Core
/// 转换成的类型
/// 需要转换的json
///
- public OutT ModelConverter(string json)
+ public static OutT ModelConverter(string json)
{
Type InType = typeof(InT);
InT inTModel = JsonSerializer.Deserialize(json);
diff --git a/Vampirewal.Core/Vampirewal.Core.csproj b/Vampirewal.Core/Vampirewal.Core.csproj
index c46975f..acbd4e5 100644
--- a/Vampirewal.Core/Vampirewal.Core.csproj
+++ b/Vampirewal.Core/Vampirewal.Core.csproj
@@ -7,7 +7,7 @@
该Core类库详细介绍请查看:https://blog.csdn.net/weixin_42806176/article/details/120705323
(2.X开始的ORM使用SqlSugar,1.X使用的EFCore)
true
- 2.1.1.8
+ 2.1.1.10
true
https://blog.csdn.net/weixin_42806176/article/details/120705323
Vampirewal-Logo.png
diff --git a/YC.Core.sln b/YC.Core.sln
index ecaa04e..1850ccc 100644
--- a/YC.Core.sln
+++ b/YC.Core.sln
@@ -27,10 +27,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "test.View2", "test.View2\te
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vampirewal.Core.OperationExcelService", "Vampirewal.Core.OperationExcelService\Vampirewal.Core.OperationExcelService.csproj", "{898CEEAD-8595-4CD7-A05F-2C40AC0DB640}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vampirewal.Core.HttpClientService", "Vampirewal.Core.HttpClientService\Vampirewal.Core.HttpClientService.csproj", "{4DE48346-5142-46EB-8AA9-168C7C96728A}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vampirewal.Core.HttpClientService", "Vampirewal.Core.HttpClientService\Vampirewal.Core.HttpClientService.csproj", "{4DE48346-5142-46EB-8AA9-168C7C96728A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Components", "Components", "{D70678FD-58AC-4EFF-B995-F27A6F15AF4B}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vampirewal.Core.Mapper", "Vampirewal.Core.Mapper\Vampirewal.Core.Mapper.csproj", "{149DA856-E073-40FD-95AF-A0C3D77C5FDA}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -85,6 +87,10 @@ Global
{4DE48346-5142-46EB-8AA9-168C7C96728A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4DE48346-5142-46EB-8AA9-168C7C96728A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4DE48346-5142-46EB-8AA9-168C7C96728A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {149DA856-E073-40FD-95AF-A0C3D77C5FDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {149DA856-E073-40FD-95AF-A0C3D77C5FDA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {149DA856-E073-40FD-95AF-A0C3D77C5FDA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {149DA856-E073-40FD-95AF-A0C3D77C5FDA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -99,6 +105,7 @@ Global
{E2EFCFE0-FECA-485D-A60D-3480A81906FB} = {DFE920C8-C41C-4596-86AF-BAF20E305BDC}
{898CEEAD-8595-4CD7-A05F-2C40AC0DB640} = {D70678FD-58AC-4EFF-B995-F27A6F15AF4B}
{4DE48346-5142-46EB-8AA9-168C7C96728A} = {D70678FD-58AC-4EFF-B995-F27A6F15AF4B}
+ {149DA856-E073-40FD-95AF-A0C3D77C5FDA} = {D70678FD-58AC-4EFF-B995-F27A6F15AF4B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F95EFBE7-9DF8-4104-AFCC-ADE3D80BD902}
--
Gitee
From 4e23bbd69740a0d3086941bfa0213c6caf72a89e Mon Sep 17 00:00:00 2001
From: YangCheng <235160615@qq.com>
Date: Tue, 1 Nov 2022 17:29:07 +0800
Subject: [PATCH 27/53] 123
---
.../Attributes/ListenDetailChangeAttribute.cs | 45 ++++
Vampirewal.Core/Models/DetailBaseModel.cs | 57 +----
.../Models/DetailItemChangeBaseModel.cs | 236 ++++++++++++++++++
Vampirewal.Core/Vampirewal.Core.csproj | 14 +-
YC.Core.sln | 2 +-
5 files changed, 294 insertions(+), 60 deletions(-)
create mode 100644 Vampirewal.Core/Attributes/ListenDetailChangeAttribute.cs
create mode 100644 Vampirewal.Core/Models/DetailItemChangeBaseModel.cs
diff --git a/Vampirewal.Core/Attributes/ListenDetailChangeAttribute.cs b/Vampirewal.Core/Attributes/ListenDetailChangeAttribute.cs
new file mode 100644
index 0000000..a432aa5
--- /dev/null
+++ b/Vampirewal.Core/Attributes/ListenDetailChangeAttribute.cs
@@ -0,0 +1,45 @@
+
+#region 文件信息
+/*----------------------------------------------------------------
+//
+// 文件名称:
+// 文件功能描述:
+// 设计要求:
+//
+// 文 件 名: ListenDetailChangeAttribute
+// 创建者: 杨程
+// 创建日期: 2022/10/31 18:23:24
+
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Threading.Tasks;
+
+
+
+namespace Vampirewal.Core.Attributes
+{
+ ///
+ /// 监听明细项属性变更特性
+ ///
+ [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
+ public class ListenDetailChangeAttribute: Attribute
+ {
+ ///
+ ///
+ ///
+ /// 属性名称
+ public ListenDetailChangeAttribute([CallerMemberName] string propertyName="")
+ {
+ PropertyName = propertyName;
+ //构造函数
+ }
+
+ public string PropertyName { get; set; }
+ }
+}
diff --git a/Vampirewal.Core/Models/DetailBaseModel.cs b/Vampirewal.Core/Models/DetailBaseModel.cs
index 0048a74..9cbd6b4 100644
--- a/Vampirewal.Core/Models/DetailBaseModel.cs
+++ b/Vampirewal.Core/Models/DetailBaseModel.cs
@@ -11,10 +11,12 @@
//----------------------------------------------------------------*/
#endregion
+using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Vampirewal.Core.Attributes;
@@ -79,58 +81,5 @@ namespace Vampirewal.Core.Models
}
- public class DetailBaseModel : TopModel where T:BillBaseModel
-
- {
- public DetailBaseModel()
- {
- //构造函数
- }
-
- private string _DtlId;
- ///
- /// 明细ID
- ///
- [SugarColumn(IsPrimaryKey = true, IsNullable = false, ColumnDescription = "主键")]
- //[ExportExcel(propertyChineseName: "明细ID", propertyName: "DtlId", IsCanExport = true)]
- public string DtlId
- {
- get
- {
- if (string.IsNullOrEmpty(_DtlId))
- {
- _DtlId = Guid.NewGuid().ToString();
- }
- return _DtlId;
- }
- set
- {
- _DtlId = value;
- DoNotify();
- }
- }
-
- private string _BillId;
-
- ///
- /// 关联单据Id
- ///
- [SugarColumn(IsNullable = false)]
- //[ExportExcel(propertyChineseName: "单据ID", propertyName: "BillId", IsCanExport = true)]
- public string BillId
- {
- get
- {
- return _BillId;
- }
- set
- {
- _BillId = value;
- DoNotify();
- }
- }
-
-
-
- }
+
}
diff --git a/Vampirewal.Core/Models/DetailItemChangeBaseModel.cs b/Vampirewal.Core/Models/DetailItemChangeBaseModel.cs
new file mode 100644
index 0000000..cfd8665
--- /dev/null
+++ b/Vampirewal.Core/Models/DetailItemChangeBaseModel.cs
@@ -0,0 +1,236 @@
+
+#region 文件信息
+/*----------------------------------------------------------------
+//
+// 文件名称:
+// 文件功能描述:
+// 设计要求:
+//
+// 文 件 名: DetailItemChangeBaseModel
+// 创建者: 杨程
+// 创建日期: 2022/11/1 17:21:18
+
+//----------------------------------------------------------------*/
+#endregion
+
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using Vampirewal.Core.Attributes;
+
+namespace Vampirewal.Core.Models
+{
+ ///
+ /// 明细项变更基类
+ ///
+ ///
+ public abstract class DetailItemChangeBaseModel : TopModel where TDto : TopModel
+
+ {
+
+ //private string _sourceValueMD5;
+ ///
+ /// 当前项的变更状态
+ ///
+ public ChangeType InnerItemChangeType { get; private set; }
+
+ public DetailItemChangeBaseModel(TDto dto)
+ {
+ if (dto == null)
+ {
+ InnerItemChangeType = ChangeType.Add;
+
+
+ }
+ else
+ {
+ LoadDTO(dto);
+ RefreshSourceValue();
+
+ }
+ }
+
+ #region 基础属性
+ private string _DtlId;
+ ///
+ /// 明细ID
+ ///
+ [SugarColumn(IsPrimaryKey = true, IsNullable = false, ColumnDescription = "主键")]
+ //[ExportExcel(propertyChineseName: "明细ID", propertyName: "DtlId", IsCanExport = true)]
+ public string DtlId
+ {
+ get
+ {
+ if (string.IsNullOrEmpty(_DtlId))
+ {
+ _DtlId = Guid.NewGuid().ToString();
+ }
+ return _DtlId;
+ }
+ set
+ {
+ _DtlId = value;
+ DoNotify();
+ }
+ }
+
+ private string _BillId;
+
+ ///
+ /// 关联单据Id
+ ///
+ [SugarColumn(IsNullable = false)]
+ //[ExportExcel(propertyChineseName: "单据ID", propertyName: "BillId", IsCanExport = true)]
+ public string BillId
+ {
+ get
+ {
+ return _BillId;
+ }
+ set
+ {
+ _BillId = value;
+ DoNotify();
+ }
+ }
+ #endregion
+
+
+ ///
+ /// 记录原始值,并刷新变更状态为NoChanged
+ ///
+ public void RefreshSourceValue()
+ {
+ InnerItemChangeType = ChangeType.NoChanged;
+ //_sourceValueMD5 = CreateCurrentValueToken();
+ GetOldValueByAttribute();
+ }
+
+ ///
+ /// 设置当前项为删除状态
+ ///
+ public void SetDeleteState()
+ {
+ InnerItemChangeType = ChangeType.Deleted;
+ }
+ ///
+ /// 加载DTO,如果这里使用到该DTO,需要在该方法里面实例化
+ ///
+ /// 原始的DTO,可以为null
+ public abstract void LoadDTO(TDto dto);
+
+
+ /////
+ ///// 比较原始值
+ /////
+ //public virtual bool CompareSourceValue()
+ //{
+ // if (InnerItemChangeType != ChangeType.Deleted &&
+ // InnerItemChangeType != ChangeType.Add)
+ // {
+ // string curToken = CreateCurrentValueToken();
+ // InnerItemChangeType = _sourceValueMD5 != curToken ?
+ // ChangeType.Changed : ChangeType.NoChanged;
+ // }
+ // return InnerItemChangeType != ChangeType.NoChanged;
+ //}
+ /////
+ ///// 创建当前值的标识
+ /////
+ //protected virtual string CreateCurrentValueToken()
+ //{
+ // var jsonStr = JsonConvert.SerializeObject(this);
+ // return Utils.GetMD5String(jsonStr);
+
+
+ //}
+
+
+ private Dictionary OldDic = new Dictionary();
+
+ ///
+ /// 通过特性获取初始值
+ ///
+ private void GetOldValueByAttribute()
+ {
+ var Props = this.GetType().GetProperties().Where(w => w.GetCustomAttribute() != null);
+
+ foreach (PropertyInfo prop in Props)
+ {
+ var att = prop.GetCustomAttribute();
+
+ if (att != null)
+ {
+ var OldVaule = prop.GetValue(this, null);
+
+ OldDic.Add(att.PropertyName, OldVaule);
+ }
+ }
+ }
+
+ ///
+ /// 比较原始值
+ ///
+ ///
+ public bool CompareSourceValue()
+ {
+ var Props = this.GetType().GetProperties().Where(w => w.GetCustomAttribute() != null);
+
+ bool IsChange = false;
+
+ foreach (PropertyInfo prop in Props)
+ {
+ if (IsChange)
+ {
+ continue;
+ }
+
+ var Newatt = prop.GetCustomAttribute();
+
+ if (Newatt != null && OldDic.TryGetValue(Newatt.PropertyName, out object OldVaule))
+ {
+ var NewVaule = prop.GetValue(this, null);
+
+ if (InnerItemChangeType != ChangeType.Deleted && InnerItemChangeType != ChangeType.Add)
+ {
+ InnerItemChangeType = NewVaule != OldVaule ? ChangeType.Changed : ChangeType.NoChanged;
+ }
+ }
+
+ if (InnerItemChangeType != ChangeType.NoChanged)
+ {
+ IsChange = true;
+ }
+ }
+
+ return IsChange;
+ }
+ }
+
+ ///
+ /// 细目变更状态
+ ///
+ public enum ChangeType
+ {
+ ///
+ /// 删除
+ ///
+ Deleted = -1,
+ ///
+ /// 未变更
+ ///
+ NoChanged = 0,
+ ///
+ /// 新增
+ ///
+ Add = 1,
+ ///
+ /// 编辑
+ ///
+ Changed = 2
+ }
+}
diff --git a/Vampirewal.Core/Vampirewal.Core.csproj b/Vampirewal.Core/Vampirewal.Core.csproj
index acbd4e5..854330e 100644
--- a/Vampirewal.Core/Vampirewal.Core.csproj
+++ b/Vampirewal.Core/Vampirewal.Core.csproj
@@ -36,7 +36,6 @@
-
@@ -72,10 +71,6 @@
-
- True
-
-
@@ -95,6 +90,15 @@
+
+
+
+
+
+ True
+ \
+
+
diff --git a/YC.Core.sln b/YC.Core.sln
index 1850ccc..f9994d2 100644
--- a/YC.Core.sln
+++ b/YC.Core.sln
@@ -31,7 +31,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vampirewal.Core.HttpClientS
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Components", "Components", "{D70678FD-58AC-4EFF-B995-F27A6F15AF4B}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vampirewal.Core.Mapper", "Vampirewal.Core.Mapper\Vampirewal.Core.Mapper.csproj", "{149DA856-E073-40FD-95AF-A0C3D77C5FDA}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vampirewal.Core.Mapper", "Vampirewal.Core.Mapper\Vampirewal.Core.Mapper.csproj", "{149DA856-E073-40FD-95AF-A0C3D77C5FDA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
--
Gitee
From 33f1cf7da29834dbfc6650d817be3c60bc742aa4 Mon Sep 17 00:00:00 2001
From: YangCheng <235160615@qq.com>
Date: Mon, 7 Nov 2022 11:34:03 +0800
Subject: [PATCH 28/53] 20221107
---
.../Models/DetailItemChangeBaseModel.cs | 1 -
Vampirewal.Core/SimpleMVVM/Messenger.cs | 2 +-
Vampirewal.Core/Vampirewal.Core.csproj | 5 +-
.../WpfTheme/Attach/TouchEventCommands.cs | 134 +++++
Vampirewal.Core/WpfTheme/CoreTheme.xaml | 24 +-
.../DataGrid/DataGridStyles.xaml | 17 +-
.../EditPage/EditContaninerStyle.xaml | 282 +++++-----
.../LoadingContainerStyle.xaml | 478 +++++++---------
.../NumTextBox/NumTextBoxStyle.xaml | 87 ++-
.../Pagination/VPaginationStyles.xaml | 216 ++++----
.../SearchControl/SearchControlStyle.xaml | 63 ++-
.../WpfTheme/UcView/UcViewStyles.xaml | 6 +-
.../WpfTheme/WindowStyle/WindowStyles.xaml | 524 ++++++++----------
13 files changed, 909 insertions(+), 930 deletions(-)
create mode 100644 Vampirewal.Core/WpfTheme/Attach/TouchEventCommands.cs
diff --git a/Vampirewal.Core/Models/DetailItemChangeBaseModel.cs b/Vampirewal.Core/Models/DetailItemChangeBaseModel.cs
index cfd8665..a5c027f 100644
--- a/Vampirewal.Core/Models/DetailItemChangeBaseModel.cs
+++ b/Vampirewal.Core/Models/DetailItemChangeBaseModel.cs
@@ -29,7 +29,6 @@ namespace Vampirewal.Core.Models
///
///
public abstract class DetailItemChangeBaseModel : TopModel where TDto : TopModel
-
{
//private string _sourceValueMD5;
diff --git a/Vampirewal.Core/SimpleMVVM/Messenger.cs b/Vampirewal.Core/SimpleMVVM/Messenger.cs
index 663dc73..11fcabc 100644
--- a/Vampirewal.Core/SimpleMVVM/Messenger.cs
+++ b/Vampirewal.Core/SimpleMVVM/Messenger.cs
@@ -40,7 +40,7 @@ namespace Vampirewal.Core.SimpleMVVM
foreach (var v in types)
{
object obj = Activator.CreateInstance(v);
- MethodInfo[] methods = obj.GetType().GetMethods();
+ MethodInfo[] methods = obj.GetType().GetMethods().Where(w=>w.GetCustomAttribute()!=null).ToArray();
foreach (var item in methods)
{
RegistMethodAttribute attribute = item.GetCustomAttribute();
diff --git a/Vampirewal.Core/Vampirewal.Core.csproj b/Vampirewal.Core/Vampirewal.Core.csproj
index 854330e..557ada7 100644
--- a/Vampirewal.Core/Vampirewal.Core.csproj
+++ b/Vampirewal.Core/Vampirewal.Core.csproj
@@ -7,7 +7,7 @@
该Core类库详细介绍请查看:https://blog.csdn.net/weixin_42806176/article/details/120705323
(2.X开始的ORM使用SqlSugar,1.X使用的EFCore)
true
- 2.1.1.10
+ 2.1.1.12
true
https://blog.csdn.net/weixin_42806176/article/details/120705323
Vampirewal-Logo.png
@@ -37,6 +37,7 @@
+
@@ -82,7 +83,7 @@
-
+
diff --git a/Vampirewal.Core/WpfTheme/Attach/TouchEventCommands.cs b/Vampirewal.Core/WpfTheme/Attach/TouchEventCommands.cs
new file mode 100644
index 0000000..f9e6feb
--- /dev/null
+++ b/Vampirewal.Core/WpfTheme/Attach/TouchEventCommands.cs
@@ -0,0 +1,134 @@
+
+#region 文件信息
+/*----------------------------------------------------------------
+//
+// 文件名称:
+// 文件功能描述:
+// 设计要求:
+//
+// 文 件 名: TouchEventCommands
+// 创建者: 杨程
+// 创建日期: 2022/11/2 17:55:35
+
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Diagnostics.Tracing;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace Vampirewal.Core.WpfTheme.Attach
+{
+ public interface IEventAction
+ {
+ string EventName { get; }
+ }
+
+ ///
+ /// MVVM事件绑定,详细看CSDN博客
+ /// 此处代码引用自 若汝棋茗
+ /// CSDN博客:https://blog.csdn.net/qq_40374647/article/details/127651804?spm=1001.2014.3001.5501
+ /// 哔哩哔哩视频:https://space.bilibili.com/94253567
+ /// Gitee源代码仓库:https://gitee.com/RRQM_Home
+ /// Github源代码仓库:https://github.com/RRQM
+ /// API首页:https://www.yuque.com/rrqm/touchsocket/index
+ /// 交流QQ群:234762506
+ ///
+ public static class TouchEventCommands
+ {
+ // Using a DependencyProperty as the backing store for Events. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty EventsProperty =
+ DependencyProperty.RegisterAttached("Events", typeof(IEnumerable), typeof(TouchEventCommands), new PropertyMetadata(null, OnCommandChanged));
+
+ public static IEnumerable GetEvents(DependencyObject obj)
+ {
+ return (IEnumerable)obj.GetValue(EventsProperty);
+ }
+
+ public static void SetEvents(DependencyObject obj, IEnumerable value)
+ {
+ obj.SetValue(EventsProperty, value);
+ }
+
+ private static void OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ if (e.NewValue is IEnumerable eventActions)
+ {
+ foreach (IEventAction eventAction in eventActions)
+ {
+ if (!string.IsNullOrEmpty(eventAction.EventName))
+ {
+ EventInfo eventInfo = d.GetType().GetEvent(eventAction.EventName);
+ if (eventInfo == null)
+ {
+ throw new Exception($"没有找到名称为{eventAction.EventName}的事件");
+ }
+ Delegate @delegate = Delegate.CreateDelegate(eventInfo.EventHandlerType, eventAction, "Event");
+ //Delegate @delegate2 = eventAction.Begin(eventInfo.EventHandlerType, typeof(object), typeof(MouseButtonEventArgs));
+ //Delegate @delegate = DelegateBuilder.CreateDelegate(eventAction, "Event", eventInfo.EventHandlerType, BindingFlags.NonPublic);
+ eventInfo.AddEventHandler(d, @delegate);
+ }
+ else
+ {
+ throw new Exception($"事件名不能为空");
+ }
+ }
+ }
+ }
+ }
+
+ public class EventAction : IEventAction
+ {
+ private readonly Action action;
+
+ private readonly string eventName;
+
+ public EventAction(string eventName, Action action)
+ {
+ this.eventName = eventName;
+ this.action = action;
+ }
+
+ public string EventName => this.eventName;
+
+ private void Event(TSender sender, TE e)
+ {
+ this.action?.Invoke(sender, e);
+ }
+ }
+
+ public class EventAction : IEventAction
+ {
+ private readonly Action action;
+
+ private readonly Action action2;
+
+ private readonly string eventName;
+
+ public EventAction(string eventName, Action action)
+ {
+ this.eventName = eventName;
+ this.action = action;
+ }
+
+ public EventAction(string eventName, Action action)
+ {
+ this.eventName = eventName;
+ this.action2 = action;
+ }
+
+ public string EventName => this.eventName;
+
+ private void Event(object sender, TE e)
+ {
+ this.action?.Invoke(sender);
+ this.action2?.Invoke(e);
+ }
+ }
+}
diff --git a/Vampirewal.Core/WpfTheme/CoreTheme.xaml b/Vampirewal.Core/WpfTheme/CoreTheme.xaml
index 3b233fd..d254523 100644
--- a/Vampirewal.Core/WpfTheme/CoreTheme.xaml
+++ b/Vampirewal.Core/WpfTheme/CoreTheme.xaml
@@ -48,9 +48,8 @@
-
-
+
+
@@ -82,20 +81,17 @@
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/DataGrid/DataGridStyles.xaml b/Vampirewal.Core/WpfTheme/CustomControl/DataGrid/DataGridStyles.xaml
index 371bd33..0becd00 100644
--- a/Vampirewal.Core/WpfTheme/CustomControl/DataGrid/DataGridStyles.xaml
+++ b/Vampirewal.Core/WpfTheme/CustomControl/DataGrid/DataGridStyles.xaml
@@ -1,11 +1,8 @@
-
-
-
-
-
-
+
+
\ No newline at end of file
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/EditPage/EditContaninerStyle.xaml b/Vampirewal.Core/WpfTheme/CustomControl/EditPage/EditContaninerStyle.xaml
index e17a556..63c2eb9 100644
--- a/Vampirewal.Core/WpfTheme/CustomControl/EditPage/EditContaninerStyle.xaml
+++ b/Vampirewal.Core/WpfTheme/CustomControl/EditPage/EditContaninerStyle.xaml
@@ -1,51 +1,43 @@
-
+
-
+
-
+
@@ -98,19 +88,20 @@
-
-
-
-
+
+
+
+
\ No newline at end of file
diff --git a/Vampirewal.Core/WpfTheme/CustomControl/Pagination/VPaginationStyles.xaml b/Vampirewal.Core/WpfTheme/CustomControl/Pagination/VPaginationStyles.xaml
index 3774bad..79a2a54 100644
--- a/Vampirewal.Core/WpfTheme/CustomControl/Pagination/VPaginationStyles.xaml
+++ b/Vampirewal.Core/WpfTheme/CustomControl/Pagination/VPaginationStyles.xaml
@@ -1,149 +1,147 @@
-
+
-
-
-
-
-
-
+
+
+
\ No newline at end of file
diff --git a/Vampirewal.Core/WpfTheme/UcView/UcViewStyles.xaml b/Vampirewal.Core/WpfTheme/UcView/UcViewStyles.xaml
index 78b9c27..6b14691 100644
--- a/Vampirewal.Core/WpfTheme/UcView/UcViewStyles.xaml
+++ b/Vampirewal.Core/WpfTheme/UcView/UcViewStyles.xaml
@@ -12,7 +12,7 @@
-
+
-
+
-
+
+
@@ -9,47 +10,41 @@
-
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
\ No newline at end of file
--
Gitee
From c5253370626155cb15b17be60bae3f4fa2436a65 Mon Sep 17 00:00:00 2001
From: YangCheng <235160615@qq.com>
Date: Fri, 25 Nov 2022 19:10:17 +0800
Subject: [PATCH 29/53] =?UTF-8?q?20221125=201=E3=80=81=E8=B0=83=E6=95=B4?=
=?UTF-8?q?=E4=BB=A3=E7=A0=81=EF=BC=8C=E4=BC=98=E5=8C=96=E7=BB=86=E8=8A=82?=
=?UTF-8?q?=20=202=E3=80=81=E6=96=B0=E5=A2=9E=E6=8E=A7=E4=BB=B6TreeListVie?=
=?UTF-8?q?w=EF=BC=8C=E6=A0=91=E5=BD=A2DataGrid=E6=8E=A7=E4=BB=B6=20=203?=
=?UTF-8?q?=E3=80=81=E8=B0=83=E6=95=B4HttpClientService=E4=BB=A3=E7=A0=81?=
=?UTF-8?q?=20=204=E3=80=81=E6=96=B0=E5=A2=9E=E6=B6=88=E6=81=AF=E7=AE=A1?=
=?UTF-8?q?=E7=90=86=E4=B8=AD=E5=BF=83=E6=9C=8D=E5=8A=A1=20=20=205?=
=?UTF-8?q?=E3=80=81=E6=96=B0=E5=A2=9E=E5=AF=B9=E8=B1=A1=E6=B1=A0=E7=AE=A1?=
=?UTF-8?q?=E7=90=86=E4=B8=AD=E5=BF=83=EF=BC=88=E6=84=9F=E8=A7=89=E7=94=A8?=
=?UTF-8?q?=E5=A4=84=E4=B8=8D=E5=A4=A7=EF=BC=8C=E6=95=B4=E7=9D=80=E7=8E=A9?=
=?UTF-8?q?=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Test.Console/Program.cs | 350 ++++-
Test.Console/Test.Console.csproj | 2 +
.../IHttpClientService.cs | 348 +----
.../RequestParam.cs | 57 +
.../Vampirewal.Core.HttpClientService.csproj | 6 +-
.../VampirewalHttpClientService.cs | 536 ++++++++
.../ISubMessageService.cs | 203 +++
.../SubMessage.cs | 42 +
.../Vampirewal.Core.SubMessageService.csproj | 7 +
.../{Interface/ISubFile.cs => AppContext.cs} | 36 +-
Vampirewal.Core/Components/VampirewalLog.cs | 132 +-
.../DBContexts/VampirewalDbBase.cs | 71 +-
Vampirewal.Core/Interface/IEFRepository.cs | 41 -
Vampirewal.Core/Interface/ISearcher.cs | 8 +-
Vampirewal.Core/IoC/VampirewalIoC.cs | 1 +
Vampirewal.Core/Models/BillBaseModel.cs | 40 +-
Vampirewal.Core/Models/FrameworkUserBase.cs | 18 +-
Vampirewal.Core/SimpleMVVM/BaseCRUDVM.cs | 981 --------------
Vampirewal.Core/SimpleMVVM/BaseListVM.cs | 1150 -----------------
Vampirewal.Core/SimpleMVVM/BaseSearcher.cs | 2 +-
Vampirewal.Core/SimpleMVVM/BaseVM.cs | 123 --
Vampirewal.Core/SimpleMVVM/BillListBaseVM.cs | 16 +-
Vampirewal.Core/SimpleMVVM/BillVM.cs | 89 +-
.../SimpleMVVM/FileAttachmentVM.cs | 45 -
Vampirewal.Core/SimpleMVVM/Messenger.cs | 3 -
Vampirewal.Core/SimpleMVVM/RelayCommand.cs | 28 +-
Vampirewal.Core/SimpleMVVM/ViewModelBase.cs | 93 +-
Vampirewal.Core/SimpleMVVM/WindowsManager.cs | 176 ++-
Vampirewal.Core/SystemDataContext.cs | 53 -
Vampirewal.Core/Vampirewal.Core.csproj | 22 +-
.../Converter/Bool2VisibilityConverter.cs | 13 +
.../Converter/LevelToIndentConverter.cs | 7 +-
Vampirewal.Core/WpfTheme/CoreTheme.xaml | 1 +
.../CustomControl/TreeGrid/ITreeModel.cs | 38 -
.../TreeGrid/ObservableCollectionAdv.cs | 59 -
.../CustomControl/TreeGrid/RowExpander.cs | 34 -
.../CustomControl/TreeGrid/TreeGridStyle.xaml | 75 --
.../CustomControl/TreeGrid/TreeList.cs | 260 ----
.../CustomControl/TreeGrid/TreeListItem.cs | 121 --
.../CustomControl/TreeGrid/TreeNode.cs | 391 ------
.../CustomControl/TreeListView/FirstColumn.cs | 144 +++
.../TreeListView/GeneralTreeContainer.cs | 229 ++++
.../TreeListView/GeneralTreeItemsManager.cs | 116 ++
.../TreeListView/ITreeBuilder.cs | 91 ++
.../CustomControl/TreeListView/ITreeNode.cs | 85 ++
.../TreeListView/TreeBuilderBase.cs | 394 ++++++
.../TreeListView/TreeBuilderByFullLoad.cs | 54 +
.../TreeListView/TreeListView.cs | 590 +++++++++
.../TreeListView/TreeListViewStyle.xaml | 261 ++++
.../TreeListView/list_header_bk.png | Bin 0 -> 2862 bytes
.../TreeView/TreeViewStyles.xaml | 9 -
Vampirewal.Core/WpfTheme/UcView/UcViewBase.cs | 10 +-
.../WpfTheme/WindowStyle/MainWindowBase.cs | 42 +-
.../WpfTheme/WindowStyle/WindowBase.cs | 82 +-
...77\347\224\250\350\257\264\346\230\216.cs" | 53 -
Vampirewal.Coree.ClassObjectPool/Pool.cs | 94 ++
.../PoolManager.cs | 64 +
.../Vampirewal.Coree.ClassObjectPool.csproj | 9 +
YC.Core.sln | 14 +
test.ViewModel/MainViewModel.cs | 505 +++++---
test.ViewModel/Model/TestBillModel.cs | 33 +-
test/App.xaml | 9 +-
test/MainWindow.xaml | 209 ++-
test/MainWindow.xaml.cs | 9 +-
64 files changed, 4442 insertions(+), 4342 deletions(-)
create mode 100644 Vampirewal.Core.HttpClientService/RequestParam.cs
create mode 100644 Vampirewal.Core.HttpClientService/VampirewalHttpClientService.cs
create mode 100644 Vampirewal.Core.SubMessageService/ISubMessageService.cs
create mode 100644 Vampirewal.Core.SubMessageService/SubMessage.cs
create mode 100644 Vampirewal.Core.SubMessageService/Vampirewal.Core.SubMessageService.csproj
rename Vampirewal.Core/{Interface/ISubFile.cs => AppContext.cs} (39%)
delete mode 100644 Vampirewal.Core/Interface/IEFRepository.cs
delete mode 100644 Vampirewal.Core/SimpleMVVM/BaseCRUDVM.cs
delete mode 100644 Vampirewal.Core/SimpleMVVM/BaseListVM.cs
delete mode 100644 Vampirewal.Core/SimpleMVVM/BaseVM.cs
delete mode 100644 Vampirewal.Core/SimpleMVVM/FileAttachmentVM.cs
delete mode 100644 Vampirewal.Core/SystemDataContext.cs
delete mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/ITreeModel.cs
delete mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/ObservableCollectionAdv.cs
delete mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/RowExpander.cs
delete mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/TreeGridStyle.xaml
delete mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/TreeList.cs
delete mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/TreeListItem.cs
delete mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeGrid/TreeNode.cs
create mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeListView/FirstColumn.cs
create mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeListView/GeneralTreeContainer.cs
create mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeListView/GeneralTreeItemsManager.cs
create mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeListView/ITreeBuilder.cs
create mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeListView/ITreeNode.cs
create mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeListView/TreeBuilderBase.cs
create mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeListView/TreeBuilderByFullLoad.cs
create mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeListView/TreeListView.cs
create mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeListView/TreeListViewStyle.xaml
create mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeListView/list_header_bk.png
delete mode 100644 Vampirewal.Core/WpfTheme/CustomControl/TreeView/TreeViewStyles.xaml
delete mode 100644 "Vampirewal.Core/\344\275\277\347\224\250\350\257\264\346\230\216.cs"
create mode 100644 Vampirewal.Coree.ClassObjectPool/Pool.cs
create mode 100644 Vampirewal.Coree.ClassObjectPool/PoolManager.cs
create mode 100644 Vampirewal.Coree.ClassObjectPool/Vampirewal.Coree.ClassObjectPool.csproj
diff --git a/Test.Console/Program.cs b/Test.Console/Program.cs
index dd90f37..6b36cef 100644
--- a/Test.Console/Program.cs
+++ b/Test.Console/Program.cs
@@ -1,7 +1,14 @@
using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
using System.Linq;
using System.Reflection;
+using System.Runtime.Serialization;
using Vampirewal.Core.Mapper;
+using Vampirewal.Coree.ClassObjectPool;
+using Yitter.IdGenerator;
namespace Test.Console;
@@ -13,31 +20,90 @@ public class Program
//MapperManager.RegisterAll();
- testclass testclass1 = new testclass()
- {
- Id=1234567890123456789,
- Study=2,
- Supplement="aaaaaaaaaaaaaaaaa",
- MarryState=1,
- Birthday=DateTime.Now,
- CarHouse=1,
- Constellation=1,
- Gender=1,
- Height="123",
- Interests="sssssssssssssssssssssss",
- MarryPlan="aaaaaaaaaaaaaaaaaaa",
- MemberName="aaa",
- NewPosition="asd",
- OldPosition="qwe",
- PhoneNum="123456789",
- Professional="qwewert",
- Weight="22",
- YearMoney=789
- };
-
- var target1 = testclass1.SimpleMap();
-
- var target2= Mapper.Map(testclass1);
+ //testclass testclass1 = new testclass()
+ //{
+ // Id=1234567890123456789,
+ // Study=2,
+ // Supplement="aaaaaaaaaaaaaaaaa",
+ // MarryState=1,
+ // Birthday=DateTime.Now,
+ // CarHouse=1,
+ // Constellation=1,
+ // Gender=1,
+ // Height="123",
+ // Interests="sssssssssssssssssssssss",
+ // MarryPlan="aaaaaaaaaaaaaaaaaaa",
+ // MemberName="aaa",
+ // NewPosition="asd",
+ // OldPosition="qwe",
+ // PhoneNum="123456789",
+ // Professional="qwewert",
+ // Weight="22",
+ // YearMoney=789
+ //};
+
+ //var target1 = testclass1.SimpleMap();
+
+ //var target2= Mapper.Map(testclass1);
+
+ //IdentityGenerator id=new IdentityGenerator();
+ //System.Console.WriteLine(id.GetIdentity(5));
+
+ //var options = new IdGeneratorOptions(5);
+ //options.WorkerIdBitLength = 16;
+ //YitIdHelper.SetIdGenerator(options);
+
+ //System.Console.WriteLine(YitIdHelper.NextId());
+
+ //List l1 = new List();
+ //List l2 = new List();
+
+ //string a1 = GetMethodExcuteTime(() =>
+ //{
+ // for (int i = 0; i < 10000; i++)
+ // {
+ // testclass t1 = new testclass();
+ // l1.Add(t1);
+ // }
+ //});
+
+ //string a2 = GetMethodExcuteTime(() =>
+ //{
+ // assetBundleItemPool = PoolManager.GetInstance.GetOrCreateClassObjectPool(10000);
+
+ // for (int i = 0; i < 10000; i++)
+ // {
+ // var tt= assetBundleItemPool.Spawn(true);
+
+ // l2.Add(tt);
+ // }
+ //});
+
+ //System.Console.WriteLine($"a1耗时:{a1}");
+ //System.Console.WriteLine($"a2耗时:{a2}");
+
+ string fileName = Path.GetFileName("D:\\聚爱团项目\\BlindDate\\BlindDate\\BlindDate\\bin\\Debug\\net5.0-windows\\Temp\\测试1_202211161554083981.jpg");
+
+ System.Console.WriteLine($"fileName:{fileName}");
+
+ System.Console.ReadKey();
+ }
+
+ private static Pool assetBundleItemPool ;
+
+ ///
+ /// 获取方法执行时间
+ ///
+ ///
+ ///
+ public static string GetMethodExcuteTime(Action action)
+ {
+ Stopwatch sw = new Stopwatch();
+ sw.Start();
+ action.Invoke();
+ sw.Stop();
+
+ return sw.ElapsedMilliseconds.ToString();
}
}
@@ -225,3 +291,237 @@ public class testclassDTO
///
public virtual string PhoneNum { get; set; }
}
+
+///
+/// 简单Id生成器
+///
+public class IdentityGenerator
+{
+ ///
+ /// 随机数缓存
+ ///
+ private static Hashtable ht;
+ ///
+ /// 时间戳刻度缓存
+ ///
+ private long lastTimeStampStyleTicks;
+ ///
+ /// 时间戳缓存(上一次计算ID的系统时间按时间戳刻度取值)
+ ///
+ private long lastEndDateTimeTicks;
+
+ public IdentityGenerator()
+ {
+ if (ht == null)
+ ht = new Hashtable();
+ }
+
+ ///
+ /// IdentityGenerator的静态实例
+ ///
+ private static IdentityGenerator ig;
+ public IdentityGenerator GetInstance()
+ {
+ if (ig == null)
+ ig = new IdentityGenerator();
+ return ig;
+ }
+
+ ///
+ /// 按照时间戳刻度计算当前时间戳
+ ///
+ /// 起始时间
+ /// 时间戳刻度值
+ /// long
+ private long GetTimestamp(DateTime startDateTime, long timestampStyleTicks)
+ {
+ if (timestampStyleTicks == 0)
+ throw new Exception("时间戳刻度样式精度值不符,不能为0或负数");
+ DateTime endDateTime = DateTime.Now;
+ long ticks = (endDateTime.Ticks - startDateTime.Ticks) / timestampStyleTicks;
+ return ticks;
+ }
+
+ ///
+ /// 静态随机数生成器
+ ///
+ private static Random random;
+ ///
+ /// 获取随机数
+ ///
+ /// 随机数长度
+ ///
+ private long GetRandom(int length)
+ {
+ if (length <= 0)
+ throw new Exception("随机数长度指派错误,长度不能为0或负数");
+ if (random == null)
+ random = new Random();
+
+ int minValue = 0;
+ int maxValue = int.Parse(System.Math.Pow(10, length).ToString());
+ long result = long.Parse(random.Next(minValue, maxValue).ToString());
+ return result;
+ }
+
+ ///
+ /// 计算一个Id
+ /// 以2005-1-1 00:00 000为起始时间刻度
+ ///
+ /// long
+ public long GetIdentity()
+ {
+ DateTime startDateTime = new DateTime(2005, 1, 1, 0, 0, 0, 0);
+ TimestampStyle timestampStyle = TimestampStyle.SecondTicks;
+ int randomLength = 3;
+ return GetIdentity(startDateTime, timestampStyle, randomLength);
+ }
+
+ ///
+ /// 计算一个Id
+ /// 以2005-1-1 00:00 000为起始时间刻度
+ ///
+ /// 时间戳刻度
+ /// long
+ public long GetIdentity(TimestampStyle timestampStyle)
+ {
+ DateTime startDateTime = new DateTime(2005, 1, 1, 0, 0, 0, 0);
+ int randomLength = 3;
+ return GetIdentity(startDateTime, timestampStyle, randomLength);
+ }
+
+ ///
+ /// 计算一个Id
+ ///
+ /// 随机数长度
+ /// long
+ public long GetIdentity(int randomLength)
+ {
+ DateTime startDateTime = new DateTime(2005, 1, 1, 0, 0, 0, 0);
+ TimestampStyle timestampStyle = TimestampStyle.SecondTicks;
+ return GetIdentity(startDateTime, timestampStyle, randomLength);
+ }
+
+ ///
+ /// 计算一个Id
+ ///
+ /// 时间戳刻度
+ /// 随机数长度
+ /// long
+ public long GetIdentity(TimestampStyle timestampStyle, int randomLength)
+ {
+ DateTime startDateTime = new DateTime(2005, 1, 1, 0, 0, 0, 0);
+ return GetIdentity(startDateTime, timestampStyle, randomLength);
+ }
+
+ ///
+ /// 计算一个Id
+ ///
+ /// 时间戳的起始时间
+ /// 时间戳刻度
+ /// 随机数长度
+ /// long
+ public long GetIdentity(DateTime startDateTime, TimestampStyle timestampStyle, int randomLength)
+ {
+ long timestampStyleTicks = long.Parse(timestampStyle.ToString("D"));
+ return GetIdentity(startDateTime, timestampStyleTicks, randomLength);
+ }
+
+ ///
+ /// 计算一个Id
+ ///
+ /// 时间戳的起始时间
+ /// 时间戳刻度(毫微秒单位)
+ /// 随机数长度
+ /// long
+ public long GetIdentity(DateTime startDateTime, long timestampStyleTicks, int randomLength)
+ {
+ // 新一轮时间戳刻度更新后更新缓存
+ //如果该参数不变则不进行此更新
+ if (timestampStyleTicks != lastTimeStampStyleTicks)
+ ht.Clear();
+
+ //取得时间戳(当前时间按刻度取值)
+ long timestamp = GetTimestamp(startDateTime, timestampStyleTicks);
+
+ //新一轮时间戳更新后更新缓存
+ if (timestamp != lastEndDateTimeTicks)
+ ht.Clear();
+ //幂
+ long power = long.Parse(Math.Pow(10, randomLength).ToString());
+ //随机数
+ long rand = GetRandom(randomLength);
+ //生成结果(Id)
+ long result = timestamp * power + rand;
+
+ //如果发现重复
+ if (ht.ContainsKey(result))
+ {
+ //在随机数长度范围内再重复查找一次
+ for (int i = 0; i < power; i++)
+ {
+ rand = GetRandom(randomLength);
+ result = timestamp * power + rand;
+ //发现非重复的Id
+ if (!ht.ContainsKey(result))
+ {
+ //将新的Id加入HashTable缓存
+ ht.Add(result, result);
+ break;//找到一个同一时间戳内的Id即退出
+ }
+ }
+ // 此处运行在当前时间戳内无法再继续生成Id的代码,如:
+ //
+ //throw new Exception("已无法生成更多Id,请增加时间戳刻度TimestampStyle或增加随机数长度randomLength");
+ }
+ else
+ {
+ //将新的Id加入HashTable缓存
+ ht.Add(result, result);
+ }
+ //记录当前一轮时间戳(当前时间按刻度取值)
+ this.lastEndDateTimeTicks = timestamp;
+ //记录当前一轮时间戳刻度
+ this.lastTimeStampStyleTicks = timestampStyleTicks;
+ return result;
+ }
+}
+
+///
+/// 时间戳精度样式
+/// 采用格里高利时间刻度单位-毫微秒(1秒 =10,000,000毫微秒 )
+/// 疑问:MSDN上写的一毫微秒为一百万分之一秒 =100,000,000毫微秒,但是我始终无法算出该值,
+/// 不知是我错了还是MSDN的问题实际得出的数字是1秒 =10,000,000毫微秒,认为是我错了的话请将
+/// 下面的每一项枚举值都加一个0即可
+///
+public enum TimestampStyle : long
+{
+ ///
+ /// 时间刻度精度取为1毫秒(此项无意义,因为一般PC机系统时钟只能精确到10毫秒)
+ ///
+ MillSecondTicks = 10000,
+ ///
+ /// 时间刻度精度取为10毫秒,这是一般PC机系统时钟的最小精度单位
+ ///
+ TenMillSecondTicks = 100000,
+ ///
+ /// 时间刻度精度取为100毫秒
+ ///
+ HundredMillSecondTicks = 1000000,
+ ///
+ /// 时间刻度精度取为1秒,即1000毫秒
+ ///
+ SecondTicks = 10000000,
+ ///
+ /// 时间刻度精度取为5秒
+ ///
+ FiveSecondTicks = 50000000,
+ ///
+ /// 时间刻度精度取为10秒
+ ///
+ TenSecondTicks = 100000000,
+ ///
+ /// 时间刻度精度取为1分种(60秒)
+ ///
+ MinutesTicks = 600000000
+}
diff --git a/Test.Console/Test.Console.csproj b/Test.Console/Test.Console.csproj
index 085c627..ec45128 100644
--- a/Test.Console/Test.Console.csproj
+++ b/Test.Console/Test.Console.csproj
@@ -7,6 +7,8 @@
+
+
diff --git a/Vampirewal.Core.HttpClientService/IHttpClientService.cs b/Vampirewal.Core.HttpClientService/IHttpClientService.cs
index 0ed3a18..08fb43c 100644
--- a/Vampirewal.Core.HttpClientService/IHttpClientService.cs
+++ b/Vampirewal.Core.HttpClientService/IHttpClientService.cs
@@ -11,23 +11,10 @@
//----------------------------------------------------------------*/
#endregion
-using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
-using System.Net.Http;
-using System.ComponentModel.DataAnnotations;
-using System.Xml.Linq;
-using System.ComponentModel;
-using System.Text.Encodings.Web;
-using System.Text.Unicode;
-using System.Text.Json.Serialization;
-using System.Net.Http.Headers;
-using System.Net.Http.Json;
-using System.Reflection;
namespace Vampirewal.Core.HttpClientService
{
@@ -66,7 +53,7 @@ namespace Vampirewal.Core.HttpClientService
///
///
///
- string HttpGetAsync(string url);
+ string HttpGet(string url);
///
/// GET请求(返回对象)
@@ -74,161 +61,32 @@ namespace Vampirewal.Core.HttpClientService
///
///
///
- T HttpGetAsync(string url);
+ T HttpGet(string url);
///
- /// POST请求
- ///
- /// API地址
- /// 传递的参数
- /// application/xml、application/json、application/text、application/x-www-form-urlencoded
- ///
- /// Json文本
- string HttpPostAsync(string url, object obj, ContentType contentType, string charset = "UTF-8");
-
- ///
- /// POST请求(返回对象)
- ///
- /// API地址
- /// 传递的参数
- /// application/xml、application/json、application/text、application/x-www-form-urlencoded
- ///
- /// 对象
- T HttpPostAsync(string url, object obj, ContentType contentType, string charset = "UTF-8");
- }
-
- public class VampirewalHttpClientService : IHttpClientService
- {
-
- #region 配置
- public ServiceProvider ServiceProvider { get; private set; }
- public ServiceCollection serviceCollection { get; private set; }
-
- public JsonSerializerOptions options { get; private set; }
-
- public VampirewalHttpClientService()
- {
- serviceCollection = new ServiceCollection();
- ServiceProvider = serviceCollection.AddHttpClient().BuildServiceProvider();
- ConfigureServices(serviceCollection);
-
- _httpClientFactory = ServiceProvider.GetService();
-
-
- }
-
- private void ConfigureServices(ServiceCollection services)
- {
- //services.AddHttpClient();
- //ServiceProvider = services.BuildServiceProvider();
- }
-
- public Dictionary RequestHeaderDic { get; private set; } = new Dictionary();
-
- ///
- /// 设置请求头
+ /// 自定义参数的GET请求(无需将参数自行写进url中)
///
- ///
- public void SetHeader(Dictionary _requestHeaderDic)
- {
- RequestHeaderDic = _requestHeaderDic;
- }
-
-
- [Obsolete("暂时不可用", true)]
- public void AddHttpClient(string ClientName, Dictionary RequestHeaderDic)
- {
- serviceCollection.AddHttpClient("aaa", c =>
- {
-
- });
- }
-
- public void SetJsonSerializerOptions(JsonSerializerOptions options)
- {
- this.options = options;
- }
- #endregion
-
-
- protected IHttpClientFactory _httpClientFactory { get; set; }
+ /// 请求地址
+ /// 参数
+ ///
+ string RequestGetOfCustomParameter(string url, params RequestParam[] requestParams);
- #region GET请求
///
- /// GET请求
+ /// 自定义参数的GET请求(无需将参数自行写进url中)
///
- ///
+ /// 返回值类型
+ /// 请求地址
+ /// 参数
///
- public string HttpGetAsync(string url)
- {
- string result = "";
-
- var _httpClient = _httpClientFactory.CreateClient();
-
- //if (token != null)
- //{
- // //_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Authorization", $"{token.token_type} {token.access_token}");
- // _httpClient.DefaultRequestHeaders.Add("Authorization", $"{token.token_type} {token.access_token}");
- //}
-
- if (RequestHeaderDic.Count > 0)
- {
- foreach (var item in RequestHeaderDic)
- {
- _httpClient.DefaultRequestHeaders.Add(item.Key, item.Value);
- }
- }
-
-
- var response = _httpClient.GetAsync(url).Result;
-
- if (response.IsSuccessStatusCode)
- {
- Task t = response.Content.ReadAsStringAsync();
- if (t != null)
- {
- result = t.Result;
- }
- }
- return result;
- }
+ T RequestGetOfCustomParameter(string url, params RequestParam[] requestParams);
///
- /// GET请求(返回对象)
+ /// 通过GET调用下载附件
///
///
+ ///
///
- public T HttpGetAsync(string url)
- {
-
- var _httpClient = _httpClientFactory.CreateClient();
-
- if (RequestHeaderDic.Count > 0)
- {
- foreach (var item in RequestHeaderDic)
- {
- _httpClient.DefaultRequestHeaders.Add(item.Key, item.Value);
- }
- }
-
- var response = _httpClient.GetAsync(url).Result;
-
- if (response.IsSuccessStatusCode)
- {
- Task t = response.Content.ReadAsStringAsync();
- if (t != null)
- {
- //options.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); //解决中文序列化被编码的问题
- //options.Converters.Add(new DateTimeConverter()); //解决时间格式序列化的问题
-
- return JsonSerializer.Deserialize(t.Result, options);
- }
- }
- return default(T);
- }
- #endregion
-
- #region POST请求--异步方法
+ Task HttpGetDownLoad(string url, string SavePath);
///
/// POST请求
@@ -238,40 +96,7 @@ namespace Vampirewal.Core.HttpClientService
/// application/xml、application/json、application/text、application/x-www-form-urlencoded
///
/// Json文本
- public string HttpPostAsync(string url, object obj, ContentType contentType, string charset = "UTF-8")
- {
- string result = "";
-
- var _httpClient = _httpClientFactory.CreateClient();
-
- _httpClient.DefaultRequestHeaders.Accept.Clear();
- _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType.GetDisplay()));
-
- if (RequestHeaderDic.Count > 0)
- {
- foreach (var item in RequestHeaderDic)
- {
- _httpClient.DefaultRequestHeaders.Add(item.Key, item.Value);
- }
- }
-
-
- string content = JsonSerializer.Serialize(obj);
-
- var httpContent = new StringContent(content, Encoding.UTF8, contentType.GetDisplay());
-
- var response = _httpClient.PostAsync(url, httpContent).Result;
- if (response.IsSuccessStatusCode)
- {
- Task t = response.Content.ReadAsStringAsync();
- if (t != null)
- {
- result = t.Result;
- }
- }
- return result;
- }
-
+ string HttpPost(string url, object obj, ContentType contentType, string charset = "UTF-8");
///
/// POST请求(返回对象)
@@ -281,123 +106,42 @@ namespace Vampirewal.Core.HttpClientService
/// application/xml、application/json、application/text、application/x-www-form-urlencoded
///
/// 对象
- public T HttpPostAsync(string url, object obj, ContentType contentType, string charset = "UTF-8")
- {
- var _httpClient = _httpClientFactory.CreateClient();
-
- _httpClient.DefaultRequestHeaders.Accept.Clear();
- _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType.GetDisplay()));
-
- if (RequestHeaderDic.Count > 0)
- {
- foreach (var item in RequestHeaderDic)
- {
- _httpClient.DefaultRequestHeaders.Add(item.Key, item.Value);
- }
- }
-
-
- string content = JsonSerializer.Serialize(obj);
-
- var httpContent = new StringContent(content, Encoding.UTF8, contentType.GetDisplay());
-
- var response = _httpClient.PostAsync(url, httpContent).Result;
- if (response.IsSuccessStatusCode)
- {
- Task t = response.Content.ReadAsStringAsync();
- if (t != null)
- {
- return JsonSerializer.Deserialize(t.Result, options);
- }
- else
- {
- return default(T);
- }
- }
- else
- {
- return default(T);
- }
-
- }
-
-
- #endregion
- }
-
-
-
- ///
- ///
- ///
- public class Token
- {
- public string access_token { get; set; }
-
- public int expires_in { get; set; }
-
- public string token_type { get; set; }
-
- public string refresh_token { get; set; }
- }
+ T HttpPost(string url, object obj, ContentType contentType, string charset = "UTF-8");
- ///
- /// 传输类型枚举
- ///
- public enum ContentType
- {
- [Display(Name = "application/xml")]
- application_xml = 0,
- [Display(Name = "application/json")]
- application_json = 1,
- [Display(Name = "application/text")]
- application_text = 2,
- [Display(Name = "application/x-www-form-urlencoded")]
- application_x_www_form_urlencoded = 3
- }
-
- public class DateTimeConverter : JsonConverter
- {
- public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
- {
- return DateTime.Parse(reader.GetString());
- }
-
- public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
- {
- writer.WriteStringValue(value.ToString("yyyy-MM-dd HH:mm:ss"));
- }
- }
+ ///
+ /// 自定义参数的POST请求(无需将参数自行写进url中)
+ ///
+ ///
+ ///
+ ///
+ string RequestPostOfCustomParameter(string url, params RequestParam[] requestParams);
- public class DateTimeNullableConverter : JsonConverter
- {
- public override DateTime? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
- {
- return string.IsNullOrEmpty(reader.GetString()) ? default(DateTime?) : DateTime.Parse(reader.GetString());
- }
+ ///
+ /// 自定义参数的POST请求(无需将参数自行写进url中)
+ ///
+ ///
+ ///
+ ///
+ ///
+ T RequestPostOfCustomParameter(string url, params RequestParam[] requestParams);
- public override void Write(Utf8JsonWriter writer, DateTime? value, JsonSerializerOptions options)
- {
- writer.WriteStringValue(value?.ToString("yyyy-MM-dd HH:mm:ss"));
- }
- }
+ ///
+ /// 通过POST模拟表单调用上传图片
+ ///
+ /// 请求地址
+ /// 图片路径
+ /// 表单参数
+ ///
+ ///
+ Task PostUploadImage(string uploadUrl, string imgPath,Dictionary Param = null, string fileparameter = "file");
- ///
- /// 枚举扩展类
- ///
- internal static class EnumHelper
- {
///
- /// 获取枚举的Display文本
+ /// 模拟web表单提交
///
- ///
+ ///
+ ///
///
- public static String GetDisplay(this Enum value)
- {
- var type = value.GetType();//先获取这个枚举的类型
- var field = type.GetField(value.ToString());//通过这个类型获取到值
- var obj = (DisplayAttribute)field.GetCustomAttribute(typeof(DisplayAttribute));//得到特性
- return obj.Name ?? "";
- }
+ Task FormRequestPost(string url, RequestParam[] requestParams);
}
+
}
diff --git a/Vampirewal.Core.HttpClientService/RequestParam.cs b/Vampirewal.Core.HttpClientService/RequestParam.cs
new file mode 100644
index 0000000..015274b
--- /dev/null
+++ b/Vampirewal.Core.HttpClientService/RequestParam.cs
@@ -0,0 +1,57 @@
+
+#region 文件信息
+/*----------------------------------------------------------------
+//
+// 文件名称:
+// 文件功能描述:
+// 设计要求:
+//
+// 文 件 名: RequestParam
+// 创建者: 杨程
+// 创建日期: 2022/11/14 12:08:59
+
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+
+
+namespace Vampirewal.Core.HttpClientService
+{
+ ///
+ /// 请求参数
+ ///
+ public class RequestParam
+ {
+ public RequestParam(string requestParameterName, object requestValue)
+ {
+ RequestParameterName = requestParameterName;
+ RequestValue = requestValue;
+ }
+
+ ///
+ /// 请求的参数名
+ ///
+ public string RequestParameterName { get; }
+ ///
+ /// 请求参数值
+ ///
+ public object RequestValue { get; }
+
+ ///
+ /// 拼接好的参数Key=value
+ ///
+ public string RequestString
+ {
+ get
+ {
+ return $"{RequestParameterName}={RequestValue}";
+ }
+ }
+ }
+}
diff --git a/Vampirewal.Core.HttpClientService/Vampirewal.Core.HttpClientService.csproj b/Vampirewal.Core.HttpClientService/Vampirewal.Core.HttpClientService.csproj
index aa387d6..c8843eb 100644
--- a/Vampirewal.Core.HttpClientService/Vampirewal.Core.HttpClientService.csproj
+++ b/Vampirewal.Core.HttpClientService/Vampirewal.Core.HttpClientService.csproj
@@ -4,7 +4,7 @@
net5.0
True
vampirewal
- 1.0.0.2
+ 1.0.0.12
Vampirewal.Core中请求WebApi的组件
Vampirewal-Logo.png
LICENSE
@@ -21,8 +21,8 @@
-
-
+
+
diff --git a/Vampirewal.Core.HttpClientService/VampirewalHttpClientService.cs b/Vampirewal.Core.HttpClientService/VampirewalHttpClientService.cs
new file mode 100644
index 0000000..f70246c
--- /dev/null
+++ b/Vampirewal.Core.HttpClientService/VampirewalHttpClientService.cs
@@ -0,0 +1,536 @@
+
+#region 文件信息
+/*----------------------------------------------------------------
+//
+// 文件名称:
+// 文件功能描述:
+// 设计要求:
+//
+// 文 件 名: VampirewalHttpClientService
+// 创建者: 杨程
+// 创建日期: 2022/11/14 15:20:57
+
+//----------------------------------------------------------------*/
+#endregion
+
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net.Http.Headers;
+using System.Net.Http;
+using System.Net;
+using System.Text;
+using System.Text.Json;
+using System.Threading.Tasks;
+using System.Text.Json.Serialization;
+using System.ComponentModel.DataAnnotations;
+using System.Reflection;
+
+namespace Vampirewal.Core.HttpClientService
+{
+ ///
+ ///
+ ///
+ public class VampirewalHttpClientService : IHttpClientService
+ {
+
+ #region 配置
+ public ServiceProvider ServiceProvider { get; private set; }
+ public ServiceCollection serviceCollection { get; private set; }
+
+ public JsonSerializerOptions options { get; private set; }
+
+ public VampirewalHttpClientService()
+ {
+ serviceCollection = new ServiceCollection();
+ ServiceProvider = serviceCollection.AddHttpClient().BuildServiceProvider();
+ ConfigureServices(serviceCollection);
+
+ _httpClientFactory = ServiceProvider.GetService();
+
+
+ }
+
+ private void ConfigureServices(ServiceCollection services)
+ {
+ //services.AddHttpClient();
+ //ServiceProvider = services.BuildServiceProvider();
+ }
+
+ public Dictionary RequestHeaderDic { get; private set; } = new Dictionary();
+
+ ///
+ /// 设置请求头
+ ///
+ ///
+ public void SetHeader(Dictionary _requestHeaderDic)
+ {
+ RequestHeaderDic = _requestHeaderDic;
+ }
+
+
+ [Obsolete("暂时不可用", true)]
+ public void AddHttpClient(string ClientName, Dictionary RequestHeaderDic)
+ {
+ serviceCollection.AddHttpClient("aaa", c =>
+ {
+
+ });
+ }
+
+ ///
+ /// 设置自定义反序列化设置
+ ///
+ ///
+ public void SetJsonSerializerOptions(JsonSerializerOptions options)
+ {
+ this.options = options;
+ }
+ #endregion
+
+
+ protected IHttpClientFactory _httpClientFactory { get; set; }
+
+
+ private HttpClient CreateClient(string url)
+ {
+ if (url.StartsWith("https"))
+ {
+ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
+ }
+
+ var _httpClient = _httpClientFactory.CreateClient();
+
+ if (RequestHeaderDic.Count > 0)
+ {
+ foreach (var item in RequestHeaderDic)
+ {
+ _httpClient.DefaultRequestHeaders.Add(item.Key, item.Value);
+ }
+ }
+
+ return _httpClient;
+ }
+
+ #region GET请求
+ ///
+ /// GET请求
+ ///
+ ///
+ ///
+ public string HttpGet(string url)
+ {
+ string result = "";
+
+ var _httpClient = CreateClient(url);
+
+ var response = _httpClient.GetAsync(url).Result;
+
+ if (response.IsSuccessStatusCode)
+ {
+ Task t = response.Content.ReadAsStringAsync();
+ if (t != null)
+ {
+ result = t.Result;
+ }
+ }
+ return result;
+ }
+
+ ///
+ /// GET请求(返回对象)
+ ///
+ ///
+ ///
+ public T HttpGet(string url)
+ {
+ var _httpClient = CreateClient(url);
+
+ var response = _httpClient.GetAsync(url).Result;
+
+ if (response.IsSuccessStatusCode)
+ {
+ Task t = response.Content.ReadAsStringAsync();
+ if (t != null)
+ {
+ //options.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); //解决中文序列化被编码的问题
+ //options.Converters.Add(new DateTimeConverter()); //解决时间格式序列化的问题
+
+ return JsonSerializer.Deserialize(t.Result, options);
+ }
+ }
+ return default(T);
+ }
+
+ public async Task HttpGetDownLoad(string url, string SavePath)
+ {
+ var _httpClient = CreateClient(url);
+
+ HttpResponseMessage response = _httpClient.GetAsync(url).Result;
+ response.EnsureSuccessStatusCode();
+ if (response.IsSuccessStatusCode)
+ {
+ using (FileStream fs = File.Open(SavePath, FileMode.Create))
+ {
+ using Stream ms = response.Content.ReadAsStream();
+ await ms.CopyToAsync(fs);
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+ public string RequestGetOfCustomParameter(string url, params RequestParam[] requestParams)
+ {
+ string result = "";
+ var _httpClient = CreateClient(url);
+
+ List ParamList = new List();
+ foreach (var item in requestParams)
+ {
+ ParamList.Add(item.RequestString);
+ }
+ string UrlAndParamStr = $"{url}?{string.Join("&", ParamList)}";
+
+ var response = _httpClient.GetAsync(UrlAndParamStr).Result;
+
+ if (response.IsSuccessStatusCode)
+ {
+ Task t = response.Content.ReadAsStringAsync();
+ if (t != null)
+ {
+ result = t.Result;
+ }
+ }
+ return result;
+ }
+
+ public T RequestGetOfCustomParameter(string url, params RequestParam[] requestParams)
+ {
+ var _httpClient = CreateClient(url);
+
+ List ParamList = new List();
+ foreach (var item in requestParams)
+ {
+ ParamList.Add(item.RequestString);
+ }
+ string UrlAndParamStr = $"{url}?{string.Join("&", ParamList)}";
+
+ var response = _httpClient.GetAsync(UrlAndParamStr).Result;
+
+ if (response.IsSuccessStatusCode)
+ {
+ Task t = response.Content.ReadAsStringAsync();
+ if (t != null)
+ {
+ return JsonSerializer.Deserialize(t.Result, options);
+ }
+ }
+ return default(T);
+ }
+ #endregion
+
+ #region POST请求--异步方法
+
+ ///
+ /// POST请求
+ ///
+ /// API地址
+ /// 传递的参数
+ /// application/xml、application/json、application/text、application/x-www-form-urlencoded
+ ///
+ /// Json文本
+ public string HttpPost(string url, object obj, ContentType contentType, string charset = "UTF-8")
+ {
+ string result = "";
+ var _httpClient = CreateClient(url);
+
+ _httpClient.DefaultRequestHeaders.Accept.Clear();
+ _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType.GetDisplay()));
+
+ string content = JsonSerializer.Serialize(obj);
+
+ var httpContent = new StringContent(content, Encoding.UTF8, contentType.GetDisplay());
+
+ var response = _httpClient.PostAsync(url, httpContent).Result;
+ if (response.IsSuccessStatusCode)
+ {
+ Task t = response.Content.ReadAsStringAsync();
+ if (t != null)
+ {
+ result = t.Result;
+ }
+ }
+ return result;
+ }
+
+ public string RequestPostOfCustomParameter(string url, params RequestParam[] requestParams)
+ {
+ string result = "";
+ var _httpClient = CreateClient(url);
+
+ List ParamList = new List();
+ foreach (var item in requestParams)
+ {
+ ParamList.Add(item.RequestString);
+ }
+ string UrlAndParamStr = $"{url}?{string.Join("&", ParamList)}";
+
+ HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, UrlAndParamStr);
+
+ var response = _httpClient.SendAsync(request).Result;
+
+ if (response.IsSuccessStatusCode)
+ {
+ Task t = response.Content.ReadAsStringAsync();
+ if (t != null)
+ {
+ result = t.Result;
+ }
+ }
+ return result;
+ }
+
+ public T RequestPostOfCustomParameter(string url, params RequestParam[] requestParams)
+ {
+ var _httpClient = CreateClient(url);
+
+ List ParamList = new List();
+ foreach (var item in requestParams)
+ {
+ ParamList.Add(item.RequestString);
+ }
+ string UrlAndParamStr = $"{url}?{string.Join("&", ParamList)}";
+
+ HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, UrlAndParamStr);
+
+ var response = _httpClient.SendAsync(request).Result;
+
+ if (response.IsSuccessStatusCode)
+ {
+ Task t = response.Content.ReadAsStringAsync();
+ if (t != null)
+ {
+ return JsonSerializer.Deserialize(t.Result, options);
+ }
+ else
+ {
+ return default(T);
+ }
+ }
+ else
+ {
+ return default(T);
+ }
+ }
+
+ ///
+ /// POST请求(返回对象)
+ ///
+ /// API地址
+ /// 传递的参数
+ /// application/xml、application/json、application/text、application/x-www-form-urlencoded
+ ///
+ /// 对象
+ public T HttpPost(string url, object obj, ContentType contentType, string charset = "UTF-8")
+ {
+ var _httpClient = CreateClient(url);
+
+ _httpClient.DefaultRequestHeaders.Accept.Clear();
+ _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType.GetDisplay()));
+
+ string content = JsonSerializer.Serialize(obj);
+
+ var httpContent = new StringContent(content, Encoding.UTF8, contentType.GetDisplay());
+
+ var response = _httpClient.PostAsync(url, httpContent).Result;
+ if (response.IsSuccessStatusCode)
+ {
+ Task t = response.Content.ReadAsStringAsync();
+ if (t != null)
+ {
+ return JsonSerializer.Deserialize(t.Result, options);
+ }
+ else
+ {
+ return default(T);
+ }
+ }
+ else
+ {
+ return default(T);
+ }
+
+ }
+
+ ///
+ /// 通过POST模拟表单调用上传图片
+ ///
+ /// 请求地址
+ /// 图片路径
+ /// 表单参数
+ ///
+ ///
+ public async Task PostUploadImage(string uploadUrl, string imgPath, Dictionary Param = null, string fileparameter = "file")
+ {
+ var httpClient = CreateClient(uploadUrl);
+
+ httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/JOSN"));//设定要响应的数据格式
+
+ using (MultipartFormDataContent httpContent = new MultipartFormDataContent())
+ {
+ using (var fileContent = new ByteArrayContent(System.IO.File.ReadAllBytes(imgPath)))
+ {
+ //int pos = imgPath.LastIndexOf("/");
+ //string fileName = imgPath.Substring(pos + 1);
+ string fileName = Path.GetFileName(imgPath);
+ httpContent.Add(fileContent, fileparameter, fileName);
+
+ if (Param != null && Param.Count > 0)
+ {
+ foreach (var (key, value) in Param)
+ {
+ var valueBytes = Encoding.UTF8.GetBytes(value);
+ var byteArray = new ByteArrayContent(valueBytes);
+ byteArray.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
+ {
+ Name = key
+ };
+ httpContent.Add(byteArray);
+ }
+ }
+
+
+ var response = await httpClient.PostAsync(uploadUrl, httpContent);
+
+ if (response.IsSuccessStatusCode)
+ {
+ string result = await response.Content.ReadAsStringAsync();
+ return result;
+ }
+ return null;
+ }
+
+ }
+ }
+
+ public async Task FormRequestPost(string url, RequestParam[] requestParams)
+ {
+ if (requestParams == null)
+ {
+ throw new Exception("请求参数不能为null!");
+ }
+
+ var httpClient = CreateClient(url);
+
+ using (MultipartFormDataContent httpContent = new MultipartFormDataContent())
+ {
+ foreach (var item in requestParams)
+ {
+ var valueBytes = Encoding.UTF8.GetBytes(item.RequestValue.ToString());
+ var byteArray = new ByteArrayContent(valueBytes);
+ byteArray.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
+ {
+ Name = item.RequestParameterName
+ };
+ httpContent.Add(byteArray);
+ }
+
+ var response = await httpClient.PostAsync(url, httpContent);
+
+ if (response.IsSuccessStatusCode)
+ {
+ string result = await response.Content.ReadAsStringAsync();
+ return result;
+ }
+ return null;
+ }
+
+ }
+
+ #endregion
+ }
+
+
+
+
+
+
+ ///
+ ///
+ ///
+ public class Token
+ {
+ public string access_token { get; set; }
+
+ public int expires_in { get; set; }
+
+ public string token_type { get; set; }
+
+ public string refresh_token { get; set; }
+ }
+
+ ///
+ /// 传输类型枚举
+ ///
+ public enum ContentType
+ {
+ [Display(Name = "application/xml")]
+ application_xml = 0,
+ [Display(Name = "application/json")]
+ application_json = 1,
+ [Display(Name = "application/text")]
+ application_text = 2,
+ [Display(Name = "application/x-www-form-urlencoded")]
+ application_x_www_form_urlencoded = 3
+ }
+
+ public class DateTimeConverter : JsonConverter
+ {
+ public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+ {
+ return DateTime.Parse(reader.GetString());
+ }
+
+ public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.ToString("yyyy-MM-dd HH:mm:ss"));
+ }
+ }
+
+ public class DateTimeNullableConverter : JsonConverter
+ {
+ public override DateTime? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+ {
+ return string.IsNullOrEmpty(reader.GetString()) ? default(DateTime?) : DateTime.Parse(reader.GetString());
+ }
+
+ public override void Write(Utf8JsonWriter writer, DateTime? value, JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value?.ToString("yyyy-MM-dd HH:mm:ss"));
+ }
+ }
+
+ ///
+ /// 枚举扩展类
+ ///
+ internal static class EnumHelper
+ {
+ ///
+ /// 获取枚举的Display文本
+ ///
+ ///
+ ///
+ public static String GetDisplay(this Enum value)
+ {
+ var type = value.GetType();//先获取这个枚举的类型
+ var field = type.GetField(value.ToString());//通过这个类型获取到值
+ var obj = (DisplayAttribute)field.GetCustomAttribute(typeof(DisplayAttribute));//得到特性
+ return obj.Name ?? "";
+ }
+ }
+}
diff --git a/Vampirewal.Core.SubMessageService/ISubMessageService.cs b/Vampirewal.Core.SubMessageService/ISubMessageService.cs
new file mode 100644
index 0000000..fa34f38
--- /dev/null
+++ b/Vampirewal.Core.SubMessageService/ISubMessageService.cs
@@ -0,0 +1,203 @@
+
+#region 文件信息
+/*----------------------------------------------------------------
+//
+// 文件名称:
+// 文件功能描述:
+// 设计要求:
+//
+// 文 件 名: ISubMessageService
+// 创建者: 杨程
+// 创建日期: 2022/11/12 13:50:48
+
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+//
+
+namespace Vampirewal.Core.SubMessageService
+{
+ ///
+ ///
+ ///
+ public interface ISubMessageService
+ {
+ ///
+ /// 订阅消息
+ ///
+ /// 继承自SubMessage的消息类
+ ///
+ ///
+ ///
+ void Subscribe(object recipient, Action action,
+ ThreadOption threadOption = ThreadOption.PublisherThread) where TMessage : SubMessage;
+
+ ///
+ /// 取消订阅
+ ///
+ ///
+ ///
+ ///
+ void Unsubscribe(object recipient, Action? action = null) where TMessage : SubMessage;
+
+ ///
+ /// 消息推送
+ ///
+ ///
+ ///
+ ///
+ void Publish(object sender, TMessage message) where TMessage : SubMessage;
+ }
+
+ public enum ThreadOption
+ {
+ PublisherThread,
+ BackgroundThread,
+ UiThread
+ }
+
+ public class VampirewalSubMessageService : ISubMessageService
+ {
+ public static readonly VampirewalSubMessageService Default = new VampirewalSubMessageService();
+ private readonly object registerLock = new object();
+
+ private Dictionary>? recipientsOfSubclassesAction;
+
+ public void Subscribe(object recipient, Action action, ThreadOption threadOption)
+ where TMessage : SubMessage
+ {
+ lock (this.registerLock)
+ {
+ var messageType = typeof(TMessage);
+
+ this.recipientsOfSubclassesAction ??= new Dictionary>();
+
+ List list;
+
+ if (!this.recipientsOfSubclassesAction.ContainsKey(messageType))
+ {
+ list = new List();
+ this.recipientsOfSubclassesAction.Add(messageType, list);
+ }
+ else
+ {
+ list = this.recipientsOfSubclassesAction[messageType];
+ }
+
+ var item = new WeakActionAndToken
+ {
+ Recipient = recipient,
+ ThreadOption = threadOption,
+ Action = action
+ };
+
+ list.Add(item);
+ }
+ }
+
+ public void Unsubscribe(object? recipient, Action? action) where TMessage : SubMessage
+ {
+ var messageType = typeof(TMessage);
+
+ if (recipient == null || this.recipientsOfSubclassesAction == null ||
+ this.recipientsOfSubclassesAction.Count == 0 || !this.recipientsOfSubclassesAction.ContainsKey(messageType))
+ {
+ return;
+ }
+
+ var lstActions = this.recipientsOfSubclassesAction[messageType];
+ for (var i = lstActions.Count - 1; i >= 0; i--)
+ {
+ var item = lstActions[i];
+ var pastAction = item.Action;
+
+ if (pastAction != null
+ && recipient == pastAction.Target
+ && (action == null || action.Method.Name == pastAction.Method.Name))
+ {
+ lstActions.Remove(item);
+ }
+ }
+ }
+
+ public void Publish(object sender, TMessage message) where TMessage : SubMessage
+ {
+ var messageType = typeof(TMessage);
+
+ if (this.recipientsOfSubclassesAction != null)
+ {
+ var listClone = this.recipientsOfSubclassesAction.Keys.Take(this.recipientsOfSubclassesAction.Count)
+ .ToList();
+
+ foreach (var type in listClone)
+ {
+ List? list = null;
+
+ if (messageType == type || messageType.IsSubclassOf(type) || type.IsAssignableFrom(messageType))
+ {
+ list = this.recipientsOfSubclassesAction[type]
+ .Take(this.recipientsOfSubclassesAction[type].Count)
+ .ToList();
+ }
+
+ if (list is { Count: > 0 })
+ {
+ this.SendToList(message, list);
+ }
+ }
+ }
+ }
+
+ private void SendToList(TMessage message, IEnumerable weakActionsAndTokens)
+ where TMessage : SubMessage
+ {
+ var list = weakActionsAndTokens.ToList();
+ var listClone = list.Take(list.Count()).ToList();
+
+ foreach (var item in listClone)
+ {
+ if (item.Action is { Target: { } })
+ {
+ switch (item.ThreadOption)
+ {
+ case ThreadOption.BackgroundThread:
+ Task.Run(() => { item.ExecuteWithObject(message); });
+ break;
+ case ThreadOption.UiThread:
+ SynchronizationContext.Current!.Post(_ => { item.ExecuteWithObject(message); }, null);
+ break;
+ default:
+ item.ExecuteWithObject(message);
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ public class WeakActionAndToken
+ {
+ public object? Recipient { get; set; }
+
+ public ThreadOption ThreadOption { get; set; }
+
+ public Delegate? Action { get; set; }
+
+ public string? Tag { get; set; }
+
+ public void ExecuteWithObject(TMessage message) where TMessage : SubMessage
+ {
+ if (this.Action is Action factAction)
+ {
+ factAction.Invoke(message);
+ }
+ }
+ }
+}
diff --git a/Vampirewal.Core.SubMessageService/SubMessage.cs b/Vampirewal.Core.SubMessageService/SubMessage.cs
new file mode 100644
index 0000000..d0a8fe7
--- /dev/null
+++ b/Vampirewal.Core.SubMessageService/SubMessage.cs
@@ -0,0 +1,42 @@
+
+#region 文件信息
+/*----------------------------------------------------------------
+//
+// 文件名称:
+// 文件功能描述:
+// 设计要求:
+//
+// 文 件 名: SubMessage
+// 创建者: 杨程
+// 创建日期: 2022/11/12 13:47:31
+
+//----------------------------------------------------------------*/
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+
+
+namespace Vampirewal.Core.SubMessageService
+{
+ ///
+ /// 消息抽象类,用于定义消息类型,具体的消息需要继承该类
+ ///
+ public abstract class SubMessage
+ {
+ ///
+ ///
+ ///
+ protected SubMessage(object sender)
+ {
+ //构造函数
+ this.Sender = sender ?? throw new ArgumentNullException(nameof(sender));
+ }
+
+ public object Sender { get; set; }
+ }
+}
diff --git a/Vampirewal.Core.SubMessageService/Vampirewal.Core.SubMessageService.csproj b/Vampirewal.Core.SubMessageService/Vampirewal.Core.SubMessageService.csproj
new file mode 100644
index 0000000..f208d30
--- /dev/null
+++ b/Vampirewal.Core.SubMessageService/Vampirewal.Core.SubMessageService.csproj
@@ -0,0 +1,7 @@
+
+
+
+ net5.0
+
+
+
diff --git a/Vampirewal.Core/Interface/ISubFile.cs b/Vampirewal.Core/AppContext.cs
similarity index 39%
rename from Vampirewal.Core/Interface/ISubFile.cs
rename to Vampirewal.Core/AppContext.cs
index 6ab5c54..605fd9e 100644
--- a/Vampirewal.Core/Interface/ISubFile.cs
+++ b/Vampirewal.Core/AppContext.cs
@@ -1,13 +1,15 @@
-#region << 文 件 说 明 >>
+
+#region 文件信息
/*----------------------------------------------------------------
-// 文件名称:ISubFile
-// 创 建 者:杨程
-// 创建时间:2021/9/16 11:12:06
-// 文件版本:V1.0.0
-// ===============================================================
-// 功能描述:
-//
+//
+// 文件名称:
+// 文件功能描述:
+// 设计要求:
//
+// 文 件 名: AppContext
+// 创建者: 杨程
+// 创建日期: 2022/11/25 14:17:13
+
//----------------------------------------------------------------*/
#endregion
@@ -18,12 +20,20 @@ using System.Text;
using System.Threading.Tasks;
using Vampirewal.Core.Models;
-namespace Vampirewal.Core.Interface
+namespace Vampirewal.Core
{
- public interface ISubFile
+ ///
+ /// 程序上下文
+ ///
+ public class AppContext:BaseSingleton
{
- Guid FileId { get; set; }
- FileAttachment File { get; set; }
- int order { get; set; }
+
+ ///
+ /// 当前使用用户
+ ///
+ public FrameworkUserBase User { get; set; }
}
+
+
+
}
diff --git a/Vampirewal.Core/Components/VampirewalLog.cs b/Vampirewal.Core/Components/VampirewalLog.cs
index 7dd9c6d..b95c9e7 100644
--- a/Vampirewal.Core/Components/VampirewalLog.cs
+++ b/Vampirewal.Core/Components/VampirewalLog.cs
@@ -51,20 +51,20 @@ namespace Vampirewal.Core.Components
///
public void DebugLog(string Msg, string SystemModuleName)
{
- if (SystemDataContext.GetInstance().LogLevel >= 0)
- {
- Logger logger = new Logger()
- {
- LoggerContent = Msg,
- loggerType = LoggerType.Debug,
- SystemMoudleName = SystemModuleName,
- CreateTime = DateTime.Now,
- CreateBy = SystemDataContext.GetInstance().loginUserInfo?.ITCode
- };
-
- DC.AddEntity(logger);
- //DC.SaveChanges();
- }
+ //if (SystemDataContext.GetInstance().LogLevel >= 0)
+ //{
+ // Logger logger = new Logger()
+ // {
+ // LoggerContent = Msg,
+ // loggerType = LoggerType.Debug,
+ // SystemMoudleName = SystemModuleName,
+ // CreateTime = DateTime.Now,
+ // CreateBy = SystemDataContext.GetInstance().loginUserInfo?.ITCode
+ // };
+
+ // DC.AddEntity(logger);
+ // //DC.SaveChanges();
+ //}
}
@@ -75,20 +75,20 @@ namespace Vampirewal.Core.Components
///
public void ErrorLog(string Msg, string SystemModuleName)
{
- if (SystemDataContext.GetInstance().LogLevel >= 2)
- {
- Logger logger = new Logger()
- {
- LoggerContent = Msg,
- loggerType = LoggerType.Error,
- SystemMoudleName = SystemModuleName,
- CreateTime = DateTime.Now,
- CreateBy = SystemDataContext.GetInstance().loginUserInfo?.ITCode
- };
-
- DC.AddEntity(logger);
- //DC.SaveChanges();
- }
+ //if (SystemDataContext.GetInstance().LogLevel >= 2)
+ //{
+ // Logger logger = new Logger()
+ // {
+ // LoggerContent = Msg,
+ // loggerType = LoggerType.Error,
+ // SystemMoudleName = SystemModuleName,
+ // CreateTime = DateTime.Now,
+ // CreateBy = SystemDataContext.GetInstance().loginUserInfo?.ITCode
+ // };
+
+ // DC.AddEntity(logger);
+ // //DC.SaveChanges();
+ //}
}
@@ -100,20 +100,20 @@ namespace Vampirewal.Core.Components
///
public void SQLLog(string Msg, string SystemModuleName)
{
- if (SystemDataContext.GetInstance().LogLevel >= 3)
- {
- Logger logger = new Logger()
- {
- LoggerContent = Msg,
- loggerType = LoggerType.SQL,
- SystemMoudleName = SystemModuleName,
- CreateTime = DateTime.Now,
- CreateBy = SystemDataContext.GetInstance().loginUserInfo?.ITCode
- };
-
- DC.AddEntity(logger);
- //DC.SaveChanges();
- }
+ //if (SystemDataContext.GetInstance().LogLevel >= 3)
+ //{
+ // Logger logger = new Logger()
+ // {
+ // LoggerContent = Msg,
+ // loggerType = LoggerType.SQL,
+ // SystemMoudleName = SystemModuleName,
+ // CreateTime = DateTime.Now,
+ // CreateBy = SystemDataContext.GetInstance().loginUserInfo?.ITCode
+ // };
+
+ // DC.AddEntity(logger);
+ // //DC.SaveChanges();
+ //}
}
@@ -124,20 +124,20 @@ namespace Vampirewal.Core.Components
///
public void WarningLog(string Msg, string SystemModuleName)
{
- if (SystemDataContext.GetInstance().LogLevel >= 1)
- {
- Logger logger = new Logger()
- {
- LoggerContent = Msg,
- loggerType = LoggerType.Warning,
- SystemMoudleName = SystemModuleName,
- CreateTime = DateTime.Now,
- CreateBy = SystemDataContext.GetInstance().loginUserInfo?.ITCode
- };
-
- DC.AddEntity(logger);
- //DC.SaveChanges();
- }
+ //if (SystemDataContext.GetInstance().LogLevel >= 1)
+ //{
+ // Logger logger = new Logger()
+ // {
+ // LoggerContent = Msg,
+ // loggerType = LoggerType.Warning,
+ // SystemMoudleName = SystemModuleName,
+ // CreateTime = DateTime.Now,
+ // CreateBy = SystemDataContext.GetInstance().loginUserInfo?.ITCode
+ // };
+
+ // DC.AddEntity(logger);
+ // //DC.SaveChanges();
+ //}
}
@@ -149,16 +149,16 @@ namespace Vampirewal.Core.Components
///
public void WriteLog(string Msg, LoggerType loggerType, string SystemModuleName)
{
- Logger logger = new Logger()
- {
- LoggerContent = Msg,
- loggerType = loggerType,
- SystemMoudleName = SystemModuleName,
- CreateTime = DateTime.Now,
- CreateBy = SystemDataContext.GetInstance().loginUserInfo?.ITCode
- };
-
- DC.AddEntity(logger);
+ //Logger logger = new Logger()
+ //{
+ // LoggerContent = Msg,
+ // loggerType = loggerType,
+ // SystemMoudleName = SystemModuleName,
+ // CreateTime = DateTime.Now,
+ // CreateBy = SystemDataContext.GetInstance().loginUserInfo?.ITCode
+ //};
+
+ //DC.AddEntity(logger);
//DC.SaveChanges();
}
}
diff --git a/Vampirewal.Core/DBContexts/VampirewalDbBase.cs b/Vampirewal.Core/DBContexts/VampirewalDbBase.cs
index 8111b3d..eeffa28 100644
--- a/Vampirewal.Core/DBContexts/VampirewalDbBase.cs
+++ b/Vampirewal.Core/DBContexts/VampirewalDbBase.cs
@@ -11,12 +11,14 @@
//----------------------------------------------------------------*/
#endregion
+using Google.Protobuf.WellKnownTypes;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Windows;
using Vampirewal.Core.AppConfig;
using Vampirewal.Core.Interface;
using Vampirewal.Core.Models;
@@ -37,7 +39,7 @@ namespace Vampirewal.Core.DBContexts
{
config.LoadAppConfig();
- SystemDataContext.GetInstance().LogLevel = (int)config.LogLevel;
+ //SystemDataContext.GetInstance().LogLevel = (int)config.LogLevel;
var dbConnectConfigList = new List();
@@ -70,6 +72,9 @@ namespace Vampirewal.Core.DBContexts
//可以修改SQL和参数的值
Client.Aop.OnExecutingChangeSql = OnExecutingChangeSql;
+ Client.Aop.DataExecuting= DataExecuting;
+ Client.Aop.DataExecuted = DataExecuted;
+
Client.DbMaintenance.CreateDatabase();
CodeFirst();
}
@@ -151,6 +156,70 @@ namespace Vampirewal.Core.DBContexts
}
+ ///
+ /// 数据执行过滤
+ /// 可用于新增或修改的时候,处理CreateName或UpdateName
+ ///
+ ///
+ ///
+ public virtual void DataExecuting(object OldValue, DataFilterModel entityInfo)
+ {
+ // 新增操作
+ if (entityInfo.OperationType == DataFilterType.InsertByObject)
+ {
+ // 主键赋值
+ if (entityInfo.EntityColumnInfo.IsPrimarykey && entityInfo.EntityColumnInfo.PropertyInfo.PropertyType == typeof(Guid))
+ {
+ var billid = ((dynamic)entityInfo.EntityValue).Billid;
+ if (billid == null )
+ entityInfo.SetValue(Guid.NewGuid().ToString());
+
+ var dtlid = ((dynamic)entityInfo.EntityValue).DtlId;
+ if (dtlid == null)
+ entityInfo.SetValue(Guid.NewGuid().ToString());
+ }
+
+ if (entityInfo.PropertyName == "CreateTime" && ((dynamic)entityInfo.EntityValue).CreateTime == null)
+ entityInfo.SetValue(DateTime.Now);
+
+ if (AppContext.GetInstance().User != null)
+ {
+
+ if (entityInfo.PropertyName == "CreateUserId")
+ {
+ var createUserId = ((dynamic)entityInfo.EntityValue).CreatedUserId;
+ if (createUserId == null || createUserId == 0)
+ entityInfo.SetValue(AppContext.GetInstance().User?.BillId);
+ }
+
+ if (entityInfo.PropertyName == "CreateBy" && ((dynamic)entityInfo.EntityValue).CreatedUserName == null)
+ entityInfo.SetValue(AppContext.GetInstance().User?.Name);
+ }
+ }
+
+ // 更新操作
+ if (entityInfo.OperationType == DataFilterType.UpdateByObject)
+ {
+ if (entityInfo.PropertyName == "UpdateTime")
+ entityInfo.SetValue(DateTime.Now);
+ if (entityInfo.PropertyName == "UpdateUserId")
+ entityInfo.SetValue(AppContext.GetInstance().User?.BillId);
+ if (entityInfo.PropertyName == "UpdateBy")
+ entityInfo.SetValue(AppContext.GetInstance().User?.Name);
+
+ }
+
+
+ }
+
+ ///
+ /// 查询后数据替换
+ ///
+ ///
+ ///
+ public virtual void DataExecuted(object value, DataAfterModel entity) { }
+
+
///
/// 可以修改SQL和参数的值
///
diff --git a/Vampirewal.Core/Interface/IEFRepository.cs b/Vampirewal.Core/Interface/IEFRepository.cs
deleted file mode 100644
index a7f34c7..0000000
--- a/Vampirewal.Core/Interface/IEFRepository.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-#region << 文 件 说 明 >>
-/*----------------------------------------------------------------
-// 文件名称:IEFRepository
-// 创 建 者:杨程
-// 创建时间:2021/9/10 13:30:27
-// 文件版本:V1.0.0
-// ===============================================================
-// 功能描述:
-//
-//
-//----------------------------------------------------------------*/
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Linq.Expressions;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Vampirewal.Core.Interface
-{
- ///
- /// EF帮助类接口
- ///
- ///
- public interface IEFRepository
- {
-
- bool AddEntity(TEntity entity) where TEntity : class;
- bool UpdateEntity(TEntity entity) where TEntity : class;
- bool UpdateEntityList(IEnumerable entities) where TEntity : class;
- bool DeleteEntity(object ID) where TEntity : class;
- bool DeleteEntity(TEntity entity) where TEntity : class;
- bool DeleteEntity(Expression> predicate) where TEntity : class;
- bool DeleteEntityList(IEnumerable entities) where TEntity : class;
- IEnumerable LoadEntities(Func whereLambda) where TEntity : class;
- IEnumerable LoadEntities(int pageIndex = 1, int pageSize = 30, Func whereLambda = null) where TEntity : class;
- TEntity GetByID(object ID) where TEntity : class;
- }
-}
diff --git a/Vampirewal.Core/Interface/ISearcher.cs b/Vampirewal.Core/Interface/ISearcher.cs
index 20414c7..415ec19 100644
--- a/Vampirewal.Core/Interface/ISearcher.cs
+++ b/Vampirewal.Core/Interface/ISearcher.cs
@@ -95,10 +95,10 @@ namespace Vampirewal.Core.Interface
#endregion
#region Method
- ///
- /// 将源 VM 的 FC 等内容复制到本VM中
- ///
- ///
+ /////
+ ///// 将源 VM 的 FC 等内容复制到本VM中
+ /////
+ /////
//void CopyContext(IBaseVM vm);
///
diff --git a/Vampirewal.Core/IoC/VampirewalIoC.cs b/Vampirewal.Core/IoC/VampirewalIoC.cs
index 6138e8c..5908295 100644
--- a/Vampirewal.Core/IoC/VampirewalIoC.cs
+++ b/Vampirewal.Core/IoC/VampirewalIoC.cs
@@ -335,6 +335,7 @@ namespace Vampirewal.Core.IoC
for (int i = 0; i < infoCollection.Length; i++)
{
ConstructorInfo constructorInfo = infoCollection[i];
+ //获取构造函数中的参数
ParameterInfo[] parameters = constructorInfo.GetParameters();
if (parameters.Length == 0)
diff --git a/Vampirewal.Core/Models/BillBaseModel.cs b/Vampirewal.Core/Models/BillBaseModel.cs
index 88bd6fa..0b497d2 100644
--- a/Vampirewal.Core/Models/BillBaseModel.cs
+++ b/Vampirewal.Core/Models/BillBaseModel.cs
@@ -43,10 +43,7 @@ namespace Vampirewal.Core.Models
{
get
{
- if (string.IsNullOrEmpty(_BillId))
- {
- _BillId = Guid.NewGuid().ToString();
- }
+
return _BillId;
}
set
@@ -65,10 +62,7 @@ namespace Vampirewal.Core.Models
{
get
{
- if (_CreateTime == null)
- {
- _CreateTime = DateTime.Now;
- }
+
return _CreateTime;
}
set
@@ -89,6 +83,19 @@ namespace Vampirewal.Core.Models
set { _CreateBy = value; DoNotify(); }
}
+ private string _CreateUserId;
+ ///
+ /// 创建人ID
+ ///
+ [SugarColumn(IsNullable = true, IsOnlyIgnoreUpdate = true)]
+ public string CreateUserId
+ {
+ get { return _CreateUserId; }
+ set { _CreateUserId = value; DoNotify(); }
+ }
+
+
+
private DateTime? _UpdateTime;
///
/// 更新时间
@@ -98,10 +105,7 @@ namespace Vampirewal.Core.Models
{
get
{
- if (_UpdateTime == null)
- {
- _UpdateTime = DateTime.Now;
- }
+
return _UpdateTime;
}
set
@@ -124,6 +128,18 @@ namespace Vampirewal.Core.Models
DoNotify();
}
}
+
+ private string _UpdateUserId;
+ ///
+ /// 更新人ID
+ ///
+ [SugarColumn(IsNullable = true, IsOnlyIgnoreInsert = true)]
+ public string UpdateUserId
+ {
+ get { return _UpdateUserId; }
+ set { _UpdateUserId = value; DoNotify(); }
+ }
+
#endregion
}
}
diff --git a/Vampirewal.Core/Models/FrameworkUserBase.cs b/Vampirewal.Core/Models/FrameworkUserBase.cs
index 064dd83..f7f1f60 100644
--- a/Vampirewal.Core/Models/FrameworkUserBase.cs
+++ b/Vampirewal.Core/Models/FrameworkUserBase.cs
@@ -28,38 +28,26 @@ namespace Vampirewal.Core.Models
/// 系统人员基类
///
[SugarTable("FrameworkUserBase")]
- public class FrameworkUserBase : BillBaseModel
+ public abstract class FrameworkUserBase : BillBaseModel
{
///
/// 工号
///
[Display(Name = "工号")]
- [StringLength(50, ErrorMessage = "字段长度超过50!")]
- public string ITCode { get; set; }
+ public string LoginId { get; set; }
///
/// 密码
///
[Display(Name = "密码")]
- [Required(AllowEmptyStrings = false, ErrorMessage = "密码不能为空!")]
- [StringLength(32, ErrorMessage = "密码最长32位!")]
public string Password { get; set; }
///
/// 姓名
///
[Display(Name = "姓名")]
- [Required(ErrorMessage = "姓名不能为空")]
public string Name { get; set; }
- ///
- /// 角色
- ///
- [Display(Name = "角色")]
- [SugarColumn(IsIgnore =true)]
- public List UserRoles { get; set; }
-
- //[Display(Name = "Group")]
- //public List UserGroups { get; set; }
+
}
}
diff --git a/Vampirewal.Core/SimpleMVVM/BaseCRUDVM.cs b/Vampirewal.Core/SimpleMVVM/BaseCRUDVM.cs
deleted file mode 100644
index 1d79dce..0000000
--- a/Vampirewal.Core/SimpleMVVM/BaseCRUDVM.cs
+++ /dev/null
@@ -1,981 +0,0 @@
-#region << 文 件 说 明 >>
-/*----------------------------------------------------------------
-// 文件名称:BaseCRUDVM
-// 创 建 者:杨程
-// 创建时间:2021/9/16 10:09:04
-// 文件版本:V1.0.0
-// ===============================================================
-// 功能描述:
-//
-//
-//----------------------------------------------------------------*/
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations.Schema;
-using System.Linq;
-using System.Linq.Expressions;
-using System.Reflection;
-using System.Text;
-using System.Threading.Tasks;
-using Microsoft.VisualBasic.CompilerServices;
-using Vampirewal.Core.Extensions;
-using Vampirewal.Core.Helper;
-using Vampirewal.Core.Interface;
-using Vampirewal.Core.Models;
-
-namespace Vampirewal.Core.SimpleMVVM
-{
- ///
- /// CRUD基类VM
- ///
- ///
- //public class BaseCRUDVM : ViewModelBase, IBaseCRUDVM where TModel : TopBaseModel, new()
- //{
- // private TModel _Entity;
- // ///
- // /// 实体类
- // ///
- // public TModel Entity
- // {
- // get
- // {
- // return _Entity;
- // }
-
- // set
- // {
- // _Entity = value;
- // DoNotify();
- // }
- // }
-
- // //保存读取时Include的内容
- // private List>> _toInclude { get; set; }
-
- // ///
- // /// 无参构造函数
- // ///
- // public BaseCRUDVM()
- // {
- // //初始化Entity
- // var ctor = typeof(TModel).GetConstructor(Type.EmptyTypes);
- // Entity = ctor.Invoke(null) as TModel;
- // //初始化VM中所有List<>的类
- // var lists = typeof(TModel).GetProperties().Where(x => x.PropertyType.IsGeneric(typeof(List<>)));
- // foreach (var li in lists)
- // {
- // var gs = li.PropertyType.GetGenericArguments();
- // var newObj = Activator.CreateInstance(typeof(List<>).MakeGenericType(gs[0]));
- // li.SetValue(Entity, newObj, null);
- // }
- // BaseCRUDInit();
- // }
-
- // ///
- // /// 获取DC的构造函数
- // ///
- // ///
- // public BaseCRUDVM(IDataContext dc):base(dc)
- // {
- // //初始化Entity
- // var ctor = typeof(TModel).GetConstructor(Type.EmptyTypes);
- // Entity = ctor.Invoke(null) as TModel;
- // //初始化VM中所有List<>的类
- // var lists = typeof(TModel).GetProperties().Where(x => x.PropertyType.IsGeneric(typeof(List<>)));
- // foreach (var li in lists)
- // {
- // var gs = li.PropertyType.GetGenericArguments();
- // var newObj = Activator.CreateInstance(typeof(List<>).MakeGenericType(gs[0]));
- // li.SetValue(Entity, newObj, null);
- // }
- // BaseCRUDInit();
- // }
-
- // ///
- // /// 获取DC和配置文件的构造函数
- // ///
- // ///
- // ///
- // public BaseCRUDVM(IDataContext dc,IAppConfig config) : base(dc,config)
- // {
- // //初始化Entity
- // var ctor = typeof(TModel).GetConstructor(Type.EmptyTypes);
- // Entity = ctor.Invoke(null) as TModel;
- // //初始化VM中所有List<>的类
- // var lists = typeof(TModel).GetProperties().Where(x => x.PropertyType.IsGeneric(typeof(List<>)));
- // foreach (var li in lists)
- // {
- // var gs = li.PropertyType.GetGenericArguments();
- // var newObj = Activator.CreateInstance(typeof(List<>).MakeGenericType(gs[0]));
- // li.SetValue(Entity, newObj, null);
- // }
-
- // BaseCRUDInit();
- // }
-
- // //public IQueryable GetBaseQuery()
- // //{
- // // return DC.Set();
- // //}
-
- // ///
- // /// 设定读取是Include的内容
- // ///
- // /// 需要关联的类
- // public void SetInclude(params Expression>[] exps)
- // {
- // _toInclude = _toInclude ?? new List>>();
- // _toInclude.AddRange(exps);
- // }
-
-
- // ///
- // /// 设定添加和修改时对于重复数据的判断,子类进行相关操作时应重载这个函数
- // ///
- // /// 唯一性属性
- // public virtual DuplicatedInfo SetDuplicatedCheck()
- // {
- // return null;
- // }
- // ///
- // /// 添加
- // ///
- // //public void DoAdd()
- // //{
- // // DoAddPrepare();
- // // //删除不需要的附件
- // // if (DeletedFileIds != null)
- // // {
- // // foreach (var item in DeletedFileIds)
- // // {
- // // FileAttachmentVM ofa = new FileAttachmentVM();
- // // ofa.CopyVM(this);
- // // ofa.SetEntityById(item);
- // // ofa.DoDelete();
- // // }
- // // }
- // // DC.SaveChanges();
- // //}
-
- // //private void DoAddPrepare()
- // //{
- // // var pros = typeof(TModel).GetProperties();
- // // //将所有TopBaseModel的属性赋空值,防止添加关联的重复内容
- // // if (typeof(TModel) != typeof(FileAttachment))
- // // {
- // // foreach (var pro in pros)
- // // {
- // // if (pro.PropertyType.GetTypeInfo().IsSubclassOf(typeof(TopBaseModel)))
- // // {
- // // pro.SetValue(Entity, null);
- // // }
- // // }
- // // }
- // // //自动设定添加日期和添加人
- // // if ( typeof(TModel).GetTypeInfo().IsSubclassOf(typeof(TopBaseModel)))
- // // {
- // // TopBaseModel ent = Entity as TopBaseModel;
- // // if (ent.CreateTime == null)
- // // {
- // // ent.CreateTime = DateTime.Now;
- // // }
- // // if (string.IsNullOrEmpty(ent.CreateBy))
- // // {
- // // ent.CreateBy = loginUserInfo?.ITCode;
- // // }
- // // }
-
- // // if (typeof(TModel).GetTypeInfo().IsSubclassOf(typeof(PersistModel)))
- // // {
- // // (Entity as PersistModel).IsValid = true;
- // // }
-
- // // #region 更新子表
- // // foreach (var pro in pros)
- // // {
- // // //找到类型为List的字段
- // // if (pro.PropertyType.GenericTypeArguments.Count() > 0)
- // // {
- // // //获取xxx的类型
- // // var ftype = pro.PropertyType.GenericTypeArguments.First();
- // // //如果xxx继承自TopBaseModel
- // // if (ftype.IsSubclassOf(typeof(TopBaseModel)))
- // // {
- // // //界面传过来的子表数据
- // // IEnumerable list = pro.GetValue(Entity) as IEnumerable;
- // // if (list != null && list.Count() > 0)
- // // {
- // // string fkname = DC.GetFKName(pro.Name);
- // // PropertyInfo[] itemPros = ftype.GetProperties();
-
- // // bool found = false;
- // // foreach (var newitem in list)
- // // {
- // // foreach (var itempro in itemPros)
- // // {
- // // if (itempro.PropertyType.IsSubclassOf(typeof(TopBaseModel)))
- // // {
- // // itempro.SetValue(newitem, null);
- // // }
- // // if (!string.IsNullOrEmpty(fkname))
- // // {
- // // if (itempro.Name.ToLower() == fkname.ToLower())
- // // {
- // // itempro.SetValue(newitem, Entity.GetID());
- // // found = true;
- // // }
- // // }
- // // }
- // // }
- // // //如果没有找到相应的外建字段,则可能是多对多的关系,或者做了特殊的设定,这种情况框架无法支持,直接退出本次循环
- // // if (found == false)
- // // {
- // // continue;
- // // }
- // // //循环页面传过来的子表数据,自动设定添加日期和添加人
- // // foreach (var newitem in list)
- // // {
- // // var subtype = newitem.GetType();
- // // BaseModel ent = newitem as BaseModel;
- // // if (ent.CreateTime == null)
- // // {
- // // ent.CreateTime = DateTime.Now;
- // // }
- // // if (string.IsNullOrEmpty(ent.CreateBy))
- // // {
- // // ent.CreateBy = loginUserInfo?.ITCode;
- // // }
- // // }
- // // }
- // // }
- // // }
- // // }
- // // #endregion
-
-
- // // //添加数据
- // // DC.Set().Add(Entity);
-
- // //}
- // ///
- // /// 异步添加
- // ///
- // ///
- // //public async Task DoAddAsync()
- // //{
- // // DoAddPrepare();
- // // //删除不需要的附件
- // // if (DeletedFileIds != null)
- // // {
- // // foreach (var item in DeletedFileIds)
- // // {
- // // FileAttachmentVM ofa = new FileAttachmentVM();
- // // ofa.CopyVM(this);
- // // ofa.SetEntityById(item);
- // // await ofa.DoDeleteAsync();
- // // }
- // // }
- // // await DC.SaveChangesAsync();
- // //}
- // ///
- // /// 删除
- // ///
- // //public virtual void DoDelete()
- // //{
- // // //如果是PersistPoco,则把IsValid设为false,并不进行物理删除
- // // if (typeof(TModel).GetTypeInfo().IsSubclassOf(typeof(PersistModel)))
- // // {
- // // //FC.Add("Entity.IsValid", 0);
- // // (Entity as PersistModel).IsValid = false;
- // // DoEditPrepare(false);
- // // DC.SaveChanges();
- // // }
- // // //如果是普通的TopBaseModel,则进行物理删除
- // // else if (typeof(TModel).GetTypeInfo().IsSubclassOf(typeof(TopBaseModel)))
- // // {
- // // DoRealDelete();
- // // }
- // //}
- // ///
- // /// 异步删除
- // ///
- // ///
- // //public virtual async Task DoDeleteAsync()
- // //{
- // // //如果是PersistPoco,则把IsValid设为false,并不进行物理删除
- // // if (typeof(TModel).GetTypeInfo().IsSubclassOf(typeof(PersistModel)))
- // // {
- // // (Entity as PersistModel).IsValid = false;
- // // (Entity as PersistModel).UpdateTime = DateTime.Now;
- // // (Entity as PersistModel).UpdateBy = loginUserInfo?.ITCode;
- // // DC.UpdateProperty(Entity, "IsValid");
- // // DC.UpdateProperty(Entity, "UpdateTime");
- // // DC.UpdateProperty(Entity, "UpdateBy");
- // // try
- // // {
- // // await DC.SaveChangesAsync();
- // // }
- // // catch (DbUpdateException)
- // // {
- // // //MSD.AddModelError("", Program._localizer["DeleteFailed"]);
- // // }
- // // }
- // // //如果是普通的TopBaseModel,则进行物理删除
- // // else if (typeof(TModel).GetTypeInfo().IsSubclassOf(typeof(TopBaseModel)))
- // // {
- // // DoRealDelete();
- // // }
- // //}
- // ///
- // /// 保存编辑
- // ///
- // ///
- // //public virtual void DoEdit(bool updateAllFields)
- // //{
- // // DoEditPrepare(updateAllFields);
-
- // // DC.SaveChanges();
- // // //删除不需要的附件
- // // if (DeletedFileIds != null)
- // // {
- // // foreach (var item in DeletedFileIds)
- // // {
- // // FileAttachmentVM ofa = new FileAttachmentVM();
- // // ofa.CopyVM(this);
- // // ofa.SetEntityById(item);
- // // ofa.DoDelete();
- // // }
- // // }
- // //}
- // ///
- // /// 异步保存编辑
- // ///
- // ///
- // ///
- // //public virtual async Task DoEditAsync(bool updateAllFields)
- // //{
- // // DoEditPrepare(updateAllFields);
-
- // // await DC.SaveChangesAsync();
- // // //删除不需要的附件
- // // if (DeletedFileIds != null)
- // // {
- // // foreach (var item in DeletedFileIds)
- // // {
- // // FileAttachmentVM ofa = new FileAttachmentVM();
- // // ofa.CopyVM(this);
- // // ofa.SetEntityById(item);
- // // await ofa.DoDeleteAsync();
- // // }
- // // }
- // //}
-
- // //private void DoEditPrepare(bool updateAllFields)
- // //{
- // // if (typeof(TModel).GetTypeInfo().IsSubclassOf(typeof(BaseModel)))
- // // {
- // // BaseModel ent = Entity as BaseModel;
- // // if (ent.UpdateTime == null)
- // // {
- // // ent.UpdateTime = DateTime.Now;
- // // }
- // // if (string.IsNullOrEmpty(ent.UpdateBy))
- // // {
- // // ent.UpdateBy = loginUserInfo?.ITCode;
- // // }
- // // }
- // // var pros = typeof(TModel).GetProperties();
-
- // // #region 更新子表
- // // foreach (var pro in pros)
- // // {
- // // //找到类型为List的字段
- // // if (pro.PropertyType.GenericTypeArguments.Count() > 0)
- // // {
- // // //获取xxx的类型
- // // var ftype = pro.PropertyType.GenericTypeArguments.First();
- // // //如果xxx继承自TopBaseModel
- // // if (ftype.IsSubclassOf(typeof(TopBaseModel)))
- // // {
- // // //界面传过来的子表数据
-
- // // if (pro.GetValue(Entity) is IEnumerable list && list.Count() > 0)
- // // {
- // // //获取外键字段名称
- // // string fkname = DC.GetFKName(pro.Name);
- // // PropertyInfo[] itemPros = ftype.GetProperties();
-
- // // bool found = false;
- // // foreach (var newitem in list)
- // // {
- // // var subtype = newitem.GetType();
- // // if (subtype.IsSubclassOf(typeof(BaseModel)))
- // // {
- // // BaseModel ent = newitem as BaseModel;
- // // if (ent.UpdateTime == null)
- // // {
- // // ent.UpdateTime = DateTime.Now;
- // // }
- // // if (string.IsNullOrEmpty(ent.UpdateBy))
- // // {
- // // ent.UpdateBy = loginUserInfo?.ITCode;
- // // }
- // // }
- // // //循环页面传过来的子表数据,将关联到TopBaseModel的字段设为null,并且把外键字段的值设定为主表ID
- // // foreach (var itempro in itemPros)
- // // {
- // // if (itempro.PropertyType.IsSubclassOf(typeof(TopBaseModel)))
- // // {
- // // itempro.SetValue(newitem, null);
- // // }
- // // if (!string.IsNullOrEmpty(fkname))
- // // {
- // // if (itempro.Name.ToLower() == fkname.ToLower())
- // // {
- // // itempro.SetValue(newitem, Entity.GetID());
- // // found = true;
- // // }
- // // }
- // // }
- // // }
- // // //如果没有找到相应的外建字段,则可能是多对多的关系,或者做了特殊的设定,这种情况框架无法支持,直接退出本次循环
- // // if (found == false)
- // // {
- // // continue;
- // // }
-
-
- // // TModel _entity = null;
- // // //打开新的数据库联接,获取数据库中的主表和子表数据
- // // using (var ndc = DC.CreateNew())
- // // {
- // // _entity = ndc.Set().Include(pro.Name).AsNoTracking().CheckID(Entity.GetID()).FirstOrDefault();
- // // }
- // // //比较子表原数据和新数据的区别
- // // IEnumerable toadd = null;
- // // IEnumerable toremove = null;
- // // IEnumerable data = _entity.GetType().GetSingleProperty(pro.Name).GetValue(_entity) as IEnumerable;
- // // Utils.CheckDifference(data, list, out toremove, out toadd);
- // // //设定子表应该更新的字段
- // // //List setnames = new List();
- // // //foreach (var field in FC.Keys)
- // // //{
- // // // if (field.StartsWith("Entity." + pro.Name + "[0]."))
- // // // {
- // // // string name = field.Replace("Entity." + pro.Name + "[0].", "");
- // // // setnames.Add(name);
- // // // }
- // // //}
-
- // // //前台传过来的数据
- // // //foreach (var newitem in list)
- // // //{
- // // // //数据库中的数据
- // // // foreach (var item in data)
- // // // {
- // // // //需要更新的数据
- // // // if (newitem.GetID().ToString() == item.GetID().ToString())
- // // // {
- // // // dynamic i = newitem;
- // // // var newitemType = item.GetType();
- // // // foreach (var itempro in itemPros)
- // // // {
- // // // if (!itempro.PropertyType.IsSubclassOf(typeof(TopBaseModel)) && (updateAllFields == true || setnames.Contains(itempro.Name)))
- // // // {
- // // // var notmapped = itempro.GetCustomAttribute();
- // // // if (itempro.Name != "ID" && notmapped == null && itempro.PropertyType.IsList() == false)
- // // // {
- // // // DC.UpdateProperty(i, itempro.Name);
- // // // }
- // // // }
- // // // }
- // // // if (item.GetType().IsSubclassOf(typeof(BaseModel)))
- // // // {
- // // // DC.UpdateProperty(i, "UpdateTime");
- // // // DC.UpdateProperty(i, "UpdateBy");
- // // // }
- // // // }
- // // // }
- // // //}
- // // //需要删除的数据
- // // foreach (var item in toremove)
- // // {
- // // //如果是PersistPoco,则把IsValid设为false,并不进行物理删除
- // // if (ftype.IsSubclassOf(typeof(PersistModel)))
- // // {
- // // (item as PersistModel).IsValid = false;
- // // (item as PersistModel).UpdateTime = DateTime.Now;
- // // (item as PersistModel).UpdateBy = loginUserInfo?.ITCode;
- // // dynamic i = item;
- // // DC.UpdateEntity(i);
- // // }
- // // else
- // // {
- // // foreach (var itempro in itemPros)
- // // {
- // // if (itempro.PropertyType.IsSubclassOf(typeof(TopBaseModel)))
- // // {
- // // itempro.SetValue(item, null);
- // // }
- // // }
- // // dynamic i = item;
- // // DC.DeleteEntity(i);
- // // }
- // // }
- // // //需要添加的数据
- // // foreach (var item in toadd)
- // // {
- // // if (item.GetType().IsSubclassOf(typeof(BaseModel)))
- // // {
- // // BaseModel ent = item as BaseModel;
- // // if (ent.CreateTime == null)
- // // {
- // // ent.CreateTime = DateTime.Now;
- // // }
- // // if (string.IsNullOrEmpty(ent.CreateBy))
- // // {
- // // ent.CreateBy = loginUserInfo?.ITCode;
- // // }
- // // }
- // // DC.AddEntity(item);
- // // }
- // // }
- // // //else if (FC.Keys.Contains("Entity." + pro.Name + ".DONOTUSECLEAR") || (FC.ContainsKey("Entity." + pro.Name) && pro.GetValue(Entity) is IEnumerable list2 && list2?.Count() == 0))
- // // //{
- // // // PropertyInfo[] itemPros = ftype.GetProperties();
- // // // var _entity = DC.Set().Include(pro.Name).AsNoTracking().CheckID(Entity.GetID()).FirstOrDefault();
- // // // if (_entity != null)
- // // // {
- // // // IEnumerable removeData = _entity.GetType().GetSingleProperty(pro.Name).GetValue(_entity) as IEnumerable;
- // // // //如果是PersistPoco,则把IsValid设为false,并不进行物理删除
- // // // if (removeData is IEnumerable removePersistPocoData)
- // // // {
- // // // foreach (var item in removePersistPocoData)
- // // // {
- // // // (item as PersistPoco).IsValid = false;
- // // // (item as PersistPoco).UpdateTime = DateTime.Now;
- // // // (item as PersistPoco).UpdateBy = LoginUserInfo?.ITCode;
- // // // dynamic i = item;
- // // // DC.UpdateEntity(i);
- // // // }
- // // // }
- // // // else
- // // // {
- // // // foreach (var item in removeData)
- // // // {
- // // // foreach (var itempro in itemPros)
- // // // {
- // // // if (itempro.PropertyType.IsSubclassOf(typeof(TopBaseModel)))
- // // // {
- // // // itempro.SetValue(item, null);
- // // // }
- // // // }
- // // // dynamic i = item;
- // // // DC.DeleteEntity(i);
- // // // }
- // // // }
-
- // // // }
- // // //}
- // // }
- // // }
- // // }
- // // #endregion
-
-
- // // if (updateAllFields == false)
- // // {
- // // //foreach (var field in FC.Keys)
- // // //{
- // // // if (field.StartsWith("Entity.") && !field.Contains("["))
- // // // {
- // // // string name = field.Replace("Entity.", "");
- // // // try
- // // // {
- // // // DC.UpdateProperty(Entity, name);
- // // // }
- // // // catch (Exception ea)
- // // // {
- // // // }
- // // // }
- // // //}
- // // if (typeof(TModel).GetTypeInfo().IsSubclassOf(typeof(BaseModel)))
- // // {
- // // try
- // // {
- // // DC.UpdateProperty(Entity, "UpdateTime");
- // // DC.UpdateProperty(Entity, "UpdateBy");
- // // }
- // // catch (Exception)
- // // {
- // // }
- // // }
- // // }
- // // else
- // // {
- // // DC.UpdateEntity(Entity);
- // // }
- // //}
- // ///
- // /// 物理删除
- // ///
- // //public virtual void DoRealDelete()
- // //{
- // // try
- // // {
- // // List fileids = new List();
- // // var pros = typeof(TModel).GetProperties();
-
- // // //如果包含附件,则先删除附件
- // // var fa = pros.Where(x => x.PropertyType == typeof(FileAttachment) || typeof(TopBaseModel).IsAssignableFrom(x.PropertyType)).ToList();
- // // foreach (var f in fa)
- // // {
- // // if (f.GetValue(Entity) is FileAttachment file)
- // // {
- // // fileids.Add(new Guid(file.ID));
- // // }
- // // f.SetValue(Entity, null);
- // // }
-
- // // var fas = pros.Where(x => typeof(IEnumerable).IsAssignableFrom(x.PropertyType)).ToList();
- // // foreach (var f in fas)
- // // {
- // // var subs = f.GetValue(Entity) as IEnumerable;
- // // if (subs != null)
- // // {
- // // foreach (var sub in subs)
- // // {
- // // fileids.Add(sub.FileId);
- // // }
- // // f.SetValue(Entity, null);
- // // }
- // // }
- // // if (typeof(TModel) != typeof(FileAttachment))
- // // {
- // // foreach (var pro in pros)
- // // {
- // // if (pro.PropertyType.GetTypeInfo().IsSubclassOf(typeof(TopBaseModel)))
- // // {
- // // pro.SetValue(Entity, null);
- // // }
- // // }
- // // }
- // // DC.DeleteEntity(Entity);
- // // DC.SaveChanges();
- // // foreach (var item in fileids)
- // // {
- // // FileAttachmentVM ofa = new FileAttachmentVM();
- // // ofa.CopyVM(this);
- // // ofa.SetEntityById(item);
- // // ofa.DoDelete();
- // // }
- // // }
- // // catch (Exception)
- // // {
- // // //MSD.AddModelError("", Program._localizer["DeleteFailed"]);
- // // }
- // //}
- // ///
- // /// 异步物理删除
- // ///
- // ///
- // //public virtual async Task DoRealDeleteAsync()
- // //{
- // // try
- // // {
- // // List fileids = new List();
- // // var pros = typeof(TModel).GetProperties();
-
- // // //如果包含附件,则先删除附件
- // // var fa = pros.Where(x => x.PropertyType == typeof(FileAttachment) || typeof(TopBaseModel).IsAssignableFrom(x.PropertyType)).ToList();
- // // foreach (var f in fa)
- // // {
- // // if (f.GetValue(Entity) is FileAttachment file)
- // // {
- // // fileids.Add(new Guid(file.ID));
- // // }
- // // f.SetValue(Entity, null);
- // // }
-
- // // var fas = pros.Where(x => typeof(IEnumerable).IsAssignableFrom(x.PropertyType)).ToList();
- // // foreach (var f in fas)
- // // {
- // // var subs = f.GetValue(Entity) as IEnumerable;
- // // foreach (var sub in subs)
- // // {
- // // fileids.Add(sub.FileId);
- // // }
- // // f.SetValue(Entity, null);
- // // }
- // // if (typeof(TModel) != typeof(FileAttachment))
- // // {
- // // foreach (var pro in pros)
- // // {
- // // if (pro.PropertyType.GetTypeInfo().IsSubclassOf(typeof(TopBaseModel)))
- // // {
- // // pro.SetValue(Entity, null);
- // // }
- // // }
- // // }
- // // DC.DeleteEntity(Entity);
- // // await DC.SaveChangesAsync();
- // // foreach (var item in fileids)
- // // {
- // // FileAttachmentVM ofa = new FileAttachmentVM();
- // // ofa.CopyVM(this);
- // // ofa.SetEntityById(item);
- // // await ofa.DoDeleteAsync();
- // // }
- // // }
- // // catch (Exception e)
- // // {
- // // //MSD.AddModelError("", Program._localizer["DeleteFailed"]);
- // // }
- // //}
-
- // ///
- // /// 设置当前VM的数据模型
- // ///
- // ///
- // public void SetEntity(object entity)
- // {
- // this.Entity = entity as TModel;
- // }
-
- // ///
- // /// 通过ID设置当前VM的数据模型
- // ///
- // ///
- // //public void SetEntityById(object id)
- // //{
- // // this.Entity = GetById(id);
- // //}
-
- // ///
- // /// 验证数据,默认验证重复数据。子类如需要其他自定义验证,则重载这个函数
- // ///
- // /// 验证结果
- // //public virtual void Validate()
- // //{
- // // ValidateDuplicateData();
- // //}
-
- // ///
- // /// 根据主键获取Entity
- // ///
- // /// 主键Id
- // /// Entity
- // //protected virtual TModel GetById(object Id)
- // //{
- // // TModel rv = null;
- // // //建立基础查询
- // // var query = DC.Set().AsQueryable();
- // // //循环添加其他设定的Include
- // // if (_toInclude != null)
- // // {
- // // foreach (var item in _toInclude)
- // // {
- // // query = query.Include(item);
- // // }
- // // }
- // // if (typeof(TModel).IsSubclassOf(typeof(PersistModel)))
- // // {
- // // var mod = new IsValidModifier();
- // // var newExp = mod.Modify(query.Expression);
- // // query = query.Provider.CreateQuery(newExp) as IOrderedQueryable;
- // // }
-
- // // //获取数据
- // // rv = query.CheckID(Id).AsNoTracking().SingleOrDefault();
- // // if (rv == null)
- // // {
- // // throw new Exception("数据不存在");
- // // }
- // // //如果TopBaseModel有关联的附件,则自动Include 附件名称
- // // var fa = typeof(TModel).GetProperties().Where(x => x.PropertyType == typeof(FileAttachment)).ToList();
- // // foreach (var f in fa)
- // // {
- // // var fname = DC.GetFKName2(f.Name);
- // // var fid = typeof(TModel).GetSingleProperty(fname).GetValue(rv) as Guid?;
- // // var file = DC.Set().Where(x => x.ID == fid.ToString()).Select(x => new FileAttachment
- // // {
- // // ID = x.ID,
- // // CreateBy = x.CreateBy,
- // // CreateTime = x.CreateTime,
- // // UpdateBy = x.UpdateBy,
- // // UpdateTime = x.UpdateTime,
- // // UploadTime = x.UploadTime,
- // // FileExt = x.FileExt,
- // // FileName = x.FileName,
- // // Length = x.Length,
- // // GroupName = x.GroupName,
- // // IsTemprory = x.IsTemprory,
- // // Path = x.Path,
- // // SaveFileMode = x.SaveFileMode
- // // }).FirstOrDefault();
- // // rv.SetPropertyValue(f.Name, file);
- // // }
-
- // // return rv;
- // //}
-
- // ///
- // /// 创建重复数据信息
- // ///
- // /// 重复数据信息
- // /// 重复数据信息
- // protected DuplicatedInfo CreateFieldsInfo(params DuplicatedField[] FieldExps)
- // {
- // DuplicatedInfo d = new DuplicatedInfo();
- // d.AddGroup(FieldExps);
- // return d;
- // }
-
- // ///
- // /// 创建一个简单重复数据信息
- // ///
- // /// 重复数据的字段
- // /// 重复数据信息
- // public static DuplicatedField SimpleField(Expression> FieldExp)
- // {
- // return new DuplicatedField(FieldExp);
- // }
-
- // ///
- // /// 创建一个关联到其他表数组中数据的重复信息
- // ///
- // /// 关联表类
- // /// 指向关联表类数组的Lambda
- // /// 指向最终字段的Lambda
- // /// 重复数据信息
- // public static DuplicatedField SubField(Expression>> MiddleExp, params Expression>[] FieldExps)
- // {
- // return new ComplexDuplicatedField(MiddleExp, FieldExps);
- // }
-
- // ///
- // /// 验证重复数据
- // ///
- // //protected void ValidateDuplicateData()
- // //{
- // // //获取设定的重复字段信息
- // // var checkCondition = SetDuplicatedCheck();
- // // if (checkCondition != null && checkCondition.Groups.Count > 0)
- // // {
- // // //生成基础Query
- // // var baseExp = DC.Set().AsQueryable();
- // // var modelType = typeof(TModel);
- // // ParameterExpression para = Expression.Parameter(modelType, "tm");
- // // //循环所有重复字段组
- // // foreach (var group in checkCondition.Groups)
- // // {
- // // List conditions = new List();
- // // //生成一个表达式,类似于 x=>x.Id != id,这是为了当修改数据时验证重复性的时候,排除当前正在修改的数据
- // // var idproperty = typeof(TModel).GetProperties().Where(x => x.Name.ToLower() == "id").FirstOrDefault();
- // // MemberExpression idLeft = Expression.Property(para, idproperty);
- // // ConstantExpression idRight = Expression.Constant(Entity.GetID());
- // // BinaryExpression idNotEqual = Expression.NotEqual(idLeft, idRight);
- // // conditions.Add(idNotEqual);
- // // List props = new List();
- // // //在每个组中循环所有字段
- // // foreach (var field in group.Fields)
- // // {
- // // Expression exp = field.GetExpression(Entity, para);
- // // if (exp != null)
- // // {
- // // conditions.Add(exp);
- // // }
- // // //将字段名保存,为后面生成错误信息作准备
- // // props.AddRange(field.GetProperties());
- // // }
- // // //如果要求判断id不重复,则去掉id不相等的判断,加入id相等的判断
- // // if (props.Any(x => x.Name.ToLower() == "id"))
- // // {
- // // conditions.RemoveAt(0);
- // // BinaryExpression idEqual = Expression.Equal(idLeft, idRight);
- // // conditions.Insert(0, idEqual);
- // // }
- // // int count = 0;
- // // if (conditions.Count > 1)
- // // {
- // // //循环添加条件并生成Where语句
- // // Expression conExp = conditions[0];
- // // for (int i = 1; i < conditions.Count; i++)
- // // {
- // // conExp = Expression.And(conExp, conditions[i]);
- // // }
-
- // // MethodCallExpression whereCallExpression = Expression.Call(
- // // typeof(Queryable),
- // // "Where",
- // // new Type[] { modelType },
- // // baseExp.Expression,
- // // Expression.Lambda>(conExp, new ParameterExpression[] { para }));
- // // var result = baseExp.Provider.CreateQuery(whereCallExpression);
-
- // // foreach (var res in result)
- // // {
- // // count++;
- // // }
- // // }
- // // if (count > 0)
- // // {
- // // //循环拼接所有字段名
- // // string AllName = "";
- // // foreach (var prop in props)
- // // {
- // // string name = PropertyHelper.GetPropertyDisplayName(prop);
- // // AllName += name + ",";
- // // }
- // // if (AllName.EndsWith(","))
- // // {
- // // AllName = AllName.Remove(AllName.Length - 1);
- // // }
- // // //如果只有一个字段重复,则拼接形成 xxx字段重复 这种提示
- // // if (props.Count == 1)
- // // {
- // // //MSD.AddModelError(GetValidationFieldName(props[0])[0], Program._localizer["DuplicateError", AllName]);
- // // }
- // // //如果多个字段重复,则拼接形成 xx,yy,zz组合字段重复 这种提示
- // // else if (props.Count > 1)
- // // {
- // // //MSD.AddModelError(GetValidationFieldName(props.First())[0], Program._localizer["DuplicateGroupError", AllName]);
- // // }
- // // }
- // // }
- // // }
- // //}
-
- // ///
- // /// 根据属性信息获取验证字段名
- // ///
- // /// 属性信息
- // /// 验证字段名称数组,用于ValidationResult
- // private string[] GetValidationFieldName(PropertyInfo pi)
- // {
- // return new[] { "Entity." + pi.Name };
- // }
-
- // #region 基础命令
- // ///
- // /// 保存命令(需重写)
- // ///
- // public virtual RelayCommand SaveCommand => new RelayCommand(() =>
- // {
-
- // });
-
-
- // #endregion
-
- // ///
- // /// BaseCRUDVM中的数据初始化,生命周期落后于InitData()
- // ///
- // protected virtual void BaseCRUDInit()
- // {
-
- // }
- //}
-}
diff --git a/Vampirewal.Core/SimpleMVVM/BaseListVM.cs b/Vampirewal.Core/SimpleMVVM/BaseListVM.cs
deleted file mode 100644
index a82a0bd..0000000
--- a/Vampirewal.Core/SimpleMVVM/BaseListVM.cs
+++ /dev/null
@@ -1,1150 +0,0 @@
-//#region << 文 件 说 明 >>
-///*----------------------------------------------------------------
-//// 文件名称:BaseListVM
-//// 创 建 者:杨程
-//// 创建时间:2021/9/16 13:32:07
-//// 文件版本:V1.0.0
-//// ===============================================================
-//// 功能描述:
-////
-////
-////----------------------------------------------------------------*/
-//#endregion
-
-//using System;
-//using System.Collections.Generic;
-//using System.ComponentModel.DataAnnotations.Schema;
-//using System.Data.Common;
-//using System.Data;
-//using System.IO;
-//using System.Linq;
-//using System.Linq.Expressions;
-//using System.Reflection;
-//using System.Text;
-//using System.Text.RegularExpressions;
-//using System.Threading.Tasks;
-//using NPOI.HSSF.Util;
-//using NPOI.SS.UserModel;
-//using NPOI.SS.Util;
-//using NPOI.XSSF.UserModel;
-//using Vampirewal.Core.Extensions;
-//using Vampirewal.Core.Helper;
-//using Vampirewal.Core.Interface;
-//using Vampirewal.Core.Models;
-//using System.Text.Json.Serialization;
-
-//namespace Vampirewal.Core.SimpleMVVM
-//{
-// ///
-// /// ListVM的基类,所有ListVM应该继承这个类, 基类提供了搜索,导出等列表常用功能
-// ///
-// /// ListVM中的Model类
-// /// ListVM使用的Searcher类
-// public class BaseListVM : ViewModelBase, IBaseListVM
-// where TModel : TopBaseModel
-// where TSearcher : BaseSearcher
-// {
-// [JsonIgnore]
-// public string TotalText { get; set; }
-
-// public virtual DbCommand GetSearchCommand()
-// {
-// return null;
-// }
-
-
-
-// #region GenerateExcel
-
-
-
-// ///
-// /// 根据集合生成单个Excel
-// ///
-// ///
-// ///
-// //private IWorkbook GenerateWorkBook(List List)
-// //{
-// // IWorkbook book = new XSSFWorkbook();
-// // ISheet sheet = book.CreateSheet();
-// // IRow row = sheet.CreateRow(0);
-
-// // //创建表头样式
-// // ICellStyle headerStyle = book.CreateCellStyle();
-// // headerStyle.FillBackgroundColor = ExportTitleBackColor == null ? HSSFColor.LightBlue.Index : ExportTitleBackColor.Value;
-// // headerStyle.FillPattern = FillPattern.SolidForeground;
-// // headerStyle.FillForegroundColor = ExportTitleBackColor == null ? HSSFColor.LightBlue.Index : ExportTitleBackColor.Value;
-// // headerStyle.BorderBottom = BorderStyle.Thin;
-// // headerStyle.BorderTop = BorderStyle.Thin;
-// // headerStyle.BorderLeft = BorderStyle.Thin;
-// // headerStyle.BorderRight = BorderStyle.Thin;
-// // IFont font = book.CreateFont();
-// // font.FontName = "Calibri";
-// // font.FontHeightInPoints = 12;
-// // font.Color = ExportTitleFontColor == null ? HSSFColor.Black.Index : ExportTitleFontColor.Value;
-// // headerStyle.SetFont(font);
-
-// // ICellStyle cellStyle = book.CreateCellStyle();
-// // cellStyle.BorderBottom = BorderStyle.Thin;
-// // cellStyle.BorderTop = BorderStyle.Thin;
-// // cellStyle.BorderLeft = BorderStyle.Thin;
-// // cellStyle.BorderRight = BorderStyle.Thin;
-
-// // //生成表头
-// // int max = MakeExcelHeader(sheet, GridHeaders, 0, 0, headerStyle);
-
-// // //放入数据
-// // var ColIndex = 0;
-// // for (int i = 0; i < List.Count; i++)
-// // {
-// // ColIndex = 0;
-// // var DR = sheet.CreateRow(i + max);
-// // foreach (var baseCol in GridHeaders)
-// // {
-
-// // foreach (var col in baseCol.BottomChildren)
-// // {
-// // //处理枚举变量的多语言
-// // bool IsEmunBoolParp = false;
-// // var proType = col.FieldType;
-// // if (proType.IsEnumOrNullableEnum())
-// // {
-// // IsEmunBoolParp = true;
-// // }
-// // //获取数据,并过滤特殊字符
-// // string text = Regex.Replace(col.GetText(List[i]).ToString(), @"<[^>]*>", String.Empty);
-
-// // //处理枚举变量的多语言
-// // if (IsEmunBoolParp)
-// // {
-// // if (int.TryParse(text, out int enumvalue))
-// // {
-// // text = PropertyHelper.GetEnumDisplayName(proType, enumvalue);
-// // }
-// // }
-
-// // //建立excel单元格
-// // ICell cell;
-// // if (col.FieldType?.IsNumber() == true)
-// // {
-// // cell = DR.CreateCell(ColIndex, CellType.Numeric);
-// // try
-// // {
-// // cell.SetCellValue(Convert.ToDouble(text));
-// // }
-// // catch { }
-// // }
-// // else
-// // {
-// // cell = DR.CreateCell(ColIndex);
-// // cell.SetCellValue(text);
-// // }
-// // cell.CellStyle = cellStyle;
-// // ColIndex++;
-// // }
-// // }
-// // }
-// // return book;
-// //}
-
-// //private byte[] DownLoadExcel()
-// //{
-// // var book = GenerateWorkBook(EntityList);
-// // byte[] rv = new byte[] { };
-// // using (MemoryStream ms = new MemoryStream())
-// // {
-// // book.Write(ms);
-// // rv = ms.ToArray();
-// // }
-// // return rv;
-// //}
-
-// //private byte[] DownLoadZipPackage(string FileName)
-// //{
-// // //文件根目录
-// // string RootPath = $"{GlobalServices.GetRequiredService().WebRootPath}\\{FileName}";
-
-// // //文件夹目录
-// // string FilePath = $"{RootPath}//FileFolder";
-
-// // //压缩包目录
-// // string ZipPath = $"{RootPath}//{FileName}.zip";
-
-// // //打开文件夹
-// // DirectoryInfo FileFolder = new DirectoryInfo(FilePath);
-// // if (!FileFolder.Exists)
-// // {
-// // //创建文件夹
-// // FileFolder.Create();
-// // }
-// // else
-// // {
-// // //清空文件夹
-// // FileSystemInfo[] Files = FileFolder.GetFileSystemInfos();
-// // foreach (var item in Files)
-// // {
-// // if (item is DirectoryInfo)
-// // {
-// // DirectoryInfo Directory = new DirectoryInfo(item.FullName);
-// // Directory.Delete(true);
-// // }
-// // else
-// // {
-// // File.Delete(item.FullName);
-// // }
-// // }
-// // }
-
-// // //放入数据
-// // for (int i = 0; i < ExportExcelCount; i++)
-// // {
-// // var List = EntityList.Skip(i * ExportMaxCount).Take(ExportMaxCount).ToList();
-// // var WorkBook = GenerateWorkBook(List);
-// // string SavePath = $"{FilePath}/{FileName}_{i + 1}.xlsx";
-// // using (FileStream FS = new FileStream(SavePath, FileMode.CreateNew))
-// // {
-// // WorkBook.Write(FS);
-// // }
-// // }
-
-// // //生成压缩包
-// // ZipFile.CreateFromDirectory(FilePath, ZipPath);
-
-// // //读取压缩包
-// // FileStream ZipFS = new FileStream(ZipPath, FileMode.Open, FileAccess.Read);
-// // byte[] bt = new byte[ZipFS.Length];
-// // ZipFS.Read(bt, 0, bt.Length);
-// // ZipFS.Close();
-
-// // //删除根目录文件夹
-// // DirectoryInfo RootFolder = new DirectoryInfo(RootPath);
-// // if (RootFolder.Exists)
-// // {
-// // RootFolder.Delete(true);
-// // }
-
-// // return bt;
-// //}
-
-// ///
-// /// 生成Excel的表头
-// ///
-// ///
-// ///
-// ///
-// ///
-// ///
-// ///
-// //private int MakeExcelHeader(ISheet sheet, IEnumerable> cols, int rowIndex, int colIndex, ICellStyle style)
-// //{
-// // var row = sheet.GetRow(rowIndex);
-// // if (row == null)
-// // {
-// // row = sheet.CreateRow(rowIndex);
-// // }
-// // int maxLevel = cols.Select(x => x.MaxLevel).Max();
-// // //循环所有列
-// // foreach (var col in cols)
-// // {
-// // //添加新单元格
-// // var cell = row.CreateCell(colIndex);
-// // cell.CellStyle = style;
-// // cell.SetCellValue(col.Title);
-// // var bcount = col.BottomChildren.Count();
-// // var rowspan = 0;
-// // if (rowIndex >= 0)
-// // {
-// // rowspan = maxLevel - col.MaxLevel;
-// // }
-// // var cellRangeAddress = new CellRangeAddress(rowIndex, rowIndex + rowspan, colIndex, colIndex + bcount - 1);
-// // sheet.AddMergedRegion(cellRangeAddress);
-// // if (rowspan > 0 || bcount > 1)
-// // {
-// // cell.CellStyle.Alignment = HorizontalAlignment.Center;
-// // cell.CellStyle.VerticalAlignment = VerticalAlignment.Center;
-// // }
-// // for (int i = cellRangeAddress.FirstRow; i <= cellRangeAddress.LastRow; i++)
-// // {
-// // IRow r = CellUtil.GetRow(i, sheet);
-// // for (int j = cellRangeAddress.FirstColumn; j <= cellRangeAddress.LastColumn; j++)
-// // {
-// // ICell c = CellUtil.GetCell(r, (short)j);
-// // c.CellStyle = style;
-// // }
-// // }
-// // if (col.Children != null && col.Children.Count() > 0)
-// // {
-// // MakeExcelHeader(sheet, col.Children, rowIndex + rowspan + 1, colIndex, style);
-// // }
-// // colIndex += bcount;
-// // }
-// // return maxLevel;
-// //}
-
-// #endregion
-
-// #region Old
-// public SortInfo CreateSortInfo(Expression> pro, SortDir dir)
-// {
-// SortInfo rv = new SortInfo
-// {
-// Property = PropertyHelper.GetPropertyName(pro),
-// Direction = dir
-// };
-// return rv;
-// }
-
-// ///
-// /// InitList后触发的事件
-// ///
-// public event Action> OnAfterInitList;
-
-// ///
-// ///记录批量操作时列表中选择的Id
-// ///
-// public List Ids { get; set; }
-
-// ///
-// /// 每页行数
-// ///
-// [Obsolete("弃用,改用 DataTableHelper上的Limit")]
-// public int RecordsPerPage { get; set; }
-
-// ///
-// /// 是否已经搜索过
-// ///
-// [JsonIgnore]
-// public bool IsSearched { get; set; }
-
-// [JsonIgnore]
-// public bool PassSearch { get; set; }
-// ///
-// /// 查询模式
-// ///
-// [JsonIgnore]
-// public ListVMSearchModeEnum SearcherMode { get; set; }
-
-// ///
-// /// 是否需要分页
-// ///
-// [JsonIgnore]
-// public bool NeedPage { get; set; }
-
-// ///
-// /// 允许导出Excel的最大行数,超过行数会分成多个文件,最多不能超过100万
-// ///
-// [JsonIgnore]
-// public int ExportMaxCount { get; set; }
-
-// ///
-// /// 根据允许导出的Excel最大行数,算出最终导出的Excel个数
-// ///
-// [JsonIgnore]
-// public int ExportExcelCount { get; set; }
-
-// ///
-// /// 导出文件第一行背景颜色,使用HSSFColor,例如:HSSFColor.Red.Index
-// ///
-// [JsonIgnore]
-// public short? ExportTitleBackColor { get; set; }
-
-// ///
-// /// 导出文件第一行文字颜色,使用HSSFColor,例如:HSSFColor.Red.Index
-// ///
-// [JsonIgnore]
-// public short? ExportTitleFontColor { get; set; }
-
-// private List _EntityList;
-// ///
-// /// 数据列表
-// ///
-// [JsonIgnore]
-// public List EntityList
-// {
-// get
-// {
-// return _EntityList;
-// }
-// set
-// {
-// _EntityList = value;
-// DoNotify();
-// }
-// }
-
-
-// ///
-// /// 搜索条件
-// ///
-// [JsonIgnore]
-// public TSearcher Searcher { get; set; }
-
-// ///
-// /// 使用 VM 的 Id 来生成 SearcherDiv 的 Id
-// ///
-// [JsonIgnore]
-// public string SearcherDivId
-// {
-// get { return Guid.NewGuid().ToString() + "Searcher"; }
-// }
-
-
-// ///
-// /// 替换查询条件,如果被赋值,则列表会使用里面的Lambda来替换原有Query里面的Where条件
-// ///
-// [JsonIgnore()]
-// public Expression> ReplaceWhere { get; set; }
-
-// ///
-// /// 构造函数
-// ///
-// public BaseListVM()
-// {
-// //默认需要分页
-// NeedPage = true;
-// //初始化数据列表
-// EntityList = new List();
-// //初始化搜索条件
-// Searcher = typeof(TSearcher).GetConstructor(Type.EmptyTypes).Invoke(null) as TSearcher;
-// }
-
-// ///
-// /// 获取数据列表
-// ///
-// /// 数据列表
-// public IEnumerable GetEntityList()
-// {
-// if (IsSearched == false && (EntityList == null || EntityList.Count == 0))
-// {
-// DoSearch();
-// }
-// return EntityList?.AsEnumerable();
-// }
-
-
-// ///
-// /// 调用InitListVM并触发OnAfterInitList事件
-// ///
-// public void DoInitListVM()
-// {
-// InitListVM();
-// OnAfterInitList?.Invoke(this);
-// }
-
-
-// ///
-// /// 初始化ListVM,继承的类应该重载这个函数来设定数据的列和动作
-// ///
-// protected virtual void InitListVM()
-// {
-
-// }
-
-// public virtual bool GetIsSelected(object item)
-// {
-// return false;
-// }
-
-// public void Validate()
-// {
-// Searcher?.Validate();
-// //base.Validate();
-// }
-
-// ///
-// /// 设定行前景色,继承的类应重载这个函数来根据每行的数据显示不同的前景色
-// ///
-// /// 数据
-// /// 前景颜色
-// public virtual string SetFullRowColor(object entity)
-// {
-// return "";
-// }
-
-// ///
-// /// 设定行背景色,继承的类应重载这个函数来根据每行的数据显示不同的背景色
-// ///
-// /// 数据
-// /// 背景颜色
-// public virtual string SetFullRowBgColor(object entity)
-// {
-// return "";
-// }
-
-// ///
-// /// 设定搜索语句,继承的类应该重载这个函数来指定自己的搜索语句
-// ///
-// /// 搜索语句
-// public virtual IOrderedQueryable GetSearchQuery()
-// {
-// return DC.Set().OrderByDescending(x => x.ID);
-// }
-
-// ///
-// /// 设定导出时搜索语句,继承的类应该重载这个函数来指定自己导出时的搜索语句,如不指定则默认和搜索用的搜索语句相同
-// ///
-// /// 搜索语句
-// public virtual IOrderedQueryable GetExportQuery()
-// {
-// return GetSearchQuery();
-// }
-
-// ///
-// /// 设定搜索语句,继承的类应该重载这个函数来指定自己导出时的搜索语句,如不指定则默认和搜索用的搜索语句相同
-// ///
-// /// 搜索语句
-// public virtual IOrderedQueryable GetSelectorQuery()
-// {
-// return GetSearchQuery();
-// }
-
-// ///
-// /// 设定勾选后导出的搜索语句,继承的类应该重载这个函数来指定自己导出时的搜索语句,如不指定则默认和搜索用的搜索语句相同
-// ///
-// /// 搜索语句
-// public virtual IOrderedQueryable GetCheckedExportQuery()
-// {
-// var baseQuery = GetBatchQuery();
-// return baseQuery;
-// }
-
-// ///
-// /// 设定批量模式下的搜索语句,继承的类应重载这个函数来指定自己批量模式的搜索语句,如果不指定则默认使用Ids.Contains(x.Id)来代替搜索语句中的Where条件
-// ///
-// /// 搜索语句
-// public virtual IOrderedQueryable GetBatchQuery()
-// {
-// var baseQuery = GetSearchQuery();
-// if (ReplaceWhere == null)
-// {
-// var mod = new WhereReplaceModifier(Ids.GetContainIdExpression());
-// var newExp = mod.Modify(baseQuery.Expression);
-// var newQuery = baseQuery.Provider.CreateQuery(newExp) as IOrderedQueryable;
-// return newQuery;
-// }
-// else
-// {
-// return baseQuery;
-// }
-// }
-
-// ///
-// /// 设定主从模式的搜索语句,继承的类应该重载这个函数来指定自己主从模式的搜索语句,如不指定则默认和搜索用的搜索语句相同
-// ///
-// /// 搜索语句
-// public virtual IOrderedQueryable GetMasterDetailsQuery()
-// {
-// return GetSearchQuery();
-// }
-
-// ///
-// /// 进行搜索
-// ///
-// public virtual void DoSearch()
-// {
-// var cmd = GetSearchCommand();
-// if (cmd == null)
-// {
-// IOrderedQueryable query = null;
-// //根据搜索模式调用不同的函数
-// switch (SearcherMode)
-// {
-// case ListVMSearchModeEnum.Search:
-// query = GetSearchQuery();
-// break;
-// case ListVMSearchModeEnum.Export:
-// query = GetExportQuery();
-// break;
-// case ListVMSearchModeEnum.Batch:
-// query = GetBatchQuery();
-// break;
-// case ListVMSearchModeEnum.MasterDetail:
-// query = GetMasterDetailsQuery();
-// break;
-// case ListVMSearchModeEnum.CheckExport:
-// query = GetCheckedExportQuery();
-// break;
-// case ListVMSearchModeEnum.Selector:
-// query = GetSelectorQuery();
-// break;
-// default:
-// query = GetSearchQuery();
-// break;
-// }
-
-// //如果设定了替换条件,则使用替换条件替换Query中的Where语句
-// if (ReplaceWhere != null)
-// {
-// var mod = new WhereReplaceModifier(ReplaceWhere);
-// var newExp = mod.Modify(query.Expression);
-// query = query.Provider.CreateQuery(newExp) as IOrderedQueryable;
-// }
-// if (Searcher.SortInfo != null)
-// {
-// var mod = new OrderReplaceModifier(Searcher.SortInfo);
-// var newExp = mod.Modify(query.Expression);
-// query = query.Provider.CreateQuery(newExp) as IOrderedQueryable;
-// }
-// if (typeof(TModel).IsSubclassOf(typeof(PersistModel)))
-// {
-// var mod = new IsValidModifier();
-// var newExp = mod.Modify(query.Expression);
-// query = query.Provider.CreateQuery(newExp) as IOrderedQueryable;
-// }
-// if (PassSearch == false)
-// {
-// //如果需要分页,则添加分页语句
-// if (NeedPage && Searcher.Limit != -1)
-// {
-// //获取返回数据的数量
-// var count = query.Count();
-// if (count < 0)
-// {
-// count = 0;
-// }
-// if (Searcher.Limit == 0)
-// {
-// //TODO 暂时没有配置文件来进行获取,进行动态设置
-// //Searcher.Limit = ConfigInfo?.UiOptions.DataTable.RPP ?? 20;
-// Searcher.Limit = 20;
-// }
-// //根据返回数据的数量,以及预先设定的每页行数来设定数据量和总页数
-// Searcher.Count = count;
-// Searcher.PageCount = (int)Math.Ceiling((1.0 * Searcher.Count / Searcher.Limit));
-// if (Searcher.Page <= 0)
-// {
-// Searcher.Page = 1;
-// }
-// if (Searcher.PageCount > 0 && Searcher.Page > Searcher.PageCount)
-// {
-// Searcher.Page = Searcher.PageCount;
-// }
-// EntityList = query.Skip((Searcher.Page - 1) * Searcher.Limit).Take(Searcher.Limit).AsNoTracking().ToList();
-// }
-// else //如果不需要分页则直接获取数据
-// {
-// EntityList = query.AsNoTracking().ToList();
-// Searcher.Count = EntityList.Count();
-// Searcher.Limit = EntityList.Count();
-// Searcher.PageCount = 1;
-// Searcher.Page = 1;
-// }
-// }
-// else
-// {
-// EntityList = query.AsNoTracking().ToList();
-// }
-// }
-// else
-// {
-// ProcessCommand(cmd);
-// }
-// IsSearched = true;
-// //调用AfterDoSearch函数来处理自定义的后续操作
-// AfterDoSearcher();
-// }
-
-
-// private void ProcessCommand(DbCommand cmd)
-// {
-// object total;
-
-// if (Searcher.Page <= 0)
-// {
-// Searcher.Page = 1;
-// }
-// //if (DC.Database.IsMySql())
-// //{
-// // List parms = new List();
-// // foreach (MySqlParameter item in cmd.Parameters)
-// // {
-// // parms.Add(new MySqlParameter(string.Format("@{0}", item.ParameterName), item.Value));
-// // }
-// // if (cmd.CommandType == CommandType.StoredProcedure)
-// // {
-// // parms.Add(new MySqlParameter("@SearchMode", Enum.GetName(typeof(ListVMSearchModeEnum), SearcherMode)));
-// // parms.Add(new MySqlParameter("@NeedPage", (NeedPage && Searcher.Limit != -1)));
-// // parms.Add(new MySqlParameter("@CurrentPage", Searcher.Page));
-// // parms.Add(new MySqlParameter("@RecordsPerPage", Searcher.Limit));
-// // parms.Add(new MySqlParameter("@Sort", Searcher.SortInfo?.Property));
-// // parms.Add(new MySqlParameter("@SortDir", Searcher.SortInfo?.Direction));
-// // parms.Add(new MySqlParameter("@IDs", Ids == null ? "" : Ids.ToSpratedString()));
-
-// // MySqlParameter outp = new MySqlParameter("@TotalRecords", MySqlDbType.Int64)
-// // {
-// // Value = 0,
-// // Direction = ParameterDirection.Output
-// // };
-// // parms.Add(outp);
-// // }
-// // var pa = parms.ToArray();
-
-// // EntityList = DC.Run(cmd.CommandText, cmd.CommandType, pa).ToList();
-// // if (cmd.CommandType == CommandType.StoredProcedure)
-// // {
-// // total = pa.Last().Value;
-// // }
-// // else
-// // {
-// // total = EntityList.Count;
-// // }
-// //}
-// //else if (DC.Database.IsNpgsql())
-// //{
-// // List parms = new List();
-// // foreach (NpgsqlParameter item in cmd.Parameters)
-// // {
-// // parms.Add(new NpgsqlParameter(string.Format("@{0}", item.ParameterName), item.Value));
-// // }
-
-// // if (cmd.CommandType == CommandType.StoredProcedure)
-// // {
-// // parms.Add(new NpgsqlParameter("@SearchMode", Enum.GetName(typeof(ListVMSearchModeEnum), SearcherMode)));
-// // parms.Add(new NpgsqlParameter("@NeedPage", (NeedPage && Searcher.Limit != -1)));
-// // parms.Add(new NpgsqlParameter("@CurrentPage", Searcher.Page));
-// // parms.Add(new NpgsqlParameter("@RecordsPerPage", Searcher.Limit));
-// // parms.Add(new NpgsqlParameter("@Sort", Searcher.SortInfo?.Property));
-// // parms.Add(new NpgsqlParameter("@SortDir", Searcher.SortInfo?.Direction));
-// // parms.Add(new NpgsqlParameter("@IDs", Ids == null ? "" : Ids.ToSpratedString()));
-
-// // NpgsqlParameter outp = new NpgsqlParameter("@TotalRecords", NpgsqlDbType.Bigint)
-// // {
-// // Value = 0,
-// // Direction = ParameterDirection.Output
-// // };
-// // parms.Add(outp);
-// // }
-// // var pa = parms.ToArray();
-
-// // EntityList = DC.Run(cmd.CommandText, cmd.CommandType, pa).ToList();
-// // if (cmd.CommandType == CommandType.StoredProcedure)
-// // {
-// // total = pa.Last().Value;
-// // }
-// // else
-// // {
-// // total = EntityList.Count;
-// // }
-// //}
-// //else
-// //{
-// // List parms = new List();
-// // foreach (SqlParameter item in cmd.Parameters)
-// // {
-// // parms.Add(new SqlParameter(string.Format("@{0}", item.ParameterName), item.Value));
-// // }
-// // if (cmd.CommandType == CommandType.StoredProcedure)
-// // {
-
-// // parms.Add(new SqlParameter("@SearchMode", Enum.GetName(typeof(ListVMSearchModeEnum), SearcherMode)));
-// // parms.Add(new SqlParameter("@NeedPage", (NeedPage && Searcher.Limit != -1)));
-// // parms.Add(new SqlParameter("@CurrentPage", Searcher.Page));
-// // parms.Add(new SqlParameter("@RecordsPerPage", Searcher.Limit));
-// // parms.Add(new SqlParameter("@Sort", Searcher.SortInfo?.Property));
-// // parms.Add(new SqlParameter("@SortDir", Searcher.SortInfo?.Direction));
-// // parms.Add(new SqlParameter("@IDs", Ids == null ? "" : Ids.ToSpratedString()));
-
-// // SqlParameter outp = new SqlParameter("@TotalRecords", 0)
-// // {
-// // Direction = ParameterDirection.Output
-// // };
-// // parms.Add(outp);
-// // }
-// // var pa = parms.ToArray();
-
-// // EntityList = DC.Run(cmd.CommandText, cmd.CommandType, pa).ToList();
-// // if (cmd.CommandType == CommandType.StoredProcedure)
-// // {
-// // total = pa.Last().Value;
-// // }
-// // else
-// // {
-// // total = EntityList.Count;
-// // }
-
-// //}
-// //if (NeedPage && Searcher.Limit != -1)
-// //{
-// // if (total != null)
-// // {
-// // try
-// // {
-// // Searcher.Count = long.Parse(total.ToString());
-// // Searcher.PageCount = (int)((Searcher.Count - 1) / Searcher.Limit + 1);
-// // }
-// // catch { }
-// // }
-// //}
-// //else
-// //{
-// // Searcher.PageCount = EntityList.Count;
-// //}
-
-// }
-
-// public DateTime AddTime(DateTime dt, string type, int size)
-// {
-// switch (type)
-// {
-// case "year":
-// return dt.AddYears(size);
-// case "month":
-// return dt.AddMonths(size);
-// case "day":
-// return dt.AddDays(size);
-// case "hour":
-// return dt.AddHours(size);
-// case "minute":
-// return dt.AddMinutes(size);
-// case "second":
-// return dt.AddSeconds(size);
-// default:
-// return dt;
-// }
-// }
-
-// ///
-// /// 搜索后运行的函数,继承的类如果需要在搜索结束后进行其他操作,可重载这个函数
-// ///
-// public virtual void AfterDoSearcher()
-// {
-// if (SearcherMode == ListVMSearchModeEnum.Selector && Ids != null && Ids.Count > 0 && EntityList != null && EntityList.Count > 0)
-// {
-// foreach (var item in EntityList)
-// {
-// var id = item.GetID();
-// if (Ids.Contains(id.ToString()))
-// {
-// item.Checked = true;
-// }
-// }
-// }
-// }
-
-// ///
-// /// 删除所有ActionGridColumn的列
-// ///
-// public void RemoveActionColumn(object root = null)
-// {
-// //if (root == null)
-// //{
-// // if (GridHeaders == null)
-// // {
-// // GetHeaders();
-// // }
-// // root = GridHeaders;
-// //}
-// //if (root != null)
-// //{
-// // //IEnumerable>
-// // var aroot = root as List>;
-// // var toRemove = aroot.Where(x => x.ColumnType == GridColumnTypeEnum.Action).FirstOrDefault();
-// // aroot.Remove(toRemove);
-// // foreach (var child in aroot)
-// // {
-// // if (child.Children != null && child.Children.Count() > 0)
-// // {
-// // RemoveActionColumn(child.Children);
-// // }
-// // }
-// //}
-// }
-
-// public void RemoveAction()
-// {
-// //_gridActions = new List();
-// }
-
-// //public void RemoveActionAndIdColumn(IEnumerable> root = null)
-// //{
-// // if (root == null)
-// // {
-// // if (GridHeaders == null)
-// // {
-// // GetHeaders();
-// // }
-// // root = GridHeaders;
-// // }
-// // if (root != null)
-// // {
-// // var aroot = root as List>;
-// // List> remove = null;
-// // var idpro = typeof(TModel).GetProperties().Where(x => x.Name.ToLower() == "id").Select(x => x.PropertyType).FirstOrDefault();
-// // if (idpro == typeof(string))
-// // {
-// // remove = aroot.Where(x => x.ColumnType == GridColumnTypeEnum.Action || x.Hide == true || x.DisableExport).ToList();
-// // }
-// // else
-// // {
-// // remove = aroot.Where(x => x.ColumnType == GridColumnTypeEnum.Action || x.Hide == true || x.DisableExport || x.FieldName?.ToLower() == "id").ToList();
-// // }
-// // foreach (var item in remove)
-// // {
-// // aroot.Remove(item);
-// // }
-// // foreach (var child in root)
-// // {
-// // if (child.Children != null && child.Children.Count() > 0)
-// // {
-// // RemoveActionAndIdColumn(child.Children);
-// // }
-// // }
-// // }
-// //}
-
-
-// ///
-// /// 添加Error列,主要为批量模式使用
-// ///
-// //public void AddErrorColumn()
-// //{
-// // GetHeaders();
-// // //寻找所有Header为错误信息的列,如果没有则添加
-// // if (GridHeaders.Where(x => x.Field == "BatchError").FirstOrDefault() == null)
-// // {
-// // var temp = GridHeaders as List>;
-// // if (temp.Where(x => x.ColumnType == GridColumnTypeEnum.Action).FirstOrDefault() == null)
-// // {
-// // temp.Add(this.MakeGridColumn(x => x.BatchError, Width: 200, Header: Core.Program._localizer["Error"]).SetForeGroundFunc(x => "ff0000"));
-// // }
-// // else
-// // {
-// // temp.Insert(temp.Count - 1, this.MakeGridColumn(x => x.BatchError, Width: 200, Header: Core.Program._localizer["Error"]).SetForeGroundFunc(x => "ff0000"));
-// // }
-// // }
-// //}
-
-// //public void ProcessListError(List Entities)
-// //{
-// // if (Entities == null)
-// // {
-// // return;
-// // }
-// // EntityList = Entities;
-// // IsSearched = true;
-// // bool haserror = false;
-// // List keys = new List();
-// // if (string.IsNullOrEmpty(DetailGridPrix) == false)
-// // {
-// // foreach (var item in MSD.Keys)
-// // {
-// // if (item.StartsWith(DetailGridPrix))
-// // {
-// // var errors = MSD[item];
-// // if (errors.Count > 0)
-// // {
-// // Regex r = new Regex($"{DetailGridPrix}\\[(.*?)\\]");
-// // try
-// // {
-// // if (int.TryParse(r.Match(item).Groups[1].Value, out int index))
-// // {
-// // EntityList[index].BatchError = errors.Select(x => x.ErrorMessage).ToSpratedString();
-// // keys.Add(item);
-// // haserror = true;
-// // }
-// // }
-// // catch { }
-// // }
-// // }
-// // }
-// // foreach (var item in keys)
-// // {
-// // //MSD.RemoveModelError(item);
-// // }
-// // if (haserror)
-// // {
-// // AddErrorColumn();
-// // }
-// // }
-// //}
-
-// public TModel CreateEmptyEntity()
-// {
-// return typeof(TModel).GetConstructor(Type.EmptyTypes).Invoke(null) as TModel;
-// }
-
-// public void ClearEntityList()
-// {
-// EntityList?.Clear();
-// }
-
-// public string DetailGridPrix { get; set; }
-
-// #endregion
-
-// public virtual void UpdateEntityList(bool updateAllFields = false)
-// {
-// if (EntityList != null)
-// {
-// var ftype = EntityList.GetType().GenericTypeArguments.First();
-// PropertyInfo[] itemPros = ftype.GetProperties();
-
-// foreach (var newitem in EntityList)
-// {
-// var subtype = newitem.GetType();
-// if (subtype.IsSubclassOf(typeof(BaseModel)))
-// {
-// BaseModel ent = newitem as BaseModel;
-// if (ent.UpdateTime == null)
-// {
-// ent.UpdateTime = DateTime.Now;
-// }
-// if (string.IsNullOrEmpty(ent.UpdateBy))
-// {
-// ent.UpdateBy = loginUserInfo?.ITCode;
-// }
-// }
-// //循环页面传过来的子表数据,将关联到TopBaseModel的字段设为null,并且把外键字段的值设定为主表ID
-// foreach (var itempro in itemPros)
-// {
-// if (itempro.PropertyType.IsSubclassOf(typeof(TopBaseModel)))
-// {
-// itempro.SetValue(newitem, null);
-// }
-// }
-// }
-
-// IEnumerable data = null;
-// //打开新的数据库联接,获取数据库中的主表和子表数据
-// using (var ndc = DC.CreateNew())
-// {
-// var ids = EntityList.Select(x => x.GetID().ToString()).ToList();
-// data = ndc.Set().AsNoTracking().Where(ids.GetContainIdExpression