using Casic.Birmm.RbFreqStandMeasure.Tools; using MySql.Data.MySqlClient; using System; using System.Collections.Generic; using System.Data; using System.Reflection; namespace Casic.Birmm.RbFreqStandMeasure.R_DataBase.Service.Impl { class DictServiceImpl:DictService { public String getNameByCode(string codeType,string code) { String name = ""; MySqlConnection conn = null; try { string sql = "SELECT name FROM r_dict where pid = (select id from r_dict where code = '" + codeType + "') and code = " + code; conn = DbConnectService.getConnection(); MySqlCommand cmd = new MySqlCommand(sql, conn); MySqlDataReader aReader = cmd.ExecuteReader(CommandBehavior.Default); if (aReader != null) { if (aReader.Read()) { //判断门的状态 if (!aReader.IsDBNull(0)) { name = aReader.GetString(0); } } } aReader.Close(); cmd.Dispose(); return name; } catch(MySqlException ex) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getNameByCode: " + ex.Message); name = ""; } finally { if (null != conn) { conn.Close(); conn.Dispose(); // 用完即关闭连接 } } return name; } public List<String> getTypeListByCodeType(string codeType) { List<String> nameList = new List<string>(); MySqlConnection conn = null; try { conn = DbConnectService.getConnection(); string sQry = "SELECT name FROM r_dict where pid = (select id from r_dict where code = '" + codeType + "')"; MySqlCommand aCommand = new MySqlCommand(sQry, conn); using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) { if (!aReader.IsDBNull(0)) nameList.Add(aReader.GetString(0)); } aCommand.Dispose(); conn.Close(); conn.Dispose(); // 用完即关闭连接 } } catch(MySqlException ex) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getTypeListByCodeType: " + ex.Message); nameList = null; } finally { if (null != conn) { conn.Close(); conn.Dispose(); // 用完即关闭连接 } } return nameList; } } }