105040 增加数据库保存,优化界面

This commit is contained in:
lihanbo 2024-12-03 11:50:36 +08:00
parent 870faf37a9
commit 2740456d41
15 changed files with 523 additions and 181 deletions

View File

@ -0,0 +1,36 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sinvo.EplanHpD.Plugin.Service
{
public class DBHelper
{
private static string _dbUser = "sa";
private static string _dbPassword = "Sa1234";
private static string _dbServer = ".";
private static string _dbName = "MotorData";
private static string _connectionString => $"Server={_dbServer};Database={_dbName};User Id={_dbUser};Password={_dbPassword};";
private static SqlSugarClient _db;
public static SqlSugarClient DB
{
get
{
_db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = _connectionString,
DbType = DbType.SqlServer,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute
});
return _db;
}
}
}
}

View File

@ -0,0 +1,18 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sinvo.EplanHpD.Plugin.Service.Model
{
[SugarTable("T_MOTOR_DATA")]
public class MotorDataModel
{
[SugarColumn(IsPrimaryKey = true, ColumnDataType = "VARCHAR(64)")]
public string ID { get; set; }
[SugarColumn(ColumnDataType = "TEXT")]
public string Data { get; set; }
}
}

View File

@ -0,0 +1,34 @@
using Sinvo.EplanHpD.Plugin.Service.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sinvo.EplanHpD.Plugin.Service
{
public class MotorLectotypeService
{
public string GetMotorLectotypeData(string motorOccId)
{
var data = DBHelper.DB.Queryable<MotorDataModel>("mt")
.Where(mt => mt.ID == motorOccId)
.First();
if (data != null)
{
return data.Data;
}
else
{
return "";
}
}
public bool SaveMotorLectotypeData(string motorOccId, string data)
{
var motorData = new MotorDataModel { ID = motorOccId, Data = data };
var result = DBHelper.DB.Storageable<MotorDataModel>(motorData).WhereColumns(p => p.ID).ExecuteCommand();
return result != 0;
}
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sinvo.EplanHpD.Plugin.Service
{
public class PluginServices
{
}
}

View File

@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Sinvo.EplanHpD.Plugin.Service")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Sinvo.EplanHpD.Plugin.Service")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("ad1aa2bc-9289-46ae-bdc0-30ae13f51b3f")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{AD1AA2BC-9289-46AE-BDC0-30AE13F51B3F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Sinvo.EplanHpD.Plugin.Service</RootNamespace>
<AssemblyName>Sinvo.EplanHpD.Plugin.Service</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DBHelper.cs" />
<Compile Include="Model\MotorDataModel.cs" />
<Compile Include="MotorLectotypeService.cs" />
<Compile Include="PluginServices.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="SqlSugar">
<Version>5.1.4.170</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -245,6 +245,10 @@
<Project>{60d3c75c-e71d-4116-bd7e-cac68c4dd96b}</Project>
<Name>PdfiumViewer</Name>
</ProjectReference>
<ProjectReference Include="..\Sinvo.EplanHpD.Plugin.Service\Sinvo.EplanHpD.Plugin.Service.csproj">
<Project>{AD1AA2BC-9289-46AE-BDC0-30AE13F51B3F}</Project>
<Name>Sinvo.EplanHpD.Plugin.Service</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm">
@ -256,6 +260,9 @@
<PackageReference Include="MiniExcel">
<Version>1.34.2</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.3</Version>
</PackageReference>
<PackageReference Include="PolySharp">
<Version>1.14.1</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@ -1,4 +1,5 @@
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
using Sinvo.EplanHpD.Plugin.Service;
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel;
using System;
using System.Collections.Generic;
@ -6,6 +7,7 @@ using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Markup;
namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
@ -19,7 +21,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
{
private static readonly IDictionary<string, CableLectotypeViewModel> _motorViewModel = new Dictionary<string, CableLectotypeViewModel>();
public static CableLectotypeViewModel CreateOrGet(MotorModel motor)
public static async Task<CableLectotypeViewModel> CreateOrGetAsync(MotorModel motor)
{
if (motor == null || string.IsNullOrEmpty(motor.OccPartId))
{
@ -27,16 +29,24 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
return new CableLectotypeViewModel(new MotorModel());
}
if (_motorViewModel.ContainsKey(motor.OccPartId))
CableLectotypeViewModel viewModel = null;
Task.Factory.StartNew(() =>
{
Debug.WriteLine($"CreateOrGet Get -> {motor.MotorModelStr} => {motor.OccPartId}");
return _motorViewModel[motor.OccPartId];
var service = new MotorLectotypeService();
var data = service.GetMotorLectotypeData(motor.OccPartId);
if (!string.IsNullOrEmpty(data))
{
viewModel = Newtonsoft.Json.JsonConvert.DeserializeObject<CableLectotypeViewModel>(data);
}
}).Wait();
if (viewModel == null)
{
return new CableLectotypeViewModel(motor);
}
else
{
var viewModel = new CableLectotypeViewModel(motor);
_motorViewModel.Add(motor.OccPartId, viewModel);
Debug.WriteLine($"CreateOrGet Create -> {motor.MotorModelStr} => {motor.OccPartId}");
return viewModel;
}
}

View File

@ -33,6 +33,13 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
}
}
}
public static void Unsubscribe(string message)
{
if (_subscribers.ContainsKey(message))
{
_subscribers.Remove(message);
}
}
public static void Publish(string message, object parameter = null)
{

View File

@ -1,4 +1,4 @@
<Page
<UserControl
x:Class="Sinvo.EplanHpD.Plugin.WPFUI.View.CableLectotypeWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@ -8,14 +8,13 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:util="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.Utils"
xmlns:viewmodel="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.ViewModel"
Title="CableLectotypeWindow"
Height="750"
d:DataContext="{d:DesignInstance Type=viewmodel:CableLectotypeViewModel}"
IsVisibleChanged="Page_IsVisibleChanged"
Loaded="Page_Loaded"
SnapsToDevicePixels="True"
mc:Ignorable="d">
<Page.Resources>
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Sinvo.EplanHpD.Plugin.WPFUI;component/Themes/Theme.xaml" />
@ -32,8 +31,8 @@
</Grid>
</DataTemplate>
</ResourceDictionary>
</Page.Resources>
<Grid>
</UserControl.Resources>
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="60" />
@ -42,20 +41,7 @@
<ColumnDefinition Width="400" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ScrollViewer
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="0"
Grid.ColumnSpan="2"
HorizontalAlignment="Center"
Panel.ZIndex="99"
VerticalScrollBarVisibility="Hidden">
<StackPanel
x:Name="GrowlParent"
Margin="0,10,10,10"
VerticalAlignment="Top"
Panel.ZIndex="99" />
</ScrollViewer>
<ContentPresenter
x:Name="LoadingContentMask"
Grid.Row="0"
@ -63,7 +49,8 @@
Grid.Column="0"
Grid.ColumnSpan="2"
Panel.ZIndex="99"
ContentTemplate="{StaticResource LoadingMask}" />
ContentTemplate="{StaticResource LoadingMask}"
Visibility="Collapsed" />
<hc:Card
x:Name="InfoCard"
Grid.Row="0"
@ -346,12 +333,7 @@
Grid.ColumnSpan="2"
HorizontalAlignment="Right"
Orientation="Horizontal">
<Button
Margin="10,0,0,0"
hc:IconElement.Geometry="{StaticResource DialogBoxLauncherGeometry}"
Content="置顶显示"
FontSize="14"
Style="{StaticResource ButtonSuccess}" />
<Button
Margin="10,0,0,0"
hc:IconElement.Geometry="{StaticResource SaveGeometry}"
@ -362,9 +344,10 @@
<Button
Margin="10,0,10,0"
hc:IconElement.Geometry="{StaticResource CloseGeometry}"
Click="CloseBtn_Click"
Content="关闭"
FontSize="14"
Style="{StaticResource ButtonDanger}" />
</hc:SimpleStackPanel>
</Grid>
</Page>
</UserControl>

View File

@ -1,9 +1,16 @@
using EPLAN.Harness.Core.Tasks;
using CommunityToolkit.Mvvm.Messaging;
using EPLAN.Harness.Core.Tasks;
using EPLAN.Harness.Graphics;
using HandyControl.Controls;
using Sinvo.EplanHpD.Plugin.Service;
using Sinvo.EplanHpD.Plugin.WPFUI.Common;
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
@ -14,38 +21,77 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
/// <summary>
/// CableLectotypeWindow.xaml 的交互逻辑
/// </summary>
public partial class CableLectotypeWindow : Page
public partial class CableLectotypeWindow : UserControl, INotifyPropertyChanged
{
private MotorModel _motor;
private CableLectotypeViewModel ViewModel;
public static readonly DependencyProperty MotorProperty =
DependencyProperty.Register("Motor", typeof(object), typeof(CableLectotypeWindow), new PropertyMetadata(null));
public object Motor
{
get { return GetValue(MotorProperty); }
set
{
_motor = (MotorModel)value;
_viewModel.Motor = _motor;
SetValue(MotorProperty, value);
}
}
private CableLectotypeViewModel _viewModel;
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public CableLectotypeWindow()
{
InitializeComponent();
Growl.Register("CableLectotypeMessage", GrowlParent);
MessageSend.Subscribe("MotorChanged", (x) => OnMotorChanged());
this.Initialized += CableLectotypeWindow_Initialized;
}
private void CableLectotypeWindow_Initialized(object sender, EventArgs e)
{
OnMotorChanged();
Debug.WriteLine($"Page_Loaded -> {_motor?.MotorModelStr} => {_motor?.OccPartId}");
}
private void OnMotorChanged()
{
this.Dispatcher.BeginInvoke(() =>
{
_motor = LectotypeManager.Motor;
if (ViewModel == null)
_motor = (Motor as MotorModel);
if (_motor != null)
this.Dispatcher.BeginInvoke(() =>
{
this.DataContext = ViewModel = LectotypeViewModelFactory.CreateOrGet(_motor);
}
else
{
ViewModel.Motor = _motor;
}
Debug.WriteLine($"OnMotorChanged - ViewModel -> {ViewModel.Motor.MotorModelStr} => {ViewModel.Motor.OccPartId}");
Debug.WriteLine($"OnMotorChanged -> {LectotypeManager.Motor.MotorModelStr} => {LectotypeManager.Motor.OccPartId}");
});
try
{
LoadingContentMask.Visibility = Visibility.Visible;
_viewModel = LectotypeViewModelFactory.CreateOrGetAsync(_motor).Result;
//if(_viewModel == null)
//{
// _viewModel = new
//}
this.DataContext = _viewModel;
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
finally
{
LoadingContentMask.Visibility = Visibility.Collapsed;
}
});
}
private void CableratorBtn_Click(object sender, RoutedEventArgs e)
{
ViewModel.Cablerator();
_viewModel.Cablerator();
}
private void ListView_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
@ -60,20 +106,38 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
private void Page_Loaded(object sender, RoutedEventArgs e)
{
Debug.WriteLine($"Page_Loaded -> {_motor?.MotorModelStr} => {_motor?.OccPartId}");
}
private void Page_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
//_motor = LectotypeManager.Motor;
//this.DataContext = ViewModel = LectotypeViewModelFactory.CreateOrGet(_motor);
Debug.WriteLine($"Page_IsVisibleChanged -> {LectotypeManager.Motor?.MotorModelStr} => {LectotypeManager.Motor?.OccPartId}");
MessageSend.Publish("MotorChanged", null);
Debug.WriteLine($"Page_IsVisibleChanged -> {(Motor as MotorModel)?.MotorModelStr} => {(Motor as MotorModel)?.OccPartId}");
//OnMotorChanged();
}
private void SaveBtn_Click(object sender, RoutedEventArgs e)
{
LoadingContentMask.Visibility = Visibility.Visible;
try
{
if (_viewModel.SaveToDb())
{
Growl.Success("保存成功", "CableLectotypeMessage");
}
else
{
Growl.Error("保存失败", "CableLectotypeMessage");
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
LoadingContentMask.Visibility = Visibility.Collapsed;
}
private void CloseBtn_Click(object sender, RoutedEventArgs e)
{
}
}
}

View File

@ -8,8 +8,9 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pdf="clr-namespace:PdfiumViewer;assembly=PdfiumViewer"
xmlns:util="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.Utils"
xmlns:view="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.View"
xmlns:viewmodel="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.ViewModel"
Title="多芯线数据抓取"
Title="伺服电机数据抓取"
Width="1600"
Height="800"
d:DataContext="{d:DesignInstance Type=viewmodel:LectotypeViewModel}"
@ -113,6 +114,17 @@
<RowDefinition Height="80" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ScrollViewer
Grid.Row="0"
HorizontalAlignment="Right"
Panel.ZIndex="99"
VerticalScrollBarVisibility="Hidden">
<StackPanel
x:Name="GrowlParent"
Margin="5"
VerticalAlignment="Top"
Panel.ZIndex="99" />
</ScrollViewer>
<ContentPresenter
x:Name="LoadingMask"
Grid.Row="0"
@ -157,84 +169,112 @@
Click="EnableSelectSetBtn_Click"
Content="启用选择监听"
Style="{StaticResource ButtonPrimary}" />
<Button
Margin="10,0,0,0"
hc:IconElement.Geometry="{StaticResource DialogBoxLauncherGeometry}"
Content="置顶显示"
FontSize="14"
Style="{StaticResource ButtonSuccess}" />
</hc:SimpleStackPanel>
</hc:Card>
<TabControl Grid.Row="1" FontSize="14">
<TabItem Header="电机数据">
<DataGrid
x:Name="MotorDataGrid"
AutoGenerateColumns="False"
IsReadOnly="True"
<ListBox
x:Name="MotorListView"
HorizontalContentAlignment="Stretch"
ItemsSource="{Binding Motors}"
MouseDoubleClick="MotorDataGrid_MouseDoubleClick"
RowDetailsVisibilityMode="{Binding RowDetailsVisibility}"
RowHeight="NaN"
ScrollViewer.CanContentScroll="False"
SelectionChanged="MotorDataGrid_SelectionChanged">
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Click="MotorDataGridToMotorSourceMenuItem_Click" Header="在3D中查看转至电机" />
<MenuItem Click="MotorDataGridToCableLectotype_Click" Header="根据此电机开始选择线材" />
</ContextMenu>
</DataGrid.ContextMenu>
<DataGrid.Resources>
<Style BasedOn="{StaticResource DataGridCellStyle}" TargetType="DataGridCell">
<Setter Property="Height" Value="Auto" />
<Setter Property="MaxHeight" Value="9999" />
VirtualizingPanel.ScrollUnit="Pixel">
<ListBox.Resources>
<Style TargetType="ListBoxItem">
<Setter Property="Background" Value="Transparent" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="White" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
<DataGrid.RowStyle>
<Style BasedOn="{StaticResource DataGridRowStyle}" TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding IsError}" Value="True">
<Setter Property="Background" Value="#dc4d41" />
<Setter Property="Foreground" Value="White" />
</DataTrigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="White" />
<Setter Property="Background" Value="#326cf3" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn
Width="160"
Binding="{Binding MotorModelStr}"
Header="电机型号" />
<DataGridTextColumn
Width="160"
Binding="{Binding MotorPower}"
Header="电机功率" />
<DataGridTextColumn
Width="160"
Binding="{Binding AxisNo}"
Header="轴号" />
<DataGridTextColumn Binding="{Binding CheckedMsg}" Header="异常信息" />
<DataGridTemplateColumn Width="300" Header="操作">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel MinWidth="90" Orientation="Horizontal">
<Button Click="SelectedLectotype_Click" Content="展开线材选型" />
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
</ListBox.Resources>
<!-- 定义每一项的模板 -->
<ListBox.ItemTemplate>
<DataTemplate>
<hc:TransitioningContentControl TransitionMode="Top2BottomWithFade">
<Frame SnapsToDevicePixels="True" Source="pack://application:,,,/Sinvo.EplanHpD.Plugin.WPFUI;component/View/CableLectotypeWindow.xaml" />
</hc:TransitioningContentControl>
<!-- 直接使用 Expander 作为根元素 -->
<Expander
HorizontalAlignment="Stretch"
FontSize="14"
IsExpanded="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ListBoxItem}}">
<!-- Expander 的标题部分 -->
<Expander.Header>
<!-- 使用 Grid 定义列布局 -->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="160" MinWidth="160" />
<ColumnDefinition Width="160" MinWidth="160" />
<ColumnDefinition Width="160" MinWidth="160" />
<ColumnDefinition Width="*" MinWidth="300" />
<ColumnDefinition Width="300" MinWidth="300" />
<ColumnDefinition Width="160" MinWidth="160" />
</Grid.ColumnDefinitions>
<!-- 电机型号 -->
<TextBlock
Grid.Column="0"
VerticalAlignment="Center"
Text="{Binding MotorModelStr}" />
<!-- 电机功率 -->
<TextBlock
Grid.Column="1"
VerticalAlignment="Center"
Text="{Binding MotorPower}" />
<!-- 轴号 -->
<TextBlock
Grid.Column="2"
VerticalAlignment="Center"
Text="{Binding AxisNo}" />
<!-- 异常信息 -->
<TextBlock
Grid.Column="3"
VerticalAlignment="Center"
Text="{Binding CheckedMsg}" />
<!-- 操作按钮 -->
<StackPanel
Grid.Column="4"
VerticalAlignment="Center"
Orientation="Horizontal">
<Button Click="SelectedLectotype_Click" Content="展开线材选型" />
</StackPanel>
<!-- ID -->
<TextBlock Grid.Column="5" Text="{Binding OccPartId}" />
</Grid>
</Expander.Header>
<!-- Expander 的内容部分 -->
<Expander.Content>
<!-- 原来的 RowDetailsTemplate 内容 -->
<hc:TransitioningContentControl TransitionMode="Top2Bottom">
<!--<Frame SnapsToDevicePixels="True" Source="pack://application:,,,/Sinvo.EplanHpD.Plugin.WPFUI;component/View/CableLectotypeWindow.xaml" />-->
<view:CableLectotypeWindow Motor="{Binding}" />
</hc:TransitioningContentControl>
</Expander.Content>
</Expander>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
</ListBox.ItemTemplate>
<!-- 如果需要上下文菜单,可以取消注释以下部分 -->
<!--
<ListBox.ContextMenu>
<ContextMenu>
<MenuItem
Click="MotorListViewToMotorSourceMenuItem_Click"
Header="在3D中查看转至电机" />
<MenuItem
Click="MotorListViewToCableLectotype_Click"
Header="根据此电机开始选择线材" />
</ContextMenu>
</ListBox.ContextMenu>
-->
</ListBox>
</TabItem>
<TabItem Header="整理后的数据">
<!--
@ -482,7 +522,6 @@
</DataGrid.RowDetailsTemplate>
</DataGrid>
</TabItem>
</TabControl>
<Grid
Grid.Row="0"

View File

@ -1,7 +1,9 @@
using EPLAN.Harness.Core.Controls;
using CommunityToolkit.Mvvm.Messaging;
using EPLAN.Harness.Core.Controls;
using HandyControl.Controls;
using Microsoft.Win32;
using Microsoft.WindowsAPICodePack.Dialogs;
using Sinvo.EplanHpD.Plugin.WPFUI.Common;
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
using Sinvo.EplanHpD.Plugin.WPFUI.View;
@ -32,6 +34,14 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI
this.DataContext = ViewModel = new LectotypeViewModel(docId);
Application.Current.SetMainWindow(this);
WeakReferenceMessenger.Default.Register<CommonMessage>("RowDetailsVisibility", (sender, message) =>
{
if (Enum.IsDefined(typeof(DataGridRowDetailsVisibilityMode), message.Value))
{
ViewModel.RowDetailsVisibility = (DataGridRowDetailsVisibilityMode)message.Value;
}
});
Growl.Register("CableLectotypeMessage", GrowlParent);
}
private void Window_Loaded(object sender, RoutedEventArgs e)
@ -155,6 +165,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI
private void Window_Closed(object sender, System.EventArgs e)
{
//DrawPDFHelper.ClearCache();
WeakReferenceMessenger.Default.Unregister<CommonMessage>("RowDetailsVisibility");
MotorExcelHelper.Instance.CloseStream();
}
@ -340,23 +351,6 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI
private void MotorDataGridToMotorSourceMenuItem_Click(object sender, RoutedEventArgs e)
{
var selectItem = MotorDataGrid.SelectedItem;
if (selectItem is MotorModel model)
{
var motorModelPartId = model.OccPartId;
//var cableName = model.IsComplexLine ? model.CableName.Split('/')[1] : model.CableName;
if (string.IsNullOrEmpty(motorModelPartId))
{
FlexMessageBox.ShowText(FlexMessageBox.Type.INFO, "未获取到电机名称");
}
else
{
ViewModel.ToMotorSource(motorModelPartId, null);
}
//}
}
}
private void MotorDataGridToCableLectotype_Click(object sender, RoutedEventArgs e)
@ -377,46 +371,28 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI
eventArg.Source = sender;
(sender as ListView).RaiseEvent(eventArg);
}
private void MotorDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (LectotypeManager.Motor?.OccPartId != (MotorDataGrid.SelectedItem as MotorModel)?.OccPartId)
{
//ViewModel.RowDetailsVisibility = DataGridRowDetailsVisibilityMode.Collapsed;
LectotypeManager.Motor = MotorDataGrid.SelectedItem as MotorModel;
Debug.WriteLine($"{LectotypeManager.Motor.MotorModelStr} => {LectotypeManager.Motor.OccPartId}");
//ViewModel.RowDetailsVisibility = DataGridRowDetailsVisibilityMode.VisibleWhenSelected;
MessageSend.Publish("MotorChanged", null);
}
}
private void MotorDataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
}
private bool showRowDetails = false;
private void SelectedLectotype_Click(object sender, RoutedEventArgs e)
{
var curSelItem = MotorDataGrid.SelectedItem as MotorModel;
if (LectotypeManager.Motor == null || LectotypeManager.Motor.OccPartId == curSelItem.OccPartId)
}
private void MotorListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (LectotypeManager.Motor?.OccPartId != (MotorListView.SelectedItem as MotorModel)?.OccPartId)
{
if (showRowDetails)
{
ViewModel.RowDetailsVisibility = DataGridRowDetailsVisibilityMode.Collapsed;
}
else
{
ViewModel.RowDetailsVisibility = DataGridRowDetailsVisibilityMode.VisibleWhenSelected;
}
//LectotypeManager.Motor = new MotorModel();
showRowDetails = !showRowDetails;
Debug.WriteLine($"MotorListView_SelectionChanged {LectotypeManager.Motor.MotorModelStr} => {LectotypeManager.Motor.OccPartId}");
}
else
{
LectotypeManager.Motor = curSelItem;
ViewModel.RowDetailsVisibility = DataGridRowDetailsVisibilityMode.VisibleWhenSelected;
}
MessageSend.Publish("MotorChanged", null);
}
private void MotorListViewToMotorSourceMenuItem_Click(object sender, RoutedEventArgs e)
{
}
private void MotorListViewToCableLectotype_Click(object sender, RoutedEventArgs e)
{
}
}
}

View File

@ -1,4 +1,5 @@
using HandyControl.Controls;
using Sinvo.EplanHpD.Plugin.Service;
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
using System;
@ -312,11 +313,63 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
OnPropertyChanged(nameof(IsEnableParagraph));
}
}
public bool SaveToDb()
{
var id = Motor.OccPartId;
var json = Newtonsoft.Json.JsonConvert.SerializeObject(this);
var service = new MotorLectotypeService();
return service.SaveMotorLectotypeData(id, json);
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
public void Apply(CableLectotypeViewModel viewModel)
{
if (viewModel == null)
{
return;
}
CableConnectionType = viewModel.CableConnectionType;
AxisNo = viewModel.AxisNo;
CableType = viewModel.CableType;
EncoderLineParagraph = viewModel.EncoderLineParagraph;
PowerLineParagraph = viewModel.PowerLineParagraph;
CableModelStr = viewModel.CableModelStr;
// 深拷贝 SelectedLines
SelectedLines = viewModel.SelectedLines.Select(line => new LectotypeLineModel
{
SeqNo = line.SeqNo,
MechanicalNo = line.MechanicalNo,
MechanicalName = line.MechanicalName,
AxisNo = line.AxisNo,
CableConnectionClass = line.CableConnectionClass,
CableType = line.CableType,
IsFlexibility = line.IsFlexibility,
PowerLineLength = line.PowerLineLength,
EncoderLineLength = line.EncoderLineLength,
DrawingNo = line.DrawingNo,
CableModelNo = line.CableModelNo,
LineCount = line.LineCount,
CurrentLine = line.CurrentLine,
Motor = line.Motor,
IsLectotype = line.IsLectotype,
SubLines = line.SubLines.Select(subLine => new LectotypeLineModel
{
SeqNo = subLine.SeqNo,
CableModel = subLine.CableModel,
CableType = subLine.CableType
}).ToList()
}).ToList();
OnPropertyChanged(nameof(SelectedLines));
}
#endregion
}

View File

@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sinvo.EplanHpD.Plugin.Test"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PdfiumViewer", "..\PdfiumViewer\PdfiumViewer.csproj", "{60D3C75C-E71D-4116-BD7E-CAC68C4DD96B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sinvo.EplanHpD.Plugin.Service", "Sinvo.EplanHpD.Plugin.Service\Sinvo.EplanHpD.Plugin.Service.csproj", "{AD1AA2BC-9289-46AE-BDC0-30AE13F51B3F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -69,6 +71,18 @@ Global
{60D3C75C-E71D-4116-BD7E-CAC68C4DD96B}.Release|x64.Build.0 = Release|Any CPU
{60D3C75C-E71D-4116-BD7E-CAC68C4DD96B}.Release|x86.ActiveCfg = Release|x86
{60D3C75C-E71D-4116-BD7E-CAC68C4DD96B}.Release|x86.Build.0 = Release|x86
{AD1AA2BC-9289-46AE-BDC0-30AE13F51B3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD1AA2BC-9289-46AE-BDC0-30AE13F51B3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD1AA2BC-9289-46AE-BDC0-30AE13F51B3F}.Debug|x64.ActiveCfg = Debug|Any CPU
{AD1AA2BC-9289-46AE-BDC0-30AE13F51B3F}.Debug|x64.Build.0 = Debug|Any CPU
{AD1AA2BC-9289-46AE-BDC0-30AE13F51B3F}.Debug|x86.ActiveCfg = Debug|Any CPU
{AD1AA2BC-9289-46AE-BDC0-30AE13F51B3F}.Debug|x86.Build.0 = Debug|Any CPU
{AD1AA2BC-9289-46AE-BDC0-30AE13F51B3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD1AA2BC-9289-46AE-BDC0-30AE13F51B3F}.Release|Any CPU.Build.0 = Release|Any CPU
{AD1AA2BC-9289-46AE-BDC0-30AE13F51B3F}.Release|x64.ActiveCfg = Release|Any CPU
{AD1AA2BC-9289-46AE-BDC0-30AE13F51B3F}.Release|x64.Build.0 = Release|Any CPU
{AD1AA2BC-9289-46AE-BDC0-30AE13F51B3F}.Release|x86.ActiveCfg = Release|Any CPU
{AD1AA2BC-9289-46AE-BDC0-30AE13F51B3F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE