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;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HighWayIot.Winform.MainForm
{
    public partial class LoginForm : Form
    {
        SysUserInfoService sysUserInfoService = SysUserInfoService.Instance;

        public LoginForm()
        {
            InitializeComponent();
            
        }



        /// <summary>
        /// 登陆验证
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Login_Click(object sender, EventArgs e)
        {
            //验证账号密码，或从数据库验证成功
            var lists = sysUserInfoService.GetUserInfoByUserName(UserText.Text);

            if (lists.Count == 1 && lists.First().Password == PassText.Text)
            {
                //更新登录时间
                lists.First().LastLoginTime = DateTime.Now;
                RoleBusiness.LoginUserName = UserText.Text;
                sysUserInfoService.UpdateUserInfo(lists.First());
                DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("账号或密码错误！");
                return;
            }
        }

        /// <summary>
        /// 自动登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LoginForm_Load(object sender, EventArgs e)
        {
            //Login_Click(sender, e);
        }
    }
}
