using HandyControl.Controls;
using HandyControl.Data;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using System.Media;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using TouchSocket.Core;
using WCS.Model.ApiModel.MatInventoryDetail;
using 智慧物流软件系统.ViewModels;

namespace 智慧物流软件系统
{
    public partial class OutInventoryAddMatView : HandyControl.Controls.Window
    {
        public OutInventoryAddMatViewModel viewModel = new OutInventoryAddMatViewModel();

        public MatInventorySummaryModel inventorySummary = null;

        public OutInventoryAddMatView(int shelfTypeId)
        {
            InitializeComponent();
            this.DataContext = viewModel;
            viewModel.ShelfTypeId = shelfTypeId;
        }

        private void closeClick(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }

        private void comfirmClick(object sender, RoutedEventArgs e)
        {
            if (viewModel.DataGridItemSource == null)
            {
                HandyControl.Controls.MessageBox.Show("请搜索后选择物料！若不需要添加请点击【取消】按钮！");
                return;
            }
            var item = viewModel.DataGridItemSource.Where(t => t.isSelected).FirstOrDefault();
            if (item == null)
            {
                HandyControl.Controls.MessageBox.Show("请选择物料！");
                return;
            }
            else
            {
                //选中物料返回
                inventorySummary = item;
                this.DialogResult = true;
                this.Close();
            }
        }

        private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (viewModel.SelectedataGridItem != null)
                {
                    viewModel.SelectedataGridItem.IsSelected = true;
                    //dataGrid.UnselectAllCells();//取消选中 避免手动点击check选项时反选失败 和重新点击该项时反选失败
                }

            }
            catch
            {

            }
        }

        private void dataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            comfirmClick(sender, e);
        }
    }

}
