using CCDCount.DLL;
using CCDCount.DLL.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CCDCountWpf
{
    /// <summary>
    /// UserLoginWindow.xaml 的交互逻辑
    /// </summary>
    public partial class UserLoginWindow : Window
    {
        public UserLoginWindow()
        {
            InitializeComponent();
        }

        private void UserLoginBtn_Click(object sender, RoutedEventArgs e)
        {
            if(!MessageBus.UserMessageClass.CheckUserLogin(UserNameTbx.Text, UserPassTbx.Password))
            {
                MessageBox.Show("用户名或密码错误！");
                return;
            }
            MessageBus.NowLoginUserMessage = MessageBus.UserMessageClass.GetUserMessageForName(UserNameTbx.Text)[0];
            FaultLog.SetUserID(MessageBus.NowLoginUserMessage.Id);
            SplashWindow splash = new SplashWindow();
            splash.Show();
            this.Close();

            MainWindow mainWindow = new MainWindow();
            mainWindow.Show();
            splash.Close();
        }

        private void UserCancelBtn_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
            Environment.Exit(0);
        }

        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                // 触发目标按钮的点击事件
                UserLoginBtn.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                e.Handled = true; // 标记事件已处理
            }
        }

        private void UserNameTbx_GotFocus(object sender, RoutedEventArgs e)
        {
            //OnScreenKeyboard.Show();
        }

        private void UserPassTbx_GotFocus(object sender, RoutedEventArgs e)
        {
            //OnScreenKeyboard.Show();
        }

        private void KeyBoardBtn_Click(object sender, RoutedEventArgs e)
        {
            OnScreenKeyboard.KeyBoardShow();
        }
    }
}
