using PageAdmin.BLL;
using PageAdmin.Common;using PageAdmin.Utils.ORM;using PageAdmin.Utils;
using PageAdmin.Web.Filter;
using System;
using System.Web.Mvc;

namespace PageAdmin.Web.Areas.Admin.Controllers
{

    public class InfoTableController : DefaultBaseController
    {
        public InfoTableController() : base("pa_info_table", "System/Table/")
        {
            base.CheckRepeatFieldDic.Add("name", "表名");
            base.ListDataExecuting = OnListData;
            base.AddExecuted= new Action(OnAddActioned);
            base.DeleteExecuting = DeleteRelative;
            base.MvcContext.ListOrder = "xuhao asc";
        }

        private void OnListData()
        {
           string isLoad = Request.QueryString["_isload"];
            if(isLoad=="1")
            {
                MvcContext.Fields = "id,name,remark";
            }
        }

        /// <summary>
        /// 添加记录后，添加表
        /// </summary>
        private void OnAddActioned()
        {
            InfoTableBLL tableBll = new InfoTableBLL();
            tableBll.Add(base.MvcContext);
        }

        private void DeleteRelative()
        {
            InfoTableBLL tableBll = new InfoTableBLL();
            int id = StringHelper.Format<int>(base.MvcContext.Data["id"]);
           base.MvcContext.TipsInfo=tableBll.Delete(id);
        }


        [AjaxOnly]
        [HttpGet]
        public string GetRemark()
        {
            InfoTableBLL tableBll = new InfoTableBLL();
            string name = StringHelper.Format<string>(Request.QueryString["name"]);
            return tableBll.GetRemark(name);
        }


        [HttpGet]
        [CheckTable(TableType = TableTypeEnum.CustomInfoTable)]
        ///获取表单html
        public ActionResult FormHtml()
        {
            return View();
        }

        [NotCheckMenuItemPermissions]
        [HttpGet]
        public ActionResult Select()
        {
            return View();
        }
    }
}
