private string GetRealtimeInfo(IList <SensorDataLineEntity> lstLine) { if (lstLine != null && lstLine.Count > 0) { SensorDataLineEntity eLine = lstLine[lstLine.Count - 1]; StringBuilder sbRealtimeInfo = new StringBuilder(); if (eLine.ValueNumber1 != null && eLine.ValueNumber1.HasValue) { sbRealtimeInfo.AppendLine(string.Format("{0}: {1}", Properties.Resource.TemperatureSeries, eLine.ValueNumber1.Value.ToString("0.00"))); } if (eLine.ValueNumber2 != null && eLine.ValueNumber2.HasValue) { sbRealtimeInfo.AppendLine(string.Format("{0}: {1}", Properties.Resource.PressureSeries, eLine.ValueNumber2.Value.ToString("0.00"))); } if (eLine.ValueNumber3 != null && eLine.ValueNumber3.HasValue) { sbRealtimeInfo.AppendLine(string.Format("{0}: {1}", Properties.Resource.HumiditySeries, eLine.ValueNumber3.Value.ToString("0.00"))); } if (eLine.ValueNumber4 != null && eLine.ValueNumber4.HasValue) { sbRealtimeInfo.AppendLine(string.Format("{0}: {1}", Properties.Resource.VoltageSeries, eLine.ValueNumber4.Value.ToString("0.00"))); } return(sbRealtimeInfo.ToString()); } return(string.Empty); }
private Bitmap GetProgressMark(SensorDataHeadEntity eHead, SensorDataLineEntity eLine) { TimeSpan ts = eLine.SensorDate.Value.Subtract(eHead.BeginDate.Value); double mins = ts.TotalMinutes; string strPrefix = mins > 60 ? "DvMonitorOver_" : "DvMonitorIn_"; string strImageName = string.Empty; if (mins > 60) { mins = 55; //超过60分钟的保持在55分钟状态 } if (mSensor.PositionMark == "End") { mins = 60; //结束时为60分钟状态 } if (mSensor.PositionMark == "On") { mins = 0; } int num = Convert.ToInt16(mins) / 5 * 5; strImageName = strPrefix + num.ToString(); object obj = Infecon.CSSD.Resources.Images.ResourceManager.GetObject( strImageName, Infecon.CSSD.Resources.Images.resourceCulture); if (obj != null) { return(obj as Bitmap); } else { return(null); } }
private SensorStatusDTO GetStatusData(SensorDataHeadEntity eHead) { SensorStatusDTO dtoStatus = new SensorStatusDTO(); dtoStatus.SensorCaption = mSensor.SensorName; dtoStatus.SensorStatus = mSensor.PositionMark; StatusItemDTO item = null; SensorHelper <object> helper = new SensorHelper <object>(); SensorDataLineEntity eLine = helper.SelectSingle <SensorDataLineEntity>(string.Format("SensorDataHeadID = '{0}'", eHead.SensorDataHeadID.ToString().ToUpper()), "ReceivedDate DESC"); if (eLine != null) { dtoStatus.SensorDate = eLine.SensorDate; dtoStatus.ReceivedDate = eLine.ReceivedDate; // Temperature AddValueNumberToStatus(dtoStatus, eLine.ValueNumber1, Properties.Resource.TemperatureSeries); AddValueNumberToStatus(dtoStatus, eLine.ValueNumber2, Properties.Resource.PressureSeries); AddValueNumberToStatus(dtoStatus, eLine.ValueNumber3, Properties.Resource.HumiditySeries); AddValueNumberToStatus(dtoStatus, eLine.ValueNumber4, Properties.Resource.VoltageSeries); // 确定更新时间 if (eLine.SensorDate != null && eLine.SensorDate.HasValue) { item = new StatusItemDTO(Properties.Resource.UpdatedTime, StatusItemDTO.StatusItemType.DateTimeValue, eLine.SensorDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); dtoStatus.StatusData.Add(item); } } return(dtoStatus); }
private SensorStatusDTO GetStatusData(SensorDataHeadEntity eHead) { SensorStatusDTO dtoStatus = new SensorStatusDTO(); dtoStatus.SensorCaption = mSensor.SensorName; dtoStatus.SensorStatus = mSensor.PositionMark; StatusItemDTO item = null; SensorHelper <object> helper = new SensorHelper <object>(); SensorDataLineEntity eLine = helper.SelectSingle <SensorDataLineEntity>(string.Format("SensorDataHeadID = '{0}'", eHead.SensorDataHeadID.ToString().ToUpper()), "ReceivedDate DESC"); if (eLine != null) { dtoStatus.ProgressMark = GetProgressMark(eHead, eLine); dtoStatus.ErrorData = Utility.GetSensorErrors(eHead, eLine.ReceivedDate); dtoStatus.SensorDate = eLine.SensorDate; dtoStatus.ReceivedDate = eLine.ReceivedDate; IList <SensorDataLineValueEntity> lstLineValue = helper.SelectList <SensorDataLineValueEntity>(string.Format("SensorDataLineID = '{0}'", eLine.SensorDataLineID.ToString().ToUpper()), string.Empty); if (lstLineValue != null && lstLineValue.Count > 0) { string temp = string.Empty; AddContentStringToStatus(dtoStatus, lstLineValue, SystemData.Status.ToString()); // 程序 AddContentStringToStatus(dtoStatus, lstLineValue, SystemData.ProgramNo.ToString()); AddContentStringToStatus(dtoStatus, lstLineValue, SystemData.ProgramName.ToString()); AddContentStringToStatus(dtoStatus, lstLineValue, SystemData.ProgramPhase.ToString()); AddProgramNameCaption(dtoStatus); // MeasurementSensor1 ~ MeasurementSensor7 AddContentNumberToStatus(dtoStatus, lstLineValue, SystemData.MeasurementSensor1.ToString()); AddContentNumberToStatus(dtoStatus, lstLineValue, SystemData.MeasurementSensor2.ToString()); AddContentNumberToStatus(dtoStatus, lstLineValue, SystemData.MeasurementSensor3.ToString()); AddContentNumberToStatus(dtoStatus, lstLineValue, SystemData.MeasurementSensor4.ToString()); AddContentNumberToStatus(dtoStatus, lstLineValue, SystemData.MeasurementSensor5.ToString()); AddContentNumberToStatus(dtoStatus, lstLineValue, SystemData.MeasurementSensor6.ToString()); AddContentNumberToStatus(dtoStatus, lstLineValue, SystemData.MeasurementSensor7.ToString()); // 已用时间 if (eLine.SensorDate != null && eLine.SensorDate.HasValue) { TimeSpan tsUsed = eLine.SensorDate.Value.Subtract(eHead.BeginDate.Value); item = new StatusItemDTO(Properties.Resource.ElapsedTime, StatusItemDTO.StatusItemType.DoubleValue, tsUsed.TotalMinutes.ToString("f2")); dtoStatus.StatusData.Add(item); } // 确定更新时间 if (eLine.SensorDate != null && eLine.SensorDate.HasValue) { item = new StatusItemDTO(Properties.Resource.UpdatedTime, StatusItemDTO.StatusItemType.DateTimeValue, eLine.SensorDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); dtoStatus.StatusData.Add(item); } } } return(dtoStatus); }
private void AnalyseData(IList <string> row, string strByteData) { string sysNo = ParseHelper.ParseString(row[(int)SystemData.SystemNo]); string batchNo = ParseHelper.ParseString(row[(int)SystemData.BatchNo]); DateTime timestamp = ConvertDate(row[(int)SystemData.Timestamp]); SensorHelper <object> helperSensor = new SensorHelper <object>(); SensorEntity eSensor = helperSensor.SelectSingle <SensorEntity>(string.Format("SensorGroup = '{0}' AND SensorKey = '{1}'", mSensorGroup, sysNo), string.Empty); if (eSensor == null) { logger.WarnFormat("系统中组和编号为:[{0}].[{1}]的设备没有登记。", mSensorGroup, sysNo); return; } SensorDataHeadEntity eHead = helperSensor.SelectSingle <SensorDataHeadEntity>(string.Format("SensorID = '{0}' AND DataKey = '{1}'", eSensor.SensorID.ToString().ToUpper(), batchNo), string.Empty); Enumerator.BelimedStatus status;//0-Off,1-On,2-Run,3-End try { status = (Enumerator.BelimedStatus)Enum.Parse(typeof(Enumerator.BelimedStatus), row[(int)SystemData.Status]); } catch (Exception ex) { logger.ErrorFormat("传感器状态取得失败,状态值:[{0}]", row[(int)SystemData.Status]); throw ex; } System.Threading.Monitor.Enter(Monitor.Common.Utility.SyncSqlLock); try { logger.Info("开始保存数据。"); using (TransactionScope tran = Monitor.Common.Utility.GetTransactionScope()) { switch (status) { case Enumerator.BelimedStatus.Off: eSensor.PositionMark = status.ToString(); helperSensor.Update(eSensor); break; case Enumerator.BelimedStatus.On: eSensor.PositionMark = status.ToString(); helperSensor.Update(eSensor); break; case Enumerator.BelimedStatus.Run: if (eHead == null) { // 主数据 eHead = new SensorDataHeadEntity(); eHead.SensorDataHeadID = Guid.NewGuid(); eHead.SensorID = eSensor.SensorID; eHead.DataKey = batchNo; eHead.BeginDate = timestamp; eHead.IsCompressed = false; eHead.DataVer = DataVersion.V1.ToString(); helperSensor.Create(eHead); } eSensor.PositionMark = status.ToString(); helperSensor.Update(eSensor); // 原始数据 SensorDataRawLineEntity eRawLine = new SensorDataRawLineEntity(); eRawLine.SensorDataRawLineID = Guid.NewGuid(); eRawLine.SensorDataHeadID = eHead.SensorDataHeadID; eRawLine.ReceivedDate = DateTime.Now; eRawLine.RawData = strByteData; helperSensor.Create(eRawLine); // 解析数据 SensorDataLineEntity eLine = new SensorDataLineEntity(); eLine.SensorDataLineID = Guid.NewGuid(); eLine.SensorDataHeadID = eHead.SensorDataHeadID; eLine.SensorDataRawLineID = eRawLine.SensorDataRawLineID; eLine.ReceivedDate = eRawLine.ReceivedDate; eLine.SensorDate = timestamp; if (eLine.SensorDate != null && eLine.SensorDate.HasValue && eHead.BeginDate != null && eHead.BeginDate.HasValue) { eLine.SensorTimeSpan = Convert.ToInt64(eLine.SensorDate.Value.Subtract(eHead.BeginDate.Value).TotalMilliseconds); } //eLine.AnalysedData = row.ToString(); eLine.AnalysedData = string.Join(";", row.ToArray <string>()); helperSensor.Create(eLine); SensorDataLineValueEntity eLineValue = null; for (int i = 0; i < row.Count; i++) { eLineValue = new SensorDataLineValueEntity(); eLineValue.SensorDataLineValueID = Guid.NewGuid(); eLineValue.SensorDataHeadID = eLine.SensorDataHeadID; eLineValue.SensorDataLineID = eLine.SensorDataLineID; switch (i) { case (int)SystemData.Status: string ss = ParseHelper.ParseString(row[i]); if (!string.IsNullOrEmpty(ss)) { eLineValue.ValueType = SystemData.Status.ToString(); eLineValue.ContentString = ss; helperSensor.Create(eLineValue); } break; case (int)SystemData.ErrorNo: string errorNo = ParseHelper.ParseString(row[i]); if (!string.IsNullOrEmpty(errorNo)) { eLineValue.ValueType = SystemData.ErrorNo.ToString(); eLineValue.ContentString = errorNo; helperSensor.Create(eLineValue); } break; case (int)SystemData.ProgramNo: eLineValue.ValueType = SystemData.ProgramNo.ToString(); eLineValue.ContentString = ParseHelper.ParseString(row[i]); helperSensor.Create(eLineValue); break; case (int)SystemData.ProgramName: eLineValue.ValueType = SystemData.ProgramName.ToString(); eLineValue.ContentString = ParseHelper.ParseString(row[i]); helperSensor.Create(eLineValue); break; case (int)SystemData.ProgramPhase: eLineValue.ValueType = SystemData.ProgramPhase.ToString(); eLineValue.ContentString = ParseHelper.ParseString(row[i]); helperSensor.Create(eLineValue); break; default: break; } if (Convert.ToInt32(eSensor.SensorType).Equals(Convert.ToInt32(Common.Consts.SensorType.Washer))) { switch (i) { case (int)SystemData.MeasurementSensor1: // Med eLineValue.ValueType = SystemData.MeasurementSensor1.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]); helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor2: // CT eLineValue.ValueType = SystemData.MeasurementSensor2.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]) / 10; helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor3: // CDNo eLineValue.ValueType = SystemData.MeasurementSensor3.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]); helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor4: // DosV eLineValue.ValueType = SystemData.MeasurementSensor4.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]) / 10; helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor5: // Ao eLineValue.ValueType = SystemData.MeasurementSensor5.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]); helperSensor.Create(eLineValue); break; default: break; } } else if (Convert.ToInt32(eSensor.SensorType).Equals(Convert.ToInt32(Common.Consts.SensorType.Sterilizer))) { switch (i) { case (int)SystemData.MeasurementSensor1: // T1 eLineValue.ValueType = SystemData.MeasurementSensor1.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]) / 10; helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor2: // T2 eLineValue.ValueType = SystemData.MeasurementSensor2.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]) / 10; helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor4: // P1 eLineValue.ValueType = SystemData.MeasurementSensor4.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]); helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor5: // P2 eLineValue.ValueType = SystemData.MeasurementSensor5.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]); helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor6: // P3 eLineValue.ValueType = SystemData.MeasurementSensor6.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]); helperSensor.Create(eLineValue); break; case (int)SystemData.MeasurementSensor7: // P4 eLineValue.ValueType = SystemData.MeasurementSensor7.ToString(); eLineValue.ContentNumber = Convert.ToDecimal(row[i]); helperSensor.Create(eLineValue); break; default: break; } } } break; case Enumerator.BelimedStatus.End: if (eHead != null) { eHead.EndDate = ConvertDate(row[(int)SystemData.Timestamp]); helperSensor.Update(eHead); eSensor.PositionMark = status.ToString(); eSensor.Remarks = ParseHelper.ParseString(row[(int)SystemData.StatusInfo]); helperSensor.Update(eSensor); if (eHead.LogID != null && eHead.LogID.HasValue && eHead.LogID.Value != Guid.Empty) { DevicesUseLogEntity logEntity = helperSensor.SelectSingle <DevicesUseLogEntity>("LogID='" + eHead.LogID.Value.ToString().ToUpper() + "'", string.Empty); if (logEntity != null) { if (eHead.BeginDate != null && eHead.BeginDate.HasValue) { logEntity.OldBeginDate = logEntity.BeginDate; logEntity.BeginDate = eHead.BeginDate.Value; } logEntity.EndDate = eHead.EndDate; // TODO: DevicesUseLog 关联到 Sensor 的字段 //logEntity.MonitorDataID = eHead.SensorDataHeadID; helperSensor.Update(logEntity); } } } break; default: break; } tran.Complete(); logger.Info("数据保存成功。"); } } finally { System.Threading.Monitor.Exit(Monitor.Common.Utility.SyncSqlLock); } }
private void SaveData(SensorData receivedData) { SensorHelper <object> helperSensor = new SensorHelper <object>(); SensorEntity eSensor = helperSensor.SelectSingle <SensorEntity>(string.Format("SensorGroup = '{0}' AND SensorKey = '{1}'", mSensorGroup, receivedData.SourceAddress), string.Empty); if (eSensor == null) { logger.WarnFormat("系统中组和编号为:[{0}].[{1}]的设备没有登记。", mSensorGroup, receivedData.SourceAddress); return; } string dataKey = receivedData.ReceiveDate.Value.ToString("yyyyMMdd"); SensorDataHeadEntity eHead = helperSensor.SelectSingle <SensorDataHeadEntity>(string.Format("SensorID = '{0}' AND DataKey = '{1}'", eSensor.SensorID.ToString().ToUpper(), dataKey), string.Empty); System.Threading.Monitor.Enter(Monitor.Common.Utility.SyncSqlLock); try { logger.Debug("开始保存数据。"); using (TransactionScope tran = Monitor.Common.Utility.GetTransactionScope()) { if (eHead == null) { // 主数据 eHead = new SensorDataHeadEntity(); eHead.SensorDataHeadID = Guid.NewGuid(); eHead.SensorID = eSensor.SensorID; eHead.DataKey = dataKey; eHead.BeginDate = receivedData.ReceiveDate; eHead.IsCompressed = false; helperSensor.Create(eHead); } // 原始数据 SensorDataRawLineEntity eRawLine = new SensorDataRawLineEntity(); eRawLine.SensorDataRawLineID = Guid.NewGuid(); eRawLine.SensorDataHeadID = eHead.SensorDataHeadID; eRawLine.ReceivedDate = receivedData.ReceiveDate; eRawLine.RawData = receivedData.SourceData; helperSensor.Create(eRawLine); // 明细数据 SensorDataLineEntity eLine = new SensorDataLineEntity(); eLine.SensorDataLineID = Guid.NewGuid(); eLine.SensorDataHeadID = eHead.SensorDataHeadID; eLine.SensorDataRawLineID = eRawLine.SensorDataRawLineID; eLine.ReceivedDate = eRawLine.ReceivedDate; eLine.SensorDate = eRawLine.ReceivedDate; if (eLine.SensorDate != null && eLine.SensorDate.HasValue && eHead.BeginDate != null && eHead.BeginDate.HasValue) { eLine.SensorTimeSpan = Convert.ToInt64(eLine.SensorDate.Value.Subtract(eHead.BeginDate.Value).TotalMilliseconds); } //eLine.AnalysedData = string.Empty; eLine.ValueNumber1 = receivedData.Temperature; eLine.ValueNumber2 = receivedData.Pressure; eLine.ValueNumber3 = receivedData.Humidity; eLine.ValueNumber4 = receivedData.Voltage; helperSensor.Create(eLine); tran.Complete(); logger.Debug("数据保存成功。"); } } finally { System.Threading.Monitor.Exit(Monitor.Common.Utility.SyncSqlLock); } }