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(int 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(int deviceId) { 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; 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.ToInt32(aReader.GetString(0)); if (!aReader.IsDBNull(1)) detectionDto.LogTime = aReader.GetString(1); 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; } } }