325 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			325 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C#
		
	
	
	
using DM_Weight.Models;
 | 
						||
using DM_Weight.msg;
 | 
						||
using DM_Weight.select;
 | 
						||
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.Configuration;
 | 
						||
using System.Drawing.Printing;
 | 
						||
using System.Linq;
 | 
						||
using System.Reactive.Joins;
 | 
						||
using System.Text;
 | 
						||
using System.Threading.Channels;
 | 
						||
using System.Threading.Tasks;
 | 
						||
using System.Windows.Controls;
 | 
						||
 | 
						||
namespace DM_Weight.ViewModels
 | 
						||
{
 | 
						||
    public class CollectDrugWindowViewModel : BindableBase,INavigationAware,IRegionMemberLifetime
 | 
						||
    {
 | 
						||
        private int _pageNum = 1;
 | 
						||
        public int PageNum
 | 
						||
        {
 | 
						||
            get => _pageNum;
 | 
						||
            set
 | 
						||
            {
 | 
						||
                SetProperty(ref _pageNum, value);
 | 
						||
                RequestData();
 | 
						||
            }
 | 
						||
        }
 | 
						||
 | 
						||
        private int _pageCount = 1;
 | 
						||
        public int PageCount
 | 
						||
        {
 | 
						||
            get => _pageCount;
 | 
						||
            set
 | 
						||
            {
 | 
						||
                SetProperty(ref _pageCount, value);
 | 
						||
            }
 | 
						||
        }
 | 
						||
 | 
						||
        private int _pageSize = 8;
 | 
						||
        public int PageSize
 | 
						||
        {
 | 
						||
            get => _pageSize;
 | 
						||
            set
 | 
						||
            {
 | 
						||
                SetProperty(ref _pageSize, value);
 | 
						||
            }
 | 
						||
        }
 | 
						||
 | 
						||
        private int _totalCount = 0;
 | 
						||
        public int TotalCount
 | 
						||
        {
 | 
						||
            get => _totalCount;
 | 
						||
            set
 | 
						||
            {
 | 
						||
                SetProperty(ref _totalCount, value);
 | 
						||
            }
 | 
						||
        }
 | 
						||
        public static List<OrderTakeSelect> StaticSelects = new()
 | 
						||
        {
 | 
						||
            new OrderTakeSelect
 | 
						||
            {
 | 
						||
                Code = "DrugName",
 | 
						||
                Name = "药品名称"
 | 
						||
            },
 | 
						||
            new OrderTakeSelect
 | 
						||
            {
 | 
						||
                Code = "PyCode",
 | 
						||
                Name = "拼音码"
 | 
						||
            },
 | 
						||
            new OrderTakeSelect
 | 
						||
            {
 | 
						||
                Code = "DrugBarcode",
 | 
						||
                Name = "药品条码"
 | 
						||
            },
 | 
						||
            new OrderTakeSelect
 | 
						||
            {
 | 
						||
                Code = "DrugId",
 | 
						||
                Name = "药品编码"
 | 
						||
            }
 | 
						||
        };
 | 
						||
 | 
						||
        private List<OrderTakeSelect> _selects = StaticSelects;
 | 
						||
 | 
						||
        public List<OrderTakeSelect> Selects
 | 
						||
        {
 | 
						||
            get { return _selects; }
 | 
						||
            set
 | 
						||
            {
 | 
						||
                SetProperty(ref _selects, value);
 | 
						||
            }
 | 
						||
        }
 | 
						||
        private List<CollectDrug> _collectDrugs = new();
 | 
						||
 | 
						||
        public List<CollectDrug> CollectDrugs { get { return _collectDrugs; } set { SetProperty(ref _collectDrugs, value); } }
 | 
						||
 | 
						||
        private CollectDrug _selectCollectDrugs;
 | 
						||
        public CollectDrug selectCollectDrug { get { return _selectCollectDrugs; } set { SetProperty(ref _selectCollectDrugs, value); } }
 | 
						||
 | 
						||
        private OrderTakeSelect _selectedItem = StaticSelects[0];
 | 
						||
        /// <summary>
 | 
						||
        /// 查询条件 查询字段
 | 
						||
        /// </summary>
 | 
						||
        public OrderTakeSelect SelectedItem
 | 
						||
        {
 | 
						||
            get { return _selectedItem; }
 | 
						||
            set
 | 
						||
            {
 | 
						||
                SetProperty(ref _selectedItem, value);
 | 
						||
                RequestData();
 | 
						||
            }
 | 
						||
        }
 | 
						||
        IEventAggregator _eventAggregator;
 | 
						||
        IDialogService _dialogService;
 | 
						||
        public CollectDrugWindowViewModel(IDialogService dialogService, IEventAggregator eventAggregator)
 | 
						||
        {
 | 
						||
            _dialogService = dialogService;
 | 
						||
            _eventAggregator = eventAggregator;
 | 
						||
        }
 | 
						||
        //private void BindSelectCollect(CollectDrug collectDrug)
 | 
						||
        //{
 | 
						||
        //    if (SelectCollects == null)
 | 
						||
        //    {
 | 
						||
        //        SelectCollects = new List<CollectDrug>();
 | 
						||
        //    }
 | 
						||
        //    if (SelectCollects.Contains(collectDrug))
 | 
						||
        //    {
 | 
						||
        //        SelectCollects.Remove(collectDrug);
 | 
						||
        //    }
 | 
						||
        //    else
 | 
						||
        //    {
 | 
						||
        //        SelectCollects.Add(collectDrug);
 | 
						||
        //    }
 | 
						||
        //}
 | 
						||
        /// <summary>
 | 
						||
        /// 选中处方的请领药品
 | 
						||
        /// </summary>
 | 
						||
        //private List<CollectDrug> _selectCollects;
 | 
						||
        //public List<CollectDrug> SelectCollects
 | 
						||
        //{
 | 
						||
        //    get { return _selectCollects; }
 | 
						||
        //    set { SetProperty(ref _selectCollects, value); }
 | 
						||
        //}
 | 
						||
 | 
						||
        private string? _searchValue;
 | 
						||
 | 
						||
        /// <summary>
 | 
						||
        /// 查询条件 查询字段值
 | 
						||
        /// </summary>
 | 
						||
        public string? SearchValue
 | 
						||
        {
 | 
						||
            get { return _searchValue; }
 | 
						||
            set
 | 
						||
            {
 | 
						||
                SetProperty(ref _searchValue, value);
 | 
						||
                RequestData();
 | 
						||
            }
 | 
						||
        }
 | 
						||
        void RequestData_for_SurgicalShedule()
 | 
						||
        {
 | 
						||
            int totalCount = 0;
 | 
						||
            List<CollectDrug> queryData = SqlSugarHelper.Db.Queryable<SurgicalSchedule>()
 | 
						||
         .InnerJoin<SurgicalScheduleDetail>((oi, od) => oi.OperationId == od.OperationId)
 | 
						||
         .InnerJoin<DrugInfo>((oi, od, di) => od.DrugId == di.DrugId.ToString())
 | 
						||
         .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugId"), (oi, od, di) => di.DrugId.ToString() == SearchValue)
 | 
						||
         .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugName"), (oi, od, di) => di.DrugName.Contains(SearchValue))
 | 
						||
         .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PyCode"), (oi, od, di) => di.PyCode.Contains(SearchValue))
 | 
						||
         .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugBarcode"), (oi, od, di) => di.DrugBarcode.Contains(SearchValue))
 | 
						||
         .Where(oi => oi.DmStatus == 1)
 | 
						||
         .Where(oi => oi.HisState == 1)
 | 
						||
         .GroupBy(oi => oi.ScheduleTime)
 | 
						||
         .Select((oi, od, di) => new CollectDrug
 | 
						||
         {
 | 
						||
             PatientId = oi.PatientId,
 | 
						||
             PName = oi.PName,
 | 
						||
             Sex = oi.Sex,
 | 
						||
             Age = oi.Age,
 | 
						||
             IdNumber = oi.IdNumber,
 | 
						||
             OrderNo = oi.OperationId,
 | 
						||
             //DeptName = oi.DeptName,
 | 
						||
             DrugName = di.DrugName,
 | 
						||
             Quantity = od.Quantity,
 | 
						||
             DrugSpec = di.DrugSpec,
 | 
						||
             Manufactory = di.Manufactory,
 | 
						||
             DrugId = di.DrugId.ToString(),
 | 
						||
         }).ToList();
 | 
						||
            CollectDrugs = queryData;
 | 
						||
            TotalCount = totalCount;
 | 
						||
            PageCount = (int)Math.Ceiling((double)TotalCount / PageSize);
 | 
						||
 | 
						||
        }
 | 
						||
        void RequestData()
 | 
						||
        {
 | 
						||
            int totalCount = 0;
 | 
						||
 | 
						||
            List<CollectDrug> queryData = SqlSugarHelper.Db.Queryable<OrderInfo>()
 | 
						||
          .InnerJoin<OrderDetail>((oi, od) => oi.OrderNo == od.OrderNo)
 | 
						||
          .InnerJoin<DrugInfo>((oi, od, di) => od.DrugId == di.DrugId.ToString())
 | 
						||
          .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugId"), (oi, od, di) => di.DrugId.ToString() == SearchValue)
 | 
						||
          .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugName"), (oi, od, di) => di.DrugName.Contains(SearchValue))
 | 
						||
          .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PyCode"), (oi, od, di) => di.PyCode.Contains(SearchValue))
 | 
						||
          .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugBarcode"), (oi, od, di) => di.DrugBarcode.Contains(SearchValue))
 | 
						||
          .WhereIF(!String.IsNullOrEmpty(ConfigurationManager.AppSettings["storage"]), oi => oi.Pharmacy == ConfigurationManager.AppSettings["storage"])
 | 
						||
          .Where(oi => oi.DmStatus == 1)
 | 
						||
          .Where(oi => oi.HisDispFlag == 0)
 | 
						||
          .Where(oi => oi.CancelFlag == 0) 
 | 
						||
          .Where(oi=>oi.ApplyStatus==0)
 | 
						||
          .Where(oi => oi.Pharmacy.Equals(ConfigurationManager.AppSettings["storage"] ?? ""))
 | 
						||
          .GroupBy(oi => oi.OrderDate)
 | 
						||
          .Select((oi, od, di) => new CollectDrug
 | 
						||
          {
 | 
						||
              PatientId = oi.PatientId,
 | 
						||
              PName = oi.PName,
 | 
						||
              Sex = oi.Sex,
 | 
						||
              Age = oi.Age,
 | 
						||
              IdNumber = oi.IdNumber,
 | 
						||
              OrderNo = oi.OrderNo,
 | 
						||
              DeptName = oi.DeptName,
 | 
						||
              DrugName = di.DrugName,
 | 
						||
              Quantity = od.Quantity,
 | 
						||
              DrugSpec = di.DrugSpec,
 | 
						||
              Manufactory = di.Manufactory,
 | 
						||
              DrugId=di.DrugId.ToString(),
 | 
						||
          }).ToList();
 | 
						||
         // .ToPageList(PageNum, PageSize, ref totalCount);
 | 
						||
            //.ToList();
 | 
						||
            CollectDrugs = queryData;
 | 
						||
            TotalCount = totalCount;
 | 
						||
            PageCount = (int)Math.Ceiling((double)TotalCount / PageSize);
 | 
						||
 | 
						||
        }
 | 
						||
        public DelegateCommand RowSelected
 | 
						||
        {
 | 
						||
            get => new DelegateCommand(() =>
 | 
						||
            {
 | 
						||
                if (selectCollectDrug != null)
 | 
						||
                {
 | 
						||
                    CollectDrugs = CollectDrugs.Select(x =>
 | 
						||
                    {
 | 
						||
                        if (x.OrderNo == selectCollectDrug.OrderNo)
 | 
						||
                        {
 | 
						||
                            x.IsSelected = !x.IsSelected;
 | 
						||
                        }
 | 
						||
                        return x;
 | 
						||
                    }).ToList();
 | 
						||
                }
 | 
						||
            });
 | 
						||
        }
 | 
						||
        public DelegateCommand Query
 | 
						||
        {
 | 
						||
            get => new DelegateCommand(() =>
 | 
						||
            {
 | 
						||
                RequestData();
 | 
						||
            });
 | 
						||
        }
 | 
						||
        /// <summary>
 | 
						||
        /// 生成请领单
 | 
						||
        /// </summary>
 | 
						||
        public DelegateCommand CreateApplyOrder
 | 
						||
        {
 | 
						||
            get => new DelegateCommand(OpenCreateApplyDialog);
 | 
						||
        }
 | 
						||
 | 
						||
        public bool KeepAlive => false;
 | 
						||
 | 
						||
        public async void OpenCreateApplyDialog()
 | 
						||
        {
 | 
						||
            if (CollectDrugs != null)
 | 
						||
            {
 | 
						||
                List<CollectDrug> selectCollect = CollectDrugs.Where(cd => cd.IsSelected).ToList();
 | 
						||
                if (selectCollect.Count > 0)
 | 
						||
                {
 | 
						||
                    // 此处延时1毫秒,等待页面渲染
 | 
						||
                    await Task.Delay(TimeSpan.FromMilliseconds(1));
 | 
						||
                    DialogParameters dialogParameters = new DialogParameters();
 | 
						||
                    dialogParameters.Add("ApplyDrug", selectCollect);
 | 
						||
                    DialogServiceExtensions.ShowDialogHost(_dialogService, "CollectDrugDialog", dialogParameters, DoDialogResult, "RootDialog");
 | 
						||
 | 
						||
                }
 | 
						||
                else
 | 
						||
                {
 | 
						||
                    AlertMsg alertMsg = new AlertMsg
 | 
						||
                    {
 | 
						||
                        Message = "未选择任何数据,请先选择数据信息!",
 | 
						||
                        Type = MsgType.ERROR,
 | 
						||
                    };
 | 
						||
                    _eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
 | 
						||
                    return;
 | 
						||
                }
 | 
						||
            }
 | 
						||
        }
 | 
						||
 | 
						||
        private void DoDialogResult(IDialogResult dialogResult)
 | 
						||
        {
 | 
						||
            // 委托   被动执行     被子窗口执行
 | 
						||
            // dialogResult  第一方面可以拿到任意参数   第二方面   可判断关闭状态
 | 
						||
            //if(dialogResult.Result == ButtonResult.OK)
 | 
						||
            //{
 | 
						||
            RequestData();
 | 
						||
            //}
 | 
						||
            //MessageBox.Show("返回值:" + dialogResult.Result.ToString());
 | 
						||
        }
 | 
						||
 | 
						||
        public void OnNavigatedTo(NavigationContext navigationContext)
 | 
						||
        {
 | 
						||
            RequestData();
 | 
						||
        }
 | 
						||
 | 
						||
        public bool IsNavigationTarget(NavigationContext navigationContext)
 | 
						||
        {
 | 
						||
            return true;
 | 
						||
        }
 | 
						||
 | 
						||
        public void OnNavigatedFrom(NavigationContext navigationContext)
 | 
						||
        { 
 | 
						||
        }
 | 
						||
    }
 | 
						||
}
 |