From 6030f63100803df438523d3ed9ceea961da87584 Mon Sep 17 00:00:00 2001 From: liushoushan_notebook Date: Mon, 13 Jun 2022 16:41:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug=E5=92=8C=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E8=A1=A8=E8=BE=BE=E5=BC=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BasicData/Controllers/DeviceVariableController.cs | 5 +++++ Plugins/Plugin/DeviceService.cs | 7 ++++++- Plugins/Plugin/DeviceThread.cs | 2 +- WalkingTec.Mvvm/WalkingTec.Mvvm.Core/BaseCRUDVM.cs | 8 +++++--- WalkingTec.Mvvm/WalkingTec.Mvvm.Core/DataContext.cs | 2 ++ 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/IoTGateway/Areas/BasicData/Controllers/DeviceVariableController.cs b/IoTGateway/Areas/BasicData/Controllers/DeviceVariableController.cs index b727f98..588fb5d 100644 --- a/IoTGateway/Areas/BasicData/Controllers/DeviceVariableController.cs +++ b/IoTGateway/Areas/BasicData/Controllers/DeviceVariableController.cs @@ -50,6 +50,9 @@ namespace IoTGateway.Controllers [ActionDescription("Sys.Create")] public ActionResult Create(DeviceVariableVM vm) { + + if (vm.FC.ContainsKey("Entity.Expressions")) + vm.Entity.Expressions = vm.FC["Entity.Expressions"].ToString(); if (!ModelState.IsValid) { return PartialView(vm); @@ -83,6 +86,8 @@ namespace IoTGateway.Controllers [ValidateFormItemOnly] public ActionResult Edit(DeviceVariableVM vm) { + if (vm.FC.ContainsKey("Entity.Expressions")) + vm.Entity.Expressions = vm.FC["Entity.Expressions"].ToString(); if (!ModelState.IsValid) { return PartialView(vm); diff --git a/Plugins/Plugin/DeviceService.cs b/Plugins/Plugin/DeviceService.cs index 8321fa1..dc4d721 100644 --- a/Plugins/Plugin/DeviceService.cs +++ b/Plugins/Plugin/DeviceService.cs @@ -82,11 +82,16 @@ namespace Plugin { try { - _logger.LogInformation($"CreateDeviceThread Start:{Device.DeviceName}"); + _logger.LogInformation($"CreateDeviceThread Start:{Device.DeviceName},Driver:{Device.Driver}"); + if (Device.Driver == null) + return; using (var DC = new DataContext(connnectSetting, DBType)) { var systemManage = DC.Set().FirstOrDefault(); var driver = _DrvierManager.DriverInfos.Where(x => x.Type.FullName == Device.Driver.AssembleName).SingleOrDefault(); + if (driver == null) + return; + var settings = DC.Set().Where(x => x.DeviceId == Device.ID).AsNoTracking().ToList(); Type[] types = new Type[1] { typeof(Guid) }; object[] param = new object[1] { Device.ID }; diff --git a/Plugins/Plugin/DeviceThread.cs b/Plugins/Plugin/DeviceThread.cs index 77c5e95..d7fc1f5 100644 --- a/Plugins/Plugin/DeviceThread.cs +++ b/Plugins/Plugin/DeviceThread.cs @@ -274,7 +274,7 @@ namespace Plugin //mysql会把一些符号转义,没找到原因,先临时处理下 private string DealMysqlStr(string Expression) { - return Expression.Replace("<", ">").Replace(">", "<").Replace("&", "&"); + return Expression.Replace("<", "<").Replace(">", ">").Replace("&", "&"); } } diff --git a/WalkingTec.Mvvm/WalkingTec.Mvvm.Core/BaseCRUDVM.cs b/WalkingTec.Mvvm/WalkingTec.Mvvm.Core/BaseCRUDVM.cs index d74eb23..96ce27a 100644 --- a/WalkingTec.Mvvm/WalkingTec.Mvvm.Core/BaseCRUDVM.cs +++ b/WalkingTec.Mvvm/WalkingTec.Mvvm.Core/BaseCRUDVM.cs @@ -344,8 +344,9 @@ namespace WalkingTec.Mvvm.Core /// 为true时,框架会更新当前Entity的全部值,为false时,框架会检查Request.Form里的key,只更新表单提交的字段 public virtual void DoEdit(bool updateAllFields = false) { + DoEditPrepare(updateAllFields); - + try { DC.SaveChanges(); @@ -629,10 +630,11 @@ namespace WalkingTec.Mvvm.Core string name = f.Replace("entity.", ""); try { - DC.UpdateProperty(Entity, pros.Where(x => x.Name.ToLower() == name).Select(x => x.Name).FirstOrDefault()); + DC.UpdateProperty(Entity, pros.Where(x => name!="id" && x.Name.ToLower() == name).Select(x => x.Name).FirstOrDefault());//id字段不可修改 } - catch (Exception) + catch (Exception ex) { + MSD.AddModelError("", CoreProgram._localizer?["Sys.EditPrepare"]); } } } diff --git a/WalkingTec.Mvvm/WalkingTec.Mvvm.Core/DataContext.cs b/WalkingTec.Mvvm/WalkingTec.Mvvm.Core/DataContext.cs index 3d97f2e..f1b7933 100644 --- a/WalkingTec.Mvvm/WalkingTec.Mvvm.Core/DataContext.cs +++ b/WalkingTec.Mvvm/WalkingTec.Mvvm.Core/DataContext.cs @@ -508,6 +508,8 @@ namespace WalkingTec.Mvvm.Core public void UpdateProperty(T entity, string fieldName) where T : TopBasePoco { + if (string.IsNullOrEmpty(fieldName)) + return; var set = this.Set(); if (set.Local.AsQueryable().CheckID(entity.GetID()).FirstOrDefault() == null) {