212 lines
		
	
	
		
			7.1 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			212 lines
		
	
	
		
			7.1 KiB
		
	
	
	
		
			C#
		
	
	
	
| 
								 | 
							
								using DM_Weight.Models;
							 | 
						|||
| 
								 | 
							
								using DM_Weight.msg;
							 | 
						|||
| 
								 | 
							
								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;
							 | 
						|||
| 
								 | 
							
								using static Unity.Storage.RegistrationSet;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								namespace DM_Weight.ViewModels
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    public class DestoryEmptyDialogViewModel : BindableBase, IDialogAware, IRegionMemberLifetime
							 | 
						|||
| 
								 | 
							
								    {
							 | 
						|||
| 
								 | 
							
								        public bool KeepAlive => false;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public string Title => "空瓶销毁";
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        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);
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        IEventAggregator _eventAggregator;
							 | 
						|||
| 
								 | 
							
								        public DestoryEmptyDialogViewModel(IEventAggregator eventAggregator)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            _eventAggregator = eventAggregator;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public event Action<IDialogResult> RequestClose;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public bool CanCloseDialog()
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            return true;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public void OnDialogClosed()
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public void OnDialogOpened(IDialogParameters parameters)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            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
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            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++)
							 | 
						|||
| 
								 | 
							
								                        {
							 | 
						|||
| 
								 | 
							
								                            MachineRecord record= records[i];
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                            //修改库存数量
							 | 
						|||
| 
								 | 
							
								                            _ChannelStock.Quantity = _ChannelStock.Quantity - record.Quantity; 
							 | 
						|||
| 
								 | 
							
								                            SqlSugarHelper.Db.Updateable(_ChannelStock).ExecuteCommand();
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                            //修改记录表中状态
							 | 
						|||
| 
								 | 
							
								                            SqlSugarHelper.Db.Updateable(record).ReSetValue(mr =>
							 | 
						|||
| 
								 | 
							
								                            {
							 | 
						|||
| 
								 | 
							
								                                mr.IsDestroy = 1; 
							 | 
						|||
| 
								 | 
							
								                            }).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
							 | 
						|||
| 
								 | 
							
								                        {
							 | 
						|||
| 
								 | 
							
								                            Message = "销毁完成",
							 | 
						|||
| 
								 | 
							
								                            Type = MsgType.SUCCESS,
							 | 
						|||
| 
								 | 
							
								                        };
							 | 
						|||
| 
								 | 
							
								                        _eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
							 | 
						|||
| 
								 | 
							
								                        RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
							 | 
						|||
| 
								 | 
							
								                    }
							 | 
						|||
| 
								 | 
							
								                    if (!f.IsSuccess)
							 | 
						|||
| 
								 | 
							
								                    {
							 | 
						|||
| 
								 | 
							
								                        AlertMsg alertMsg = new AlertMsg
							 | 
						|||
| 
								 | 
							
								                        {
							 | 
						|||
| 
								 | 
							
								                            Message = "销毁失败!",
							 | 
						|||
| 
								 | 
							
								                            Type = MsgType.ERROR,
							 | 
						|||
| 
								 | 
							
								                        };
							 | 
						|||
| 
								 | 
							
								                        _eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
							 | 
						|||
| 
								 | 
							
								                    }
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                else
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    AlertMsg alertMsg = new AlertMsg
							 | 
						|||
| 
								 | 
							
								                    {
							 | 
						|||
| 
								 | 
							
								                        Message = "请选择要销毁的数据",
							 | 
						|||
| 
								 | 
							
								                        Type = MsgType.ERROR,
							 | 
						|||
| 
								 | 
							
								                    };
							 | 
						|||
| 
								 | 
							
								                    _eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								            });
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 |