using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PageAdmin.BLL;using PageAdmin.Filter;
using PageAdmin.Common;
using System.Data;
using System.Collections.Specialized;

namespace PageAdmin.Web.Areas.Admin.Controllers
{
    public class CollectionDetailRuleController : BaseView
    {
        CollectionDetailRuleBLL BLL = new CollectionDetailRuleBLL();
        public CollectionDetailRuleController() : base("Tool")
        {
        }
        [HttpGet]
        public ActionResult Add()
        {
            int collection_id = StringHelper.Format<int>(Request.QueryString["collection_id"]);
            string FieldName = BLL.SelectField(collection_id);
            ViewBag.FieldName = FieldName;
            return View((object)FieldName);
        }
        [ValidateInput(false)]
        [HttpPost]
        public JsonResult Add(FormCollection form)
        {
            return Json(BLL.Add(form));
        }
        [HttpGet]
        public ActionResult Test()
        {
            NameValueCollection form = Request.QueryString;
            ViewBag.Test = BLL.Test(form);
            return View();
        }
        [ValidateInput(false)]
        [HttpPost]
        public JsonResult Test(FormCollection form)
        {
            int collection_id = StringHelper.Format<int>(form["collection_id"]);
            BLL.InsertRule(form, collection_id);
            TipsInfo tipsInfo = new TipsInfo();
            return Json(tipsInfo);
        }
        [HttpGet]
        public string GetCollectionDetailRule()
        {
            int collection_id = StringHelper.Format<int>(Request.QueryString["collection_id"]);
            DataTable dt = PA.GetDataTable("pa_collection_detail_rule", "*", "collection_id=" + collection_id);
            return Json(dt);
        }
        [HttpGet]
        public ActionResult Set()
        {
            return View();
        }
        [HttpGet]
        public string ListData()
        {
            var form = Request.QueryString;
            int site_id = StringHelper.Format<int>(form["site_id"]);
            DataTable dt = PA.GetDataTable("pa_column", "id,name", "site_id=" + site_id);
            return Json(dt);
        }
    }
}

