using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Dto; 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 DeviceServiceImpl : DeviceService { public long add(string devName, string devCode, string devTypeId, string devModel, string custometDev, string customerName, string channel,string statusId) { long deviceId = -1; //DetectionItemService detectionItemService = new DetectionItemServiceImpl(); try { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "addDeviced : 数据库链接断开"); int iRetval = DbConnectService.openDb(); if (iRetval != 0) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重连失败!"); return iRetval; } } string sQry = "INSERT INTO r_device (DEV_NAME,DEV_CODE,DEV_TYPEID,DEV_MODEL,REG_TIME,CUSTOMER_NAME,CUSTOMER_DEV,STATUSID,CHANNEL,ACTIVE)" + "values(@DEV_NAME,@DEV_CODE,@DEV_TYPEID,@DEV_MODEL,@REG_TIME,@CUSTOMER_NAME,@CUSTOMER_DEV,@STATUSID,@CHANNEL,@ACTIVE)"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@DEV_NAME", MySqlDbType.String, 30).Value = devName; cmd.Parameters.Add("@DEV_CODE", MySqlDbType.String, 30).Value = devCode; cmd.Parameters.Add("@DEV_TYPEID", MySqlDbType.String, 30).Value = devTypeId; cmd.Parameters.Add("@DEV_MODEL", MySqlDbType.String, 30).Value = devModel; cmd.Parameters.Add("@REG_TIME", MySqlDbType.Date, 0).Value = DateTime.Now; cmd.Parameters.Add("@CUSTOMER_NAME", MySqlDbType.String, 30).Value = customerName; cmd.Parameters.Add("@CUSTOMER_DEV", MySqlDbType.String, 30).Value = custometDev; cmd.Parameters.Add("@STATUSID", MySqlDbType.String, 20).Value = statusId; cmd.Parameters.Add("@CHANNEL", MySqlDbType.String, 20).Value = channel; cmd.Parameters.Add("@ACTIVE", MySqlDbType.Int64, 0).Value = 0; cmd.ExecuteNonQuery(); sQry = "SELECT max(ID) from r_device"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); using (MySqlDataReader aReader = cmd.ExecuteReader()) { if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); aReader.Close(); } cmd.Dispose(); } catch (MySqlException ex) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "addDeviced : " + ex.Message); deviceId = -1; } return deviceId; } public int update(long id, string devName, string devCode, string devTypeId, string devModel, string custometDev, string customerName, string channel, string statusId) { int iRetval = -1; try { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "updateDeviced : 数据库链接断开"); iRetval = DbConnectService.openDb(); if (iRetval != 0) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重连失败!"); return iRetval; } } string sQry = "UPDATE r_device SET DEV_NAME=@DEV_NAME, DEV_CODE=@DEV_CODE ,DEV_TYPEID=@DEV_TYPEID ,DEV_MODEL=@DEV_MODEL ,CUSTOMER_NAME=@CUSTOMER_NAME ,CUSTOMER_DEV=@CUSTOMER_DEV ,CHANNEL=@CHANNEL "; if (!statusId.Equals("")) sQry = sQry + ", STATUSID=@STATUSID"; sQry = sQry+ " WHERE ID = " + id; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@DEV_NAME", MySqlDbType.String, 30).Value = devName; cmd.Parameters.Add("@DEV_CODE", MySqlDbType.String, 30).Value = devCode; cmd.Parameters.Add("@DEV_TYPEID", MySqlDbType.String, 30).Value = devTypeId; cmd.Parameters.Add("@DEV_MODEL", MySqlDbType.String, 30).Value = devModel; cmd.Parameters.Add("@CUSTOMER_NAME", MySqlDbType.String, 30).Value = customerName; cmd.Parameters.Add("@CUSTOMER_DEV", MySqlDbType.String, 30).Value = custometDev; cmd.Parameters.Add("@CHANNEL", MySqlDbType.String, 20).Value = channel; if (!statusId.Equals("")) cmd.Parameters.Add("@STATUSID", MySqlDbType.String, 20).Value = statusId; cmd.ExecuteNonQuery(); cmd.Dispose(); iRetval = 0; } catch (MySqlException ex) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "updateDeviced : " + ex.Message); } return iRetval; } public int delete(long id) { int iRetval = -1; try { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "deleteDeviced : 数据库链接断开"); iRetval = DbConnectService.openDb(); if (iRetval != 0) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重连失败!"); return iRetval; } } string sQry = "UPDATE r_device SET ACTIVE = 1 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; } public List<DeviceDto> search(string devName, string devCode, string devModel, string suctomerDev, string customerName, string statusId) { List<DeviceDto> deviceDtoList = new List<DeviceDto>(); DictService dictService = new DictServiceImpl(); try { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDevice : 数据库链接断开"); int iRetval = DbConnectService.openDb(); if (iRetval != 0) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重连失败!"); return null; } } string sQry = "SELECT * FROM r_device where active = " + 0; if (devName != "" && devName != null) sQry += " and DEV_NAME = '" + devName + "'"; if (devCode != "" && devCode != null) sQry += " and DEV_CODE like '%" + devCode + "%'"; if (devModel != "" && devModel != null) sQry += " and DEV_MODEL like '%" + devModel + "%'"; if (suctomerDev != "" && suctomerDev != null) sQry += " and CUSTOMER_DEV like '%" + suctomerDev + "%'"; if (customerName != "" && customerName != null) sQry += " and CUSTOMER_NAME like '%" + customerName + "%'"; if (statusId != "" && statusId != null) { if(statusId.Equals("4")) sQry += " and STATUSID != 2 "; else sQry += " and STATUSID = " + statusId; } MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) { DeviceDto deviceDto = new DeviceDto(); if (!aReader.IsDBNull(0)) deviceDto.Id = Convert.ToInt64(aReader.GetString(0)); if (!aReader.IsDBNull(1)) deviceDto.DevName = aReader.GetString(1); if (!aReader.IsDBNull(2)) deviceDto.DevCode = aReader.GetString(2); if (!aReader.IsDBNull(3)) { deviceDto.DevTypeId = aReader.GetString(3); } if (!aReader.IsDBNull(4)) deviceDto.DevModel = aReader.GetString(4); if (!aReader.IsDBNull(6)) deviceDto.CustomerName = aReader.GetString(6); if (!aReader.IsDBNull(7)) deviceDto.CustomerDev = aReader.GetString(7); if (!aReader.IsDBNull(8)) { deviceDto.StatusId = aReader.GetString(8); } if (!aReader.IsDBNull(9)) deviceDto.Channel = aReader.GetString(9); deviceDtoList.Add(deviceDto); } aReader.Close(); } aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) { deviceDto.DevTypeName = dictService.getNameByCode("devType", deviceDto.DevTypeId); deviceDto.StatusName = dictService.getNameByCode("devStatus", deviceDto.StatusId); } } } catch (MySqlException ex) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDevice: " + ex.Message); deviceDtoList = null; } return deviceDtoList; } public List<DeviceDto> getAllCounter() { List<DeviceDto> deviceDtoList = new List<DeviceDto>(); DictService dictService = new DictServiceImpl(); try { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDevice : 数据库链接断开"); int iRetval = DbConnectService.openDb(); if (iRetval != 0) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重连失败!"); return null; } } string sQry = "SELECT * FROM r_device where active = " + 0 + " and DEV_TYPEID='2'"; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); //MySqlDataAdapter adap = new MySqlDataAdapter(aCommand); //DataTable dt = new DataTable(); //adap.Fill(dt); //aCommand.Dispose(); //adap.Dispose(); //if (dt != null && dt.Rows.Count > 0) //{ // foreach (DataRow row in dt.Rows) // { // DeviceDto deviceDto = new DeviceDto(); // if (row[0] != DBNull.Value) deviceDto.Id = Convert.ToInt64(row[0]); // if (row[1] != DBNull.Value) deviceDto.DevName = row[1].ToString(); // if (row[2] != DBNull.Value) deviceDto.DevCode = row[2].ToString(); // if (row[3] != DBNull.Value) deviceDto.DevTypeId = row[3].ToString(); // if (row[4] != DBNull.Value) deviceDto.DevModel = row[4].ToString(); // if (row[5] != DBNull.Value) deviceDto.RegTime = Convert.ToDateTime(row[5]).ToString("yyyy-MM-dd"); // if (row[6] != DBNull.Value) deviceDto.CustomerName = row[6].ToString(); // if (row[7] != DBNull.Value) deviceDto.CustomerDev = row[7].ToString(); // if (row[8] != DBNull.Value) deviceDto.StatusId = row[8].ToString(); // if (row[9] != DBNull.Value) deviceDto.Channel = row[9].ToString(); // deviceDtoList.Add(deviceDto); // } //} using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) { DeviceDto deviceDto = new DeviceDto(); if (!aReader.IsDBNull(0)) deviceDto.Id = Convert.ToInt64(aReader.GetString(0)); if (!aReader.IsDBNull(1)) deviceDto.DevName = aReader.GetString(1); if (!aReader.IsDBNull(2)) deviceDto.DevCode = aReader.GetString(2); if (!aReader.IsDBNull(3)) { deviceDto.DevTypeId = aReader.GetString(3); } if (!aReader.IsDBNull(4)) deviceDto.DevModel = aReader.GetString(4); if (!aReader.IsDBNull(5)) deviceDto.CustomerName = aReader.GetString(6); if (!aReader.IsDBNull(6)) deviceDto.CustomerDev = aReader.GetString(7); if (!aReader.IsDBNull(7)) { deviceDto.StatusId = aReader.GetString(8); } if (!aReader.IsDBNull(9)) deviceDto.Channel = aReader.GetString(9); deviceDtoList.Add(deviceDto); } aReader.Close(); } aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) { deviceDto.DevTypeName = dictService.getNameByCode("devType", deviceDto.DevTypeId); deviceDto.StatusName = dictService.getNameByCode("devStatus", deviceDto.StatusId); } } } catch (MySqlException ex) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDevice: " + ex.Message); deviceDtoList = null; } return deviceDtoList; } public List<DeviceDto> searchPage(string devName, string devCode, string devModel, string customDev, string customerName, string statusId, int page, int limit) { List<DeviceDto> deviceDtoList = new List<DeviceDto>(); DictService dictService = new DictServiceImpl(); try { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDevice : 数据库链接断开"); int iRetval = DbConnectService.openDb(); if (iRetval != 0) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重连失败!"); return null; } } string sQry = "SELECT * FROM r_device where active = " + 0; if (devName != "" && devName != null) sQry += " and DEV_NAME like '%" + devName + "%'"; if (devCode != "" && devCode != null) sQry += " and DEV_CODE like '%" + devCode + "%'"; if (devModel != "" && devModel != null) sQry += " and DEV_MODEL like '%" + devModel + "%'"; if (customDev != "" && customDev != null) sQry += " and CUSTOMER_DEV like '%" + customDev + "%'"; if (customerName != "" && customerName != null) sQry += " and CUSTOMER_NAME like '%" + customerName + "%'"; if (statusId != "" && statusId != null) { if(statusId.Equals("4")) sQry += " and STATUSID != 2"; else sQry += " and STATUSID = " + statusId; } sQry += " order by ID desc limit " + (page - 1) * limit+ " , "+ limit; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); //MySqlDataAdapter adap = new MySqlDataAdapter(aCommand); //DataTable dt = new DataTable(); //adap.Fill(dt); //aCommand.Dispose(); //adap.Dispose(); //if (dt != null && dt.Rows.Count > 0) //{ // foreach (DataRow row in dt.Rows) // { // DeviceDto deviceDto = new DeviceDto(); // if (row[0] != DBNull.Value) deviceDto.Id = Convert.ToInt64(row[0]); // if (row[1] != DBNull.Value) deviceDto.DevName = row[1].ToString(); // if (row[2] != DBNull.Value) deviceDto.DevCode = row[2].ToString(); // if (row[3] != DBNull.Value) deviceDto.DevTypeId = row[3].ToString(); // if (row[4] != DBNull.Value) deviceDto.DevModel = row[4].ToString(); // if (row[5] != DBNull.Value) deviceDto.RegTime = Convert.ToDateTime(row[5]).ToString("yyyy-MM-dd"); // if (row[6] != DBNull.Value) deviceDto.CustomerName = row[6].ToString(); // if (row[7] != DBNull.Value) deviceDto.CustomerDev = row[7].ToString(); // if (row[8] != DBNull.Value) deviceDto.StatusId = row[8].ToString(); // if (row[9] != DBNull.Value) deviceDto.Channel = row[9].ToString(); // deviceDtoList.Add(deviceDto); // } //} using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) { DeviceDto deviceDto = new DeviceDto(); if (!aReader.IsDBNull(0)) deviceDto.Id = Convert.ToInt64(aReader.GetString(0)); // id if (!aReader.IsDBNull(1)) deviceDto.DevName = aReader.GetString(1); // devName if (!aReader.IsDBNull(2)) deviceDto.DevCode = aReader.GetString(2); // devCode if (!aReader.IsDBNull(3)) { deviceDto.DevTypeId = aReader.GetString(3); // devType } if (!aReader.IsDBNull(4)) deviceDto.DevModel = aReader.GetString(4); // devModel if (!aReader.IsDBNull(5)) { DateTime reg = aReader.GetDateTime(5); // regTime deviceDto.RegTime = reg.ToString("yyyy-MM-dd"); } if (!aReader.IsDBNull(6)) deviceDto.CustomerName = aReader.GetString(6); // customName if (!aReader.IsDBNull(7)) deviceDto.CustomerDev = aReader.GetString(7); // customDev if (!aReader.IsDBNull(8)) { deviceDto.StatusId = aReader.GetString(8); // devStatus } if (!aReader.IsDBNull(9)) deviceDto.Channel = aReader.GetString(9); deviceDtoList.Add(deviceDto); } aReader.Close(); } aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) { deviceDto.DevTypeName = dictService.getNameByCode("devType", deviceDto.DevTypeId); deviceDto.StatusName = dictService.getNameByCode("devStatus", deviceDto.StatusId); } } } catch (MySqlException ex) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDevice: " + ex.Message); deviceDtoList = null; } finally { } return deviceDtoList; } public int getTotalCount(string devName, string devCode, string devModel, string customDev, string customerName, string statusId) { int totalCount = 0; try { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDevice : 数据库链接断开"); int iRetval = DbConnectService.openDb(); if (iRetval != 0) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重连失败!"); return iRetval; } } string sQry = "SELECT count(id) FROM r_device where active = " + 0; if (devName != "" && devName != null) sQry += " and DEV_NAME like '%" + devName + "%'"; if (devCode != "" && devCode != null) sQry += " and DEV_CODE like '%" + devCode + "%'"; if (devModel != "" && devModel != null) sQry += " and DEV_MODEL like '%" + devModel + "%'"; if (customDev != "" && customDev != null) sQry += " and CUSTOMER_DEV like '%" + customDev + "%'"; if (customerName != "" && customerName != null) sQry += " and CUSTOMER_NAME like '%" + customerName + "%'"; if (statusId != "" && statusId != null) { if (statusId.Equals("4")) sQry += " and STATUSID != 2"; else sQry += " and STATUSID = " + statusId; } MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) { totalCount = aReader.GetInt32(0); } aReader.Close(); } aCommand.Dispose(); } catch (MySqlException ex) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getTotalCount: " + ex.Message); totalCount = 0; } finally { } return totalCount; } public List<DeviceView> getDeviceByChannel() { List<DeviceView> deviceViewList = new List<DeviceView>(); DictService dictService = new DictServiceImpl(); try { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDevice : 数据库链接断开"); int iRetval = DbConnectService.openDb(); if (iRetval != 0) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重连失败!"); return null; } } DataTable dt = new DataTable(); //string sQry = "SELECT * FROM r_deviceview where ACTIVE = 0 and STATUSID = 2 " + "and ('" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' < END_TIME)"; string sQry = "select a.ID,a.DEV_NAME,a.DEV_CODE,a.DEV_TYPEID,a.DEV_MODEL,a.REG_TIME,a.CUSTOMER_NAME," + " a.CUSTOMER_DEV,a.CHANNEL,a.ACTIVE,b.START_TIME,b.END_TIME,a.STATUSID,b.STABILITY,b.ACCURACY,b.BOOT_FEATURE," + "b.AGE_RATE,b.ID as DETECTION_ITEM_ID from r_device a join r_detection_item b on (a.ID = b.DEVICE_ID and a.ACTIVE = 0 and a.STATUSID = '2' and ('" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' < b.END_TIME))"; //string sQry = "select a.ID,a.DEV_NAME,a.DEV_CODE,a.DEV_TYPEID,a.DEV_MODEL,a.REG_TIME,a.CUSTOMER_NAME," + // " a.CUSTOMER_DEV,a.CHANNEL,a.ACTIVE,b.START_TIME,b.END_TIME,a.STATUSID,b.STABILITY,b.ACCURACY,b.BOOT_FEATURE," + // "b.AGE_RATE,b.ID as DETECTION_ITEM_ID from r_device a join r_detection_item b on (a.ID = b.DEVICE_ID and a.ACTIVE = 0 and a.STATUSID = '2'"; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) { DeviceView deviceView = new DeviceView(); if (!aReader.IsDBNull(0)) deviceView.Id = Convert.ToInt64(aReader.GetString(0)); // id if (!aReader.IsDBNull(1)) deviceView.DevName = aReader.GetString(1); // devName if (!aReader.IsDBNull(2)) deviceView.DevCode = aReader.GetString(2); // devCode if (!aReader.IsDBNull(3)) deviceView.DevTypeId = aReader.GetString(3); // devType if (!aReader.IsDBNull(4)) deviceView.DevModel = aReader.GetString(4); // devModel if (!aReader.IsDBNull(5)) deviceView.RegTime = aReader.GetDateTime(5).ToString("yyyy-MM-dd"); if (!aReader.IsDBNull(6)) deviceView.CustomerName = aReader.GetString(6); // customName if (!aReader.IsDBNull(7)) deviceView.CustomerDev = aReader.GetString(7); // customDev if (!aReader.IsDBNull(8)) deviceView.Channel = aReader.GetString(8); // devStatus if (!aReader.IsDBNull(9)) deviceView.Active = Convert.ToInt32(aReader.GetString(9)); if (!aReader.IsDBNull(10)) deviceView.StartTime = aReader.GetDateTime(10).ToString("yyyy-MM-dd HH:mm:ss"); if (!aReader.IsDBNull(11)) deviceView.EndTime = aReader.GetDateTime(11).ToString("yyyy-MM-dd HH:mm:ss"); if (!aReader.IsDBNull(12)) deviceView.StatusId = aReader.GetString(12); if (!aReader.IsDBNull(13)) deviceView.Stability = aReader.GetString(13); if (!aReader.IsDBNull(14)) deviceView.Accuracy = aReader.GetString(14); if (!aReader.IsDBNull(15)) deviceView.BootFeature = aReader.GetString(15); if (!aReader.IsDBNull(16)) deviceView.AgeRate = aReader.GetString(16); if (!aReader.IsDBNull(17)) deviceView.DetectionItemId = aReader.GetInt64(17); deviceViewList.Add(deviceView); } aReader.Close(); } aCommand.Dispose(); if (deviceViewList.Count > 0) { foreach (DeviceView deviceView in deviceViewList) { deviceView.DevTypeName = dictService.getNameByCode("devType", deviceView.DevTypeId); } } } catch (MySqlException e) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getDeviceByChannel: " + e.Message + " ; " + e.ToString()); deviceViewList = null; } catch (Exception ex) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getDeviceByChannel: " + ex.Message + " ; " + ex.ToString()); deviceViewList = null; } finally { } return deviceViewList; } public int updateStatus(long id, string status, string channel) { int iRetval = -1; try { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "updateDeviced : 数据库链接断开"); iRetval = DbConnectService.openDb(); if (iRetval != 0) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重连失败!"); return iRetval; } } string sQry = "UPDATE r_device SET STATUSID=@STATUS, CHANNEL=@CHANNEL WHERE ID = " + id; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@STATUS", MySqlDbType.String, 30).Value = status; cmd.Parameters.Add("@CHANNEL", MySqlDbType.String, 30).Value = channel; cmd.ExecuteNonQuery(); cmd.Dispose(); iRetval = 0; } catch (MySqlException ex) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "updateDeviced : " + ex.Message); } return iRetval; } public int clearChannel() { int iRetval = -1; try { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "clearChannel : 数据库链接断开"); iRetval = DbConnectService.openDb(); if (iRetval != 0) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重连失败!"); return iRetval; } } string sQry = "UPDATE r_device SET CHANNEL=''"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); sQry = "UPDATE r_device SET STATUSID='1' WHERE STATUSID='2'"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); cmd.Dispose(); iRetval = 0; } catch (MySqlException ex) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "clearChannel : " + ex.Message); } return iRetval; } } }