添加计划号递增功能

dev
liulb@mesnac.com 1 year ago
parent 2c727f8cd4
commit 8ed2ff0f21

@ -23,6 +23,9 @@ using NPOI.SS.Formula.Functions;
using log4net;
using Aucma.Core.HwPLc;
using static Npgsql.Replication.PgOutput.Messages.RelationMessage;
using System.Text;
using System.Threading;
using Admin.Core.Service;
/*
*
*/
@ -215,12 +218,13 @@ namespace Aucma.Core.SheetMetal.ViewModels
var list = _taskExecutionPlanInfoServices.QueryAsync(x => x.IsFlag == 0 && x.ProductLineCode == stationCode && x.BeginTime > view.StartTime || x.ExecuteStatus == 2).Result;
if (list == null) return Task.CompletedTask;
var execList = list.OrderByDescending(d => d.ExecuteOrder);
int i = 1;
string planType = string.Empty;
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
PlanInfoDataGrid.Clear();
var execList = list.OrderByDescending(d => d.ExecuteOrder);
foreach (var item in execList)
{
TaskExecModel task = new TaskExecModel();
@ -303,7 +307,7 @@ namespace Aucma.Core.SheetMetal.ViewModels
private async Task MoveUp(string Id)
{
string stationCode = Appsettings.app("StationInfo", "StationCode");
bool result = await _taskExecutionPlanInfoServices.PlanMoveUp(Id, stationCode);
bool result = await _taskExecutionPlanInfoServices.PlanMoveDown(Id, stationCode);
if (result)
{
await LoadData();
@ -319,10 +323,9 @@ namespace Aucma.Core.SheetMetal.ViewModels
private async Task MoveDown(string Id)
{
string stationCode = Appsettings.app("StationInfo", "StationCode");
bool result = await _taskExecutionPlanInfoServices.PlanMoveDown(Id, stationCode);
bool result = await _taskExecutionPlanInfoServices.PlanMoveUp(Id, stationCode);
if (result)
{
PlanInfoDataGrid.Clear();
await LoadData();
}
}
@ -338,31 +341,110 @@ namespace Aucma.Core.SheetMetal.ViewModels
MessageBoxResult msg = MessageBox.Show("确定要删除吗?", "系统提醒", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);
if (MessageBoxResult.Yes == msg)
{
int id = Convert.ToInt32(Id);
ExecutePlanInfo executionPlanInfo= _taskExecutionPlanInfoServices.FirstAsync(s => s.ObjId == id).Result;
if (executionPlanInfo.PlanAmount== executionPlanInfo.CompleteAmount)
{
MessageBox.Show("执行计划已经完成,不可以删除!", "系统信息");
return;
}
executionPlanInfo.IsFlag = 1;
bool result = await _taskExecutionPlanInfoServices.UpdateAsync(executionPlanInfo);
if (result)
try
{
//下发该计划取消PLC任务
//var obj_sidePanel = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("SidePanelPlc"));
//var obj_backPanel = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("BackPanelPLC"));
//obj_backPanel.plc.WriteInt16("D4021","5");//下传5为计划结束
int id = Convert.ToInt32(Id);
ExecutePlanInfo executionPlanInfo = _taskExecutionPlanInfoServices.FirstAsync(s => s.ObjId == id).Result;
PlanInfoDataGrid.Clear();
await LoadData();
MessageBox.Show("执行计划删除成功", "系统信息");
if (executionPlanInfo.PlanAmount == executionPlanInfo.CompleteAmount)
{
MessageBox.Show("执行计划已经完成,不可以删除!", "系统信息");
return;
}
if (executionPlanInfo.PlanType == 1)
{
var obj_sidePanel = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("SidePanelPlc"));
var obj_backPanel = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("BackPanelPLC"));
string taskSideCode = this.GetSidePlanCode(obj_sidePanel);
string taskBackCode = this.GetBackPlanCode(obj_backPanel);
if (taskSideCode.Equals(executionPlanInfo.TaskCode))
{
obj_sidePanel.plc.WriteInt16("D6021", "5");
}
if (taskBackCode.Equals(executionPlanInfo.TaskCode))
{
obj_backPanel.plc.WriteInt16("D4021", "5");
}
var backPanelList = _recordBackPanelComplateServices.QueryAsync(d => d.PlanCode.Equals(executionPlanInfo.TaskCode)).Result;
int backPanelCount = backPanelList.Sum(d => d.OutPutAmount);
var sidePanelList = _recordSidePanelComplateServices.QueryAsync(d => d.PlanCode.Equals(executionPlanInfo.TaskCode)).Result;
int sidePanelCount = sidePanelList.Sum(d => d.OutPutAmount);
if (backPanelCount == 0&& sidePanelCount==0)
{
executionPlanInfo.IsFlag =0;
}
else
{
executionPlanInfo.IsFlag = 1;
}
}
if (executionPlanInfo.PlanType == 2)
{
var obj_sidePanel = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("SidePanelPlc"));
string taskSideCode = this.GetSidePlanCode(obj_sidePanel);
if (taskSideCode.Equals(executionPlanInfo.TaskCode))
{
obj_sidePanel.plc.WriteInt16("D6021", "5");
}
var sidePanelList = _recordSidePanelComplateServices.QueryAsync(d => d.PlanCode.Equals(executionPlanInfo.TaskCode)).Result;
int sidePanelCount = sidePanelList.Sum(d => d.OutPutAmount);
if (sidePanelCount == 0)
{
executionPlanInfo.IsFlag = 0;
}
else
{
executionPlanInfo.IsFlag = 1;
}
}
if (executionPlanInfo.PlanType == 3)
{
var obj_backPanel = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("BackPanelPLC"));
string taskBackCode = this.GetBackPlanCode(obj_backPanel);
if (taskBackCode.Equals(executionPlanInfo.TaskCode))
{
obj_backPanel.plc.WriteInt16("D4021", "5");
}
var backPanelList = _recordBackPanelComplateServices.QueryAsync(d => d.PlanCode.Equals(executionPlanInfo.TaskCode)).Result;
int backPanelCount = backPanelList.Sum(d => d.OutPutAmount);
if (backPanelCount == 0)
{
executionPlanInfo.IsFlag = 0;
}
else
{
executionPlanInfo.IsFlag = 1;
}
}
bool result= false;
if (executionPlanInfo.IsFlag == 0)
{
result = await _taskExecutionPlanInfoServices.DeleteAsync(executionPlanInfo);
}
else
{
result = await _taskExecutionPlanInfoServices.UpdateAsync(executionPlanInfo);
}
if (result)
{
PlanInfoDataGrid.Clear();
await LoadData();
MessageBox.Show("执行计划删除成功", "系统信息");
}
else
{
MessageBox.Show("执行计划删除失败", "系统信息");
}
}
else
catch (Exception ex)
{
MessageBox.Show("执行计划删除失败", "系统信息");
log.Error("钣金取消计划异常:"+ex.Message);
}
}
}
@ -915,5 +997,50 @@ namespace Aucma.Core.SheetMetal.ViewModels
}
#endregion
public string GetSidePlanCode(PlcModel obj)
{
bool flag = true;
string planCode = string.Empty;
do
{
byte[] info = obj.plc.Read("D6030", 59);
if (info == null)
{
Thread.Sleep(1000);
continue;
}
//计划编号
planCode = Encoding.ASCII.GetString(info.Skip(0).Take(20).ToArray()).Replace("\0", "").Trim();
if (!string.IsNullOrEmpty(planCode)) flag = false;
} while (flag);
return planCode;
}
public string GetBackPlanCode(PlcModel obj)
{
bool flag = true;
string planCode = string.Empty;
do
{
byte[] info = obj.plc.Read("D4030", 59);
if (info == null)
{
Thread.Sleep(1000);
continue;
}
//计划编号
planCode = Encoding.ASCII.GetString(info.Skip(0).Take(20).ToArray()).Replace("\0", "").Trim();
if (!string.IsNullOrEmpty(planCode)) flag = false;
} while (flag);
return planCode;
}
}
}

@ -86,7 +86,7 @@ namespace Aucma.Core.SheetMetal.ViewModels
if (productPlanInfo != null)
{
//下传到PLC
string stationCode = "1001";
string stationCode = Appsettings.app("StationInfo", "StationCode");
var list = await _executePlanInfoServices.QueryAsync(d => d.ProductLineCode.Equals(stationCode));
ExecutePlanInfo task = new ExecutePlanInfo();
@ -94,7 +94,7 @@ namespace Aucma.Core.SheetMetal.ViewModels
task.ProductPlanCode = PlanInfo.PlanCode;
task.OrderCode = PlanInfo.OrderCode;
task.ProductLineCode = stationCode;//计划工位
task.TaskCode = productPlanInfo.PlanCode;// DateTime.Now.ToString("yyMMddHHmmss");
task.TaskCode = GetMaxNum(PlanInfo.PlanCode);// DateTime.Now.ToString("yyMMddHHmmss");
task.MaterialCode = PlanInfo.MaterialCode;
task.MaterialName = PlanInfo.MaterialName;
if (list.Count == 0)
@ -178,6 +178,37 @@ namespace Aucma.Core.SheetMetal.ViewModels
}
#endregion
#region 获取最大值
/// <summary>
/// 获取最大值
/// </summary>
/// <param name="taskCode">MES编码</param>
/// <returns></returns>
public string GetMaxNum(string mesId)
{
try
{
List<int> tempList = new List<int>();
var list = _executePlanInfoServices.QueryAsync(d => d.TaskCode.Contains(mesId)).Result;
if (list.Count() == 0)
{
return mesId + "0001";
}
foreach (var item in list)
{
string code = item.TaskCode.Substring(item.TaskCode.Length - 4);
int num = Convert.ToInt32(code);
tempList.Add(num);
}
string maxStr = (tempList.Max() + 1).ToString();
string taskCode = mesId+ maxStr.PadLeft(4, '0');
return taskCode;
}
catch
{
return mesId + "0001";
}
}
#endregion
}
}

@ -21,6 +21,7 @@ using Admin.Core.Common;
using System.Drawing.Drawing2D;
using Aucma.Core.SheetMetal.Business;
using Aucma.Core.HwPLc;
using Admin.Core.Service;
namespace Aucma.Core.SheetMetal.ViewModels
{
@ -147,8 +148,6 @@ namespace Aucma.Core.SheetMetal.ViewModels
/// <summary>
/// 创建任务
/// </summary>
private async Task CreateTask(string obj)
{
if (string.IsNullOrEmpty(obj))
@ -156,22 +155,23 @@ namespace Aucma.Core.SheetMetal.ViewModels
MessageBox.Show("请选中需要拆分的计划!", "系统提醒");
return;
}
string productLineCode=Appsettings.app("StationInfo", "ProductLineCode");
ExecutePlanInfo task = new ExecutePlanInfo();
var list = await _executePlanInfoServices.QueryAsync(d => d.ProductLineCode.Equals("1001"));
string stationCode = Appsettings.app("StationInfo", "StationCode");
string plan_code = SelectedCells.PlanCode;
string order_code = SelectedCells.OrderCode;
string material_code = SelectedCells.MaterialCode;
string material_name = SelectedCells.MaterialName;
int plan_amount = SelectedCells.PlanAmount;
var list = await _executePlanInfoServices.QueryAsync(d=>d.ProductLineCode.Equals("1001"));
ExecutePlanInfo task=new ExecutePlanInfo();
task.TaskCode = Guid.NewGuid().ToString().Substring(0, 16);
task.TaskCode = GetMaxNum(plan_code);
task.ExecutePlanCode = Guid.NewGuid().ToString().Substring(0, 16);
task.ProductPlanCode = plan_code;
task.OrderCode = order_code;
task.MaterialCode = material_code;
task.MaterialName = material_name;
task.ProductLineCode = "1001";//计划工位
task.ProductLineCode = stationCode;//计划工位
if (list.Count == 0)
task.ExecuteOrder = 1;
if (list.Count != 0)
@ -396,7 +396,40 @@ namespace Aucma.Core.SheetMetal.ViewModels
{
_radioButtonStatus = 3;
}
}
}
#endregion
#region 获取最大值
/// <summary>
/// 获取最大值
/// </summary>
/// <param name="taskCode">MES编码</param>
/// <returns></returns>
public string GetMaxNum(string mesId)
{
try
{
List<int> tempList = new List<int>();
var list = _executePlanInfoServices.QueryAsync(d => d.TaskCode.Contains(mesId)).Result;
if (list.Count() == 0)
{
return mesId+"0001";
}
foreach (var item in list)
{
string code = item.TaskCode.Substring(item.TaskCode.Length - 4);
int num = Convert.ToInt32(code);
tempList.Add(num);
}
string maxStr = (tempList.Max() + 1).ToString();
string taskCode = maxStr.PadLeft(4, '0');
return taskCode;
}
catch
{
return mesId+"0001";
}
}
#endregion
}
}

Loading…
Cancel
Save