示例#1
0
 /// <summary>
 /// 获取设备指定参数最近的日志数据
 /// </summary>
 /// <param name="strDeviceId">设备编号</param>
 /// <param name="parType">参数类型</param>
 /// <returns></returns>
 public DeviceProduceLog GetDeviceProduceLog(string strDeviceId, SysHelper.Enums.DeviceParameterType parType)
 {
     try
     {
         using (DataModels.HnfactoryautodbDB dataContext = new DataModels.HnfactoryautodbDB())
         {
             DataModels.LDeviceproducelog data = (from d in dataContext.LDeviceproducelogs
                                                  where d.DeviceId == strDeviceId & d.ParType == parType.ToString()
                                                  orderby d.Created descending
                                                  select d).FirstOrDefault();
             if (data != null)
             {
                 return(new DeviceProduceLog(data));
             }
             else
             {
                 return(null);
             }
         }
     }
     catch
     {
         throw;
     }
 }
 internal DeviceProduceLog(DataModels.LDeviceproducelog data)
 {
     this.Id = data.Id;
     this.DeviceProduceLogId = data.DeviceProduceLogId;
     this.DeviceId           = data.DeviceId;
     this.Created            = data.Created;
     this.IsCurrent          = Convert.ToBoolean(data.IsCurrent);
     this.DeviceStatus       = SysHelper.Enums.EnumHelper.Parse <SysHelper.Enums.DeviceActionType>(data.DeviceStatus);
     this.SensorId           = data.SensorId;
     this.ValueType          = data.ValueType;
     this.SensorStatusValue  = data.SensorStatusValue;
     this.SensorStatus       = SysHelper.Enums.EnumHelper.Parse <SysHelper.Enums.SenserStatusType>(data.SensorStatus);
     this.ParType            = SysHelper.Enums.EnumHelper.Parse <SysHelper.Enums.DeviceParameterType>(data.ParType);
     this.ParUnit            = data.ParUnit;
     this.ParValue           = data.ParValue;
 }
        internal DataModels.LDeviceproducelog ToData()
        {
            DataModels.LDeviceproducelog data = new DataModels.LDeviceproducelog();

            data.Id = this.Id;
            data.DeviceProduceLogId = this.DeviceProduceLogId;
            data.DeviceId           = this.DeviceId;
            data.Created            = this.Created;
            data.IsCurrent          = Convert.ToSByte(this.IsCurrent);
            data.DeviceStatus       = Enum.GetName(this.DeviceStatus.GetType(), this.DeviceStatus);
            data.SensorId           = this.SensorId;
            data.ValueType          = this.ValueType;
            data.SensorStatusValue  = this.SensorStatusValue;
            data.SensorStatus       = Enum.GetName(this.SensorStatus.GetType(), this.SensorStatus);
            data.ParType            = Enum.GetName(this.ParType.GetType(), this.ParType);
            data.ParUnit            = this.ParUnit;
            data.ParValue           = this.ParValue;

            return(data);
        }