using HandyControl.Controls;
using HandyControl.Tools.Extension;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using WCS.BLL.DbModels;
using WCS.Model;
using WCS.Model.ApiModel.MatBaseInfo;
using 智慧物流软件系统.Api;
using 智慧物流软件系统.Tool;
using 智慧物流软件系统.ViewModel;
using 智慧物流软件系统.Views.Controls;

namespace 智慧物流软件系统
{
    public partial class MatBaseInoScanGenarateMatInfoView : System.Windows.Window
    {
        public MatBaseInoScanGenarateMatInfoViewModel viewModel = new MatBaseInoScanGenarateMatInfoViewModel();
        public MatBaseInoScanGenarateMatInfoView()
        {
            InitializeComponent();
            this.DataContext = viewModel;
            viewModel.ChangelessCode = LocalFile.Config.ChangelessCode;
            viewModel.ReservedCode = LocalFile.Config.ReservedCode;
            this.Topmost = true;
            this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
        }


        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;
            this.DialogResult = true;
            this.Close();
        }

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

        private void txtMatBatch_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e)
        {
            e.Handled = !IsInputNumberAllowed(e.Text);
        }

        private bool IsInputNumberAllowed(string text)
        {
            Regex regex = new Regex("^[0-9]+$"); // 只允许数字  
            return regex.IsMatch(text);
        }



        private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                txtMatQty.Focus();
                Thread.Sleep(1);
                txtTotalCount.Focus();
            }
        }

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