using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Threading.Tasks;
|
using System.ComponentModel.DataAnnotations;
|
using WalkingTec.Mvvm.Core;
|
using WalkingTec.Mvvm.Core.Extensions;
|
using cy_scdz.Model.Set;
|
using utils;
|
|
namespace cy_scdz.ViewModel.dictionary.DictionaryVMs
|
{
|
public partial class DictionaryVM : BaseCRUDVM<Dictionary>
|
{
|
public List<ComboSelectListItem> AllParents { get; set; }
|
|
public DictionaryVM()
|
{
|
SetInclude(x => x.Parent);
|
}
|
|
protected override void InitVM()
|
{
|
AllParents = DC.Set<Dictionary>().Where(x => x.Parent == null).GetSelectListItems(Wtm, y => y.Name);
|
}
|
|
public override void DoAdd()
|
{
|
base.DoAdd();
|
}
|
public override DuplicatedInfo<Dictionary> SetDuplicatedCheck()
|
{
|
var rv = CreateFieldsInfo(SimpleField(x => x.Name));
|
rv.AddGroup(SimpleField(x => x.Key));
|
|
return rv;
|
|
}
|
public override void DoEdit(bool updateAllFields = false)
|
{
|
base.DoEdit(updateAllFields);
|
}
|
|
public override void DoDelete()
|
{
|
base.DoDelete();
|
}
|
/// <summary>
|
/// 增加一个新的字典
|
/// </summary>
|
/// <param name="name">名称</param>
|
/// <param name="PKey">父建key</param>
|
/// <param name="Key">自身key</param>
|
/// <param name="value">值</param>
|
public void addNew(string name, string? PKey = null, string? Key = null, string? value = null)
|
{
|
Dictionary Pd = null;
|
if (!string.IsNullOrEmpty(PKey))
|
{
|
Pd = DC.Set<Dictionary>().Where(x => x.IsEn == true && x.Key == PKey).FirstOrDefault();
|
if (Pd == null)
|
{
|
MSD.AddModelError("ParentId", "没有找到上级信息");
|
return;
|
}
|
|
}
|
Entity = new Dictionary()
|
{
|
Key = Key ?? utilsFun.GenerateRandomString(10),
|
Value = value,
|
Name = name,
|
IsEn = true,
|
ParentId = Pd == null ? null : Pd.ID,
|
|
|
|
};
|
base.DoAdd();
|
|
|
|
|
}
|
}
|
}
|