Exemple #1
0
        private async Task <bool> OnSaveAsync(UserDto item, ItemChangedType changedType)
        {
            if (changedType == ItemChangedType.Add)
            {
                var response = await Http.PostAsJsonAsync("/api/base/user", item);

                //var result = await response.Content.ReadFromJsonAsync<UserDto>();
                //System.Console.WriteLine(JsonSerializer.Serialize(result));
            }
            else
            {
                //if (oldItem != null)
                //{
                //    oldItem.Name = item.Name;
                //    oldItem.Address = item.Address;
                //    oldItem.DateTime = item.DateTime;
                //    oldItem.Count = item.Count;
                //    oldItem.Complete = item.Complete;
                //    oldItem.Education = item.Education;
                //}
                //var oldItem = Items.FirstOrDefault(i => i.Id == item.Id);
                var jobList = await GetJobListAsync();

                var OrgList = await GetOrgListAsync();

                var user = await Http.GetFromJsonAsync <UserDto>("/api/base/user/" + item.Id);

                var userRoles = await GetUserRoles(item.Id);

                //item.RoleNames = string.Join(",", userRoles.Select(_ => _.Name).ToList());
            }
            return(false);
        }
Exemple #2
0
 private Task <bool> OnSaveAsync(Foo item, ItemChangedType changedType)
 {
     // 对象已经更新
     // 输出日志信息
     Trace.Log($"单元格变化通知 类: Foo - 值: 单元格");
     return(Task.FromResult(true));
 }
Exemple #3
0
    private async Task <bool> OnSaveAsync(Foo item, ItemChangedType changedType)
    {
        // 模拟延时
        await Task.Delay(1000);

        if (changedType == ItemChangedType.Add)
        {
            item.Id = Items.Max(i => i.Id) + 1;
            Items.Add(item);
        }
        else
        {
            var oldItem = Items.FirstOrDefault(i => i.Id == item.Id);
            if (oldItem != null)
            {
                oldItem.Name      = item.Name;
                oldItem.Address   = item.Address;
                oldItem.DateTime  = item.DateTime;
                oldItem.Count     = item.Count;
                oldItem.Complete  = item.Complete;
                oldItem.Education = item.Education;
            }
        }
        return(true);
    }
Exemple #4
0
    public void IsEditable_IsReadonlyWhenEdit(ItemChangedType itemChangedType, bool val)
    {
        var editorItem = new EditorItem <Foo, string>()
        {
            IsReadonlyWhenEdit = val
        };

        Assert.Equal(val, !editorItem.IsEditable(itemChangedType));
    }
Exemple #5
0
    public void IsEditable_Search(ItemChangedType itemChangedType)
    {
        var editorItem = new EditorItem <Foo, string>();

        editorItem.SetParametersAsync(ParameterView.FromDictionary(new Dictionary <string, object?>
        {
            ["Editable"] = false
        }));
        Assert.True(editorItem.IsEditable(itemChangedType, true));
    }
Exemple #6
0
    public void IsEditable_Readonly(ItemChangedType itemChangedType)
    {
        var editorItem = new EditorItem <Foo, string>();

        editorItem.SetParametersAsync(ParameterView.FromDictionary(new Dictionary <string, object?>
        {
            ["Readonly"] = true
        }));
        Assert.False(editorItem.IsEditable(itemChangedType));
    }
    /// <summary>
    /// 保存方法
    /// </summary>
    /// <param name="model"></param>
    /// <param name="changedType"></param>
    /// <returns></returns>
    public override async Task <bool> SaveAsync(TModel model, ItemChangedType changedType)
    {
        if (_db.Entry(model).IsKeySet)
        {
            _db.Update(model);
        }
        else
        {
            await _db.AddAsync(model);
        }

        await _db.SaveChangesAsync();

        return(true);
    }
Exemple #8
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="model"></param>
    /// <param name="changedType"></param>
    /// <returns></returns>
    public override Task <bool> SaveAsync(TModel model, ItemChangedType changedType)
    {
        var ret = false;

        if (model is Foo foo)
        {
            if (changedType == ItemChangedType.Add)
            {
                var id = Items.Count + 1;
                while (Items.FirstOrDefault(item => (item as Foo) !.Id == id) != null)
                {
                    id++;
                }
                var item = new Foo()
                {
                    Id        = id,
                    Name      = foo.Name,
                    Address   = foo.Address,
                    Complete  = foo.Complete,
                    Count     = foo.Count,
                    DateTime  = foo.DateTime,
                    Education = foo.Education,
                    Hobby     = foo.Hobby
                } as TModel;
                Items.Add(item !);
            }
            else
            {
                var item = Items.First(item =>
                {
                    var f = item as Foo;
                    return(f?.Id == foo.Id);
                });
                var f = item as Foo;
                f !.Name      = foo.Name;
                f !.Address   = foo.Address;
                f !.Complete  = foo.Complete;
                f !.Count     = foo.Count;
                f !.DateTime  = foo.DateTime;
                f !.Education = foo.Education;
                f !.Hobby     = foo.Hobby;
            }
            ret = true;
        }
        return(Task.FromResult(ret));
    }
Exemple #9
0
 private Task <bool> OnSaveAsync(EditFooTree item, ItemChangedType changedType)
 {
     if (changedType == ItemChangedType.Add)
     {
         item.Id = AllItems.Max(i => i.Id) + 1;
         AllItems.Add(item);
     }
     else
     {
         var oldItem = AllItems.FirstOrDefault(i => i.Id == item.Id);
         if (oldItem != null)
         {
             oldItem.ParentId = item.ParentId;
             oldItem.Name     = item.Name;
             oldItem.DateTime = item.DateTime;
             oldItem.Address  = item.Address;
             oldItem.Count    = item.Count;
         }
     }
     return(Task.FromResult(true));
 }
Exemple #10
0
 private Task <bool> OnSaveAsync(UserDto item, ItemChangedType changedType)
 {
     // 增加数据演示代码
     if (changedType == ItemChangedType.Add)
     {
         //System.Console.WriteLine(JsonSerializer.Serialize(item));
         Items.Add(item);
     }
     else
     {
         //var oldItem = Items.FirstOrDefault(i => i.Id == item.Id);
         //if (oldItem != null)
         //{
         //    oldItem.Name = item.Name;
         //    oldItem.Address = item.Address;
         //    oldItem.DateTime = item.DateTime;
         //    oldItem.Count = item.Count;
         //    oldItem.Complete = item.Complete;
         //    oldItem.Education = item.Education;
         //}
     }
     return(Task.FromResult(true));
 }
 private Task <bool> OnSaveAsync(Foo item, ItemChangedType changedType)
 {
     // 增加数据演示代码
     if (changedType == ItemChangedType.Add)
     {
         item.Id = Items.Max(i => i.Id) + 1;
         Items.Add(item);
     }
     else
     {
         var oldItem = Items.FirstOrDefault(i => i.Id == item.Id);
         if (oldItem != null)
         {
             oldItem.Name      = item.Name;
             oldItem.Address   = item.Address;
             oldItem.DateTime  = item.DateTime;
             oldItem.Count     = item.Count;
             oldItem.Complete  = item.Complete;
             oldItem.Education = item.Education;
         }
     }
     return(Task.FromResult(true));
 }
Exemple #12
0
    private async Task <bool> InternalOnSaveAsync(TItem item, ItemChangedType changedType)
    {
        var ret = false;

        if (OnSaveAsync != null)
        {
            ret = await OnSaveAsync(item, changedType);
        }
        else
        {
            if (Items != null)
            {
                // always return true if use Items as datasource
                ret = true;
            }
            else
            {
                var d = DataService ?? InjectDataService;
                ret = await d.SaveAsync(item, changedType);
            }
        }
        return(ret);
    }
    /// <summary>
    /// 保存方法
    /// </summary>
    /// <param name="model"></param>
    /// <param name="changedType"></param>
    /// <returns></returns>
    public override async Task <bool> SaveAsync(TModel model, ItemChangedType changedType)
    {
        await _db.GetRepository <TModel>().InsertOrUpdateAsync(model);

        return(true);
    }
Exemple #14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="model"></param>
 /// <param name="changedType"></param>
 /// <returns></returns>
 public override Task <bool> SaveAsync(TModel model, ItemChangedType changedType) => Task.FromResult(false);
Exemple #15
0
 public ItemChangedEventArgs(ItemChangedType type, T item)
 {
     this.Type = type;
     this.Item = item;
 }
Exemple #16
0
    /// <summary>
    /// 保存方法
    /// </summary>
    /// <param name="model"></param>
    /// <param name="changedType"></param>
    /// <returns></returns>
    public override async Task <bool> SaveAsync(TModel model, ItemChangedType changedType)
    {
        await _db.SaveAsync(model);

        return(true);
    }
Exemple #17
0
    /// <summary>
    /// RenderTreeBuilder 扩展方法 通过指定模型与属性生成编辑组件
    /// </summary>
    /// <param name="builder"></param>
    /// <param name="model"></param>
    /// <param name="component"></param>
    /// <param name="item"></param>
    /// <param name="changedType"></param>
    /// <param name="isSearch"></param>
    /// <param name="lookUpService"></param>
    public static void CreateComponentByFieldType(this RenderTreeBuilder builder, ComponentBase component, IEditorItem item, object model, ItemChangedType changedType = ItemChangedType.Update, bool isSearch = false, ILookupService?lookUpService = null)
    {
        var fieldType   = item.PropertyType;
        var fieldName   = item.GetFieldName();
        var displayName = item.GetDisplayName() ?? GetDisplayName(model, fieldName);

        var fieldValue        = GenerateValue(model, fieldName);
        var fieldValueChanged = GenerateValueChanged(component, model, fieldName, fieldType);
        var valueExpression   = GenerateValueExpression(model, fieldName, fieldType);
        var lookup            = item.Lookup ?? lookUpService?.GetItemsByKey(item.LookupServiceKey);
        var componentType     = item.ComponentType ?? GenerateComponentType(fieldType, item.Rows != 0, lookup);

        builder.OpenComponent(0, componentType);
        if (componentType.IsSubclassOf(typeof(ValidateBase <>).MakeGenericType(fieldType)))
        {
            builder.AddAttribute(1, nameof(ValidateBase <string> .DisplayText), displayName);
            builder.AddAttribute(2, nameof(ValidateBase <string> .Value), fieldValue);
            builder.AddAttribute(3, nameof(ValidateBase <string> .ValueChanged), fieldValueChanged);
            builder.AddAttribute(4, nameof(ValidateBase <string> .ValueExpression), valueExpression);

            if (!item.CanWrite(model.GetType(), changedType, isSearch))
            {
                builder.AddAttribute(5, nameof(ValidateBase <string> .IsDisabled), true);
            }

            if (item.ValidateRules != null)
            {
                builder.AddAttribute(6, nameof(ValidateBase <string> .ValidateRules), item.ValidateRules);
            }

            if (item.ShowLabelTooltip != null)
            {
                builder.AddAttribute(7, nameof(ValidateBase <string> .ShowLabelTooltip), item.ShowLabelTooltip);
            }
        }

        if (componentType == typeof(NullSwitch) && TryGetProperty(model.GetType(), fieldName, out var propertyInfo))
        {
            // 读取默认值
            var defaultValueAttr = propertyInfo.GetCustomAttribute <DefaultValueAttribute>();
            if (defaultValueAttr != null)
            {
                var dv = defaultValueAttr.Value is bool v && v;
                builder.AddAttribute(8, nameof(NullSwitch.DefaultValueWhenNull), dv);
            }
        }

        if (IsCheckboxList(fieldType, componentType) && item.Items != null)
        {
            builder.AddAttribute(9, nameof(CheckboxList <IEnumerable <string> > .Items), item.Items.Clone());
        }

        // Nullabl<bool?>
        if (item.ComponentType == typeof(Select <bool?>) && fieldType == typeof(bool?) && lookup == null && item.Items == null)
        {
            builder.AddAttribute(10, nameof(Select <bool?> .Items), GetNullableBoolItems(model, fieldName));
        }

        // Lookup
        if (lookup != null && item.Items == null)
        {
            builder.AddAttribute(11, nameof(Select <SelectedItem> .Items), lookup.Clone());
            builder.AddAttribute(12, nameof(Select <SelectedItem> .StringComparison), item.LookupStringComparison);
        }

        // 增加非枚举类,手动设定 ComponentType 为 Select 并且 Data 有值 自动生成下拉框
        if (item.Items != null && item.ComponentType == typeof(Select <>).MakeGenericType(fieldType))
        {
            builder.AddAttribute(13, nameof(Select <SelectedItem> .Items), item.Items.Clone());
        }

        // 设置 SkipValidate 参数
        if (IsValidatableComponent(componentType))
        {
            builder.AddAttribute(14, nameof(IEditorItem.SkipValidate), item.SkipValidate);
        }

        builder.AddMultipleAttributes(15, CreateMultipleAttributes(fieldType, model, fieldName, item));

        if (item.ComponentParameters != null)
        {
            builder.AddMultipleAttributes(16, item.ComponentParameters);
        }
        builder.CloseComponent();
    }
 public override Task <bool> SaveAsync(TModel model, ItemChangedType changedType)
 {
     return(base.SaveAsync(model, changedType));
 }
Exemple #19
0
 public Task <bool> SaveAsync(TModel model, ItemChangedType changedType) => Task.FromResult(true);
Exemple #20
0
 private static Task <bool> OnSaveAsync(Foo foo, ItemChangedType changedType)
 {
     return(Task.FromResult(true));
 }
Exemple #21
0
    public void IsEditable_Editable(ItemChangedType itemChangedType)
    {
        var editorItem = new EditorItem <Foo, string>();

        Assert.True(editorItem.IsEditable(itemChangedType));
    }