From a95dc42495472cf931db97f8ccbe9d075708aa0b Mon Sep 17 00:00:00 2001 From: duheng <2784771470@qq.com> Date: 星期二, 22 十月 2024 16:33:40 +0800 Subject: [PATCH] 修改泵信息界面 --- WinFrmUI/HStation.WinFrmUI.Basic/01-SysCatalogManage/SysCatalogManageMainPanel.cs | 179 +++++++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 142 insertions(+), 37 deletions(-) diff --git a/WinFrmUI/HStation.WinFrmUI.Basic/01-SysCatalogManage/SysCatalogManageMainPanel.cs b/WinFrmUI/HStation.WinFrmUI.Basic/01-SysCatalogManage/SysCatalogManageMainPanel.cs index 97a304f..0e25282 100644 --- a/WinFrmUI/HStation.WinFrmUI.Basic/01-SysCatalogManage/SysCatalogManageMainPanel.cs +++ b/WinFrmUI/HStation.WinFrmUI.Basic/01-SysCatalogManage/SysCatalogManageMainPanel.cs @@ -1,4 +1,13 @@ -锘縩amespace HStation.WinFrmUI.Basic +锘縰sing DevExpress.Utils.DragDrop; +using DevExpress.XtraEditors; +using DevExpress.XtraTreeList; +using DevExpress.XtraTreeList.Handler; +using DevExpress.XtraTreeList.Nodes; +using SqlSugar; +using System.ComponentModel; +using System.Reflection; + +namespace HStation.WinFrmUI.Basic { public partial class SysCatalogManageMainPanel : DocumentPage { @@ -6,14 +15,17 @@ { InitializeComponent(); this.PageTitle.Caption = "鍒嗙被绠$悊"; + this.treeList1.InitialMultiColSettings(); this.PageTitle.HeaderSvgImage = this.svgImage32[0]; this.PageTitle.SvgImageSize = new Size(24, 24); this.typeTreeListCtrl2.FocusedChangedEvent += TypeTreeListCtrl2_FocusedChangedEvent; } - private List<SysCatalogViewModel> _allBindingList = null; + private List<SysCatalogViewModel> _allBindingList; - private Yw.BLL.SysCatalog _bll = null; + private Yw.BLL.SysCatalog _bll; + + private List<SysCatalogViewModel> _IndexList; public override void InitialDataSource() { @@ -31,9 +43,10 @@ { _allBindingList.Add(new SysCatalogViewModel(item)); } - _allBindingList = _allBindingList.OrderBy(x => x.SortCode).ToList(); - this.catlogViewModelBindingSource.DataSource = _allBindingList; - this.catlogViewModelBindingSource.ResetBindings(false); + this.catalogViewModelBindingSource.DataSource = _allBindingList; + _IndexList = _allBindingList.Select(x => new SysCatalogViewModel(x)).ToList(); + this.catalogViewModelBindingSource.ResetBindings(false); + this.treeList1.ExpandAll(); } //娣诲姞 @@ -51,7 +64,7 @@ { var model = await _bll.GetByID(id); _allBindingList.Add(new SysCatalogViewModel(model)); - this.catlogViewModelBindingSource.ResetBindings(false); + this.catalogViewModelBindingSource.ResetBindings(false); return true; } return false; @@ -59,37 +72,10 @@ dlg.ShowDialog(); } - //娣诲姞瀛愰」 - private void BtnAddChild_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) - { - var dlg = new AddSysCatalogDlg(); - var vm = this.treeList1.GetCurrentViewModel(_allBindingList); - if (vm == null) - { - MessageBoxHelper.ShowWarning("璇烽�夋嫨鏁版嵁琛岋紒"); - return; - } - var typeID = this.typeTreeListCtrl2.GetCurrentID(); - dlg.SetBindingData(typeID, vm.ID); - dlg.ReloadDataEvent += async (rhs) => - { - var id = await _bll.Insert(rhs); - if (id > 0) - { - var model = await _bll.GetByID(id); - _allBindingList.Add(new SysCatalogViewModel(model)); - this.catlogViewModelBindingSource.ResetBindings(false); - return true; - } - return false; - }; - dlg.ShowDialog(); - } - //缂栬緫 private void barBtnEditPumpCurve_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { - var dlg = new EditSysCatlaogDlg(); + var dlg = new EditSysCatalogDlg(); var vm = this.treeList1.GetCurrentViewModel(_allBindingList); if (vm == null) { @@ -102,7 +88,7 @@ if (await _bll.Update(rhs)) { vm.Reset(rhs); - this.catlogViewModelBindingSource.ResetBindings(false); + this.catalogViewModelBindingSource.ResetBindings(false); return true; } return false; @@ -127,7 +113,7 @@ if (result) { _allBindingList.Remove(currentVm); - this.catlogViewModelBindingSource.ResetBindings(false); + this.catalogViewModelBindingSource.ResetBindings(false); MessageBoxHelper.ShowSuccess($"鍒犻櫎鎴愬姛!"); } else @@ -158,5 +144,124 @@ return; } } + + /// <summary> + ///璁剧疆鐖剁骇 + /// </summary> + private void barBtnUpdateParent_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) + { + var currentVm = this.treeList1.GetCurrentViewModel(_allBindingList); + if (currentVm == null) + { + MessageBoxHelper.ShowWarning("璇烽�夋嫨鏁版嵁琛岋紒"); + return; + } + var dlg = new UpdateCatalogParentDlg(); + dlg.SetBindingData(currentVm.TypeID, currentVm.ID, currentVm.ParentID); + dlg.ReloadEvent += async (parentId) => + { + var bol = await _bll.UpdateTreeSortCode(currentVm.ID, parentId, 1); + if (bol) + { + this.InitialDataSource(); + return true; + } + return false; + }; + dlg.ShowDialog(); + } + + private TreeListNode currentDragNode = null; + + private void treeList1_DragDrop(object sender, DragEventArgs e) + { + currentDragNode = (TreeListNode)e.Data.GetData(typeof(TreeListNode)); + var currentvm = GetViewModel(currentDragNode); + var dragInsertPosition = AjustDirection(sender, e); + var targetNode = GetTargetNode(e); + var targetVm = GetViewModel(targetNode); + var currentIndex = _allBindingList.IndexOf(currentvm); //鎿嶄綔鐩爣绱㈠紩 + var targetIndex = _allBindingList.IndexOf(targetVm); //鐩爣浣嶇疆绱㈠紩 + + if (dragInsertPosition == DragInsertPosition.AsChild || targetVm == null || currentvm == null) + { + e.Effect = DragDropEffects.None; + return; + } + if (dragInsertPosition == DragInsertPosition.After) + { + _IndexList.RemoveAt(currentIndex); + _IndexList.Insert(targetIndex + 1, currentvm); + } + else if (dragInsertPosition == DragInsertPosition.Before) + { + _IndexList.RemoveAt(currentIndex); + _IndexList.Insert(targetIndex - 1, currentvm); + } + if (currentvm.ParentID == targetVm.ParentID) + { + /* var sortIndex = currentvm.SortCode; + currentvm.SortCode = targetVm.SortCode; + targetVm.SortCode = sortIndex;*/ + SetTreeListSorter(currentvm.ParentID); + return; + } + e.Effect = DragDropEffects.None; + } + + /// <summary> + /// 鑾峰彇鎷栧姩杩囩▼涓殑鏂瑰悜 + /// </summary> + private DragInsertPosition AjustDirection(object sender, DragEventArgs e) + { + PropertyInfo pi = typeof(TreeList).GetProperty("Handler", BindingFlags.Instance | BindingFlags.NonPublic); + TreeListHandler handler = (TreeListHandler)pi.GetValue(this.treeList1, null); + return handler.StateData.DragInfo.DragInsertPosition; + } + + private async void SetTreeListSorter(long parentId) + { + var sortList = new List<Yw.Vmo.Sorter>(); + var targetList = _IndexList.Where(x => x.ParentID == parentId).ToList(); + int i = 1; + foreach (var item in targetList) + { + sortList.Add(new Yw.Vmo.Sorter { ID = item.ID, SortCode = i }); + i++; + } + if (!await _bll.UpdateSorter(sortList)) + { + TipFormHelper.ShowError("淇敼鎺掑簭澶辫触!"); + } + // this.catalogViewModelBindingSource.ResetBindings(false); + } + + private TreeListNode GetTargetNode(DragEventArgs e) + { + var point = new Point(e.X, e.Y); + var clientPoint = this.treeList1.PointToClient(point); + var targetNode = this.treeList1.GetNodeAt(clientPoint); + return targetNode; + } + + private SysCatalogViewModel GetViewModel(TreeListNode node) + { + if (node == null) + return default; + var vm = this.treeList1.GetDataRecordByNode(node) as SysCatalogViewModel; + return vm; + } + + private void barCheckSorter_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e) + { + if (barCheckSorter.Checked) + { + this.treeList1.OptionsDragAndDrop.DragNodesMode = DragNodesMode.Single; + } + else + { + this.treeList1.OptionsDragAndDrop.DragNodesMode = DragNodesMode.None; + } + } } } \ No newline at end of file -- Gitblit v1.9.3