478 lines
16 KiB
C#
478 lines
16 KiB
C#
![]() |
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Collections.ObjectModel;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Web.UI.WebControls;
|
|||
|
using System.Windows;
|
|||
|
using System.Windows.Forms;
|
|||
|
using System.Windows.Input;
|
|||
|
using System.Windows.Interop;
|
|||
|
using System.Windows.Media;
|
|||
|
using DryIoc;
|
|||
|
using Prism.Dialogs;
|
|||
|
using SWS.CAD.Models;
|
|||
|
using SWS.CAD.Services;
|
|||
|
using SWS.CAD.ViewModels.myViewModelBase;
|
|||
|
using SWS.CAD.Views.CustomControl;
|
|||
|
using SWS.CAD.Views.Dialog;
|
|||
|
using Telerik.Windows.Controls;
|
|||
|
using Telerik.Windows.Controls.VirtualKeyboard;
|
|||
|
using Unity;
|
|||
|
using static SWS.CAD.Services.IOModuleService;
|
|||
|
|
|||
|
namespace SWS.CAD.ViewModels
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 电缆连接新建端子排的ViewModel
|
|||
|
/// </summary>
|
|||
|
public class DialogCableConnection_NewStripViewModel : DialogBase, IDialogAware
|
|||
|
{
|
|||
|
#region 页面渲染字段
|
|||
|
private ObservableCollection<ec_PanelStrip> _StripList = new ObservableCollection<ec_PanelStrip>();
|
|||
|
/// <summary>
|
|||
|
/// 端子排集合
|
|||
|
/// </summary>
|
|||
|
public ObservableCollection<ec_PanelStrip> StripList
|
|||
|
{
|
|||
|
get { return _StripList; }
|
|||
|
set
|
|||
|
{
|
|||
|
_StripList = value;
|
|||
|
RaisePropertyChanged(nameof(StripList));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private ec_PanelStrip _SelectedStrip;
|
|||
|
/// <summary>
|
|||
|
/// 当前选择的端子排
|
|||
|
/// </summary>
|
|||
|
public ec_PanelStrip SelectedStrip
|
|||
|
{
|
|||
|
get { return _SelectedStrip; }
|
|||
|
set
|
|||
|
{
|
|||
|
_SelectedStrip = value;
|
|||
|
RaisePropertyChanged(nameof(SelectedStrip));
|
|||
|
UpdaStrip(_SelectedStrip);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private ObservableCollection<StripInfo> _StripInfos = new ObservableCollection<StripInfo>();
|
|||
|
/// <summary>
|
|||
|
/// 表格数据源
|
|||
|
/// </summary>
|
|||
|
public ObservableCollection<StripInfo> StripInfos
|
|||
|
{
|
|||
|
get { return _StripInfos; }
|
|||
|
set
|
|||
|
{
|
|||
|
_StripInfos = value;
|
|||
|
RaisePropertyChanged(nameof(StripInfos));
|
|||
|
}
|
|||
|
}
|
|||
|
private StripInfo _SelectedStripInfo;
|
|||
|
/// <summary>
|
|||
|
/// 选中的表格行
|
|||
|
/// </summary>
|
|||
|
public StripInfo SelectedStripInfo
|
|||
|
{
|
|||
|
get { return _SelectedStripInfo; }
|
|||
|
set
|
|||
|
{
|
|||
|
_SelectedStripInfo = value;
|
|||
|
RaisePropertyChanged(nameof(SelectedStripInfo));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private string _NewStripName;
|
|||
|
/// <summary>
|
|||
|
/// 新端子排名称
|
|||
|
/// </summary>
|
|||
|
public string NewStripName
|
|||
|
{
|
|||
|
get { return _NewStripName; }
|
|||
|
set
|
|||
|
{
|
|||
|
_NewStripName = value;
|
|||
|
RaisePropertyChanged(nameof(NewStripName));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
//接口服务
|
|||
|
private EnginedataService _enginedataService;
|
|||
|
IOModuleService _iOModuleService;
|
|||
|
public DialogCableConnection_NewStripViewModel()
|
|||
|
{
|
|||
|
_enginedataService = GlobalObject.container.Resolve<EnginedataService>();
|
|||
|
_iOModuleService = GlobalObject.container.Resolve<IOModuleService>();
|
|||
|
}
|
|||
|
public DialogCloseListener RequestClose { get; }
|
|||
|
|
|||
|
public bool CanCloseDialog()
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public void OnDialogClosed()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
private ec_Panel Panel;
|
|||
|
private ec_Cable ResCableEngID;
|
|||
|
private string comeFrom;
|
|||
|
public async void OnDialogOpened(IDialogParameters parameters)
|
|||
|
{
|
|||
|
|
|||
|
title = "新建端子排";
|
|||
|
ResCableEngID = parameters.GetValue<ec_Cable>(GlobalObject.dialogPar.para1.ToString());
|
|||
|
ResCableEngID = await _iOModuleService.GetCableByEngID(ResCableEngID.EngineerDataID);
|
|||
|
//先判断是左边或者右边
|
|||
|
comeFrom = parameters.GetValue<string>(GlobalObject.dialogPar.info.ToString());
|
|||
|
if (comeFrom.Equals("Fo"))
|
|||
|
{
|
|||
|
//获取左边的设备对象
|
|||
|
Panel = ResCableEngID.FromPanel;
|
|||
|
}
|
|||
|
if (comeFrom.Equals("To"))
|
|||
|
{
|
|||
|
//获取右边的设备对象
|
|||
|
Panel = ResCableEngID.ToPanel;
|
|||
|
}
|
|||
|
//先做排序在进行赋值
|
|||
|
StripList.AddRange(Panel.strips.OrderBy(s => s.Panel_Strip_Seq));
|
|||
|
SelectedStrip = StripList.FirstOrDefault();
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
public override void ExecuteOKCommandAsync(object para)
|
|||
|
{
|
|||
|
Prism.Dialogs.DialogParameters res = new Prism.Dialogs.DialogParameters();
|
|||
|
//res.Add(GlobalObject.dialogPar.info.ToString(), $"{TextInfo}");
|
|||
|
RequestClose.Invoke(res, ButtonResult.Yes);
|
|||
|
}
|
|||
|
public override void ExecuteCloseCommand(object parameter)
|
|||
|
{
|
|||
|
//if (smInfos.Any(s => s.IsModified == true))
|
|||
|
//{
|
|||
|
// MessageBoxResult resultMessage = MessageBox.Show("修改未保存,是否取消修改", "KunHengCAD", MessageBoxButton.OKCancel, MessageBoxImage.Question);
|
|||
|
// if (resultMessage != MessageBoxResult.OK)
|
|||
|
// {
|
|||
|
// return;
|
|||
|
// }
|
|||
|
//}
|
|||
|
if (parameter as string == "ClickNo")
|
|||
|
{
|
|||
|
RequestClose.Invoke(ButtonResult.No);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
RequestClose.Invoke(ButtonResult.Cancel);
|
|||
|
}
|
|||
|
this.Dispose();
|
|||
|
}
|
|||
|
#region 方法
|
|||
|
|
|||
|
#region 端子排下拉改变
|
|||
|
private ec_PanelStrip ResPannelStrip;
|
|||
|
public async void UpdaStrip(ec_PanelStrip ec_PanelStrip)
|
|||
|
{
|
|||
|
IsBusy = true;
|
|||
|
try
|
|||
|
{
|
|||
|
//先清空
|
|||
|
StripInfos.Clear();
|
|||
|
if (SelectedStrip != null)
|
|||
|
{
|
|||
|
var ResPanelStrip = await _iOModuleService.GetPanelStrip(SelectedStrip.StripID, false, false);
|
|||
|
if (ResPanelStrip == null) return;
|
|||
|
int count = ResPanelStrip.Channels.FirstOrDefault().Terms.Count();
|
|||
|
count = count > 17 ? count : 17;
|
|||
|
for (int i = 0; i < count; i++)
|
|||
|
{
|
|||
|
StripInfos.Add(new StripInfo() { Index = i });
|
|||
|
}
|
|||
|
foreach (var item in StripInfos)
|
|||
|
{
|
|||
|
item.StripName = "";
|
|||
|
}
|
|||
|
|
|||
|
for (int i = 0; i < count; i++)
|
|||
|
{
|
|||
|
if (i < ResPanelStrip.Channels.FirstOrDefault().Terms.Count())
|
|||
|
{
|
|||
|
StripInfos[i].StripName = ResPanelStrip.Channels.FirstOrDefault().Terms[i].Term_No;
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
|
|||
|
System.Windows.MessageBox.Show(ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|||
|
}
|
|||
|
finally
|
|||
|
{
|
|||
|
IsBusy = false;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#region 右侧按钮方法
|
|||
|
public ICommand TableButtonCmd => new DelegateCommand(TableButton_Click);
|
|||
|
/// <summary>
|
|||
|
/// 右侧按钮点击事件
|
|||
|
/// </summary>
|
|||
|
/// <param name="parameter"></param>
|
|||
|
public virtual async void TableButton_Click(object parameter)
|
|||
|
{
|
|||
|
#region 删除
|
|||
|
if (parameter.ToString().Equals("删除"))
|
|||
|
{
|
|||
|
if (SelectedStrip != null)
|
|||
|
{
|
|||
|
MessageBoxResult result = System.Windows.MessageBox.Show($"确定删除端子排[{SelectedStrip.StripName}]吗?", "KunHengCAD", MessageBoxButton.OKCancel, MessageBoxImage.Question);
|
|||
|
if (result == MessageBoxResult.OK)
|
|||
|
{
|
|||
|
var httpres = await _iOModuleService.DeletePanelStrip(SelectedStrip.StripID);
|
|||
|
if (httpres == null)
|
|||
|
{
|
|||
|
ResCableEngID = await _iOModuleService.GetCableByEngID(ResCableEngID.EngineerDataID);
|
|||
|
if (comeFrom.Equals("Fo"))
|
|||
|
{
|
|||
|
Panel = ResCableEngID.FromPanel;
|
|||
|
}
|
|||
|
if (comeFrom.Equals("To"))
|
|||
|
{
|
|||
|
Panel = ResCableEngID.ToPanel;
|
|||
|
}
|
|||
|
StripList.Clear();
|
|||
|
StripList.AddRange(Panel.strips.OrderBy(s => s.Panel_Strip_Seq));
|
|||
|
SelectedStrip = StripList.FirstOrDefault();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 更新
|
|||
|
if (parameter.ToString().Equals("更新"))
|
|||
|
{
|
|||
|
var SavePanelStrip = await _iOModuleService.GetPanelStrip(SelectedStrip.StripID, false, false);
|
|||
|
if (SavePanelStrip == null) return;
|
|||
|
if (SavePanelStrip.Channels.FirstOrDefault().Terms == null)
|
|||
|
{
|
|||
|
SavePanelStrip.Channels.FirstOrDefault().Terms = new List<ec_PanelStripTerm>();
|
|||
|
}
|
|||
|
foreach (var StripInfo in StripInfos)
|
|||
|
{
|
|||
|
|
|||
|
if (StripInfo.IsModified)
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(StripInfo.StripName))
|
|||
|
{
|
|||
|
var term = SavePanelStrip.Channels.FirstOrDefault().Terms.Where(t => t.Term_Seq == StripInfo.Index).FirstOrDefault();
|
|||
|
if (term != null)
|
|||
|
{
|
|||
|
term.NeedRemove = true;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
var term = SavePanelStrip.Channels.FirstOrDefault().Terms.Where(t => t.Term_Seq == StripInfo.Index).FirstOrDefault();
|
|||
|
if (term == null)
|
|||
|
{
|
|||
|
term = new ec_PanelStripTerm();
|
|||
|
}
|
|||
|
if (term != null)
|
|||
|
{
|
|||
|
term.ChannelID = SavePanelStrip.Channels.FirstOrDefault().ChannelID;
|
|||
|
term.CreateTime = SavePanelStrip.CreateTime;
|
|||
|
term.CreateUserID = SavePanelStrip.CreateUserID;
|
|||
|
|
|||
|
term.NeedRemove = false;
|
|||
|
term.StripID = SavePanelStrip.StripID;
|
|||
|
|
|||
|
term.Term_No = StripInfo.StripName;
|
|||
|
term.Term_Seq = StripInfo.Index;
|
|||
|
|
|||
|
//term.UpdateTime = SavePanelStrip.CreateTime;
|
|||
|
//term.UpdateUserID = SavePanelStrip.CreateUserID;
|
|||
|
|
|||
|
SavePanelStrip.Channels.FirstOrDefault().Terms.Add(term);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
var res = await _iOModuleService.SavePanelStripNoChannel(SavePanelStrip);
|
|||
|
if (res != null)
|
|||
|
{
|
|||
|
ResCableEngID = await _iOModuleService.GetCableByEngID(ResCableEngID.EngineerDataID);
|
|||
|
if (comeFrom.Equals("Fo"))
|
|||
|
{
|
|||
|
Panel = ResCableEngID.FromPanel;
|
|||
|
}
|
|||
|
if (comeFrom.Equals("To"))
|
|||
|
{
|
|||
|
Panel = ResCableEngID.ToPanel;
|
|||
|
}
|
|||
|
StripList.Clear();
|
|||
|
StripList.AddRange(Panel.strips.OrderBy(s => s.Panel_Strip_Seq));
|
|||
|
SelectedStrip = StripList.Where(s => s.StripName.Equals(SavePanelStrip.StripName)).FirstOrDefault();
|
|||
|
System.Windows.MessageBox.Show("端子更新成功", "KunHengCAD", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
return;
|
|||
|
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 新增
|
|||
|
if (parameter.ToString().Equals("新增"))
|
|||
|
{
|
|||
|
if (!string.IsNullOrEmpty(NewStripName))
|
|||
|
{
|
|||
|
|
|||
|
ec_PanelStrip panelStrip = new ec_PanelStrip()
|
|||
|
{
|
|||
|
StripName = NewStripName,
|
|||
|
PanelID = Panel.PanelID,
|
|||
|
CreateUserID = GlobalObject.userInfo.userId,
|
|||
|
CreateTime = DateTime.Now,
|
|||
|
UpdateUserID = GlobalObject.userInfo.userId,
|
|||
|
UpdateTime = DateTime.Now,
|
|||
|
Panel_Strip_Seq = Panel.strips.Count(),
|
|||
|
};
|
|||
|
|
|||
|
var res = await _iOModuleService.SavePanelStripNoChannel(panelStrip);
|
|||
|
if (res != null)
|
|||
|
{
|
|||
|
ResCableEngID = await _iOModuleService.GetCableByEngID(ResCableEngID.EngineerDataID);
|
|||
|
if (comeFrom.Equals("Fo"))
|
|||
|
{
|
|||
|
Panel = ResCableEngID.FromPanel;
|
|||
|
}
|
|||
|
if (comeFrom.Equals("To"))
|
|||
|
{
|
|||
|
Panel = ResCableEngID.ToPanel;
|
|||
|
}
|
|||
|
StripList.Clear();
|
|||
|
StripList.AddRange(Panel.strips.OrderBy(s => s.Panel_Strip_Seq));
|
|||
|
StripList.OrderBy(s=>s.Panel_Strip_Seq);
|
|||
|
SelectedStrip = StripList.Where(s => s.StripName.Equals(NewStripName)).FirstOrDefault();
|
|||
|
}
|
|||
|
}
|
|||
|
return;
|
|||
|
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 清空端子
|
|||
|
if (parameter.ToString().Equals("清空端子"))
|
|||
|
{
|
|||
|
if (StripInfos != null)
|
|||
|
{
|
|||
|
foreach (var StripInfo in StripInfos)
|
|||
|
{
|
|||
|
StripInfo.StripName = "";
|
|||
|
StripInfo.IsModified = true;
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
return;
|
|||
|
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 添加一页
|
|||
|
if (parameter.ToString().Equals("添加一页"))
|
|||
|
{
|
|||
|
int index = StripInfos.Count();
|
|||
|
for (int i = 0; i < 17; i++)
|
|||
|
{
|
|||
|
index++;
|
|||
|
StripInfos.Add(new StripInfo() { Index = index });
|
|||
|
}
|
|||
|
|
|||
|
return;
|
|||
|
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 表格编辑结束事件
|
|||
|
public ICommand EditEndCmd => new DelegateCommand(EditEnd);
|
|||
|
/// <summary>
|
|||
|
/// 编辑结束事件
|
|||
|
/// </summary>
|
|||
|
/// <param name="parameter"></param>
|
|||
|
public virtual void EditEnd(object parameter)
|
|||
|
{
|
|||
|
//做个标记表示该项修改过
|
|||
|
SelectedStripInfo.IsModified = true;
|
|||
|
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
public class StripInfo : DialogBase
|
|||
|
{
|
|||
|
private int _Index;
|
|||
|
/// <summary>
|
|||
|
/// 序号
|
|||
|
/// </summary>
|
|||
|
public int Index
|
|||
|
{
|
|||
|
get { return _Index; }
|
|||
|
set
|
|||
|
{
|
|||
|
_Index = value;
|
|||
|
RaisePropertyChanged(nameof(Index));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private string _StripName;
|
|||
|
/// <summary>
|
|||
|
/// 端子名
|
|||
|
/// </summary>
|
|||
|
public string StripName
|
|||
|
{
|
|||
|
get { return _StripName; }
|
|||
|
set
|
|||
|
{
|
|||
|
_StripName = value;
|
|||
|
RaisePropertyChanged(nameof(StripName));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private bool _IsModified;
|
|||
|
/// <summary>
|
|||
|
/// 是否修改
|
|||
|
/// </summary>
|
|||
|
public bool IsModified
|
|||
|
{
|
|||
|
get { return _IsModified; }
|
|||
|
set { _IsModified = value; RaisePropertyChanged(nameof(IsModified)); }
|
|||
|
}
|
|||
|
}
|
|||
|
}
|