Esempio n. 1
0
        /// <summary>
        /// 更新排序
        /// </summary>
        /// <param name="items"></param>
        private void UpdateSort(ItemCollection items)
        {
            foreach (var i in items)
            {
                var item  = (TreeViewItem)i;
                var model = (LeftMenus)item.DataContext;
                if (model.DisplayName == Config.RootDisplayName)
                {
                    continue;
                }

                var requestModel = new LeftMenusUpdateSortRequestModel
                {
                    DisplayName = model.DisplayName,
                    Sort        = model.Sort,
                    Timestamp   = _leftMenusManage.ServerTime.ToUnixTimestamp()
                };
                var result = _leftMenusManage.UpdateSort(model.Id, model.Timestamp, requestModel);
                if (result.ResultStatus == ResultStatus.Success)
                {
                    model.Timestamp = result.Data.Timestamp;
                }
                else
                {
                    _metroWindow.ShowMessageAsync("更新节点排序失败", result.Message);
                }

                if (item.HasItems)
                {
                    UpdateSort(item.Items);
                }
            }
        }
Esempio n. 2
0
        public CommandResult <LeftMenus> UpdateSort(int leftMenuId, long timestamp, LeftMenusUpdateSortRequestModel requestModel)
        {
            var result = new CommandResult <LeftMenus>();

            if (!Exist(a => a.Id == leftMenuId))
            {
                result.Message = $"节点名称“{requestModel.DisplayName}”在系统中已不存在";
            }
            else if (!Exist(a => a.Id == leftMenuId && a.Timestamp == timestamp))
            {
                result.Message = $"节点名称为“{requestModel.DisplayName}”的节点排序已在别处被修改";
            }
            else
            {
                using (var db = new FrameContext())
                {
                    var entity = BaseService.Find(db, a => a.Id == leftMenuId);
                    entity.Sort      = requestModel.Sort;
                    entity.Timestamp = requestModel.Timestamp;
                    if (!BaseService.Update(db, entity))
                    {
                        result.Message = "系统出现未知原因,节点排序更新失败!";
                    }
                    else
                    {
                        result.ResultStatus = ResultStatus.Success;
                        result.Message      = "节点排序更新成功";
                        result.Data         = entity;
                    }
                }
            }
            return(result);
        }
Esempio n. 3
0
        private void AddTreeViewItem(CTreeView treeView, ItemCollection items, TreeViewImgItem selectedItem, LeftMenus leftMenus)
        {
            if (leftMenus.ParentId == 0)
            {
                treeView.Items.Add(GetSelectedTreeView().GenerateTreeViewItem(selectedItem));
                selectedItem.IsSelected = true;
                return;
            }

            foreach (var i in items)
            {
                var item = (TreeViewImgItem)i;
                if (((LeftMenus)item.DataContext).Id == leftMenus.ParentId)
                {
                    var treeViewMain = GetSelectedTreeView();
                    item.Items.Add(treeViewMain.GenerateTreeViewItem(selectedItem));
                    selectedItem.IsSelected = true;
                    item.IsExpanded         = true;

                    var requestModel = new LeftMenusUpdateSortRequestModel
                    {
                        DisplayName = leftMenus.DisplayName,
                        Sort        = int.MaxValue,
                        Timestamp   = _leftMenusManage.ServerTime.ToUnixTimestamp()
                    };
                    var result = _leftMenusManage.UpdateSort(leftMenus.Id, Timestamp, requestModel);
                    if (result.ResultStatus == ResultStatus.Success)
                    {
                        leftMenus.DisplayName = result.Data.DisplayName;
                        leftMenus.Sort        = result.Data.Sort;
                        leftMenus.Timestamp   = result.Data.Timestamp;
                    }
                    else
                    {
                        _metroWindow.ShowMessageAsync("更新节点排序失败", result.Message);
                    }
                    break;
                }

                if (item.HasItems)
                {
                    AddTreeViewItem(treeView, item.Items, selectedItem, leftMenus);
                }
            }
        }