You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
4.1 KiB
C#
113 lines
4.1 KiB
C#
using HighWayIot.Plc;
|
|
using HighWayIot.Plc.PlcHelper;
|
|
using HighWayIot.Repository.domain;
|
|
using HighWayIot.Repository.service;
|
|
using HighWayIot.Winform.MainForm;
|
|
using HslCommunication;
|
|
using Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using Timer = System.Threading.Timer;
|
|
|
|
namespace HighWayIot.Winform.Business
|
|
{
|
|
/// <summary>
|
|
/// 上位机配方同步业务类
|
|
/// </summary>
|
|
public class RecipeParaSyncBusiness
|
|
{
|
|
//private Timer _readSignalTimer;
|
|
|
|
//private RecipeParaHelper recipeParaHelper = new RecipeParaHelper();
|
|
|
|
//private ZxRecipeParaService zxRecipeParaService = ZxRecipeParaService.Instance;
|
|
|
|
//private ZxRecipePositionParaService zxRecipePositionParaService = ZxRecipePositionParaService.Instance;
|
|
|
|
//public RecipeParaSyncBusiness()
|
|
//{
|
|
// _readSignalTimer = new Timer(new System.Threading.TimerCallback(ReadSignal), null, 0, 1500);
|
|
//}
|
|
|
|
///// <summary>
|
|
///// 读取某个点位
|
|
///// </summary>
|
|
///// <param name="o"></param>
|
|
//private void ReadSignal(object o)
|
|
//{
|
|
// OperateResult<bool> boolReault = PlcConnect.ReadBool2("B100");
|
|
// if (!boolReault.IsSuccess)
|
|
// {
|
|
// return;
|
|
// }
|
|
// if (boolReault.Content)
|
|
// {
|
|
// PlcConnect.PlcWrite2("B100", false,DataTypeEnum.Bool); //写入完成信号
|
|
// SyncRecipe();
|
|
// }
|
|
//}
|
|
|
|
///// <summary>
|
|
///// 配方同步
|
|
///// </summary>
|
|
//private void SyncRecipe()
|
|
//{
|
|
// ZxRecipeParaEntity recipeParaEntity = new ZxRecipeParaEntity();
|
|
// List<ZxRecipePositionParaEntity> positionParaEntities = recipeParaHelper.DownLoadFormPlc(ref recipeParaEntity);
|
|
|
|
// //查重
|
|
// var nowParaEntity = zxRecipeParaService.GetRecipeParaInfoByRecipeCode(recipeParaEntity.RecipeCode);
|
|
// var nowPositionParaEntity = zxRecipePositionParaService.GetRecipePositionParaInfoByRecipeCode(recipeParaEntity.RecipeCode);
|
|
|
|
// //保存公共参数
|
|
// if (nowParaEntity.Count == 0) //没有就插入
|
|
// {
|
|
// if (!zxRecipeParaService.InsertRecipeParaInfo(recipeParaEntity))
|
|
// {
|
|
// Log4net.LogHelper.Instance.Error("配方公共参数插入数据库失败");
|
|
// return;
|
|
// }
|
|
// }
|
|
// else //有就更新 多条更新第一条
|
|
// {
|
|
// recipeParaEntity.Id = nowParaEntity[0].Id;
|
|
// if (!zxRecipeParaService.UpdateRecipeParaInfo(recipeParaEntity))
|
|
// {
|
|
// Log4net.LogHelper.Instance.Error("配方公共参数更新数据库失败");
|
|
// return;
|
|
// }
|
|
// }
|
|
|
|
|
|
// //保存贴合参数
|
|
// var flag2 = true;
|
|
// foreach (var item in positionParaEntities)
|
|
// {
|
|
// item.RecipeCode = recipeParaEntity.RecipeCode;
|
|
// var count = positionParaEntities.Count(x => x.Position == item.Position);
|
|
// //如果没有
|
|
// if (count == 0)
|
|
// {
|
|
// flag2 = zxRecipePositionParaService.InsertRecipePositionParaInfo(item);
|
|
// }
|
|
// else //有 多条存第一条
|
|
// {
|
|
// item.Id = positionParaEntities.FirstOrDefault(x => x.Position == item.Position).Id;
|
|
// flag2 = zxRecipePositionParaService.UpdateRecipePositionParaInfo(item);
|
|
|
|
// if (count != 1) //多条提示
|
|
// {
|
|
// Log4net.LogHelper.Instance.Error($"配方贴合参数重复,配方号:{recipeParaEntity.RecipeCode},工位号:{item.Position}");
|
|
// }
|
|
// }
|
|
// if (!flag2) break;
|
|
// }
|
|
//}
|
|
}
|
|
}
|