
# Conflicts: # newFront/c#前端/SWS.CAD/Commands.cs # newFront/c#前端/SWS.Electrical/obj/Debug/Views/DialogTest2.g.i.cs # newFront/c#前端/SWS.Electrical/obj/Debug/Views/SWSDialogWindow.g.cs # newFront/c#前端/SWS.Electrical/obj/Debug/Views/SWSDialogWindow.g.i.cs # newFront/c#前端/SWS.WPF/obj/Debug/Views/CustomDialogWindow.g.cs # newFront/c#前端/SWS.WPF/obj/Debug/Views/CustomDialogWindow.g.i.cs
345 lines
12 KiB
C#
345 lines
12 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Collections.ObjectModel;
|
||
using SWS.CAD.ViewModels.myViewModelBase;
|
||
using System.Windows.Input;
|
||
using Telerik.Windows.Controls;
|
||
using Prism.Services.Dialogs;
|
||
using SWS.Commons;
|
||
using SWS.Model;
|
||
using SWS.Service;
|
||
using Unity;
|
||
using System.Linq;
|
||
using Telerik.Windows.Controls.MaskedInput.Tokens.Numeric;
|
||
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
|
||
|
||
namespace SWS.CAD.ViewModels
|
||
{
|
||
public class DialogCablePreAssignResultViewModel : DialogBase, IDialogAware
|
||
{
|
||
#region 字段
|
||
private ObservableCollection<PreAllocationResult> _PreAllocationResultls = new ObservableCollection<PreAllocationResult>();
|
||
/// <summary>
|
||
/// 预分配结果表格源
|
||
/// </summary>
|
||
public ObservableCollection<PreAllocationResult> PreAllocationResultls
|
||
{
|
||
get { return _PreAllocationResultls; }
|
||
set
|
||
{
|
||
_PreAllocationResultls = value;
|
||
RaisePropertyChanged(nameof(PreAllocationResultls));
|
||
}
|
||
}
|
||
|
||
|
||
private string _SuccessOrFailure = "分配成功";
|
||
/// <summary>
|
||
/// 选择成功还是选择失败
|
||
/// </summary>
|
||
public string SuccessOrFailure
|
||
{
|
||
get { return _SuccessOrFailure; }
|
||
set
|
||
{
|
||
_SuccessOrFailure = value;
|
||
RaisePropertyChanged(nameof(SuccessOrFailure));
|
||
UpdataPreAssignCables();
|
||
}
|
||
}
|
||
|
||
private ObservableCollection<ec_Cable> _PreAssignCables = new ObservableCollection<ec_Cable>();
|
||
/// <summary>
|
||
/// 左侧预分配电缆列表
|
||
/// </summary>
|
||
public ObservableCollection<ec_Cable> PreAssignCables
|
||
{
|
||
get { return _PreAssignCables; }
|
||
set
|
||
{
|
||
_PreAssignCables = value;
|
||
RaisePropertyChanged(nameof(PreAssignCables));
|
||
}
|
||
}
|
||
|
||
private ec_Cable _SelectedPreAssignCable;
|
||
/// <summary>
|
||
/// 选择的预分配电缆
|
||
/// </summary>
|
||
public ec_Cable SelectedPreAssignCable
|
||
{
|
||
get { return _SelectedPreAssignCable; }
|
||
set
|
||
{
|
||
_SelectedPreAssignCable = value;
|
||
RaisePropertyChanged(nameof(SelectedPreAssignCable));
|
||
UpdataPreAllocationResultls(_SelectedPreAssignCable);
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
IOModuleService _iOModuleService;
|
||
public DialogCablePreAssignResultViewModel()
|
||
{
|
||
_iOModuleService = GlobalObject.container.Resolve<IOModuleService>();
|
||
}
|
||
public string Title => "";
|
||
|
||
public event Action<IDialogResult> RequestClose;
|
||
public bool CanCloseDialog()
|
||
{
|
||
return true;
|
||
}
|
||
|
||
public void OnDialogClosed()
|
||
{
|
||
|
||
}
|
||
|
||
//全部预分配电缆
|
||
private List<ec_Cable> AllPreAssignCables;
|
||
public async void OnDialogOpened(IDialogParameters parameters)
|
||
{
|
||
//title = parameters.GetValue<string>(GlobalObject.dialogPar.title.ToString());
|
||
title = "信号预分配结果";
|
||
AllPreAssignCables = await _iOModuleService.AutoAssignCable2channel_step2();
|
||
UpdataPreAssignCables();
|
||
}
|
||
|
||
public override async void ExecuteOKCommandAsync(object para)
|
||
{
|
||
//只传入分配成功的电缆
|
||
var Cables = new List<ec_Cable>();
|
||
if (AllPreAssignCables != null)
|
||
{
|
||
foreach (var PreAssignCable in AllPreAssignCables)
|
||
{
|
||
if (PreAssignCable.Sets != null && !string.IsNullOrEmpty(PreAssignCable.Sets.FirstOrDefault().ConnectionInfo))
|
||
{
|
||
Cables.Add(PreAssignCable);
|
||
}
|
||
}
|
||
}
|
||
|
||
var resHttp = await _iOModuleService.AutoAssignCable2channel_step3(Cables);
|
||
//返回结果
|
||
IDialogParameters res = new Prism.Services.Dialogs.DialogParameters();
|
||
//res.Add(GlobalObject.dialogPar.para1.ToString(), SelectedStripParametersInfo);
|
||
RequestClose.Invoke(new DialogResult(ButtonResult.Yes, res));
|
||
}
|
||
public override void ExecuteCloseCommand(object parameter)
|
||
{
|
||
if (parameter as string == "ClickNo")
|
||
{
|
||
DialogResult res = new DialogResult(ButtonResult.No);
|
||
RequestClose.Invoke(res);
|
||
}
|
||
else
|
||
{
|
||
RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
|
||
}
|
||
this.Dispose();
|
||
}
|
||
|
||
#region 方法
|
||
/// <summary>
|
||
/// 修改预分配电缆列表,成功或者失败的电缆列表
|
||
/// </summary>
|
||
public void UpdataPreAssignCables()
|
||
{
|
||
PreAssignCables = new ObservableCollection<ec_Cable>();
|
||
if (AllPreAssignCables != null)
|
||
{
|
||
if (SuccessOrFailure.Equals("分配成功"))
|
||
{
|
||
foreach (var PreAssignCable in AllPreAssignCables)
|
||
{
|
||
if (PreAssignCable.AssignedPanel!=null)
|
||
{
|
||
if (PreAssignCable.Sets!=null&&!string.IsNullOrEmpty(PreAssignCable.Sets.FirstOrDefault().ConnectionInfo))
|
||
{
|
||
PreAssignCables.Add(PreAssignCable);
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
foreach (var PreAssignCable in AllPreAssignCables)
|
||
{
|
||
if (PreAssignCable.Sets == null || PreAssignCable.Sets.Count()==0)
|
||
{
|
||
PreAssignCables.Add(PreAssignCable);
|
||
}
|
||
else
|
||
{
|
||
if (string.IsNullOrEmpty(PreAssignCable.Sets.FirstOrDefault().ConnectionInfo))
|
||
{
|
||
PreAssignCables.Add(PreAssignCable);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 修改表格显示数据
|
||
/// </summary>
|
||
public void UpdataPreAllocationResultls(ec_Cable cable)
|
||
{
|
||
|
||
PreAllocationResultls = new ObservableCollection<PreAllocationResult>();
|
||
if (cable == null) return;
|
||
if (cable.AssignedPanel != null)
|
||
{
|
||
foreach (var Set in cable.Sets)
|
||
{
|
||
PreAllocationResult preAllocationResult = new PreAllocationResult();
|
||
preAllocationResult.CablePair = Set.CableSetName;
|
||
preAllocationResult.IOType = cable.PreAssignIOType;
|
||
preAllocationResult.ToPanel_TagNumber = cable.AssignedPanel == null ? "" : cable.AssignedPanel.TagNumber;
|
||
if (!string.IsNullOrEmpty(Set.ConnectionInfo))
|
||
{
|
||
preAllocationResult.Panel_TagNumber = string.IsNullOrEmpty(Set.ConnectionInfo) ? "" : Set.ConnectionInfo.Split('/')[0].Split(':')[1].Trim();
|
||
|
||
if (Set.ConnectionInfo.Split('/').Count()>1)
|
||
{
|
||
preAllocationResult.StripName = string.IsNullOrEmpty(Set.ConnectionInfo) ? "" : Set.ConnectionInfo.Split('/')[1].Split(':')[1].Trim();
|
||
}
|
||
}
|
||
preAllocationResult.Terms = Set.AssignedTerms==null?new ObservableCollection<ec_PanelStripTerm>(): new ObservableCollection<ec_PanelStripTerm>(Set.AssignedTerms);
|
||
PreAllocationResultls.Add(preAllocationResult);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
public ICommand HeadButtonCmd => new DelegateCommand(HeadButton_Click);
|
||
/// <summary>
|
||
/// 导出按钮
|
||
/// </summary>
|
||
/// <param name="parameter"></param>
|
||
public virtual async void HeadButton_Click(object parameter)
|
||
{
|
||
if (parameter.Equals("导出电缆预分配结果明细表"))
|
||
{
|
||
System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||
saveFileDialog.Filter = "Excel文件 (*.xlsx)|*.xlsx|所有文件 (*.*)|*.*";
|
||
saveFileDialog.Title = "选择保存路径";
|
||
|
||
if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
||
{
|
||
|
||
string selectedPath = saveFileDialog.FileName;
|
||
if (System.IO.File.Exists(selectedPath))
|
||
{ System.IO.File.Delete(selectedPath); }
|
||
|
||
var msg = await _iOModuleService.AutoAssignCable2Channel_ResExport(selectedPath);
|
||
if (string.IsNullOrEmpty(msg))
|
||
{
|
||
System.Windows.MessageBox.Show("下载文件成功!");
|
||
}
|
||
else { System.Windows.MessageBox.Show("下载文件异常:" + msg); }
|
||
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
public ICommand EditEndCmd => new DelegateCommand(EditEnd);
|
||
/// <summary>
|
||
/// 编辑结束事件
|
||
/// </summary>
|
||
/// <param name="parameter"></param>
|
||
public virtual void EditEnd(object parameter)
|
||
{
|
||
//做个标记表示该项修改过
|
||
|
||
}
|
||
#endregion
|
||
}
|
||
/// <summary>
|
||
/// 预分配结果类
|
||
/// </summary>
|
||
public class PreAllocationResult : DialogBase
|
||
{
|
||
private string _CablePair;
|
||
/// <summary>
|
||
/// 电缆对
|
||
/// </summary>
|
||
public string CablePair
|
||
{
|
||
get { return _CablePair; }
|
||
set { _CablePair = value;
|
||
RaisePropertyChanged(nameof(CablePair));
|
||
}
|
||
}
|
||
|
||
private string _IOType;
|
||
/// <summary>
|
||
/// IO类型
|
||
/// </summary>
|
||
public string IOType
|
||
{
|
||
get { return _IOType; }
|
||
set { _IOType = value;
|
||
RaisePropertyChanged(nameof(IOType));
|
||
}
|
||
}
|
||
|
||
|
||
private string _ToPanel_TagNumber;
|
||
/// <summary>
|
||
/// 预分配的系统柜
|
||
/// </summary>
|
||
public string ToPanel_TagNumber
|
||
{
|
||
get { return _ToPanel_TagNumber; }
|
||
set { _ToPanel_TagNumber = value;
|
||
RaisePropertyChanged(nameof(ToPanel_TagNumber));
|
||
}
|
||
}
|
||
|
||
private string _Panel_TagNumber;
|
||
/// <summary>
|
||
/// 实际分配的系统柜
|
||
/// </summary>
|
||
public string Panel_TagNumber
|
||
{
|
||
get { return _Panel_TagNumber; }
|
||
set { _Panel_TagNumber = value;
|
||
RaisePropertyChanged(nameof(Panel_TagNumber));
|
||
}
|
||
}
|
||
|
||
private string _StripName;
|
||
/// <summary>
|
||
/// 实际分配的端子排
|
||
/// </summary>
|
||
public string StripName
|
||
{
|
||
get { return _StripName; }
|
||
set { _StripName = value;
|
||
RaisePropertyChanged(nameof(StripName));
|
||
}
|
||
}
|
||
|
||
private ObservableCollection<ec_PanelStripTerm> _Terms;
|
||
/// <summary>
|
||
/// 实际端子
|
||
/// </summary>
|
||
public ObservableCollection<ec_PanelStripTerm> Terms
|
||
{
|
||
get { return _Terms; }
|
||
set { _Terms = value;
|
||
RaisePropertyChanged(nameof(Terms));
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
|
||
}
|