[fix]Config创建默认配置文件的开关Runtime.CreateConfigOnMissing,仅需对自动创建生效,而不应该阻止用户主动Save
智能大石头 编写于 2024-08-09 00:30:41 石头 提交于 2024-08-10 14:22:24
X
/*
 * XCoder v4.4.2011.1031
 * 作者:nnhy/NEWLIFE
 * 时间:2011-11-07 16:54:58
 * 版权:版权所有 (C) 新生命开发团队 2011
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using NewLife.CommonEntity;
using NewLife.Web;
using XCode;
using XControl;

/// <summary>实体列表页面基类</summary>
public abstract class MyEntityList : Page
{
    #region 管理页控制器
    private Type _EntityType;
    /// <summary>实体类</summary>
    public virtual Type EntityType { get { return _EntityType; } set { _EntityType = value; } }

    /// <summary>管理页控制器</summary>
    protected IManagePage Manager;

    protected override void OnPreInit(EventArgs e)
    {
        Manager = CommonService.Get<IManagePage>().Init(this, EntityType);

        base.OnPreInit(e);
    }
    #endregion

    protected override void OnPreLoad(EventArgs e)
    {
        base.OnPreLoad(e);

        AutoAddParamForAdd();
    }

    /// <summary>
    /// 自动为添加按钮附加参数,Request中,只要是当前实体成员的参数,否附加上去
    /// </summary>
    void AutoAddParamForAdd()
    {
        if (Request.QueryString == null || Request.QueryString.Count < 1) return;
        if (EntityType == null) return;

        LinkBox lb = ControlHelper.FindControlByField<LinkBox>(Page, "lbAdd");
        if (lb == null) return;

        StringBuilder sb = new StringBuilder();
        IEntityOperate op = EntityFactory.CreateOperate(EntityType);
        HashSet<String> hs = new HashSet<string>(op.FieldNames, StringComparer.OrdinalIgnoreCase);
        foreach (String item in Request.QueryString.Keys)
        {
            // 仅接受实体类成员
            if (!hs.Contains(item)) continue;

            if (sb.Length > 0) sb.Append("&");
            sb.AppendFormat("{0}={1}", item, Request.QueryString[item]);
        }
        if (sb.Length > 0)
        {
            if (!lb.Url.Contains("?"))
                lb.Url += "?" + sb;
            else
                lb.Url += "&" + sb;
        }
    }
}

/// <summary>实体列表页面基类</summary>
public class MyEntityList<TEntity> : MyEntityList where TEntity : Entity<TEntity>, new()
{
    /// <summary>实体类</summary>
    public override Type EntityType { get { return base.EntityType ?? (base.EntityType = typeof(TEntity)); } set { base.EntityType = value; } }
}