|
@@ -36,10 +36,65 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
|
|
|
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);
|
|
|
GetPLCConfig();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ private void Edit(object obj)
|
|
|
+ {
|
|
|
+ int id = Convert.ToInt32(obj);
|
|
|
+ var findPlc = allPLCConfigList.FirstOrDefault(x => (x.Id ==id));
|
|
|
+ DialogParameters parm = new DialogParameters();
|
|
|
+ parm.Add("Key", findPlc);
|
|
|
+ //弹出详情对话框
|
|
|
+ _dialog.ShowDialog("AddDetailView", parm, async callback =>
|
|
|
+ {
|
|
|
+ if (callback.Result == ButtonResult.OK)
|
|
|
+ {
|
|
|
+ BasPlcItemConfigDto returnValue = callback.Parameters.GetValue<BasPlcItemConfigDto>("ReturnValue");
|
|
|
+ if (returnValue != null)
|
|
|
+ {
|
|
|
+ var plcCon = _mapper.Map<BasPlcItemConfigDto, bas_plc_item_config>(returnValue);
|
|
|
+ var findPlc = allPLCConfigList.FirstOrDefault(x => (x.PlcAddress == returnValue.PlcAddress) || (x.PlcItem == returnValue.PlcAddress));
|
|
|
+ if (findPlc != null)
|
|
|
+ {
|
|
|
+ MessageBox.Show("已有此PLC变量地址或名称,请更改名称!", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //修改
|
|
|
+ plcCon.id = id;
|
|
|
+ bool isSucc = _iBasPlcItemConfigService.Edit(plcCon);
|
|
|
+ if (isSucc)
|
|
|
+ {
|
|
|
+ //重新读取PLC
|
|
|
+ GetPLCConfig();
|
|
|
+ _logger.LogInformation($"修改PLC变量成功。变量名{PLCItem},地址{PLCAddr}");
|
|
|
+ MessageBox.Show("修改PLC变量成功", "确认", 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 = _iBasPlcItemConfigService.Delete(id);
|
|
|
+ if (del)
|
|
|
+ {
|
|
|
+ MessageBox.Show("删除成功!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ GetPLCConfig();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -108,10 +163,9 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
private void Add(object obj)
|
|
|
{
|
|
|
- DialogParameters parm = new DialogParameters();
|
|
|
- parm.Add("Key", "");
|
|
|
+
|
|
|
//弹出详情对话框
|
|
|
- _dialog.ShowDialog("AddDetailView", parm, async callback =>
|
|
|
+ _dialog.ShowDialog("AddDetailView", async callback =>
|
|
|
{
|
|
|
if (callback.Result == ButtonResult.OK)
|
|
|
{
|
|
@@ -185,6 +239,15 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
|
|
|
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; }
|
|
|
#endregion
|
|
|
|
|
|
#region 数据绑定
|