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 @@ + + + + + + + + + + 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 @@ + + + + + + + + + + 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/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 @@ - - - - - - - - - - - - -