!提交代码
This commit is contained in:
207
货架标准上位机/ViewModels/InInventoryViewModel.cs
Normal file
207
货架标准上位机/ViewModels/InInventoryViewModel.cs
Normal file
@ -0,0 +1,207 @@
|
||||
using HandyControl.Controls;
|
||||
using MiniExcelLibs;
|
||||
using Ping9719.WpfEx.Mvvm;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using SqlSugar;
|
||||
using HandyControl.Data;
|
||||
using System.Windows;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using 货架标准上位机.Views.Controls;
|
||||
using WCS.Model.ApiModel.User;
|
||||
using 货架标准上位机.Api;
|
||||
using WCS.Model;
|
||||
using WCS.Model.ApiModel;
|
||||
using System.Windows.Controls;
|
||||
using WCS.Model.ApiModel.InterfaceRecord;
|
||||
using TouchSocket.Sockets;
|
||||
using TouchSocket.Core;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Collections.ObjectModel;
|
||||
using WCS.BLL.DbModels;
|
||||
using WCS.Model.ApiModel.MatBaseInfo;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace 货架标准上位机.ViewModel
|
||||
{
|
||||
public class InInventoryViewModel : BindableBase
|
||||
{
|
||||
public InInventoryViewModel()
|
||||
{
|
||||
//初始化串口接收事件
|
||||
var scanners = ScannerManager.Scanners;
|
||||
foreach (var scanner in scanners)
|
||||
{
|
||||
scanner.SerialPortClient.Received = (client, e) =>
|
||||
{
|
||||
//获取串口号
|
||||
var COM = client.MainSerialPort.PortName;
|
||||
//获取扫码枪对象
|
||||
var scanner = ScannerManager.Scanners.Where(t => t.COM == COM).FirstOrDefault();
|
||||
if (scanner == null)
|
||||
return EasyTask.CompletedTask;
|
||||
int newBytes = e.ByteBlock.Len;
|
||||
if (newBytes > 0)
|
||||
{
|
||||
var currentScanedCode = Encoding.UTF8.GetString(e.ByteBlock, 0, e.ByteBlock.Len);
|
||||
Logs.Write($"接收到扫码枪扫码数据{currentScanedCode}");
|
||||
scanner.TempCode += currentScanedCode;
|
||||
//校验末尾码
|
||||
CheckDataCompleteness(scanner);
|
||||
scanner.ScannerDisplayControl.RefreshValues(scanner.ShelfCode, scanner.MatSn);
|
||||
}
|
||||
return EasyTask.CompletedTask;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#region Property
|
||||
private string shelfCode;
|
||||
public string ShelfCode
|
||||
{
|
||||
get { return shelfCode; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref shelfCode, value);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Command
|
||||
public void CheckDataCompleteness(Scanner scanner)
|
||||
{
|
||||
if (scanner.TempCode.EndsWith("\r"))//结束符 TODO结束符是否需要自定义 现场配置
|
||||
{
|
||||
scanner.TempCode = scanner.TempCode.Replace("\r", string.Empty).Replace("\n", string.Empty);
|
||||
try
|
||||
{
|
||||
//TO DO 配置项进行配置正则表达式
|
||||
//数据处理
|
||||
string ModuleCodePattern = "^[ABCD][0-9]{2}-R[0-9]{1,2}C[0-9]{1,2}$";
|
||||
var isModuleCode = Regex.IsMatch(scanner.TempCode, ModuleCodePattern);
|
||||
if (isModuleCode)
|
||||
{
|
||||
ModuleCodeProcess(scanner);
|
||||
}
|
||||
//TO DO 增加正则表达式进行判断是否扫到的是物料码
|
||||
else
|
||||
{
|
||||
MatSnProcess(scanner);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var message = "入库扫码枪扫码发生异常:" + ex.Message;
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
//不管入库成功与否 认为本次扫码完毕 清空暂存数据
|
||||
scanner.TempCode = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 扫到模组码的数据处理
|
||||
/// </summary>
|
||||
/// <param name="scanner"></param>
|
||||
public void ModuleCodeProcess(Scanner scanner)
|
||||
{
|
||||
//如果扫码枪前一个货架未退出入库
|
||||
if (scanner.IsInstoreMode)
|
||||
{
|
||||
//判断当前入库货架是否包含本次扫码的模组
|
||||
if (scanner.ModulesStr.Contains(scanner.TempCode))
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
#region 调用接口结束扫码枪占用入库的货架
|
||||
try
|
||||
{
|
||||
var body = new ShelfGoOutInStoreRequest()
|
||||
{
|
||||
ShelfCode = scanner.ShelfCode,
|
||||
IPAdress = scanner.COM,
|
||||
DeviceType = LocalFile.Config.DeviceType,
|
||||
UserName = LocalStatic.CurrentUser,
|
||||
};
|
||||
var Result = ApiHelp.GetDataFromHttp<ResponseBase>(LocalFile.Config.ApiIpHost + "instore/shelfGoOutInStore", body, "POST");
|
||||
if (Result != null && Result.Code == 200)
|
||||
{
|
||||
scanner.ShelfCode = string.Empty;
|
||||
scanner.ModulesStr = string.Empty;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
//调用接口 请求进入入库模式
|
||||
#region 调用接口进入入库模式
|
||||
try
|
||||
{
|
||||
var body = new ShelfGoInInstoreRequest()
|
||||
{
|
||||
ModuleCode = scanner.TempCode,
|
||||
DeviceType = LocalFile.Config.DeviceType,
|
||||
UserName = LocalStatic.CurrentUser,
|
||||
IpAdress = scanner.COM,
|
||||
};
|
||||
var Result = ApiHelp.GetDataFromHttp<ShelfGoInInstoreResponse>(LocalFile.Config.ApiIpHost + "instore/shelfGoInInStore", body, "POST");
|
||||
if (Result != null && Result.Code == 200)
|
||||
{
|
||||
scanner.ShelfCode = Result.Data.ShelfCode;
|
||||
scanner.ModulesStr = Result.Data.ModulesStr;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 扫到物料码的数据处理
|
||||
/// </summary>
|
||||
public void MatSnProcess(Scanner scanner)
|
||||
{
|
||||
#region 调用接口 扫物料码获取物料信息并绑定
|
||||
try
|
||||
{
|
||||
var body = new QueryByMatSnRequest()
|
||||
{
|
||||
ShelfCode = scanner.ShelfCode,
|
||||
IpAddress = scanner.COM,
|
||||
DeviceType = LocalFile.Config.DeviceType,
|
||||
UserName = LocalStatic.CurrentUser,
|
||||
};
|
||||
var Result = ApiHelp.GetDataFromHttp<QueryByMatSnResponse>(LocalFile.Config.ApiIpHost + "instore/queryByMatSn", body, "POST");
|
||||
if (Result != null && Result.Code == 200)
|
||||
{
|
||||
scanner.MatSn = Result.Data.materialBar;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user