using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Model; 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; namespace Casic.Birmm.RbFreqStandMeasure.R_DataBase.Service.Impl { class CounterDetecInitServiceImpl:CounterDetecInitService { public List<CounterDetecInit> getAll() { List<CounterDetecInit> counterDetecInitList = new List<CounterDetecInit>(); try { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDevice : 数据库链接断开"); return null; } string sQry = "SELECT * FROM r_counter_detec_init order by FREQUENCY"; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) { CounterDetecInit counterDetecInit = new CounterDetecInit(); if (!aReader.IsDBNull(0)) counterDetecInit.Id = Convert.ToInt32(aReader.GetString(0)); if (!aReader.IsDBNull(1)) counterDetecInit.Frequency = aReader.GetString(1); if (!aReader.IsDBNull(2)) counterDetecInit.Cycle = aReader.GetString(2); counterDetecInitList.Add(counterDetecInit); } aCommand.Dispose(); } } catch (MySqlException ex) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDevice: " + ex.Message); } return counterDetecInitList; } public int add(string frequency, string cycle) { int iRetval = -1; try { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "addCounterData : 数据库链接断开"); return iRetval; } string sQry = "INSERT INTO r_counter_detec_init (FREQUENCY, CYCLE)" + " values (@FREQUENCY,@CYCLE)"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@FREQUENCY", MySqlDbType.Int64, 20).Value = frequency; cmd.Parameters.Add("@CYCLE", MySqlDbType.String, 30).Value = cycle; cmd.ExecuteNonQuery(); cmd.Dispose(); iRetval = 0; } catch(MySqlException ex) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "addCounterData : " + ex.Message); iRetval = -1; } return iRetval; } public int update(int id, string frequency, string cycle) { int iRetval = -1; try { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "updateDeviced : 数据库链接断开"); return iRetval; } string sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE " + "WHERE ID = " + id; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@FREQUENCY", MySqlDbType.String, 30).Value = frequency; cmd.Parameters.Add("@CYCLE", MySqlDbType.String, 30).Value = cycle; cmd.ExecuteNonQuery(); cmd.Dispose(); iRetval = 0; } catch (MySqlException ex) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "updateDeviced : " + ex.Message); } return iRetval; } public int delete(int id) { int iRetval = -1; try { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "deleteDeviced : 数据库链接断开"); return iRetval; } string sQry = "delete from r_counter_detec_init WHERE ID = " + id; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); cmd.Dispose(); iRetval = 0; } catch (MySqlException ex) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "deleteDeviced : " + ex.Message); } return iRetval; } } }