public int InsertMeasure(SensorInfo sensor) { var now = DateTime.Now; var dataInsert = new { SensorId = sensor.SensorId, Alarm_Value = sensor.Alarm_Value, Start_time = now, //End_time = now, Measure_Type = (int)clsConst.emMeasureType.AlarmTest, Measure_Result = (int)clsConst.emMeasureResult.Pass, UserId = AppManager.UserLogin.UserId, UpdateTime = now, Delete_Flag = 0 }; var sqlInsert = GenerateSqlInsert("Measure", dataInsert); var sqlGetLastId = " SELECT seq FROM sqlite_sequence where name='Measure'; "; var sql = string.Empty; sql += " BEGIN; "; sql += sqlInsert; sql += sqlGetLastId; sql += " END; "; lock (_syncDB) { return(_dbConnection.QueryFirst <int>(sql, dataInsert)); } }
public bool UpdateSensor(SensorInfo sensor, int currentOrdinalDisplay, int swapOrdinalDisplay, bool flag, int userId = 1) { if (sensor == null) { return(true); } if (_dbConnection.State == ConnectionState.Closed) { _dbConnection.Open(); } if (AppManager.UserLogin != null) { userId = AppManager.UserLogin.UserId; } using (var transaction = _dbConnection.BeginTransaction()) { try { var intRst = Update("Sensors", new string[] { "SensorId" }, new { SensorId = sensor.SensorId, SensorName = sensor.SensorName, Alarm_Value = sensor.Alarm_Value, Ordinal_Display = swapOrdinalDisplay, OfBlock = sensor.OfBlock, Active = sensor.Active, UpdateTime = DateTime.Now, UpdateBy = userId, MeasureType = sensor.MeasureType, DecayUpperValue = sensor.DecayUpperValue, DecayLowerValue = sensor.DecayLowerValue, DecayTimeCheck = sensor.DecayTimeCheck, DecayStopTime = sensor.DecayStopTime, IonValueCheck = sensor.IonValueCheck, IonTimeCheck = sensor.IonTimeCheck, AutoCheckFlag = sensor.AutoCheckFlag, AutoCheckTime = sensor.AutoCheckTime, AutoCheckDays = sensor.AutoCheckDays }); var sql = string.Empty; sql += flag ? string.Format("UPDATE Sensors SET Ordinal_Display = Ordinal_Display + 1 WHERE Ordinal_Display >= {0} AND Ordinal_Display <= {1} AND SensorId <> {2} AND OfBlock = {3}", swapOrdinalDisplay, currentOrdinalDisplay, sensor.SensorId, sensor.OfBlock) : string.Format("UPDATE Sensors SET Ordinal_Display = Ordinal_Display - 1 WHERE Ordinal_Display >= {0} AND Ordinal_Display <= {1} AND SensorId <> {2} AND OfBlock = {3}", currentOrdinalDisplay, swapOrdinalDisplay, sensor.SensorId, sensor.OfBlock); var intResul = _dbConnection.Execute(sql); transaction.Commit(); return(true); } catch (Exception ex) { transaction.Rollback(); return(false); } } }
public bool InsertSensor(SensorInfo sensor) { var intRst = Insert("Sensors", new { SensorId = sensor.SensorId, SensorName = sensor.SensorName, Alarm_Value = sensor.Alarm_Value, Ordinal_Display = sensor.Ordinal_Display, OfBlock = sensor.OfBlock, Active = sensor.Active, UpdateTime = DateTime.Now, UpdateBy = AppManager.UserLogin.UserId, }); return(intRst > 0); }
public bool UpdateSensor(SensorInfo sensor) { if (sensor == null) { return(true); } var intRst = Update("Sensors", new string[] { "SensorId" }, new { SensorId = sensor.SensorId, SensorName = sensor.SensorName, Alarm_Value = sensor.Alarm_Value, Ordinal_Display = sensor.Ordinal_Display, OfBlock = sensor.OfBlock, Active = sensor.Active, UpdateTime = DateTime.Now, UpdateBy = AppManager.UserLogin.UserId }); return(intRst > 0); }