using HKCardIN.Logic;
using HKCardIN.Logic.Model;
using HKLog;
using System.Text.RegularExpressions;
using System.Windows;
using UHFHelper;
using XExten.Advance.LinqFramework;

namespace HKCardIN.Views
{
    /// <summary>
    /// CardView.xaml 的交互逻辑
    /// </summary>
    public partial class CardView : System.Windows.Window
    {
        UserAndCardInfo info;
        public CardView()
        {
            InitializeComponent();
        }

        private void QueryClick(object sender, RoutedEventArgs e)
        {
            if (this.Phone.Text.IsNullOrEmpty()) HandyControl.Controls.Growl.InfoGlobal("手机号不能为空!");
            if (!Regex.IsMatch(this.Phone.Text, "\\d{11}")) HandyControl.Controls.Growl.InfoGlobal("请输入正确的手机号!");
            info = BaseLogic.GetInstance().GetCardNoByPhone(Phone.Text);
            if (info != null)
                //查询接口
                Create.IsEnabled = true;
        }

        private void CreateClick(object sender, RoutedEventArgs e)
        {
            if (info.CardNum == null) return;
            var res = UHFCardHelper.GetInstance().WriteCard(info.CardNum);
            HKLogImport.WriteInfo(res.ResMes);
            DialogResult = true;
            Close();
        }
    }
}
