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.Services.Dialogs; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Reflection.PortableExecutable; using System.Text; using System.Threading.Tasks; namespace DM_Weight.ViewModels { public class CollectDrugDialogViewModel : BindableBase, IDialogAware { public string Title => "请领申请确认"; //请领数量 private int _quantityCount; public int QuantityCount { get { return _quantityCount; } set { SetProperty(ref _quantityCount, value); } } //交处方张数 private int _orderCount; public int OrderCount { get { return _orderCount; } set { SetProperty(ref _orderCount, value); } } //空瓶数量 //private int _emptyCount; //public int EmptyCount { get { return _emptyCount; } set { SetProperty(ref _emptyCount, value); } } static string[] strColloctedId=ConfigurationManager.AppSettings["colloctedId"].Split(','); public static List StaticSelects = new() { new OrderTakeSelect { Code = strColloctedId[1] is null?"":strColloctedId[1], Name = strColloctedId[0]is null?"":strColloctedId[0] }, new OrderTakeSelect { Code = strColloctedId[1] is null?"":strColloctedId[3], Name = strColloctedId[0]is null?"":strColloctedId[2] } }; private List _selects = StaticSelects; public List Selects { get { return _selects; } set { SetProperty(ref _selects, value); } } private OrderTakeSelect _selectedItem = StaticSelects[0]; /// /// 查询条件 查询字段 /// public OrderTakeSelect SelectedItem { get { return _selectedItem; } set { SetProperty(ref _selectedItem, value); } } private List _beforeGroupcollectDrugList; public List BeforeGroupCollectDrugList { get { return _beforeGroupcollectDrugList; } set { SetProperty(ref _beforeGroupcollectDrugList, value); } } private List _collectDrugList; public List CollectDrugList { get { return _collectDrugList; } set { SetProperty(ref _collectDrugList, value); } } IEventAggregator _eventAggregator; public CollectDrugDialogViewModel(IEventAggregator eventAggregator) { _eventAggregator = eventAggregator; } public event Action RequestClose; public bool CanCloseDialog() { return true; } public void OnDialogClosed() { } public void OnDialogOpened(IDialogParameters parameters) { BeforeGroupCollectDrugList = parameters.GetValue>("ApplyDrug"); QuantityCount = BeforeGroupCollectDrugList.Sum(ap => ap.Quantity); OrderCount = BeforeGroupCollectDrugList.Count; CollectDrugList = BeforeGroupCollectDrugList.GroupBy(cd => cd.DrugId).Select(cd => new CollectDrug { DrugName = cd.Aggregate("", (Ccurrent, collectdrug) => collectdrug.DrugName), Quantity = cd.Sum(cd => cd.Quantity), DrugSpec = cd.Max(cd => cd.DrugSpec), Manufactory = cd.Max(cd => cd.Manufactory), DrugId=cd.Max(cd=>cd.DrugId) }).ToList(); //EmptyCount = 0; } public DelegateCommand CreateApply { get => new DelegateCommand(CreateApplyMethod); } /// /// 生成请领单 /// public void CreateApplyMethod() { var f = SqlSugarHelper.Db.UseTran(() => { string pleaseNo = DateTime.Now.ToString("yyyyMMddHHmmss"); if (CollectDrugList != null && CollectDrugList.Count > 0) { for (int d = 0; d < CollectDrugList.Count; d++) { CollectDrug groupDrug= CollectDrugList[d]; //保存请领申请表 SqlSugarHelper.Db.Insertable(new DrugPleaseClaim() { GetQuantity = groupDrug.Quantity,// QuantityCount, ReturnPrQuantity = OrderCount, Type = 32, State = 0, MachineId = SelectedItem.Code, ApplyUser = HomeWindowViewModel.Operator.Id, ReviewUser = HomeWindowViewModel.Reviewer == null ? 0 : HomeWindowViewModel.Reviewer.Id, DoDate = DateTime.Now, Department = ConfigurationManager.AppSettings["department"].ToString(), PleaseNo = pleaseNo, DrugId = groupDrug.DrugId, TotalQuantity= QuantityCount }).ExecuteCommand(); } } for (int i = 0; i < BeforeGroupCollectDrugList.Count; i++) { CollectDrug collectDrug = BeforeGroupCollectDrugList[i]; //修改处方表里的 药品请领状态(0未请领;1已请领) SqlSugarHelper.Db.Updateable(new OrderInfo() { ApplyStatus = 1, OrderNo = collectDrug.OrderNo, MachineId = ConfigurationManager.AppSettings["machineId"].ToString() }).UpdateColumns(it => new { it.ApplyStatus }).Where(it => it.OrderNo == collectDrug.OrderNo).ExecuteCommand(); //保存处方、请领申请中间表 SqlSugarHelper.Db.Insertable(new CollectDrug() { DrugPleaseClaimId = pleaseNo, OrderNo = collectDrug.OrderNo, DrugId = collectDrug.DrugId, Createdate = DateTime.Now, Status = 0, MachineId = ConfigurationManager.AppSettings["machineId"].ToString(), CurrentMachineId = ConfigurationManager.AppSettings["machineId"].ToString(), //ConfigurationManager.AppSettings["colloctedId"].ToString(), Quantity = collectDrug.Quantity }).ExecuteCommand(); } }); if (f.IsSuccess) { AlertMsg alertMsg = new AlertMsg { Message = "请领单已生成!", Type = MsgType.SUCCESS, }; _eventAggregator.GetEvent().Publish(alertMsg); } else { AlertMsg alertMsg = new AlertMsg { Message = "请领单生成失败!", Type = MsgType.ERROR, }; _eventAggregator.GetEvent().Publish(alertMsg); return; } RequestClose?.Invoke(new DialogResult(ButtonResult.OK)); } public DelegateCommand BtnCloseCommand { get => new DelegateCommand(() => { //DialogParameters parameters = new DialogParameters(); //parameters.Add("",); // 关闭当前窗口 RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); }); } } }