From 3bb1ef457aafa14c47dcd4136feeb917f1becafd Mon Sep 17 00:00:00 2001 From: maqiao <625215135@qq.com> Date: Tue, 27 Feb 2024 09:32:55 +0800 Subject: [PATCH] =?UTF-8?q?1)=E5=A4=9A=E6=89=B9=E6=AC=A1=E5=8A=A0=E8=8D=AF?= =?UTF-8?q?=E6=97=B6=E5=86=99=E8=A1=A8channel=5Fstock=E4=B8=AD=E7=9A=84dru?= =?UTF-8?q?g=5Fid=E4=B8=BAchannel=5Fstock=E8=A1=A8=E4=B8=AD=E7=9A=84drug?= =?UTF-8?q?=5Fid;=202)=E8=8D=AF=E5=93=81=E7=BB=91=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B8=B2=E6=9F=93=E6=A0=87=E7=AD=BE=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=203=EF=BC=89=E6=8C=87=E7=BA=B9=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E6=97=B6=E6=9F=A5=E6=95=B0=E6=8D=AE=E5=BA=93=E7=94=A8=E6=89=8B?= =?UTF-8?q?=E5=86=99sql=E6=89=A7=E8=A1=8C=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DM_Weight/App.xaml.cs | 6 +- .../ViewModels/AddDrugControlViewModel.cs | 4 +- .../BindingChannelNewDialogViewModel.cs | 60 ++++++++- .../CheckStockNewWindowViewModel.cs | 123 +++++++++++++----- DM_Weight/ViewModels/LoginWindowViewModel.cs | 8 +- .../Views/Dialog/BindingChannelNewDialog.xaml | 6 + 6 files changed, 162 insertions(+), 45 deletions(-) diff --git a/DM_Weight/App.xaml.cs b/DM_Weight/App.xaml.cs index 3015529..7ac68ee 100644 --- a/DM_Weight/App.xaml.cs +++ b/DM_Weight/App.xaml.cs @@ -59,9 +59,9 @@ namespace DM_Weight private readonly ILog logger = LogManager.GetLogger(typeof(App)); public App() { - //TabTipAutomation.IgnoreHardwareKeyboard = HardwareKeyboardIgnoreOptions.IgnoreAll; - //TabTipAutomation.BindTo(); - //TabTipAutomation.BindTo(); + TabTipAutomation.IgnoreHardwareKeyboard = HardwareKeyboardIgnoreOptions.IgnoreAll; + TabTipAutomation.BindTo(); + TabTipAutomation.BindTo(); } diff --git a/DM_Weight/ViewModels/AddDrugControlViewModel.cs b/DM_Weight/ViewModels/AddDrugControlViewModel.cs index d6a90ed..ee4cb7c 100644 --- a/DM_Weight/ViewModels/AddDrugControlViewModel.cs +++ b/DM_Weight/ViewModels/AddDrugControlViewModel.cs @@ -248,7 +248,8 @@ namespace DM_Weight.ViewModels ManuNo = it.ManuNo, EffDate = it.EffDate, Id = it.Id, - }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate }).ExecuteCommand(); + DrugId= it.DrugId, + }).UpdateColumns(it => new { it.Quantity, it.ManuNo, it.EffDate,it.DrugId }).ExecuteCommand(); } else { @@ -510,6 +511,7 @@ namespace DM_Weight.ViewModels cl.channelStocks = cl.channelStocks.Select(cs => { cs.drugManuNo = cl.Drug.DrugManuNos.Find(it => it.ManuNo.Equals(cs.ManuNo)); + cs.DrugId=cl.DrugId; return cs; }).ToList(); return cl; diff --git a/DM_Weight/ViewModels/BindingChannelNewDialogViewModel.cs b/DM_Weight/ViewModels/BindingChannelNewDialogViewModel.cs index 9303581..8e09db2 100644 --- a/DM_Weight/ViewModels/BindingChannelNewDialogViewModel.cs +++ b/DM_Weight/ViewModels/BindingChannelNewDialogViewModel.cs @@ -253,11 +253,11 @@ namespace DM_Weight.ViewModels .OrderBy(cl => cl.DrawerNo) .OrderBy(cl => cl.ColNo) .ToPageList(PageNum, PageSize, ref totalCount); - if(list!=null&&list.Count>0) + if (list != null && list.Count > 0) { for (int i = 0; i < list.Count; i++) { - if(list[i].channelStocks!=null&& list[i].channelStocks.Count>0) + if (list[i].channelStocks != null && list[i].channelStocks.Count > 0) { for (int j = 0; j < list[i].channelStocks.Count; j++) { @@ -322,7 +322,7 @@ namespace DM_Weight.ViewModels 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); + _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); @@ -360,7 +360,7 @@ namespace DM_Weight.ViewModels if (c > 0) { - if(c>1) + if (c > 1) { SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c")); SnackbarMessageQueue.Enqueue("同一药品不可绑多个库位"); @@ -399,8 +399,8 @@ namespace DM_Weight.ViewModels SnackbarMessageQueue.Enqueue("该药品已绑定库位,不可绑定多个库位"); return; } - var channelStock = SqlSugarHelper.Db.Queryable().Where(cs => cs.Chnguid == item.Id&&cs.Quantity>0).ToList(); - if(channelStock.Count>0) + var channelStock = SqlSugarHelper.Db.Queryable().Where(cs => cs.Chnguid == item.Id && cs.Quantity > 0).ToList(); + if (channelStock.Count > 0) { //有库存,不能解绑 @@ -485,7 +485,7 @@ namespace DM_Weight.ViewModels //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(); + SqlSugarHelper.Db.Updateable().SetColumns(it => new ChannelStock { DrugId = null, ManuNo = null, EffDate = null }).Where(it => it.Chnguid == item.Id).ExecuteCommand(); if (item.BoardType == 5) { // 清除显示屏库位信息 @@ -505,7 +505,53 @@ namespace DM_Weight.ViewModels } }); } + /// + /// 渲染标签 + /// + public DelegateCommand ResetLabelCommand + { + get => new DelegateCommand(async () => + { + var SelectChannels = Channels.FindAll(item => item.IsSelected); + var c = SelectChannels.Count; + if (c > 0) + { + SelectChannels.ForEach(async item => + { + //var channelStock = SqlSugarHelper.Db.Queryable().Where(cs => cs.Chnguid == item.Id).ToList(); + if (item.BoardType == 5) + { + if (item.DrugId == null) + { + // 清除显示屏库位信息 + _portUtil.ClearContent(item.DrawerNo, item.ColNo); + await Task.Delay(200); + _portUtil.ShowContent(item.DrawerNo, item.ColNo); + } + else + { + DrugInfo drugSelected = item.Drug; + _portUtil.WindowName = "BindingChannelDialog"; + // 向显示屏写入库位信息 + _portUtil.WriteChannelInfo(1, drugSelected.DrugName, item.DrawerNo, item.ColNo); + await Task.Delay(200); + _portUtil.WriteChannelInfo(2, drugSelected.DrugSpec, item.DrawerNo, item.ColNo); + await Task.Delay(200); + _portUtil.WriteChannelInfo(8, drugSelected.Manufactory.Length > 10 ? drugSelected.Manufactory.Substring(0, 10) : drugSelected.Manufactory, item.DrawerNo, item.ColNo); + await Task.Delay(200); + _portUtil.ShowContent(item.DrawerNo, item.ColNo); + //_portUtil.WriteChannelInfo(6, DrugManuNo.EffDate==null?"": DrugManuNo.EffDate, item.DrawerNo, item.ColNo); + await Task.Delay(200); + _portUtil.WriteQuantity(item.DrawerNo, item.ColNo, item.totalCount); + //await Task.Delay(200); + } + } + }); + //GetChannelsByDrawerNo(); + } + }); + } public DelegateCommand BtnCloseCommand { get => new DelegateCommand(() => diff --git a/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs b/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs index 6cd723f..fb16be6 100644 --- a/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs +++ b/DM_Weight/ViewModels/CheckStockNewWindowViewModel.cs @@ -170,8 +170,8 @@ namespace DM_Weight.ViewModels if (msg.WindowName == "CheckStockNewWindow") { - IGrouping grouping = enumerator.Current; - int DrawerNo =Convert.ToInt32(grouping.Key.Substring(0, grouping.Key.IndexOf('-'))); + IGrouping grouping = enumerator.Current; + int DrawerNo = grouping.Key;// Convert.ToInt32(grouping.Key.Substring(0, grouping.Key.IndexOf('-'))); List channelStocks = grouping.ToList(); switch (msg.EventType) @@ -198,34 +198,36 @@ namespace DM_Weight.ViewModels { channelStocks.ForEach(it => it.process = 3); } - IGrouping groupingBefore = enumerator.Current; - int DrawerNoBefore = Convert.ToInt32(groupingBefore.Key.Substring(0, groupingBefore.Key.IndexOf('-'))); + IGrouping groupingBefore = enumerator.Current; + int DrawerNoBefore = groupingBefore.Key; //Convert.ToInt32(groupingBefore.Key.Substring(0, groupingBefore.Key.IndexOf('-'))); if (enumerator.MoveNext()) { - IGrouping groupingAfter = enumerator.Current; - int DrawerNoAfter = Convert.ToInt32(groupingAfter.Key.Substring(0, groupingAfter.Key.IndexOf('-'))); + IGrouping groupingAfter = enumerator.Current; + int DrawerNoAfter = groupingAfter.Key;//Convert.ToInt32(groupingAfter.Key.Substring(0, groupingAfter.Key.IndexOf('-'))); //if (DrawerNoBefore < 9 && DrawerNoAfter > 8) //{ // Thread.Sleep(50); //} logger.Info($"抽屉号DrawerNoBefore【{DrawerNoBefore}】抽屉号DrawerNoAfter【{DrawerNoAfter}】"); - if (DrawerNoAfter == 17) + if (DrawerNoAfter == 17|| DrawerNoBefore == 17) { - if (DrawerNoBefore == 17) + //if (DrawerNoBefore == 17) { - Thread.Sleep(1000); - } - else - { - Thread.Sleep(500); + int sleepMilliseconds = Convert.ToInt32(ConfigurationManager.AppSettings["CheckSleepMilliseconds"]??"500"); + Thread.Sleep(sleepMilliseconds); } + //else + //{ + // Thread.Sleep(500); + //} } else { - Thread.Sleep(80); + //Thread.Sleep(80); + Thread.Sleep(500); } - logger.Info($"抽屉号DrawerNoBefore【{DrawerNoBefore}】抽屉号DrawerNoAfter【{DrawerNoAfter}】"); + //logger.Info($"抽屉号DrawerNoBefore【{DrawerNoBefore}】抽屉号DrawerNoAfter【{DrawerNoAfter}】"); OpenOneByOne(); } // 已经全部取出 @@ -272,8 +274,8 @@ namespace DM_Weight.ViewModels set => SetProperty(ref _channelStocks, value); } - private IEnumerable> enumerable; - private IEnumerator> enumerator; + private IEnumerable> enumerable; + private IEnumerator> enumerator; public DelegateCommand BindingChannelDialog { @@ -301,8 +303,8 @@ namespace DM_Weight.ViewModels { if (Status == 0) { - //enumerable = ChannelStocks.GroupBy(cs => cs.DrawerNo, cs => cs); - enumerable = ChannelStocks.GroupBy(cs => cs.Location, cs => cs); + enumerable = ChannelStocks.GroupBy(cs => cs.DrawerNo, cs => cs); + //enumerable = ChannelStocks.GroupBy(cs => cs.Location, cs => cs); enumerator = enumerable.GetEnumerator(); enumerator.MoveNext(); Status = 1; @@ -312,8 +314,9 @@ namespace DM_Weight.ViewModels } private void OpenOneByOne() { - IGrouping grouping = enumerator.Current; - int DrawerNo =Convert.ToInt32(grouping.Key.Substring(0,grouping.Key.IndexOf('-'))); + IGrouping grouping = enumerator.Current; + //int DrawerNo =Convert.ToInt32(grouping.Key.Substring(0,grouping.Key.IndexOf('-'))); + int DrawerNo = grouping.Key; List channelStocks = grouping.ToList(); channelStocks.ForEach(it => it.process = 1); _portUtil.SpeakAsync("正在打开" + DrawerNo + "号抽屉"); @@ -372,7 +375,6 @@ namespace DM_Weight.ViewModels string InvoiceId = "CHECK_" + CurrentTimeMillis(); var f = SqlSugarHelper.Db.UseTran(() => { - for (int i = 0; i < record.Count; i++) { ChannelStock it = record[i]; @@ -416,8 +418,8 @@ namespace DM_Weight.ViewModels logger.Info($"库存盘点->库位【{it.DrawerNo}-{it.ColNo}】药品【{it.DrugInfo.DrugName}】盘点前库存【{it.Quantity}】,更改后【{it.CheckQuantity}】"); } - - + + //Task.Factory.StartNew(()=> SaveCheckRecord()); string machine_id = (ConfigurationManager.AppSettings["machineId"] ?? "DM1"); string strSql = $@"SELECT cl.`row_no` AS rowNo,cl.`col_no` AS colNo,cl.`quantity` AS quantity,cl.`manu_no` AS manuNo,cl.`eff_date` AS effDate, di.`drug_name` AS drugName,di.`drug_spec` AS drugSpec,di.`pack_unit` AS packUnit,di.`manufactory` AS manufactory,di.`max_stock` maxStock, @@ -429,6 +431,9 @@ namespace DM_Weight.ViewModels }) .Select(it => new CheckRecordStock()) .ToList(); + + logger.Info("已完成-查询channel_stock关联drug_info表信息查询"); + List insertList = new List(); if (checkRecordStockList != null && checkRecordStockList.Count > 0) @@ -467,15 +472,14 @@ namespace DM_Weight.ViewModels }).ExecuteCommand(); } } - - + logger.Info("已完成-保存数据 盘点后药品总库存及批次库存数"); return true; }); if (f.Data) { // 更新屏显库存 //List singleChannels = record.FindAll(it => it.BoardType != 1); - List singleChannels = record.FindAll(it => it.BoardType != 1) + List singleChannels = record.FindAll(it => it.BoardType == 5) .GroupBy(it => new { it.DrawerNo, @@ -487,7 +491,7 @@ namespace DM_Weight.ViewModels //ret.AddQuantity = it.Sum(itx => itx.AddQuantity); return ret; }).ToList(); - if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) + //if ((singleChannels.Count > 0 ? singleChannels[0].BoardType : 1) == 5) { singleChannels.ForEach(it => { @@ -496,14 +500,15 @@ namespace DM_Weight.ViewModels }); } - - RequestData(); + logger.Info("已完成-更新标签"); AlertMsg alertMsg = new AlertMsg { Message = "抽屉盘点完成,库存已更新", Type = MsgType.SUCCESS, }; _eventAggregator.GetEvent().Publish(alertMsg); + + RequestData(); } if (!f.IsSuccess) { @@ -533,7 +538,64 @@ namespace DM_Weight.ViewModels }, () => Status == 3 && !_isFinishClick).ObservesProperty(() => Status); } + public void SaveCheckRecord() + { + string machine_id = (ConfigurationManager.AppSettings["machineId"] ?? "DM1"); + string strSql = $@"SELECT cl.`row_no` AS rowNo,cl.`col_no` AS colNo,cl.`quantity` AS quantity,cl.`manu_no` AS manuNo,cl.`eff_date` AS effDate, + di.`drug_name` AS drugName,di.`drug_spec` AS drugSpec,di.`pack_unit` AS packUnit,di.`manufactory` AS manufactory,di.`max_stock` maxStock, + cl.`drug_id` AS drugId,cl.`machine_id` AS MachineId FROM channel_stock cl INNER JOIN drug_info di ON di.`drug_id` = cl.`drug_id` WHERE cl.`machine_id` = '{machine_id}' AND cl.`drawer_type` = 1 ORDER BY cl.`drug_id`"; + List checkRecordStockList = SqlSugarHelper.Db.SqlQueryable(strSql) + .AddParameters(new + { + machineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1" + }) + .Select(it => new CheckRecordStock()) + .ToList(); + logger.Info("已完成-查询channel_stock关联drug_info表信息查询"); + + List insertList = new List(); + + if (checkRecordStockList != null && checkRecordStockList.Count > 0) + { + for (int i = 0; i < checkRecordStockList.Count; i++) + { + if (!(insertList.Where(it => it.drugId == checkRecordStockList[i].drugId && it.manuNo == checkRecordStockList[i].manuNo).Count() > 0)) + { + insertList.Add(checkRecordStockList[i]); + } + } + for (int j = 0; j < insertList.Count; j++) + { + + + CheckRecordStock cStock = insertList[j]; + // 保存数据 盘点后药品总库存及批次库存数 + SqlSugarHelper.Db.Insertable(new CheckRecordStock() + { + rowNo = cStock.rowNo, + colNo = cStock.colNo, + ManuQuantity = checkRecordStockList.Where(it => it.drugId == cStock.drugId && it.manuNo == cStock.manuNo).Sum(it => it.quantity), + manuNo = cStock.manuNo, + effDate = cStock.effDate, + drugName = cStock.drugName, + manufactory = cStock.manufactory, + drugSpec = cStock.drugSpec, + packUnit = cStock.packUnit, + maxStock = cStock.maxStock, + drugId = cStock.drugId, + MachineId = cStock.MachineId, + quantity = checkRecordStockList.Where(it => it.drugId == cStock.drugId).Sum(it => it.quantity), + optdate = DateTime.Now.ToString(), + operatorUser = HomeWindowViewModel.Operator?.Id.ToString(), + reviewerUser = HomeWindowViewModel.Reviewer?.Id.ToString() + }).ExecuteCommand(); + } + } + + + logger.Info("已完成-插入check_stock表信息"); + } // 取消按钮 public DelegateCommand CancleTake { @@ -613,6 +675,7 @@ namespace DM_Weight.ViewModels .WhereIF(!String.IsNullOrEmpty(SearchValue), cs => cs.DrugInfo.DrugName == SearchValue) .OrderBy(cs => cs.DrawerNo) + //.OrderByDescending(cs => cs.DrawerNo) .OrderBy(cs => cs.ColNo) //.OrderBy(cs => cs.DrugId) .ToList(); diff --git a/DM_Weight/ViewModels/LoginWindowViewModel.cs b/DM_Weight/ViewModels/LoginWindowViewModel.cs index 048a019..48654fd 100644 --- a/DM_Weight/ViewModels/LoginWindowViewModel.cs +++ b/DM_Weight/ViewModels/LoginWindowViewModel.cs @@ -339,11 +339,11 @@ _exitCommand ??= new DelegateCommand(Exit); logger.Info($"msg.Message.Equals:{msg.Message}"); if (msg.Message.Equals("LOGIN")) { - UserList userList = SqlSugarHelper.Db.Queryable() - .Includes(u => u.Role) - .First(u => u.Id == msg.Id); + //UserList userList = SqlSugarHelper.Db.Queryable() + //.Includes(u => u.Role) + //.First(u => u.Id == msg.Id); - //UserList userList = new UserService().CheckUserByFingerPrinter(msg.Id); + UserList userList = new UserService().CheckUserByFingerPrinter(msg.Id); logger.Info($"userList是空?{userList == null}"); if (userList == null) diff --git a/DM_Weight/Views/Dialog/BindingChannelNewDialog.xaml b/DM_Weight/Views/Dialog/BindingChannelNewDialog.xaml index 2961b14..31cec02 100644 --- a/DM_Weight/Views/Dialog/BindingChannelNewDialog.xaml +++ b/DM_Weight/Views/Dialog/BindingChannelNewDialog.xaml @@ -73,7 +73,13 @@ DisplayMemberPath="drug_name_spec" IsEditable="True" IsTextSearchEnabled="False" KeyUp="ComboBox_KeyUp" /> +