using CCDCount.MODEL.SqlDataModel;
using CCDCountWpf.WpfFrom;
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.Navigation;
using System.Windows.Shapes;

namespace CCDCountWpf.WpfPage
{
    /// <summary>
    /// UserManagementPage.xaml 的交互逻辑
    /// </summary>
    public partial class UserManagementPage : Page
    {
        UserMesDataModelClass SelectUserMessage = null;
        public UserManagementPage()
        {
            InitializeComponent();
            DataContext = ShowMessageBus.ShowBinding;
            ShowMessageBus.ShowBinding.UserMesDataModels = MessageBus.UserMessageClass.GetAllUserMessage();
        }

        private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var selectedItem = UserMessageDataGrid.SelectedItem as UserMesDataModelClass; // 替换为实际数据类型
            if (selectedItem != null)
            {
                SelectUserMessage = selectedItem;
            }
        }

        private void ChangeUserBtn_Click(object sender, RoutedEventArgs e)
        {
            if (SelectUserMessage.Id == 1&&MessageBus.NowLoginUserMessage.Id != 1)
            {
                MessageBox.Show("权限不足，不可操作Admin用户");
                return;
            }
            if (SelectUserMessage == null)
            {
                MessageBox.Show("请选择用户");
                return;
            }
            ChangeUserWindow changeUserWindow = new ChangeUserWindow();
            changeUserWindow.UserMessage = SelectUserMessage;
            changeUserWindow.ShowDialog();
        }

        private void DeleteUserBtn_Click(object sender, RoutedEventArgs e)
        {
            if (SelectUserMessage.Id == 1)
            {
                MessageBox.Show("Admin管理员账户，不可删除");
                return;
            }
            if (SelectUserMessage == null)
            {
                MessageBox.Show("请选择用户");
                return;
            }
            MessageBus.UserMessageClass.DeleteUserMessage(SelectUserMessage.Id);
            ShowMessageBus.ShowBinding.UserMesDataModels = MessageBus.UserMessageClass.GetAllUserMessage();
        }

        private void AddUserBtn_Click(object sender, RoutedEventArgs e)
        {
            AddUserWindow addUserWindow = new AddUserWindow();
            addUserWindow.ShowDialog();
        }
    }
}
