using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Dto; using Casic.Birmm.RbFreqStandMeasure.Tools; using MySql.Data.MySqlClient; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Text; using static System.Net.Mime.MediaTypeNames; namespace Casic.Birmm.RbFreqStandMeasure.R_DataBase.Service.Impl { class DetectionServiceImpl : DetectionService { public int add(long deviceId, DateTime logTime,String frequency) { int iRetval = -1; try { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "addDetection : 数据库链接断开"); return iRetval; } string sQry = "INSERT INTO r_detection (DEVICE_ID,LOG_TIME,FREQUENCY)" + "values(@DEVICE_ID,@LOG_TIME,@FREQUENCY)"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@DEVICE_ID", MySqlDbType.Int64, 20).Value = deviceId; cmd.Parameters.Add("@FREQUENCY", MySqlDbType.String, 255).Value = frequency; cmd.Parameters.Add("@LOG_TIME", MySqlDbType.DateTime, 0).Value = logTime; cmd.ExecuteNonQuery(); cmd.Dispose(); iRetval = 0; } catch (MySqlException ex) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "addDetection : " + ex.Message); iRetval = -1; } return iRetval; } public List<DetectionDto> search(long deviceId, string detectionType, string startTime, string endTime) { List<DetectionDto> detectionDtoList = new List<DetectionDto>(); try { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDetection : 数据库链接断开"); return null; } string sQry = "SELECT DEVICE_ID,LOG_TIME,FREQUENCY FROM r_detection where DEVICE_ID = " + deviceId +" and DETECTION_ITEM=" + detectionType + " and (LOG_TIME BETWEEN '" + startTime + "' and '"+ endTime + "') order by LOG_TIME"; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) { DetectionDto detectionDto = new DetectionDto(); //姓名 if (!aReader.IsDBNull(0)) detectionDto.DeviceId = Convert.ToInt64(aReader.GetString(0)); if (!aReader.IsDBNull(1)) detectionDto.LogTime = Convert.ToDateTime(aReader.GetString(1)).ToString("yyyy-MM-dd HH:mm:ss"); if (!aReader.IsDBNull(2)) detectionDto.Frequency = aReader.GetString(2); detectionDtoList.Add(detectionDto); } aCommand.Dispose(); } } catch (MySqlException ex) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDetectionItem: " + ex.Message); detectionDtoList = null; } return detectionDtoList; } } }