From ae95b8c2689c7488c830f88a84f2fadacaa58852 Mon Sep 17 00:00:00 2001
From: maqiao <625215135@qq.com>
Date: Thu, 18 Jul 2024 09:21:59 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8D=AF=E7=9B=92=E3=80=81?=
=?UTF-8?q?=E6=A0=87=E7=AD=BE=E6=98=BE=E7=A4=BA=E5=B1=8F=E6=8C=87=E4=BB=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
DM_Weight/App.config | 2 +-
DM_Weight/Models/DrugType.cs | 14 ++++
DM_Weight/Port/PortUtil.cs | 71 +++++++++++++++++--
.../ViewModels/AccountWindowViewModel.cs | 60 ++++++++++++----
.../BindingChannelDialogViewModel.cs | 7 ++
DM_Weight/Views/AccountWindow.xaml | 10 ++-
6 files changed, 141 insertions(+), 23 deletions(-)
create mode 100644 DM_Weight/Models/DrugType.cs
diff --git a/DM_Weight/App.config b/DM_Weight/App.config
index 2684df2..ee262d3 100644
--- a/DM_Weight/App.config
+++ b/DM_Weight/App.config
@@ -60,7 +60,7 @@
-
+
diff --git a/DM_Weight/Models/DrugType.cs b/DM_Weight/Models/DrugType.cs
new file mode 100644
index 0000000..44eb58b
--- /dev/null
+++ b/DM_Weight/Models/DrugType.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DM_Weight.Models
+{
+ public class DrugType
+ {
+ public int TypeValue { get; set; }
+ public string TypeName { get; set; }
+ }
+}
diff --git a/DM_Weight/Port/PortUtil.cs b/DM_Weight/Port/PortUtil.cs
index 4eb50ce..a9afcac 100644
--- a/DM_Weight/Port/PortUtil.cs
+++ b/DM_Weight/Port/PortUtil.cs
@@ -970,12 +970,14 @@ namespace DM_Weight.Port
///
///
///
- public async Task OpenBox(int ColNo)
+ public async Task OpenBox(int DrawerNo, int ColNo)
{
- var vlock = 321;
+ int[] iNum = new int[] { 3, 2, 1 };
+ var colNo2 = ColNo % 3 > 0 ? (ColNo % 3) - 1 : 2;
+ var bColNo = iNum[colNo2];
decimal decolNO = (decimal)ColNo;
- var channel = Convert.ToInt32((DrawerNo * 10 + Math.Ceiling(decolNO % 3)).ToString(), 16);
- byte[] buffer = new byte[] { 0xaa, (byte)channel, 5,(byte)vlock, 0x00,0x00,0x00,0xee};
+ var channel = Convert.ToInt32((DrawerNo * 10 + Math.Ceiling(decolNO / 3)).ToString(), 16);
+ byte[] buffer = new byte[] { 0xaa, (byte)channel, 5,(byte)bColNo, 0x00,0x00,0x00,0xee};
canBusSerial.Write(buffer, 0, 8);
await Task.Delay(TimeSpan.FromMilliseconds(20));
}
@@ -984,7 +986,7 @@ namespace DM_Weight.Port
///
///
///
- public async Task GetBoxLockState(int ColNo)
+ public async Task OpenBoxState(int drawerNo, int ColNo)
{
decimal deColNo = (decimal)ColNo;
var channel = Convert.ToInt32((DrawerNo * 10 + Math.Ceiling(deColNo / 3)).ToString(), 16);
@@ -1135,10 +1137,65 @@ namespace DM_Weight.Port
{
decimal deColNo = colNo;
var channel = drawerNo * 10 + Math.Ceiling(deColNo / 3);
- var colNo2 = 321;
- byte[] buffer = new byte[] { 0xaa };
+ int[] iNum =new int[] { 3, 2, 1 };
+ var colNo2 = colNo%3>0?(colNo%3)-1:2;
+ var bColNo = iNum[colNo2];
+ byte[] buffer = new byte[] { 0xaa,(byte)channel,0x09,(byte)bColNo ,0xee};
canBusSerial.Write(buffer, 0, 8);
}
+ //刷新内容
+ public void ShowContentMethod(int drawerNo, int colNo)
+ {
+ var channel = drawerNo * 10 + Math.Ceiling((decimal)colNo % 3);
+ byte[] buffer = new byte[] { 0xaa, (byte)channel, 0x0c, 0x00, 0x00, 0x00, 0x00, 0xee};
+ canBusSerial.Write(buffer,0,8);
+ }
+ // 基础数据写入方法
+ public async void WriteChannelInfoMethod(int type,string content,int drawerNo,int colNo)
+ {
+ try
+ {
+ canBusSerial.DiscardInBuffer();
+ Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
+ byte[] contentBuf = Encoding.GetEncoding("gb2312").GetBytes(trim(content));
+ content = content.Substring(0, 10);
+ int channel = Convert.ToInt32((DrawerNo * 10 + Math.Ceiling((decimal)colNo / 3)).ToString(), 16);
+ int[] iNum = new int[] { 3, 2, 1 };
+ var colNo2 = colNo % 3 > 0 ? (colNo % 3) - 1 : 2;
+ var bColNo = iNum[colNo2]; if (contentBuf.Length % 2 != 0)
+ {
+ Array.Resize(ref contentBuf, contentBuf.Length + 1);
+ }
+ byte[] buffer = new byte[] { 0xaa, (byte)channel, (byte)colNo2, (byte)type, 0, 0, 0, 0xee };
+ canBusSerial.Write(buffer, 0, 8);
+ await Task.Delay(20);
+ buffer[4] = 1;
+ for (int i = 0; i < contentBuf.Length; i += 2)
+ {
+ buffer[5] = contentBuf[i];
+ buffer[6] = contentBuf[i + 1];
+ canBusSerial.Write(buffer, 0, 8);
+ await Task.Delay(20);
+ }
+ buffer[4] = 2;
+ buffer[5] = 0;
+ buffer[6] = 0;
+ canBusSerial.Write(buffer, 0, 8);
+ await Task.Delay(20);
+
+ }
+ catch (Exception ex)
+ {
+ _eventAggregator.GetEvent().Publish(new util.DeviceMsg()
+ {
+ EventType = util.EventType.OPENERROR,
+ WindowName = WindowName,
+ Message = $"2.4寸汉显屏异常{ex.Message}"
+ });
+ logger.Info($"2.4寸汉显屏异常:ex:{ex.Message}");
+ }
+ }
+
#endregion
#region 回收箱操作
diff --git a/DM_Weight/ViewModels/AccountWindowViewModel.cs b/DM_Weight/ViewModels/AccountWindowViewModel.cs
index bd1ba10..323697d 100644
--- a/DM_Weight/ViewModels/AccountWindowViewModel.cs
+++ b/DM_Weight/ViewModels/AccountWindowViewModel.cs
@@ -180,11 +180,38 @@ namespace DM_Weight.ViewModels
RequestData();
}
}
+ ///
+ /// 药品类型
+ ///
+ private List _drugTypeList = new List()
+ {
+ new DrugType{ TypeValue=1,TypeName="精一"},
+ new DrugType{TypeValue=2,TypeName="精二"}
+ };
+ public List? DrugTypeList
+ {
+ get => _drugTypeList;
+ set
+ {
+ SetProperty(ref _drugTypeList, value);
+ }
+ }
+
+ private DrugType? _drugType;
+ public DrugType? _DrugType
+ {
+ get => _drugType; set
+ {
+ SetProperty(ref _drugType, value);
+ RequestData();
+ }
+ }
+
//MachineRecordService _machineRecordService;
IEventAggregator _eventAggregator;
////private SqlSugarScope SqlSugarHelper.Db;
- public AccountWindowViewModel( IEventAggregator eventAggregator)
+ public AccountWindowViewModel(IEventAggregator eventAggregator)
{
//_machineRecordService = machineRecord;
////this.SqlSugarHelper.Db = sqlSugarScope;
@@ -194,7 +221,7 @@ namespace DM_Weight.ViewModels
void RequestData()
{
int totalCount = 0;
- AccountList = ReportAccountBook(StartDate, EndDate, AccountType == null ? 0 : AccountType.AccountTypeValue, DrugInfo == null ? "" : DrugInfo.DrugId.ToString() ?? "");
+ AccountList = ReportAccountBook(StartDate, EndDate, AccountType == null ? 0 : AccountType.AccountTypeValue, _DrugType == null ? 0 : _DrugType.TypeValue, DrugInfo == null ? "" : DrugInfo.DrugId.ToString() ?? "");
//for (int i = 0; i < accountList.Count; i++)
//{
// if (accountList[i].DrugInfo is null)
@@ -219,7 +246,7 @@ namespace DM_Weight.ViewModels
DrugInfos = list;
DrugInfo = list[0];
}
-
+
public long CurrentTimeMillis()
{
return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds;
@@ -229,8 +256,9 @@ namespace DM_Weight.ViewModels
///
public DelegateCommand DownloadOrderUser
{
- get => new DelegateCommand(() => {
- GridReportUtil.OrderUseReport(StartDate, EndDate, DrugInfo == null ? "" : DrugInfo.DrugId.ToString() ?? "");
+ get => new DelegateCommand(() =>
+ {
+ GridReportUtil.OrderUseReport(StartDate, EndDate, DrugInfo == null ? "" : DrugInfo.DrugId.ToString() ?? "");
});
}
@@ -293,7 +321,7 @@ namespace DM_Weight.ViewModels
{
}
- private List ReportAccountBook(DateTime? startDate, DateTime? endDate, int type, string drug_id = "")
+ private List ReportAccountBook(DateTime? startDate, DateTime? endDate, int type, int drugType, string drug_id = "")
{
DateTime? p_startDate = startDate ?? Convert.ToDateTime("2010-1-1");
DateTime? p_endDate = endDate ?? DateTime.Now.AddDays(1);
@@ -312,31 +340,35 @@ namespace DM_Weight.ViewModels
{
if (type == 1)
{
- SQL += " WHERE ac.add_quantity>0 ";
+ SQL += " AND ac.add_quantity>0 ";
}
if (type == 2)
{
- SQL += " WHERE ac.out_quantity>0 ";
+ SQL += " AND ac.out_quantity>0 ";
}
if (type == 3)
{
- SQL += " WHERE type=3 ";
+ SQL += " AND type=3 ";
}
if (type == 4)
{
- SQL += " WHERE type=4 ";
+ SQL += " AND type=4 ";
}
}
+ if (drugType > 0)
+ {
+ SQL += $" AND di.Drug_type={drugType}";
+ }
SQL += " ORDER BY ac.create_date desc,ac.drug_id";
//ChannelStocks = q.Select(it => { it.CheckQuantity = it.Quantity; return it; }).ToList();
List accountList = SqlSugarHelper.Db.SqlQueryable(SQL)
- //.AddParameters(new
- //{
- // machineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"
- //})
+ //.AddParameters(new
+ //{
+ // machineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"
+ //})
//.Select(it => new { o = new AccountModel(), i = new DrugInfo() })
//.Select(it=>new AccountModel())
//.Select("*") //让上面一行不生成sql
diff --git a/DM_Weight/ViewModels/BindingChannelDialogViewModel.cs b/DM_Weight/ViewModels/BindingChannelDialogViewModel.cs
index 6f06729..957f4fa 100644
--- a/DM_Weight/ViewModels/BindingChannelDialogViewModel.cs
+++ b/DM_Weight/ViewModels/BindingChannelDialogViewModel.cs
@@ -209,6 +209,13 @@ namespace DM_Weight.ViewModels
var SelectChannels = Channels.FindAll(item => item.IsSelected && item.Quantity == 0);
+ if(SelectChannels is null || SelectChannels.Count <= 0)
+ {
+ SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c"));
+ SnackbarMessageQueue.Enqueue("未选中库位或库位还存在药品无法绑定");
+ return;
+ }
+
if (SelectChannels.All(it => it.DrawerType != 1))
{
if (SelectChannels.Count == 1)
diff --git a/DM_Weight/Views/AccountWindow.xaml b/DM_Weight/Views/AccountWindow.xaml
index 54167ec..3c00696 100644
--- a/DM_Weight/Views/AccountWindow.xaml
+++ b/DM_Weight/Views/AccountWindow.xaml
@@ -63,13 +63,21 @@
SelectedItem="{Binding DrugInfo}"
DisplayMemberPath="DrugName"
/>-->
- -->
+