using HandyControl.Controls;
using SqlSugar;
using System;
using System.Windows;
using WCS.BLL.DbModels;
using WCS.Model.ApiModel.Stocktaking;
using 智慧物流软件系统.ViewModel;

namespace 智慧物流软件系统
{
    public partial class MatDetailStocktakingInfoUpdateView : System.Windows.Window
    {
        public MatDetailStocktakingInfoModel matDetailStocktakingInfo = null;


        public MatDetailStocktakingInfoUpdateView(string _titleText, MatDetailStocktakingInfoModel _matDetailStocktakingInfo = null)
        {
            InitializeComponent();

            if (_matDetailStocktakingInfo != null)
            {
                matDetailStocktakingInfo = _matDetailStocktakingInfo;
                //绑定数据
                MatCode.Text = matDetailStocktakingInfo.MatCode;
                MatName.Text = matDetailStocktakingInfo.MatName;
                MatBatch.Text = matDetailStocktakingInfo.MatBatch;
                MatSpec.Text = matDetailStocktakingInfo.MatSpec;

                ShelfCode.Text = matDetailStocktakingInfo.ShelfCode;
                ShelfArea.Text = matDetailStocktakingInfo.ShelfArea;

                MatQty.Text = matDetailStocktakingInfo.MatQty.ToString();
                StocktakingQty.Text = matDetailStocktakingInfo.StocktakingQty.ToString();
            }

            //绑定标题
            if (!string.IsNullOrEmpty(_titleText))
            {
                Title.Text = _titleText;
            }

        }


        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int.Parse(StocktakingQty.Text);
            }
            catch
            {
                HandyControl.Controls.MessageBox.Show("盘点数量请输入有效数字！");
                StocktakingQty.Focus();
                StocktakingQty.SelectionStart = StocktakingQty.Text.Length;
                return;
            }

            matDetailStocktakingInfo.StocktakingQty = int.Parse(StocktakingQty.Text); ;

            this.DialogResult = true;
            this.Close();
        }

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

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            StocktakingQty.Focus();
            StocktakingQty.SelectionStart = StocktakingQty.Text.Length;
        }
    }
}
