Ejemplo n.º 1
0
 public SysDicViewModel(Guid id)
 {
     _id       = id;
     this.Save = new DelegateCommand(() => {
         if (NTMinerRoot.Instance.ServerContext.SysDicSet.ContainsKey(this.Id))
         {
             VirtualRoot.Execute(new UpdateSysDicCommand(this));
         }
         else
         {
             VirtualRoot.Execute(new AddSysDicCommand(this));
         }
         CloseWindow?.Invoke();
     });
     this.AddSysDicItem = new DelegateCommand(() => {
         new SysDicItemViewModel(Guid.NewGuid())
         {
             DicId      = id,
             SortNumber = this.SysDicItems.Count + 1
         }.Edit.Execute(FormType.Add);
     });
     this.Edit = new DelegateCommand <FormType?>((formType) => {
         VirtualRoot.Execute(new SysDicEditCommand(formType ?? FormType.Edit, this));
     });
     this.Remove = new DelegateCommand(() => {
         if (this.Id == Guid.Empty)
         {
             return;
         }
         this.ShowSoftDialog(new DialogWindowViewModel(message: $"您确定删除{this.Code}系统字典吗?", title: "确认", onYes: () => {
             VirtualRoot.Execute(new RemoveSysDicCommand(this.Id));
         }));
     });
     this.SortUp = new DelegateCommand(() => {
         SysDicViewModel upOne = AppContext.Instance.SysDicVms.GetUpOne(this.SortNumber);
         if (upOne != null)
         {
             int sortNumber   = upOne.SortNumber;
             upOne.SortNumber = this.SortNumber;
             VirtualRoot.Execute(new UpdateSysDicCommand(upOne));
             this.SortNumber = sortNumber;
             VirtualRoot.Execute(new UpdateSysDicCommand(this));
             AppContext.Instance.SysDicVms.OnPropertyChanged(nameof(AppContext.SysDicViewModels.List));
         }
     });
     this.SortDown = new DelegateCommand(() => {
         SysDicViewModel nextOne = AppContext.Instance.SysDicVms.GetNextOne(this.SortNumber);
         if (nextOne != null)
         {
             int sortNumber     = nextOne.SortNumber;
             nextOne.SortNumber = this.SortNumber;
             VirtualRoot.Execute(new UpdateSysDicCommand(nextOne));
             this.SortNumber = sortNumber;
             VirtualRoot.Execute(new UpdateSysDicCommand(this));
             AppContext.Instance.SysDicVms.OnPropertyChanged(nameof(AppContext.SysDicViewModels.List));
         }
     });
 }
Ejemplo n.º 2
0
 public SysDicViewModel(Guid id)
 {
     _id       = id;
     this.Save = new DelegateCommand(() => {
         if (NTMinerRoot.Current.SysDicSet.ContainsKey(this.Id))
         {
             VirtualRoot.Execute(new UpdateSysDicCommand(this));
         }
         else
         {
             VirtualRoot.Execute(new AddSysDicCommand(this));
         }
         CloseWindow?.Invoke();
     });
     this.AddSysDicItem = new DelegateCommand(() => {
         new SysDicItemViewModel(Guid.NewGuid())
         {
             DicId      = id,
             SortNumber = this.SysDicItems.Count + 1
         }.Edit.Execute(FormType.Add);
     });
     this.Edit = new DelegateCommand <FormType?>((formType) => {
         SysDicEdit.ShowWindow(formType ?? FormType.Edit, this);
     });
     this.Remove = new DelegateCommand(() => {
         if (this.Id == Guid.Empty)
         {
             return;
         }
         DialogWindow.ShowDialog(message: $"您确定删除{this.Code}系统字典吗?", title: "确认", onYes: () => {
             VirtualRoot.Execute(new RemoveSysDicCommand(this.Id));
         }, icon: IconConst.IconConfirm);
     });
     this.SortUp = new DelegateCommand(() => {
         SysDicViewModel upOne = SysDicViewModels.Current.List.OrderByDescending(a => a.SortNumber).FirstOrDefault(a => a.SortNumber < this.SortNumber);
         if (upOne != null)
         {
             int sortNumber   = upOne.SortNumber;
             upOne.SortNumber = this.SortNumber;
             VirtualRoot.Execute(new UpdateSysDicCommand(upOne));
             this.SortNumber = sortNumber;
             VirtualRoot.Execute(new UpdateSysDicCommand(this));
             SysDicViewModels.Current.OnPropertyChanged(nameof(SysDicViewModels.List));
         }
     });
     this.SortDown = new DelegateCommand(() => {
         SysDicViewModel nextOne = SysDicViewModels.Current.List.OrderBy(a => a.SortNumber).FirstOrDefault(a => a.SortNumber > this.SortNumber);
         if (nextOne != null)
         {
             int sortNumber     = nextOne.SortNumber;
             nextOne.SortNumber = this.SortNumber;
             VirtualRoot.Execute(new UpdateSysDicCommand(nextOne));
             this.SortNumber = sortNumber;
             VirtualRoot.Execute(new UpdateSysDicCommand(this));
             SysDicViewModels.Current.OnPropertyChanged(nameof(SysDicViewModels.List));
         }
     });
 }
Ejemplo n.º 3
0
 private SysDicViewModels()
 {
     foreach (var item in NTMinerRoot.Current.SysDicSet)
     {
         SysDicViewModel sysDicVm = new SysDicViewModel(item);
         _dicById.Add(item.GetId(), sysDicVm);
         _dicByCode.Add(item.Code, sysDicVm);
     }
     this.Add = new DelegateCommand(() => {
         new SysDicViewModel(Guid.NewGuid())
         {
             SortNumber = this.Count + 1
         }.Edit.Execute(null);
     });
     Global.Access <SysDicAddedEvent>(
         Guid.Parse("eef03852-17c4-4124-bb64-444f6c4f19ab"),
         "添加了系统字典后调整VM内存",
         LogEnum.Log,
         action: (message) => {
         if (!_dicById.ContainsKey(message.Source.GetId()))
         {
             SysDicViewModel sysDicVm = new SysDicViewModel(message.Source);
             _dicById.Add(message.Source.GetId(), sysDicVm);
             if (!_dicByCode.ContainsKey(message.Source.Code))
             {
                 _dicByCode.Add(message.Source.Code, sysDicVm);
             }
             OnPropertyChanged(nameof(List));
             OnPropertyChanged(nameof(Count));
         }
     });
     Global.Access <SysDicUpdatedEvent>(
         Guid.Parse("f34d33e9-981b-4513-9425-e8694a4b5b17"),
         "更新了系统字典后调整VM内存",
         LogEnum.Log,
         action: (message) => {
         if (_dicById.ContainsKey(message.Source.GetId()))
         {
             SysDicViewModel entity = _dicById[message.Source.GetId()];
             int sortNumber         = entity.SortNumber;
             entity.Update(message.Source);
             if (sortNumber != entity.SortNumber)
             {
                 this.OnPropertyChanged(nameof(List));
             }
         }
     });
     Global.Access <SysDicRemovedEvent>(
         Guid.Parse("25c11087-a479-40de-8ddc-9c807a66afab"),
         "删除了系统字典后调整VM内存",
         LogEnum.Log,
         action: (message) => {
         _dicById.Remove(message.Source.GetId());
         _dicByCode.Remove(message.Source.Code);
         OnPropertyChanged(nameof(List));
         OnPropertyChanged(nameof(Count));
     });
 }
Ejemplo n.º 4
0
 public SysDicViewModel(Guid id)
 {
     _id = id;
     this.AddSysDicItem = new DelegateCommand(() => {
         new SysDicItemViewModel(Guid.NewGuid())
         {
             DicId      = id,
             SortNumber = this.SysDicItems.Count + 1
         }.Edit.Execute(null);
     });
     this.Edit = new DelegateCommand(() => {
         SysDicEdit.ShowEditWindow(this);
     });
     this.Remove = new DelegateCommand(() => {
         if (this.Id == Guid.Empty)
         {
             return;
         }
         DialogWindow.ShowDialog(message: $"您确定删除{this.Code}系统字典吗?", title: "确认", onYes: () => {
             Global.Execute(new RemoveSysDicCommand(this.Id));
         }, icon: "Icon_Confirm");
     });
     this.SortUp = new DelegateCommand(() => {
         SysDicViewModel upOne = SysDicViewModels.Current.List.OrderByDescending(a => a.SortNumber).FirstOrDefault(a => a.SortNumber < this.SortNumber);
         if (upOne != null)
         {
             int sortNumber   = upOne.SortNumber;
             upOne.SortNumber = this.SortNumber;
             Global.Execute(new UpdateSysDicCommand(upOne));
             this.SortNumber = sortNumber;
             Global.Execute(new UpdateSysDicCommand(this));
             SysDicViewModels.Current.OnPropertyChanged(nameof(SysDicViewModels.List));
         }
     });
     this.SortDown = new DelegateCommand(() => {
         SysDicViewModel nextOne = SysDicViewModels.Current.List.OrderBy(a => a.SortNumber).FirstOrDefault(a => a.SortNumber > this.SortNumber);
         if (nextOne != null)
         {
             int sortNumber     = nextOne.SortNumber;
             nextOne.SortNumber = this.SortNumber;
             Global.Execute(new UpdateSysDicCommand(nextOne));
             this.SortNumber = sortNumber;
             Global.Execute(new UpdateSysDicCommand(this));
             SysDicViewModels.Current.OnPropertyChanged(nameof(SysDicViewModels.List));
         }
     });
 }
Ejemplo n.º 5
0
 private void Init()
 {
     VirtualRoot.On <SysDicAddedEvent>("添加了系统字典后调整VM内存", LogEnum.DevConsole,
                                       action: (message) => {
         if (!_dicById.ContainsKey(message.Source.GetId()))
         {
             SysDicViewModel sysDicVm = new SysDicViewModel(message.Source);
             _dicById.Add(message.Source.GetId(), sysDicVm);
             if (!_dicByCode.ContainsKey(message.Source.Code))
             {
                 _dicByCode.Add(message.Source.Code, sysDicVm);
             }
             OnPropertyChanged(nameof(List));
             OnPropertyChanged(nameof(Count));
         }
     }).AddToCollection(NTMinerRoot.Current.ContextHandlers);
     VirtualRoot.On <SysDicUpdatedEvent>("更新了系统字典后调整VM内存", LogEnum.DevConsole,
                                         action: (message) => {
         if (_dicById.ContainsKey(message.Source.GetId()))
         {
             SysDicViewModel entity = _dicById[message.Source.GetId()];
             int sortNumber         = entity.SortNumber;
             entity.Update(message.Source);
             if (sortNumber != entity.SortNumber)
             {
                 this.OnPropertyChanged(nameof(List));
             }
         }
     }).AddToCollection(NTMinerRoot.Current.ContextHandlers);
     VirtualRoot.On <SysDicRemovedEvent>("删除了系统字典后调整VM内存", LogEnum.DevConsole,
                                         action: (message) => {
         _dicById.Remove(message.Source.GetId());
         _dicByCode.Remove(message.Source.Code);
         OnPropertyChanged(nameof(List));
         OnPropertyChanged(nameof(Count));
     }).AddToCollection(NTMinerRoot.Current.ContextHandlers);
     foreach (var item in NTMinerRoot.Current.SysDicSet)
     {
         SysDicViewModel sysDicVm = new SysDicViewModel(item);
         _dicById.Add(item.GetId(), sysDicVm);
         _dicByCode.Add(item.Code, sysDicVm);
     }
 }
Ejemplo n.º 6
0
 public bool TryGetSysDicVm(string dicCode, out SysDicViewModel sysDicVm)
 {
     return(_dicByCode.TryGetValue(dicCode, out sysDicVm));
 }
Ejemplo n.º 7
0
 public bool TryGetSysDicVm(Guid dicId, out SysDicViewModel sysDicVm)
 {
     return(_dicById.TryGetValue(dicId, out sysDicVm));
 }