public float getLastData(Model.CasicPress pressInfo) { using (OracleConnection conn = new OracleConnection(OracleHelper.ConnectionStringOrderDistributedTransaction)) { String SQL = " SELECT DATA " + " FROM " + " (SELECT * " + " FROM ALARM_PRESS " + " WHERE DEVCODE = :devCode " + " and UPTIME < :uptime " + " order by UPTIME desc) " + " where rownum=1 "; /* * String SQL = " SELECT DATA " + * " FROM ALARM_PRESS " + * " WHERE DEVCODE = :devCode " + * " and UPTIME < :uptime " + * " and rownum=1 " + * " order by UPTIME desc "; **/ OracleParameter[] oraParams = new OracleParameter[] { new OracleParameter(":devCode", pressInfo.DEVCODE), new OracleParameter(":uptime", pressInfo.UpTime) }; DataTable dt = OracleHelper.ExecuteDataset(conn, CommandType.Text, SQL, oraParams).Tables[0]; if (dt.Rows.Count > 0) { float lastData = float.Parse(dt.Rows[0]["DATA"].ToString()); return(lastData); } } return(-1); }
/// <summary> /// An internal function to bind values parameters for insert /// </summary> /// <param name="parms">Database parameters</param> /// <param name="noise">Values to bind to parameters</param> private void SetAdapterParameters(OracleParameter[] parms, Model.CasicPress casicPress) { parms[0].Value = casicPress.DEVCODE; if (null != casicPress.Data) { parms[1].Value = casicPress.Data; } else { parms[1].Value = DBNull.Value; } if (null != casicPress.LogTime) { parms[2].Value = casicPress.LogTime; } else { parms[2].Value = DBNull.Value; } if (null != casicPress.UpTime) { parms[3].Value = casicPress.UpTime; } else { parms[3].Value = DBNull.Value; } if (null != casicPress.Cell) { parms[4].Value = casicPress.Cell; } else { parms[4].Value = DBNull.Value; } }
private AlarmRecordInfo getAlarmRecord(AlarmRuleInfo alarmRuleInfo, Model.CasicPress pressInfo) { if (null != alarmRuleInfo) { float curValue = float.Parse(pressInfo.Data); IDevice deviceDal = SensorHub.DALFactory.Device.Create(); ICasicPress pressDal = SensorHub.DALFactory.CasicPress.Create(); AlarmRecordInfo alarmRecordInfo = new AlarmRecordInfo(); alarmRecordInfo.ACTIVE = true; alarmRecordInfo.DEVICE_CODE = pressInfo.DEVCODE; alarmRecordInfo.DEVICE_ID = alarmRuleInfo.DeviceId; alarmRecordInfo.DEVICE_TYPE_NAME = deviceDal.getDevTypeByCode(pressInfo.DEVCODE); alarmRecordInfo.ITEMNAME = "压力值"; alarmRecordInfo.ITEMVALUE = curValue.ToString(); alarmRecordInfo.MESSAGE_STATUS = 0; alarmRecordInfo.RECORDCODE = ""; alarmRecordInfo.RECORDDATE = System.DateTime.Now; if (alarmRuleInfo.HighValue != 0 && curValue > alarmRuleInfo.HighValue) { alarmRecordInfo.MESSAGE = "压力超限"; return(alarmRecordInfo); } if (alarmRuleInfo.Saltation != 0) { float lastData = pressDal.getLastData(pressInfo); if (-1 != lastData && Math.Abs(curValue - lastData) > alarmRuleInfo.Saltation) { alarmRecordInfo.MESSAGE = "压力突变"; return(alarmRecordInfo); // return null; } } } return(null); }
public float getLastData(Model.CasicPress pressInfo) { return(SensorHub.DALFactory.CasicPress.Create().getLastData(pressInfo)); }