// 廣告成效頁
        public ActionResult Index(AdsStatisticsSearchModel search, long?siteId, int?index)
        {
            DateTime today = DateTime.Now;
            DateTime firstDayOfCurrentMonth = new DateTime(today.Year, today.Month, 1);
            DateTime endDayOfCurrentMonth   = firstDayOfCurrentMonth.AddMonths(1).AddDays(-1);

            if (Request.HttpMethod == "GET")
            {
                if (index == null)
                {
                    Utility.ClearSearchValue();
                    search.StartDate        = search.StartDate != DateTime.MinValue ? search.StartDate : firstDayOfCurrentMonth;
                    search.EndDate          = search.EndDate != DateTime.MinValue ? search.EndDate : endDayOfCurrentMonth;
                    Session["ExportSearch"] = search;
                }
                else
                {
                    AdsStatisticsSearchModel prevSearch = Utility.GetSearchValue <AdsStatisticsSearchModel>();
                    if (prevSearch != null)
                    {
                        search = prevSearch;
                    }
                }
            }
            else if (Request.HttpMethod == "POST")
            {
                Utility.SetSearchValue(search);
                Session["ExportSearch"] = search;
            }

            search.SiteId = search.SiteId ?? siteId;

            if (index == null)
            {
                index = 1;
            }

            int pageSize    = 20;
            int recordCount = 0;
            List <AdsStatisticsViewModel> statisticsData = AdvertisementStatisticsDAO.GetAdsStatisticsData(search, pageSize, (int)index, out recordCount);

            ViewBag.Pagination = new Pagination {
                PageSize = pageSize, PageIndex = (int)index, TotalRecord = recordCount
            };
            ViewBag.AdsPositionMapping = AdvertisementStatisticsDAO.AdsPosition;
            ViewBag.UploadUrl          = WorkV3.Golbal.UpdFileInfo.GetVPathBySiteID((long)search.SiteId, "Advertisement");
            ViewBag.Search             = search;
            ViewBag.StartDate          = firstDayOfCurrentMonth;
            ViewBag.EndDate            = endDayOfCurrentMonth;
            ViewBag.SiteId             = search.SiteId;

            return(View(statisticsData));
        }
        // 廣告成效詳細內容頁
        public ActionResult Detail(AdsDetailStatisticsSearchModel search, int?index)
        {
            DateTime          today = DateTime.Now;
            DateTime          firstDayOfCurrentMonth = new DateTime(today.Year, today.Month, 1);
            DateTime          endDayOfCurrentMonth   = firstDayOfCurrentMonth.AddMonths(1).AddDays(-1);
            AdsCustomizeModel adCustomize            = AdvertisementDAO.GetAdsCustomizeItem(search.AdsCustomId);

            adCustomize = adCustomize ?? new AdsCustomizeModel();

            if (Request.HttpMethod == "GET")
            {
                if (index == null)
                {
                    Utility.ClearSearchValue();
                    search.StartDate = search.StartDate != DateTime.MinValue ? search.StartDate : firstDayOfCurrentMonth;
                    search.EndDate   = search.EndDate != DateTime.MinValue ? search.EndDate : endDayOfCurrentMonth;
                    Session["ExportDetailSearch"] = search;
                }
                else
                {
                    AdsDetailStatisticsSearchModel prevSearch = Utility.GetSearchValue <AdsDetailStatisticsSearchModel>();
                    if (prevSearch != null)
                    {
                        search = prevSearch;
                    }
                }
            }
            else if (Request.HttpMethod == "POST")
            {
                Utility.SetSearchValue(search);
                Session["ExportDetailSearch"] = search;
            }

            if (index == null)
            {
                index = 1;
            }

            int pageSize    = 20;
            int recordCount = 0;
            List <AdsStatisticsDetailViewModel> statisticsData = AdvertisementStatisticsDAO.GetStatisticsDetail(search, pageSize, (int)index, out recordCount);

            ViewBag.Pagination = new Pagination {
                PageSize = pageSize, PageIndex = (int)index, TotalRecord = recordCount
            };
            ViewBag.Search    = search;
            ViewBag.StartDate = firstDayOfCurrentMonth;
            ViewBag.EndDate   = endDayOfCurrentMonth;
            ViewBag.AdsCustomizeDescription = adCustomize.Description;
            return(View(statisticsData));
        }
        public FileResult ExportAdvertisers(bool?privacy)
        {
            AdsDetailStatisticsSearchModel search = Session["ExportAdvertiserSearch"] as AdsDetailStatisticsSearchModel;

            if (search == null)
            {
                search = new AdsDetailStatisticsSearchModel();
            }

            ViewData["AdvertiserInfo"]    = AdvertisementStatisticsDAO.GetAllAdvertisers(search);
            ViewData["AdvertiserPrivacy"] = privacy ?? false;

            string html = Utility.GetViewHtml(this, "ExportAdvertisers", null);

            string title = $"廣告主分析報表-{DateTime.Now.ToString("yyyyMMddHHmmsss")}.xls";

            return(File(System.Text.Encoding.UTF8.GetBytes(html), "application/vnd.ms-excel", title));
        }
        public FileResult ExportDetail(bool?privacy, bool IsClick = true)
        {
            AdsDetailStatisticsSearchModel search = Session["ExportDetailSearch"] as AdsDetailStatisticsSearchModel;

            if (search == null)
            {
                search = new AdsDetailStatisticsSearchModel();
            }

            ViewData["DetailInfo"]    = AdvertisementStatisticsDAO.GetAllDetail(search);
            ViewData["DetailPrivacy"] = privacy ?? false;

            string html = Utility.GetViewHtml(this, "ExportDetail", null);

            string titleCategory = IsClick ? "點擊量" : "瀏覽量";
            string title         = $"廣告{titleCategory}分析報表-{DateTime.Now.ToString("yyyyMMddHHmmsss")}.xls";

            return(File(System.Text.Encoding.UTF8.GetBytes(html), "application/vnd.ms-excel", title));
        }
        public ActionResult GetChart(DateTime startTime, DateTime endTime, List <long> advertisers = null, long adsCustomizeId = 0)
        {
            string jsonData = AdvertisementStatisticsDAO.GetChart(startTime, endTime, advertisers, adsCustomizeId);

            return(Content(jsonData));
        }