105040 Update 线材检查增加导出文件名自定义,增加刷新报表数据,修复部分情况下导致的长度异常

This commit is contained in:
lihanbo 2024-11-15 15:04:08 +08:00
parent 40cbbc7d55
commit 9c0d3acdfa
11 changed files with 285 additions and 43 deletions

View File

@ -16,5 +16,5 @@ using System.Runtime.InteropServices;
[assembly: Guid("aec39474-528b-4da8-b650-99189acb7a2c")]
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.16")]
[assembly: AssemblyFileVersion("1.0.0.16")]
[assembly: AssemblyVersion("1.0.0.18")]
[assembly: AssemblyFileVersion("1.0.0.18")]

View File

@ -38,6 +38,24 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.2.2.10\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>

View File

@ -16,8 +16,7 @@
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml" />
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml" />
<ResourceDictionary Source="pack://application:,,,/Sinvo.EplanHpD.Plugin.WPFUI;component/Themes/Theme.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style
x:Key="DataGridCheckBoxCellStyle"
@ -28,6 +27,7 @@
</Style>
<util:FlagEnumConverter x:Key="FlagEnumConverter" />
<util:NameTypeConverter x:Key="NameTypeConverter" />
<DataTemplate x:Key="LoadingMask">
<Grid Background="#66424242">
<StackPanel
@ -53,6 +53,18 @@
<RowDefinition Height="105" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ScrollViewer
Grid.Row="0"
Grid.RowSpan="2"
HorizontalAlignment="Right"
Panel.ZIndex="99"
VerticalScrollBarVisibility="Hidden">
<StackPanel
x:Name="GrowlParent"
Margin="0,10,10,10"
VerticalAlignment="Top"
Panel.ZIndex="99" />
</ScrollViewer>
<ContentPresenter
x:Name="LoadingMask"
Grid.Row="0"
@ -153,6 +165,15 @@
IsChecked="{Binding OnlyShowError}"
Style="{StaticResource ToggleButtonSwitch}" />
</StackPanel>
<Button
x:Name="RefreshReportDataBtn"
Height="40"
Margin="10"
Padding="10"
Click="RefreshReportDataBtn_Click"
Content="刷新报表数据"
FontSize="14"
Style="{StaticResource ButtonPrimary}" />
</StackPanel>
</Grid>
<TabControl x:Name="DataTabControl" Grid.Row="1">
@ -400,11 +421,20 @@
<TabItem Header="导入模板预览">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="70" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="300" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<hc:SimpleStackPanel
Grid.Column="1"
HorizontalAlignment="Center"
Orientation="Horizontal">
<Button
Grid.Row="0"
Width="300"
Height="40"
Margin="5"
@ -412,6 +442,34 @@
Content="导出下单数据"
FontSize="16"
Style="{StaticResource ButtonPrimary}" />
</hc:SimpleStackPanel>
<StackPanel Grid.Column="2" VerticalAlignment="Center">
<StackPanel Margin="10,0,0,0">
<RadioButton
HorizontalAlignment="Left"
Content="使用项目编号作为文件名"
FontSize="14"
GroupName="ExportFileName"
IsChecked="{Binding NameType, Converter={StaticResource NameTypeConverter}, ConverterParameter={x:Static util:ExportFileNameType.ProjectNo}}" />
<RadioButton
HorizontalAlignment="Left"
Content="使用机构号&机构名作为文件名"
FontSize="14"
GroupName="ExportFileName"
IsChecked="{Binding NameType, Converter={StaticResource NameTypeConverter}, ConverterParameter={x:Static util:ExportFileNameType.Mechanism}}" />
<RadioButton
HorizontalAlignment="Left"
FontSize="14"
GroupName="ExportFileName"
IsChecked="{Binding NameType, Converter={StaticResource NameTypeConverter}, ConverterParameter={x:Static util:ExportFileNameType.Custom}}">
<StackPanel Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Text="自定义:" />
<hc:TextBox Width="200" Text="{Binding CustomFileName}" />
</StackPanel>
</RadioButton>
</StackPanel>
</StackPanel>
</Grid>
<DataGrid
x:Name="ImportDataGrid"
Grid.Row="1"
@ -444,7 +502,6 @@
<DataGridTextColumn Binding="{Binding RearTerminalStripLength}" Header="后端子剥线长度" />
<DataGridTextColumn Binding="{Binding InsulationModel}" Header="绝缘软套型号" />
<DataGridTextColumn Binding="{Binding InsulationMaterialNo}" Header="绝缘软套型号物料编码" />
</DataGrid.Columns>
</DataGrid>
</Grid>

View File

@ -10,6 +10,7 @@ using EPLAN.Harness.ProjectCore;
using EPLAN.Harness.ProjectCore.Occurrences;
using EPLAN.Harness.ProjectCore.Occurrences.Designer;
using EPLAN.Harness.ProjectCore.Report;
using HandyControl.Controls;
using Microsoft.Win32;
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
@ -29,9 +30,9 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI;
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
public partial class MainWindow : System.Windows.Window
{
private readonly MainViewModel ViewModel;
private MainViewModel ViewModel;
public delegate void UpdateDataGridColumns(List<DataGridColumn> columns, DataGridType type);
private IEnumerable<BaseReportEntry> datas;
private List<ReportColumn> reportColumns;
@ -40,10 +41,15 @@ public partial class MainWindow : Window
{
InitializeComponent();
_report = report;
Init();
Application.Current.SetMainWindow(this);
}
private void Init()
{
this.DataContext = ViewModel = new MainViewModel();
ViewModel.UpdateDataGridColumns = UpdateDataGridColumnsByType;
var columns = report.Reporter.Formater.RepColumns;
var datas = report.GetAllReportEntries();
var columns = _report.Reporter.Formater.RepColumns;
var datas = _report.GetAllReportEntries();
this.datas = datas;
this.reportColumns = columns;
ViewModel.DataColumns = [];
@ -139,7 +145,7 @@ public partial class MainWindow : Window
{
try
{
Growl.Register("Message", GrowlParent);
LoadingMask.Visibility = Visibility.Visible;
this.Dispatcher.BeginInvoke(async delegate ()
{
@ -209,12 +215,20 @@ public partial class MainWindow : Window
}
else
{
if (ViewModel.NameType == ExportFileNameType.ProjectNo && string.IsNullOrEmpty(ViewModel.ProjectNo))
{
FlexMessageBox.Warning($"请输入项目号!");
}
else
{
SaveFileDialog saveFileDialog = new()
{
Filter = "MS Excel (*.xlsx)|*.xlsx",//Singleton<LRS>.Instance["Report_ExpFilter", "Report_ExpFilter"],
FilterIndex = 1,
//FileName = $"{单芯线下单}{DateTime.Now:yyyy_MM_dd}.xlsx",
FileName = $"{ViewModel.MechanismName}&{ViewModel.MechanismNo}.xlsx",
FileName = $"{GetFileName()}.xlsx",
AddExtension = true,
InitialDirectory = StudioSettings.Instance.ReportExport_Path,
CheckPathExists = true
@ -226,11 +240,26 @@ public partial class MainWindow : Window
}
}
}
}
catch (System.Exception ex)
{
FlexMessageBox.Error($"{ex}");
}
}
private string GetFileName()
{
if (ViewModel.NameType == ExportFileNameType.ProjectNo)
{
return $"{ViewModel.ProjectNo}";
}
if (ViewModel.NameType == ExportFileNameType.Mechanism)
{
return $"{ViewModel.MechanismNo}&{ViewModel.MechanismName}";
}
return $"{ViewModel.CustomFileName}";
}
/// <summary>
/// 忽略异常
/// </summary>
@ -480,4 +509,48 @@ public partial class MainWindow : Window
Trace.WriteLine(e.Info.ToString());
ViewModel.SearchByWireName(e.Info);
}
private void RefreshReportDataBtn_Click(object sender, RoutedEventArgs e)
{
if (_report != null)
{
var isNeedUpdate = FlexReport.IsUpToDate(_report);
if (!isNeedUpdate)
{
if (FlexMessageBox.Warning(FlexMessageBox.Buttons.OK_CANCEL,
"Report",
"是否更新报表数据?", false) == System.Windows.Forms.DialogResult.OK)
{
_report.UpdateReport();
Init();
try
{
LoadingMask.Visibility = Visibility.Visible;
this.Dispatcher.BeginInvoke(async delegate ()
{
ExcelHelper.CheckAndGetCache(true);
await LoadDataAsync(datas, reportColumns);
});
}
catch (System.Exception ex)
{
FlexMessageBox.Error($"{ex}");
}
}
}
else
{
try
{
Growl.Success("报表数据已是最新!", "Message");
}
catch (Exception)
{
}
}
}
}
}

View File

@ -46,6 +46,6 @@ using System.Windows;
// 生成号
// 修订号
//
[assembly: AssemblyVersion("1.0.0.17")]
[assembly: AssemblyFileVersion("1.0.0.17")]
[assembly: AssemblyInformationalVersion("1.0.0.17")]
[assembly: AssemblyVersion("1.0.0.18")]
[assembly: AssemblyFileVersion("1.0.0.18")]
[assembly: AssemblyInformationalVersion("1.0.0.18")]

View File

@ -0,0 +1,6 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml" />
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

View File

@ -0,0 +1,18 @@
namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
{
public enum ExportFileNameType
{
/// <summary>
/// 项目名
/// </summary>
ProjectNo,
/// <summary>
/// 机构信息 -> 机构号&机构名
/// </summary>
Mechanism,
/// <summary>
/// 自定义
/// </summary>
Custom
}
}

View File

@ -0,0 +1,29 @@
using System;
using System.Globalization;
using System.Windows.Data;
namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
{
public class NameTypeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var flag = (ExportFileNameType)value;
if (!Enum.IsDefined(typeof(ExportFileNameType), flag))
{
return false;
}
return flag == (ExportFileNameType)parameter;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is not bool isChecked)
{
throw new InvalidOperationException("The value must be a bool");
}
return isChecked ? (ExportFileNameType)parameter : Binding.DoNothing;
}
}
}

View File

@ -1,5 +1,4 @@
using EPLAN.Harness.Common.Extensions;
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
using System;
using System.Collections.Generic;
@ -272,23 +271,31 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
}
else
{
#if DEBUG
//var newModel = $"RV-{item.WireColor}-1x{item.CrossSection}-{item.WireLength + 5}-16×N2-{item.WireNumber}";
var newModel = GenWireModel(item.WireColor, item.CrossSection, $"{double.Parse(item.WireLength) + 5}_add_5", item.WireNumber);
#else
var newModel = GenWireModel(item.WireColor, item.CrossSection, $"{double.Parse(item.WireLength) + 5}", item.WireNumber);
#endif
if (StuffedData.Any(it => it.Model == newModel))
{
//var newModel2 = $"RV-{item.WireColor}-1x{item.CrossSection}-{item.WireLength + 10}-16×N2-{item.WireNumber}";
#if DEBUG
var newModel2 = GenWireModel(item.WireColor, item.CrossSection, $"{double.Parse(item.WireLength) + 10}_add_10", item.WireNumber);
#else
var newModel2 = GenWireModel(item.WireColor, item.CrossSection, $"{double.Parse(item.WireLength) + 10}", item.WireNumber);
#endif
if (StuffedData.Any(it => it.Model == newModel2))
SetItemError(item, $"{item.Model} 该型号存在重复!\r\n");
else
{
item.WireLength += 10;
item.WireLength = $"{double.Parse(item.WireLength) + 10}";
item.Model = newModel2;
}
}
else
{
item.WireLength += 5;
item.WireLength = $"{double.Parse(item.WireLength) + 5}";
item.Model = newModel;
}
}

View File

@ -165,6 +165,28 @@ public partial class MainViewModel : INotifyPropertyChanged
}
}
private ExportFileNameType _nameType;
public ExportFileNameType NameType
{
get => _nameType;
set
{
_nameType = value;
OnPropertyChanged(nameof(NameType));
FormUISettings.Instance.SetValue("NameType", $"{NameType}");
FormUISettings.Instance.SaveSingleton();
}
}
private string _customFileName;
public string CustomFileName
{
get => _customFileName;
set
{
_customFileName = value;
OnPropertyChanged(nameof(CustomFileName));
}
}
private bool _toSourceAndMinSelf;
public bool ToSourceAndMinSelf
{
@ -192,8 +214,7 @@ public partial class MainViewModel : INotifyPropertyChanged
}
return Task.FromResult(dataColumns);
}
public Task<List<ReportModel>> LoadReportDataAsync(IEnumerable<BaseReportEntry> data, List<ReportColumn> columns)
private void LoadSavedUISettings()
{
var savedFlagType = FormUISettings.Instance.GetValue("FlagType") ?? WireFlagType.Dual;
if (Enum.IsDefined(typeof(WireFlagType), savedFlagType))
@ -204,6 +225,19 @@ public partial class MainViewModel : INotifyPropertyChanged
{
FlagType = WireFlagType.Dual;
}
var savedNameType = FormUISettings.Instance.GetValue("NameType") ?? ExportFileNameType.Mechanism;
if (Enum.IsDefined(typeof(ExportFileNameType), savedNameType))
{
NameType = (ExportFileNameType)Enum.Parse(typeof(ExportFileNameType), savedNameType.ToString());
}
else
{
NameType = ExportFileNameType.Mechanism;
}
}
public Task<List<ReportModel>> LoadReportDataAsync(IEnumerable<BaseReportEntry> data, List<ReportColumn> columns)
{
LoadSavedUISettings();
var reportDatas = new ConcurrentBag<ReportModel>();
//foreach (var entry in data)

View File

@ -28,6 +28,6 @@ using System.Runtime.InteropServices;
// 生成号
// 修订号
//
[assembly: AssemblyVersion("1.0.0.16")]
[assembly: AssemblyFileVersion("1.0.0.16")]
[assembly: AssemblyVersion("1.0.0.18")]
[assembly: AssemblyFileVersion("1.0.0.18")]
[assembly: AssemblyInformationalVersion("1.0.0.16")]