Przeglądaj źródła

修改名称bug

ltwork 1 rok temu
rodzic
commit
a29ac2eb67

+ 19 - 6
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/DeviceKindViewModel.cs

@@ -27,6 +27,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
     public class DeviceKindViewModel : BindableBase
     {
         private readonly IBasicDeviceKindService _iBasicDeviceKindService;
+        private readonly IBasicPlcTestSchemeService _iBasicPlcTestSchemeService;
         private readonly IMapper _mapper;
         private readonly IDialogService _dialog;
         private readonly ILogger _logger;
@@ -34,9 +35,11 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         private List<BasDeviceKindDto> allDeviceKindList = new List<BasDeviceKindDto>();//所有方案
         private List<BasDeviceKindDto> conditionDeviceKind = new List<BasDeviceKindDto>();//符合条件的方案
         private List<CrumbViewModel> breadCrumbs = new List<CrumbViewModel>();
-        public DeviceKindViewModel(IBasicDeviceKindService iBasicDeviceKindService, IMapper mapper,  IEventAggregator aggregator, IDialogService dialog, ILogger logger)
+        private string deviceKindBefore;//修改前的设备方案名称
+        public DeviceKindViewModel(IBasicDeviceKindService iBasicDeviceKindService, IBasicPlcTestSchemeService iBasicPlcTestSchemeService, IMapper mapper,  IEventAggregator aggregator, IDialogService dialog, ILogger logger)
         {
             _iBasicDeviceKindService = iBasicDeviceKindService;
+            _iBasicPlcTestSchemeService= iBasicPlcTestSchemeService;
             _mapper = mapper;
             _dialog = dialog;
             _logger = logger;
@@ -48,7 +51,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             DeleteCommand = new DelegateCommand<object>(Delete);
             ResetCommand = new DelegateCommand<object>(Reset);
             OnLoadCommand = new DelegateCommand(OnLoad);
-            GetPprojectConfig();
+           
           
         }
 
@@ -75,6 +78,8 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             breadCrumbs.Add(new CrumbViewModel { Name = "设备类型管理" });
             _aggregator.GetEvent<BreadEvent>().Publish(breadCrumbs);
             // DeviceKindNameList= _iBasicDeviceKindService.FindAllDeviceKind();
+            //获取数据
+            GetPprojectConfig();
         }
         private void Reset(object obj)
         {
@@ -91,9 +96,9 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         private void Edit(object obj)
         {
             int id = Convert.ToInt32(obj);
-            var finrProject = allDeviceKindList.FirstOrDefault(x => (x.DeviceKindId == id));
+            var findDeviceKind = allDeviceKindList.FirstOrDefault(x => (x.DeviceKindId == id));
             DialogParameters parm = new DialogParameters();
-            parm.Add("Key", finrProject);
+            parm.Add("Key", findDeviceKind);
             //蒙层显示
             _aggregator.GetEvent<MaskEvent>().Publish(true);
             //弹出详情对话框
@@ -109,8 +114,8 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
                         returnValue.UpdateTime = DateTime.Now;
                         returnValue.UpdateBy = Appsession.UserName;
                         //创建时间
-                        returnValue.CreateTime = finrProject.CreateTime;
-                        returnValue.CreateBy = finrProject?.CreateBy;
+                        returnValue.CreateTime = findDeviceKind.CreateTime;
+                        returnValue.CreateBy = findDeviceKind?.CreateBy;
 
                         var deviceKindCon = _mapper.Map<BasDeviceKindDto, bas_device_kind>(returnValue);
                         var findPlcs = allDeviceKindList.FindAll(x => (x.DeviceKindName == returnValue.DeviceKindName) || (x.DeviceKindNo == returnValue.DeviceKindNo));
@@ -128,12 +133,20 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
                         bool isSucc = _iBasicDeviceKindService.Edit(deviceKindCon);
                         if (isSucc)
                         {
+                            //更改测试方案表中的设备类型命令
+                            var tests = _iBasicPlcTestSchemeService.FindAllByKind(findDeviceKind.DeviceKindName);
+                            foreach (var item in tests)
+                            {
+                                item.devicekind_name = returnValue.DeviceKindName;
+                                _iBasicPlcTestSchemeService.Edit(item);
+                            }
                             //重新读取PLC
                             GetPprojectConfig();
                             _logger.LogInformation($"修改设备类型成功,类型为{deviceKindCon}");
                             SendLogToDis($"修改设备类型成功,类型为{deviceKindCon}");
                             MessageBox.Show("修改设备类型成功", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
                         }
+                        
                     }
                 }
 

+ 3 - 1
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/DeviceViewModel.cs

@@ -50,7 +50,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             DeleteCommand = new DelegateCommand<object>(Delete);
             ResetCommand = new DelegateCommand<object>(Reset);
             OnLoadCommand = new DelegateCommand(OnLoad);
-            GetPprojectConfig();
+          
           
         }
 
@@ -86,6 +86,8 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             breadCrumbs.Add(new CrumbViewModel { Name = "基础设置" });
             breadCrumbs.Add(new CrumbViewModel { Name = "设备管理" });
             _aggregator.GetEvent<BreadEvent>().Publish(breadCrumbs);
+            //获取数据
+            GetPprojectConfig();
         }
         private void Reset(object obj)
         {

+ 12 - 7
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/EditSchViewModel.cs

@@ -175,15 +175,20 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         }
         private void Delete(object obj)
         {
-            int id = Convert.ToInt32(obj);
-            bool isResult = _basicPlcTestSchemeDtlService.Delete(id);
-            if (isResult)
+            MessageBoxResult boxResult = MessageBox.Show("确认删除此条数据?", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Question);
+            if (boxResult == MessageBoxResult.OK)
             {
-                MessageBox.Show("删除成功!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
-                //更新已有的测试项
-                GetExistSchs();
-                SendLogToDis($"删除测试项,测试项id为{id},方案名称为{ScheduleName}");
+                int id = Convert.ToInt32(obj);
+                bool isResult = _basicPlcTestSchemeDtlService.Delete(id);
+                if (isResult)
+                {
+                    MessageBox.Show("删除成功!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
+                    //更新已有的测试项
+                    GetExistSchs();
+                    SendLogToDis($"删除测试项,测试项id为{id},方案名称为{ScheduleName}");
+                }
             }
+               
 
         }
 

+ 3 - 1
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/ProjectViewModel.cs

@@ -46,7 +46,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             ResetCommand = new DelegateCommand<object>(Reset);
             OnLoadCommand = new DelegateCommand(OnLoad);
 
-            GetPprojectConfig();
+          
             
         }
 
@@ -62,6 +62,8 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             breadCrumbs.Add(new CrumbViewModel { Name = "基础设置" });
             breadCrumbs.Add(new CrumbViewModel { Name = "项目管理" });
             _aggregator.GetEvent<BreadEvent>().Publish(breadCrumbs);
+            //获取数据
+            GetPprojectConfig();
         }
         private void Reset(object obj)
         {