2024-06-24 17:30:26 +08:00
|
|
|
|
using DM_Weight.Models;
|
|
|
|
|
using DM_Weight.msg;
|
2024-07-31 14:28:22 +08:00
|
|
|
|
using DM_Weight.Port;
|
2024-06-24 17:30:26 +08:00
|
|
|
|
using DM_Weight.util;
|
|
|
|
|
using Prism.Commands;
|
|
|
|
|
using Prism.Events;
|
|
|
|
|
using Prism.Mvvm;
|
|
|
|
|
using Prism.Regions;
|
|
|
|
|
using Prism.Services.Dialogs;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Configuration;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection.PortableExecutable;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Channels;
|
|
|
|
|
using System.Threading.Tasks;
|
2024-07-31 14:28:22 +08:00
|
|
|
|
using System.Windows.Threading;
|
2024-06-24 17:30:26 +08:00
|
|
|
|
using static Unity.Storage.RegistrationSet;
|
|
|
|
|
|
|
|
|
|
namespace DM_Weight.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class DestoryEmptyDialogViewModel : BindableBase, IDialogAware, IRegionMemberLifetime
|
|
|
|
|
{
|
|
|
|
|
public bool KeepAlive => false;
|
|
|
|
|
|
2024-07-31 14:28:22 +08:00
|
|
|
|
public string Title => "空瓶取出";
|
2024-06-24 17:30:26 +08:00
|
|
|
|
|
|
|
|
|
private List<MachineRecord> _machineRecords = new();
|
|
|
|
|
|
|
|
|
|
public List<MachineRecord> _MachineRecords
|
|
|
|
|
{
|
|
|
|
|
get => _machineRecords;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetProperty(ref _machineRecords, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MachineRecord _machineRecord = new();
|
|
|
|
|
|
|
|
|
|
public MachineRecord _MachineRecord
|
|
|
|
|
{
|
|
|
|
|
get => _machineRecord;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetProperty(ref _machineRecord, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ChannelStock _channelStock;
|
|
|
|
|
|
|
|
|
|
public ChannelStock _ChannelStock
|
|
|
|
|
{
|
|
|
|
|
get => _channelStock;
|
|
|
|
|
set => SetProperty(ref _channelStock, value);
|
|
|
|
|
}
|
2024-07-31 14:28:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private IEnumerable<IGrouping<int, ChannelStock>> enumerable;
|
|
|
|
|
private IEnumerator<IGrouping<int, ChannelStock>> enumerator;
|
|
|
|
|
|
|
|
|
|
private int _status = 0;
|
|
|
|
|
|
|
|
|
|
public int Status
|
|
|
|
|
{
|
|
|
|
|
get => _status; set => SetProperty(ref _status, value);
|
|
|
|
|
}
|
|
|
|
|
private PortUtil _portUtil;
|
2024-06-24 17:30:26 +08:00
|
|
|
|
IEventAggregator _eventAggregator;
|
2024-07-31 14:28:22 +08:00
|
|
|
|
public DestoryEmptyDialogViewModel(PortUtil portUtil, IEventAggregator eventAggregator)
|
2024-06-24 17:30:26 +08:00
|
|
|
|
{
|
2024-07-31 14:28:22 +08:00
|
|
|
|
_portUtil = portUtil;
|
2024-06-24 17:30:26 +08:00
|
|
|
|
_eventAggregator = eventAggregator;
|
|
|
|
|
}
|
2024-07-31 14:28:22 +08:00
|
|
|
|
void DoMyPrismEvent(DeviceMsg msg)
|
|
|
|
|
{
|
|
|
|
|
if (msg.WindowName == "DrawerTakeDrugWindow")
|
|
|
|
|
{
|
|
|
|
|
switch (msg.EventType)
|
|
|
|
|
{
|
|
|
|
|
// 抽屉打开
|
|
|
|
|
case EventType.DRAWEROPEN:
|
|
|
|
|
if (Status == 1)
|
|
|
|
|
{
|
|
|
|
|
Status = 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
// 抽屉关闭
|
|
|
|
|
case EventType.DRAWERCLOSE:
|
|
|
|
|
if (Status == 2)
|
|
|
|
|
{
|
|
|
|
|
Status = 3;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
// 数量变化
|
|
|
|
|
case EventType.UPDATEQUANTITY:
|
|
|
|
|
if (Status == 2)
|
|
|
|
|
{
|
|
|
|
|
_ChannelStock.TakeQuantity = msg.Quantitys[_ChannelStock.ColNo - 1];
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
// 打开失败
|
|
|
|
|
case EventType.OPENERROR:
|
|
|
|
|
AlertMsg alertMsg = new AlertMsg
|
|
|
|
|
{
|
|
|
|
|
Message = msg.Message,
|
|
|
|
|
Type = MsgType.ERROR,
|
|
|
|
|
};
|
|
|
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
|
|
|
Status = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-24 17:30:26 +08:00
|
|
|
|
|
2024-07-31 14:28:22 +08:00
|
|
|
|
}
|
2024-06-24 17:30:26 +08:00
|
|
|
|
public event Action<IDialogResult> RequestClose;
|
|
|
|
|
|
|
|
|
|
public bool CanCloseDialog()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnDialogClosed()
|
|
|
|
|
{
|
2024-07-31 14:28:22 +08:00
|
|
|
|
// 取消消息订阅
|
|
|
|
|
_eventAggregator.GetEvent<PortUtilEvent>().Unsubscribe(DoMyPrismEvent);
|
2024-06-24 17:30:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnDialogOpened(IDialogParameters parameters)
|
|
|
|
|
{
|
2024-07-31 14:28:22 +08:00
|
|
|
|
_eventAggregator.GetEvent<PortUtilEvent>().Subscribe(DoMyPrismEvent);
|
2024-06-24 17:30:26 +08:00
|
|
|
|
ChannelStock _record = parameters.GetValue<ChannelStock>("channel");
|
|
|
|
|
_ChannelStock = _record;
|
|
|
|
|
|
|
|
|
|
RequestData();
|
|
|
|
|
}
|
|
|
|
|
public void RequestData()
|
|
|
|
|
{
|
|
|
|
|
List<MachineRecord> queryData = SqlSugarHelper.Db.Queryable<MachineRecord>()
|
|
|
|
|
.Includes<UserList>(mr => mr.User)
|
|
|
|
|
.Where(mr => mr.DrugId == _ChannelStock.DrugId)
|
|
|
|
|
.Where(mr => mr.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1"))
|
|
|
|
|
.Where(mr => mr.Type == 32)
|
|
|
|
|
//.Where(mr => mr.Status != 2)
|
|
|
|
|
.Where(mr=>mr.IsDestroy==0)
|
|
|
|
|
.OrderByDescending(mr => mr.OperationTime)
|
|
|
|
|
.OrderBy(mr => mr.Id)
|
|
|
|
|
.ToList();
|
|
|
|
|
_MachineRecords = queryData;
|
|
|
|
|
}
|
|
|
|
|
// 取消按钮
|
|
|
|
|
public DelegateCommand CancleTake
|
|
|
|
|
{
|
|
|
|
|
get => new DelegateCommand(() =>
|
|
|
|
|
{
|
|
|
|
|
RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DelegateCommand BtnCloseCommand
|
|
|
|
|
{
|
|
|
|
|
get => new DelegateCommand(() =>
|
|
|
|
|
{
|
|
|
|
|
//DialogParameters parameters = new DialogParameters();
|
|
|
|
|
//parameters.Add("",);
|
|
|
|
|
// 关闭当前窗口
|
|
|
|
|
RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
public DelegateCommand RowSelected
|
|
|
|
|
{
|
|
|
|
|
get => new DelegateCommand(() =>
|
|
|
|
|
{
|
|
|
|
|
if (_MachineRecord != null && _MachineRecord.Quantity > 0)
|
|
|
|
|
{
|
|
|
|
|
_MachineRecords = _MachineRecords.Select(x =>
|
|
|
|
|
{
|
|
|
|
|
if (x.Id == _MachineRecord.Id)
|
|
|
|
|
{
|
|
|
|
|
x.IsSelected = !x.IsSelected;
|
|
|
|
|
}
|
|
|
|
|
return x;
|
|
|
|
|
}).ToList();
|
|
|
|
|
//DialogParameters dialogParameters = new DialogParameters();
|
|
|
|
|
//dialogParameters.Add("channel", Channel);
|
|
|
|
|
//DialogServiceExtensions.ShowDialogHost(_dialogService, "ReturnEmptyDialog", dialogParameters, DoDialogResult, "RootDialog");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 空瓶销毁
|
|
|
|
|
/// </summary>
|
|
|
|
|
public DelegateCommand DestoryEmptyCommand
|
|
|
|
|
{
|
2024-07-31 14:28:22 +08:00
|
|
|
|
get => new DelegateCommand(() =>
|
|
|
|
|
{
|
|
|
|
|
if (Status == 0)
|
|
|
|
|
{
|
|
|
|
|
Status = 1;
|
|
|
|
|
//_portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉");
|
|
|
|
|
|
|
|
|
|
//IEnumerable<string> strDrugName = _MachineRecords.Select(cs => cs.DrugInfo.DrugName);
|
|
|
|
|
//string strNames = string.Empty;
|
|
|
|
|
//foreach (string name in strDrugName)
|
|
|
|
|
//{
|
|
|
|
|
// if (!strNames.Contains(name))
|
|
|
|
|
// {
|
|
|
|
|
// strNames += name + ";";
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
int sumQuantity = _MachineRecords.FindAll(it => it.IsSelected).Sum(cs => cs.Quantity);
|
|
|
|
|
_portUtil.SpeakAsync($"正在打开 {_ChannelStock.DrawerNo} 号抽屉,请取出空瓶 {_ChannelStock.DrugInfo.DrugName} ,数量共计 {sumQuantity}");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_portUtil.WindowName = "DrawerTakeDrugWindow";
|
|
|
|
|
_portUtil.BoardType = _ChannelStock.BoardType;
|
|
|
|
|
_portUtil.ColNos=new int[] { _ChannelStock.ColNo };
|
|
|
|
|
_portUtil.DrawerNo = _ChannelStock.DrawerNo;
|
|
|
|
|
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Normal, () => _portUtil.Start())
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DelegateCommand TakeFinish {
|
2024-06-24 17:30:26 +08:00
|
|
|
|
get => new DelegateCommand(() =>
|
|
|
|
|
{
|
|
|
|
|
List<MachineRecord> records = _MachineRecords.FindAll(it => it.IsSelected).ToList();
|
|
|
|
|
if (records != null && records.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var f = SqlSugarHelper.Db.UseTran(() =>
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < records.Count; i++)
|
|
|
|
|
{
|
2024-07-31 14:28:22 +08:00
|
|
|
|
MachineRecord record = records[i];
|
2024-06-24 17:30:26 +08:00
|
|
|
|
|
|
|
|
|
//修改库存数量
|
2024-07-31 14:28:22 +08:00
|
|
|
|
_ChannelStock.Quantity = _ChannelStock.Quantity - record.Quantity;
|
2024-06-24 17:30:26 +08:00
|
|
|
|
SqlSugarHelper.Db.Updateable(_ChannelStock).ExecuteCommand();
|
|
|
|
|
|
2024-07-31 14:28:22 +08:00
|
|
|
|
|
|
|
|
|
|
2024-06-24 17:30:26 +08:00
|
|
|
|
//修改记录表中状态
|
|
|
|
|
SqlSugarHelper.Db.Updateable(record).ReSetValue(mr =>
|
|
|
|
|
{
|
2024-07-31 14:28:22 +08:00
|
|
|
|
mr.IsDestroy = 1;
|
2024-06-24 17:30:26 +08:00
|
|
|
|
}).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
//记录销毁明细
|
|
|
|
|
SqlSugarHelper.Db.Insertable(new DestoryDetail()
|
|
|
|
|
{
|
|
|
|
|
MachineId = ConfigurationManager.AppSettings["machineId"].ToString(),
|
|
|
|
|
Operatorid = HomeWindowViewModel.Operator?.Id,
|
|
|
|
|
Reviewerid = HomeWindowViewModel.Reviewer?.Id,
|
|
|
|
|
RecordId = record.Id,
|
|
|
|
|
//OrderId = ChannelStock.ManuNo,
|
|
|
|
|
|
|
|
|
|
//,StockQuantity = nowChannels.Sum(it => it.Quantity)
|
|
|
|
|
}).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
if (f.Data)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
RequestData();
|
|
|
|
|
AlertMsg alertMsg = new AlertMsg
|
|
|
|
|
{
|
2024-07-31 14:28:22 +08:00
|
|
|
|
Message = "取出完成",
|
2024-06-24 17:30:26 +08:00
|
|
|
|
Type = MsgType.SUCCESS,
|
|
|
|
|
};
|
|
|
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
|
|
|
RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
|
|
|
|
|
}
|
|
|
|
|
if (!f.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
AlertMsg alertMsg = new AlertMsg
|
|
|
|
|
{
|
2024-07-31 14:28:22 +08:00
|
|
|
|
Message = "取出失败!",
|
2024-06-24 17:30:26 +08:00
|
|
|
|
Type = MsgType.ERROR,
|
|
|
|
|
};
|
|
|
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-06 10:25:01 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
AlertMsg alertMsg = new AlertMsg
|
|
|
|
|
{
|
2024-07-31 14:28:22 +08:00
|
|
|
|
Message = "请选择要取空瓶的数据",
|
2024-07-06 10:25:01 +08:00
|
|
|
|
Type = MsgType.ERROR,
|
|
|
|
|
};
|
|
|
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
|
|
|
}
|
2024-06-24 17:30:26 +08:00
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|