271 lines
		
	
	
		
			8.3 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			271 lines
		
	
	
		
			8.3 KiB
		
	
	
	
		
			C#
		
	
	
	
| 
								 | 
							
								using DM_Weight.Models;
							 | 
						|||
| 
								 | 
							
								using DM_Weight.select;
							 | 
						|||
| 
								 | 
							
								using DM_Weight.util;
							 | 
						|||
| 
								 | 
							
								using Newtonsoft.Json;
							 | 
						|||
| 
								 | 
							
								using Prism.Commands;
							 | 
						|||
| 
								 | 
							
								using Prism.Mvvm;
							 | 
						|||
| 
								 | 
							
								using Prism.Regions;
							 | 
						|||
| 
								 | 
							
								using Prism.Services.Dialogs;
							 | 
						|||
| 
								 | 
							
								using System;
							 | 
						|||
| 
								 | 
							
								using System.Collections;
							 | 
						|||
| 
								 | 
							
								using System.Collections.Generic;
							 | 
						|||
| 
								 | 
							
								using System.Configuration;
							 | 
						|||
| 
								 | 
							
								using System.Linq;
							 | 
						|||
| 
								 | 
							
								using System.Text;
							 | 
						|||
| 
								 | 
							
								using System.Threading.Tasks;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								namespace DM_Weight.ViewModels
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    public class InvoiceOutWindowViewModel : BindableBase, IConfirmNavigationRequest, 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);
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        IDialogService _dialogService;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        private DelegateCommand _rowSelected;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public DelegateCommand RowSelected => _rowSelected ??= new DelegateCommand(OpenOrderDialog);
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public InvoiceOutWindowViewModel(IDialogService DialogService)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            _dialogService = DialogService;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public static List<OrderTakeSelect> StaticOrderTakeSelects = new()
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            new OrderTakeSelect
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                Code = "invoiceNo",
							 | 
						|||
| 
								 | 
							
								                Name = "凭证单号"
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        };
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        private List<OrderTakeSelect> _orderTakeSelects = StaticOrderTakeSelects;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public List<OrderTakeSelect> OrderTakeSelects
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get { return _orderTakeSelects; }
							 | 
						|||
| 
								 | 
							
								            set
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                SetProperty(ref _orderTakeSelects, value);
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        private OrderTakeSelect _selectedItem = StaticOrderTakeSelects[0];
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 查询条件 查询字段
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        public OrderTakeSelect SelectedItem
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get { return _selectedItem; }
							 | 
						|||
| 
								 | 
							
								            set
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                SetProperty(ref _selectedItem, value);
							 | 
						|||
| 
								 | 
							
								                RequestData();
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        private Invoice? _selectedInvoice;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public Invoice? SelectedInvoice
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get { return _selectedInvoice; }
							 | 
						|||
| 
								 | 
							
								            set
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                SetProperty(ref _selectedInvoice, value);
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                //OpenOrderDialog();
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        private string _orderDate = DateTime.Now.ToString("yyyy-MM-dd");
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 查询条件  处方日期
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        public string OrderDate
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get { return _orderDate; }
							 | 
						|||
| 
								 | 
							
								            set
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                if (!String.IsNullOrEmpty(value))
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    SetProperty(ref _orderDate, DateTime.Parse(value).ToString("yyyy-MM-dd"));
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                else
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    SetProperty(ref _orderDate, value);
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                RequestData();
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        private string? _searchValue;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 查询条件 查询字段值
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        public string? SearchValue
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get { return _searchValue; }
							 | 
						|||
| 
								 | 
							
								            set
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                SetProperty(ref _searchValue, value);
							 | 
						|||
| 
								 | 
							
								                RequestData();
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        private List<Invoice> _invoices = new();
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public List<Invoice> Invoices { get { return _invoices; } set { SetProperty(ref _invoices, value); } }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public bool KeepAlive => false;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public async void OpenOrderDialog()
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            if (SelectedInvoice != null && SelectedInvoice.Status == 0)
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                // 此处延时1毫秒,等待页面渲染
							 | 
						|||
| 
								 | 
							
								                await Task.Delay(TimeSpan.FromMilliseconds(1));
							 | 
						|||
| 
								 | 
							
								                DialogParameters dialogParameters = new DialogParameters();
							 | 
						|||
| 
								 | 
							
								                dialogParameters.Add("invoice", SelectedInvoice);
							 | 
						|||
| 
								 | 
							
								                DialogServiceExtensions.ShowDialogHost(_dialogService, "InvoiceTakeDialog", dialogParameters, DoDialogResult, "RootDialog");
							 | 
						|||
| 
								 | 
							
								                RequestData();
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public DelegateCommand QueryCommand
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            get => new DelegateCommand(() =>
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                RequestData();
							 | 
						|||
| 
								 | 
							
								            });
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        private void DoDialogResult(IDialogResult dialogResult)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            // 委托   被动执行     被子窗口执行
							 | 
						|||
| 
								 | 
							
								            // dialogResult  第一方面可以拿到任意参数   第二方面   可判断关闭状态
							 | 
						|||
| 
								 | 
							
								            //if (dialogResult.Result == ButtonResult.OK)
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                SelectedInvoice = null;
							 | 
						|||
| 
								 | 
							
								                RequestData();
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            //MessageBox.Show("返回值:" + dialogResult.Result.ToString());
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        //这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作
							 | 
						|||
| 
								 | 
							
								        public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            continuationCallback(true);
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        public void RequestData()
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            Invoices.Clear();
							 | 
						|||
| 
								 | 
							
								            int totalCount = 0;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								            var sb = new StringBuilder();
							 | 
						|||
| 
								 | 
							
								            sb.Append("select i.invoice_no as InvoiceNo, i.invoice_date as InvoiceDate, COUNT(i.id) as `Count`, SUM(i.quantity) as quantity, p1.pharmacy_name as PharmacyName1, p2.pharmacy_name as PharmacyName2 from in_out_invoice i");
							 | 
						|||
| 
								 | 
							
								            sb.Append(" inner join ( select c.drug_id as drug_id from channel_stock c where c.machine_id = '" + (ConfigurationManager.AppSettings["machineId"] ?? "DM1") + "' group by c.drug_id ) di on di.drug_id = i.drug_id");
							 | 
						|||
| 
								 | 
							
								            sb.Append(" left join pharmacy_info p1 on p1.pharmacy_id = i.in_pharmacy_id");
							 | 
						|||
| 
								 | 
							
								            sb.Append(" left join pharmacy_info p2 on p2.pharmacy_id = i.out_pharmacy_id");
							 | 
						|||
| 
								 | 
							
								            sb.Append(" where i.status=@Status ");
							 | 
						|||
| 
								 | 
							
								            sb.Append(" and i.type!=@type ");
							 | 
						|||
| 
								 | 
							
								            sb.Append(" and i.cancel_flag=@CancelFlag ");
							 | 
						|||
| 
								 | 
							
								            if (OrderDate != null)
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                sb.Append(" and i.invoice_date = @CreateTime ");
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            if (!String.IsNullOrEmpty(SearchValue))
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                sb.Append(" and i.invoice_no = @InvoiceNo ");
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["storage"]))
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                sb.Append(" and i.out_pharmacy_id = @OutPharmacyId ");
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            sb.Append(" group by i.invoice_no");
							 | 
						|||
| 
								 | 
							
								            sb.Append(" order by i.invoice_date ");
							 | 
						|||
| 
								 | 
							
								            Invoices = SqlSugarHelper.Db.SqlQueryable<dynamic>(sb.ToString())
							 | 
						|||
| 
								 | 
							
								                .AddParameters(new
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    Status = 0,
							 | 
						|||
| 
								 | 
							
								                    type = 1,
							 | 
						|||
| 
								 | 
							
								                    CancelFlag = 0,
							 | 
						|||
| 
								 | 
							
								                    CreateTime = OrderDate,
							 | 
						|||
| 
								 | 
							
								                    InvoiceNo = SearchValue,
							 | 
						|||
| 
								 | 
							
								                    OutPharmacyId = ConfigurationManager.AppSettings["storage"]
							 | 
						|||
| 
								 | 
							
								                })
							 | 
						|||
| 
								 | 
							
								                .Select(it => new Invoice())
							 | 
						|||
| 
								 | 
							
								                .Select("*")
							 | 
						|||
| 
								 | 
							
								                .ToPageList(PageNum, PageSize, ref totalCount);
							 | 
						|||
| 
								 | 
							
								            
							 | 
						|||
| 
								 | 
							
								            TotalCount = totalCount;
							 | 
						|||
| 
								 | 
							
								            PageCount = (int)Math.Ceiling((double)TotalCount / PageSize);
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        //接收导航传过来的参数  现在是在此处初始化了表格数据
							 | 
						|||
| 
								 | 
							
								        public void OnNavigatedTo(NavigationContext navigationContext)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            RequestData();
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        //每次导航的时候,该实列用不用重新创建,true是不重新创建,false是重新创建
							 | 
						|||
| 
								 | 
							
								        public bool IsNavigationTarget(NavigationContext navigationContext)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            return true;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        //这个方法用于拦截请求
							 | 
						|||
| 
								 | 
							
								        public void OnNavigatedFrom(NavigationContext navigationContext)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 |