duheng
2024-12-25 5685f16cc087d5645b2251ca66a7ac55dd4799ef
WinFrmUI/HStation.WinFrmUI.Basic.Core/02-SysPropManage/SysPropManageMainPanel.cs
@@ -136,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;
                }
            });
        }
    }
}