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 { /// /// 上位机配方同步业务类 /// 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); //} ///// ///// 读取某个点位 ///// ///// //private void ReadSignal(object o) //{ // OperateResult boolReault = PlcConnect.ReadBool2("B100"); // if (!boolReault.IsSuccess) // { // return; // } // if (boolReault.Content) // { // PlcConnect.PlcWrite2("B100", false,DataTypeEnum.Bool); //写入完成信号 // SyncRecipe(); // } //} ///// ///// 配方同步 ///// //private void SyncRecipe() //{ // ZxRecipeParaEntity recipeParaEntity = new ZxRecipeParaEntity(); // List 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; // } //} } }