563 lines
23 KiB
C#
563 lines
23 KiB
C#
using DM_Weight.Finger;
|
|
using DM_Weight.Models;
|
|
using DM_Weight.msg;
|
|
using DM_Weight.Port;
|
|
using DM_Weight.util;
|
|
using log4net;
|
|
using log4net.Core;
|
|
using Prism.Commands;
|
|
using Prism.Events;
|
|
using Prism.Mvvm;
|
|
using Prism.Regions;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Configuration;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DM_Weight.ViewModels
|
|
{
|
|
public class ChangeShiftsWindowViewModel : BindableBase, IRegionMemberLifetime, IConfirmNavigationRequest
|
|
{
|
|
private readonly ILog logger = LogManager.GetLogger(typeof(LoginWindowViewModel));
|
|
|
|
//交班人发药人用户名
|
|
private string jiaoFaUsername = App.CurrentFaUserList.UserName ?? "";
|
|
public string JiaoFaUsername { get => jiaoFaUsername; set { SetProperty(ref jiaoFaUsername, value); } }
|
|
|
|
//交班人发药人密码
|
|
private string jiaoFaPassword;
|
|
public string JiaoFaPassword { get => jiaoFaPassword; set { SetProperty(ref jiaoFaPassword, value); } }
|
|
|
|
//交班人审核人用户名
|
|
private string jiaoShenUsername = App.CurrentShenUserList.UserName ?? "";
|
|
public string JiaoShenUsername { get => jiaoShenUsername; set { SetProperty(ref jiaoShenUsername, value); } }
|
|
|
|
//交班人审核人密码
|
|
private string jiaoShenPassword;
|
|
public string JiaoShenPassword { get => jiaoShenPassword; set { SetProperty(ref jiaoShenPassword, value); } }
|
|
|
|
//接班人发药人用户名
|
|
private string jieFaUsername;
|
|
public string JieFaUsername { get => jieFaUsername; set { SetProperty(ref jieFaUsername, value); } }
|
|
|
|
//接班人发药人密码
|
|
private string jieFaPassword;
|
|
public string JieFaPassword { get => jieFaPassword; set { SetProperty(ref jieFaPassword, value); } }
|
|
|
|
//接班人审核人用户名
|
|
private string jieShenUsername;
|
|
public string JieShenUsername { get => jieShenUsername; set { SetProperty(ref jieShenUsername, value); } }
|
|
|
|
//接班人审核人密码
|
|
private string jieShenPassword;
|
|
public string JieShenPassword { get => jieShenPassword; set { SetProperty(ref jieShenPassword, value); } }
|
|
|
|
//接班人发药人
|
|
public UserList Operator { get; set; }
|
|
//接班人审核人
|
|
public UserList Reviewer { get; set; }
|
|
|
|
private Boolean _loginBtnEnable = true;
|
|
public Boolean LoginBtnEnable { get { return _loginBtnEnable; } set { SetProperty(ref _loginBtnEnable, value); } }
|
|
|
|
private string firstLogin = ConfigurationManager.AppSettings["firstLogin"]?.ToString() ?? "operator";
|
|
|
|
//交班确认按钮是否可用
|
|
private bool _jieBanOk = true;
|
|
public bool JieBanOk { get => _jieBanOk; set { SetProperty(ref _jieBanOk, value); } }
|
|
|
|
|
|
//接班确认按钮是否可用
|
|
private bool _jiaoBanOk = true;
|
|
public bool JiaoBanOk { get => _jiaoBanOk; set { SetProperty(ref _jiaoBanOk, value); } }
|
|
|
|
|
|
private PortUtil _portUtil;
|
|
IRegionManager _regionManager;
|
|
IEventAggregator _eventAggregator;
|
|
public bool KeepAlive => false;
|
|
|
|
private bool _fingerMsg;
|
|
|
|
public bool FingerMsg
|
|
{
|
|
get => _fingerMsg;
|
|
set => SetProperty(ref _fingerMsg, value);
|
|
}
|
|
|
|
public ChangeShiftsWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, PortUtil portUtil)
|
|
{
|
|
_portUtil = portUtil;
|
|
_regionManager = regionManager;
|
|
_eventAggregator = eventAggregator;
|
|
}
|
|
|
|
#region 交班确认按钮
|
|
|
|
private bool JiaoBanFYRFlag = false; //交班发药人flag
|
|
private bool JiaoBanSHRFlag = false; //交班审核人flag
|
|
public DelegateCommand JiaobanCommand => new DelegateCommand(JiaoBanAction);
|
|
private void JiaoBanAction()
|
|
{
|
|
if (!string.IsNullOrEmpty(JiaoFaUsername) && !string.IsNullOrEmpty(JiaoFaPassword))
|
|
{
|
|
JiaoBanFYRFlag = ChangeShiftsLogin(JiaoFaUsername.Trim(), JiaoFaPassword.Trim());
|
|
}
|
|
else if (!string.IsNullOrEmpty(JiaoShenUsername) && !string.IsNullOrEmpty(JiaoShenPassword))
|
|
{
|
|
JiaoBanSHRFlag = ChangeShiftsLogin(JiaoShenUsername.Trim(), JiaoShenPassword.Trim());
|
|
}
|
|
else
|
|
{
|
|
//提示:请输入交班人中发药人或审核人的用户名密码
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = "请输入交班人中发药人或审核人的用户名密码",
|
|
Type = MsgType.ERROR
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
}
|
|
if (JiaoBanFYRFlag || JiaoBanSHRFlag)
|
|
{
|
|
JiaoBanOk = false;
|
|
}
|
|
}
|
|
#endregion 交班确认按钮
|
|
|
|
#region 接班确认按钮
|
|
private bool JieBanFYRFlag = false; //接班发药人flag
|
|
private bool JieBanSHRFlag = false; //接班审核人flag
|
|
public DelegateCommand JiebanCommand => new DelegateCommand(JiebanAction);
|
|
private void JiebanAction()
|
|
{
|
|
if (!string.IsNullOrEmpty(JieFaUsername) && !string.IsNullOrEmpty(JieFaPassword))
|
|
{
|
|
ChangeShiftsForJieLogin(JieFaUsername.Trim(), JieFaPassword.Trim());
|
|
}
|
|
else if (!string.IsNullOrEmpty(JieShenUsername) && !string.IsNullOrEmpty(JieShenPassword))
|
|
{
|
|
ChangeShiftsForJieLogin(JieShenUsername.Trim(), JieShenPassword.Trim());
|
|
}
|
|
else
|
|
{
|
|
//提示:请输入接班人中发药人或审核人的用户名密码
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = "请输入接班人中发药人或审核人的用户名密码",
|
|
Type = MsgType.ERROR
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
}
|
|
if (JieBanFYRFlag || JieBanSHRFlag)
|
|
{
|
|
JieBanOk = false;
|
|
}
|
|
}
|
|
#endregion 接班确认按钮
|
|
|
|
#region 清空按钮
|
|
public DelegateCommand ClearOneCommand => new DelegateCommand(ClearAction);
|
|
private void ClearAction()
|
|
{
|
|
JiaoFaPassword = string.Empty;
|
|
JiaoShenPassword = string.Empty;
|
|
}
|
|
#endregion
|
|
|
|
#region 接班人清空按钮
|
|
public DelegateCommand ClearTwoCommand => new DelegateCommand(ClearTwoAction);
|
|
private void ClearTwoAction()
|
|
{
|
|
JieFaUsername = string.Empty;
|
|
JieFaPassword = string.Empty;
|
|
JieShenUsername = string.Empty;
|
|
JieShenPassword = string.Empty;
|
|
}
|
|
#endregion
|
|
|
|
#region 确认交接
|
|
public DelegateCommand ShiftsCommand => new DelegateCommand(ShiftsAction);
|
|
private void ShiftsAction()
|
|
{
|
|
//1验证交班人与接班人是否都已登录验证2写交接信息
|
|
if ((JiaoBanFYRFlag || JiaoBanSHRFlag) && (JieBanFYRFlag || JieBanSHRFlag))
|
|
{
|
|
//保存交接班信息(查询当前值班人的最后一条交接班信息(如有则修改状态,没有则插入一条)并写入一条接班人信息)
|
|
var f = SqlSugarHelper.Db.UseTran(() =>
|
|
{
|
|
List<HkcChangeShifts> listHkcChangeShifts = SqlSugarHelper.Db.Queryable<HkcChangeShifts>()
|
|
.Where(cs => cs.State == "0")
|
|
.WhereIF(App.CurrentFaUserList != null && !string.IsNullOrEmpty(App.CurrentFaUserList.UserName), cs => cs.FromOperator == App.CurrentFaUserList.UserName)
|
|
.WhereIF(App.CurrentShenUserList != null && !string.IsNullOrEmpty(App.CurrentShenUserList.UserName), cs => cs.FromRviewer == App.CurrentShenUserList.UserName)
|
|
.OrderByDescending(cs => cs.OptState)
|
|
.ToList();
|
|
|
|
//List<MachineRecord> listMachineRecord=SqlSugarHelper.Db.Queryable<MachineRecord>()
|
|
//.Where(m=>)
|
|
|
|
if (listHkcChangeShifts != null && listHkcChangeShifts.Count > 0)
|
|
{
|
|
//存在则修改,不存在则插入一条
|
|
SqlSugarHelper.Db.Updateable(new HkcChangeShifts()
|
|
{
|
|
Id = listHkcChangeShifts[0].Id,
|
|
ToOperator = Operator == null ? "" : Operator.UserName,
|
|
ToReviewer = Reviewer == null ? "" : Reviewer.UserName,
|
|
State = "1",
|
|
OptState = "1",
|
|
ToDate = DateTime.Now
|
|
}).UpdateColumns(it => new { it.ToOperator, it.ToReviewer, it.State, it.OptState,it.ToDate }).WhereColumns(it => new { it.Id }).ExecuteCommand();
|
|
}
|
|
else
|
|
{
|
|
SqlSugarHelper.Db.Insertable(new HkcChangeShifts()
|
|
{
|
|
FromOperator = App.CurrentFaUserList.UserName,
|
|
FromRviewer = App.CurrentShenUserList.UserName,
|
|
ToOperator = Operator == null ? "" : Operator.UserName,
|
|
ToReviewer = Reviewer == null ? "" : Reviewer.UserName,
|
|
State = "1",
|
|
OptState = "0",
|
|
OptDate = DateTime.Now
|
|
}).ExecuteCommand();
|
|
|
|
}
|
|
SqlSugarHelper.Db.Insertable(new HkcChangeShifts()
|
|
{
|
|
FromOperator = App.CurrentFaUserList.UserName,
|
|
FromRviewer = App.CurrentShenUserList.UserName,
|
|
State = "0",
|
|
OptState = "0",
|
|
OptDate = DateTime.Now,
|
|
ToDate = DateTime.Now
|
|
}).ExecuteCommand();
|
|
return true;
|
|
});
|
|
if (f.Data)
|
|
{
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = "交接班操作完成!",
|
|
Type = MsgType.SUCCESS,
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
}
|
|
if (!f.IsSuccess)
|
|
{
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = "交接班操作失败!",
|
|
Type = MsgType.ERROR,
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
}
|
|
}
|
|
}
|
|
#endregion 确认交接
|
|
private NavigationParameters keys = new NavigationParameters();
|
|
bool ChangeShiftsLogin(string userName, string passWord)
|
|
{
|
|
LoginBtnEnable = false;
|
|
if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(passWord))
|
|
{
|
|
{
|
|
UserList userList = SqlSugarHelper.Db.Queryable<UserList>()
|
|
.Includes<RoleDm>(u => u.Role)
|
|
.InnerJoin<RoleDm>((u, r) => u.RoleId == r.Id)
|
|
.First(u => u.UserName == userName && ConfigurationManager.AppSettings["machineId"].ToString().Equals(u.MachineId));
|
|
|
|
if (userList == null)
|
|
{
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = "无此用户",
|
|
Type = MsgType.ERROR
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
userName = "";
|
|
passWord = "";
|
|
return false;
|
|
}
|
|
else if (userList.Role == null)
|
|
{
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = "用户还未设置权限,请联系管理员",
|
|
Type = MsgType.ERROR
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
userName = "";
|
|
passWord = "";
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
if (userList.PassWord == MD5.GetMD5Hash(passWord))
|
|
{
|
|
|
|
if (userList.UserName == App.CurrentShenUserList.UserName)
|
|
{
|
|
//交班人 指纹验证发药人成功
|
|
JiaoBanFYRFlag = true;
|
|
}
|
|
else if (userList.UserName == App.CurrentFaUserList.UserName)
|
|
{
|
|
//交班人 指纹验证审核人成功
|
|
JiaoBanSHRFlag = true;
|
|
}
|
|
else
|
|
{
|
|
//接班人登录
|
|
SetUser(userList);
|
|
}
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = "密码错误",
|
|
Type = MsgType.ERROR
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
passWord = "";
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = "请输入账号或密码",
|
|
Type = MsgType.ERROR
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
return false;
|
|
}
|
|
//LoginBtnEnable = true;
|
|
}
|
|
|
|
void ChangeShiftsForJieLogin(string userName, string passWord)
|
|
{
|
|
LoginBtnEnable = false;
|
|
if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(passWord))
|
|
{
|
|
{
|
|
UserList userList = SqlSugarHelper.Db.Queryable<UserList>()
|
|
.Includes<RoleDm>(u => u.Role)
|
|
.InnerJoin<RoleDm>((u, r) => u.RoleId == r.Id)
|
|
.First(u => u.UserName == userName && ConfigurationManager.AppSettings["machineId"].ToString().Equals(u.MachineId));
|
|
|
|
if (userList == null)
|
|
{
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = "无此用户",
|
|
Type = MsgType.ERROR
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
userName = "";
|
|
passWord = "";
|
|
}
|
|
else if (userList.Role == null)
|
|
{
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = "用户还未设置权限,请联系管理员",
|
|
Type = MsgType.ERROR
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
userName = "";
|
|
passWord = "";
|
|
}
|
|
else
|
|
{
|
|
if (userList.PassWord == MD5.GetMD5Hash(passWord))
|
|
{
|
|
//接班人登录
|
|
SetUser(userList);
|
|
}
|
|
else
|
|
{
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = "密码错误",
|
|
Type = MsgType.ERROR
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
passWord = "";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = "请输入账号或密码",
|
|
Type = MsgType.ERROR
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
}
|
|
//LoginBtnEnable = true;
|
|
}
|
|
void ChangeShiftsLoginEvent(FingerprintMsg msg)
|
|
{
|
|
logger.Info(msg.ToString());
|
|
if (msg.Message.Equals("CONNECT"))
|
|
{
|
|
FingerMsg = !msg.Result;
|
|
}
|
|
if (LoginBtnEnable)
|
|
{
|
|
if (msg.Message.Equals("LOGIN"))
|
|
{
|
|
UserList userList = SqlSugarHelper.Db.Queryable<UserList>()
|
|
.Includes<RoleDm>(u => u.Role)
|
|
.First(u => u.Id == msg.Id);
|
|
|
|
if (userList == null)
|
|
{
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = "无此用户",
|
|
Type = MsgType.ERROR
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
//Username = "";
|
|
//Password = "";
|
|
}
|
|
else if (userList.Role == null)
|
|
{
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = "用户还未设置权限,请联系管理员",
|
|
Type = MsgType.ERROR
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
//Username = "";
|
|
//Password = "";
|
|
}
|
|
else
|
|
{
|
|
if (userList.UserName == App.CurrentShenUserList.UserName)
|
|
{
|
|
//交班人 指纹验证发药人成功
|
|
JiaoBanFYRFlag = true;
|
|
}
|
|
else if (userList.UserName == App.CurrentFaUserList.UserName)
|
|
{
|
|
//交班人 指纹验证审核人成功
|
|
JiaoBanSHRFlag = true;
|
|
}
|
|
else
|
|
{
|
|
//接班人登录
|
|
SetUser(userList);
|
|
}
|
|
if (JiaoBanFYRFlag || JiaoBanSHRFlag)
|
|
{
|
|
JiaoBanOk = false;
|
|
}
|
|
if (JieBanFYRFlag || JieBanSHRFlag)
|
|
{
|
|
JieBanOk = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void SetUser(UserList user)
|
|
{
|
|
// 双人登录模式
|
|
{
|
|
// 如果已经录入了发药人,已经有一个用户登录
|
|
if (keys.ContainsKey("operator"))
|
|
{
|
|
if (keys.GetValue<UserList>("operator").Id != user.Id)
|
|
{
|
|
keys.Add("reviewer", user);
|
|
Reviewer = user;
|
|
JieBanFYRFlag = true;
|
|
//RaisePropertyChanged("Reviewer");
|
|
}
|
|
else
|
|
{
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = "该发药人账号已登录,请输入不同账号",
|
|
Type = MsgType.ERROR
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
}
|
|
}
|
|
// 如果已经录入了审核人, 已经有一个用户登录
|
|
else if (keys.ContainsKey("reviewer"))
|
|
{
|
|
if (keys.GetValue<UserList>("reviewer").Id != user.Id)
|
|
{
|
|
keys.Add("operator", user);
|
|
Operator = user;
|
|
//RaisePropertyChanged("Operator");
|
|
JieBanSHRFlag = true;
|
|
}
|
|
else
|
|
{
|
|
AlertMsg alertMsg = new AlertMsg
|
|
{
|
|
Message = "该审核人账号已登录,请输入不同账号",
|
|
Type = MsgType.ERROR
|
|
};
|
|
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
}
|
|
}
|
|
// 第一个用户登录
|
|
else
|
|
{
|
|
if (firstLogin.Equals("operator"))
|
|
{
|
|
keys.Add("operator", user);
|
|
Operator = user;
|
|
JieBanFYRFlag = true;
|
|
}
|
|
else
|
|
{
|
|
keys.Add("reviewer", user);
|
|
Reviewer = user;
|
|
JieBanSHRFlag = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
|
|
{
|
|
continuationCallback(true);
|
|
}
|
|
|
|
public void OnNavigatedTo(NavigationContext navigationContext)
|
|
{
|
|
FingerMsg = false;// !_fingerprintUtil.bIsConnected;
|
|
_eventAggregator.GetEvent<FingerprintEvent>().Subscribe(ChangeShiftsLoginEvent);
|
|
}
|
|
|
|
public bool IsNavigationTarget(NavigationContext navigationContext)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public void OnNavigatedFrom(NavigationContext navigationContext)
|
|
{
|
|
_eventAggregator.GetEvent<FingerprintEvent>().Unsubscribe(ChangeShiftsLoginEvent);
|
|
}
|
|
}
|
|
}
|