using Aborlen.Model;
|
|
using Aborlen.Opc.PlcBase;
|
|
using FrameWork.Log;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Aborlen.PlcCommunicationInit
|
|
{
|
|
public partial class WorkStation: StationBase
|
|
{
|
|
|
|
|
|
|
|
private void OpcTag_EventTagChanged(string tagId, int tagMarkCode, object tagValue, DateTime timeTrigger)
|
|
{
|
|
try
|
|
{
|
|
if (!Convert.ToBoolean(tagValue))
|
|
{
|
|
return;
|
|
}
|
|
|
|
|
|
//判断数据库采集功能配置表(DataCollectConfig) 是否包含当前信号
|
|
List<DataCollectConfig> configList = CollectsConfig.Where(p => p.TagMarkCode == tagMarkCode && p.TagConfigCode == ThisStationInfo.TagConfigCode).ToList();
|
|
long InsertIndex = 0;
|
|
foreach (var configItem in configList)
|
|
{
|
|
|
|
//保存质量数据
|
|
//判断是否保存索引
|
|
if (configItem.CollectIndexMarkCode > 0)
|
|
{
|
|
//存在索引 这里统计索引信息
|
|
string indexTableName = configItem.CollectIndexTableName;
|
|
|
|
//索引标志TagMarkId
|
|
int indexTagMarkCode = configItem.CollectIndexMarkCode;
|
|
|
|
//获取索引需要保存的字段
|
|
|
|
List<DataCollectConfigDetail> stationConfigDetails = StationConfigDetails.Where(p => p.TagConfigCode == configItem.TagConfigCode).ToList();
|
|
|
|
//通过反射创建表实例 Aborlen.Model.QualityDataInfoIndex
|
|
Assembly assembly = Assembly.Load("Aborlen.Model");
|
|
Type type = assembly.GetType("Aborlen.Model." + indexTableName);
|
|
|
|
var instace = Activator.CreateInstance(type);
|
|
|
|
foreach (var detailItem in stationConfigDetails)
|
|
{
|
|
//读取对应点数据
|
|
|
|
if (type.GetProperty(detailItem.TargetColName).PropertyType == typeof(string))
|
|
{
|
|
type.GetProperty(detailItem.TargetColName).SetValue(instace, Read(detailItem.CollectIndexMarkCode).ToString());
|
|
}
|
|
else
|
|
{
|
|
type.GetProperty(detailItem.TargetColName).SetValue(instace, Convert.ToInt32(Read(detailItem.CollectIndexMarkCode)));
|
|
}
|
|
}
|
|
type.GetProperty("StationId").SetValue(instace, ThisStationInfo.StationId);
|
|
|
|
type.GetProperty("StationCode").SetValue(instace, ThisStationInfo.StationCode);
|
|
|
|
type.GetProperty("StationName").SetValue(instace, ThisStationInfo.StationName);
|
|
|
|
InsertIndex = EntityFrameWork.DbHelperMapping[indexTableName + "_Insert"].Invoke(instace);
|
|
|
|
}
|
|
|
|
//保存明细数据
|
|
|
|
//获取表名称
|
|
|
|
string DetailTableName = configItem.CollectTableName;
|
|
|
|
|
|
|
|
//遍历当前工位所有质量数据信号点
|
|
foreach (var qualityTagDetails in StationQualityTagDetails.GroupBy(p => p.GroupSerialNumber))
|
|
{
|
|
foreach (var qualityTagItem in qualityTagDetails)
|
|
{
|
|
|
|
int itemQualityMark = 0;
|
|
if (qualityTagItem.SerialType == 1 && qualityTagItem.IsValidate == 0)
|
|
{
|
|
|
|
itemQualityMark = Convert.ToInt32(Read(qualityTagItem.TagId, timeTrigger));
|
|
}
|
|
else
|
|
{
|
|
QualityDataInfo qualityDataInfo = new QualityDataInfo();
|
|
qualityDataInfo.TagId = qualityTagItem.TagId;
|
|
qualityDataInfo.ParentId = InsertIndex;
|
|
|
|
qualityDataInfo.MeasurePosition = qualityTagItem.MeasurePosition;
|
|
qualityDataInfo.MeasureItem = qualityTagItem.MeasureItem;
|
|
qualityDataInfo.TagValue = Read(qualityTagItem.TagId, timeTrigger).ToString();
|
|
|
|
qualityDataInfo.MeasureUnit = qualityTagItem.MeasureUnit;
|
|
|
|
if (qualityTagItem.IsValidate == 1)
|
|
{
|
|
qualityDataInfo.UpperLimit = qualityTagItem.UpperLimit;
|
|
qualityDataInfo.LowerLimit = qualityTagItem.LowerLimit;
|
|
if (Convert.ToDouble(qualityDataInfo.TagValue) > Convert.ToDouble(qualityTagItem.LowerLimit) && Convert.ToDouble(qualityDataInfo.TagValue) < Convert.ToDouble(qualityTagItem.UpperLimit))
|
|
{
|
|
qualityDataInfo.QualifiedMark = 1;
|
|
}
|
|
else
|
|
{
|
|
qualityDataInfo.QualifiedMark = 2;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
qualityDataInfo.QualifiedMark = itemQualityMark;
|
|
}
|
|
|
|
qualityDataInfo.ItemSerialNumber = qualityTagItem.ItemSerialNumber;
|
|
qualityDataInfo.GroupSerialNumber = qualityTagItem.GroupSerialNumber;
|
|
qualityDataInfo.CreateTime = DateTime.Now;
|
|
|
|
QualityDataInfo.Insert(qualityDataInfo);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
LogHelper.WriteLog(LogHelper.GetMethodInfo(), ex);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|