using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZXDT.CallCenter.MVCWeb.Models;

namespace ZXDT.CallCenter.MVCWeb.Controllers
{
    public class OptLogsController : Controller
    {
        //
        // GET: /OptLogs/

        /// <summary>
        /// 登录日志
        /// </summary>
        /// <returns></returns>
        public ActionResult LoginLogList()
        {
            WorkOrderMyModel model = new WorkOrderMyModel();
            return View(model);
        }
        /// <summary>
        /// 获取通话记录
        /// </summary>
        /// <param name="page">当前页码</param>
        /// <param name="limit">每页数据量</param>
        /// <param name="sqlWhere">查询条件</param>
        /// <returns></returns>
        [ActionName("LoginLogsData")]
        [HttpGet]
        public string LoginLogsData(DateTime? NowDateTime, int page, int limit, string userName, string dateParty)
        {

            //数据结果集
            ResponseData dataModel = new ResponseData();

            string sql = "";


            if (!string.IsNullOrEmpty(userName))
            {
                sql += " and F_LoginName like '%" + userName + "%'";
            }

            //查询按钮

            if (!string.IsNullOrEmpty(dateParty))
            {

                string startDate = dateParty.Substring(0, 19);
                string endDate = dateParty.Substring(21);
                sql += " and F_LoginDate>= '" + startDate + "'";
                sql += " and F_LoginDate<= '" + endDate + "'";
            }

            DataTable dt = new DataTable();
            int recordCount = 0;
            Model.PageData<Model.T_Call_CallRecords_All> pageModel = new Model.PageData<Model.T_Call_CallRecords_All>();
            dt = BLL.PagerBLL.GetListPager(
                "T_Sys_LoginLogs",
                "F_Id",
                "*,CONVERT(varchar,F_LoginDate, 120 ) as F_LoginDateNew",
                sql,
                "ORDER BY F_Id desc",
                limit,
                page,
                true,
                out recordCount);


            dataModel.code = 0;
            dataModel.count = recordCount;
            dataModel.data = dt;
            string json = JsonConvert.SerializeObject(dataModel);
            return json;
        }

    }
}
