添加药盒、标签显示屏指令

This commit is contained in:
maqiao 2024-07-18 09:21:59 +08:00
parent 17a6ddd0da
commit ae95b8c268
6 changed files with 141 additions and 23 deletions

View File

@ -60,7 +60,7 @@
<!--是否有冰箱抽屉0无1有一个2两个-->
<add key="hasFridge" value="1"/>
<add key="hasFridge" value="0"/>
<!-- 冰箱的串口号 -->
<add key="FridgePortPath" value="COM7" />

View File

@ -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; }
}
}

View File

@ -970,12 +970,14 @@ namespace DM_Weight.Port
/// </summary>
/// <param name="ColNo"></param>
/// <returns></returns>
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
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public async Task<byte[]> GetBoxLockState(int ColNo)
public async Task<byte[]> 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<PortUtilEvent>().Publish(new util.DeviceMsg()
{
EventType = util.EventType.OPENERROR,
WindowName = WindowName,
Message = $"2.4寸汉显屏异常{ex.Message}"
});
logger.Info($"2.4寸汉显屏异常ex:{ex.Message}");
}
}
#endregion
#region

View File

@ -180,11 +180,38 @@ namespace DM_Weight.ViewModels
RequestData();
}
}
/// <summary>
/// 药品类型
/// </summary>
private List<DrugType> _drugTypeList = new List<DrugType>()
{
new DrugType{ TypeValue=1,TypeName="精一"},
new DrugType{TypeValue=2,TypeName="精二"}
};
public List<DrugType>? 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
/// </summary>
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<AccountBookG2> ReportAccountBook(DateTime? startDate, DateTime? endDate, int type, string drug_id = "")
private List<AccountBookG2> 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<AccountBookG2> accountList = SqlSugarHelper.Db.SqlQueryable<AccountBookG2>(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

View File

@ -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)

View File

@ -63,13 +63,21 @@
SelectedItem="{Binding DrugInfo}"
DisplayMemberPath="DrugName"
/>-->
<ComboBox
<!--<ComboBox
Margin="6 0 6 0"
Grid.Column="2"
materialDesign:HintAssist.Hint="药品名称/拼音码/药品编码"
ItemsSource="{Binding DrugInfos}"
SelectedItem="{Binding DrugInfo}"
DisplayMemberPath="DrugName" IsEditable="True" IsTextSearchEnabled="False" KeyUp="ComboBox_KeyUp"
/>-->
<ComboBox
Margin="6 0 6 0"
Grid.Column="2"
materialDesign:HintAssist.Hint="药品类型"
ItemsSource="{Binding DrugTypeList}"
SelectedItem="{Binding _DrugType}"
DisplayMemberPath="TypeName" IsEditable="True" IsTextSearchEnabled="False" KeyUp="ComboBox_KeyUp"
/>
<ComboBox
Margin="12 0 0 0"