152 lines
		
	
	
		
			5.1 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			152 lines
		
	
	
		
			5.1 KiB
		
	
	
	
		
			C#
		
	
	
	
| 
								 | 
							
								using DM_Weight.Models;
							 | 
						|||
| 
								 | 
							
								using DM_Weight.msg;
							 | 
						|||
| 
								 | 
							
								using DM_Weight.Port;
							 | 
						|||
| 
								 | 
							
								using DM_Weight.util;
							 | 
						|||
| 
								 | 
							
								using Prism.Commands;
							 | 
						|||
| 
								 | 
							
								using Prism.Events;
							 | 
						|||
| 
								 | 
							
								using Prism.Mvvm;
							 | 
						|||
| 
								 | 
							
								using Prism.Regions;
							 | 
						|||
| 
								 | 
							
								using Prism.Services.Dialogs;
							 | 
						|||
| 
								 | 
							
								using System;
							 | 
						|||
| 
								 | 
							
								using System.Collections.Generic;
							 | 
						|||
| 
								 | 
							
								using System.Collections.ObjectModel;
							 | 
						|||
| 
								 | 
							
								using System.Configuration;
							 | 
						|||
| 
								 | 
							
								using System.Linq;
							 | 
						|||
| 
								 | 
							
								using System.Text;
							 | 
						|||
| 
								 | 
							
								using System.Threading.Tasks;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								namespace DM_Weight.ViewModels
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    public class AddManunoDialogViewModel : BindableBase, IDialogAware, IRegionMemberLifetime
							 | 
						|||
| 
								 | 
							
								    {
							 | 
						|||
| 
								 | 
							
								        public string Title => "添加批次";
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public bool KeepAlive => false;
							 | 
						|||
| 
								 | 
							
								        private ChannelStock? _channelStock;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        private ObservableCollection<AddChannelStockManuNo>? _addChannelStocks;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public ObservableCollection<AddChannelStockManuNo>? AddChannelStocks
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get => _addChannelStocks;
							 | 
						|||
| 
								 | 
							
								            set => SetProperty(ref _addChannelStocks, value);
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        public ChannelStock? ChStock
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get => _channelStock;
							 | 
						|||
| 
								 | 
							
								            set => SetProperty(ref _channelStock, value);
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								         ///全选
							 | 
						|||
| 
								 | 
							
								         /// </summary>
							 | 
						|||
| 
								 | 
							
								        private bool _allChecked = false;
							 | 
						|||
| 
								 | 
							
								        public bool IsAllChecked
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get { return _allChecked; }
							 | 
						|||
| 
								 | 
							
								            set
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                SetProperty(ref _allChecked, value);
							 | 
						|||
| 
								 | 
							
								                if (!IsItemCheck)
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    RequestData();
							 | 
						|||
| 
								 | 
							
								                    //根据全选或反选设置其后的选中状态
							 | 
						|||
| 
								 | 
							
								                    AddChannelStocks.ToList().ForEach(oi => oi.ItemIsChecked = _allChecked);
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                else
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    IsItemCheck = false;
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        public bool _isItemCheck = false;
							 | 
						|||
| 
								 | 
							
								        public bool IsItemCheck
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get => _isItemCheck;
							 | 
						|||
| 
								 | 
							
								            set
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                SetProperty(ref _isItemCheck, value);
							 | 
						|||
| 
								 | 
							
								                if (AddChannelStocks.ToList().Where(od => od.ItemIsChecked == false).Count() <= 0)
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    IsAllChecked = true;
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        public event Action<IDialogResult> RequestClose;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public bool CanCloseDialog()
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            return true;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public void OnDialogClosed()
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public void OnDialogOpened(IDialogParameters parameters)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            ChannelStock channelStock = parameters.GetValue<ChannelStock>("addManuno");
							 | 
						|||
| 
								 | 
							
								            ChStock = channelStock;
							 | 
						|||
| 
								 | 
							
								            RequestData();
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        IDialogService _dialogService;
							 | 
						|||
| 
								 | 
							
								        IEventAggregator _eventAggregator;
							 | 
						|||
| 
								 | 
							
								        public AddManunoDialogViewModel(IDialogService DialogService, IEventAggregator eventAggregator)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            _dialogService = DialogService;
							 | 
						|||
| 
								 | 
							
								            _eventAggregator = eventAggregator;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        public void RequestData()
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            //List<ChannelStock> queryData = SqlSugarHelper.Db.Queryable<ChannelStock>()
							 | 
						|||
| 
								 | 
							
								            //    .Includes(cs => cs.DrugInfo, di => di.DrugManuNos)
							 | 
						|||
| 
								 | 
							
								            //    .Where(cs => cs.DrawerNo == ChStock.DrawerNo&&cs.ColNo==ChStock.ColNo)
							 | 
						|||
| 
								 | 
							
								            //    .Where(cs => cs.DrawerType == 1)
							 | 
						|||
| 
								 | 
							
								            //    .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1"))
							 | 
						|||
| 
								 | 
							
								            //    .Where(cs => cs.DrugId ==ChStock.DrugId )
							 | 
						|||
| 
								 | 
							
								            //    .OrderBy(cs => cs.ManuNo)
							 | 
						|||
| 
								 | 
							
								            //    .ToList();
							 | 
						|||
| 
								 | 
							
								            //ChannelStocks = queryData.Select(cs =>
							 | 
						|||
| 
								 | 
							
								            //{
							 | 
						|||
| 
								 | 
							
								            //    cs.drugManuNo = cs.DrugInfo.DrugManuNos.Find(it => it.ManuNo.Equals(cs.ManuNo));
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								            //    return cs;
							 | 
						|||
| 
								 | 
							
								            //}).ToList();
							 | 
						|||
| 
								 | 
							
								            //obChannelStock = new ObservableCollection<ChannelStock>(ChannelStocks);
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								            string strSQl = @"SELECT DISTINCT c.Col_no as ColNo,d.DRUG_NAME as DrugName,d.DRUG_SPEC as DrugSpec,m.eff_date as EffDate,m.Manu_No as ManuNo
							 | 
						|||
| 
								 | 
							
								                            from drug_manu_no m inner join drug_info d on m.drug_id=d.drug_id  inner join  channel_stock c on m.drug_id=c.drug_id  
							 | 
						|||
| 
								 | 
							
								                            where c.row_no=@RowNo and col_no=@ColNo and machine_id=@MachineId and m.Manu_NO<>@ManuNo order by m.Manu_No desc";
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								            List<AddChannelStockManuNo> queryData = SqlSugarHelper.Db.SqlQueryable<dynamic>(strSQl)
							 | 
						|||
| 
								 | 
							
								                .AddParameters(new
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1",
							 | 
						|||
| 
								 | 
							
								                    RowNo = ChStock.DrawerNo,
							 | 
						|||
| 
								 | 
							
								                    ColNo = ChStock.ColNo,
							 | 
						|||
| 
								 | 
							
								                    ManuNo=ChStock.ManuNo
							 | 
						|||
| 
								 | 
							
								                })
							 | 
						|||
| 
								 | 
							
								                .Select(it => new AddChannelStockManuNo())
							 | 
						|||
| 
								 | 
							
								                .ToList();
							 | 
						|||
| 
								 | 
							
								            AddChannelStocks = new ObservableCollection<AddChannelStockManuNo>(queryData);
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        public DelegateCommand SaveCommand
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get => new DelegateCommand(() =>
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								            });
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        public DelegateCommand BtnCloseCommand
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get => new DelegateCommand(() =>
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                // 关闭当前窗口
							 | 
						|||
| 
								 | 
							
								                RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
							 | 
						|||
| 
								 | 
							
								            });
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 |