using HighWayIot.Repository.domain;
using HighWayIot.Repository.service;
using HighWayIot.Winform.Business;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HighWayIot.Winform.UserControlPages
{
    public partial class OperateConfigPage : UserControl
    {
        private static SysLogService sysLogService = SysLogService.Instance;

        private List<SysLogEntity> Lists;

        public OperateConfigPage()
        {
            InitializeComponent();
            Init();
        }

        private void Init()
        {
            LogDataGridView.AutoGenerateColumns = false;

            Lists = sysLogService.GetLogInfos();
            LogDataGridView.DataSource = null;
            LogDataGridView.DataSource = Lists;
        }

        private void SelectRole_Click(object sender, EventArgs e)
        {
            List<SysLogEntity> list = sysLogService.GetLogInfos();
           
            string logText = LogTextTextBox.Text.Trim();
            string operatorName = OperatorNameTextBox.Text.Trim();
            bool logTimeChecked = IsCheckByLogTime.Checked;
            DateTime logBeginTime = SelectLogBeginTime.Value;
            DateTime logEndTime = SelectLogEndTime.Value;

            Lists = list.Where(x =>
                (string.IsNullOrEmpty(logText) || x.Text.Contains(logText)) &&
                (string.IsNullOrEmpty(operatorName) || x.Operator == operatorName) &&
                (!logTimeChecked || (x.LogTime >= logBeginTime && x.LogTime <= logEndTime))
            ).ToList();

            LogDataGridView.DataSource = null;
            LogDataGridView.DataSource = Lists;
        }
    }
}
