|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
using Microsoft.AspNetCore.Components.Forms;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.IdentityModel.Protocols;
|
|
|
|
|
using NVelocity.Util.Introspection;
|
|
|
|
|
using SlnMesnac.Business;
|
|
|
|
@ -30,6 +31,7 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
{
|
|
|
|
|
public class ExecuteViewModel : INotifyPropertyChanged
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<ExecuteViewModel> _logger;
|
|
|
|
|
public ObservableCollection<string> OrderCodeComboBoxItems { get; set; }
|
|
|
|
|
public ObservableCollection<string> PlanCodeComboBoxItems { get; set; }
|
|
|
|
|
public ObservableCollection<string> MaterialNameComboBoxItems { get; set; }
|
|
|
|
@ -39,16 +41,23 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
private List<ProdPLanInfo> prodPlanInfos;
|
|
|
|
|
private ProdPlanDetailService _prodPlanDetailService;
|
|
|
|
|
private IRecordStaffAttendanceService _recordStaffAttendanceService;
|
|
|
|
|
private IRecordStaffRealTimeService _recordStaffRealTimeService;
|
|
|
|
|
private IBaseStaffService _baseStaffService;
|
|
|
|
|
//private string StationCode;
|
|
|
|
|
private string DeviceCode;
|
|
|
|
|
private string ProcessCode;
|
|
|
|
|
public static bool isComplete = true;
|
|
|
|
|
public static string theStartTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//记录每个明细的开始时间
|
|
|
|
|
public static string intervalvalTime = "2023-11-11 00:00:00";
|
|
|
|
|
public static int stations = 0;
|
|
|
|
|
private string theOrderCode = "";
|
|
|
|
|
private ProdPLanInfo pLanInfo;
|
|
|
|
|
private ProdPLanInfo haveInfo;
|
|
|
|
|
private SerialPortBusiness _serialPortBusiness;
|
|
|
|
|
private string executeText = "待执行";
|
|
|
|
|
private int isSearch = 0;
|
|
|
|
|
public static string lastReportTime;
|
|
|
|
|
//public static string batchNums = "";//批次
|
|
|
|
|
|
|
|
|
|
#region 定义命令
|
|
|
|
|
/// <summary>
|
|
|
|
@ -75,6 +84,11 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
/// 执行命令
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ICommand ExecuteCommand { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 撤回命令
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ICommand WithdrawCommand { get; private set; }
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 定义委托
|
|
|
|
@ -132,10 +146,10 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
/// 工位
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string stationTextBlock;
|
|
|
|
|
public string StationTextBox
|
|
|
|
|
public string StationTextBox
|
|
|
|
|
{
|
|
|
|
|
get { return stationTextBlock; }
|
|
|
|
|
set { stationTextBlock = value; new PropertyChangedEventArgs(nameof(StationTextBox)); }
|
|
|
|
|
set { stationTextBlock = value; OnPropertyChanged("StationTextBox"); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -148,6 +162,19 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
set { prodPLanInfoDataGrid = value; OnPropertyChanged("ProdPLanInfoDataGrid"); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 工单计划选中行
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ProdPLanInfo _selectedRow;
|
|
|
|
|
public ProdPLanInfo SelectedRow
|
|
|
|
|
{
|
|
|
|
|
get { return _selectedRow; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_selectedRow = value; OnPropertyChanged(nameof(SelectedRow));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// DetailDataGrid
|
|
|
|
|
/// </summary>
|
|
|
|
@ -159,15 +186,15 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 选中行
|
|
|
|
|
/// 工单明细选中行
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ProdPLanInfo _selectedRow;
|
|
|
|
|
public ProdPLanInfo SelectedRow
|
|
|
|
|
public ProdPlanDetail _selectedDetialRow;
|
|
|
|
|
public ProdPlanDetail SelectedDetailRow
|
|
|
|
|
{
|
|
|
|
|
get { return _selectedRow; }
|
|
|
|
|
get { return _selectedDetialRow; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_selectedRow = value; OnPropertyChanged(nameof(SelectedRow));
|
|
|
|
|
_selectedDetialRow = value; OnPropertyChanged(nameof(SelectedDetailRow));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -194,11 +221,11 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 原料Text
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string materialCodeText;
|
|
|
|
|
public string MaterialCodeText
|
|
|
|
|
private string materialNameText;
|
|
|
|
|
public string MaterialNameText
|
|
|
|
|
{
|
|
|
|
|
get { return materialCodeText; }
|
|
|
|
|
set { materialCodeText = value; OnPropertyChanged("MaterialCodeText"); }
|
|
|
|
|
get { return materialNameText; }
|
|
|
|
|
set { materialNameText = value; OnPropertyChanged("MaterialNameText"); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -220,13 +247,25 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
get { return stationCodeText; }
|
|
|
|
|
set { stationCodeText = value; OnPropertyChanged("StationCodeText"); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 批次号
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string batchNumbers;
|
|
|
|
|
public string BatchNumbers
|
|
|
|
|
{
|
|
|
|
|
get { return batchNumbers; }
|
|
|
|
|
set { batchNumbers = value; OnPropertyChanged("BatchNumbers"); }
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public ExecuteViewModel()
|
|
|
|
|
{
|
|
|
|
|
_logger = App.ServiceProvider.GetService<ILogger<ExecuteViewModel>>();
|
|
|
|
|
_prodPlanInfoService = App.ServiceProvider.GetService<ProdPlanInfoService>();
|
|
|
|
|
_prodPlanDetailService = App.ServiceProvider.GetService<ProdPlanDetailService>();
|
|
|
|
|
_recordStaffAttendanceService = App.ServiceProvider.GetService<IRecordStaffAttendanceService>();
|
|
|
|
|
_recordStaffRealTimeService = App.ServiceProvider.GetService<IRecordStaffRealTimeService>();
|
|
|
|
|
_RfidHandleBusniess = App.ServiceProvider.GetService<RfidHandleBusniess>();
|
|
|
|
|
_baseStaffService = App.ServiceProvider.GetService<IBaseStaffService>();
|
|
|
|
|
_serialPortBusiness = App.ServiceProvider.GetService<SerialPortBusiness>();
|
|
|
|
@ -235,7 +274,7 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
.SetBasePath(System.AppContext.BaseDirectory)
|
|
|
|
|
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
|
|
|
|
|
IConfigurationRoot configuration = configurationBuilder.Build();
|
|
|
|
|
pLanInfo = _prodPlanInfoService.GetRecordStaffAttendancesByConditions("", "", "", "", "1").FirstOrDefault();
|
|
|
|
|
pLanInfo = _prodPlanInfoService.GetPlanInfoByConditions("", "", "", "", "1").FirstOrDefault();
|
|
|
|
|
Refresh(pLanInfo);
|
|
|
|
|
havePlanOnDuty();
|
|
|
|
|
// 从配置文件中获取ProductLineNameTextBlock的值
|
|
|
|
@ -246,6 +285,10 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
//};
|
|
|
|
|
//StationList = ConvertStringToList(StationCodes);
|
|
|
|
|
//RfidHandleBusniess.stationCode = StationCodes;
|
|
|
|
|
EmployeeLoginViewModel.TransmitStationNameAction += stationName =>
|
|
|
|
|
{
|
|
|
|
|
updateStationName(stationName);
|
|
|
|
|
};
|
|
|
|
|
DeviceCode = configuration.GetSection("AppConfig")["DeviceCode"];
|
|
|
|
|
ProcessCode = configuration.GetSection("AppConfig")["ProcessCode"];
|
|
|
|
|
HandoverCommand = new RelayCommand(Handover);
|
|
|
|
@ -253,12 +296,47 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
TechnologicalInformationCommand = new RelayCommand(TechnologicalInformation);
|
|
|
|
|
SearchCommand = new RelayCommand(Search);
|
|
|
|
|
ExecuteCommand = new RelayCommand(Execute);
|
|
|
|
|
WithdrawCommand = new RelayCommand(Withdraw);
|
|
|
|
|
ProductionReportViewModel.RefreshDelegateEvent += Refresh;
|
|
|
|
|
EmployeeLoginViewModel.TransmitUserDelegateEvent += ShowTeamMember;
|
|
|
|
|
//SerialPortBusiness.ReceivedBarcodeInfoEvent += HandleOrderCode;
|
|
|
|
|
MainWindowViewModel.TransferOrderCodeEvent += HandleOrderCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 撤回
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
|
|
private void Withdraw()
|
|
|
|
|
{
|
|
|
|
|
//BatchNumbers = batchNums;
|
|
|
|
|
MainWindowViewModel.wins = 2;
|
|
|
|
|
var removeConfirmWin = new RemoveConfirmWin();
|
|
|
|
|
removeConfirmWin.Owner = Application.Current.MainWindow;
|
|
|
|
|
removeConfirmWin.WindowStartupLocation = WindowStartupLocation.CenterOwner;
|
|
|
|
|
removeConfirmWin.ShowDialog();
|
|
|
|
|
if (RemoveConfirmViewModel.times == 1)
|
|
|
|
|
{
|
|
|
|
|
//当前正在执行的工单的单号和产量
|
|
|
|
|
string planCode = pLanInfo.PlanCode;
|
|
|
|
|
int batch = _selectedDetialRow.BatchNumber;
|
|
|
|
|
//删除planInfo对应产量
|
|
|
|
|
pLanInfo = _prodPlanInfoService.GetPlanInfoByConditions("", "", "", "", "1").FirstOrDefault();
|
|
|
|
|
double planNum = double.Parse(pLanInfo.CompleteAmount);
|
|
|
|
|
double detailNum = double.Parse(_selectedDetialRow.CompleteAmount);
|
|
|
|
|
pLanInfo.CompleteAmount = (planNum - detailNum).ToString();
|
|
|
|
|
_prodPlanInfoService.Update(pLanInfo);
|
|
|
|
|
//删除对应批次的明细和执行人信息
|
|
|
|
|
_databaseHandleBusniess.DeleteTheBatchDetailAndExecuter(planCode, batch);
|
|
|
|
|
//刷新
|
|
|
|
|
Refresh(pLanInfo);
|
|
|
|
|
}
|
|
|
|
|
MainWindowViewModel.wins = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否有计划正在执行
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void havePlanOnDuty()
|
|
|
|
|
{
|
|
|
|
|
haveInfo = _prodPlanInfoService.GetPlanInfoByConditions("", "", "", "", "1").FirstOrDefault();
|
|
|
|
@ -271,6 +349,15 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新工位名称
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="stationName"></param>
|
|
|
|
|
private void updateStationName(string stationName)
|
|
|
|
|
{
|
|
|
|
|
StationTextBox = EmployeeLoginViewModel.stationName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 换班弹窗
|
|
|
|
|
/// </summary>
|
|
|
|
@ -289,7 +376,7 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
{
|
|
|
|
|
if (RfidHandleBusniess.stationCode != "")
|
|
|
|
|
{
|
|
|
|
|
pLanInfo = _prodPlanInfoService.GetRecordStaffAttendancesByConditions("", "", "", RfidHandleBusniess.stationCode, "1").FirstOrDefault();
|
|
|
|
|
pLanInfo = _prodPlanInfoService.GetPlanInfoByConditions("", "", "", RfidHandleBusniess.stationCode, "1").FirstOrDefault();
|
|
|
|
|
if (pLanInfo != null)
|
|
|
|
|
{
|
|
|
|
|
MainWindowViewModel.wins = 3;
|
|
|
|
@ -297,8 +384,13 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
reportWin.Owner = Application.Current.MainWindow; // 设置父窗口为当前主窗口
|
|
|
|
|
reportWin.WindowStartupLocation = WindowStartupLocation.CenterScreen; // 让窗体出现在屏幕中央
|
|
|
|
|
reportWin.ShowDialog();//窗体出现后禁止后面的用户控件
|
|
|
|
|
Search();
|
|
|
|
|
Refresh(pLanInfo);
|
|
|
|
|
ShowTeamMember();
|
|
|
|
|
if (stations >= 3)
|
|
|
|
|
{
|
|
|
|
|
_databaseHandleBusniess.UpdateOrderInfoStatus(theOrderCode, "2");
|
|
|
|
|
}
|
|
|
|
|
MainWindowViewModel.wins = 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -337,7 +429,8 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void Search()
|
|
|
|
|
{
|
|
|
|
|
if (EmployeeLoginViewModel.isOnDuty == true)
|
|
|
|
|
var staffList = _recordStaffRealTimeService.Query().ToList();
|
|
|
|
|
if (staffList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
//在这里执行其他操作,可以通过InputText获取用户输入的信息
|
|
|
|
|
//Console.WriteLine("用户输入的信息:" + OrderCodeTextBox + PlanCodeTextBox + MaterialCodeTextBox);
|
|
|
|
@ -364,10 +457,13 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void HandleOrderCode(string orderCode)
|
|
|
|
|
{
|
|
|
|
|
theOrderCode = orderCode;
|
|
|
|
|
if (isComplete)
|
|
|
|
|
{
|
|
|
|
|
if (isSearch == 1)
|
|
|
|
|
{
|
|
|
|
|
//更新当前工单状态
|
|
|
|
|
_databaseHandleBusniess.UpdateOrderInfoStatus(orderCode,"1");
|
|
|
|
|
//判断当前工位的工单编号是否存在
|
|
|
|
|
var plan = _prodPlanInfoService.GetProdPLanInfoByOrderCode(RfidHandleBusniess.stationCode, orderCode);
|
|
|
|
|
if (plan == null)//不存在,就在生产工单表中新增一条当前工位的订单,且执行状态改为4,重新检索,并高亮这条工单,执行按钮可用
|
|
|
|
@ -393,10 +489,10 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
}
|
|
|
|
|
Search();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("请先检索工单!");
|
|
|
|
|
}
|
|
|
|
|
//else
|
|
|
|
|
//{
|
|
|
|
|
// MessageBox.Show("请先检索工单!");
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -415,33 +511,43 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
{
|
|
|
|
|
if (isComplete)//判断是否完成,未完成不能执行其他工单
|
|
|
|
|
{
|
|
|
|
|
// 将当前记录存为实体,可以通过parameter获取当前记录的信息
|
|
|
|
|
string orderCode = _selectedRow.OrderCode.ToString();
|
|
|
|
|
string planCode = _selectedRow.PlanCode.ToString();
|
|
|
|
|
pLanInfo = _prodPlanInfoService.GetRecordStaffAttendancesByConditions(orderCode, planCode, "", "", "0").First();
|
|
|
|
|
RecordStaffAttendance currentRecord = _recordStaffAttendanceService.GetLastestOnRecord();
|
|
|
|
|
BaseStaffInfo staffInfo = _baseStaffService.GetMonitorByTeamCode(currentRecord.TeamCode);
|
|
|
|
|
RecordStaffAttendance nextRecord = _recordStaffAttendanceService.GetLastestOffRecord();
|
|
|
|
|
// 向detail表里插入一条数据
|
|
|
|
|
ProdPlanDetail prodPlanDetail = new ProdPlanDetail
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
PlanCode = pLanInfo.PlanCode,
|
|
|
|
|
MaterialCode = pLanInfo.MaterialCode,
|
|
|
|
|
PlanAmount = pLanInfo.PlanAmount,
|
|
|
|
|
CompleteAmount = pLanInfo.CompleteAmount,
|
|
|
|
|
BeginTime = DateTime.Now.ToString(),
|
|
|
|
|
CurrentStaffId = staffInfo.StaffId
|
|
|
|
|
//NextStaffId = nextRecord.StaffId,
|
|
|
|
|
};
|
|
|
|
|
_prodPlanDetailService.Insert(prodPlanDetail);
|
|
|
|
|
//按钮文字变成执行中并锁定,其他的订单执行按钮也禁用
|
|
|
|
|
pLanInfo.BeginTime = DateTime.Now.ToString();
|
|
|
|
|
pLanInfo.PlanStatus = "1";
|
|
|
|
|
_prodPlanInfoService.Update(pLanInfo);
|
|
|
|
|
Search();
|
|
|
|
|
//查明细表显示出来
|
|
|
|
|
Refresh(pLanInfo);
|
|
|
|
|
isComplete = false;
|
|
|
|
|
// 将当前记录存为实体,可以通过parameter获取当前记录的信息
|
|
|
|
|
string orderCode = _selectedRow.OrderCode.ToString();
|
|
|
|
|
string planCode = _selectedRow.PlanCode.ToString();
|
|
|
|
|
pLanInfo = _prodPlanInfoService.GetRecordStaffAttendancesByConditions(orderCode, planCode, "", "", "0").First();
|
|
|
|
|
//RecordStaffAttendance currentRecord = _recordStaffAttendanceService.GetLastestOnRecord();
|
|
|
|
|
//BaseStaffInfo staffInfo = _baseStaffService.GetMonitorByTeamCode(currentRecord.TeamCode);
|
|
|
|
|
RecordStaffAttendance nextRecord = _recordStaffAttendanceService.GetLastestOffRecord();
|
|
|
|
|
// 向detail表里插入一条数据
|
|
|
|
|
if (pLanInfo.CompleteAmount == "0.00")
|
|
|
|
|
{
|
|
|
|
|
ProdPlanDetail prodPlanDetail = new ProdPlanDetail
|
|
|
|
|
{
|
|
|
|
|
PlanCode = pLanInfo.PlanCode,
|
|
|
|
|
MaterialCode = pLanInfo.MaterialCode,
|
|
|
|
|
PlanAmount = pLanInfo.PlanAmount,
|
|
|
|
|
CompleteAmount = pLanInfo.CompleteAmount,
|
|
|
|
|
BeginTime = DateTime.Now.ToString(),
|
|
|
|
|
//CurrentStaffId = staffInfo.StaffId
|
|
|
|
|
//NextStaffId = nextRecord.StaffId,
|
|
|
|
|
};
|
|
|
|
|
_prodPlanDetailService.Insert(prodPlanDetail);
|
|
|
|
|
}
|
|
|
|
|
//按钮文字变成执行中并锁定,其他的订单执行按钮也禁用
|
|
|
|
|
//pLanInfo.BeginTime = DateTime.Now.ToString();
|
|
|
|
|
pLanInfo.PlanStatus = "1";
|
|
|
|
|
_prodPlanInfoService.Update(pLanInfo);
|
|
|
|
|
Search();
|
|
|
|
|
//查明细表显示出来
|
|
|
|
|
Refresh(pLanInfo);
|
|
|
|
|
isComplete = false;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError("执行异常", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -461,7 +567,7 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
var planDetail = planDetails.FirstOrDefault();
|
|
|
|
|
PlanCodeText = planDetail.PlanCode;
|
|
|
|
|
OrderCodeText = pLanInfo.OrderCode;
|
|
|
|
|
MaterialCodeText = planDetail.MaterialCode;
|
|
|
|
|
MaterialNameText = pLanInfo.MaterialName;
|
|
|
|
|
StationCodeText = pLanInfo.StationCode;
|
|
|
|
|
System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () =>
|
|
|
|
|
{
|
|
|
|
|