From a5f6a79a3416e4445d6a78348137a4695a7adc3f Mon Sep 17 00:00:00 2001 From: Tyrone CT Date: Tue, 27 May 2025 08:56:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B7=B2=E7=9F=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CapMachine.Model/ProgramSeg.cs | 6 ++ .../ViewModels/DialogExpInfoViewModel.cs | 26 +++++- .../ViewModels/ProConfigViewModel.cs | 86 ++++++++++++++++++- CapMachine.Wpf/Views/DialogExpInfoView.xaml | 28 +++++- CapMachine.Wpf/Views/ProConfigView.xaml | 30 +++++++ CapMachine.Wpf/Views/ProConfigView.xaml.cs | 2 + 6 files changed, 174 insertions(+), 4 deletions(-) diff --git a/CapMachine.Model/ProgramSeg.cs b/CapMachine.Model/ProgramSeg.cs index 94ddd6e..4cb6458 100644 --- a/CapMachine.Model/ProgramSeg.cs +++ b/CapMachine.Model/ProgramSeg.cs @@ -49,6 +49,11 @@ namespace CapMachine.Model [Column(ServerTime = DateTimeKind.Local, CanUpdate = false)] public DateTime CreateTime { get; set; } + ///// + ///// 当前的步骤的时间 + ///// + //[Column(IsIgnore = true)] + //public int ProSegTime { get; set; } /// /// ///////////////////////////////////////////导航属性/////////////////////////////////////////////////////// @@ -56,5 +61,6 @@ namespace CapMachine.Model public List? ProSteps { get; set; } + } } diff --git a/CapMachine.Wpf/ViewModels/DialogExpInfoViewModel.cs b/CapMachine.Wpf/ViewModels/DialogExpInfoViewModel.cs index db9301c..ca0eb14 100644 --- a/CapMachine.Wpf/ViewModels/DialogExpInfoViewModel.cs +++ b/CapMachine.Wpf/ViewModels/DialogExpInfoViewModel.cs @@ -16,7 +16,7 @@ namespace CapMachine.Wpf.ViewModels /// public class DialogExpInfoViewModel : DialogViewModel { - public DialogExpInfoViewModel(ConfigService configService, IFreeSql freeSql,PPCService pPCService, IMapper mapper, MachineRtDataService machineRtDataService) + public DialogExpInfoViewModel(ConfigService configService, IFreeSql freeSql, PPCService pPCService, IMapper mapper, MachineRtDataService machineRtDataService) { this.Title = "试验信息拓展设置"; ConfigService = configService; @@ -25,6 +25,20 @@ namespace CapMachine.Wpf.ViewModels this.Mapper = mapper; MachineRtDataService = machineRtDataService; + // 获取ProgramSeg的数据 + var workCondList = FreeSql.Select() + .ToList() + .Select(g => g.Name) + .ToList(); + + // 转换为CbxItems集合,都是文本内容 + WorkCondCbxItems = new ObservableCollection( + workCondList.Select(workCond => new CbxItems + { + Key = workCond, + Text = workCond + })); + } public ConfigService ConfigService { get; } @@ -40,6 +54,16 @@ namespace CapMachine.Wpf.ViewModels public IFreeSql FreeSql { get; } public PPCService PPCService { get; } + private ObservableCollection _WorkCondCbxItems; + /// + /// 供选择的工况集合信息 + /// + public ObservableCollection WorkCondCbxItems + { + get { return _WorkCondCbxItems; } + set { _WorkCondCbxItems = value; RaisePropertyChanged(); } + } + /// /// AutoMap映射 /// diff --git a/CapMachine.Wpf/ViewModels/ProConfigViewModel.cs b/CapMachine.Wpf/ViewModels/ProConfigViewModel.cs index 0672408..0990da1 100644 --- a/CapMachine.Wpf/ViewModels/ProConfigViewModel.cs +++ b/CapMachine.Wpf/ViewModels/ProConfigViewModel.cs @@ -182,6 +182,8 @@ namespace CapMachine.Wpf.ViewModels //新选择ProSeg后,此时还没有选择具体的速度等参数,需要禁用设置,等选择了具体的ProStep后再启用 SpeedTabControlEnable = false; OtherParTabControlEnable = false; + + SumProSegTime(); } @@ -214,6 +216,17 @@ namespace CapMachine.Wpf.ViewModels set { _SelectedProgramSeg = value; RaisePropertyChanged(); } } + private string _ProSegTime; + /// + /// 当前程序段的时间 + /// + public string ProSegTime + { + get { return _ProSegTime; } + set { _ProSegTime = value; RaisePropertyChanged(); } + } + + /// /// 加载最新的数据 /// @@ -432,7 +445,7 @@ namespace CapMachine.Wpf.ViewModels //获取全部的数据 //RefreshProSeg(); - + MessageBox.Show("更新后请重新选中程序后,【总循环次数】和【总时间】将会正确显示", "数据更新", MessageBoxButton.OK, MessageBoxImage.Hand); } else if (par.Result == ButtonResult.Cancel) { @@ -2785,6 +2798,8 @@ namespace CapMachine.Wpf.ViewModels } + //更新后检测时间是否匹配并界面提示 + CheckSpeedSlopListTime(); } @@ -3182,6 +3197,8 @@ namespace CapMachine.Wpf.ViewModels //新增时,总是在斜率中 SelectedProStepDto.SpeedCycle!.IsSlop = true; SelectedProStepDto.SpeedCycle!.Cycle = SelectedProStepDto.SpeedCycle.Cycle; + + SumProSegTime(); //if (MeterSpeedExDto.TotalSlopTime != GetKeepTimeBySpeed()) //{ // MeterSpeedExDto.IsTimeOk = false; @@ -3192,6 +3209,73 @@ namespace CapMachine.Wpf.ViewModels //} } + /// + /// 计算程序段的总时间 + /// 按照速度为牟定参数 + /// + public void SumProSegTime() + { + //更新程序段总时间,ProSeg + if (SelectedProgramSeg != null && SelectedProgramSeg.ProSteps != null + && SelectedProgramSeg.ProSteps.Count() > 0) + { + var SegStepTime = 0; + foreach (var itemProStep in SelectedProgramSeg.ProSteps) + { + if (itemProStep.MeterSpeeds != null && itemProStep.MeterSpeeds.Count()>0) + { + if (itemProStep.MeterSpeeds.FirstOrDefault()!.ValueType == ConfigValueType.Slope) + { + //带斜率 + var SegTimeCell = itemProStep.SpeedCycle * itemProStep.MeterSpeeds.Sum(a => a.KeepTime); + SegStepTime = SegStepTime + SegTimeCell; + } + else + { + //常值数据 + SegStepTime = SegStepTime + itemProStep.MeterSpeeds.Sum(a => a.KeepTime); + } + } + else + { + SegStepTime = 0; + } + } + + ProSegTime = ConvertSecondsToTimeString(SegStepTime * SelectedProgramSeg.ProRepeat); + + } + } + + /// + /// 秒数转时间字符串 + /// + /// + /// + public string ConvertSecondsToTimeString(int totalSeconds) + { + TimeSpan time = TimeSpan.FromSeconds(totalSeconds); + List parts = new List(); + + if (time.Hours > 0) + { + parts.Add($"{time.Hours}小时"); + parts.Add($"{time.Minutes}分"); + parts.Add($"{time.Seconds}秒"); + } + else if (time.Minutes > 0) + { + parts.Add($"{time.Minutes}分"); + parts.Add($"{time.Seconds}秒"); + } + else + { + parts.Add($"{time.Seconds}秒"); + } + + return string.Join("", parts); + } + private string MeterSpeedToString(List data) { var strInfo = new StringBuilder(); diff --git a/CapMachine.Wpf/Views/DialogExpInfoView.xaml b/CapMachine.Wpf/Views/DialogExpInfoView.xaml index ae87d4c..62c6676 100644 --- a/CapMachine.Wpf/Views/DialogExpInfoView.xaml +++ b/CapMachine.Wpf/Views/DialogExpInfoView.xaml @@ -105,10 +105,34 @@ Binding="{Binding Name}" Header="名称" IsReadOnly="{Binding Source={StaticResource Proxy}, Path=Data.IsComplete}" /> - + + + + + + + + + + + + + + + + + + + + diff --git a/CapMachine.Wpf/Views/ProConfigView.xaml.cs b/CapMachine.Wpf/Views/ProConfigView.xaml.cs index ee2e615..cbe5b02 100644 --- a/CapMachine.Wpf/Views/ProConfigView.xaml.cs +++ b/CapMachine.Wpf/Views/ProConfigView.xaml.cs @@ -52,5 +52,7 @@ namespace CapMachine.Wpf.Views //} } + + } }