|
@@ -15,6 +15,7 @@ using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
+using System.Windows.Controls;
|
|
|
|
|
|
namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
{
|
|
@@ -41,16 +42,15 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
_dialog = dialog;
|
|
|
_logger = logger;
|
|
|
QueryCommand = new DelegateCommand<object>(Query);
|
|
|
- AddCommand = new DelegateCommand<object>(Add);
|
|
|
+
|
|
|
ExportCommand = new DelegateCommand<string>(Export);
|
|
|
- EditCommand = new DelegateCommand<object>(Edit);
|
|
|
- DeleteCommand = new DelegateCommand<object>(Delete);
|
|
|
+;
|
|
|
ResetCommand = new DelegateCommand<object>(Reset);
|
|
|
OnLoadCommand = new DelegateCommand(OnLoad);
|
|
|
//手动 自动测试
|
|
|
AutoTestCommand = new DelegateCommand<object>(AutoDest);
|
|
|
ManualTestCommand = new DelegateCommand<object>(ManualTest);
|
|
|
- GetPprojectConfig();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -68,6 +68,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
{
|
|
|
DeviceKindNameList = _iBasicDeviceKindService.FindAllDeviceKind();
|
|
|
ProjectNameList = _iBasicProjectService.FindAllProject();
|
|
|
+ GetPprojectConfig();
|
|
|
}
|
|
|
private void Reset(object obj)
|
|
|
{
|
|
@@ -83,10 +84,14 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
/// <param name="obj"></param>
|
|
|
private void AutoDest(object obj)
|
|
|
{
|
|
|
+ object[] multiObj = obj as object[];
|
|
|
+
|
|
|
//测试方案明细主键ID
|
|
|
- long id = Convert.ToInt64(obj);
|
|
|
+ long id =(long) multiObj[0];
|
|
|
+ long deviceId= (long)multiObj[1];
|
|
|
DialogParameters parm = new DialogParameters();
|
|
|
parm.Add("Key", id);
|
|
|
+ parm.Add("Key2", deviceId);
|
|
|
//弹出详情对话框
|
|
|
//弹出详情对话框
|
|
|
_dialog.ShowDialog("AutoTestView", parm, async callback =>
|
|
@@ -102,10 +107,14 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
|
|
|
private void ManualTest(object obj)
|
|
|
{
|
|
|
- //测试方案主键ID
|
|
|
- long id = Convert.ToInt64(obj);
|
|
|
+ object[] multiObj = obj as object[];
|
|
|
+
|
|
|
+ //测试方案明细主键ID
|
|
|
+ long id = (long)multiObj[0];
|
|
|
+ long deviceId = (long)multiObj[1];
|
|
|
DialogParameters parm = new DialogParameters();
|
|
|
parm.Add("Key", id);
|
|
|
+ parm.Add("Key2", deviceId);
|
|
|
//弹出详情对话框
|
|
|
//弹出详情对话框
|
|
|
_dialog.ShowDialog("ManualTestView", parm, async callback =>
|
|
@@ -118,74 +127,6 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
|
|
|
});
|
|
|
}
|
|
|
- /// <summary>
|
|
|
- /// 修改
|
|
|
- /// </summary>
|
|
|
- /// <param name="obj"></param>
|
|
|
- private void Edit(object obj)
|
|
|
- {
|
|
|
- int id = Convert.ToInt32(obj);
|
|
|
- var findDevice = allDeviceList.FirstOrDefault(x => (x.DeviceId == id));
|
|
|
- DialogParameters parm = new DialogParameters();
|
|
|
- parm.Add("Key", findDevice);
|
|
|
- //弹出详情对话框
|
|
|
- _dialog.ShowDialog("AddOrEditDeviceView", parm, async callback =>
|
|
|
- {
|
|
|
- if (callback.Result == ButtonResult.OK)
|
|
|
- {
|
|
|
- BasDeviceDto returnValue = callback.Parameters.GetValue<BasDeviceDto>("ReturnValue");
|
|
|
-
|
|
|
- if (returnValue != null)
|
|
|
- {
|
|
|
- //更新时间
|
|
|
- returnValue.UpdateTime = DateTime.Now;
|
|
|
- returnValue.UpdateBy = Appsession.UserName;
|
|
|
- //创建时间
|
|
|
- returnValue.CreateTime = findDevice.CreateTime;
|
|
|
- returnValue.CreateBy = findDevice?.CreateBy;
|
|
|
-
|
|
|
- var deviceKindCon = _mapper.Map<BasDeviceDto, bas_device>(returnValue);
|
|
|
- var findPlcs = allDeviceList.FindAll(x => (x.DeviceName == returnValue.DeviceName) || (x.DeviceNo == returnValue.DeviceNo));
|
|
|
- foreach (var item in findPlcs)
|
|
|
- {
|
|
|
- if (item.DeviceId != id)
|
|
|
- {
|
|
|
- MessageBox.Show("已有此设备编号,请更改名称!", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //修改
|
|
|
- deviceKindCon.device_id = id;
|
|
|
- bool isSucc = _iBasicDeviceService.Edit(deviceKindCon);
|
|
|
- if (isSucc)
|
|
|
- {
|
|
|
- //重新读取PLC
|
|
|
- GetPprojectConfig();
|
|
|
- _logger.LogInformation($"修改项目成功");
|
|
|
- MessageBox.Show("修改项目成功", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- private void Delete(object obj)
|
|
|
- {
|
|
|
- int id = Convert.ToInt32(obj);
|
|
|
- MessageBoxResult boxResult = MessageBox.Show("确认删除此条数据?", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Question);
|
|
|
- if (boxResult == MessageBoxResult.OK)
|
|
|
- {
|
|
|
- var del = _iBasicDeviceService.Delete(id);
|
|
|
- if (del)
|
|
|
- {
|
|
|
- MessageBox.Show("删除成功!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
- GetPprojectConfig();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查询
|
|
@@ -196,7 +137,8 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
conditionDevices = (from a in allDeviceList
|
|
|
where (string.IsNullOrEmpty(DeviceName) ? true : (a.DeviceName == DeviceName))
|
|
|
&& (string.IsNullOrEmpty(DeviceNo) ? true : (a.DeviceNo == DeviceNo))
|
|
|
- && (string.IsNullOrEmpty(DeviceKindName) ? true : (a.DeviceKindName == DeviceKindName))
|
|
|
+ //&& (string.IsNullOrEmpty(DeviceKindName) ? true : (a.DeviceKindId == DeviceKindName))
|
|
|
+ // && (string.IsNullOrEmpty(ProjectName) ? true : (a.ProjectId == ProjectName))
|
|
|
select a).ToList();
|
|
|
//默认显示的第一页
|
|
|
conditionDevices = conditionDevices.OrderBy(x => x.DeviceId).ToList();
|
|
@@ -243,46 +185,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
|
|
|
}
|
|
|
}
|
|
|
- /// <summary>
|
|
|
- /// 添加PLC变量
|
|
|
- /// </summary>
|
|
|
- /// <param name="obj"></param>
|
|
|
- /// <exception cref="NotImplementedException"></exception>
|
|
|
- private void Add(object obj)
|
|
|
- {
|
|
|
|
|
|
- //弹出详情对话框
|
|
|
- _dialog.ShowDialog("AddOrEditDeviceView", async callback =>
|
|
|
- {
|
|
|
- if (callback.Result == ButtonResult.OK)
|
|
|
- {
|
|
|
- BasDeviceDto returnValue = callback.Parameters.GetValue<BasDeviceDto>("ReturnValue");
|
|
|
- if (returnValue != null)
|
|
|
- {
|
|
|
- returnValue.CreateTime = DateTime.Now;
|
|
|
- returnValue.CreateBy = Appsession.UserName;
|
|
|
- returnValue.UpdateTime = DateTime.Now;
|
|
|
- returnValue.UpdateBy = Appsession.UserName;
|
|
|
- var deviceCon = _mapper.Map<BasDeviceDto, bas_device>(returnValue);
|
|
|
- var findPlc = allDeviceList.FirstOrDefault(x => (x.DeviceName == returnValue.DeviceName) || (x.DeviceNo == returnValue.DeviceNo));
|
|
|
- if (findPlc != null)
|
|
|
- {
|
|
|
- MessageBox.Show("已有此项目名称或编号,请更改!", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
|
|
|
- return;
|
|
|
- }
|
|
|
- bool isSucc = _iBasicDeviceService.Add(deviceCon);
|
|
|
- if (isSucc)
|
|
|
- {
|
|
|
- //重新读取PLC
|
|
|
- GetPprojectConfig();
|
|
|
- _logger.LogInformation($"添加项目成功");
|
|
|
- MessageBox.Show("添加项目成功!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
- }
|
|
|
/// <summary>
|
|
|
/// 获取所有项目
|
|
|
/// </summary>
|
|
@@ -290,8 +193,8 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
{
|
|
|
allDeviceList.Clear();
|
|
|
conditionDevices.Clear();
|
|
|
- var projectlist = _iBasicDeviceService.QueryList();
|
|
|
- var allDeviceKinds = _mapper.Map<List<bas_device>, List<BasDeviceDto>>(projectlist);
|
|
|
+ var devicelist = _iBasicDeviceService.QueryList();
|
|
|
+ var allDeviceKinds = _mapper.Map<List<bas_device>, List<BasDeviceDto>>(devicelist);
|
|
|
//所有测试方案
|
|
|
var schlist = _basicPlcTestSchemeService.QueryList();
|
|
|
var schDtoList = _mapper.Map<List<bas_plc_test_scheme>, List<BasicPlcTestSchemeDto>>(schlist);
|
|
@@ -299,7 +202,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
|
|
|
foreach (var item in allDeviceKinds)
|
|
|
{
|
|
|
- string deviceKind = item.DeviceKindName;
|
|
|
+ string deviceKind =_iBasicDeviceKindService.Find((int)item.DeviceKindId)?.devicekind_name;
|
|
|
//在测试方案中查找此设备类型的所有方案
|
|
|
var schs= schDtoList.FindAll(x => x.DeviceKindName == deviceKind);
|
|
|
//设备方案
|
|
@@ -310,8 +213,8 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
DeviceId = item.DeviceId,
|
|
|
DeviceNo = item.DeviceNo,
|
|
|
DeviceName = item.DeviceName,
|
|
|
- DeviceKindName = item.DeviceKindName,
|
|
|
- ProjectName = item.ProjectName,
|
|
|
+ DeviceKindId = item.DeviceKindId,
|
|
|
+ ProjectId = item.ProjectId,
|
|
|
SchemeName = sch.SchemeName,
|
|
|
SchemeId=sch.SchemeId,
|
|
|
}) ;
|
|
@@ -320,8 +223,8 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
DeviceId = item.DeviceId,
|
|
|
DeviceNo = item.DeviceNo,
|
|
|
DeviceName = item.DeviceName,
|
|
|
- DeviceKindName = item.DeviceKindName,
|
|
|
- ProjectName = item.ProjectName,
|
|
|
+ DeviceKindId = item.DeviceKindId,
|
|
|
+ ProjectId = item.ProjectId,
|
|
|
SchemeName = sch.SchemeName,
|
|
|
SchemeId = sch.SchemeId,
|
|
|
});
|
|
@@ -360,17 +263,10 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
#region 命令绑定
|
|
|
|
|
|
public DelegateCommand<object> QueryCommand { set; get; }
|
|
|
- public DelegateCommand<object> AddCommand { set; get; }
|
|
|
+
|
|
|
public DelegateCommand<string> ExportCommand { set; get; }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 表格删除
|
|
|
- /// </summary>
|
|
|
- public DelegateCommand<Object> DeleteCommand { set; get; }
|
|
|
- /// <summary>
|
|
|
- /// 表格编辑按钮
|
|
|
- /// </summary>
|
|
|
- public DelegateCommand<Object> EditCommand { set; get; }
|
|
|
+
|
|
|
public DelegateCommand<object> ResetCommand { set; get; }
|
|
|
|
|
|
public DelegateCommand OnLoadCommand { set; get; }
|