From 5f9570f243c7744b9e13c1a63506e7587a047b1d Mon Sep 17 00:00:00 2001 From: duheng <2784771470@qq.com> Date: 星期二, 24 十二月 2024 19:18:18 +0800 Subject: [PATCH] 曲线删除优化 --- WinFrmUI/HStation.WinFrmUI.Basic.Core/02-SysPropManage/SysPropManageMainPanel.cs | 109 +++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 78 insertions(+), 31 deletions(-) diff --git a/WinFrmUI/HStation.WinFrmUI.Basic.Core/02-SysPropManage/SysPropManageMainPanel.cs b/WinFrmUI/HStation.WinFrmUI.Basic.Core/02-SysPropManage/SysPropManageMainPanel.cs index 977858f..a51aeb0 100644 --- a/WinFrmUI/HStation.WinFrmUI.Basic.Core/02-SysPropManage/SysPropManageMainPanel.cs +++ b/WinFrmUI/HStation.WinFrmUI.Basic.Core/02-SysPropManage/SysPropManageMainPanel.cs @@ -1,6 +1,4 @@ -锘縰sing DevExpress.Utils.Behaviors; -using DevExpress.Utils.DragDrop; -using DevExpress.XtraTreeList; +锘縰sing DevExpress.Utils.DragDrop; namespace HStation.WinFrmUI.Basic { @@ -138,42 +136,91 @@ //鎺掑簭 private void barCheckItemSorter_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { - if (barCheckSorter.Checked) + var be = this.behaviorManager1.GetBehavior<DevExpress.Utils.DragDrop.DragDropBehavior>(this.gridView1); + be.Properties.AllowDrag = barCheckSorter.Checked; + } + + private async void dragDropEvents1_DragDrop(object sender, DevExpress.Utils.DragDrop.DragDropEventArgs e) + { + var indexs = e.Data as int[]; + if (indexs == null || indexs.Length < 1) { - behaviorManager1.Attach<DragDropBehavior>(gridView1, behavior => + e.Handled = true; + return; + } + var sourceIndex = indexs[0]; + var sourceObj = this.gridView1.GetRow(sourceIndex) as SysPropViewModel; + if (sourceObj == null) + { + e.Handled = true; + return; + } + + var destIndex = this.gridView1.GetRowHandleByCP(e.Location); + if (destIndex < 0) + { + e.Handled = true; + return; + } + + var destObj = this.gridView1.GetRow(destIndex) as SysPropViewModel; + if (destObj == null) + { + e.Handled = true; + return; + } + + var sorters = new List<Yw.Vmo.Sorter>(); + + if (e.InsertType == InsertType.Before) + { + sorters.Add(new Yw.Vmo.Sorter() { ID = sourceObj.ID, SortCode = destObj.SortCode }); + _allBindingList.ForEach(x => { - // behavior.BeginDragDrop += Behavior_BeginDragDrop; - behavior.EndDragDrop += Behavior_EndDragDrop; + if (x.SortCode >= destObj.SortCode) + { + if (x != sourceObj) + { + sorters.Add(new Yw.Vmo.Sorter() { ID = x.ID, SortCode = x.SortCode + 1 }); + } + } + }); + } + else if (e.InsertType == InsertType.After) + { + sorters.Add(new Yw.Vmo.Sorter() { ID = sourceObj.ID, SortCode = destObj.SortCode + 1 }); + _allBindingList.ForEach(x => + { + if (x.SortCode > destObj.SortCode) + { + if (x != sourceObj) + { + sorters.Add(new Yw.Vmo.Sorter() { ID = x.ID, SortCode = x.SortCode + 1 }); + } + } }); } else { - behaviorManager1.Detach<DragDropBehavior>(gridView1); - } - } - - private async void Behavior_EndDragDrop(object sender, EndDragDropEventArgs e) - { - var vm = this.gridView1.GetCurrentViewModel(_allBindingList); - var sorterList = new List<Yw.Vmo.Sorter>(); - int i = 1; - foreach (var item in _allBindingList) - { - sorterList.Add(new Yw.Vmo.Sorter() { ID = item.ID, SortCode = i }); - i++; - } - var bol = await _bll.UpdateSorter(sorterList); - if (await _bll.UpdateSorter(sorterList)) - { - this.propViewModelBindingSource.ResetBindings(false); - } - else - { - // e.Effect= bol? DragDropEffects.Move : DragDropEffects.None; - // gridView1.FocusedRowHandle = _LastRowIndex; - TipFormHelper.ShowError("淇敼鎺掑簭澶辫触!"); + e.Handled = true; return; } + + var bol = await _bll.UpdateSorter(sorters); + if (!bol) + { + e.Handled = true; + return; + } + + _allBindingList.ForEach(x => + { + var sorter = sorters.Find(t => t.ID == x.ID); + if (sorter != null) + { + x.SortCode = sorter.SortCode; + } + }); } } } \ No newline at end of file -- Gitblit v1.9.3