555 lines
19 KiB
C#
555 lines
19 KiB
C#
using DM_Weight.Models;
|
|
using DM_Weight.Port;
|
|
using DM_Weight.util;
|
|
using log4net;
|
|
using log4net.Repository.Hierarchy;
|
|
using Prism.Commands;
|
|
using Prism.Events;
|
|
using Prism.Mvvm;
|
|
using Prism.Regions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing.Printing;
|
|
using System.Linq;
|
|
using System.Security.Cryptography.Pkcs;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Media;
|
|
|
|
namespace DM_Weight.ViewModels
|
|
{
|
|
public class OpenBoxNewWindowViewModel : BindableBase, INavigationAware, IRegionMemberLifetime
|
|
{
|
|
private readonly ILog logger = LogManager.GetLogger(typeof(CheckOrderNewWindowViewModel));
|
|
private int _drawerType = -1;
|
|
|
|
public int DrawerType
|
|
{
|
|
get => _drawerType;
|
|
set => SetProperty(ref _drawerType, value);
|
|
}
|
|
//所选药箱号
|
|
private int _drawerNo = -1;
|
|
|
|
public int DrawerNo
|
|
{
|
|
get => _drawerNo;
|
|
set => SetProperty(ref _drawerNo, value);
|
|
}
|
|
//开名下药箱按钮的显示状态
|
|
private bool _selfEnable = false;
|
|
public bool SelfEnable { get => _selfEnable; set => SetProperty(ref _selfEnable, value); }
|
|
|
|
//名下药箱按钮显示内容
|
|
private string _selfContent= "打开手术间药箱";
|
|
public string SelfContent { get => _selfContent; set => SetProperty(ref _selfContent, value); }
|
|
|
|
|
|
//开公共药箱按钮的显示状态
|
|
private bool _publicEnable = true;
|
|
public bool PublicEnable { get => _publicEnable; set => SetProperty(ref _publicEnable, value); }
|
|
|
|
//公共药箱按钮显示内容
|
|
private string _publicContent;
|
|
public string PublicContent { get => _publicContent; set => SetProperty(ref _publicContent, value); }
|
|
|
|
//公共药箱状态
|
|
//private int _publicStatus = 0;
|
|
//public int PublicStatus { get => _publicStatus; set => SetProperty(ref _publicStatus, value); }
|
|
//名下药箱状态
|
|
private int _selfStatus = 0;
|
|
public int SelfStatus { get => _selfStatus; set => SetProperty(ref _selfStatus, value); }
|
|
//抽屉号列表
|
|
public static List<ChannelList> iList = new List<ChannelList>();
|
|
//第几个抽屉号
|
|
//public static int iNumber = 1;
|
|
private PortUtil _portUtil;
|
|
IEventAggregator _eventAggregator;
|
|
public OpenBoxNewWindowViewModel(PortUtil portUtil, IEventAggregator eventAggregator)
|
|
{
|
|
_portUtil = portUtil;
|
|
_eventAggregator = eventAggregator;
|
|
}
|
|
#region 抽屉按钮
|
|
private Brush _button1Color = Brushes.White;
|
|
public Brush Button1Color
|
|
{
|
|
get => _button1Color;
|
|
set => SetProperty(ref _button1Color, value);
|
|
}
|
|
private Brush _button2Color = Brushes.White;
|
|
public Brush Button2Color
|
|
{
|
|
get => _button2Color;
|
|
set => SetProperty(ref _button2Color, value);
|
|
}
|
|
private Brush _button3Color = Brushes.White;
|
|
public Brush Button3Color
|
|
{
|
|
get => _button3Color;
|
|
set => SetProperty(ref _button3Color, value);
|
|
}
|
|
private Brush _button4Color = Brushes.White;
|
|
public Brush Button4Color
|
|
{
|
|
get => _button4Color;
|
|
set => SetProperty(ref _button4Color, value);
|
|
}
|
|
private Brush _button5Color = Brushes.White;
|
|
public Brush Button5Color
|
|
{
|
|
get => _button5Color;
|
|
set => SetProperty(ref _button5Color, value);
|
|
}
|
|
private Brush _button6Color = Brushes.White;
|
|
public Brush Button6Color
|
|
{
|
|
get => _button6Color;
|
|
set => SetProperty(ref _button6Color, value);
|
|
}
|
|
private Brush _button7Color = Brushes.White;
|
|
public Brush Button7Color
|
|
{
|
|
get => _button7Color;
|
|
set => SetProperty(ref _button7Color, value);
|
|
}
|
|
private Brush _button8Color = Brushes.White;
|
|
public Brush Button8Color
|
|
{
|
|
get => _button8Color;
|
|
set => SetProperty(ref _button8Color, value);
|
|
}
|
|
private Brush _button9Color = Brushes.White;
|
|
public Brush Button9Color
|
|
{
|
|
get => _button9Color;
|
|
set => SetProperty(ref _button9Color, value);
|
|
}
|
|
private Brush _button10Color = Brushes.White;
|
|
public Brush Button10Color
|
|
{
|
|
get => _button10Color;
|
|
set => SetProperty(ref _button10Color, value);
|
|
}
|
|
private Brush _button11Color = Brushes.White;
|
|
public Brush Button11Color
|
|
{
|
|
get => _button11Color;
|
|
set => SetProperty(ref _button11Color, value);
|
|
}
|
|
private Brush _button12Color = Brushes.White;
|
|
public Brush Button12Color
|
|
{
|
|
get => _button12Color;
|
|
set => SetProperty(ref _button12Color, value);
|
|
}
|
|
private Brush _button13Color = Brushes.White;
|
|
public Brush Button13Color
|
|
{
|
|
get => _button13Color;
|
|
set => SetProperty(ref _button13Color, value);
|
|
}
|
|
private Brush _button14Color = Brushes.White;
|
|
public Brush Button14Color
|
|
{
|
|
get => _button14Color;
|
|
set => SetProperty(ref _button14Color, value);
|
|
}
|
|
private Brush _button15Color = Brushes.White;
|
|
public Brush Button15Color
|
|
{
|
|
get => _button15Color;
|
|
set => SetProperty(ref _button15Color, value);
|
|
}
|
|
private Brush _button16Color = Brushes.White;
|
|
public Brush Button16Color
|
|
{
|
|
get => _button16Color;
|
|
set => SetProperty(ref _button16Color, value);
|
|
}
|
|
private Brush _button17Color = Brushes.White;
|
|
public Brush Button17Color
|
|
{
|
|
get => _button17Color;
|
|
set => SetProperty(ref _button17Color, value);
|
|
}
|
|
private Brush _button18Color = Brushes.White;
|
|
public Brush Button18Color
|
|
{
|
|
get => _button18Color;
|
|
set => SetProperty(ref _button18Color, value);
|
|
}
|
|
|
|
private bool _button1Enable = false;
|
|
public bool Button1Enable
|
|
{
|
|
get => _button1Enable;
|
|
set => SetProperty(ref _button1Enable, value);
|
|
}
|
|
private bool _button2Enable = false;
|
|
public bool Button2Enable
|
|
{
|
|
get => _button2Enable;
|
|
set => SetProperty(ref _button2Enable, value);
|
|
}
|
|
private bool _button3Enable = false;
|
|
public bool Button3Enable
|
|
{
|
|
get => _button3Enable;
|
|
set => SetProperty(ref _button3Enable, value);
|
|
}
|
|
private bool _button4Enable = false;
|
|
public bool Button4Enable
|
|
{
|
|
get => _button4Enable;
|
|
set => SetProperty(ref _button4Enable, value);
|
|
}
|
|
private bool _button5Enable = false;
|
|
public bool Button5Enable
|
|
{
|
|
get => _button5Enable;
|
|
set => SetProperty(ref _button5Enable, value);
|
|
}
|
|
private bool _button6Enable = false;
|
|
public bool Button6Enable
|
|
{
|
|
get => _button6Enable;
|
|
set => SetProperty(ref _button6Enable, value);
|
|
}
|
|
private bool _button7Enable = false;
|
|
public bool Button7Enable
|
|
{
|
|
get => _button7Enable;
|
|
set => SetProperty(ref _button7Enable, value);
|
|
}
|
|
private bool _button8Enable = false;
|
|
public bool Button8Enable
|
|
{
|
|
get => _button8Enable;
|
|
set => SetProperty(ref _button8Enable, value);
|
|
}
|
|
private bool _button9Enable = false;
|
|
public bool Button9Enable
|
|
{
|
|
get => _button9Enable;
|
|
set => SetProperty(ref _button9Enable, value);
|
|
}
|
|
private bool _button10Enable = false;
|
|
public bool Button10Enable
|
|
{
|
|
get => _button10Enable;
|
|
set => SetProperty(ref _button10Enable, value);
|
|
}
|
|
private bool _button11Enable = false;
|
|
public bool Button11Enable
|
|
{
|
|
get => _button11Enable;
|
|
set => SetProperty(ref _button11Enable, value);
|
|
}
|
|
private bool _button12Enable = false;
|
|
public bool Button12Enable
|
|
{
|
|
get => _button12Enable;
|
|
set => SetProperty(ref _button12Enable, value);
|
|
}
|
|
private bool _button13Enable = false;
|
|
public bool Button13Enable
|
|
{
|
|
get => _button13Enable;
|
|
set => SetProperty(ref _button13Enable, value);
|
|
}
|
|
private bool _button14Enable = false;
|
|
public bool Button14Enable
|
|
{
|
|
get => _button14Enable;
|
|
set => SetProperty(ref _button14Enable, value);
|
|
}
|
|
private bool _button15Enable = false;
|
|
public bool Button15Enable
|
|
{
|
|
get => _button15Enable;
|
|
set => SetProperty(ref _button15Enable, value);
|
|
}
|
|
private bool _button16Enable = false;
|
|
public bool Button16Enable
|
|
{
|
|
get => _button16Enable;
|
|
set => SetProperty(ref _button16Enable, value);
|
|
}
|
|
private bool _button17Enable = false;
|
|
public bool Button17Enable
|
|
{
|
|
get => _button17Enable;
|
|
set => SetProperty(ref _button17Enable, value);
|
|
}
|
|
private bool _button18Enable = false;
|
|
public bool Button18Enable
|
|
{
|
|
get => _button18Enable;
|
|
set => SetProperty(ref _button18Enable, value);
|
|
}
|
|
|
|
#endregion
|
|
public bool KeepAlive => false;
|
|
//设置按钮颜色
|
|
private void SetBtnColor(int drawerNo)
|
|
{
|
|
switch (drawerNo)
|
|
{
|
|
case 1:
|
|
Button1Color = Brushes.Yellow;
|
|
break;
|
|
case 2:
|
|
Button2Color = Brushes.Yellow;
|
|
break;
|
|
case 3:
|
|
Button3Color = Brushes.Yellow;
|
|
break;
|
|
case 4:
|
|
Button4Color = Brushes.Yellow;
|
|
break;
|
|
case 5:
|
|
Button5Color = Brushes.Yellow;
|
|
break;
|
|
case 6:
|
|
Button6Color = Brushes.Yellow;
|
|
break;
|
|
case 7:
|
|
Button7Color = Brushes.Yellow;
|
|
break;
|
|
case 8:
|
|
Button8Color = Brushes.Yellow;
|
|
break;
|
|
case 9:
|
|
Button9Color = Brushes.Yellow;
|
|
break;
|
|
case 10:
|
|
Button10Color = Brushes.Yellow;
|
|
break;
|
|
case 11:
|
|
Button11Color = Brushes.Yellow;
|
|
break;
|
|
case 12:
|
|
Button12Color = Brushes.Yellow;
|
|
break;
|
|
case 13:
|
|
Button13Color = Brushes.Yellow;
|
|
break;
|
|
case 14:
|
|
Button14Color = Brushes.Yellow;
|
|
break;
|
|
case 15:
|
|
Button15Color = Brushes.Yellow;
|
|
break;
|
|
case 16:
|
|
Button16Color = Brushes.Yellow;
|
|
break;
|
|
case 17:
|
|
Button17Color = Brushes.Yellow;
|
|
break;
|
|
case 18:
|
|
Button18Color = Brushes.Yellow;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
//设置按钮可用状态
|
|
private void SetBtnEnable(int drawerNo)
|
|
{
|
|
switch (drawerNo)
|
|
{
|
|
case 1:
|
|
Button1Enable = true;
|
|
break;
|
|
case 2:
|
|
Button2Enable = true;
|
|
break;
|
|
case 3:
|
|
Button3Enable = true;
|
|
break;
|
|
case 4:
|
|
Button4Enable = true;
|
|
break;
|
|
case 5:
|
|
Button5Enable = true;
|
|
break;
|
|
case 6:
|
|
Button6Enable = true;
|
|
break;
|
|
case 7:
|
|
Button7Enable = true;
|
|
break;
|
|
case 8:
|
|
Button8Enable = true;
|
|
break;
|
|
case 9:
|
|
Button9Enable = true;
|
|
break;
|
|
case 10:
|
|
Button10Enable = true;
|
|
break;
|
|
case 11:
|
|
Button11Enable = true;
|
|
break;
|
|
case 12:
|
|
Button12Enable = true;
|
|
break;
|
|
case 13:
|
|
Button13Enable = true;
|
|
break;
|
|
case 14:
|
|
Button14Enable = true;
|
|
break;
|
|
case 15:
|
|
Button15Enable = true;
|
|
break;
|
|
case 16:
|
|
Button16Enable = true;
|
|
break;
|
|
case 17:
|
|
Button17Enable = true;
|
|
break;
|
|
case 18:
|
|
Button18Enable = true;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void RequestData()
|
|
{
|
|
List<ChannelList> chlList = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5").ToList();//.Select(cl => cl.BelongUser).First();
|
|
if (chlList != null && chlList.Count > 0)
|
|
{
|
|
for (int i = 0; i < chlList.Count; i++)
|
|
{
|
|
ChannelList chl = chlList[i];
|
|
if (Convert.ToDateTime(chl.EffDate).ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd"))
|
|
{
|
|
SetBtnColor(chl.DrawerNo);
|
|
}
|
|
//DrawerType== 1为公共药箱
|
|
if (chl.DrawerType == 1)
|
|
{
|
|
SetBtnEnable(chl.DrawerNo);
|
|
}
|
|
if (!string.IsNullOrEmpty(chl.BelongUser)&& chl.BelongUser == HomeWindowViewModel.Operator.UserBarcode)
|
|
{
|
|
SetBtnEnable(chl.DrawerNo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 选择药箱,打开药箱
|
|
/// </summary>
|
|
public DelegateCommand<string> UpdateDrawerNo
|
|
{
|
|
get => new DelegateCommand<string>(OpenBoxAction);
|
|
}
|
|
public async void OpenBoxAction(string strDrawerNo)
|
|
{
|
|
DrawerNo = Convert.ToInt32(strDrawerNo);
|
|
DrawerType = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5" && cl.DrawerNo == Convert.ToInt32(strDrawerNo)).Select(cl => cl.DrawerType).First();
|
|
SelfEnable = true;
|
|
//int listSelfState = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5")
|
|
// .WhereIf(cl => cl.BelongUser == HomeWindowViewModel.Operator.UserBarcode).Select(cl => cl.DrawerState).First();
|
|
|
|
int listDrawerState = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5" && cl.DrawerType == this.DrawerType)
|
|
.WhereIF(this.DrawerType == 0, cl => cl.BelongUser == HomeWindowViewModel.Operator.UserBarcode).Select(cl => cl.DrawerState).First();
|
|
if (DrawerType == 1) //公共药箱
|
|
{
|
|
if (listDrawerState == 0)
|
|
{
|
|
SelfContent = "还公共手术间药箱";
|
|
}
|
|
else
|
|
{
|
|
SelfContent = "取公共手术间药箱";
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
if (listDrawerState == 0)
|
|
{
|
|
SelfContent = "还名下手术间药箱";
|
|
}
|
|
else
|
|
{
|
|
SelfContent = "取名下手术间药箱";
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
public DelegateCommand<string> OpenBoxDelegate
|
|
{
|
|
get => new DelegateCommand<string>((DrawerType) =>
|
|
{
|
|
SearchBox();
|
|
}
|
|
);
|
|
}
|
|
private void SearchBox()
|
|
{
|
|
iList = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5" && cl.DrawerType == this.DrawerType)
|
|
.WhereIF(this.DrawerType == 0, cl => cl.BelongUser == HomeWindowViewModel.Operator.UserBarcode).ToList();
|
|
// .Select(cl => cl.DrawerNo).ToList();
|
|
if (iList.Count > 0)
|
|
{
|
|
//_portUtil.SpeakAsync("正在打开药箱");
|
|
//_portUtil.DrawerNo = iList[iNumber];
|
|
//iNumber++;
|
|
//_portUtil.OpenBox();
|
|
|
|
for (int i = 0; i < iList.Count; i++)
|
|
{
|
|
ChannelList channelList = iList[i];
|
|
//记录开药箱日志
|
|
SqlSugarHelper.Db.Insertable(new MachineRecord()
|
|
{
|
|
MachineId = "DM5",
|
|
DrawerNo = channelList.DrawerNo,
|
|
Operator = HomeWindowViewModel.Operator?.Id,
|
|
OperationTime = DateTime.Now,
|
|
Type = 55,
|
|
InvoiceId = $"打开{iList[i].DrawerNo}号手术间",
|
|
OptionType= SelfContent.Substring(0,1)=="取"? 0:1
|
|
}).ExecuteCommand();
|
|
//记录药箱打开时间
|
|
channelList.EffDate = DateTime.Now.ToString();
|
|
channelList.DrawerState = SelfContent.Substring(0, 1) == "取" ? 0 : 1;
|
|
SqlSugarHelper.Db.Updateable(channelList).UpdateColumns(it => new { it.EffDate, it.DrawerState }).ExecuteCommand();
|
|
|
|
_portUtil.SpeakAsync($"正在打开{channelList.DrawerNo}号手术间");
|
|
logger.Info($"正在打开{channelList.DrawerNo}号手术间");
|
|
ModbusHelper.GetInstance().OpenBoxDoor(channelList.DrawerNo - 1);
|
|
Thread.Sleep(1000);
|
|
}
|
|
|
|
SelfStatus = 0;
|
|
PublicEnable = true;
|
|
SelfEnable = true;
|
|
DrawerType = -1;
|
|
}
|
|
}
|
|
public void OnNavigatedTo(NavigationContext navigationContext)
|
|
{
|
|
RequestData();
|
|
}
|
|
|
|
public bool IsNavigationTarget(NavigationContext navigationContext)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public void OnNavigatedFrom(NavigationContext navigationContext)
|
|
{
|
|
}
|
|
}
|
|
}
|