Преглед на файлове

修改采集管理删除通道bug

wyq преди 3 месеца
родител
ревизия
62dd095de6
променени са 2 файла, в които са добавени 23 реда и са изтрити 11 реда
  1. 11 10
      DW5S.App/EditForms/StationEditor.cs
  2. 12 1
      DW5S.App/UserControl/CtrlStation.cs

+ 11 - 10
DW5S.App/EditForms/StationEditor.cs

@@ -1,6 +1,7 @@
 using DW5S.Entity;
 using DW5S.Repostory;
 using DW5S.ViewModel;
+using DxHelper;
 using ExtensionsDev;
 using System;
 using System.Collections.Generic;
@@ -16,6 +17,7 @@ namespace DW5S.App.EditForms
     {
         public AdCardViewModel info;
         public List<AdChannelViewModel> AdChItems = new List<AdChannelViewModel>();
+        public List<AdChannelViewModel> DeleteChItems = new List<AdChannelViewModel>();
         private List<AdCardViewModel> infos;
         public StationEditor()
         {
@@ -101,10 +103,10 @@ namespace DW5S.App.EditForms
         {
             if (e.Column.FieldName == nameof(AdChannelViewModel.ChNum))
             {
-                var AdChannel = gvChannelList.GetSelectRow<AdChannelViewModel>().FirstOrDefault();
-                if (AdChItems.Count(i => i.ChNum == AdChannel.ChNum) > 1)
+                var ChNum = (int)e.Value;
+                if (AdChItems.Count(i => i.ChNum == ChNum) > 1)
                 {
-                    DxHelper.MsgBoxHelper.ShowError($"采集通道[{AdChannel.ChNum}]已经存在!");
+                    DxHelper.MsgBoxHelper.ShowError($"采集通道[{ChNum}]已经存在!");
                     return;
                 }
 
@@ -234,7 +236,7 @@ namespace DW5S.App.EditForms
             this.DialogResult = DialogResult.Cancel;
         }
 
-        private async void GroupChannel_CustomButtonClick(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e)
+        private  void GroupChannel_CustomButtonClick(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e)
         {
             string caption = e.Button.Properties.Caption;
             switch (caption)
@@ -246,12 +248,11 @@ namespace DW5S.App.EditForms
                 case "删除":
                     try
                     {
-                        var deletes = gvChannelList.DeleteSelectedRows<AdChannelViewModel>();
-                        var unitOfWork = IocContainer.UnitOfWork;
-                        var repsCh = unitOfWork.Of<AdChannel>();
-                        await repsCh.DeleteAsync(deletes.To<List<AdChannel>>());
-                        await unitOfWork.SaveAsync();
-
+                        if (MsgBoxHelper.ShowConfirm("确定删除选中的采集通道吗?"))
+                        {
+                            var deletes = gvChannelList.DeleteSelectedRows<AdChannelViewModel>();
+                            DeleteChItems.AddRange(deletes);
+                        }
                     }
                     catch (Exception ex)
                     {

+ 12 - 1
DW5S.App/UserControl/CtrlStation.cs

@@ -1,8 +1,10 @@
 using DevExpress.Office.Utils;
+using DevExpress.XtraDiagram.Base;
 using DW5S.App.EditForms;
 using DW5S.Entity;
 using DW5S.Repostory;
 using DW5S.ViewModel;
+using DxHelper;
 using Microsoft.EntityFrameworkCore;
 using System;
 using System.Collections.Generic;
@@ -102,8 +104,15 @@ namespace DW5S.App.UserControl
             {
                 StationEditor frm = new StationEditor(editItem);
                 if (frm.ShowDialog() != DialogResult.OK) return null;
-                editItem = frm.info;
+
                 var unitOfWork = IocContainer.UnitOfWork;
+                if (frm.DeleteChItems.Count > 0)
+                {
+                    var repsCh = unitOfWork.Of<AdChannel>();
+                    await repsCh.DeleteAsync(frm.DeleteChItems.To<List<AdChannel>>());
+                    await unitOfWork.SaveAsync();
+                }
+                editItem = frm.info;
                 var repsStation = unitOfWork.Of<AdCard>();
                 await repsStation.AddOrUpdateAsync(editItem.To<AdCard>());
                 await unitOfWork.SaveAsync();
@@ -122,11 +131,13 @@ namespace DW5S.App.UserControl
         {
             try
             {
+
                 var unitOfWork = IocContainer.UnitOfWork;
                 var repsCxTx = unitOfWork.Of<AdCard>();
                 await repsCxTx.DeleteAsync(list.To<List<AdCard>>());
                 await unitOfWork.SaveAsync();
                 return true;
+
             }
             catch (Exception ex)
             {