@page "/stock/biaoDing" @using MasaBlazorApp3.Pojo.Config; @using MasaBlazorApp3.Util; @using Microsoft.AspNetCore.Components @using Microsoft.Extensions.Options; @using Newtonsoft.Json; @using log4net;
@if (DrawerNos.Count() > 8) {
@foreach (int i in DrawerNos) { }
} else {
@foreach (int i in DrawerNos) { }
}
@if (channel.Quantity == 0 && !String.IsNullOrEmpty(channel.DrugId)) { @((context as DrugManuNo)?.ManuNo) @((context as DrugManuNo)?.EffDate) } else { @channel.drugManuNo?.ManuNo @channel.drugManuNo?.EffDate } @if (cs.BoardType == 2) { @cs.AddQuantity } else { }
@code { @inject IChannelListDao channelListDao; @inject NavigationManager na; @inject PortUtil PortUtil; @inject NotificationService _message @inject IOptions setting; int status = 0; int drawerNo = 1; RadzenDataGrid grid; private List? channels; bool isLoading; int count; int[] DrawerNos = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; int[] BeforeQuantity = new int[9]; int[] AfterQuantity = new int[9]; private readonly ILog logger = LogManager.GetLogger(typeof(DrawerAdd)); // 当前操作的库位号列表 public List ColNos { get; set; } = new List(); int currentCol = 0; bool CompleteIsEnable = true; bool CancleIsEnable = true; void SelectDrawer(int drawerNo) { this.drawerNo = drawerNo; grid.Reload(); } async Task LoadData(LoadDataArgs args) { isLoading = true; var result = await channelListDao.GetChannelStockByDrawerNoWithDrawers(drawerNo); DrawerNos = result.DrawerArray; channels = result.ChannelStocks; count = result.ChannelStocks.Count; isLoading = false; } async Task OpenDrawer() { this.status = 1; var promiseUtil = new PromiseUtil(); await promiseUtil.taskAsyncLoop(500, null, async (data, next, stop) => { try { if (this.status == 0) { stop(); } // 开启抽屉 else if (this.status == 1) { // if(库存》0) // {} } var b = await PortUtil.OpenDrawerStatus(this.drawerNo); if (b) { PortUtil.SpeakAsync($"{drawerNo}号抽屉已经打开,请,加药"); this.status = 2; PortUtil.Operate = true; next(); } // else // { // _message.Notify( // new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "提示", Detail = $"抽屉【{drawerNo}】打开失败,请检测硬件", Duration = 4000 } // ); // logger.Info($"抽屉打开失败"); // RestData(); // PortUtil.Operate = false; // stop(); // } else if (this.status == 2) { if (setting.Value.box != null && setting.Value.box.Contains(this.drawerNo)) { //药盒抽屉,开药盒 for (int i = 0; i < ColNos.Count; i++) { await PortUtil.OpenBoxByColNo(ColNos[i]); } } // 查询抽屉是否为关闭状态 var b2 = await PortUtil.CheckDrawerStatus2(drawerNo); // 关闭则改变状态并终止循环 if (b2) { PortUtil.SpeakAsync($"加药完成,请,核对,或,录入,正确的,添加数量"); // 判断是否为称重抽屉 if (setting.Value.weigh != null && setting.Value.weigh.Contains(this.drawerNo)) { //关闭抽屉后获取称重稳定数量 // await GetWeightQuantity(); } this.status = 3; PortUtil.Operate = false; stop(); } else { if (setting.Value.single != null && setting.Value.single.Contains(this.drawerNo)) { byte[] quantity = await PortUtil.CheckQuantityByDrawer(this.drawerNo); AfterQuantity = quantity.Select(it => Convert.ToInt32(it)).ToArray().Skip(3).Take(9).ToArray(); logger.Info($"单支抽屉,抽屉未关检测数量【{string.Join(",", AfterQuantity)}】"); channels.ForEach(cl => { cl.AddQuantity = this.AfterQuantity[cl.ColNo - 1] - this.BeforeQuantity[cl.ColNo - 1]; }); } // 判断是否为称重抽屉 if (setting.Value.weigh != null && setting.Value.weigh.Contains(this.drawerNo)) { //开抽屉后查数 for (int i = 0; i < 9; i++) { int afterQuantity = await PortUtil.CheckQuantityForSingle(i); AfterQuantity[i] = afterQuantity; logger.Info($"AfterQuantity:{i}-{AfterQuantity}数量{string.Join(",", BeforeQuantity)}"); } channels.ForEach(cl => { cl.AddQuantity = this.AfterQuantity[cl.ColNo - 1] - this.BeforeQuantity[cl.ColNo - 1]; }); } next(); // continue iteration } } } catch (Exception e) { logger.Info($"抽屉加药发生错误,{e.Message}"); _message.Notify( new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "提示", Detail = $"发生错误,{e.Message}", Duration = 4000 } ); if (setting.Value.single != null && setting.Value.single.Contains(this.drawerNo)) { PortUtil.AllLightOff(); } RestData(); stop(); } }); } void RestData() { this.status = 0; } void OnCellClick(DataGridCellMouseEventArgs args) { if (args.Data.BoardType.ToString().Contains("3")) { //是药盒抽屉则点击行,打开对应行的药箱 if (!ColNos.Contains(args.Data.ColNo)) { ColNos.Add(args.Data.ColNo); } } else { grid.EditRow(args.Data); } } }