using M55128_rec.Business.TK;
using M55128_rec.Models.ViewModels.GallerMangerModel;
using M55128_rec.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace M55128_rec.Controllers
{
    [RoutePrefix("tk")]
    public class TKController : Controller
    {
        // GET: TK
        /// <summary>
        /// 图库首页
        /// </summary>
        /// <returns></returns>
        [Route("index.html")]
        public ActionResult Index()
        {
            int countrow = 0, countpage = 0;
            Dictionary<string, Object> dict = new Dictionary<string, object>();
            dict["AreaCode"] = "A";
            List<QueryAllDataModel> tkarea = TKApiBLL.QueryAll(1, 30, dict, out countrow, out countpage, 0);
            int qs = DateHelper.getTimeSpan();
            string q = DateTime.Now.Year + qs.ToString().PadLeft(3, '0');
            ViewBag.totalp = countpage;
            return View(Tuple.Create(tkarea, q));
        }
        /// <summary>
        /// 详情
        /// </summary>
        /// <param name="id"></param>
        /// <param name="p"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        [Route("{param}.html")]     
        public ActionResult TKXQ(string param)
        {
            string q = param.Split('_')[0];
            string id = param.Split('_')[1].Substring(1); 

            string qs =null;
            if (q != "0" && !string.IsNullOrWhiteSpace(q))
            {
                qs = q.Substring(4, 3);
            }

            ImageInfoModel model = TKApiBLL.QueryArtInfo(null, qs,id);
            var tk = TKApiBLL.GetBykey(model.galleryId);
            ViewBag.name = tk.GalleryName;
            ViewBag.mark = tk.Reamrk;
            ViewBag.qs = q;
            ViewBag.code=param.Split('_')[1].Substring(0,1);
            return View(model);
        }

        /// <summary>
        /// 图库全部
        /// </summary>
        /// <param name="t">1:带a b c;2:返回list数据</param>
        /// <param name="p"></param>
        /// <param name="r"></param>
        /// <param name="a"></param>
        /// <param name="q"></param>
        /// <returns>/TK/GetTKQB</returns>
        public ActionResult GetTKQB(string t = "1", int p = 1, int r = 50, string a = "A", string q = "")
        {
            ViewBag.qs = q;
            int qs = 0;
            if (q != "0" && !string.IsNullOrWhiteSpace(q))
            {
                qs = int.Parse(q.Substring(4, 3));
            }
            int countrow = 0, countpage = 0;
            Dictionary<string, Object> dict = new Dictionary<string, object>();
            dict["AreaCode"] = a;
            List<QueryAllDataModel> tkarea = TKApiBLL.QueryAll(p, r, dict, out countrow, out countpage, qs);
            ViewBag.p = p;
            ViewBag.totalp = countpage;
            return PartialView("TKQB", Tuple.Create(tkarea, t));
        }
        /// <summary>
        /// 图库热门
        /// </summary>
        /// <param name="type">1:带热门;2:返回list数据</param>
        /// <param name="page"></param>
        /// <param name="rows"></param>
        /// <param name="n"></param>
        /// <param name="periodsNumber"></param>
        public ActionResult GetTKRM(string t = "1", int p = 1, int r = 50, string n = "彩吧图谜", string q = "0")
        {
            ViewBag.qs = q;
            int qs = 0;
            if (q != "0" && !string.IsNullOrWhiteSpace(q))
            {
                qs = int.Parse(q.Substring(4, 3));
            }
            int countrow = 0, countpage = 0;
            List<HotMenuModel> tkhotmenu = new List<HotMenuModel>();
            if (t == "1")
            {
                tkhotmenu = TKApiBLL.QueryHotMenu(new List<string>() { "A", "B", "C" });
            }
            List<ImageMenuInfoModel> tkhlist = TKApiBLL.QueryHotArtList(p, r, n, out countrow, out countpage, qs);
            ViewBag.p = p;
            ViewBag.totalp = countpage;
            return PartialView("TKRM", Tuple.Create(tkhotmenu, tkhlist, t));
        }
        /// <summary>
        /// 图库最新
        /// </summary>
        /// <param name="t">1:第一次 2:下拉加载</param>
        /// <param name="p"></param>
        /// <param name="r"></param>
        /// <param name="q"></param>
        /// <returns></returns>
        public ActionResult GetTKZX(string t = "1", int p = 1, int r = 50, string q = "0")
        {
            int countrow = 0, countpage = 0;
            ViewBag.t = t;
            ViewBag.qs = q;
            int qs = 0;
            if (q != "0" && !string.IsNullOrWhiteSpace(q))
            {
                qs = int.Parse(q.Substring(4, 3));
            }
            ViewBag.t = t;
            List<ImageMenuInfoModel> tkzx = TKApiBLL.QueryNew(p, r, out countrow, out countpage, qs);
            ViewBag.p = p;
            ViewBag.totalp = countpage;
            return PartialView("TKZX", tkzx);
        }
        /// <summary>
        /// 图库历史
        /// </summary>
        /// <returns></returns>
        public ActionResult GetTKLS()
        {
            List<GalleryNumberList> tkls = TKApiBLL.GetTkPeriodsNumberList();
            return PartialView("TKLS", tkls);
        }

        public ActionResult Getqs(string y)
        {
            string qs = TKApiBLL.GetMaxInYear(y);
            return Json(qs, JsonRequestBehavior.AllowGet);
        }
    }
}