using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Data;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using MySystem.PxcModels;
using System.Threading;
using Library;
using LitJson;

namespace MySystem.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;

        public HomeController(ILogger<HomeController> logger)
        {
            _logger = logger;
        }

        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Error()
        {
            string isapi = Request.Headers["Api"].ToString();
            if (isapi != "1")
            {
                if (Response.StatusCode == 500)
                {
                    return Redirect("/public/errpage/pc/500.html");
                }
                else if (Response.StatusCode == 502)
                {
                    return Redirect("/public/errpage/pc/502.html");
                }
                else if (Response.StatusCode == 404)
                {
                    return Redirect("/public/errpage/pc/404.html");
                }
            }
            return View();
        }
        public string Tmp()
        {
            string result = "";
            // string conn = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
            // DataTable dt = CustomerSqlConn.dtable("select UserId from HelpProfitAmountSummary where TradeMonth>MaxAmount and TradeMonth='202301'", conn);
            // foreach(DataRow dr in dt.Rows)
            // {
            //     int UserId = int.Parse(dr["UserId"].ToString());
            //     decimal HelpAmount = 0; //当天总交易额
            //     DataTable dtsub = CustomerSqlConn.dtable("SELECT SUM(TradeAmount) TradeAmount FROM HelpProfitMerTradeSummay WHERE MerchantId IN(SELECT MerchantId FROM HelpProfitMerIds WHERE UserId=" + UserId + ") AND TradeDate='20230101'", conn);
            //     if(dtsub.Rows.Count > 0)
            //     {
            //         HelpAmount = decimal.Parse(function.CheckNum(dtsub.Rows[0]["TradeAmount"].ToString()));
            //     }
            //     result += test(UserId, HelpAmount);
            //     result += "\n\n";
            // }
            return result;
        }

        public string Test()
        {
            string result = "ok";
            StatService.Instance.Other();
            return result;
        }
    }
}