diff --git a/DM_Weight/ViewModels/BindingChannelNewDialogViewModel.cs b/DM_Weight/ViewModels/BindingChannelNewDialogViewModel.cs deleted file mode 100644 index 9303581..0000000 --- a/DM_Weight/ViewModels/BindingChannelNewDialogViewModel.cs +++ /dev/null @@ -1,544 +0,0 @@ -using MaterialDesignThemes.Wpf; -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.Text; -using System.Threading.Tasks; -using System.Windows.Media; -using DM_Weight.Models; -using DM_Weight.msg; -using DM_Weight.Port; -using DM_Weight.util; -using log4net; -using System.Threading; -using System.Reflection.Metadata.Ecma335; - -namespace DM_Weight.ViewModels -{ - public class BindingChannelNewDialogViewModel : BindableBase, IDialogAware, IRegionMemberLifetime - { - - public string Title => "库位绑定"; - - public event Action RequestClose; - - private int _drawerNo = 0; - - - private SolidColorBrush _colorBrush; - - public SolidColorBrush SnackbarBackground - { - get => _colorBrush; - set => SetProperty(ref _colorBrush, value); - } - - private ISnackbarMessageQueue _snackbarMessageQueue = new SnackbarMessageQueue(TimeSpan.FromSeconds(3)); - - public ISnackbarMessageQueue SnackbarMessageQueue - { - get => _snackbarMessageQueue; - set => SetProperty(ref _snackbarMessageQueue, value); - } - - IEventAggregator _eventAggregator; - PortUtil _portUtil; - //ScreenUtil _screenUtil; - ////private SqlSugarScope SqlSugarHelper.Db; - public static BindingChannelNewDialogViewModel vm; - public BindingChannelNewDialogViewModel(IEventAggregator eventAggregator, PortUtil portUtil//, ScreenUtil screenUtil - ) - { - _eventAggregator = eventAggregator; - _portUtil = portUtil; - //_screenUtil = screenUtil; - ////this.SqlSugarHelper.Db = sqlSugarScope; - vm = this; - } - - public int DrawerNo - { - get => _drawerNo; - set - { - SetProperty(ref _drawerNo, value); - GetChannelsByDrawerNo(); - } - } - - private DrugInfo? _drugInfo; - - public DrugInfo? DrugInfo - { - get => _drugInfo; - set - { - SetProperty(ref _drugInfo, value); - //if (_drugInfo != null) - //{ - // DrugManuNos = _drugInfo.DrugManuNos.OrderByDescending(dm => dm.ManuNo).ToList(); - //} - } - } - private List? _drugInfos; - public List? DrugInfos - { - get => _drugInfos; - set => SetProperty(ref _drugInfos, value); - } - ////拼音码对应药品实体 - //private DrugInfo? _durgInfo_for_py; - //public DrugInfo? DrugInfo_Py - //{ - // get => _durgInfo_for_py; - // set - // { - - // SetProperty(ref _durgInfo_for_py, value); - // if (_durgInfo_for_py != null) - // { - // DrugInfos = GetDrugByDrugPY(_durgInfo_for_py.PyCode); - // } - // else - // { - // DrugInfos = GetDrugByDrugPY(""); - // } - // } - //} - - //#region 根据药品拼音码查询药品名称 - //private List GetDrugByDrugPY(string pycode) - //{ - // List DrugList = null; - // if (!string.IsNullOrEmpty(pycode)) - // { - // DrugList = SqlSugarHelper.Db.Queryable().Includes(di => di.DrugManuNos).Where(di => di.PyCode.Contains(pycode)).OrderBy(di => di.DrugId).ToList(); - // } - // else - // { - // DrugList = SqlSugarHelper.Db.Queryable().Includes(di => di.DrugManuNos).OrderBy(di => di.DrugId).ToList(); - // } - // return DrugList; - //} - //private List? _drugInfos_py; - //public List? DrugInfos_PY - //{ - // get => _drugInfos_py; - // set => SetProperty(ref _drugInfos_py, value); - //} - //#endregion 根据药品拼音码查询药品名称 - - - public void UpdateComboBoxItems(string text) - { - string str = @"SELECT d.drug_id,d.py_code,d.drug_barcode,d.drug_name,d.drug_brand_name,d.drug_spec,d.dosage,d.pack_unit, - d.manufactory,d.max_stock,CONCAT(drug_name,' ',drug_spec)as drug_name_spec FROM `drug_info` d"; - if (string.IsNullOrEmpty(text)) - { - DrugInfos = SqlSugarHelper.Db.SqlQueryable(str).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList(); - return; - } - if (DrugInfos != null) - { - DrugInfos.Clear(); - } - - DrugInfos = SqlSugarHelper.Db.SqlQueryable(str).Where(di => di.DrugName.Contains(text) || di.PyCode.Contains(text) || di.DrugId.Contains(text)).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList(); - - } - //private List? _drugInfos; - - //public List? DrugInfos - //{ - // get => _drugInfos; - // set => SetProperty(ref _drugInfos, value); - //} - - //private DrugManuNo? _drugManuNo; - - //public DrugManuNo? DrugManuNo - //{ - // get => _drugManuNo; - // set => SetProperty(ref _drugManuNo, value); - //} - //private List? _drugManuNos; - - //public List? DrugManuNos - //{ - // get => _drugManuNos; - // set => SetProperty(ref _drugManuNos, value); - //} - - - private List? _channels; - - public List? Channels - { - get => _channels; - set => SetProperty(ref _channels, value); - } - - private int _totalCount = 0; - public int TotalCount { get => _totalCount; set => SetProperty(ref _totalCount, value); } - - private int _pageNum = 1; - public int PageNum - { - get => _pageNum; - set - { - SetProperty(ref _pageNum, value); - GetChannelsByDrawerNo(); - } - } - - 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); - } - } - - - - public bool CanCloseDialog() - { - return true; - } - - public void OnDialogClosed() - { - _eventAggregator.GetEvent().Unsubscribe(DoMyPrismEvent); - } - - private void GetAllDrugInfos() - { - //var list = SqlSugarHelper.Db.Queryable().Includes(di => di.DrugManuNos).OrderBy(di => di.DrugId).ToList(); - //DrugInfos = list; - //DrugInfos_PY = list; - string str = "SELECT d.drug_id,d.py_code,d.drug_barcode,d.drug_name,d.drug_brand_name,d.drug_spec,d.dosage,d.pack_unit,d.manufactory,d.max_stock,CONCAT(drug_name,' ',drug_spec)as drug_name_spec FROM `drug_info` d"; - DrugInfos = SqlSugarHelper.Db.SqlQueryable(str).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList(); - - } - - private void GetChannelsByDrawerNo() - { - Channels?.Clear(); - int totalCount = 0; - var list = SqlSugarHelper.Db.Queryable() - .Includes(cl => cl.Drug) - .Includes(cs => cs.channelStocks) - .WhereIF(DrawerNo > 0, cl => cl.DrawerNo == DrawerNo) - .Where(cl => cl.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) - .OrderBy(cl => cl.DrawerNo) - .OrderBy(cl => cl.ColNo) - .ToPageList(PageNum, PageSize, ref totalCount); - if(list!=null&&list.Count>0) - { - for (int i = 0; i < list.Count; i++) - { - if(list[i].channelStocks!=null&& list[i].channelStocks.Count>0) - { - for (int j = 0; j < list[i].channelStocks.Count; j++) - { - list[i].totalCount += list[i].channelStocks[j].Quantity; - } - } - } - } - Channels = list; - TotalCount = totalCount; - } - public void OnDialogOpened(IDialogParameters parameters) - { - if (parameters.ContainsKey("DrawerNo")) - { - DrawerNo = parameters.GetValue("DrawerNo"); - } - GetAllDrugInfos(); - GetChannelsByDrawerNo(); - _eventAggregator.GetEvent().Subscribe(DoMyPrismEvent); - } - public DelegateCommand Query - { - get => new DelegateCommand(() => - { - GetChannelsByDrawerNo(); - }); - } - - - public DelegateCommand BindingDrug - { - get => new DelegateCommand(async () => - { - - var SelectChannels = Channels.FindAll(item => item.IsSelected); - - if (SelectChannels.All(it => it.DrawerType != 1)) - { - if (SelectChannels.Count == 1) - { - if (DrugInfo != null) - { - int count = SqlSugarHelper.Db.Queryable().Where(cs => cs.DrugId.Equals(DrugInfo.DrugId.ToString())).Where(cs => cs.DrawerType != 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).Count(); - if (count == 0) - { - var item = SelectChannels[0]; - - if (item.DrugId == null || !DrugInfo.DrugId.ToString().Equals(item.DrugId)) - { - item.PosNo = 0; - } - item.DrugId = DrugInfo.DrugId.ToString(); - SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId, it.PosNo }).ExecuteCommand(); - GetChannelsByDrawerNo(); - - if (item.BoardType == 5) - { - _portUtil.WindowName = "BindingChannelDialog"; - // 向显示屏写入库位信息 - _portUtil.WriteChannelInfo(1, DrugInfo.DrugName, item.DrawerNo, item.ColNo); - await Task.Delay(200); - _portUtil.WriteChannelInfo(2, DrugInfo.DrugSpec, item.DrawerNo, item.ColNo); - await Task.Delay(200); - _portUtil.WriteChannelInfo(8, DrugInfo.Manufactory.Length>10? DrugInfo.Manufactory.Substring(0, 10): DrugInfo.Manufactory, item.DrawerNo, item.ColNo); - await Task.Delay(200); - //_portUtil.WriteChannelInfo(6, DrugManuNo.EffDate==null?"": DrugManuNo.EffDate, item.DrawerNo, item.ColNo); - //await Task.Delay(200); - //_portUtil.WriteChannelInfo(5, DrugManuNo.ManuNo, item.DrawerNo, item.ColNo); - //await Task.Delay(200); - _portUtil.ShowContent(item.DrawerNo, item.ColNo); - } - //_screenUtil.SetStockInfo(item, 1); - - } - else - { - SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); - SnackbarMessageQueue.Enqueue($"药品【{DrugInfo.DrugName}】已经绑定了回收库位不可再次绑定"); - } - } - else - { - SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); - SnackbarMessageQueue.Enqueue("请选择库位需要绑定的药品信息"); - } - } - else - { - SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); - SnackbarMessageQueue.Enqueue("每种药品只能绑定一个回收库位"); - } - } - else - { - //if (DrugInfo != null && DrugManuNo != null) - //{ - - var c = SelectChannels.Count; - - if (c > 0) - { - if(c>1) - { - SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); - SnackbarMessageQueue.Enqueue("同一药品不可绑多个库位"); - return; - } - //else - //{ - // int count = SqlSugarHelper.Db.Queryable() - // .Where(cs => cs.DrugId.Equals(DrugInfo.DrugId.ToString())) - // .Where(cs => cs.DrawerType == 1) - // .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) - // .Where(cs=>cs.DrawerNo=) - // .Count(); - - // if (count > 0) - // { - // SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); - // SnackbarMessageQueue.Enqueue("该药品已绑定库位,不可绑定多个库位"); - // return; - // } - //} - - for (int i = 0; i < SelectChannels.Count; i++) - { - var item = SelectChannels[i]; - int count = SqlSugarHelper.Db.Queryable() - .Where(cs => cs.DrugId.Equals(DrugInfo.DrugId.ToString())) - .Where(cs => cs.DrawerType == 1) - .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")) - .Where(cs => cs.DrawerNo == item.DrawerNo) - .Count(); - - if (count > 0) - { - SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); - SnackbarMessageQueue.Enqueue("该药品已绑定库位,不可绑定多个库位"); - return; - } - var channelStock = SqlSugarHelper.Db.Queryable().Where(cs => cs.Chnguid == item.Id&&cs.Quantity>0).ToList(); - if(channelStock.Count>0) - { - //有库存,不能解绑 - - SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); - SnackbarMessageQueue.Enqueue($"库位{item.DrawerNo}-{item.ColNo}中还存在药品,不能绑定其他药品"); - continue; - } - if (item.DrugId == null || !DrugInfo.DrugId.ToString().Equals(item.DrugId)) - { - item.PosNo = 0; - } - - item.DrugId = DrugInfo.DrugId.ToString(); - //item.ManuNo = DrugManuNo.ManuNo; - item.Drug = DrugInfo; - //item.EffDate = String.Format("{0:yyyy-MM-dd}", DrugManuNo.EffDate); - SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId, it.PosNo }).ExecuteCommand(); - - if (item.BoardType == 5) - { - _portUtil.WindowName = "BindingChannelDialog"; - // 向显示屏写入库位信息 - _portUtil.WriteChannelInfo(1, DrugInfo.DrugName, item.DrawerNo, item.ColNo); - await Task.Delay(200); - //Thread.Sleep(200); - _portUtil.WriteChannelInfo(2, DrugInfo.DrugSpec, item.DrawerNo, item.ColNo); - await Task.Delay(200); - //Thread.Sleep(200); - _portUtil.WriteChannelInfo(8, DrugInfo.Manufactory.Length > 10 ? DrugInfo.Manufactory.Substring(0, 10) : DrugInfo.Manufactory, item.DrawerNo, item.ColNo); - await Task.Delay(200); - //Thread.Sleep(200); - //_portUtil.WriteChannelInfo(6, DrugManuNo.ManuNo, item.DrawerNo, item.ColNo); - //await Task.Delay(200); - //Thread.Sleep(200); - //_portUtil.WriteChannelInfo(5, String.Format("{0:yyyy-MM-dd}", DrugManuNo.EffDate), item.DrawerNo, item.ColNo); - ////await Task.Delay(200); - //Thread.Sleep(200); - _portUtil.ShowContent(item.DrawerNo, item.ColNo); - } - } - - - GetChannelsByDrawerNo(); - } - else - { - SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); - SnackbarMessageQueue.Enqueue("所选库位中无可绑定库位【库位还存在药品】"); - } - //} - //else - //{ - // SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); - // SnackbarMessageQueue.Enqueue("请选择库位需要绑定的药品及批次信息"); - //} - } - }); - } - - public DelegateCommand RemoveBinding - { - get => new DelegateCommand(async () => - { - var SelectChannels = Channels.FindAll(item => item.IsSelected && item.DrugId != null); - var c = SelectChannels.Count; - if (c > 0) - { - - SelectChannels.ForEach(async item => - { - var channelStock = SqlSugarHelper.Db.Queryable().Where(cs => cs.Chnguid == item.Id && cs.Quantity > 0).ToList(); - if (channelStock.Count > 0) - { - SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); - SnackbarMessageQueue.Enqueue("所选库位中无可解绑药品【库位还存在药品】"); - //该药品下的批次还有库存则不能解绑 - return; - } - - item.DrugId = null; - //item.ManuNo = null; - //item.EffDate = null; - item.Drug = null; - SqlSugarHelper.Db.Updateable(item).UpdateColumns(it => new { it.DrugId }).ExecuteCommand(); - SqlSugarHelper.Db.Updateable().SetColumns(it =>new ChannelStock { DrugId = null, ManuNo = null, EffDate = null} ).Where(it=>it.Chnguid==item.Id).ExecuteCommand(); - if (item.BoardType == 5) - { - // 清除显示屏库位信息 - _portUtil.ClearContent(item.DrawerNo, item.ColNo); - await Task.Delay(200); - _portUtil.ShowContent(item.DrawerNo, item.ColNo); - } - - //_screenUtil.SetStockInfo(item, 1); - }); - GetChannelsByDrawerNo(); - } - else - { - SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); - SnackbarMessageQueue.Enqueue("所选库位中无可解绑药品"); - } - }); - } - - public DelegateCommand BtnCloseCommand - { - get => new DelegateCommand(() => - { - //DialogParameters parameters = new DialogParameters(); - //parameters.Add("",); - // 关闭当前窗口 - RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); - }); - } - - public bool KeepAlive => true; - string message = string.Empty; - private void DoMyPrismEvent(DeviceMsg msg) - { - if (msg.WindowName == "BindingChannelDialog") - { - switch (msg.EventType) - { - case EventType.OPENERROR: - AlertMsg alertMsg = new AlertMsg - { - Message = msg.Message, - Type = MsgType.ERROR, - }; - if (message != msg.Message) - { - message = msg.Message; - _eventAggregator.GetEvent().Publish(alertMsg); - } - break; - } - } - } - } -}