using Ping9719.WpfEx;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
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;
using 智慧物流软件系统.ViewModel;

namespace 智慧物流软件系统
{
    public partial class ShelfInfoView : UserControlBase
    {
        public ShelfInfoViewModel viewModel { get; set; } = new ShelfInfoViewModel();
        public ShelfInfoView()
        {
            InitializeComponent();
            this.DataContext = viewModel;
        }

        private void LoadedVisible(object sender, EventArgs e)
        {
            //viewModel.BtnReset();

            viewModel.InitShelfTypeItems();

            viewModel.BtnSearchReset();
        }

        private void allChecked_Checked(object sender, RoutedEventArgs e)
        {
            if (viewModel != null && viewModel.DataGridItemSource != null && viewModel.DataGridItemSource.Count() > 0)
            {
                foreach (var item in viewModel.DataGridItemSource)
                {
                    item.IsSelected = true;
                }
            }
        }

        private void allChecked_Unchecked(object sender, RoutedEventArgs e)
        {
            if (viewModel != null && viewModel.DataGridItemSource != null && viewModel.DataGridItemSource.Count() > 0)
            {
                foreach (var item in viewModel.DataGridItemSource)
                {
                    item.IsSelected = false;
                }
            }
        }

        private void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                // 更新选中项的状态
                if (dataGrid.SelectedCells.Count > 0 && viewModel.SelectedataGridItem != null)
                {
                    viewModel.SelectedataGridItem.IsSelected = !viewModel.SelectedataGridItem.IsSelected;
                    dataGrid.UnselectAllCells(); // 取消选中所有单元格
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("SelectionChanged event handler failed: " + ex.Message);
            }
        }

        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            ;
        }

        private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            ;
        }

        private void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            ;
        }

        private void UserControlBase_Loaded(object sender, RoutedEventArgs e)
        {
            //viewModel.BtnSearch();
        }
    }
}
