using HandyControl.Controls; using SqlSugar; using System; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Windows; using System.Windows.Input; using WCS.BLL.DbModels; using WCS.Model; using WCS.Model.ApiModel.MatBaseInfo; using 货架标准上位机.Api; using 货架标准上位机.ViewModel; namespace 货架标准上位机 { public partial class MatBaseInoGenarateMatInfoView : System.Windows.Window { public MatBaseInfoModel matBaseInfo = null; public MatBaseInoGenarateMatInfoView(MatBaseInfoModel _matBaseInfo = null) { InitializeComponent(); if (_matBaseInfo != null) { matBaseInfo = _matBaseInfo; //绑定数据 txtMatCode.Text = matBaseInfo.MatCode; txtMatName.Text = matBaseInfo.MatName; txtMatSpec.Text = matBaseInfo.MatSpec; txtMatCustomer.Text = matBaseInfo.MatCustomer; } } private void btnOk_Click(object sender, RoutedEventArgs e) { #region 数据校验 if (string.IsNullOrEmpty(txtMatBatch.Text.Trim())) { Growl.Warning("请输入物料批次后进行操作!"); txtMatBatch.Focus(); return; } var matBatch = txtMatBatch.Text.Trim(); if (!IsInputNumberAllowed(matBatch)) { Growl.Warning("【物料批次】请输入数字!"); txtMatBatch.Focus(); return; //正则表达式 //匹配年周 //^\d{ 4}\d{ 1,2}$ //匹配年月日 //^\d{ 4} (0[1 - 9] | 1[0 - 2])(0[1 - 9] | [12]\d | 3[01])$ } var matQty = txtMatQty.Text.Trim(); if (!IsInputNumberAllowed(matQty)) { Growl.Warning("【单盘数量】请输入数字!"); txtMatQty.Focus(); return; } var totalCount = txtTotalCount.Text.Trim(); if (!IsInputNumberAllowed(totalCount)) { Growl.Warning("【物料盘数】请输入数字!"); txtTotalCount.Focus(); return; } #endregion #region 调用接口生成条码 try { var body = new GenerateMatInfoRequest() { MatBaseInfo = matBaseInfo, MatBatch = matBatch, TotalCount = Convert.ToInt32(txtTotalCount.Text.Trim()), MatQty = Convert.ToInt32(txtMatQty.Text.Trim()), UserName = LocalStatic.CurrentUser, DeviceType = LocalFile.Config.DeviceType, }; var Result = ApiHelp.GetDataFromHttp>>(LocalFile.Config.ApiIpHost + "matBaseInfo/generateMatInfo", body, "POST"); if (Result != null && Result.Data != null && Result.Data.Count > 0) { Growl.Success("生成成功!"); } } catch (Exception ex) { Growl.Error("加载数据失败:" + ex.Message); return; } #endregion 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); } } }