diff --git a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs index 963b90b..a5e9368 100644 --- a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs +++ b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs @@ -29,7 +29,7 @@ + ";password=" + databasePassword + ";Charset=utf8" + ";Allow User Variables=True" - + ";Pooling=true"; + + ";Pooling=True"; mySqlConnect = new MySqlConnection(sConnection); mySqlConnect.Open(); iRetval = 0; diff --git a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs index 963b90b..a5e9368 100644 --- a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs +++ b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs @@ -29,7 +29,7 @@ + ";password=" + databasePassword + ";Charset=utf8" + ";Allow User Variables=True" - + ";Pooling=true"; + + ";Pooling=True"; mySqlConnect = new MySqlConnection(sConnection); mySqlConnect.Open(); iRetval = 0; diff --git a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs index c69559f..f19bd95 100644 --- a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs +++ b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs @@ -38,6 +38,7 @@ private string stability10; private string stability20; private string stability100; + private string isDetecting; public long Id { get @@ -161,5 +162,6 @@ public string Stability20 { get => stability20; set => stability20 = value; } public string Stability100 { get => stability100; set => stability100 = value; } public string Stability1 { get => stability1; set => stability1 = value; } + public string IsDetecting { get => isDetecting; set => isDetecting = value; } } } \ No newline at end of file diff --git a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs index 963b90b..a5e9368 100644 --- a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs +++ b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs @@ -29,7 +29,7 @@ + ";password=" + databasePassword + ";Charset=utf8" + ";Allow User Variables=True" - + ";Pooling=true"; + + ";Pooling=True"; mySqlConnect = new MySqlConnection(sConnection); mySqlConnect.Open(); iRetval = 0; diff --git a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs index c69559f..f19bd95 100644 --- a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs +++ b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs @@ -38,6 +38,7 @@ private string stability10; private string stability20; private string stability100; + private string isDetecting; public long Id { get @@ -161,5 +162,6 @@ public string Stability20 { get => stability20; set => stability20 = value; } public string Stability100 { get => stability100; set => stability100 = value; } public string Stability1 { get => stability1; set => stability1 = value; } + public string IsDetecting { get => isDetecting; set => isDetecting = value; } } } \ No newline at end of file diff --git a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs index 399098b..781749c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs @@ -9,7 +9,7 @@ { interface DetectionService { - int add(long deviceId, string frequency, string detecItemType, long detectionItemId); + int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time); List search(long deviceId, string detectionType, string startTime, string endTime, long detectionItemId); diff --git a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs index 963b90b..a5e9368 100644 --- a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs +++ b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs @@ -29,7 +29,7 @@ + ";password=" + databasePassword + ";Charset=utf8" + ";Allow User Variables=True" - + ";Pooling=true"; + + ";Pooling=True"; mySqlConnect = new MySqlConnection(sConnection); mySqlConnect.Open(); iRetval = 0; diff --git a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs index c69559f..f19bd95 100644 --- a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs +++ b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs @@ -38,6 +38,7 @@ private string stability10; private string stability20; private string stability100; + private string isDetecting; public long Id { get @@ -161,5 +162,6 @@ public string Stability20 { get => stability20; set => stability20 = value; } public string Stability100 { get => stability100; set => stability100 = value; } public string Stability1 { get => stability1; set => stability1 = value; } + public string IsDetecting { get => isDetecting; set => isDetecting = value; } } } \ No newline at end of file diff --git a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs index 399098b..781749c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs @@ -9,7 +9,7 @@ { interface DetectionService { - int add(long deviceId, string frequency, string detecItemType, long detectionItemId); + int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time); List search(long deviceId, string detectionType, string startTime, string endTime, long detectionItemId); diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs index 0fd7b24..4df249b 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs @@ -132,7 +132,30 @@ string sQry = "SELECT * FROM r_counter_check_params"; 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) + // { + // if (row[0] != DBNull.Value) counterCheckParam.Id = Convert.ToInt32(row[0]); + // if (row[1] != DBNull.Value) counterCheckParam.SoOutDelay = row[1].ToString(); + // if (row[2] != DBNull.Value) counterCheckParam.SoEleFrequency = row[2].ToString(); + // if (row[3] != DBNull.Value) counterCheckParam.SoEleAddValue = row[3].ToString(); + // if (row[4] != DBNull.Value) counterCheckParam.SoEleAlarm = row[4].ToString(); + // if (row[5] != DBNull.Value) counterCheckParam.FreThreshold1 = row[5].ToString(); + // if (row[6] != DBNull.Value) counterCheckParam.FreThreshold2 = row[6].ToString(); + // if (row[7] != DBNull.Value) counterCheckParam.FreEleAddValue = row[7].ToString(); + // if (row[8] != DBNull.Value) counterCheckParam.CycThreshold1 = row[8].ToString(); + // if (row[9] != DBNull.Value) counterCheckParam.CycThreshold2 = row[9].ToString(); + // if (row[10] != DBNull.Value) counterCheckParam.CycEleAddValue = row[10].ToString(); + + // } + //} using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -149,10 +172,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(Exception ex) { diff --git a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs index 963b90b..a5e9368 100644 --- a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs +++ b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs @@ -29,7 +29,7 @@ + ";password=" + databasePassword + ";Charset=utf8" + ";Allow User Variables=True" - + ";Pooling=true"; + + ";Pooling=True"; mySqlConnect = new MySqlConnection(sConnection); mySqlConnect.Open(); iRetval = 0; diff --git a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs index c69559f..f19bd95 100644 --- a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs +++ b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs @@ -38,6 +38,7 @@ private string stability10; private string stability20; private string stability100; + private string isDetecting; public long Id { get @@ -161,5 +162,6 @@ public string Stability20 { get => stability20; set => stability20 = value; } public string Stability100 { get => stability100; set => stability100 = value; } public string Stability1 { get => stability1; set => stability1 = value; } + public string IsDetecting { get => isDetecting; set => isDetecting = value; } } } \ No newline at end of file diff --git a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs index 399098b..781749c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs @@ -9,7 +9,7 @@ { interface DetectionService { - int add(long deviceId, string frequency, string detecItemType, long detectionItemId); + int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time); List search(long deviceId, string detectionType, string startTime, string endTime, long detectionItemId); diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs index 0fd7b24..4df249b 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs @@ -132,7 +132,30 @@ string sQry = "SELECT * FROM r_counter_check_params"; 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) + // { + // if (row[0] != DBNull.Value) counterCheckParam.Id = Convert.ToInt32(row[0]); + // if (row[1] != DBNull.Value) counterCheckParam.SoOutDelay = row[1].ToString(); + // if (row[2] != DBNull.Value) counterCheckParam.SoEleFrequency = row[2].ToString(); + // if (row[3] != DBNull.Value) counterCheckParam.SoEleAddValue = row[3].ToString(); + // if (row[4] != DBNull.Value) counterCheckParam.SoEleAlarm = row[4].ToString(); + // if (row[5] != DBNull.Value) counterCheckParam.FreThreshold1 = row[5].ToString(); + // if (row[6] != DBNull.Value) counterCheckParam.FreThreshold2 = row[6].ToString(); + // if (row[7] != DBNull.Value) counterCheckParam.FreEleAddValue = row[7].ToString(); + // if (row[8] != DBNull.Value) counterCheckParam.CycThreshold1 = row[8].ToString(); + // if (row[9] != DBNull.Value) counterCheckParam.CycThreshold2 = row[9].ToString(); + // if (row[10] != DBNull.Value) counterCheckParam.CycEleAddValue = row[10].ToString(); + + // } + //} using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -149,10 +172,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(Exception ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs index 52b36f8..2c60ab4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs @@ -32,28 +32,29 @@ //先查询是否有历史数据 string sQry = "select ID from r_counter_data where DEVICE_ID=" + deviceId + " and OUT_VALUE = '" + outValue + "'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - - if (aReader.Read()) + bool isUpdated = false; + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - dataId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) + { + dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + + " where ID=" + dataId; + + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; + cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; + cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; + + cmd.ExecuteNonQuery(); + isUpdated = true; + } aReader.Close(); - sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + - " where ID="+ dataId; - - cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; - cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; - cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; - cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; - - cmd.ExecuteNonQuery(); - } - else - { - aReader.Close(); - + if (!isUpdated) + { sQry = "INSERT INTO r_counter_data (DEVICE_ID, OUT_VALUE, VALUE, SENSITIVITY, LOG_TIME, DETEC_TYPE)" + "values(@DEVICE_ID,@OUT_VALUE,@VALUE,@SENSITIVITY,@LOG_TIME,@DETEC_TYPE)"; @@ -70,14 +71,14 @@ sQry = "SELECT max(ID) from r_counter_data"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - - aReader = cmd.ExecuteReader(); - - if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); - + using (MySqlDataReader aReader = cmd.ExecuteReader()) + { + + if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + } } - aReader.Close(); cmd.Dispose(); iRetval = 0; @@ -144,6 +145,8 @@ cmd.ExecuteNonQuery(); } + + aReader.Close(); } @@ -282,9 +285,10 @@ if (!aReader.IsDBNull(6)) counterData.DetecType = aReader.GetString(6); counterDataList.Add(counterData); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs index 963b90b..a5e9368 100644 --- a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs +++ b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs @@ -29,7 +29,7 @@ + ";password=" + databasePassword + ";Charset=utf8" + ";Allow User Variables=True" - + ";Pooling=true"; + + ";Pooling=True"; mySqlConnect = new MySqlConnection(sConnection); mySqlConnect.Open(); iRetval = 0; diff --git a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs index c69559f..f19bd95 100644 --- a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs +++ b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs @@ -38,6 +38,7 @@ private string stability10; private string stability20; private string stability100; + private string isDetecting; public long Id { get @@ -161,5 +162,6 @@ public string Stability20 { get => stability20; set => stability20 = value; } public string Stability100 { get => stability100; set => stability100 = value; } public string Stability1 { get => stability1; set => stability1 = value; } + public string IsDetecting { get => isDetecting; set => isDetecting = value; } } } \ No newline at end of file diff --git a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs index 399098b..781749c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs @@ -9,7 +9,7 @@ { interface DetectionService { - int add(long deviceId, string frequency, string detecItemType, long detectionItemId); + int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time); List search(long deviceId, string detectionType, string startTime, string endTime, long detectionItemId); diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs index 0fd7b24..4df249b 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs @@ -132,7 +132,30 @@ string sQry = "SELECT * FROM r_counter_check_params"; 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) + // { + // if (row[0] != DBNull.Value) counterCheckParam.Id = Convert.ToInt32(row[0]); + // if (row[1] != DBNull.Value) counterCheckParam.SoOutDelay = row[1].ToString(); + // if (row[2] != DBNull.Value) counterCheckParam.SoEleFrequency = row[2].ToString(); + // if (row[3] != DBNull.Value) counterCheckParam.SoEleAddValue = row[3].ToString(); + // if (row[4] != DBNull.Value) counterCheckParam.SoEleAlarm = row[4].ToString(); + // if (row[5] != DBNull.Value) counterCheckParam.FreThreshold1 = row[5].ToString(); + // if (row[6] != DBNull.Value) counterCheckParam.FreThreshold2 = row[6].ToString(); + // if (row[7] != DBNull.Value) counterCheckParam.FreEleAddValue = row[7].ToString(); + // if (row[8] != DBNull.Value) counterCheckParam.CycThreshold1 = row[8].ToString(); + // if (row[9] != DBNull.Value) counterCheckParam.CycThreshold2 = row[9].ToString(); + // if (row[10] != DBNull.Value) counterCheckParam.CycEleAddValue = row[10].ToString(); + + // } + //} using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -149,10 +172,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(Exception ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs index 52b36f8..2c60ab4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs @@ -32,28 +32,29 @@ //先查询是否有历史数据 string sQry = "select ID from r_counter_data where DEVICE_ID=" + deviceId + " and OUT_VALUE = '" + outValue + "'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - - if (aReader.Read()) + bool isUpdated = false; + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - dataId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) + { + dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + + " where ID=" + dataId; + + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; + cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; + cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; + + cmd.ExecuteNonQuery(); + isUpdated = true; + } aReader.Close(); - sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + - " where ID="+ dataId; - - cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; - cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; - cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; - cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; - - cmd.ExecuteNonQuery(); - } - else - { - aReader.Close(); - + if (!isUpdated) + { sQry = "INSERT INTO r_counter_data (DEVICE_ID, OUT_VALUE, VALUE, SENSITIVITY, LOG_TIME, DETEC_TYPE)" + "values(@DEVICE_ID,@OUT_VALUE,@VALUE,@SENSITIVITY,@LOG_TIME,@DETEC_TYPE)"; @@ -70,14 +71,14 @@ sQry = "SELECT max(ID) from r_counter_data"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - - aReader = cmd.ExecuteReader(); - - if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); - + using (MySqlDataReader aReader = cmd.ExecuteReader()) + { + + if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + } } - aReader.Close(); cmd.Dispose(); iRetval = 0; @@ -144,6 +145,8 @@ cmd.ExecuteNonQuery(); } + + aReader.Close(); } @@ -282,9 +285,10 @@ if (!aReader.IsDBNull(6)) counterData.DetecType = aReader.GetString(6); counterDataList.Add(counterData); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs index 6795325..7500bd4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs @@ -47,10 +47,11 @@ counterDetecInitList.Add(counterDetecInit); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -75,29 +76,31 @@ return iRetval; } } - string sQry = "select ID from r_counter_detec_init where FREQUENCY=" + frequency +" AND CYCLE="+cycle; + string sQry = "select ID from r_counter_detec_init where FREQUENCY='" + frequency +"' AND CYCLE='"+cycle+"'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - if (aReader.Read()) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - initId = Convert.ToInt64(aReader.GetString(0)); - sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; + if (aReader.Read()) + { + initId = Convert.ToInt64(aReader.GetString(0)); + sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; - 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(); - } - else - { - 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 = 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(); + } + else + { + 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.ExecuteNonQuery(); + + } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); iRetval = 0; } diff --git a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs index 963b90b..a5e9368 100644 --- a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs +++ b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs @@ -29,7 +29,7 @@ + ";password=" + databasePassword + ";Charset=utf8" + ";Allow User Variables=True" - + ";Pooling=true"; + + ";Pooling=True"; mySqlConnect = new MySqlConnection(sConnection); mySqlConnect.Open(); iRetval = 0; diff --git a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs index c69559f..f19bd95 100644 --- a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs +++ b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs @@ -38,6 +38,7 @@ private string stability10; private string stability20; private string stability100; + private string isDetecting; public long Id { get @@ -161,5 +162,6 @@ public string Stability20 { get => stability20; set => stability20 = value; } public string Stability100 { get => stability100; set => stability100 = value; } public string Stability1 { get => stability1; set => stability1 = value; } + public string IsDetecting { get => isDetecting; set => isDetecting = value; } } } \ No newline at end of file diff --git a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs index 399098b..781749c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs @@ -9,7 +9,7 @@ { interface DetectionService { - int add(long deviceId, string frequency, string detecItemType, long detectionItemId); + int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time); List search(long deviceId, string detectionType, string startTime, string endTime, long detectionItemId); diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs index 0fd7b24..4df249b 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs @@ -132,7 +132,30 @@ string sQry = "SELECT * FROM r_counter_check_params"; 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) + // { + // if (row[0] != DBNull.Value) counterCheckParam.Id = Convert.ToInt32(row[0]); + // if (row[1] != DBNull.Value) counterCheckParam.SoOutDelay = row[1].ToString(); + // if (row[2] != DBNull.Value) counterCheckParam.SoEleFrequency = row[2].ToString(); + // if (row[3] != DBNull.Value) counterCheckParam.SoEleAddValue = row[3].ToString(); + // if (row[4] != DBNull.Value) counterCheckParam.SoEleAlarm = row[4].ToString(); + // if (row[5] != DBNull.Value) counterCheckParam.FreThreshold1 = row[5].ToString(); + // if (row[6] != DBNull.Value) counterCheckParam.FreThreshold2 = row[6].ToString(); + // if (row[7] != DBNull.Value) counterCheckParam.FreEleAddValue = row[7].ToString(); + // if (row[8] != DBNull.Value) counterCheckParam.CycThreshold1 = row[8].ToString(); + // if (row[9] != DBNull.Value) counterCheckParam.CycThreshold2 = row[9].ToString(); + // if (row[10] != DBNull.Value) counterCheckParam.CycEleAddValue = row[10].ToString(); + + // } + //} using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -149,10 +172,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(Exception ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs index 52b36f8..2c60ab4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs @@ -32,28 +32,29 @@ //先查询是否有历史数据 string sQry = "select ID from r_counter_data where DEVICE_ID=" + deviceId + " and OUT_VALUE = '" + outValue + "'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - - if (aReader.Read()) + bool isUpdated = false; + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - dataId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) + { + dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + + " where ID=" + dataId; + + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; + cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; + cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; + + cmd.ExecuteNonQuery(); + isUpdated = true; + } aReader.Close(); - sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + - " where ID="+ dataId; - - cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; - cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; - cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; - cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; - - cmd.ExecuteNonQuery(); - } - else - { - aReader.Close(); - + if (!isUpdated) + { sQry = "INSERT INTO r_counter_data (DEVICE_ID, OUT_VALUE, VALUE, SENSITIVITY, LOG_TIME, DETEC_TYPE)" + "values(@DEVICE_ID,@OUT_VALUE,@VALUE,@SENSITIVITY,@LOG_TIME,@DETEC_TYPE)"; @@ -70,14 +71,14 @@ sQry = "SELECT max(ID) from r_counter_data"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - - aReader = cmd.ExecuteReader(); - - if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); - + using (MySqlDataReader aReader = cmd.ExecuteReader()) + { + + if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + } } - aReader.Close(); cmd.Dispose(); iRetval = 0; @@ -144,6 +145,8 @@ cmd.ExecuteNonQuery(); } + + aReader.Close(); } @@ -282,9 +285,10 @@ if (!aReader.IsDBNull(6)) counterData.DetecType = aReader.GetString(6); counterDataList.Add(counterData); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs index 6795325..7500bd4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs @@ -47,10 +47,11 @@ counterDetecInitList.Add(counterDetecInit); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -75,29 +76,31 @@ return iRetval; } } - string sQry = "select ID from r_counter_detec_init where FREQUENCY=" + frequency +" AND CYCLE="+cycle; + string sQry = "select ID from r_counter_detec_init where FREQUENCY='" + frequency +"' AND CYCLE='"+cycle+"'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - if (aReader.Read()) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - initId = Convert.ToInt64(aReader.GetString(0)); - sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; + if (aReader.Read()) + { + initId = Convert.ToInt64(aReader.GetString(0)); + sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; - 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(); - } - else - { - 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 = 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(); + } + else + { + 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.ExecuteNonQuery(); + + } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); iRetval = 0; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs index 97b06ba..abcbaa6 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs @@ -72,26 +72,27 @@ MySqlCommand cmd = new MySqlCommand(sql, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(CommandBehavior.Default); - - if (aReader != null) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) + if (aReader != null) { - //判断门的状态 - if (!aReader.IsDBNull(0)) - counterParam.Id = Convert.ToInt32(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) - counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) - counterParam.BaudRate = aReader.GetString(2); - if (!aReader.IsDBNull(3)) - counterParam.GeneratorIp = aReader.GetString(3); - if (!aReader.IsDBNull(4)) - counterParam.SignalSourceIp = aReader.GetString(4); + if (aReader.Read()) + { + //判断门的状态 + if (!aReader.IsDBNull(0)) + counterParam.Id = Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(1)) + counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); + if (!aReader.IsDBNull(2)) + counterParam.BaudRate = aReader.GetString(2); + if (!aReader.IsDBNull(3)) + counterParam.GeneratorIp = aReader.GetString(3); + if (!aReader.IsDBNull(4)) + counterParam.SignalSourceIp = aReader.GetString(4); + } } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); } diff --git a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs index 963b90b..a5e9368 100644 --- a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs +++ b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs @@ -29,7 +29,7 @@ + ";password=" + databasePassword + ";Charset=utf8" + ";Allow User Variables=True" - + ";Pooling=true"; + + ";Pooling=True"; mySqlConnect = new MySqlConnection(sConnection); mySqlConnect.Open(); iRetval = 0; diff --git a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs index c69559f..f19bd95 100644 --- a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs +++ b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs @@ -38,6 +38,7 @@ private string stability10; private string stability20; private string stability100; + private string isDetecting; public long Id { get @@ -161,5 +162,6 @@ public string Stability20 { get => stability20; set => stability20 = value; } public string Stability100 { get => stability100; set => stability100 = value; } public string Stability1 { get => stability1; set => stability1 = value; } + public string IsDetecting { get => isDetecting; set => isDetecting = value; } } } \ No newline at end of file diff --git a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs index 399098b..781749c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs @@ -9,7 +9,7 @@ { interface DetectionService { - int add(long deviceId, string frequency, string detecItemType, long detectionItemId); + int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time); List search(long deviceId, string detectionType, string startTime, string endTime, long detectionItemId); diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs index 0fd7b24..4df249b 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs @@ -132,7 +132,30 @@ string sQry = "SELECT * FROM r_counter_check_params"; 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) + // { + // if (row[0] != DBNull.Value) counterCheckParam.Id = Convert.ToInt32(row[0]); + // if (row[1] != DBNull.Value) counterCheckParam.SoOutDelay = row[1].ToString(); + // if (row[2] != DBNull.Value) counterCheckParam.SoEleFrequency = row[2].ToString(); + // if (row[3] != DBNull.Value) counterCheckParam.SoEleAddValue = row[3].ToString(); + // if (row[4] != DBNull.Value) counterCheckParam.SoEleAlarm = row[4].ToString(); + // if (row[5] != DBNull.Value) counterCheckParam.FreThreshold1 = row[5].ToString(); + // if (row[6] != DBNull.Value) counterCheckParam.FreThreshold2 = row[6].ToString(); + // if (row[7] != DBNull.Value) counterCheckParam.FreEleAddValue = row[7].ToString(); + // if (row[8] != DBNull.Value) counterCheckParam.CycThreshold1 = row[8].ToString(); + // if (row[9] != DBNull.Value) counterCheckParam.CycThreshold2 = row[9].ToString(); + // if (row[10] != DBNull.Value) counterCheckParam.CycEleAddValue = row[10].ToString(); + + // } + //} using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -149,10 +172,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(Exception ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs index 52b36f8..2c60ab4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs @@ -32,28 +32,29 @@ //先查询是否有历史数据 string sQry = "select ID from r_counter_data where DEVICE_ID=" + deviceId + " and OUT_VALUE = '" + outValue + "'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - - if (aReader.Read()) + bool isUpdated = false; + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - dataId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) + { + dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + + " where ID=" + dataId; + + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; + cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; + cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; + + cmd.ExecuteNonQuery(); + isUpdated = true; + } aReader.Close(); - sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + - " where ID="+ dataId; - - cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; - cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; - cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; - cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; - - cmd.ExecuteNonQuery(); - } - else - { - aReader.Close(); - + if (!isUpdated) + { sQry = "INSERT INTO r_counter_data (DEVICE_ID, OUT_VALUE, VALUE, SENSITIVITY, LOG_TIME, DETEC_TYPE)" + "values(@DEVICE_ID,@OUT_VALUE,@VALUE,@SENSITIVITY,@LOG_TIME,@DETEC_TYPE)"; @@ -70,14 +71,14 @@ sQry = "SELECT max(ID) from r_counter_data"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - - aReader = cmd.ExecuteReader(); - - if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); - + using (MySqlDataReader aReader = cmd.ExecuteReader()) + { + + if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + } } - aReader.Close(); cmd.Dispose(); iRetval = 0; @@ -144,6 +145,8 @@ cmd.ExecuteNonQuery(); } + + aReader.Close(); } @@ -282,9 +285,10 @@ if (!aReader.IsDBNull(6)) counterData.DetecType = aReader.GetString(6); counterDataList.Add(counterData); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs index 6795325..7500bd4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs @@ -47,10 +47,11 @@ counterDetecInitList.Add(counterDetecInit); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -75,29 +76,31 @@ return iRetval; } } - string sQry = "select ID from r_counter_detec_init where FREQUENCY=" + frequency +" AND CYCLE="+cycle; + string sQry = "select ID from r_counter_detec_init where FREQUENCY='" + frequency +"' AND CYCLE='"+cycle+"'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - if (aReader.Read()) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - initId = Convert.ToInt64(aReader.GetString(0)); - sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; + if (aReader.Read()) + { + initId = Convert.ToInt64(aReader.GetString(0)); + sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; - 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(); - } - else - { - 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 = 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(); + } + else + { + 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.ExecuteNonQuery(); + + } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); iRetval = 0; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs index 97b06ba..abcbaa6 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs @@ -72,26 +72,27 @@ MySqlCommand cmd = new MySqlCommand(sql, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(CommandBehavior.Default); - - if (aReader != null) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) + if (aReader != null) { - //判断门的状态 - if (!aReader.IsDBNull(0)) - counterParam.Id = Convert.ToInt32(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) - counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) - counterParam.BaudRate = aReader.GetString(2); - if (!aReader.IsDBNull(3)) - counterParam.GeneratorIp = aReader.GetString(3); - if (!aReader.IsDBNull(4)) - counterParam.SignalSourceIp = aReader.GetString(4); + if (aReader.Read()) + { + //判断门的状态 + if (!aReader.IsDBNull(0)) + counterParam.Id = Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(1)) + counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); + if (!aReader.IsDBNull(2)) + counterParam.BaudRate = aReader.GetString(2); + if (!aReader.IsDBNull(3)) + counterParam.GeneratorIp = aReader.GetString(3); + if (!aReader.IsDBNull(4)) + counterParam.SignalSourceIp = aReader.GetString(4); + } } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs index cca90fb..1578937 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs @@ -33,8 +33,8 @@ MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@DEVICE_ID", MySqlDbType.Int64, 20).Value = deviceId; - cmd.Parameters.Add("@START_TIME", MySqlDbType.String, 50).Value = startTime; - cmd.Parameters.Add("@END_TIME", MySqlDbType.String, 50).Value = endTime; + cmd.Parameters.Add("@START_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(startTime); + cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(endTime); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 50).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 50).Value = accuracy; cmd.Parameters.Add("@BOOT_FEATURE", MySqlDbType.String, 50).Value = bootFeature; @@ -58,11 +58,11 @@ sQry = "SELECT max(ID) from r_detection_item"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = cmd.ExecuteReader()) { if (aReader.Read()) detectionId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); iRetval = 0; @@ -203,8 +203,9 @@ if (!stability100.Equals("")) sQry = sQry + " STABILITY_100=@STABILITY_100,"; sQry = sQry + " COUNTER_DETEC=@COUNTER_DETEC where ID = " + detectionId; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry: " + sQry); - + MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 10).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 10).Value = accuracy; @@ -283,7 +284,8 @@ return iRetval; } } - + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "停止检测 detectionItemId=======" + detectionItemId); + string sQry = "UPDATE r_device SET STATUSID="+"1"+", CHANNEL=@CHANNEL where ID=" + deviceId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@CHANNEL", MySqlDbType.String, 20).Value = ""; @@ -292,19 +294,21 @@ if (isDeleteData) { - sQry = "DELETE FROM r_detection_item WHERE DEVICE_ID = " + deviceId + " AND START_TIME='" + startTime + "' AND END_TIME='" + endTime + "'"; + sQry = "DELETE FROM r_detection_item WHERE ID=" + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); - sQry = "DELETE FROM r_detection WHERE DEVICE_ID = " + deviceId + " AND (LOG_TIME between'" + startTime + "' and '" + endTime + "')"; + sQry = "DELETE FROM r_detection WHERE DETECTION_ITEM_ID = " + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); } else { - sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME WHERE ID="+ detectionItemId; + sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME, IS_DETECTING=@IS_DETECTING WHERE ID=" + detectionItemId; + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 20).Value = DateTime.Now; + cmd.Parameters.Add("@IS_DETECTING", MySqlDbType.String, 1).Value = "0"; //0-否,1-是 cmd.ExecuteNonQuery(); } @@ -322,8 +326,7 @@ { DetectionItem detectionItem = null; try - { - + { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getById : 数据库链接断开"); @@ -337,6 +340,7 @@ string sQry = "select * from r_detection_item WHERE ID = "+ detectionItemId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + using (MySqlDataReader aReader = cmd.ExecuteReader()) { while (aReader.Read()) @@ -356,11 +360,13 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(15)) detectionItem.IsDetecting = aReader.GetString(15); } - } - + aReader.Close(); + } cmd.Dispose(); + } catch (MySqlException e) { @@ -400,7 +406,7 @@ { DetectionItem detectionItem = new DetectionItem(); //姓名 - if (!aReader.IsDBNull(0)) detectionItem.Id=Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(0)) detectionItem.Id = Convert.ToInt32(aReader.GetString(0)); if (!aReader.IsDBNull(1)) detectionItem.DeviceId = Convert.ToInt64(aReader.GetString(1)); if (!aReader.IsDBNull(2)) detectionItem.StartTime = aReader.GetString(2); if (!aReader.IsDBNull(3)) detectionItem.EndTime = aReader.GetString(3); @@ -416,9 +422,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -468,9 +475,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -498,7 +506,6 @@ string sQry = "SELECT * FROM r_detection_item where ID = " + detectionId; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -518,15 +525,43 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); + //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) + // { + // detectionItem = new DetectionItem(); + // if (row[0] != DBNull.Value) detectionItem.Id = Convert.ToInt64(row[0]); + // if (row[1] != DBNull.Value) detectionItem.DeviceId = Convert.ToInt64(row[1]); + // if (row[2] != DBNull.Value) detectionItem.StartTime = Convert.ToDateTime(row[2]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[3] != DBNull.Value) detectionItem.EndTime = Convert.ToDateTime(row[3]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[4] != DBNull.Value) detectionItem.Stability = row[4].ToString(); + // if (row[5] != DBNull.Value) detectionItem.Accuracy = row[5].ToString(); + // if (row[6] != DBNull.Value) detectionItem.BootFeature = row[6].ToString(); + // if (row[7] != DBNull.Value) detectionItem.AgeRate = row[7].ToString(); + // if (row[8] != DBNull.Value) detectionItem.Interval = row[8].ToString(); + // if (row[10] != DBNull.Value) detectionItem.Channel = row[10].ToString(); + // if (row[11] != DBNull.Value) detectionItem.Stability1 = row[11].ToString(); + // if (row[12] != DBNull.Value) detectionItem.Stability10 = row[12].ToString(); + // if (row[13] != DBNull.Value) detectionItem.Stability20 = row[13].ToString(); + // if (row[14] != DBNull.Value) detectionItem.Stability100 = row[14].ToString(); + + // } + //} } catch (MySqlException ex) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDetectionItem: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchById: " + ex.Message); } return detectionItem; } diff --git a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs index 963b90b..a5e9368 100644 --- a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs +++ b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs @@ -29,7 +29,7 @@ + ";password=" + databasePassword + ";Charset=utf8" + ";Allow User Variables=True" - + ";Pooling=true"; + + ";Pooling=True"; mySqlConnect = new MySqlConnection(sConnection); mySqlConnect.Open(); iRetval = 0; diff --git a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs index c69559f..f19bd95 100644 --- a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs +++ b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs @@ -38,6 +38,7 @@ private string stability10; private string stability20; private string stability100; + private string isDetecting; public long Id { get @@ -161,5 +162,6 @@ public string Stability20 { get => stability20; set => stability20 = value; } public string Stability100 { get => stability100; set => stability100 = value; } public string Stability1 { get => stability1; set => stability1 = value; } + public string IsDetecting { get => isDetecting; set => isDetecting = value; } } } \ No newline at end of file diff --git a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs index 399098b..781749c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs @@ -9,7 +9,7 @@ { interface DetectionService { - int add(long deviceId, string frequency, string detecItemType, long detectionItemId); + int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time); List search(long deviceId, string detectionType, string startTime, string endTime, long detectionItemId); diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs index 0fd7b24..4df249b 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs @@ -132,7 +132,30 @@ string sQry = "SELECT * FROM r_counter_check_params"; 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) + // { + // if (row[0] != DBNull.Value) counterCheckParam.Id = Convert.ToInt32(row[0]); + // if (row[1] != DBNull.Value) counterCheckParam.SoOutDelay = row[1].ToString(); + // if (row[2] != DBNull.Value) counterCheckParam.SoEleFrequency = row[2].ToString(); + // if (row[3] != DBNull.Value) counterCheckParam.SoEleAddValue = row[3].ToString(); + // if (row[4] != DBNull.Value) counterCheckParam.SoEleAlarm = row[4].ToString(); + // if (row[5] != DBNull.Value) counterCheckParam.FreThreshold1 = row[5].ToString(); + // if (row[6] != DBNull.Value) counterCheckParam.FreThreshold2 = row[6].ToString(); + // if (row[7] != DBNull.Value) counterCheckParam.FreEleAddValue = row[7].ToString(); + // if (row[8] != DBNull.Value) counterCheckParam.CycThreshold1 = row[8].ToString(); + // if (row[9] != DBNull.Value) counterCheckParam.CycThreshold2 = row[9].ToString(); + // if (row[10] != DBNull.Value) counterCheckParam.CycEleAddValue = row[10].ToString(); + + // } + //} using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -149,10 +172,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(Exception ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs index 52b36f8..2c60ab4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs @@ -32,28 +32,29 @@ //先查询是否有历史数据 string sQry = "select ID from r_counter_data where DEVICE_ID=" + deviceId + " and OUT_VALUE = '" + outValue + "'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - - if (aReader.Read()) + bool isUpdated = false; + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - dataId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) + { + dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + + " where ID=" + dataId; + + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; + cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; + cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; + + cmd.ExecuteNonQuery(); + isUpdated = true; + } aReader.Close(); - sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + - " where ID="+ dataId; - - cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; - cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; - cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; - cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; - - cmd.ExecuteNonQuery(); - } - else - { - aReader.Close(); - + if (!isUpdated) + { sQry = "INSERT INTO r_counter_data (DEVICE_ID, OUT_VALUE, VALUE, SENSITIVITY, LOG_TIME, DETEC_TYPE)" + "values(@DEVICE_ID,@OUT_VALUE,@VALUE,@SENSITIVITY,@LOG_TIME,@DETEC_TYPE)"; @@ -70,14 +71,14 @@ sQry = "SELECT max(ID) from r_counter_data"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - - aReader = cmd.ExecuteReader(); - - if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); - + using (MySqlDataReader aReader = cmd.ExecuteReader()) + { + + if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + } } - aReader.Close(); cmd.Dispose(); iRetval = 0; @@ -144,6 +145,8 @@ cmd.ExecuteNonQuery(); } + + aReader.Close(); } @@ -282,9 +285,10 @@ if (!aReader.IsDBNull(6)) counterData.DetecType = aReader.GetString(6); counterDataList.Add(counterData); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs index 6795325..7500bd4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs @@ -47,10 +47,11 @@ counterDetecInitList.Add(counterDetecInit); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -75,29 +76,31 @@ return iRetval; } } - string sQry = "select ID from r_counter_detec_init where FREQUENCY=" + frequency +" AND CYCLE="+cycle; + string sQry = "select ID from r_counter_detec_init where FREQUENCY='" + frequency +"' AND CYCLE='"+cycle+"'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - if (aReader.Read()) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - initId = Convert.ToInt64(aReader.GetString(0)); - sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; + if (aReader.Read()) + { + initId = Convert.ToInt64(aReader.GetString(0)); + sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; - 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(); - } - else - { - 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 = 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(); + } + else + { + 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.ExecuteNonQuery(); + + } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); iRetval = 0; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs index 97b06ba..abcbaa6 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs @@ -72,26 +72,27 @@ MySqlCommand cmd = new MySqlCommand(sql, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(CommandBehavior.Default); - - if (aReader != null) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) + if (aReader != null) { - //判断门的状态 - if (!aReader.IsDBNull(0)) - counterParam.Id = Convert.ToInt32(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) - counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) - counterParam.BaudRate = aReader.GetString(2); - if (!aReader.IsDBNull(3)) - counterParam.GeneratorIp = aReader.GetString(3); - if (!aReader.IsDBNull(4)) - counterParam.SignalSourceIp = aReader.GetString(4); + if (aReader.Read()) + { + //判断门的状态 + if (!aReader.IsDBNull(0)) + counterParam.Id = Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(1)) + counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); + if (!aReader.IsDBNull(2)) + counterParam.BaudRate = aReader.GetString(2); + if (!aReader.IsDBNull(3)) + counterParam.GeneratorIp = aReader.GetString(3); + if (!aReader.IsDBNull(4)) + counterParam.SignalSourceIp = aReader.GetString(4); + } } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs index cca90fb..1578937 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs @@ -33,8 +33,8 @@ MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@DEVICE_ID", MySqlDbType.Int64, 20).Value = deviceId; - cmd.Parameters.Add("@START_TIME", MySqlDbType.String, 50).Value = startTime; - cmd.Parameters.Add("@END_TIME", MySqlDbType.String, 50).Value = endTime; + cmd.Parameters.Add("@START_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(startTime); + cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(endTime); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 50).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 50).Value = accuracy; cmd.Parameters.Add("@BOOT_FEATURE", MySqlDbType.String, 50).Value = bootFeature; @@ -58,11 +58,11 @@ sQry = "SELECT max(ID) from r_detection_item"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = cmd.ExecuteReader()) { if (aReader.Read()) detectionId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); iRetval = 0; @@ -203,8 +203,9 @@ if (!stability100.Equals("")) sQry = sQry + " STABILITY_100=@STABILITY_100,"; sQry = sQry + " COUNTER_DETEC=@COUNTER_DETEC where ID = " + detectionId; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry: " + sQry); - + MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 10).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 10).Value = accuracy; @@ -283,7 +284,8 @@ return iRetval; } } - + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "停止检测 detectionItemId=======" + detectionItemId); + string sQry = "UPDATE r_device SET STATUSID="+"1"+", CHANNEL=@CHANNEL where ID=" + deviceId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@CHANNEL", MySqlDbType.String, 20).Value = ""; @@ -292,19 +294,21 @@ if (isDeleteData) { - sQry = "DELETE FROM r_detection_item WHERE DEVICE_ID = " + deviceId + " AND START_TIME='" + startTime + "' AND END_TIME='" + endTime + "'"; + sQry = "DELETE FROM r_detection_item WHERE ID=" + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); - sQry = "DELETE FROM r_detection WHERE DEVICE_ID = " + deviceId + " AND (LOG_TIME between'" + startTime + "' and '" + endTime + "')"; + sQry = "DELETE FROM r_detection WHERE DETECTION_ITEM_ID = " + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); } else { - sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME WHERE ID="+ detectionItemId; + sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME, IS_DETECTING=@IS_DETECTING WHERE ID=" + detectionItemId; + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 20).Value = DateTime.Now; + cmd.Parameters.Add("@IS_DETECTING", MySqlDbType.String, 1).Value = "0"; //0-否,1-是 cmd.ExecuteNonQuery(); } @@ -322,8 +326,7 @@ { DetectionItem detectionItem = null; try - { - + { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getById : 数据库链接断开"); @@ -337,6 +340,7 @@ string sQry = "select * from r_detection_item WHERE ID = "+ detectionItemId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + using (MySqlDataReader aReader = cmd.ExecuteReader()) { while (aReader.Read()) @@ -356,11 +360,13 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(15)) detectionItem.IsDetecting = aReader.GetString(15); } - } - + aReader.Close(); + } cmd.Dispose(); + } catch (MySqlException e) { @@ -400,7 +406,7 @@ { DetectionItem detectionItem = new DetectionItem(); //姓名 - if (!aReader.IsDBNull(0)) detectionItem.Id=Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(0)) detectionItem.Id = Convert.ToInt32(aReader.GetString(0)); if (!aReader.IsDBNull(1)) detectionItem.DeviceId = Convert.ToInt64(aReader.GetString(1)); if (!aReader.IsDBNull(2)) detectionItem.StartTime = aReader.GetString(2); if (!aReader.IsDBNull(3)) detectionItem.EndTime = aReader.GetString(3); @@ -416,9 +422,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -468,9 +475,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -498,7 +506,6 @@ string sQry = "SELECT * FROM r_detection_item where ID = " + detectionId; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -518,15 +525,43 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); + //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) + // { + // detectionItem = new DetectionItem(); + // if (row[0] != DBNull.Value) detectionItem.Id = Convert.ToInt64(row[0]); + // if (row[1] != DBNull.Value) detectionItem.DeviceId = Convert.ToInt64(row[1]); + // if (row[2] != DBNull.Value) detectionItem.StartTime = Convert.ToDateTime(row[2]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[3] != DBNull.Value) detectionItem.EndTime = Convert.ToDateTime(row[3]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[4] != DBNull.Value) detectionItem.Stability = row[4].ToString(); + // if (row[5] != DBNull.Value) detectionItem.Accuracy = row[5].ToString(); + // if (row[6] != DBNull.Value) detectionItem.BootFeature = row[6].ToString(); + // if (row[7] != DBNull.Value) detectionItem.AgeRate = row[7].ToString(); + // if (row[8] != DBNull.Value) detectionItem.Interval = row[8].ToString(); + // if (row[10] != DBNull.Value) detectionItem.Channel = row[10].ToString(); + // if (row[11] != DBNull.Value) detectionItem.Stability1 = row[11].ToString(); + // if (row[12] != DBNull.Value) detectionItem.Stability10 = row[12].ToString(); + // if (row[13] != DBNull.Value) detectionItem.Stability20 = row[13].ToString(); + // if (row[14] != DBNull.Value) detectionItem.Stability100 = row[14].ToString(); + + // } + //} } catch (MySqlException ex) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDetectionItem: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchById: " + ex.Message); } return detectionItem; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs index e2a5893..5b3deb0 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs @@ -14,7 +14,7 @@ { class DetectionServiceImpl : DetectionService { - public int add(long deviceId, string frequency, string detecItemType, long detectionItemId) + public int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time) { int iRetval = -1; try @@ -36,7 +36,7 @@ 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 = DateTime.Now; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.DateTime, 0).Value = time; cmd.Parameters.Add("@DETECTION_ITEM", MySqlDbType.String, 0).Value = detecItemType; cmd.Parameters.Add("@DETECTION_ITEM_ID", MySqlDbType.Int64, 0).Value = detectionItemId; @@ -108,24 +108,26 @@ string sQry = "SELECT * FROM r_detection where DEVICE_ID = " + deviceId +" and DETECTION_ITEM='" + detectionType + "' and (LOG_TIME BETWEEN '" + startTime + "' and '"+ endTime + "') and DETECTION_ITEM_ID="+detectionItemId+" order by LOG_TIME"; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) { - Model.Detection detection = new Model.Detection(); - //姓名 - if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) detection.LogTime = Convert.ToDateTime(aReader.GetString(2)).ToString("yyyy-MM-dd HH:mm:ss"); - if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); - if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); + Detection detection = new Detection(); + + if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); // id + if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); // devName + if (!aReader.IsDBNull(2)) detection.LogTime = aReader.GetString(2); // devCode + if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); // devType + if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); // devModel detectionDtoList.Add(detection); } + aReader.Close(); + - aCommand.Dispose(); } + aCommand.Dispose(); + } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs index 963b90b..a5e9368 100644 --- a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs +++ b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs @@ -29,7 +29,7 @@ + ";password=" + databasePassword + ";Charset=utf8" + ";Allow User Variables=True" - + ";Pooling=true"; + + ";Pooling=True"; mySqlConnect = new MySqlConnection(sConnection); mySqlConnect.Open(); iRetval = 0; diff --git a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs index c69559f..f19bd95 100644 --- a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs +++ b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs @@ -38,6 +38,7 @@ private string stability10; private string stability20; private string stability100; + private string isDetecting; public long Id { get @@ -161,5 +162,6 @@ public string Stability20 { get => stability20; set => stability20 = value; } public string Stability100 { get => stability100; set => stability100 = value; } public string Stability1 { get => stability1; set => stability1 = value; } + public string IsDetecting { get => isDetecting; set => isDetecting = value; } } } \ No newline at end of file diff --git a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs index 399098b..781749c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs @@ -9,7 +9,7 @@ { interface DetectionService { - int add(long deviceId, string frequency, string detecItemType, long detectionItemId); + int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time); List search(long deviceId, string detectionType, string startTime, string endTime, long detectionItemId); diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs index 0fd7b24..4df249b 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs @@ -132,7 +132,30 @@ string sQry = "SELECT * FROM r_counter_check_params"; 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) + // { + // if (row[0] != DBNull.Value) counterCheckParam.Id = Convert.ToInt32(row[0]); + // if (row[1] != DBNull.Value) counterCheckParam.SoOutDelay = row[1].ToString(); + // if (row[2] != DBNull.Value) counterCheckParam.SoEleFrequency = row[2].ToString(); + // if (row[3] != DBNull.Value) counterCheckParam.SoEleAddValue = row[3].ToString(); + // if (row[4] != DBNull.Value) counterCheckParam.SoEleAlarm = row[4].ToString(); + // if (row[5] != DBNull.Value) counterCheckParam.FreThreshold1 = row[5].ToString(); + // if (row[6] != DBNull.Value) counterCheckParam.FreThreshold2 = row[6].ToString(); + // if (row[7] != DBNull.Value) counterCheckParam.FreEleAddValue = row[7].ToString(); + // if (row[8] != DBNull.Value) counterCheckParam.CycThreshold1 = row[8].ToString(); + // if (row[9] != DBNull.Value) counterCheckParam.CycThreshold2 = row[9].ToString(); + // if (row[10] != DBNull.Value) counterCheckParam.CycEleAddValue = row[10].ToString(); + + // } + //} using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -149,10 +172,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(Exception ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs index 52b36f8..2c60ab4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs @@ -32,28 +32,29 @@ //先查询是否有历史数据 string sQry = "select ID from r_counter_data where DEVICE_ID=" + deviceId + " and OUT_VALUE = '" + outValue + "'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - - if (aReader.Read()) + bool isUpdated = false; + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - dataId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) + { + dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + + " where ID=" + dataId; + + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; + cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; + cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; + + cmd.ExecuteNonQuery(); + isUpdated = true; + } aReader.Close(); - sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + - " where ID="+ dataId; - - cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; - cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; - cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; - cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; - - cmd.ExecuteNonQuery(); - } - else - { - aReader.Close(); - + if (!isUpdated) + { sQry = "INSERT INTO r_counter_data (DEVICE_ID, OUT_VALUE, VALUE, SENSITIVITY, LOG_TIME, DETEC_TYPE)" + "values(@DEVICE_ID,@OUT_VALUE,@VALUE,@SENSITIVITY,@LOG_TIME,@DETEC_TYPE)"; @@ -70,14 +71,14 @@ sQry = "SELECT max(ID) from r_counter_data"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - - aReader = cmd.ExecuteReader(); - - if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); - + using (MySqlDataReader aReader = cmd.ExecuteReader()) + { + + if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + } } - aReader.Close(); cmd.Dispose(); iRetval = 0; @@ -144,6 +145,8 @@ cmd.ExecuteNonQuery(); } + + aReader.Close(); } @@ -282,9 +285,10 @@ if (!aReader.IsDBNull(6)) counterData.DetecType = aReader.GetString(6); counterDataList.Add(counterData); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs index 6795325..7500bd4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs @@ -47,10 +47,11 @@ counterDetecInitList.Add(counterDetecInit); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -75,29 +76,31 @@ return iRetval; } } - string sQry = "select ID from r_counter_detec_init where FREQUENCY=" + frequency +" AND CYCLE="+cycle; + string sQry = "select ID from r_counter_detec_init where FREQUENCY='" + frequency +"' AND CYCLE='"+cycle+"'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - if (aReader.Read()) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - initId = Convert.ToInt64(aReader.GetString(0)); - sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; + if (aReader.Read()) + { + initId = Convert.ToInt64(aReader.GetString(0)); + sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; - 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(); - } - else - { - 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 = 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(); + } + else + { + 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.ExecuteNonQuery(); + + } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); iRetval = 0; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs index 97b06ba..abcbaa6 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs @@ -72,26 +72,27 @@ MySqlCommand cmd = new MySqlCommand(sql, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(CommandBehavior.Default); - - if (aReader != null) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) + if (aReader != null) { - //判断门的状态 - if (!aReader.IsDBNull(0)) - counterParam.Id = Convert.ToInt32(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) - counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) - counterParam.BaudRate = aReader.GetString(2); - if (!aReader.IsDBNull(3)) - counterParam.GeneratorIp = aReader.GetString(3); - if (!aReader.IsDBNull(4)) - counterParam.SignalSourceIp = aReader.GetString(4); + if (aReader.Read()) + { + //判断门的状态 + if (!aReader.IsDBNull(0)) + counterParam.Id = Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(1)) + counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); + if (!aReader.IsDBNull(2)) + counterParam.BaudRate = aReader.GetString(2); + if (!aReader.IsDBNull(3)) + counterParam.GeneratorIp = aReader.GetString(3); + if (!aReader.IsDBNull(4)) + counterParam.SignalSourceIp = aReader.GetString(4); + } } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs index cca90fb..1578937 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs @@ -33,8 +33,8 @@ MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@DEVICE_ID", MySqlDbType.Int64, 20).Value = deviceId; - cmd.Parameters.Add("@START_TIME", MySqlDbType.String, 50).Value = startTime; - cmd.Parameters.Add("@END_TIME", MySqlDbType.String, 50).Value = endTime; + cmd.Parameters.Add("@START_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(startTime); + cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(endTime); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 50).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 50).Value = accuracy; cmd.Parameters.Add("@BOOT_FEATURE", MySqlDbType.String, 50).Value = bootFeature; @@ -58,11 +58,11 @@ sQry = "SELECT max(ID) from r_detection_item"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = cmd.ExecuteReader()) { if (aReader.Read()) detectionId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); iRetval = 0; @@ -203,8 +203,9 @@ if (!stability100.Equals("")) sQry = sQry + " STABILITY_100=@STABILITY_100,"; sQry = sQry + " COUNTER_DETEC=@COUNTER_DETEC where ID = " + detectionId; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry: " + sQry); - + MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 10).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 10).Value = accuracy; @@ -283,7 +284,8 @@ return iRetval; } } - + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "停止检测 detectionItemId=======" + detectionItemId); + string sQry = "UPDATE r_device SET STATUSID="+"1"+", CHANNEL=@CHANNEL where ID=" + deviceId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@CHANNEL", MySqlDbType.String, 20).Value = ""; @@ -292,19 +294,21 @@ if (isDeleteData) { - sQry = "DELETE FROM r_detection_item WHERE DEVICE_ID = " + deviceId + " AND START_TIME='" + startTime + "' AND END_TIME='" + endTime + "'"; + sQry = "DELETE FROM r_detection_item WHERE ID=" + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); - sQry = "DELETE FROM r_detection WHERE DEVICE_ID = " + deviceId + " AND (LOG_TIME between'" + startTime + "' and '" + endTime + "')"; + sQry = "DELETE FROM r_detection WHERE DETECTION_ITEM_ID = " + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); } else { - sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME WHERE ID="+ detectionItemId; + sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME, IS_DETECTING=@IS_DETECTING WHERE ID=" + detectionItemId; + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 20).Value = DateTime.Now; + cmd.Parameters.Add("@IS_DETECTING", MySqlDbType.String, 1).Value = "0"; //0-否,1-是 cmd.ExecuteNonQuery(); } @@ -322,8 +326,7 @@ { DetectionItem detectionItem = null; try - { - + { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getById : 数据库链接断开"); @@ -337,6 +340,7 @@ string sQry = "select * from r_detection_item WHERE ID = "+ detectionItemId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + using (MySqlDataReader aReader = cmd.ExecuteReader()) { while (aReader.Read()) @@ -356,11 +360,13 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(15)) detectionItem.IsDetecting = aReader.GetString(15); } - } - + aReader.Close(); + } cmd.Dispose(); + } catch (MySqlException e) { @@ -400,7 +406,7 @@ { DetectionItem detectionItem = new DetectionItem(); //姓名 - if (!aReader.IsDBNull(0)) detectionItem.Id=Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(0)) detectionItem.Id = Convert.ToInt32(aReader.GetString(0)); if (!aReader.IsDBNull(1)) detectionItem.DeviceId = Convert.ToInt64(aReader.GetString(1)); if (!aReader.IsDBNull(2)) detectionItem.StartTime = aReader.GetString(2); if (!aReader.IsDBNull(3)) detectionItem.EndTime = aReader.GetString(3); @@ -416,9 +422,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -468,9 +475,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -498,7 +506,6 @@ string sQry = "SELECT * FROM r_detection_item where ID = " + detectionId; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -518,15 +525,43 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); + //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) + // { + // detectionItem = new DetectionItem(); + // if (row[0] != DBNull.Value) detectionItem.Id = Convert.ToInt64(row[0]); + // if (row[1] != DBNull.Value) detectionItem.DeviceId = Convert.ToInt64(row[1]); + // if (row[2] != DBNull.Value) detectionItem.StartTime = Convert.ToDateTime(row[2]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[3] != DBNull.Value) detectionItem.EndTime = Convert.ToDateTime(row[3]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[4] != DBNull.Value) detectionItem.Stability = row[4].ToString(); + // if (row[5] != DBNull.Value) detectionItem.Accuracy = row[5].ToString(); + // if (row[6] != DBNull.Value) detectionItem.BootFeature = row[6].ToString(); + // if (row[7] != DBNull.Value) detectionItem.AgeRate = row[7].ToString(); + // if (row[8] != DBNull.Value) detectionItem.Interval = row[8].ToString(); + // if (row[10] != DBNull.Value) detectionItem.Channel = row[10].ToString(); + // if (row[11] != DBNull.Value) detectionItem.Stability1 = row[11].ToString(); + // if (row[12] != DBNull.Value) detectionItem.Stability10 = row[12].ToString(); + // if (row[13] != DBNull.Value) detectionItem.Stability20 = row[13].ToString(); + // if (row[14] != DBNull.Value) detectionItem.Stability100 = row[14].ToString(); + + // } + //} } catch (MySqlException ex) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDetectionItem: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchById: " + ex.Message); } return detectionItem; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs index e2a5893..5b3deb0 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs @@ -14,7 +14,7 @@ { class DetectionServiceImpl : DetectionService { - public int add(long deviceId, string frequency, string detecItemType, long detectionItemId) + public int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time) { int iRetval = -1; try @@ -36,7 +36,7 @@ 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 = DateTime.Now; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.DateTime, 0).Value = time; cmd.Parameters.Add("@DETECTION_ITEM", MySqlDbType.String, 0).Value = detecItemType; cmd.Parameters.Add("@DETECTION_ITEM_ID", MySqlDbType.Int64, 0).Value = detectionItemId; @@ -108,24 +108,26 @@ string sQry = "SELECT * FROM r_detection where DEVICE_ID = " + deviceId +" and DETECTION_ITEM='" + detectionType + "' and (LOG_TIME BETWEEN '" + startTime + "' and '"+ endTime + "') and DETECTION_ITEM_ID="+detectionItemId+" order by LOG_TIME"; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) { - Model.Detection detection = new Model.Detection(); - //姓名 - if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) detection.LogTime = Convert.ToDateTime(aReader.GetString(2)).ToString("yyyy-MM-dd HH:mm:ss"); - if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); - if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); + Detection detection = new Detection(); + + if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); // id + if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); // devName + if (!aReader.IsDBNull(2)) detection.LogTime = aReader.GetString(2); // devCode + if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); // devType + if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); // devModel detectionDtoList.Add(detection); } + aReader.Close(); + - aCommand.Dispose(); } + aCommand.Dispose(); + } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs index 9413e2f..b224bc1 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs @@ -53,7 +53,8 @@ using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); @@ -87,8 +88,7 @@ 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; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry : "+ sQry + "; statusId="+ statusId); - + 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; @@ -183,7 +183,7 @@ } MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -208,10 +208,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -254,7 +255,30 @@ 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()) @@ -279,10 +303,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -342,7 +367,30 @@ 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()) @@ -372,10 +420,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -442,9 +491,10 @@ { totalCount = aReader.GetInt32(0); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -477,89 +527,45 @@ return null; } } - - string sQry = "SELECT * FROM r_deviceview where ACTIVE = 0 and STATUSID = 2 " + "and ('" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' <= END_TIME)"; - - 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) + //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))"; + MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { - foreach (DataRow row in dt.Rows) + while (aReader.Read()) { DeviceView deviceView = new DeviceView(); - if (row[0] != DBNull.Value) deviceView.Id = Convert.ToInt64(row[0]); - if (row[1] != DBNull.Value) deviceView.DevName = row[1].ToString(); - if (row[2] != DBNull.Value) deviceView.DevCode = row[2].ToString(); - if (row[3] != DBNull.Value) deviceView.DevTypeId = row[3].ToString(); - if (row[4] != DBNull.Value) deviceView.DevModel = row[4].ToString(); - if (row[5] != DBNull.Value) deviceView.RegTime = row[5].ToString(); - if (row[6] != DBNull.Value) deviceView.CustomerName = row[6].ToString(); - if (row[7] != DBNull.Value) deviceView.CustomerDev = row[7].ToString(); - if (row[8] != DBNull.Value) deviceView.Channel = row[8].ToString(); - if (row[9] != DBNull.Value) deviceView.Active = Convert.ToInt32(row[9]); - if (row[10] != DBNull.Value) deviceView.StartTime = Convert.ToDateTime(row[10]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[11] != DBNull.Value) deviceView.EndTime = Convert.ToDateTime(row[11]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[12] != DBNull.Value) deviceView.StatusId = row[12].ToString(); - if (row[13] != DBNull.Value) deviceView.Stability = row[13].ToString(); - if (row[14] != DBNull.Value) deviceView.Accuracy = row[14].ToString(); - if (row[15] != DBNull.Value) deviceView.BootFeature = row[15].ToString(); - if (row[16] != DBNull.Value) deviceView.AgeRate = row[16].ToString(); - if (row[17] != DBNull.Value) deviceView.DetectionItemId = Convert.ToInt64(row[17]); + 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(); + + } - //using (MySqlDataReader aReader = aCommand.ExecuteReader()) - //{ - // while (aReader.Read()) - // { - // DeviceView deviceView = new DeviceView(); + aCommand.Dispose(); - // 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 - // //deviceView.DevTypeName = dictService.getNameByCode("devType", aReader.GetString(3)); - // } - // if (!aReader.IsDBNull(4)) deviceView.DevModel = aReader.GetString(4); // devModel - // if (!aReader.IsDBNull(5)) - // { - // DateTime reg = aReader.GetDateTime(5); // regTime - // deviceView.RegTime = reg.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); - // if (!aReader.IsDBNull(9)) deviceView.Active = Convert.ToInt32(aReader.GetString(9)); - // if (!aReader.IsDBNull(10)) - // { - // DateTime reg = aReader.GetDateTime(10); // regTime - // deviceView.StartTime = reg.ToString("yyyy-MM-dd HH:mm:ss"); - // } - // if (!aReader.IsDBNull(11)) - // { - // DateTime reg = aReader.GetDateTime(11); // regTime - // deviceView.EndTime = reg.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 = Convert.ToInt64(aReader.GetString(17)); - - // deviceViewList.Add(deviceView); - - // aCommand.Dispose(); - // } - //} - if (deviceViewList.Count > 0) { foreach (DeviceView deviceView in deviceViewList) @@ -568,9 +574,15 @@ } } } + + 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()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getDeviceByChannel: " + ex.Message + " ; " + ex.ToString()); deviceViewList = null; } finally diff --git a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs index 963b90b..a5e9368 100644 --- a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs +++ b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs @@ -29,7 +29,7 @@ + ";password=" + databasePassword + ";Charset=utf8" + ";Allow User Variables=True" - + ";Pooling=true"; + + ";Pooling=True"; mySqlConnect = new MySqlConnection(sConnection); mySqlConnect.Open(); iRetval = 0; diff --git a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs index c69559f..f19bd95 100644 --- a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs +++ b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs @@ -38,6 +38,7 @@ private string stability10; private string stability20; private string stability100; + private string isDetecting; public long Id { get @@ -161,5 +162,6 @@ public string Stability20 { get => stability20; set => stability20 = value; } public string Stability100 { get => stability100; set => stability100 = value; } public string Stability1 { get => stability1; set => stability1 = value; } + public string IsDetecting { get => isDetecting; set => isDetecting = value; } } } \ No newline at end of file diff --git a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs index 399098b..781749c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs @@ -9,7 +9,7 @@ { interface DetectionService { - int add(long deviceId, string frequency, string detecItemType, long detectionItemId); + int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time); List search(long deviceId, string detectionType, string startTime, string endTime, long detectionItemId); diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs index 0fd7b24..4df249b 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs @@ -132,7 +132,30 @@ string sQry = "SELECT * FROM r_counter_check_params"; 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) + // { + // if (row[0] != DBNull.Value) counterCheckParam.Id = Convert.ToInt32(row[0]); + // if (row[1] != DBNull.Value) counterCheckParam.SoOutDelay = row[1].ToString(); + // if (row[2] != DBNull.Value) counterCheckParam.SoEleFrequency = row[2].ToString(); + // if (row[3] != DBNull.Value) counterCheckParam.SoEleAddValue = row[3].ToString(); + // if (row[4] != DBNull.Value) counterCheckParam.SoEleAlarm = row[4].ToString(); + // if (row[5] != DBNull.Value) counterCheckParam.FreThreshold1 = row[5].ToString(); + // if (row[6] != DBNull.Value) counterCheckParam.FreThreshold2 = row[6].ToString(); + // if (row[7] != DBNull.Value) counterCheckParam.FreEleAddValue = row[7].ToString(); + // if (row[8] != DBNull.Value) counterCheckParam.CycThreshold1 = row[8].ToString(); + // if (row[9] != DBNull.Value) counterCheckParam.CycThreshold2 = row[9].ToString(); + // if (row[10] != DBNull.Value) counterCheckParam.CycEleAddValue = row[10].ToString(); + + // } + //} using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -149,10 +172,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(Exception ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs index 52b36f8..2c60ab4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs @@ -32,28 +32,29 @@ //先查询是否有历史数据 string sQry = "select ID from r_counter_data where DEVICE_ID=" + deviceId + " and OUT_VALUE = '" + outValue + "'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - - if (aReader.Read()) + bool isUpdated = false; + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - dataId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) + { + dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + + " where ID=" + dataId; + + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; + cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; + cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; + + cmd.ExecuteNonQuery(); + isUpdated = true; + } aReader.Close(); - sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + - " where ID="+ dataId; - - cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; - cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; - cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; - cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; - - cmd.ExecuteNonQuery(); - } - else - { - aReader.Close(); - + if (!isUpdated) + { sQry = "INSERT INTO r_counter_data (DEVICE_ID, OUT_VALUE, VALUE, SENSITIVITY, LOG_TIME, DETEC_TYPE)" + "values(@DEVICE_ID,@OUT_VALUE,@VALUE,@SENSITIVITY,@LOG_TIME,@DETEC_TYPE)"; @@ -70,14 +71,14 @@ sQry = "SELECT max(ID) from r_counter_data"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - - aReader = cmd.ExecuteReader(); - - if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); - + using (MySqlDataReader aReader = cmd.ExecuteReader()) + { + + if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + } } - aReader.Close(); cmd.Dispose(); iRetval = 0; @@ -144,6 +145,8 @@ cmd.ExecuteNonQuery(); } + + aReader.Close(); } @@ -282,9 +285,10 @@ if (!aReader.IsDBNull(6)) counterData.DetecType = aReader.GetString(6); counterDataList.Add(counterData); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs index 6795325..7500bd4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs @@ -47,10 +47,11 @@ counterDetecInitList.Add(counterDetecInit); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -75,29 +76,31 @@ return iRetval; } } - string sQry = "select ID from r_counter_detec_init where FREQUENCY=" + frequency +" AND CYCLE="+cycle; + string sQry = "select ID from r_counter_detec_init where FREQUENCY='" + frequency +"' AND CYCLE='"+cycle+"'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - if (aReader.Read()) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - initId = Convert.ToInt64(aReader.GetString(0)); - sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; + if (aReader.Read()) + { + initId = Convert.ToInt64(aReader.GetString(0)); + sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; - 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(); - } - else - { - 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 = 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(); + } + else + { + 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.ExecuteNonQuery(); + + } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); iRetval = 0; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs index 97b06ba..abcbaa6 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs @@ -72,26 +72,27 @@ MySqlCommand cmd = new MySqlCommand(sql, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(CommandBehavior.Default); - - if (aReader != null) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) + if (aReader != null) { - //判断门的状态 - if (!aReader.IsDBNull(0)) - counterParam.Id = Convert.ToInt32(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) - counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) - counterParam.BaudRate = aReader.GetString(2); - if (!aReader.IsDBNull(3)) - counterParam.GeneratorIp = aReader.GetString(3); - if (!aReader.IsDBNull(4)) - counterParam.SignalSourceIp = aReader.GetString(4); + if (aReader.Read()) + { + //判断门的状态 + if (!aReader.IsDBNull(0)) + counterParam.Id = Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(1)) + counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); + if (!aReader.IsDBNull(2)) + counterParam.BaudRate = aReader.GetString(2); + if (!aReader.IsDBNull(3)) + counterParam.GeneratorIp = aReader.GetString(3); + if (!aReader.IsDBNull(4)) + counterParam.SignalSourceIp = aReader.GetString(4); + } } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs index cca90fb..1578937 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs @@ -33,8 +33,8 @@ MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@DEVICE_ID", MySqlDbType.Int64, 20).Value = deviceId; - cmd.Parameters.Add("@START_TIME", MySqlDbType.String, 50).Value = startTime; - cmd.Parameters.Add("@END_TIME", MySqlDbType.String, 50).Value = endTime; + cmd.Parameters.Add("@START_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(startTime); + cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(endTime); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 50).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 50).Value = accuracy; cmd.Parameters.Add("@BOOT_FEATURE", MySqlDbType.String, 50).Value = bootFeature; @@ -58,11 +58,11 @@ sQry = "SELECT max(ID) from r_detection_item"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = cmd.ExecuteReader()) { if (aReader.Read()) detectionId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); iRetval = 0; @@ -203,8 +203,9 @@ if (!stability100.Equals("")) sQry = sQry + " STABILITY_100=@STABILITY_100,"; sQry = sQry + " COUNTER_DETEC=@COUNTER_DETEC where ID = " + detectionId; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry: " + sQry); - + MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 10).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 10).Value = accuracy; @@ -283,7 +284,8 @@ return iRetval; } } - + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "停止检测 detectionItemId=======" + detectionItemId); + string sQry = "UPDATE r_device SET STATUSID="+"1"+", CHANNEL=@CHANNEL where ID=" + deviceId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@CHANNEL", MySqlDbType.String, 20).Value = ""; @@ -292,19 +294,21 @@ if (isDeleteData) { - sQry = "DELETE FROM r_detection_item WHERE DEVICE_ID = " + deviceId + " AND START_TIME='" + startTime + "' AND END_TIME='" + endTime + "'"; + sQry = "DELETE FROM r_detection_item WHERE ID=" + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); - sQry = "DELETE FROM r_detection WHERE DEVICE_ID = " + deviceId + " AND (LOG_TIME between'" + startTime + "' and '" + endTime + "')"; + sQry = "DELETE FROM r_detection WHERE DETECTION_ITEM_ID = " + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); } else { - sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME WHERE ID="+ detectionItemId; + sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME, IS_DETECTING=@IS_DETECTING WHERE ID=" + detectionItemId; + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 20).Value = DateTime.Now; + cmd.Parameters.Add("@IS_DETECTING", MySqlDbType.String, 1).Value = "0"; //0-否,1-是 cmd.ExecuteNonQuery(); } @@ -322,8 +326,7 @@ { DetectionItem detectionItem = null; try - { - + { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getById : 数据库链接断开"); @@ -337,6 +340,7 @@ string sQry = "select * from r_detection_item WHERE ID = "+ detectionItemId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + using (MySqlDataReader aReader = cmd.ExecuteReader()) { while (aReader.Read()) @@ -356,11 +360,13 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(15)) detectionItem.IsDetecting = aReader.GetString(15); } - } - + aReader.Close(); + } cmd.Dispose(); + } catch (MySqlException e) { @@ -400,7 +406,7 @@ { DetectionItem detectionItem = new DetectionItem(); //姓名 - if (!aReader.IsDBNull(0)) detectionItem.Id=Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(0)) detectionItem.Id = Convert.ToInt32(aReader.GetString(0)); if (!aReader.IsDBNull(1)) detectionItem.DeviceId = Convert.ToInt64(aReader.GetString(1)); if (!aReader.IsDBNull(2)) detectionItem.StartTime = aReader.GetString(2); if (!aReader.IsDBNull(3)) detectionItem.EndTime = aReader.GetString(3); @@ -416,9 +422,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -468,9 +475,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -498,7 +506,6 @@ string sQry = "SELECT * FROM r_detection_item where ID = " + detectionId; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -518,15 +525,43 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); + //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) + // { + // detectionItem = new DetectionItem(); + // if (row[0] != DBNull.Value) detectionItem.Id = Convert.ToInt64(row[0]); + // if (row[1] != DBNull.Value) detectionItem.DeviceId = Convert.ToInt64(row[1]); + // if (row[2] != DBNull.Value) detectionItem.StartTime = Convert.ToDateTime(row[2]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[3] != DBNull.Value) detectionItem.EndTime = Convert.ToDateTime(row[3]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[4] != DBNull.Value) detectionItem.Stability = row[4].ToString(); + // if (row[5] != DBNull.Value) detectionItem.Accuracy = row[5].ToString(); + // if (row[6] != DBNull.Value) detectionItem.BootFeature = row[6].ToString(); + // if (row[7] != DBNull.Value) detectionItem.AgeRate = row[7].ToString(); + // if (row[8] != DBNull.Value) detectionItem.Interval = row[8].ToString(); + // if (row[10] != DBNull.Value) detectionItem.Channel = row[10].ToString(); + // if (row[11] != DBNull.Value) detectionItem.Stability1 = row[11].ToString(); + // if (row[12] != DBNull.Value) detectionItem.Stability10 = row[12].ToString(); + // if (row[13] != DBNull.Value) detectionItem.Stability20 = row[13].ToString(); + // if (row[14] != DBNull.Value) detectionItem.Stability100 = row[14].ToString(); + + // } + //} } catch (MySqlException ex) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDetectionItem: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchById: " + ex.Message); } return detectionItem; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs index e2a5893..5b3deb0 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs @@ -14,7 +14,7 @@ { class DetectionServiceImpl : DetectionService { - public int add(long deviceId, string frequency, string detecItemType, long detectionItemId) + public int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time) { int iRetval = -1; try @@ -36,7 +36,7 @@ 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 = DateTime.Now; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.DateTime, 0).Value = time; cmd.Parameters.Add("@DETECTION_ITEM", MySqlDbType.String, 0).Value = detecItemType; cmd.Parameters.Add("@DETECTION_ITEM_ID", MySqlDbType.Int64, 0).Value = detectionItemId; @@ -108,24 +108,26 @@ string sQry = "SELECT * FROM r_detection where DEVICE_ID = " + deviceId +" and DETECTION_ITEM='" + detectionType + "' and (LOG_TIME BETWEEN '" + startTime + "' and '"+ endTime + "') and DETECTION_ITEM_ID="+detectionItemId+" order by LOG_TIME"; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) { - Model.Detection detection = new Model.Detection(); - //姓名 - if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) detection.LogTime = Convert.ToDateTime(aReader.GetString(2)).ToString("yyyy-MM-dd HH:mm:ss"); - if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); - if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); + Detection detection = new Detection(); + + if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); // id + if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); // devName + if (!aReader.IsDBNull(2)) detection.LogTime = aReader.GetString(2); // devCode + if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); // devType + if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); // devModel detectionDtoList.Add(detection); } + aReader.Close(); + - aCommand.Dispose(); } + aCommand.Dispose(); + } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs index 9413e2f..b224bc1 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs @@ -53,7 +53,8 @@ using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); @@ -87,8 +88,7 @@ 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; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry : "+ sQry + "; statusId="+ statusId); - + 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; @@ -183,7 +183,7 @@ } MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -208,10 +208,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -254,7 +255,30 @@ 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()) @@ -279,10 +303,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -342,7 +367,30 @@ 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()) @@ -372,10 +420,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -442,9 +491,10 @@ { totalCount = aReader.GetInt32(0); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -477,89 +527,45 @@ return null; } } - - string sQry = "SELECT * FROM r_deviceview where ACTIVE = 0 and STATUSID = 2 " + "and ('" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' <= END_TIME)"; - - 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) + //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))"; + MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { - foreach (DataRow row in dt.Rows) + while (aReader.Read()) { DeviceView deviceView = new DeviceView(); - if (row[0] != DBNull.Value) deviceView.Id = Convert.ToInt64(row[0]); - if (row[1] != DBNull.Value) deviceView.DevName = row[1].ToString(); - if (row[2] != DBNull.Value) deviceView.DevCode = row[2].ToString(); - if (row[3] != DBNull.Value) deviceView.DevTypeId = row[3].ToString(); - if (row[4] != DBNull.Value) deviceView.DevModel = row[4].ToString(); - if (row[5] != DBNull.Value) deviceView.RegTime = row[5].ToString(); - if (row[6] != DBNull.Value) deviceView.CustomerName = row[6].ToString(); - if (row[7] != DBNull.Value) deviceView.CustomerDev = row[7].ToString(); - if (row[8] != DBNull.Value) deviceView.Channel = row[8].ToString(); - if (row[9] != DBNull.Value) deviceView.Active = Convert.ToInt32(row[9]); - if (row[10] != DBNull.Value) deviceView.StartTime = Convert.ToDateTime(row[10]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[11] != DBNull.Value) deviceView.EndTime = Convert.ToDateTime(row[11]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[12] != DBNull.Value) deviceView.StatusId = row[12].ToString(); - if (row[13] != DBNull.Value) deviceView.Stability = row[13].ToString(); - if (row[14] != DBNull.Value) deviceView.Accuracy = row[14].ToString(); - if (row[15] != DBNull.Value) deviceView.BootFeature = row[15].ToString(); - if (row[16] != DBNull.Value) deviceView.AgeRate = row[16].ToString(); - if (row[17] != DBNull.Value) deviceView.DetectionItemId = Convert.ToInt64(row[17]); + 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(); + + } - //using (MySqlDataReader aReader = aCommand.ExecuteReader()) - //{ - // while (aReader.Read()) - // { - // DeviceView deviceView = new DeviceView(); + aCommand.Dispose(); - // 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 - // //deviceView.DevTypeName = dictService.getNameByCode("devType", aReader.GetString(3)); - // } - // if (!aReader.IsDBNull(4)) deviceView.DevModel = aReader.GetString(4); // devModel - // if (!aReader.IsDBNull(5)) - // { - // DateTime reg = aReader.GetDateTime(5); // regTime - // deviceView.RegTime = reg.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); - // if (!aReader.IsDBNull(9)) deviceView.Active = Convert.ToInt32(aReader.GetString(9)); - // if (!aReader.IsDBNull(10)) - // { - // DateTime reg = aReader.GetDateTime(10); // regTime - // deviceView.StartTime = reg.ToString("yyyy-MM-dd HH:mm:ss"); - // } - // if (!aReader.IsDBNull(11)) - // { - // DateTime reg = aReader.GetDateTime(11); // regTime - // deviceView.EndTime = reg.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 = Convert.ToInt64(aReader.GetString(17)); - - // deviceViewList.Add(deviceView); - - // aCommand.Dispose(); - // } - //} - if (deviceViewList.Count > 0) { foreach (DeviceView deviceView in deviceViewList) @@ -568,9 +574,15 @@ } } } + + 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()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getDeviceByChannel: " + ex.Message + " ; " + ex.ToString()); deviceViewList = null; } finally diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs index 1626aa5..42ca83c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs @@ -92,10 +92,11 @@ if (!aReader.IsDBNull(3)) dict.Code = aReader.GetString(3); nameList.Add(dict); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(MySqlException ex) { @@ -139,10 +140,11 @@ if (!aReader.IsDBNull(3)) counterParam.GeneratorIp = aReader.GetString(3); if (!aReader.IsDBNull(4)) counterParam.SignalSourceIp = aReader.GetString(4); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -220,10 +222,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs index 963b90b..a5e9368 100644 --- a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs +++ b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs @@ -29,7 +29,7 @@ + ";password=" + databasePassword + ";Charset=utf8" + ";Allow User Variables=True" - + ";Pooling=true"; + + ";Pooling=True"; mySqlConnect = new MySqlConnection(sConnection); mySqlConnect.Open(); iRetval = 0; diff --git a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs index c69559f..f19bd95 100644 --- a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs +++ b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs @@ -38,6 +38,7 @@ private string stability10; private string stability20; private string stability100; + private string isDetecting; public long Id { get @@ -161,5 +162,6 @@ public string Stability20 { get => stability20; set => stability20 = value; } public string Stability100 { get => stability100; set => stability100 = value; } public string Stability1 { get => stability1; set => stability1 = value; } + public string IsDetecting { get => isDetecting; set => isDetecting = value; } } } \ No newline at end of file diff --git a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs index 399098b..781749c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs @@ -9,7 +9,7 @@ { interface DetectionService { - int add(long deviceId, string frequency, string detecItemType, long detectionItemId); + int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time); List search(long deviceId, string detectionType, string startTime, string endTime, long detectionItemId); diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs index 0fd7b24..4df249b 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs @@ -132,7 +132,30 @@ string sQry = "SELECT * FROM r_counter_check_params"; 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) + // { + // if (row[0] != DBNull.Value) counterCheckParam.Id = Convert.ToInt32(row[0]); + // if (row[1] != DBNull.Value) counterCheckParam.SoOutDelay = row[1].ToString(); + // if (row[2] != DBNull.Value) counterCheckParam.SoEleFrequency = row[2].ToString(); + // if (row[3] != DBNull.Value) counterCheckParam.SoEleAddValue = row[3].ToString(); + // if (row[4] != DBNull.Value) counterCheckParam.SoEleAlarm = row[4].ToString(); + // if (row[5] != DBNull.Value) counterCheckParam.FreThreshold1 = row[5].ToString(); + // if (row[6] != DBNull.Value) counterCheckParam.FreThreshold2 = row[6].ToString(); + // if (row[7] != DBNull.Value) counterCheckParam.FreEleAddValue = row[7].ToString(); + // if (row[8] != DBNull.Value) counterCheckParam.CycThreshold1 = row[8].ToString(); + // if (row[9] != DBNull.Value) counterCheckParam.CycThreshold2 = row[9].ToString(); + // if (row[10] != DBNull.Value) counterCheckParam.CycEleAddValue = row[10].ToString(); + + // } + //} using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -149,10 +172,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(Exception ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs index 52b36f8..2c60ab4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs @@ -32,28 +32,29 @@ //先查询是否有历史数据 string sQry = "select ID from r_counter_data where DEVICE_ID=" + deviceId + " and OUT_VALUE = '" + outValue + "'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - - if (aReader.Read()) + bool isUpdated = false; + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - dataId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) + { + dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + + " where ID=" + dataId; + + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; + cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; + cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; + + cmd.ExecuteNonQuery(); + isUpdated = true; + } aReader.Close(); - sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + - " where ID="+ dataId; - - cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; - cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; - cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; - cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; - - cmd.ExecuteNonQuery(); - } - else - { - aReader.Close(); - + if (!isUpdated) + { sQry = "INSERT INTO r_counter_data (DEVICE_ID, OUT_VALUE, VALUE, SENSITIVITY, LOG_TIME, DETEC_TYPE)" + "values(@DEVICE_ID,@OUT_VALUE,@VALUE,@SENSITIVITY,@LOG_TIME,@DETEC_TYPE)"; @@ -70,14 +71,14 @@ sQry = "SELECT max(ID) from r_counter_data"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - - aReader = cmd.ExecuteReader(); - - if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); - + using (MySqlDataReader aReader = cmd.ExecuteReader()) + { + + if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + } } - aReader.Close(); cmd.Dispose(); iRetval = 0; @@ -144,6 +145,8 @@ cmd.ExecuteNonQuery(); } + + aReader.Close(); } @@ -282,9 +285,10 @@ if (!aReader.IsDBNull(6)) counterData.DetecType = aReader.GetString(6); counterDataList.Add(counterData); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs index 6795325..7500bd4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs @@ -47,10 +47,11 @@ counterDetecInitList.Add(counterDetecInit); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -75,29 +76,31 @@ return iRetval; } } - string sQry = "select ID from r_counter_detec_init where FREQUENCY=" + frequency +" AND CYCLE="+cycle; + string sQry = "select ID from r_counter_detec_init where FREQUENCY='" + frequency +"' AND CYCLE='"+cycle+"'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - if (aReader.Read()) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - initId = Convert.ToInt64(aReader.GetString(0)); - sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; + if (aReader.Read()) + { + initId = Convert.ToInt64(aReader.GetString(0)); + sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; - 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(); - } - else - { - 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 = 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(); + } + else + { + 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.ExecuteNonQuery(); + + } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); iRetval = 0; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs index 97b06ba..abcbaa6 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs @@ -72,26 +72,27 @@ MySqlCommand cmd = new MySqlCommand(sql, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(CommandBehavior.Default); - - if (aReader != null) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) + if (aReader != null) { - //判断门的状态 - if (!aReader.IsDBNull(0)) - counterParam.Id = Convert.ToInt32(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) - counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) - counterParam.BaudRate = aReader.GetString(2); - if (!aReader.IsDBNull(3)) - counterParam.GeneratorIp = aReader.GetString(3); - if (!aReader.IsDBNull(4)) - counterParam.SignalSourceIp = aReader.GetString(4); + if (aReader.Read()) + { + //判断门的状态 + if (!aReader.IsDBNull(0)) + counterParam.Id = Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(1)) + counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); + if (!aReader.IsDBNull(2)) + counterParam.BaudRate = aReader.GetString(2); + if (!aReader.IsDBNull(3)) + counterParam.GeneratorIp = aReader.GetString(3); + if (!aReader.IsDBNull(4)) + counterParam.SignalSourceIp = aReader.GetString(4); + } } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs index cca90fb..1578937 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs @@ -33,8 +33,8 @@ MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@DEVICE_ID", MySqlDbType.Int64, 20).Value = deviceId; - cmd.Parameters.Add("@START_TIME", MySqlDbType.String, 50).Value = startTime; - cmd.Parameters.Add("@END_TIME", MySqlDbType.String, 50).Value = endTime; + cmd.Parameters.Add("@START_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(startTime); + cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(endTime); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 50).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 50).Value = accuracy; cmd.Parameters.Add("@BOOT_FEATURE", MySqlDbType.String, 50).Value = bootFeature; @@ -58,11 +58,11 @@ sQry = "SELECT max(ID) from r_detection_item"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = cmd.ExecuteReader()) { if (aReader.Read()) detectionId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); iRetval = 0; @@ -203,8 +203,9 @@ if (!stability100.Equals("")) sQry = sQry + " STABILITY_100=@STABILITY_100,"; sQry = sQry + " COUNTER_DETEC=@COUNTER_DETEC where ID = " + detectionId; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry: " + sQry); - + MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 10).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 10).Value = accuracy; @@ -283,7 +284,8 @@ return iRetval; } } - + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "停止检测 detectionItemId=======" + detectionItemId); + string sQry = "UPDATE r_device SET STATUSID="+"1"+", CHANNEL=@CHANNEL where ID=" + deviceId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@CHANNEL", MySqlDbType.String, 20).Value = ""; @@ -292,19 +294,21 @@ if (isDeleteData) { - sQry = "DELETE FROM r_detection_item WHERE DEVICE_ID = " + deviceId + " AND START_TIME='" + startTime + "' AND END_TIME='" + endTime + "'"; + sQry = "DELETE FROM r_detection_item WHERE ID=" + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); - sQry = "DELETE FROM r_detection WHERE DEVICE_ID = " + deviceId + " AND (LOG_TIME between'" + startTime + "' and '" + endTime + "')"; + sQry = "DELETE FROM r_detection WHERE DETECTION_ITEM_ID = " + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); } else { - sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME WHERE ID="+ detectionItemId; + sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME, IS_DETECTING=@IS_DETECTING WHERE ID=" + detectionItemId; + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 20).Value = DateTime.Now; + cmd.Parameters.Add("@IS_DETECTING", MySqlDbType.String, 1).Value = "0"; //0-否,1-是 cmd.ExecuteNonQuery(); } @@ -322,8 +326,7 @@ { DetectionItem detectionItem = null; try - { - + { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getById : 数据库链接断开"); @@ -337,6 +340,7 @@ string sQry = "select * from r_detection_item WHERE ID = "+ detectionItemId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + using (MySqlDataReader aReader = cmd.ExecuteReader()) { while (aReader.Read()) @@ -356,11 +360,13 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(15)) detectionItem.IsDetecting = aReader.GetString(15); } - } - + aReader.Close(); + } cmd.Dispose(); + } catch (MySqlException e) { @@ -400,7 +406,7 @@ { DetectionItem detectionItem = new DetectionItem(); //姓名 - if (!aReader.IsDBNull(0)) detectionItem.Id=Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(0)) detectionItem.Id = Convert.ToInt32(aReader.GetString(0)); if (!aReader.IsDBNull(1)) detectionItem.DeviceId = Convert.ToInt64(aReader.GetString(1)); if (!aReader.IsDBNull(2)) detectionItem.StartTime = aReader.GetString(2); if (!aReader.IsDBNull(3)) detectionItem.EndTime = aReader.GetString(3); @@ -416,9 +422,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -468,9 +475,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -498,7 +506,6 @@ string sQry = "SELECT * FROM r_detection_item where ID = " + detectionId; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -518,15 +525,43 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); + //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) + // { + // detectionItem = new DetectionItem(); + // if (row[0] != DBNull.Value) detectionItem.Id = Convert.ToInt64(row[0]); + // if (row[1] != DBNull.Value) detectionItem.DeviceId = Convert.ToInt64(row[1]); + // if (row[2] != DBNull.Value) detectionItem.StartTime = Convert.ToDateTime(row[2]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[3] != DBNull.Value) detectionItem.EndTime = Convert.ToDateTime(row[3]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[4] != DBNull.Value) detectionItem.Stability = row[4].ToString(); + // if (row[5] != DBNull.Value) detectionItem.Accuracy = row[5].ToString(); + // if (row[6] != DBNull.Value) detectionItem.BootFeature = row[6].ToString(); + // if (row[7] != DBNull.Value) detectionItem.AgeRate = row[7].ToString(); + // if (row[8] != DBNull.Value) detectionItem.Interval = row[8].ToString(); + // if (row[10] != DBNull.Value) detectionItem.Channel = row[10].ToString(); + // if (row[11] != DBNull.Value) detectionItem.Stability1 = row[11].ToString(); + // if (row[12] != DBNull.Value) detectionItem.Stability10 = row[12].ToString(); + // if (row[13] != DBNull.Value) detectionItem.Stability20 = row[13].ToString(); + // if (row[14] != DBNull.Value) detectionItem.Stability100 = row[14].ToString(); + + // } + //} } catch (MySqlException ex) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDetectionItem: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchById: " + ex.Message); } return detectionItem; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs index e2a5893..5b3deb0 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs @@ -14,7 +14,7 @@ { class DetectionServiceImpl : DetectionService { - public int add(long deviceId, string frequency, string detecItemType, long detectionItemId) + public int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time) { int iRetval = -1; try @@ -36,7 +36,7 @@ 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 = DateTime.Now; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.DateTime, 0).Value = time; cmd.Parameters.Add("@DETECTION_ITEM", MySqlDbType.String, 0).Value = detecItemType; cmd.Parameters.Add("@DETECTION_ITEM_ID", MySqlDbType.Int64, 0).Value = detectionItemId; @@ -108,24 +108,26 @@ string sQry = "SELECT * FROM r_detection where DEVICE_ID = " + deviceId +" and DETECTION_ITEM='" + detectionType + "' and (LOG_TIME BETWEEN '" + startTime + "' and '"+ endTime + "') and DETECTION_ITEM_ID="+detectionItemId+" order by LOG_TIME"; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) { - Model.Detection detection = new Model.Detection(); - //姓名 - if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) detection.LogTime = Convert.ToDateTime(aReader.GetString(2)).ToString("yyyy-MM-dd HH:mm:ss"); - if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); - if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); + Detection detection = new Detection(); + + if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); // id + if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); // devName + if (!aReader.IsDBNull(2)) detection.LogTime = aReader.GetString(2); // devCode + if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); // devType + if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); // devModel detectionDtoList.Add(detection); } + aReader.Close(); + - aCommand.Dispose(); } + aCommand.Dispose(); + } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs index 9413e2f..b224bc1 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs @@ -53,7 +53,8 @@ using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); @@ -87,8 +88,7 @@ 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; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry : "+ sQry + "; statusId="+ statusId); - + 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; @@ -183,7 +183,7 @@ } MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -208,10 +208,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -254,7 +255,30 @@ 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()) @@ -279,10 +303,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -342,7 +367,30 @@ 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()) @@ -372,10 +420,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -442,9 +491,10 @@ { totalCount = aReader.GetInt32(0); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -477,89 +527,45 @@ return null; } } - - string sQry = "SELECT * FROM r_deviceview where ACTIVE = 0 and STATUSID = 2 " + "and ('" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' <= END_TIME)"; - - 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) + //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))"; + MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { - foreach (DataRow row in dt.Rows) + while (aReader.Read()) { DeviceView deviceView = new DeviceView(); - if (row[0] != DBNull.Value) deviceView.Id = Convert.ToInt64(row[0]); - if (row[1] != DBNull.Value) deviceView.DevName = row[1].ToString(); - if (row[2] != DBNull.Value) deviceView.DevCode = row[2].ToString(); - if (row[3] != DBNull.Value) deviceView.DevTypeId = row[3].ToString(); - if (row[4] != DBNull.Value) deviceView.DevModel = row[4].ToString(); - if (row[5] != DBNull.Value) deviceView.RegTime = row[5].ToString(); - if (row[6] != DBNull.Value) deviceView.CustomerName = row[6].ToString(); - if (row[7] != DBNull.Value) deviceView.CustomerDev = row[7].ToString(); - if (row[8] != DBNull.Value) deviceView.Channel = row[8].ToString(); - if (row[9] != DBNull.Value) deviceView.Active = Convert.ToInt32(row[9]); - if (row[10] != DBNull.Value) deviceView.StartTime = Convert.ToDateTime(row[10]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[11] != DBNull.Value) deviceView.EndTime = Convert.ToDateTime(row[11]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[12] != DBNull.Value) deviceView.StatusId = row[12].ToString(); - if (row[13] != DBNull.Value) deviceView.Stability = row[13].ToString(); - if (row[14] != DBNull.Value) deviceView.Accuracy = row[14].ToString(); - if (row[15] != DBNull.Value) deviceView.BootFeature = row[15].ToString(); - if (row[16] != DBNull.Value) deviceView.AgeRate = row[16].ToString(); - if (row[17] != DBNull.Value) deviceView.DetectionItemId = Convert.ToInt64(row[17]); + 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(); + + } - //using (MySqlDataReader aReader = aCommand.ExecuteReader()) - //{ - // while (aReader.Read()) - // { - // DeviceView deviceView = new DeviceView(); + aCommand.Dispose(); - // 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 - // //deviceView.DevTypeName = dictService.getNameByCode("devType", aReader.GetString(3)); - // } - // if (!aReader.IsDBNull(4)) deviceView.DevModel = aReader.GetString(4); // devModel - // if (!aReader.IsDBNull(5)) - // { - // DateTime reg = aReader.GetDateTime(5); // regTime - // deviceView.RegTime = reg.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); - // if (!aReader.IsDBNull(9)) deviceView.Active = Convert.ToInt32(aReader.GetString(9)); - // if (!aReader.IsDBNull(10)) - // { - // DateTime reg = aReader.GetDateTime(10); // regTime - // deviceView.StartTime = reg.ToString("yyyy-MM-dd HH:mm:ss"); - // } - // if (!aReader.IsDBNull(11)) - // { - // DateTime reg = aReader.GetDateTime(11); // regTime - // deviceView.EndTime = reg.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 = Convert.ToInt64(aReader.GetString(17)); - - // deviceViewList.Add(deviceView); - - // aCommand.Dispose(); - // } - //} - if (deviceViewList.Count > 0) { foreach (DeviceView deviceView in deviceViewList) @@ -568,9 +574,15 @@ } } } + + 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()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getDeviceByChannel: " + ex.Message + " ; " + ex.ToString()); deviceViewList = null; } finally diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs index 1626aa5..42ca83c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs @@ -92,10 +92,11 @@ if (!aReader.IsDBNull(3)) dict.Code = aReader.GetString(3); nameList.Add(dict); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(MySqlException ex) { @@ -139,10 +140,11 @@ if (!aReader.IsDBNull(3)) counterParam.GeneratorIp = aReader.GetString(3); if (!aReader.IsDBNull(4)) counterParam.SignalSourceIp = aReader.GetString(4); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -220,10 +222,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/RbFreqStdMeas.cs b/RbFreqStandMeasure/RbFreqStdMeas.cs index beae3dc..8d74572 100644 --- a/RbFreqStandMeasure/RbFreqStdMeas.cs +++ b/RbFreqStandMeasure/RbFreqStdMeas.cs @@ -363,24 +363,7 @@ detectionItemService.stopDetection(deviceId, device.DetectionItemId, startTime, endTime, true); } } - deviceService.clearChannel(); - List detectionItemList = detectionItemService.getAll(); - if (detectionItemList != null && detectionItemList.Count > 0) - { - foreach (DetectionItem detectionItem in detectionItemList) - { - long detectionItemId = detectionItem.Id; - if (detectionItem.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem.Stability1.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "0", "", "", ""); - if (detectionItem.Stability10.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "0", "", ""); - if (detectionItem.Stability20.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "0", ""); - if (detectionItem.Stability100.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "", "0"); - if (detectionItem.Accuracy.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "0", "", "", "", "", "", "", ""); - if (detectionItem.BootFeature.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "0", "", "", "", "", "", ""); - if (detectionItem.AgeRate.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "0", "", "", "", "", ""); - } - } - + deviceService.clearChannel(); } else { @@ -590,7 +573,7 @@ break; case 3: // 频率计数器范围 - CounterCtrlForm counterForm = CounterCtrlForm.GetInstance(); + CounterCtrlForm counterForm = new CounterCtrlForm(); counterForm.Show(); panelMain.Controls.Add(counterForm); break; diff --git a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs index 963b90b..a5e9368 100644 --- a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs +++ b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs @@ -29,7 +29,7 @@ + ";password=" + databasePassword + ";Charset=utf8" + ";Allow User Variables=True" - + ";Pooling=true"; + + ";Pooling=True"; mySqlConnect = new MySqlConnection(sConnection); mySqlConnect.Open(); iRetval = 0; diff --git a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs index c69559f..f19bd95 100644 --- a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs +++ b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs @@ -38,6 +38,7 @@ private string stability10; private string stability20; private string stability100; + private string isDetecting; public long Id { get @@ -161,5 +162,6 @@ public string Stability20 { get => stability20; set => stability20 = value; } public string Stability100 { get => stability100; set => stability100 = value; } public string Stability1 { get => stability1; set => stability1 = value; } + public string IsDetecting { get => isDetecting; set => isDetecting = value; } } } \ No newline at end of file diff --git a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs index 399098b..781749c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs @@ -9,7 +9,7 @@ { interface DetectionService { - int add(long deviceId, string frequency, string detecItemType, long detectionItemId); + int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time); List search(long deviceId, string detectionType, string startTime, string endTime, long detectionItemId); diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs index 0fd7b24..4df249b 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs @@ -132,7 +132,30 @@ string sQry = "SELECT * FROM r_counter_check_params"; 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) + // { + // if (row[0] != DBNull.Value) counterCheckParam.Id = Convert.ToInt32(row[0]); + // if (row[1] != DBNull.Value) counterCheckParam.SoOutDelay = row[1].ToString(); + // if (row[2] != DBNull.Value) counterCheckParam.SoEleFrequency = row[2].ToString(); + // if (row[3] != DBNull.Value) counterCheckParam.SoEleAddValue = row[3].ToString(); + // if (row[4] != DBNull.Value) counterCheckParam.SoEleAlarm = row[4].ToString(); + // if (row[5] != DBNull.Value) counterCheckParam.FreThreshold1 = row[5].ToString(); + // if (row[6] != DBNull.Value) counterCheckParam.FreThreshold2 = row[6].ToString(); + // if (row[7] != DBNull.Value) counterCheckParam.FreEleAddValue = row[7].ToString(); + // if (row[8] != DBNull.Value) counterCheckParam.CycThreshold1 = row[8].ToString(); + // if (row[9] != DBNull.Value) counterCheckParam.CycThreshold2 = row[9].ToString(); + // if (row[10] != DBNull.Value) counterCheckParam.CycEleAddValue = row[10].ToString(); + + // } + //} using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -149,10 +172,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(Exception ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs index 52b36f8..2c60ab4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs @@ -32,28 +32,29 @@ //先查询是否有历史数据 string sQry = "select ID from r_counter_data where DEVICE_ID=" + deviceId + " and OUT_VALUE = '" + outValue + "'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - - if (aReader.Read()) + bool isUpdated = false; + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - dataId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) + { + dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + + " where ID=" + dataId; + + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; + cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; + cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; + + cmd.ExecuteNonQuery(); + isUpdated = true; + } aReader.Close(); - sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + - " where ID="+ dataId; - - cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; - cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; - cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; - cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; - - cmd.ExecuteNonQuery(); - } - else - { - aReader.Close(); - + if (!isUpdated) + { sQry = "INSERT INTO r_counter_data (DEVICE_ID, OUT_VALUE, VALUE, SENSITIVITY, LOG_TIME, DETEC_TYPE)" + "values(@DEVICE_ID,@OUT_VALUE,@VALUE,@SENSITIVITY,@LOG_TIME,@DETEC_TYPE)"; @@ -70,14 +71,14 @@ sQry = "SELECT max(ID) from r_counter_data"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - - aReader = cmd.ExecuteReader(); - - if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); - + using (MySqlDataReader aReader = cmd.ExecuteReader()) + { + + if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + } } - aReader.Close(); cmd.Dispose(); iRetval = 0; @@ -144,6 +145,8 @@ cmd.ExecuteNonQuery(); } + + aReader.Close(); } @@ -282,9 +285,10 @@ if (!aReader.IsDBNull(6)) counterData.DetecType = aReader.GetString(6); counterDataList.Add(counterData); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs index 6795325..7500bd4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs @@ -47,10 +47,11 @@ counterDetecInitList.Add(counterDetecInit); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -75,29 +76,31 @@ return iRetval; } } - string sQry = "select ID from r_counter_detec_init where FREQUENCY=" + frequency +" AND CYCLE="+cycle; + string sQry = "select ID from r_counter_detec_init where FREQUENCY='" + frequency +"' AND CYCLE='"+cycle+"'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - if (aReader.Read()) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - initId = Convert.ToInt64(aReader.GetString(0)); - sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; + if (aReader.Read()) + { + initId = Convert.ToInt64(aReader.GetString(0)); + sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; - 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(); - } - else - { - 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 = 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(); + } + else + { + 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.ExecuteNonQuery(); + + } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); iRetval = 0; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs index 97b06ba..abcbaa6 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs @@ -72,26 +72,27 @@ MySqlCommand cmd = new MySqlCommand(sql, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(CommandBehavior.Default); - - if (aReader != null) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) + if (aReader != null) { - //判断门的状态 - if (!aReader.IsDBNull(0)) - counterParam.Id = Convert.ToInt32(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) - counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) - counterParam.BaudRate = aReader.GetString(2); - if (!aReader.IsDBNull(3)) - counterParam.GeneratorIp = aReader.GetString(3); - if (!aReader.IsDBNull(4)) - counterParam.SignalSourceIp = aReader.GetString(4); + if (aReader.Read()) + { + //判断门的状态 + if (!aReader.IsDBNull(0)) + counterParam.Id = Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(1)) + counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); + if (!aReader.IsDBNull(2)) + counterParam.BaudRate = aReader.GetString(2); + if (!aReader.IsDBNull(3)) + counterParam.GeneratorIp = aReader.GetString(3); + if (!aReader.IsDBNull(4)) + counterParam.SignalSourceIp = aReader.GetString(4); + } } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs index cca90fb..1578937 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs @@ -33,8 +33,8 @@ MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@DEVICE_ID", MySqlDbType.Int64, 20).Value = deviceId; - cmd.Parameters.Add("@START_TIME", MySqlDbType.String, 50).Value = startTime; - cmd.Parameters.Add("@END_TIME", MySqlDbType.String, 50).Value = endTime; + cmd.Parameters.Add("@START_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(startTime); + cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(endTime); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 50).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 50).Value = accuracy; cmd.Parameters.Add("@BOOT_FEATURE", MySqlDbType.String, 50).Value = bootFeature; @@ -58,11 +58,11 @@ sQry = "SELECT max(ID) from r_detection_item"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = cmd.ExecuteReader()) { if (aReader.Read()) detectionId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); iRetval = 0; @@ -203,8 +203,9 @@ if (!stability100.Equals("")) sQry = sQry + " STABILITY_100=@STABILITY_100,"; sQry = sQry + " COUNTER_DETEC=@COUNTER_DETEC where ID = " + detectionId; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry: " + sQry); - + MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 10).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 10).Value = accuracy; @@ -283,7 +284,8 @@ return iRetval; } } - + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "停止检测 detectionItemId=======" + detectionItemId); + string sQry = "UPDATE r_device SET STATUSID="+"1"+", CHANNEL=@CHANNEL where ID=" + deviceId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@CHANNEL", MySqlDbType.String, 20).Value = ""; @@ -292,19 +294,21 @@ if (isDeleteData) { - sQry = "DELETE FROM r_detection_item WHERE DEVICE_ID = " + deviceId + " AND START_TIME='" + startTime + "' AND END_TIME='" + endTime + "'"; + sQry = "DELETE FROM r_detection_item WHERE ID=" + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); - sQry = "DELETE FROM r_detection WHERE DEVICE_ID = " + deviceId + " AND (LOG_TIME between'" + startTime + "' and '" + endTime + "')"; + sQry = "DELETE FROM r_detection WHERE DETECTION_ITEM_ID = " + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); } else { - sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME WHERE ID="+ detectionItemId; + sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME, IS_DETECTING=@IS_DETECTING WHERE ID=" + detectionItemId; + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 20).Value = DateTime.Now; + cmd.Parameters.Add("@IS_DETECTING", MySqlDbType.String, 1).Value = "0"; //0-否,1-是 cmd.ExecuteNonQuery(); } @@ -322,8 +326,7 @@ { DetectionItem detectionItem = null; try - { - + { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getById : 数据库链接断开"); @@ -337,6 +340,7 @@ string sQry = "select * from r_detection_item WHERE ID = "+ detectionItemId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + using (MySqlDataReader aReader = cmd.ExecuteReader()) { while (aReader.Read()) @@ -356,11 +360,13 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(15)) detectionItem.IsDetecting = aReader.GetString(15); } - } - + aReader.Close(); + } cmd.Dispose(); + } catch (MySqlException e) { @@ -400,7 +406,7 @@ { DetectionItem detectionItem = new DetectionItem(); //姓名 - if (!aReader.IsDBNull(0)) detectionItem.Id=Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(0)) detectionItem.Id = Convert.ToInt32(aReader.GetString(0)); if (!aReader.IsDBNull(1)) detectionItem.DeviceId = Convert.ToInt64(aReader.GetString(1)); if (!aReader.IsDBNull(2)) detectionItem.StartTime = aReader.GetString(2); if (!aReader.IsDBNull(3)) detectionItem.EndTime = aReader.GetString(3); @@ -416,9 +422,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -468,9 +475,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -498,7 +506,6 @@ string sQry = "SELECT * FROM r_detection_item where ID = " + detectionId; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -518,15 +525,43 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); + //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) + // { + // detectionItem = new DetectionItem(); + // if (row[0] != DBNull.Value) detectionItem.Id = Convert.ToInt64(row[0]); + // if (row[1] != DBNull.Value) detectionItem.DeviceId = Convert.ToInt64(row[1]); + // if (row[2] != DBNull.Value) detectionItem.StartTime = Convert.ToDateTime(row[2]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[3] != DBNull.Value) detectionItem.EndTime = Convert.ToDateTime(row[3]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[4] != DBNull.Value) detectionItem.Stability = row[4].ToString(); + // if (row[5] != DBNull.Value) detectionItem.Accuracy = row[5].ToString(); + // if (row[6] != DBNull.Value) detectionItem.BootFeature = row[6].ToString(); + // if (row[7] != DBNull.Value) detectionItem.AgeRate = row[7].ToString(); + // if (row[8] != DBNull.Value) detectionItem.Interval = row[8].ToString(); + // if (row[10] != DBNull.Value) detectionItem.Channel = row[10].ToString(); + // if (row[11] != DBNull.Value) detectionItem.Stability1 = row[11].ToString(); + // if (row[12] != DBNull.Value) detectionItem.Stability10 = row[12].ToString(); + // if (row[13] != DBNull.Value) detectionItem.Stability20 = row[13].ToString(); + // if (row[14] != DBNull.Value) detectionItem.Stability100 = row[14].ToString(); + + // } + //} } catch (MySqlException ex) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDetectionItem: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchById: " + ex.Message); } return detectionItem; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs index e2a5893..5b3deb0 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs @@ -14,7 +14,7 @@ { class DetectionServiceImpl : DetectionService { - public int add(long deviceId, string frequency, string detecItemType, long detectionItemId) + public int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time) { int iRetval = -1; try @@ -36,7 +36,7 @@ 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 = DateTime.Now; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.DateTime, 0).Value = time; cmd.Parameters.Add("@DETECTION_ITEM", MySqlDbType.String, 0).Value = detecItemType; cmd.Parameters.Add("@DETECTION_ITEM_ID", MySqlDbType.Int64, 0).Value = detectionItemId; @@ -108,24 +108,26 @@ string sQry = "SELECT * FROM r_detection where DEVICE_ID = " + deviceId +" and DETECTION_ITEM='" + detectionType + "' and (LOG_TIME BETWEEN '" + startTime + "' and '"+ endTime + "') and DETECTION_ITEM_ID="+detectionItemId+" order by LOG_TIME"; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) { - Model.Detection detection = new Model.Detection(); - //姓名 - if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) detection.LogTime = Convert.ToDateTime(aReader.GetString(2)).ToString("yyyy-MM-dd HH:mm:ss"); - if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); - if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); + Detection detection = new Detection(); + + if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); // id + if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); // devName + if (!aReader.IsDBNull(2)) detection.LogTime = aReader.GetString(2); // devCode + if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); // devType + if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); // devModel detectionDtoList.Add(detection); } + aReader.Close(); + - aCommand.Dispose(); } + aCommand.Dispose(); + } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs index 9413e2f..b224bc1 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs @@ -53,7 +53,8 @@ using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); @@ -87,8 +88,7 @@ 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; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry : "+ sQry + "; statusId="+ statusId); - + 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; @@ -183,7 +183,7 @@ } MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -208,10 +208,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -254,7 +255,30 @@ 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()) @@ -279,10 +303,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -342,7 +367,30 @@ 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()) @@ -372,10 +420,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -442,9 +491,10 @@ { totalCount = aReader.GetInt32(0); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -477,89 +527,45 @@ return null; } } - - string sQry = "SELECT * FROM r_deviceview where ACTIVE = 0 and STATUSID = 2 " + "and ('" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' <= END_TIME)"; - - 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) + //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))"; + MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { - foreach (DataRow row in dt.Rows) + while (aReader.Read()) { DeviceView deviceView = new DeviceView(); - if (row[0] != DBNull.Value) deviceView.Id = Convert.ToInt64(row[0]); - if (row[1] != DBNull.Value) deviceView.DevName = row[1].ToString(); - if (row[2] != DBNull.Value) deviceView.DevCode = row[2].ToString(); - if (row[3] != DBNull.Value) deviceView.DevTypeId = row[3].ToString(); - if (row[4] != DBNull.Value) deviceView.DevModel = row[4].ToString(); - if (row[5] != DBNull.Value) deviceView.RegTime = row[5].ToString(); - if (row[6] != DBNull.Value) deviceView.CustomerName = row[6].ToString(); - if (row[7] != DBNull.Value) deviceView.CustomerDev = row[7].ToString(); - if (row[8] != DBNull.Value) deviceView.Channel = row[8].ToString(); - if (row[9] != DBNull.Value) deviceView.Active = Convert.ToInt32(row[9]); - if (row[10] != DBNull.Value) deviceView.StartTime = Convert.ToDateTime(row[10]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[11] != DBNull.Value) deviceView.EndTime = Convert.ToDateTime(row[11]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[12] != DBNull.Value) deviceView.StatusId = row[12].ToString(); - if (row[13] != DBNull.Value) deviceView.Stability = row[13].ToString(); - if (row[14] != DBNull.Value) deviceView.Accuracy = row[14].ToString(); - if (row[15] != DBNull.Value) deviceView.BootFeature = row[15].ToString(); - if (row[16] != DBNull.Value) deviceView.AgeRate = row[16].ToString(); - if (row[17] != DBNull.Value) deviceView.DetectionItemId = Convert.ToInt64(row[17]); + 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(); + + } - //using (MySqlDataReader aReader = aCommand.ExecuteReader()) - //{ - // while (aReader.Read()) - // { - // DeviceView deviceView = new DeviceView(); + aCommand.Dispose(); - // 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 - // //deviceView.DevTypeName = dictService.getNameByCode("devType", aReader.GetString(3)); - // } - // if (!aReader.IsDBNull(4)) deviceView.DevModel = aReader.GetString(4); // devModel - // if (!aReader.IsDBNull(5)) - // { - // DateTime reg = aReader.GetDateTime(5); // regTime - // deviceView.RegTime = reg.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); - // if (!aReader.IsDBNull(9)) deviceView.Active = Convert.ToInt32(aReader.GetString(9)); - // if (!aReader.IsDBNull(10)) - // { - // DateTime reg = aReader.GetDateTime(10); // regTime - // deviceView.StartTime = reg.ToString("yyyy-MM-dd HH:mm:ss"); - // } - // if (!aReader.IsDBNull(11)) - // { - // DateTime reg = aReader.GetDateTime(11); // regTime - // deviceView.EndTime = reg.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 = Convert.ToInt64(aReader.GetString(17)); - - // deviceViewList.Add(deviceView); - - // aCommand.Dispose(); - // } - //} - if (deviceViewList.Count > 0) { foreach (DeviceView deviceView in deviceViewList) @@ -568,9 +574,15 @@ } } } + + 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()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getDeviceByChannel: " + ex.Message + " ; " + ex.ToString()); deviceViewList = null; } finally diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs index 1626aa5..42ca83c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs @@ -92,10 +92,11 @@ if (!aReader.IsDBNull(3)) dict.Code = aReader.GetString(3); nameList.Add(dict); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(MySqlException ex) { @@ -139,10 +140,11 @@ if (!aReader.IsDBNull(3)) counterParam.GeneratorIp = aReader.GetString(3); if (!aReader.IsDBNull(4)) counterParam.SignalSourceIp = aReader.GetString(4); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -220,10 +222,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/RbFreqStdMeas.cs b/RbFreqStandMeasure/RbFreqStdMeas.cs index beae3dc..8d74572 100644 --- a/RbFreqStandMeasure/RbFreqStdMeas.cs +++ b/RbFreqStandMeasure/RbFreqStdMeas.cs @@ -363,24 +363,7 @@ detectionItemService.stopDetection(deviceId, device.DetectionItemId, startTime, endTime, true); } } - deviceService.clearChannel(); - List detectionItemList = detectionItemService.getAll(); - if (detectionItemList != null && detectionItemList.Count > 0) - { - foreach (DetectionItem detectionItem in detectionItemList) - { - long detectionItemId = detectionItem.Id; - if (detectionItem.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem.Stability1.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "0", "", "", ""); - if (detectionItem.Stability10.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "0", "", ""); - if (detectionItem.Stability20.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "0", ""); - if (detectionItem.Stability100.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "", "0"); - if (detectionItem.Accuracy.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "0", "", "", "", "", "", "", ""); - if (detectionItem.BootFeature.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "0", "", "", "", "", "", ""); - if (detectionItem.AgeRate.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "0", "", "", "", "", ""); - } - } - + deviceService.clearChannel(); } else { @@ -590,7 +573,7 @@ break; case 3: // 频率计数器范围 - CounterCtrlForm counterForm = CounterCtrlForm.GetInstance(); + CounterCtrlForm counterForm = new CounterCtrlForm(); counterForm.Show(); panelMain.Controls.Add(counterForm); break; diff --git a/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe b/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe index 70dc261..11271b0 100644 --- a/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe +++ b/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe Binary files differ diff --git a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs index 963b90b..a5e9368 100644 --- a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs +++ b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs @@ -29,7 +29,7 @@ + ";password=" + databasePassword + ";Charset=utf8" + ";Allow User Variables=True" - + ";Pooling=true"; + + ";Pooling=True"; mySqlConnect = new MySqlConnection(sConnection); mySqlConnect.Open(); iRetval = 0; diff --git a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs index c69559f..f19bd95 100644 --- a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs +++ b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs @@ -38,6 +38,7 @@ private string stability10; private string stability20; private string stability100; + private string isDetecting; public long Id { get @@ -161,5 +162,6 @@ public string Stability20 { get => stability20; set => stability20 = value; } public string Stability100 { get => stability100; set => stability100 = value; } public string Stability1 { get => stability1; set => stability1 = value; } + public string IsDetecting { get => isDetecting; set => isDetecting = value; } } } \ No newline at end of file diff --git a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs index 399098b..781749c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs @@ -9,7 +9,7 @@ { interface DetectionService { - int add(long deviceId, string frequency, string detecItemType, long detectionItemId); + int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time); List search(long deviceId, string detectionType, string startTime, string endTime, long detectionItemId); diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs index 0fd7b24..4df249b 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs @@ -132,7 +132,30 @@ string sQry = "SELECT * FROM r_counter_check_params"; 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) + // { + // if (row[0] != DBNull.Value) counterCheckParam.Id = Convert.ToInt32(row[0]); + // if (row[1] != DBNull.Value) counterCheckParam.SoOutDelay = row[1].ToString(); + // if (row[2] != DBNull.Value) counterCheckParam.SoEleFrequency = row[2].ToString(); + // if (row[3] != DBNull.Value) counterCheckParam.SoEleAddValue = row[3].ToString(); + // if (row[4] != DBNull.Value) counterCheckParam.SoEleAlarm = row[4].ToString(); + // if (row[5] != DBNull.Value) counterCheckParam.FreThreshold1 = row[5].ToString(); + // if (row[6] != DBNull.Value) counterCheckParam.FreThreshold2 = row[6].ToString(); + // if (row[7] != DBNull.Value) counterCheckParam.FreEleAddValue = row[7].ToString(); + // if (row[8] != DBNull.Value) counterCheckParam.CycThreshold1 = row[8].ToString(); + // if (row[9] != DBNull.Value) counterCheckParam.CycThreshold2 = row[9].ToString(); + // if (row[10] != DBNull.Value) counterCheckParam.CycEleAddValue = row[10].ToString(); + + // } + //} using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -149,10 +172,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(Exception ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs index 52b36f8..2c60ab4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs @@ -32,28 +32,29 @@ //先查询是否有历史数据 string sQry = "select ID from r_counter_data where DEVICE_ID=" + deviceId + " and OUT_VALUE = '" + outValue + "'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - - if (aReader.Read()) + bool isUpdated = false; + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - dataId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) + { + dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + + " where ID=" + dataId; + + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; + cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; + cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; + + cmd.ExecuteNonQuery(); + isUpdated = true; + } aReader.Close(); - sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + - " where ID="+ dataId; - - cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; - cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; - cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; - cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; - - cmd.ExecuteNonQuery(); - } - else - { - aReader.Close(); - + if (!isUpdated) + { sQry = "INSERT INTO r_counter_data (DEVICE_ID, OUT_VALUE, VALUE, SENSITIVITY, LOG_TIME, DETEC_TYPE)" + "values(@DEVICE_ID,@OUT_VALUE,@VALUE,@SENSITIVITY,@LOG_TIME,@DETEC_TYPE)"; @@ -70,14 +71,14 @@ sQry = "SELECT max(ID) from r_counter_data"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - - aReader = cmd.ExecuteReader(); - - if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); - + using (MySqlDataReader aReader = cmd.ExecuteReader()) + { + + if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + } } - aReader.Close(); cmd.Dispose(); iRetval = 0; @@ -144,6 +145,8 @@ cmd.ExecuteNonQuery(); } + + aReader.Close(); } @@ -282,9 +285,10 @@ if (!aReader.IsDBNull(6)) counterData.DetecType = aReader.GetString(6); counterDataList.Add(counterData); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs index 6795325..7500bd4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs @@ -47,10 +47,11 @@ counterDetecInitList.Add(counterDetecInit); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -75,29 +76,31 @@ return iRetval; } } - string sQry = "select ID from r_counter_detec_init where FREQUENCY=" + frequency +" AND CYCLE="+cycle; + string sQry = "select ID from r_counter_detec_init where FREQUENCY='" + frequency +"' AND CYCLE='"+cycle+"'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - if (aReader.Read()) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - initId = Convert.ToInt64(aReader.GetString(0)); - sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; + if (aReader.Read()) + { + initId = Convert.ToInt64(aReader.GetString(0)); + sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; - 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(); - } - else - { - 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 = 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(); + } + else + { + 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.ExecuteNonQuery(); + + } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); iRetval = 0; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs index 97b06ba..abcbaa6 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs @@ -72,26 +72,27 @@ MySqlCommand cmd = new MySqlCommand(sql, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(CommandBehavior.Default); - - if (aReader != null) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) + if (aReader != null) { - //判断门的状态 - if (!aReader.IsDBNull(0)) - counterParam.Id = Convert.ToInt32(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) - counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) - counterParam.BaudRate = aReader.GetString(2); - if (!aReader.IsDBNull(3)) - counterParam.GeneratorIp = aReader.GetString(3); - if (!aReader.IsDBNull(4)) - counterParam.SignalSourceIp = aReader.GetString(4); + if (aReader.Read()) + { + //判断门的状态 + if (!aReader.IsDBNull(0)) + counterParam.Id = Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(1)) + counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); + if (!aReader.IsDBNull(2)) + counterParam.BaudRate = aReader.GetString(2); + if (!aReader.IsDBNull(3)) + counterParam.GeneratorIp = aReader.GetString(3); + if (!aReader.IsDBNull(4)) + counterParam.SignalSourceIp = aReader.GetString(4); + } } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs index cca90fb..1578937 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs @@ -33,8 +33,8 @@ MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@DEVICE_ID", MySqlDbType.Int64, 20).Value = deviceId; - cmd.Parameters.Add("@START_TIME", MySqlDbType.String, 50).Value = startTime; - cmd.Parameters.Add("@END_TIME", MySqlDbType.String, 50).Value = endTime; + cmd.Parameters.Add("@START_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(startTime); + cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(endTime); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 50).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 50).Value = accuracy; cmd.Parameters.Add("@BOOT_FEATURE", MySqlDbType.String, 50).Value = bootFeature; @@ -58,11 +58,11 @@ sQry = "SELECT max(ID) from r_detection_item"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = cmd.ExecuteReader()) { if (aReader.Read()) detectionId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); iRetval = 0; @@ -203,8 +203,9 @@ if (!stability100.Equals("")) sQry = sQry + " STABILITY_100=@STABILITY_100,"; sQry = sQry + " COUNTER_DETEC=@COUNTER_DETEC where ID = " + detectionId; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry: " + sQry); - + MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 10).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 10).Value = accuracy; @@ -283,7 +284,8 @@ return iRetval; } } - + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "停止检测 detectionItemId=======" + detectionItemId); + string sQry = "UPDATE r_device SET STATUSID="+"1"+", CHANNEL=@CHANNEL where ID=" + deviceId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@CHANNEL", MySqlDbType.String, 20).Value = ""; @@ -292,19 +294,21 @@ if (isDeleteData) { - sQry = "DELETE FROM r_detection_item WHERE DEVICE_ID = " + deviceId + " AND START_TIME='" + startTime + "' AND END_TIME='" + endTime + "'"; + sQry = "DELETE FROM r_detection_item WHERE ID=" + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); - sQry = "DELETE FROM r_detection WHERE DEVICE_ID = " + deviceId + " AND (LOG_TIME between'" + startTime + "' and '" + endTime + "')"; + sQry = "DELETE FROM r_detection WHERE DETECTION_ITEM_ID = " + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); } else { - sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME WHERE ID="+ detectionItemId; + sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME, IS_DETECTING=@IS_DETECTING WHERE ID=" + detectionItemId; + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 20).Value = DateTime.Now; + cmd.Parameters.Add("@IS_DETECTING", MySqlDbType.String, 1).Value = "0"; //0-否,1-是 cmd.ExecuteNonQuery(); } @@ -322,8 +326,7 @@ { DetectionItem detectionItem = null; try - { - + { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getById : 数据库链接断开"); @@ -337,6 +340,7 @@ string sQry = "select * from r_detection_item WHERE ID = "+ detectionItemId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + using (MySqlDataReader aReader = cmd.ExecuteReader()) { while (aReader.Read()) @@ -356,11 +360,13 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(15)) detectionItem.IsDetecting = aReader.GetString(15); } - } - + aReader.Close(); + } cmd.Dispose(); + } catch (MySqlException e) { @@ -400,7 +406,7 @@ { DetectionItem detectionItem = new DetectionItem(); //姓名 - if (!aReader.IsDBNull(0)) detectionItem.Id=Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(0)) detectionItem.Id = Convert.ToInt32(aReader.GetString(0)); if (!aReader.IsDBNull(1)) detectionItem.DeviceId = Convert.ToInt64(aReader.GetString(1)); if (!aReader.IsDBNull(2)) detectionItem.StartTime = aReader.GetString(2); if (!aReader.IsDBNull(3)) detectionItem.EndTime = aReader.GetString(3); @@ -416,9 +422,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -468,9 +475,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -498,7 +506,6 @@ string sQry = "SELECT * FROM r_detection_item where ID = " + detectionId; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -518,15 +525,43 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); + //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) + // { + // detectionItem = new DetectionItem(); + // if (row[0] != DBNull.Value) detectionItem.Id = Convert.ToInt64(row[0]); + // if (row[1] != DBNull.Value) detectionItem.DeviceId = Convert.ToInt64(row[1]); + // if (row[2] != DBNull.Value) detectionItem.StartTime = Convert.ToDateTime(row[2]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[3] != DBNull.Value) detectionItem.EndTime = Convert.ToDateTime(row[3]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[4] != DBNull.Value) detectionItem.Stability = row[4].ToString(); + // if (row[5] != DBNull.Value) detectionItem.Accuracy = row[5].ToString(); + // if (row[6] != DBNull.Value) detectionItem.BootFeature = row[6].ToString(); + // if (row[7] != DBNull.Value) detectionItem.AgeRate = row[7].ToString(); + // if (row[8] != DBNull.Value) detectionItem.Interval = row[8].ToString(); + // if (row[10] != DBNull.Value) detectionItem.Channel = row[10].ToString(); + // if (row[11] != DBNull.Value) detectionItem.Stability1 = row[11].ToString(); + // if (row[12] != DBNull.Value) detectionItem.Stability10 = row[12].ToString(); + // if (row[13] != DBNull.Value) detectionItem.Stability20 = row[13].ToString(); + // if (row[14] != DBNull.Value) detectionItem.Stability100 = row[14].ToString(); + + // } + //} } catch (MySqlException ex) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDetectionItem: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchById: " + ex.Message); } return detectionItem; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs index e2a5893..5b3deb0 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs @@ -14,7 +14,7 @@ { class DetectionServiceImpl : DetectionService { - public int add(long deviceId, string frequency, string detecItemType, long detectionItemId) + public int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time) { int iRetval = -1; try @@ -36,7 +36,7 @@ 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 = DateTime.Now; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.DateTime, 0).Value = time; cmd.Parameters.Add("@DETECTION_ITEM", MySqlDbType.String, 0).Value = detecItemType; cmd.Parameters.Add("@DETECTION_ITEM_ID", MySqlDbType.Int64, 0).Value = detectionItemId; @@ -108,24 +108,26 @@ string sQry = "SELECT * FROM r_detection where DEVICE_ID = " + deviceId +" and DETECTION_ITEM='" + detectionType + "' and (LOG_TIME BETWEEN '" + startTime + "' and '"+ endTime + "') and DETECTION_ITEM_ID="+detectionItemId+" order by LOG_TIME"; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) { - Model.Detection detection = new Model.Detection(); - //姓名 - if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) detection.LogTime = Convert.ToDateTime(aReader.GetString(2)).ToString("yyyy-MM-dd HH:mm:ss"); - if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); - if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); + Detection detection = new Detection(); + + if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); // id + if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); // devName + if (!aReader.IsDBNull(2)) detection.LogTime = aReader.GetString(2); // devCode + if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); // devType + if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); // devModel detectionDtoList.Add(detection); } + aReader.Close(); + - aCommand.Dispose(); } + aCommand.Dispose(); + } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs index 9413e2f..b224bc1 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs @@ -53,7 +53,8 @@ using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); @@ -87,8 +88,7 @@ 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; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry : "+ sQry + "; statusId="+ statusId); - + 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; @@ -183,7 +183,7 @@ } MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -208,10 +208,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -254,7 +255,30 @@ 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()) @@ -279,10 +303,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -342,7 +367,30 @@ 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()) @@ -372,10 +420,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -442,9 +491,10 @@ { totalCount = aReader.GetInt32(0); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -477,89 +527,45 @@ return null; } } - - string sQry = "SELECT * FROM r_deviceview where ACTIVE = 0 and STATUSID = 2 " + "and ('" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' <= END_TIME)"; - - 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) + //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))"; + MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { - foreach (DataRow row in dt.Rows) + while (aReader.Read()) { DeviceView deviceView = new DeviceView(); - if (row[0] != DBNull.Value) deviceView.Id = Convert.ToInt64(row[0]); - if (row[1] != DBNull.Value) deviceView.DevName = row[1].ToString(); - if (row[2] != DBNull.Value) deviceView.DevCode = row[2].ToString(); - if (row[3] != DBNull.Value) deviceView.DevTypeId = row[3].ToString(); - if (row[4] != DBNull.Value) deviceView.DevModel = row[4].ToString(); - if (row[5] != DBNull.Value) deviceView.RegTime = row[5].ToString(); - if (row[6] != DBNull.Value) deviceView.CustomerName = row[6].ToString(); - if (row[7] != DBNull.Value) deviceView.CustomerDev = row[7].ToString(); - if (row[8] != DBNull.Value) deviceView.Channel = row[8].ToString(); - if (row[9] != DBNull.Value) deviceView.Active = Convert.ToInt32(row[9]); - if (row[10] != DBNull.Value) deviceView.StartTime = Convert.ToDateTime(row[10]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[11] != DBNull.Value) deviceView.EndTime = Convert.ToDateTime(row[11]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[12] != DBNull.Value) deviceView.StatusId = row[12].ToString(); - if (row[13] != DBNull.Value) deviceView.Stability = row[13].ToString(); - if (row[14] != DBNull.Value) deviceView.Accuracy = row[14].ToString(); - if (row[15] != DBNull.Value) deviceView.BootFeature = row[15].ToString(); - if (row[16] != DBNull.Value) deviceView.AgeRate = row[16].ToString(); - if (row[17] != DBNull.Value) deviceView.DetectionItemId = Convert.ToInt64(row[17]); + 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(); + + } - //using (MySqlDataReader aReader = aCommand.ExecuteReader()) - //{ - // while (aReader.Read()) - // { - // DeviceView deviceView = new DeviceView(); + aCommand.Dispose(); - // 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 - // //deviceView.DevTypeName = dictService.getNameByCode("devType", aReader.GetString(3)); - // } - // if (!aReader.IsDBNull(4)) deviceView.DevModel = aReader.GetString(4); // devModel - // if (!aReader.IsDBNull(5)) - // { - // DateTime reg = aReader.GetDateTime(5); // regTime - // deviceView.RegTime = reg.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); - // if (!aReader.IsDBNull(9)) deviceView.Active = Convert.ToInt32(aReader.GetString(9)); - // if (!aReader.IsDBNull(10)) - // { - // DateTime reg = aReader.GetDateTime(10); // regTime - // deviceView.StartTime = reg.ToString("yyyy-MM-dd HH:mm:ss"); - // } - // if (!aReader.IsDBNull(11)) - // { - // DateTime reg = aReader.GetDateTime(11); // regTime - // deviceView.EndTime = reg.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 = Convert.ToInt64(aReader.GetString(17)); - - // deviceViewList.Add(deviceView); - - // aCommand.Dispose(); - // } - //} - if (deviceViewList.Count > 0) { foreach (DeviceView deviceView in deviceViewList) @@ -568,9 +574,15 @@ } } } + + 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()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getDeviceByChannel: " + ex.Message + " ; " + ex.ToString()); deviceViewList = null; } finally diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs index 1626aa5..42ca83c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs @@ -92,10 +92,11 @@ if (!aReader.IsDBNull(3)) dict.Code = aReader.GetString(3); nameList.Add(dict); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(MySqlException ex) { @@ -139,10 +140,11 @@ if (!aReader.IsDBNull(3)) counterParam.GeneratorIp = aReader.GetString(3); if (!aReader.IsDBNull(4)) counterParam.SignalSourceIp = aReader.GetString(4); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -220,10 +222,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/RbFreqStdMeas.cs b/RbFreqStandMeasure/RbFreqStdMeas.cs index beae3dc..8d74572 100644 --- a/RbFreqStandMeasure/RbFreqStdMeas.cs +++ b/RbFreqStandMeasure/RbFreqStdMeas.cs @@ -363,24 +363,7 @@ detectionItemService.stopDetection(deviceId, device.DetectionItemId, startTime, endTime, true); } } - deviceService.clearChannel(); - List detectionItemList = detectionItemService.getAll(); - if (detectionItemList != null && detectionItemList.Count > 0) - { - foreach (DetectionItem detectionItem in detectionItemList) - { - long detectionItemId = detectionItem.Id; - if (detectionItem.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem.Stability1.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "0", "", "", ""); - if (detectionItem.Stability10.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "0", "", ""); - if (detectionItem.Stability20.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "0", ""); - if (detectionItem.Stability100.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "", "0"); - if (detectionItem.Accuracy.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "0", "", "", "", "", "", "", ""); - if (detectionItem.BootFeature.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "0", "", "", "", "", "", ""); - if (detectionItem.AgeRate.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "0", "", "", "", "", ""); - } - } - + deviceService.clearChannel(); } else { @@ -590,7 +573,7 @@ break; case 3: // 频率计数器范围 - CounterCtrlForm counterForm = CounterCtrlForm.GetInstance(); + CounterCtrlForm counterForm = new CounterCtrlForm(); counterForm.Show(); panelMain.Controls.Add(counterForm); break; diff --git a/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe b/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe index 70dc261..11271b0 100644 --- a/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe +++ b/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe Binary files differ diff --git a/RbFreqStandMeasure/counter/CounterCtrlForm.cs b/RbFreqStandMeasure/counter/CounterCtrlForm.cs index 951a19c..e45f17b 100644 --- a/RbFreqStandMeasure/counter/CounterCtrlForm.cs +++ b/RbFreqStandMeasure/counter/CounterCtrlForm.cs @@ -39,6 +39,9 @@ GPIBService tcpService = new TCPServiceImpl(); string valueOld = ""; + string valueOldBack = ""; + string valueOldSensi = ""; + string valueOldTime = ""; #region 样式常量定影 private readonly Color titleBackColor = Color.FromArgb(63, 132, 215); // #3F64D7 @@ -55,8 +58,8 @@ return _counterCtrlForm; } - - private CounterCtrlForm() + + public CounterCtrlForm() { InitializeComponent(); @@ -69,7 +72,7 @@ comboBox_detecModel.SelectedIndex = 0; InitTableCounter(); - LoadCounterDetecInitList(); + //LoadCounterDetecInitList(); if (list != null && list.Count > 0) { @@ -221,12 +224,12 @@ table_counterDetecInit.Columns.Add("initId", Type.GetType("System.Int32")); table_counterDetecInit.Columns.Add("counterDataId", Type.GetType("System.Int64")); - if (comboBox_counters.Text != "") + if (((DeviceDto)comboBox_counters.SelectedItem).DevName != "") { - List list = deviceService.search(comboBox_counters.Text, "", "", "", "", ""); + List list = deviceService.search(((DeviceDto)comboBox_counters.SelectedItem).DevName, "", "", "", "", ""); if (null != list && list.Count > 0) { - devType = list[0].DevTypeName; + devType = list[0].DevModel; devCode = list[0].DevCode; } @@ -344,6 +347,18 @@ { valueOld = dataGridView_CounterResult.CurrentCell.Value.ToString(); } + else if (e.ColumnIndex == 5) + { + valueOldBack = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } + else if (e.ColumnIndex == 6) + { + valueOldSensi = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } + else if (e.ColumnIndex == 7) + { + valueOldTime = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } } @@ -522,7 +537,10 @@ dataGridView_CounterResult.ReadOnly = true; btn_add.Enabled = false; benDelete.Enabled = false; - ///btn_dropDetecModel.Enabled = false; + comboBox_counters.Enabled = false; + comboBox_detecModel.Enabled = false; + text_counterIp.ReadOnly = true; + text_signal.ReadOnly = true; string[] arr = text_counterIp.Text.Split('.'); if (arr.Length != 4) @@ -643,11 +661,11 @@ Invoke(new MethodInvoker(delegate () { SetDevTestDlg.inDetecCounterId = -1; - //text_devName.ReadOnly = false; - //btn_downCounterList.Enabled = true; btnStart.Enabled = true; - //btn_dropDetecModel.Enabled = true; - //textBox_detecModel.ReadOnly = false; + comboBox_counters.Enabled = true; + comboBox_detecModel.Enabled = true; + text_counterIp.ReadOnly = false; + text_signal.ReadOnly = false; })); dataGridView_CounterResult.ReadOnly = false; @@ -736,6 +754,8 @@ if (!checkFreq(value)) { MessageBox.Show("请输入格式正确的测量频率值!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldBack; + valueOldBack = ""; return; } } @@ -744,6 +764,8 @@ if (!checkCyc(value)) { MessageBox.Show("请输入格式正确的测量周期值!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldBack; + valueOldBack = ""; return; } } @@ -753,11 +775,21 @@ { if (!String.IsNullOrEmpty(value)) { + if (value.Contains(".") && ((value.IndexOf('.') != value.LastIndexOf('.')) || value.IndexOf('.') == 0 || value.LastIndexOf('.') == value.Length)) + { + MessageBox.Show("请输入格式正确的灵敏度!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldSensi; + valueOldSensi = ""; + return; + } + string pattern = @"^[0-9.]+$"; Regex regex = new Regex(pattern); if (!regex.IsMatch(value)) { MessageBox.Show("请输入格式正确的灵敏度!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldSensi; + valueOldSensi = ""; return; } } @@ -772,7 +804,8 @@ } catch { - dataGridView_CounterResult.Rows[e.RowIndex].Cells[7].Value = ""; + dataGridView_CounterResult.CurrentCell.Value = valueOldTime; + valueOldTime = ""; MessageBox.Show("请输入格式正确的时间!"); return; } diff --git a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs index 963b90b..a5e9368 100644 --- a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs +++ b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs @@ -29,7 +29,7 @@ + ";password=" + databasePassword + ";Charset=utf8" + ";Allow User Variables=True" - + ";Pooling=true"; + + ";Pooling=True"; mySqlConnect = new MySqlConnection(sConnection); mySqlConnect.Open(); iRetval = 0; diff --git a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs index c69559f..f19bd95 100644 --- a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs +++ b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs @@ -38,6 +38,7 @@ private string stability10; private string stability20; private string stability100; + private string isDetecting; public long Id { get @@ -161,5 +162,6 @@ public string Stability20 { get => stability20; set => stability20 = value; } public string Stability100 { get => stability100; set => stability100 = value; } public string Stability1 { get => stability1; set => stability1 = value; } + public string IsDetecting { get => isDetecting; set => isDetecting = value; } } } \ No newline at end of file diff --git a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs index 399098b..781749c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs @@ -9,7 +9,7 @@ { interface DetectionService { - int add(long deviceId, string frequency, string detecItemType, long detectionItemId); + int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time); List search(long deviceId, string detectionType, string startTime, string endTime, long detectionItemId); diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs index 0fd7b24..4df249b 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs @@ -132,7 +132,30 @@ string sQry = "SELECT * FROM r_counter_check_params"; 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) + // { + // if (row[0] != DBNull.Value) counterCheckParam.Id = Convert.ToInt32(row[0]); + // if (row[1] != DBNull.Value) counterCheckParam.SoOutDelay = row[1].ToString(); + // if (row[2] != DBNull.Value) counterCheckParam.SoEleFrequency = row[2].ToString(); + // if (row[3] != DBNull.Value) counterCheckParam.SoEleAddValue = row[3].ToString(); + // if (row[4] != DBNull.Value) counterCheckParam.SoEleAlarm = row[4].ToString(); + // if (row[5] != DBNull.Value) counterCheckParam.FreThreshold1 = row[5].ToString(); + // if (row[6] != DBNull.Value) counterCheckParam.FreThreshold2 = row[6].ToString(); + // if (row[7] != DBNull.Value) counterCheckParam.FreEleAddValue = row[7].ToString(); + // if (row[8] != DBNull.Value) counterCheckParam.CycThreshold1 = row[8].ToString(); + // if (row[9] != DBNull.Value) counterCheckParam.CycThreshold2 = row[9].ToString(); + // if (row[10] != DBNull.Value) counterCheckParam.CycEleAddValue = row[10].ToString(); + + // } + //} using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -149,10 +172,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(Exception ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs index 52b36f8..2c60ab4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs @@ -32,28 +32,29 @@ //先查询是否有历史数据 string sQry = "select ID from r_counter_data where DEVICE_ID=" + deviceId + " and OUT_VALUE = '" + outValue + "'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - - if (aReader.Read()) + bool isUpdated = false; + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - dataId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) + { + dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + + " where ID=" + dataId; + + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; + cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; + cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; + + cmd.ExecuteNonQuery(); + isUpdated = true; + } aReader.Close(); - sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + - " where ID="+ dataId; - - cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; - cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; - cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; - cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; - - cmd.ExecuteNonQuery(); - } - else - { - aReader.Close(); - + if (!isUpdated) + { sQry = "INSERT INTO r_counter_data (DEVICE_ID, OUT_VALUE, VALUE, SENSITIVITY, LOG_TIME, DETEC_TYPE)" + "values(@DEVICE_ID,@OUT_VALUE,@VALUE,@SENSITIVITY,@LOG_TIME,@DETEC_TYPE)"; @@ -70,14 +71,14 @@ sQry = "SELECT max(ID) from r_counter_data"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - - aReader = cmd.ExecuteReader(); - - if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); - + using (MySqlDataReader aReader = cmd.ExecuteReader()) + { + + if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + } } - aReader.Close(); cmd.Dispose(); iRetval = 0; @@ -144,6 +145,8 @@ cmd.ExecuteNonQuery(); } + + aReader.Close(); } @@ -282,9 +285,10 @@ if (!aReader.IsDBNull(6)) counterData.DetecType = aReader.GetString(6); counterDataList.Add(counterData); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs index 6795325..7500bd4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs @@ -47,10 +47,11 @@ counterDetecInitList.Add(counterDetecInit); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -75,29 +76,31 @@ return iRetval; } } - string sQry = "select ID from r_counter_detec_init where FREQUENCY=" + frequency +" AND CYCLE="+cycle; + string sQry = "select ID from r_counter_detec_init where FREQUENCY='" + frequency +"' AND CYCLE='"+cycle+"'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - if (aReader.Read()) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - initId = Convert.ToInt64(aReader.GetString(0)); - sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; + if (aReader.Read()) + { + initId = Convert.ToInt64(aReader.GetString(0)); + sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; - 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(); - } - else - { - 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 = 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(); + } + else + { + 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.ExecuteNonQuery(); + + } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); iRetval = 0; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs index 97b06ba..abcbaa6 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs @@ -72,26 +72,27 @@ MySqlCommand cmd = new MySqlCommand(sql, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(CommandBehavior.Default); - - if (aReader != null) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) + if (aReader != null) { - //判断门的状态 - if (!aReader.IsDBNull(0)) - counterParam.Id = Convert.ToInt32(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) - counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) - counterParam.BaudRate = aReader.GetString(2); - if (!aReader.IsDBNull(3)) - counterParam.GeneratorIp = aReader.GetString(3); - if (!aReader.IsDBNull(4)) - counterParam.SignalSourceIp = aReader.GetString(4); + if (aReader.Read()) + { + //判断门的状态 + if (!aReader.IsDBNull(0)) + counterParam.Id = Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(1)) + counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); + if (!aReader.IsDBNull(2)) + counterParam.BaudRate = aReader.GetString(2); + if (!aReader.IsDBNull(3)) + counterParam.GeneratorIp = aReader.GetString(3); + if (!aReader.IsDBNull(4)) + counterParam.SignalSourceIp = aReader.GetString(4); + } } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs index cca90fb..1578937 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs @@ -33,8 +33,8 @@ MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@DEVICE_ID", MySqlDbType.Int64, 20).Value = deviceId; - cmd.Parameters.Add("@START_TIME", MySqlDbType.String, 50).Value = startTime; - cmd.Parameters.Add("@END_TIME", MySqlDbType.String, 50).Value = endTime; + cmd.Parameters.Add("@START_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(startTime); + cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(endTime); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 50).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 50).Value = accuracy; cmd.Parameters.Add("@BOOT_FEATURE", MySqlDbType.String, 50).Value = bootFeature; @@ -58,11 +58,11 @@ sQry = "SELECT max(ID) from r_detection_item"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = cmd.ExecuteReader()) { if (aReader.Read()) detectionId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); iRetval = 0; @@ -203,8 +203,9 @@ if (!stability100.Equals("")) sQry = sQry + " STABILITY_100=@STABILITY_100,"; sQry = sQry + " COUNTER_DETEC=@COUNTER_DETEC where ID = " + detectionId; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry: " + sQry); - + MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 10).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 10).Value = accuracy; @@ -283,7 +284,8 @@ return iRetval; } } - + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "停止检测 detectionItemId=======" + detectionItemId); + string sQry = "UPDATE r_device SET STATUSID="+"1"+", CHANNEL=@CHANNEL where ID=" + deviceId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@CHANNEL", MySqlDbType.String, 20).Value = ""; @@ -292,19 +294,21 @@ if (isDeleteData) { - sQry = "DELETE FROM r_detection_item WHERE DEVICE_ID = " + deviceId + " AND START_TIME='" + startTime + "' AND END_TIME='" + endTime + "'"; + sQry = "DELETE FROM r_detection_item WHERE ID=" + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); - sQry = "DELETE FROM r_detection WHERE DEVICE_ID = " + deviceId + " AND (LOG_TIME between'" + startTime + "' and '" + endTime + "')"; + sQry = "DELETE FROM r_detection WHERE DETECTION_ITEM_ID = " + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); } else { - sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME WHERE ID="+ detectionItemId; + sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME, IS_DETECTING=@IS_DETECTING WHERE ID=" + detectionItemId; + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 20).Value = DateTime.Now; + cmd.Parameters.Add("@IS_DETECTING", MySqlDbType.String, 1).Value = "0"; //0-否,1-是 cmd.ExecuteNonQuery(); } @@ -322,8 +326,7 @@ { DetectionItem detectionItem = null; try - { - + { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getById : 数据库链接断开"); @@ -337,6 +340,7 @@ string sQry = "select * from r_detection_item WHERE ID = "+ detectionItemId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + using (MySqlDataReader aReader = cmd.ExecuteReader()) { while (aReader.Read()) @@ -356,11 +360,13 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(15)) detectionItem.IsDetecting = aReader.GetString(15); } - } - + aReader.Close(); + } cmd.Dispose(); + } catch (MySqlException e) { @@ -400,7 +406,7 @@ { DetectionItem detectionItem = new DetectionItem(); //姓名 - if (!aReader.IsDBNull(0)) detectionItem.Id=Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(0)) detectionItem.Id = Convert.ToInt32(aReader.GetString(0)); if (!aReader.IsDBNull(1)) detectionItem.DeviceId = Convert.ToInt64(aReader.GetString(1)); if (!aReader.IsDBNull(2)) detectionItem.StartTime = aReader.GetString(2); if (!aReader.IsDBNull(3)) detectionItem.EndTime = aReader.GetString(3); @@ -416,9 +422,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -468,9 +475,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -498,7 +506,6 @@ string sQry = "SELECT * FROM r_detection_item where ID = " + detectionId; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -518,15 +525,43 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); + //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) + // { + // detectionItem = new DetectionItem(); + // if (row[0] != DBNull.Value) detectionItem.Id = Convert.ToInt64(row[0]); + // if (row[1] != DBNull.Value) detectionItem.DeviceId = Convert.ToInt64(row[1]); + // if (row[2] != DBNull.Value) detectionItem.StartTime = Convert.ToDateTime(row[2]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[3] != DBNull.Value) detectionItem.EndTime = Convert.ToDateTime(row[3]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[4] != DBNull.Value) detectionItem.Stability = row[4].ToString(); + // if (row[5] != DBNull.Value) detectionItem.Accuracy = row[5].ToString(); + // if (row[6] != DBNull.Value) detectionItem.BootFeature = row[6].ToString(); + // if (row[7] != DBNull.Value) detectionItem.AgeRate = row[7].ToString(); + // if (row[8] != DBNull.Value) detectionItem.Interval = row[8].ToString(); + // if (row[10] != DBNull.Value) detectionItem.Channel = row[10].ToString(); + // if (row[11] != DBNull.Value) detectionItem.Stability1 = row[11].ToString(); + // if (row[12] != DBNull.Value) detectionItem.Stability10 = row[12].ToString(); + // if (row[13] != DBNull.Value) detectionItem.Stability20 = row[13].ToString(); + // if (row[14] != DBNull.Value) detectionItem.Stability100 = row[14].ToString(); + + // } + //} } catch (MySqlException ex) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDetectionItem: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchById: " + ex.Message); } return detectionItem; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs index e2a5893..5b3deb0 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs @@ -14,7 +14,7 @@ { class DetectionServiceImpl : DetectionService { - public int add(long deviceId, string frequency, string detecItemType, long detectionItemId) + public int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time) { int iRetval = -1; try @@ -36,7 +36,7 @@ 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 = DateTime.Now; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.DateTime, 0).Value = time; cmd.Parameters.Add("@DETECTION_ITEM", MySqlDbType.String, 0).Value = detecItemType; cmd.Parameters.Add("@DETECTION_ITEM_ID", MySqlDbType.Int64, 0).Value = detectionItemId; @@ -108,24 +108,26 @@ string sQry = "SELECT * FROM r_detection where DEVICE_ID = " + deviceId +" and DETECTION_ITEM='" + detectionType + "' and (LOG_TIME BETWEEN '" + startTime + "' and '"+ endTime + "') and DETECTION_ITEM_ID="+detectionItemId+" order by LOG_TIME"; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) { - Model.Detection detection = new Model.Detection(); - //姓名 - if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) detection.LogTime = Convert.ToDateTime(aReader.GetString(2)).ToString("yyyy-MM-dd HH:mm:ss"); - if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); - if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); + Detection detection = new Detection(); + + if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); // id + if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); // devName + if (!aReader.IsDBNull(2)) detection.LogTime = aReader.GetString(2); // devCode + if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); // devType + if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); // devModel detectionDtoList.Add(detection); } + aReader.Close(); + - aCommand.Dispose(); } + aCommand.Dispose(); + } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs index 9413e2f..b224bc1 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs @@ -53,7 +53,8 @@ using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); @@ -87,8 +88,7 @@ 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; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry : "+ sQry + "; statusId="+ statusId); - + 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; @@ -183,7 +183,7 @@ } MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -208,10 +208,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -254,7 +255,30 @@ 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()) @@ -279,10 +303,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -342,7 +367,30 @@ 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()) @@ -372,10 +420,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -442,9 +491,10 @@ { totalCount = aReader.GetInt32(0); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -477,89 +527,45 @@ return null; } } - - string sQry = "SELECT * FROM r_deviceview where ACTIVE = 0 and STATUSID = 2 " + "and ('" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' <= END_TIME)"; - - 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) + //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))"; + MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { - foreach (DataRow row in dt.Rows) + while (aReader.Read()) { DeviceView deviceView = new DeviceView(); - if (row[0] != DBNull.Value) deviceView.Id = Convert.ToInt64(row[0]); - if (row[1] != DBNull.Value) deviceView.DevName = row[1].ToString(); - if (row[2] != DBNull.Value) deviceView.DevCode = row[2].ToString(); - if (row[3] != DBNull.Value) deviceView.DevTypeId = row[3].ToString(); - if (row[4] != DBNull.Value) deviceView.DevModel = row[4].ToString(); - if (row[5] != DBNull.Value) deviceView.RegTime = row[5].ToString(); - if (row[6] != DBNull.Value) deviceView.CustomerName = row[6].ToString(); - if (row[7] != DBNull.Value) deviceView.CustomerDev = row[7].ToString(); - if (row[8] != DBNull.Value) deviceView.Channel = row[8].ToString(); - if (row[9] != DBNull.Value) deviceView.Active = Convert.ToInt32(row[9]); - if (row[10] != DBNull.Value) deviceView.StartTime = Convert.ToDateTime(row[10]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[11] != DBNull.Value) deviceView.EndTime = Convert.ToDateTime(row[11]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[12] != DBNull.Value) deviceView.StatusId = row[12].ToString(); - if (row[13] != DBNull.Value) deviceView.Stability = row[13].ToString(); - if (row[14] != DBNull.Value) deviceView.Accuracy = row[14].ToString(); - if (row[15] != DBNull.Value) deviceView.BootFeature = row[15].ToString(); - if (row[16] != DBNull.Value) deviceView.AgeRate = row[16].ToString(); - if (row[17] != DBNull.Value) deviceView.DetectionItemId = Convert.ToInt64(row[17]); + 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(); + + } - //using (MySqlDataReader aReader = aCommand.ExecuteReader()) - //{ - // while (aReader.Read()) - // { - // DeviceView deviceView = new DeviceView(); + aCommand.Dispose(); - // 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 - // //deviceView.DevTypeName = dictService.getNameByCode("devType", aReader.GetString(3)); - // } - // if (!aReader.IsDBNull(4)) deviceView.DevModel = aReader.GetString(4); // devModel - // if (!aReader.IsDBNull(5)) - // { - // DateTime reg = aReader.GetDateTime(5); // regTime - // deviceView.RegTime = reg.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); - // if (!aReader.IsDBNull(9)) deviceView.Active = Convert.ToInt32(aReader.GetString(9)); - // if (!aReader.IsDBNull(10)) - // { - // DateTime reg = aReader.GetDateTime(10); // regTime - // deviceView.StartTime = reg.ToString("yyyy-MM-dd HH:mm:ss"); - // } - // if (!aReader.IsDBNull(11)) - // { - // DateTime reg = aReader.GetDateTime(11); // regTime - // deviceView.EndTime = reg.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 = Convert.ToInt64(aReader.GetString(17)); - - // deviceViewList.Add(deviceView); - - // aCommand.Dispose(); - // } - //} - if (deviceViewList.Count > 0) { foreach (DeviceView deviceView in deviceViewList) @@ -568,9 +574,15 @@ } } } + + 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()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getDeviceByChannel: " + ex.Message + " ; " + ex.ToString()); deviceViewList = null; } finally diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs index 1626aa5..42ca83c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs @@ -92,10 +92,11 @@ if (!aReader.IsDBNull(3)) dict.Code = aReader.GetString(3); nameList.Add(dict); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(MySqlException ex) { @@ -139,10 +140,11 @@ if (!aReader.IsDBNull(3)) counterParam.GeneratorIp = aReader.GetString(3); if (!aReader.IsDBNull(4)) counterParam.SignalSourceIp = aReader.GetString(4); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -220,10 +222,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/RbFreqStdMeas.cs b/RbFreqStandMeasure/RbFreqStdMeas.cs index beae3dc..8d74572 100644 --- a/RbFreqStandMeasure/RbFreqStdMeas.cs +++ b/RbFreqStandMeasure/RbFreqStdMeas.cs @@ -363,24 +363,7 @@ detectionItemService.stopDetection(deviceId, device.DetectionItemId, startTime, endTime, true); } } - deviceService.clearChannel(); - List detectionItemList = detectionItemService.getAll(); - if (detectionItemList != null && detectionItemList.Count > 0) - { - foreach (DetectionItem detectionItem in detectionItemList) - { - long detectionItemId = detectionItem.Id; - if (detectionItem.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem.Stability1.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "0", "", "", ""); - if (detectionItem.Stability10.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "0", "", ""); - if (detectionItem.Stability20.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "0", ""); - if (detectionItem.Stability100.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "", "0"); - if (detectionItem.Accuracy.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "0", "", "", "", "", "", "", ""); - if (detectionItem.BootFeature.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "0", "", "", "", "", "", ""); - if (detectionItem.AgeRate.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "0", "", "", "", "", ""); - } - } - + deviceService.clearChannel(); } else { @@ -590,7 +573,7 @@ break; case 3: // 频率计数器范围 - CounterCtrlForm counterForm = CounterCtrlForm.GetInstance(); + CounterCtrlForm counterForm = new CounterCtrlForm(); counterForm.Show(); panelMain.Controls.Add(counterForm); break; diff --git a/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe b/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe index 70dc261..11271b0 100644 --- a/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe +++ b/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe Binary files differ diff --git a/RbFreqStandMeasure/counter/CounterCtrlForm.cs b/RbFreqStandMeasure/counter/CounterCtrlForm.cs index 951a19c..e45f17b 100644 --- a/RbFreqStandMeasure/counter/CounterCtrlForm.cs +++ b/RbFreqStandMeasure/counter/CounterCtrlForm.cs @@ -39,6 +39,9 @@ GPIBService tcpService = new TCPServiceImpl(); string valueOld = ""; + string valueOldBack = ""; + string valueOldSensi = ""; + string valueOldTime = ""; #region 样式常量定影 private readonly Color titleBackColor = Color.FromArgb(63, 132, 215); // #3F64D7 @@ -55,8 +58,8 @@ return _counterCtrlForm; } - - private CounterCtrlForm() + + public CounterCtrlForm() { InitializeComponent(); @@ -69,7 +72,7 @@ comboBox_detecModel.SelectedIndex = 0; InitTableCounter(); - LoadCounterDetecInitList(); + //LoadCounterDetecInitList(); if (list != null && list.Count > 0) { @@ -221,12 +224,12 @@ table_counterDetecInit.Columns.Add("initId", Type.GetType("System.Int32")); table_counterDetecInit.Columns.Add("counterDataId", Type.GetType("System.Int64")); - if (comboBox_counters.Text != "") + if (((DeviceDto)comboBox_counters.SelectedItem).DevName != "") { - List list = deviceService.search(comboBox_counters.Text, "", "", "", "", ""); + List list = deviceService.search(((DeviceDto)comboBox_counters.SelectedItem).DevName, "", "", "", "", ""); if (null != list && list.Count > 0) { - devType = list[0].DevTypeName; + devType = list[0].DevModel; devCode = list[0].DevCode; } @@ -344,6 +347,18 @@ { valueOld = dataGridView_CounterResult.CurrentCell.Value.ToString(); } + else if (e.ColumnIndex == 5) + { + valueOldBack = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } + else if (e.ColumnIndex == 6) + { + valueOldSensi = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } + else if (e.ColumnIndex == 7) + { + valueOldTime = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } } @@ -522,7 +537,10 @@ dataGridView_CounterResult.ReadOnly = true; btn_add.Enabled = false; benDelete.Enabled = false; - ///btn_dropDetecModel.Enabled = false; + comboBox_counters.Enabled = false; + comboBox_detecModel.Enabled = false; + text_counterIp.ReadOnly = true; + text_signal.ReadOnly = true; string[] arr = text_counterIp.Text.Split('.'); if (arr.Length != 4) @@ -643,11 +661,11 @@ Invoke(new MethodInvoker(delegate () { SetDevTestDlg.inDetecCounterId = -1; - //text_devName.ReadOnly = false; - //btn_downCounterList.Enabled = true; btnStart.Enabled = true; - //btn_dropDetecModel.Enabled = true; - //textBox_detecModel.ReadOnly = false; + comboBox_counters.Enabled = true; + comboBox_detecModel.Enabled = true; + text_counterIp.ReadOnly = false; + text_signal.ReadOnly = false; })); dataGridView_CounterResult.ReadOnly = false; @@ -736,6 +754,8 @@ if (!checkFreq(value)) { MessageBox.Show("请输入格式正确的测量频率值!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldBack; + valueOldBack = ""; return; } } @@ -744,6 +764,8 @@ if (!checkCyc(value)) { MessageBox.Show("请输入格式正确的测量周期值!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldBack; + valueOldBack = ""; return; } } @@ -753,11 +775,21 @@ { if (!String.IsNullOrEmpty(value)) { + if (value.Contains(".") && ((value.IndexOf('.') != value.LastIndexOf('.')) || value.IndexOf('.') == 0 || value.LastIndexOf('.') == value.Length)) + { + MessageBox.Show("请输入格式正确的灵敏度!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldSensi; + valueOldSensi = ""; + return; + } + string pattern = @"^[0-9.]+$"; Regex regex = new Regex(pattern); if (!regex.IsMatch(value)) { MessageBox.Show("请输入格式正确的灵敏度!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldSensi; + valueOldSensi = ""; return; } } @@ -772,7 +804,8 @@ } catch { - dataGridView_CounterResult.Rows[e.RowIndex].Cells[7].Value = ""; + dataGridView_CounterResult.CurrentCell.Value = valueOldTime; + valueOldTime = ""; MessageBox.Show("请输入格式正确的时间!"); return; } diff --git a/RbFreqStandMeasure/home/HomeCtrlForm.cs b/RbFreqStandMeasure/home/HomeCtrlForm.cs index b2568f7..586334d 100644 --- a/RbFreqStandMeasure/home/HomeCtrlForm.cs +++ b/RbFreqStandMeasure/home/HomeCtrlForm.cs @@ -7,6 +7,7 @@ using Casic.Birmm.RbFreqStandMeasure.Tools; using DevComponents.DotNetBar.Controls; using System; +using System.Collections; using System.Collections.Generic; using System.Data; using System.Drawing; @@ -23,16 +24,16 @@ public partial class HomeCtrlForm : UserControl { public static HomeCtrlForm homeCtrlForm; - int totalCount = 0; - int currentPage = 1; - int pageCount = 0; - int limitCount = 4; + public int totalCount = 0; + public int currentPage = 1; + public int pageCount = 0; + public int limitCount = 4; DataTable devToBeTestedTable = null; DataTable channelsTable = null; DeviceService deviceService = new DeviceServiceImpl(); List listChannelStatus = new List(); DetectionItemService detectionItemService = new DetectionItemServiceImpl(); - + public static Hashtable stoppedItemIdTable = new Hashtable(); public static List channelFreeList = new List(); private readonly object obj = new object(); @@ -166,10 +167,7 @@ Size = new Size(120, 32) }; tableToBeTested.Controls.Add(colCustomComp); - colCustomComp.BringToFront(); - - - + colCustomComp.BringToFront(); totalCount = 0; currentPage = 1; @@ -332,7 +330,7 @@ AutoSize = false, Text = "通道", Location = new Point(0, 0), - Size = new Size(50, 30) + Size = new Size(70, 30) }; dataGridView_Channel.Controls.Add(colChannelNo); colChannelNo.BringToFront(); @@ -346,7 +344,7 @@ BackColor = titleBackColor, AutoSize = false, Text = "仪器名称", - Location = new Point(50, 0), + Location = new Point(70, 0), Size = new Size(110, 30) }; dataGridView_Channel.Controls.Add(colDevName); @@ -361,8 +359,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "仪器编号", - Location = new Point(160, 0), - Size = new Size(110, 30) + Location = new Point(180, 0), + Size = new Size(120, 30) }; dataGridView_Channel.Controls.Add(colDevNo); colDevNo.BringToFront(); @@ -376,8 +374,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "送检单位", - Location = new Point(270, 0), - Size = new Size(110, 30) + Location = new Point(300, 0), + Size = new Size(120, 30) }; dataGridView_Channel.Controls.Add(colCustomName); colCustomName.BringToFront(); @@ -391,8 +389,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "开始时间", - Location = new Point(380, 0), - Size = new Size(120, 30) + Location = new Point(420, 0), + Size = new Size(100, 30) }; dataGridView_Channel.Controls.Add(colStartTime); colStartTime.BringToFront(); @@ -406,8 +404,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "结束时间", - Location = new Point(500, 0), - Size = new Size(120, 30) + Location = new Point(520, 0), + Size = new Size(100, 30) }; dataGridView_Channel.Controls.Add(colEndTime); colEndTime.BringToFront(); @@ -492,6 +490,11 @@ dataGridView_Channel.Controls.Add(colAgingRate); colAgingRate.BringToFront(); } + + + + + } catch (Exception ex) { @@ -506,19 +509,22 @@ { lock (obj) { - channelFreeList.Clear(); - channelFreeList.Add("1"); - channelFreeList.Add("2"); - channelFreeList.Add("3"); - channelFreeList.Add("4"); - channelFreeList.Add("5"); - - listChannelStatus = deviceService.getDeviceByChannel(); - if (listChannelStatus != null && listChannelStatus.Count > 0) + // lock (channelFreeList) { - foreach (DeviceView device in listChannelStatus) + channelFreeList.Clear(); + channelFreeList.Add("1"); + channelFreeList.Add("2"); + channelFreeList.Add("3"); + channelFreeList.Add("4"); + channelFreeList.Add("5"); + + listChannelStatus = deviceService.getDeviceByChannel(); + if (listChannelStatus != null && listChannelStatus.Count > 0) { - channelFreeList.Remove(device.Channel); + foreach (DeviceView device in listChannelStatus) + { + channelFreeList.Remove(device.Channel); + } } } } @@ -533,125 +539,131 @@ { try { - lock (obj) + //Invoke(new MethodInvoker(delegate () { - channelsTable = new DataTable(); - - channelsTable.Columns.Add("channelNo", Type.GetType("System.String")); - channelsTable.Columns.Add("devName", Type.GetType("System.String")); - channelsTable.Columns.Add("devCode", Type.GetType("System.String")); - channelsTable.Columns.Add("customComp", Type.GetType("System.String")); - channelsTable.Columns.Add("startTime", Type.GetType("System.String")); - channelsTable.Columns.Add("endTime", Type.GetType("System.String")); - channelsTable.Columns.Add("channelStatus", Type.GetType("System.String")); - channelsTable.Columns.Add("stablility", Type.GetType("System.String")); - channelsTable.Columns.Add("accuracy", Type.GetType("System.String")); - channelsTable.Columns.Add("startup", Type.GetType("System.String")); - channelsTable.Columns.Add("agingRate", Type.GetType("System.String")); - channelsTable.Columns.Add("deviceId", Type.GetType("System.Int64")); - channelsTable.Columns.Add("deviceItemId", Type.GetType("System.Int64")); - //channelsTable.Columns.Add("devType", Type.GetType("System.String")); - //channelsTable.Columns.Add("devModel", Type.GetType("System.String")); - //channelsTable.Columns.Add("customCom", Type.GetType("System.String")); - - listChannelStatus = deviceService.getDeviceByChannel(); - - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelFreeList.Clear(); - channelFreeList.Add("1"); - channelFreeList.Add("2"); - channelFreeList.Add("3"); - channelFreeList.Add("4"); - channelFreeList.Add("5"); - - if (listChannelStatus != null && listChannelStatus.Count > 0) + lock (obj) { - foreach (DeviceView device in listChannelStatus) + //lock(channelFreeList) { - channelFreeList.Remove(device.Channel); - int index = Convert.ToInt32(device.Channel) - 1; - channelsTable.Rows[index]["channelNo"] = device.Channel; - channelsTable.Rows[index]["devName"] = device.DevName; - channelsTable.Rows[index]["devCode"] = device.DevCode; - channelsTable.Rows[index]["customComp"] = device.CustomerDev; - channelsTable.Rows[index]["startTime"] = device.StartTime; - channelsTable.Rows[index]["endTime"] = device.EndTime; - channelsTable.Rows[index]["channelStatus"] = "占用"; - channelsTable.Rows[index]["deviceId"] = device.Id; - channelsTable.Rows[index]["deviceItemId"] = device.DetectionItemId; + channelsTable = new DataTable(); - if (device.Stability.Equals("-3")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.Stability.Equals("-2")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.Stability.Equals("-1")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + channelsTable.Columns.Add("channelNo", Type.GetType("System.String")); + channelsTable.Columns.Add("devName", Type.GetType("System.String")); + channelsTable.Columns.Add("devCode", Type.GetType("System.String")); + channelsTable.Columns.Add("customComp", Type.GetType("System.String")); + channelsTable.Columns.Add("startTime", Type.GetType("System.String")); + channelsTable.Columns.Add("endTime", Type.GetType("System.String")); + channelsTable.Columns.Add("channelStatus", Type.GetType("System.String")); + channelsTable.Columns.Add("stablility", Type.GetType("System.String")); + channelsTable.Columns.Add("accuracy", Type.GetType("System.String")); + channelsTable.Columns.Add("startup", Type.GetType("System.String")); + channelsTable.Columns.Add("agingRate", Type.GetType("System.String")); + channelsTable.Columns.Add("deviceId", Type.GetType("System.Int64")); + channelsTable.Columns.Add("deviceItemId", Type.GetType("System.Int64")); - if (device.Accuracy.Equals("-3")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.Accuracy.Equals("-2")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.Accuracy.Equals("-1")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; - - if (device.AgeRate.Equals("-3")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.AgeRate.Equals("-2")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.AgeRate.Equals("-1")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; - - if (device.BootFeature.Equals("-3")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.BootFeature.Equals("-2")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.BootFeature.Equals("-1")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + listChannelStatus = deviceService.getDeviceByChannel(); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelFreeList.Clear(); + channelFreeList.Add("1"); + channelFreeList.Add("2"); + channelFreeList.Add("3"); + channelFreeList.Add("4"); + channelFreeList.Add("5"); + + if (listChannelStatus != null && listChannelStatus.Count > 0) + { + foreach (DeviceView device in listChannelStatus) + { + if (String.IsNullOrEmpty(device.Channel)) continue; + channelFreeList.Remove(device.Channel); + int index = Convert.ToInt32(device.Channel) - 1; + channelsTable.Rows[index]["channelNo"] = device.Channel; + channelsTable.Rows[index]["devName"] = device.DevName; + channelsTable.Rows[index]["devCode"] = device.DevCode; + channelsTable.Rows[index]["customComp"] = device.CustomerDev; + channelsTable.Rows[index]["startTime"] = device.StartTime; + channelsTable.Rows[index]["endTime"] = device.EndTime; + channelsTable.Rows[index]["channelStatus"] = "占用"; + channelsTable.Rows[index]["deviceId"] = device.Id; + channelsTable.Rows[index]["deviceItemId"] = device.DetectionItemId; + + if (device.Stability.Equals("-3")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.Stability.Equals("-2")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.Stability.Equals("-1")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + if (device.Accuracy.Equals("-3")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.Accuracy.Equals("-2")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.Accuracy.Equals("-1")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + if (device.AgeRate.Equals("-3")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.AgeRate.Equals("-2")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.AgeRate.Equals("-1")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + if (device.BootFeature.Equals("-3")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.BootFeature.Equals("-2")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.BootFeature.Equals("-1")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + + } + } + else + { + channelsTable.Rows.Clear(); + channelsTable.Rows.Add("1", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("2", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("3", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("4", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("5", "", "", "", "", "", "空闲", "", ""); + } + + foreach (string no in channelFreeList) + { + channelsTable.Rows[Convert.ToInt32(no) - 1]["channelNo"] = no; + channelsTable.Rows[Convert.ToInt32(no) - 1]["channelStatus"] = "空闲"; + } + + + dataGridView_Channel.DataSource = channelsTable; + + // width=764px + dataGridView_Channel.Columns[11].Visible = false; + dataGridView_Channel.Columns[12].Visible = false; + dataGridView_Channel.Columns[0].Width = 70; + dataGridView_Channel.Columns[1].Width = 110; + dataGridView_Channel.Columns[2].Width = 120; + dataGridView_Channel.Columns[3].Width = 120; + dataGridView_Channel.Columns[4].Width = 100; //starttime + dataGridView_Channel.Columns[5].Width = 100; //endtime + dataGridView_Channel.Columns[6].Width = 64; + dataGridView_Channel.Columns[7].Width = 75; + dataGridView_Channel.Columns[8].Width = 75; + dataGridView_Channel.Columns[9].Width = 75; + dataGridView_Channel.Columns[10].Width = 75; + + dataGridView_Channel.Columns[0].ReadOnly = true; + dataGridView_Channel.Columns[1].ReadOnly = true; + dataGridView_Channel.Columns[2].ReadOnly = true; + dataGridView_Channel.Columns[3].ReadOnly = true; + dataGridView_Channel.Columns[4].ReadOnly = true; + dataGridView_Channel.Columns[5].ReadOnly = true; + dataGridView_Channel.Columns[6].ReadOnly = true; + dataGridView_Channel.Columns[7].ReadOnly = true; + dataGridView_Channel.Columns[8].ReadOnly = true; + dataGridView_Channel.Columns[9].ReadOnly = true; + dataGridView_Channel.Columns[10].ReadOnly = true; } } - else - { - channelsTable.Rows.Clear(); - channelsTable.Rows.Add("1", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("2", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("3", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("4", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("5", "", "", "", "", "", "空闲", "", ""); - } - - foreach (string no in channelFreeList) - { - channelsTable.Rows[Convert.ToInt32(no) - 1]["channelNo"] = no; - channelsTable.Rows[Convert.ToInt32(no) - 1]["channelStatus"] = "空闲"; - } - - - dataGridView_Channel.DataSource = channelsTable; - - // width=764px - dataGridView_Channel.Columns[11].Visible = false; - dataGridView_Channel.Columns[12].Visible = false; - dataGridView_Channel.Columns[0].Width = 50; - dataGridView_Channel.Columns[1].Width = 110; - dataGridView_Channel.Columns[2].Width = 110; - dataGridView_Channel.Columns[3].Width = 110; - dataGridView_Channel.Columns[4].Width = 120; - dataGridView_Channel.Columns[5].Width = 120; - dataGridView_Channel.Columns[6].Width = 64; - dataGridView_Channel.Columns[7].Width = 75; - dataGridView_Channel.Columns[8].Width = 75; - dataGridView_Channel.Columns[9].Width = 75; - dataGridView_Channel.Columns[10].Width = 75; - - dataGridView_Channel.Columns[0].ReadOnly = true; - dataGridView_Channel.Columns[1].ReadOnly = true; - dataGridView_Channel.Columns[2].ReadOnly = true; - dataGridView_Channel.Columns[3].ReadOnly = true; - dataGridView_Channel.Columns[4].ReadOnly = true; - dataGridView_Channel.Columns[5].ReadOnly = true; - dataGridView_Channel.Columns[6].ReadOnly = true; - dataGridView_Channel.Columns[7].ReadOnly = true; - dataGridView_Channel.Columns[8].ReadOnly = true; - dataGridView_Channel.Columns[9].ReadOnly = true; - dataGridView_Channel.Columns[10].ReadOnly = true; + //})); } } catch (Exception ex) @@ -760,7 +772,6 @@ private void cellDoubleClick(int rowIndex) { - int colIndex = dataGridView_Channel.CurrentCell.ColumnIndex; if (dataGridView_Channel.Rows[rowIndex].Cells[6].Value.ToString().Equals("占用")) { if (MessageBox.Show("该通道有正在检测的仪器,确定要停止检测?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) @@ -780,30 +791,22 @@ { return; } + DialogResult dialogResult = MessageBox.Show("是否保存此次检测的数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { - detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, false); + detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, false); } else { detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, true); } - DetectionItem detectionItem0 = detectionItemService.getById(deviceItemId); - if (detectionItem0 != null) - { - if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem0.Stability1.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "0", "", "", ""); - if (detectionItem0.Stability10.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "", "0", "", ""); - if (detectionItem0.Stability20.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "", "", "0", ""); - if (detectionItem0.Stability100.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "", "", "", "0"); - if (detectionItem0.Accuracy.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "0", "", "", "", "", "", "", ""); - if (detectionItem0.BootFeature.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "0", "", "", "", "", "", ""); - if (detectionItem0.AgeRate.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "0", "", "", "", "", ""); - - } + if (stoppedItemIdTable.Contains(rowIndex + 1)) stoppedItemIdTable.Remove(rowIndex + 1); + + stoppedItemIdTable.Add(rowIndex + 1, deviceItemId); LoadChannelStatus(); + currentPage = 1; LoadDevToBeTested(); } catch(Exception ex) diff --git a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs index 963b90b..a5e9368 100644 --- a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs +++ b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs @@ -29,7 +29,7 @@ + ";password=" + databasePassword + ";Charset=utf8" + ";Allow User Variables=True" - + ";Pooling=true"; + + ";Pooling=True"; mySqlConnect = new MySqlConnection(sConnection); mySqlConnect.Open(); iRetval = 0; diff --git a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs index c69559f..f19bd95 100644 --- a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs +++ b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs @@ -38,6 +38,7 @@ private string stability10; private string stability20; private string stability100; + private string isDetecting; public long Id { get @@ -161,5 +162,6 @@ public string Stability20 { get => stability20; set => stability20 = value; } public string Stability100 { get => stability100; set => stability100 = value; } public string Stability1 { get => stability1; set => stability1 = value; } + public string IsDetecting { get => isDetecting; set => isDetecting = value; } } } \ No newline at end of file diff --git a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs index 399098b..781749c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs @@ -9,7 +9,7 @@ { interface DetectionService { - int add(long deviceId, string frequency, string detecItemType, long detectionItemId); + int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time); List search(long deviceId, string detectionType, string startTime, string endTime, long detectionItemId); diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs index 0fd7b24..4df249b 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs @@ -132,7 +132,30 @@ string sQry = "SELECT * FROM r_counter_check_params"; 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) + // { + // if (row[0] != DBNull.Value) counterCheckParam.Id = Convert.ToInt32(row[0]); + // if (row[1] != DBNull.Value) counterCheckParam.SoOutDelay = row[1].ToString(); + // if (row[2] != DBNull.Value) counterCheckParam.SoEleFrequency = row[2].ToString(); + // if (row[3] != DBNull.Value) counterCheckParam.SoEleAddValue = row[3].ToString(); + // if (row[4] != DBNull.Value) counterCheckParam.SoEleAlarm = row[4].ToString(); + // if (row[5] != DBNull.Value) counterCheckParam.FreThreshold1 = row[5].ToString(); + // if (row[6] != DBNull.Value) counterCheckParam.FreThreshold2 = row[6].ToString(); + // if (row[7] != DBNull.Value) counterCheckParam.FreEleAddValue = row[7].ToString(); + // if (row[8] != DBNull.Value) counterCheckParam.CycThreshold1 = row[8].ToString(); + // if (row[9] != DBNull.Value) counterCheckParam.CycThreshold2 = row[9].ToString(); + // if (row[10] != DBNull.Value) counterCheckParam.CycEleAddValue = row[10].ToString(); + + // } + //} using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -149,10 +172,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(Exception ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs index 52b36f8..2c60ab4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs @@ -32,28 +32,29 @@ //先查询是否有历史数据 string sQry = "select ID from r_counter_data where DEVICE_ID=" + deviceId + " and OUT_VALUE = '" + outValue + "'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - - if (aReader.Read()) + bool isUpdated = false; + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - dataId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) + { + dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + + " where ID=" + dataId; + + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; + cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; + cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; + + cmd.ExecuteNonQuery(); + isUpdated = true; + } aReader.Close(); - sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + - " where ID="+ dataId; - - cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; - cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; - cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; - cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; - - cmd.ExecuteNonQuery(); - } - else - { - aReader.Close(); - + if (!isUpdated) + { sQry = "INSERT INTO r_counter_data (DEVICE_ID, OUT_VALUE, VALUE, SENSITIVITY, LOG_TIME, DETEC_TYPE)" + "values(@DEVICE_ID,@OUT_VALUE,@VALUE,@SENSITIVITY,@LOG_TIME,@DETEC_TYPE)"; @@ -70,14 +71,14 @@ sQry = "SELECT max(ID) from r_counter_data"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - - aReader = cmd.ExecuteReader(); - - if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); - + using (MySqlDataReader aReader = cmd.ExecuteReader()) + { + + if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + } } - aReader.Close(); cmd.Dispose(); iRetval = 0; @@ -144,6 +145,8 @@ cmd.ExecuteNonQuery(); } + + aReader.Close(); } @@ -282,9 +285,10 @@ if (!aReader.IsDBNull(6)) counterData.DetecType = aReader.GetString(6); counterDataList.Add(counterData); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs index 6795325..7500bd4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs @@ -47,10 +47,11 @@ counterDetecInitList.Add(counterDetecInit); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -75,29 +76,31 @@ return iRetval; } } - string sQry = "select ID from r_counter_detec_init where FREQUENCY=" + frequency +" AND CYCLE="+cycle; + string sQry = "select ID from r_counter_detec_init where FREQUENCY='" + frequency +"' AND CYCLE='"+cycle+"'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - if (aReader.Read()) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - initId = Convert.ToInt64(aReader.GetString(0)); - sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; + if (aReader.Read()) + { + initId = Convert.ToInt64(aReader.GetString(0)); + sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; - 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(); - } - else - { - 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 = 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(); + } + else + { + 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.ExecuteNonQuery(); + + } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); iRetval = 0; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs index 97b06ba..abcbaa6 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs @@ -72,26 +72,27 @@ MySqlCommand cmd = new MySqlCommand(sql, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(CommandBehavior.Default); - - if (aReader != null) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) + if (aReader != null) { - //判断门的状态 - if (!aReader.IsDBNull(0)) - counterParam.Id = Convert.ToInt32(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) - counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) - counterParam.BaudRate = aReader.GetString(2); - if (!aReader.IsDBNull(3)) - counterParam.GeneratorIp = aReader.GetString(3); - if (!aReader.IsDBNull(4)) - counterParam.SignalSourceIp = aReader.GetString(4); + if (aReader.Read()) + { + //判断门的状态 + if (!aReader.IsDBNull(0)) + counterParam.Id = Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(1)) + counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); + if (!aReader.IsDBNull(2)) + counterParam.BaudRate = aReader.GetString(2); + if (!aReader.IsDBNull(3)) + counterParam.GeneratorIp = aReader.GetString(3); + if (!aReader.IsDBNull(4)) + counterParam.SignalSourceIp = aReader.GetString(4); + } } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs index cca90fb..1578937 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs @@ -33,8 +33,8 @@ MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@DEVICE_ID", MySqlDbType.Int64, 20).Value = deviceId; - cmd.Parameters.Add("@START_TIME", MySqlDbType.String, 50).Value = startTime; - cmd.Parameters.Add("@END_TIME", MySqlDbType.String, 50).Value = endTime; + cmd.Parameters.Add("@START_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(startTime); + cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(endTime); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 50).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 50).Value = accuracy; cmd.Parameters.Add("@BOOT_FEATURE", MySqlDbType.String, 50).Value = bootFeature; @@ -58,11 +58,11 @@ sQry = "SELECT max(ID) from r_detection_item"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = cmd.ExecuteReader()) { if (aReader.Read()) detectionId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); iRetval = 0; @@ -203,8 +203,9 @@ if (!stability100.Equals("")) sQry = sQry + " STABILITY_100=@STABILITY_100,"; sQry = sQry + " COUNTER_DETEC=@COUNTER_DETEC where ID = " + detectionId; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry: " + sQry); - + MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 10).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 10).Value = accuracy; @@ -283,7 +284,8 @@ return iRetval; } } - + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "停止检测 detectionItemId=======" + detectionItemId); + string sQry = "UPDATE r_device SET STATUSID="+"1"+", CHANNEL=@CHANNEL where ID=" + deviceId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@CHANNEL", MySqlDbType.String, 20).Value = ""; @@ -292,19 +294,21 @@ if (isDeleteData) { - sQry = "DELETE FROM r_detection_item WHERE DEVICE_ID = " + deviceId + " AND START_TIME='" + startTime + "' AND END_TIME='" + endTime + "'"; + sQry = "DELETE FROM r_detection_item WHERE ID=" + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); - sQry = "DELETE FROM r_detection WHERE DEVICE_ID = " + deviceId + " AND (LOG_TIME between'" + startTime + "' and '" + endTime + "')"; + sQry = "DELETE FROM r_detection WHERE DETECTION_ITEM_ID = " + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); } else { - sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME WHERE ID="+ detectionItemId; + sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME, IS_DETECTING=@IS_DETECTING WHERE ID=" + detectionItemId; + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 20).Value = DateTime.Now; + cmd.Parameters.Add("@IS_DETECTING", MySqlDbType.String, 1).Value = "0"; //0-否,1-是 cmd.ExecuteNonQuery(); } @@ -322,8 +326,7 @@ { DetectionItem detectionItem = null; try - { - + { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getById : 数据库链接断开"); @@ -337,6 +340,7 @@ string sQry = "select * from r_detection_item WHERE ID = "+ detectionItemId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + using (MySqlDataReader aReader = cmd.ExecuteReader()) { while (aReader.Read()) @@ -356,11 +360,13 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(15)) detectionItem.IsDetecting = aReader.GetString(15); } - } - + aReader.Close(); + } cmd.Dispose(); + } catch (MySqlException e) { @@ -400,7 +406,7 @@ { DetectionItem detectionItem = new DetectionItem(); //姓名 - if (!aReader.IsDBNull(0)) detectionItem.Id=Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(0)) detectionItem.Id = Convert.ToInt32(aReader.GetString(0)); if (!aReader.IsDBNull(1)) detectionItem.DeviceId = Convert.ToInt64(aReader.GetString(1)); if (!aReader.IsDBNull(2)) detectionItem.StartTime = aReader.GetString(2); if (!aReader.IsDBNull(3)) detectionItem.EndTime = aReader.GetString(3); @@ -416,9 +422,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -468,9 +475,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -498,7 +506,6 @@ string sQry = "SELECT * FROM r_detection_item where ID = " + detectionId; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -518,15 +525,43 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); + //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) + // { + // detectionItem = new DetectionItem(); + // if (row[0] != DBNull.Value) detectionItem.Id = Convert.ToInt64(row[0]); + // if (row[1] != DBNull.Value) detectionItem.DeviceId = Convert.ToInt64(row[1]); + // if (row[2] != DBNull.Value) detectionItem.StartTime = Convert.ToDateTime(row[2]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[3] != DBNull.Value) detectionItem.EndTime = Convert.ToDateTime(row[3]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[4] != DBNull.Value) detectionItem.Stability = row[4].ToString(); + // if (row[5] != DBNull.Value) detectionItem.Accuracy = row[5].ToString(); + // if (row[6] != DBNull.Value) detectionItem.BootFeature = row[6].ToString(); + // if (row[7] != DBNull.Value) detectionItem.AgeRate = row[7].ToString(); + // if (row[8] != DBNull.Value) detectionItem.Interval = row[8].ToString(); + // if (row[10] != DBNull.Value) detectionItem.Channel = row[10].ToString(); + // if (row[11] != DBNull.Value) detectionItem.Stability1 = row[11].ToString(); + // if (row[12] != DBNull.Value) detectionItem.Stability10 = row[12].ToString(); + // if (row[13] != DBNull.Value) detectionItem.Stability20 = row[13].ToString(); + // if (row[14] != DBNull.Value) detectionItem.Stability100 = row[14].ToString(); + + // } + //} } catch (MySqlException ex) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDetectionItem: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchById: " + ex.Message); } return detectionItem; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs index e2a5893..5b3deb0 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs @@ -14,7 +14,7 @@ { class DetectionServiceImpl : DetectionService { - public int add(long deviceId, string frequency, string detecItemType, long detectionItemId) + public int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time) { int iRetval = -1; try @@ -36,7 +36,7 @@ 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 = DateTime.Now; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.DateTime, 0).Value = time; cmd.Parameters.Add("@DETECTION_ITEM", MySqlDbType.String, 0).Value = detecItemType; cmd.Parameters.Add("@DETECTION_ITEM_ID", MySqlDbType.Int64, 0).Value = detectionItemId; @@ -108,24 +108,26 @@ string sQry = "SELECT * FROM r_detection where DEVICE_ID = " + deviceId +" and DETECTION_ITEM='" + detectionType + "' and (LOG_TIME BETWEEN '" + startTime + "' and '"+ endTime + "') and DETECTION_ITEM_ID="+detectionItemId+" order by LOG_TIME"; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) { - Model.Detection detection = new Model.Detection(); - //姓名 - if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) detection.LogTime = Convert.ToDateTime(aReader.GetString(2)).ToString("yyyy-MM-dd HH:mm:ss"); - if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); - if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); + Detection detection = new Detection(); + + if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); // id + if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); // devName + if (!aReader.IsDBNull(2)) detection.LogTime = aReader.GetString(2); // devCode + if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); // devType + if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); // devModel detectionDtoList.Add(detection); } + aReader.Close(); + - aCommand.Dispose(); } + aCommand.Dispose(); + } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs index 9413e2f..b224bc1 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs @@ -53,7 +53,8 @@ using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); @@ -87,8 +88,7 @@ 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; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry : "+ sQry + "; statusId="+ statusId); - + 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; @@ -183,7 +183,7 @@ } MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -208,10 +208,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -254,7 +255,30 @@ 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()) @@ -279,10 +303,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -342,7 +367,30 @@ 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()) @@ -372,10 +420,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -442,9 +491,10 @@ { totalCount = aReader.GetInt32(0); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -477,89 +527,45 @@ return null; } } - - string sQry = "SELECT * FROM r_deviceview where ACTIVE = 0 and STATUSID = 2 " + "and ('" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' <= END_TIME)"; - - 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) + //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))"; + MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { - foreach (DataRow row in dt.Rows) + while (aReader.Read()) { DeviceView deviceView = new DeviceView(); - if (row[0] != DBNull.Value) deviceView.Id = Convert.ToInt64(row[0]); - if (row[1] != DBNull.Value) deviceView.DevName = row[1].ToString(); - if (row[2] != DBNull.Value) deviceView.DevCode = row[2].ToString(); - if (row[3] != DBNull.Value) deviceView.DevTypeId = row[3].ToString(); - if (row[4] != DBNull.Value) deviceView.DevModel = row[4].ToString(); - if (row[5] != DBNull.Value) deviceView.RegTime = row[5].ToString(); - if (row[6] != DBNull.Value) deviceView.CustomerName = row[6].ToString(); - if (row[7] != DBNull.Value) deviceView.CustomerDev = row[7].ToString(); - if (row[8] != DBNull.Value) deviceView.Channel = row[8].ToString(); - if (row[9] != DBNull.Value) deviceView.Active = Convert.ToInt32(row[9]); - if (row[10] != DBNull.Value) deviceView.StartTime = Convert.ToDateTime(row[10]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[11] != DBNull.Value) deviceView.EndTime = Convert.ToDateTime(row[11]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[12] != DBNull.Value) deviceView.StatusId = row[12].ToString(); - if (row[13] != DBNull.Value) deviceView.Stability = row[13].ToString(); - if (row[14] != DBNull.Value) deviceView.Accuracy = row[14].ToString(); - if (row[15] != DBNull.Value) deviceView.BootFeature = row[15].ToString(); - if (row[16] != DBNull.Value) deviceView.AgeRate = row[16].ToString(); - if (row[17] != DBNull.Value) deviceView.DetectionItemId = Convert.ToInt64(row[17]); + 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(); + + } - //using (MySqlDataReader aReader = aCommand.ExecuteReader()) - //{ - // while (aReader.Read()) - // { - // DeviceView deviceView = new DeviceView(); + aCommand.Dispose(); - // 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 - // //deviceView.DevTypeName = dictService.getNameByCode("devType", aReader.GetString(3)); - // } - // if (!aReader.IsDBNull(4)) deviceView.DevModel = aReader.GetString(4); // devModel - // if (!aReader.IsDBNull(5)) - // { - // DateTime reg = aReader.GetDateTime(5); // regTime - // deviceView.RegTime = reg.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); - // if (!aReader.IsDBNull(9)) deviceView.Active = Convert.ToInt32(aReader.GetString(9)); - // if (!aReader.IsDBNull(10)) - // { - // DateTime reg = aReader.GetDateTime(10); // regTime - // deviceView.StartTime = reg.ToString("yyyy-MM-dd HH:mm:ss"); - // } - // if (!aReader.IsDBNull(11)) - // { - // DateTime reg = aReader.GetDateTime(11); // regTime - // deviceView.EndTime = reg.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 = Convert.ToInt64(aReader.GetString(17)); - - // deviceViewList.Add(deviceView); - - // aCommand.Dispose(); - // } - //} - if (deviceViewList.Count > 0) { foreach (DeviceView deviceView in deviceViewList) @@ -568,9 +574,15 @@ } } } + + 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()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getDeviceByChannel: " + ex.Message + " ; " + ex.ToString()); deviceViewList = null; } finally diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs index 1626aa5..42ca83c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs @@ -92,10 +92,11 @@ if (!aReader.IsDBNull(3)) dict.Code = aReader.GetString(3); nameList.Add(dict); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(MySqlException ex) { @@ -139,10 +140,11 @@ if (!aReader.IsDBNull(3)) counterParam.GeneratorIp = aReader.GetString(3); if (!aReader.IsDBNull(4)) counterParam.SignalSourceIp = aReader.GetString(4); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -220,10 +222,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/RbFreqStdMeas.cs b/RbFreqStandMeasure/RbFreqStdMeas.cs index beae3dc..8d74572 100644 --- a/RbFreqStandMeasure/RbFreqStdMeas.cs +++ b/RbFreqStandMeasure/RbFreqStdMeas.cs @@ -363,24 +363,7 @@ detectionItemService.stopDetection(deviceId, device.DetectionItemId, startTime, endTime, true); } } - deviceService.clearChannel(); - List detectionItemList = detectionItemService.getAll(); - if (detectionItemList != null && detectionItemList.Count > 0) - { - foreach (DetectionItem detectionItem in detectionItemList) - { - long detectionItemId = detectionItem.Id; - if (detectionItem.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem.Stability1.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "0", "", "", ""); - if (detectionItem.Stability10.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "0", "", ""); - if (detectionItem.Stability20.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "0", ""); - if (detectionItem.Stability100.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "", "0"); - if (detectionItem.Accuracy.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "0", "", "", "", "", "", "", ""); - if (detectionItem.BootFeature.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "0", "", "", "", "", "", ""); - if (detectionItem.AgeRate.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "0", "", "", "", "", ""); - } - } - + deviceService.clearChannel(); } else { @@ -590,7 +573,7 @@ break; case 3: // 频率计数器范围 - CounterCtrlForm counterForm = CounterCtrlForm.GetInstance(); + CounterCtrlForm counterForm = new CounterCtrlForm(); counterForm.Show(); panelMain.Controls.Add(counterForm); break; diff --git a/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe b/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe index 70dc261..11271b0 100644 --- a/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe +++ b/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe Binary files differ diff --git a/RbFreqStandMeasure/counter/CounterCtrlForm.cs b/RbFreqStandMeasure/counter/CounterCtrlForm.cs index 951a19c..e45f17b 100644 --- a/RbFreqStandMeasure/counter/CounterCtrlForm.cs +++ b/RbFreqStandMeasure/counter/CounterCtrlForm.cs @@ -39,6 +39,9 @@ GPIBService tcpService = new TCPServiceImpl(); string valueOld = ""; + string valueOldBack = ""; + string valueOldSensi = ""; + string valueOldTime = ""; #region 样式常量定影 private readonly Color titleBackColor = Color.FromArgb(63, 132, 215); // #3F64D7 @@ -55,8 +58,8 @@ return _counterCtrlForm; } - - private CounterCtrlForm() + + public CounterCtrlForm() { InitializeComponent(); @@ -69,7 +72,7 @@ comboBox_detecModel.SelectedIndex = 0; InitTableCounter(); - LoadCounterDetecInitList(); + //LoadCounterDetecInitList(); if (list != null && list.Count > 0) { @@ -221,12 +224,12 @@ table_counterDetecInit.Columns.Add("initId", Type.GetType("System.Int32")); table_counterDetecInit.Columns.Add("counterDataId", Type.GetType("System.Int64")); - if (comboBox_counters.Text != "") + if (((DeviceDto)comboBox_counters.SelectedItem).DevName != "") { - List list = deviceService.search(comboBox_counters.Text, "", "", "", "", ""); + List list = deviceService.search(((DeviceDto)comboBox_counters.SelectedItem).DevName, "", "", "", "", ""); if (null != list && list.Count > 0) { - devType = list[0].DevTypeName; + devType = list[0].DevModel; devCode = list[0].DevCode; } @@ -344,6 +347,18 @@ { valueOld = dataGridView_CounterResult.CurrentCell.Value.ToString(); } + else if (e.ColumnIndex == 5) + { + valueOldBack = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } + else if (e.ColumnIndex == 6) + { + valueOldSensi = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } + else if (e.ColumnIndex == 7) + { + valueOldTime = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } } @@ -522,7 +537,10 @@ dataGridView_CounterResult.ReadOnly = true; btn_add.Enabled = false; benDelete.Enabled = false; - ///btn_dropDetecModel.Enabled = false; + comboBox_counters.Enabled = false; + comboBox_detecModel.Enabled = false; + text_counterIp.ReadOnly = true; + text_signal.ReadOnly = true; string[] arr = text_counterIp.Text.Split('.'); if (arr.Length != 4) @@ -643,11 +661,11 @@ Invoke(new MethodInvoker(delegate () { SetDevTestDlg.inDetecCounterId = -1; - //text_devName.ReadOnly = false; - //btn_downCounterList.Enabled = true; btnStart.Enabled = true; - //btn_dropDetecModel.Enabled = true; - //textBox_detecModel.ReadOnly = false; + comboBox_counters.Enabled = true; + comboBox_detecModel.Enabled = true; + text_counterIp.ReadOnly = false; + text_signal.ReadOnly = false; })); dataGridView_CounterResult.ReadOnly = false; @@ -736,6 +754,8 @@ if (!checkFreq(value)) { MessageBox.Show("请输入格式正确的测量频率值!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldBack; + valueOldBack = ""; return; } } @@ -744,6 +764,8 @@ if (!checkCyc(value)) { MessageBox.Show("请输入格式正确的测量周期值!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldBack; + valueOldBack = ""; return; } } @@ -753,11 +775,21 @@ { if (!String.IsNullOrEmpty(value)) { + if (value.Contains(".") && ((value.IndexOf('.') != value.LastIndexOf('.')) || value.IndexOf('.') == 0 || value.LastIndexOf('.') == value.Length)) + { + MessageBox.Show("请输入格式正确的灵敏度!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldSensi; + valueOldSensi = ""; + return; + } + string pattern = @"^[0-9.]+$"; Regex regex = new Regex(pattern); if (!regex.IsMatch(value)) { MessageBox.Show("请输入格式正确的灵敏度!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldSensi; + valueOldSensi = ""; return; } } @@ -772,7 +804,8 @@ } catch { - dataGridView_CounterResult.Rows[e.RowIndex].Cells[7].Value = ""; + dataGridView_CounterResult.CurrentCell.Value = valueOldTime; + valueOldTime = ""; MessageBox.Show("请输入格式正确的时间!"); return; } diff --git a/RbFreqStandMeasure/home/HomeCtrlForm.cs b/RbFreqStandMeasure/home/HomeCtrlForm.cs index b2568f7..586334d 100644 --- a/RbFreqStandMeasure/home/HomeCtrlForm.cs +++ b/RbFreqStandMeasure/home/HomeCtrlForm.cs @@ -7,6 +7,7 @@ using Casic.Birmm.RbFreqStandMeasure.Tools; using DevComponents.DotNetBar.Controls; using System; +using System.Collections; using System.Collections.Generic; using System.Data; using System.Drawing; @@ -23,16 +24,16 @@ public partial class HomeCtrlForm : UserControl { public static HomeCtrlForm homeCtrlForm; - int totalCount = 0; - int currentPage = 1; - int pageCount = 0; - int limitCount = 4; + public int totalCount = 0; + public int currentPage = 1; + public int pageCount = 0; + public int limitCount = 4; DataTable devToBeTestedTable = null; DataTable channelsTable = null; DeviceService deviceService = new DeviceServiceImpl(); List listChannelStatus = new List(); DetectionItemService detectionItemService = new DetectionItemServiceImpl(); - + public static Hashtable stoppedItemIdTable = new Hashtable(); public static List channelFreeList = new List(); private readonly object obj = new object(); @@ -166,10 +167,7 @@ Size = new Size(120, 32) }; tableToBeTested.Controls.Add(colCustomComp); - colCustomComp.BringToFront(); - - - + colCustomComp.BringToFront(); totalCount = 0; currentPage = 1; @@ -332,7 +330,7 @@ AutoSize = false, Text = "通道", Location = new Point(0, 0), - Size = new Size(50, 30) + Size = new Size(70, 30) }; dataGridView_Channel.Controls.Add(colChannelNo); colChannelNo.BringToFront(); @@ -346,7 +344,7 @@ BackColor = titleBackColor, AutoSize = false, Text = "仪器名称", - Location = new Point(50, 0), + Location = new Point(70, 0), Size = new Size(110, 30) }; dataGridView_Channel.Controls.Add(colDevName); @@ -361,8 +359,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "仪器编号", - Location = new Point(160, 0), - Size = new Size(110, 30) + Location = new Point(180, 0), + Size = new Size(120, 30) }; dataGridView_Channel.Controls.Add(colDevNo); colDevNo.BringToFront(); @@ -376,8 +374,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "送检单位", - Location = new Point(270, 0), - Size = new Size(110, 30) + Location = new Point(300, 0), + Size = new Size(120, 30) }; dataGridView_Channel.Controls.Add(colCustomName); colCustomName.BringToFront(); @@ -391,8 +389,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "开始时间", - Location = new Point(380, 0), - Size = new Size(120, 30) + Location = new Point(420, 0), + Size = new Size(100, 30) }; dataGridView_Channel.Controls.Add(colStartTime); colStartTime.BringToFront(); @@ -406,8 +404,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "结束时间", - Location = new Point(500, 0), - Size = new Size(120, 30) + Location = new Point(520, 0), + Size = new Size(100, 30) }; dataGridView_Channel.Controls.Add(colEndTime); colEndTime.BringToFront(); @@ -492,6 +490,11 @@ dataGridView_Channel.Controls.Add(colAgingRate); colAgingRate.BringToFront(); } + + + + + } catch (Exception ex) { @@ -506,19 +509,22 @@ { lock (obj) { - channelFreeList.Clear(); - channelFreeList.Add("1"); - channelFreeList.Add("2"); - channelFreeList.Add("3"); - channelFreeList.Add("4"); - channelFreeList.Add("5"); - - listChannelStatus = deviceService.getDeviceByChannel(); - if (listChannelStatus != null && listChannelStatus.Count > 0) + // lock (channelFreeList) { - foreach (DeviceView device in listChannelStatus) + channelFreeList.Clear(); + channelFreeList.Add("1"); + channelFreeList.Add("2"); + channelFreeList.Add("3"); + channelFreeList.Add("4"); + channelFreeList.Add("5"); + + listChannelStatus = deviceService.getDeviceByChannel(); + if (listChannelStatus != null && listChannelStatus.Count > 0) { - channelFreeList.Remove(device.Channel); + foreach (DeviceView device in listChannelStatus) + { + channelFreeList.Remove(device.Channel); + } } } } @@ -533,125 +539,131 @@ { try { - lock (obj) + //Invoke(new MethodInvoker(delegate () { - channelsTable = new DataTable(); - - channelsTable.Columns.Add("channelNo", Type.GetType("System.String")); - channelsTable.Columns.Add("devName", Type.GetType("System.String")); - channelsTable.Columns.Add("devCode", Type.GetType("System.String")); - channelsTable.Columns.Add("customComp", Type.GetType("System.String")); - channelsTable.Columns.Add("startTime", Type.GetType("System.String")); - channelsTable.Columns.Add("endTime", Type.GetType("System.String")); - channelsTable.Columns.Add("channelStatus", Type.GetType("System.String")); - channelsTable.Columns.Add("stablility", Type.GetType("System.String")); - channelsTable.Columns.Add("accuracy", Type.GetType("System.String")); - channelsTable.Columns.Add("startup", Type.GetType("System.String")); - channelsTable.Columns.Add("agingRate", Type.GetType("System.String")); - channelsTable.Columns.Add("deviceId", Type.GetType("System.Int64")); - channelsTable.Columns.Add("deviceItemId", Type.GetType("System.Int64")); - //channelsTable.Columns.Add("devType", Type.GetType("System.String")); - //channelsTable.Columns.Add("devModel", Type.GetType("System.String")); - //channelsTable.Columns.Add("customCom", Type.GetType("System.String")); - - listChannelStatus = deviceService.getDeviceByChannel(); - - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelFreeList.Clear(); - channelFreeList.Add("1"); - channelFreeList.Add("2"); - channelFreeList.Add("3"); - channelFreeList.Add("4"); - channelFreeList.Add("5"); - - if (listChannelStatus != null && listChannelStatus.Count > 0) + lock (obj) { - foreach (DeviceView device in listChannelStatus) + //lock(channelFreeList) { - channelFreeList.Remove(device.Channel); - int index = Convert.ToInt32(device.Channel) - 1; - channelsTable.Rows[index]["channelNo"] = device.Channel; - channelsTable.Rows[index]["devName"] = device.DevName; - channelsTable.Rows[index]["devCode"] = device.DevCode; - channelsTable.Rows[index]["customComp"] = device.CustomerDev; - channelsTable.Rows[index]["startTime"] = device.StartTime; - channelsTable.Rows[index]["endTime"] = device.EndTime; - channelsTable.Rows[index]["channelStatus"] = "占用"; - channelsTable.Rows[index]["deviceId"] = device.Id; - channelsTable.Rows[index]["deviceItemId"] = device.DetectionItemId; + channelsTable = new DataTable(); - if (device.Stability.Equals("-3")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.Stability.Equals("-2")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.Stability.Equals("-1")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + channelsTable.Columns.Add("channelNo", Type.GetType("System.String")); + channelsTable.Columns.Add("devName", Type.GetType("System.String")); + channelsTable.Columns.Add("devCode", Type.GetType("System.String")); + channelsTable.Columns.Add("customComp", Type.GetType("System.String")); + channelsTable.Columns.Add("startTime", Type.GetType("System.String")); + channelsTable.Columns.Add("endTime", Type.GetType("System.String")); + channelsTable.Columns.Add("channelStatus", Type.GetType("System.String")); + channelsTable.Columns.Add("stablility", Type.GetType("System.String")); + channelsTable.Columns.Add("accuracy", Type.GetType("System.String")); + channelsTable.Columns.Add("startup", Type.GetType("System.String")); + channelsTable.Columns.Add("agingRate", Type.GetType("System.String")); + channelsTable.Columns.Add("deviceId", Type.GetType("System.Int64")); + channelsTable.Columns.Add("deviceItemId", Type.GetType("System.Int64")); - if (device.Accuracy.Equals("-3")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.Accuracy.Equals("-2")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.Accuracy.Equals("-1")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; - - if (device.AgeRate.Equals("-3")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.AgeRate.Equals("-2")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.AgeRate.Equals("-1")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; - - if (device.BootFeature.Equals("-3")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.BootFeature.Equals("-2")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.BootFeature.Equals("-1")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + listChannelStatus = deviceService.getDeviceByChannel(); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelFreeList.Clear(); + channelFreeList.Add("1"); + channelFreeList.Add("2"); + channelFreeList.Add("3"); + channelFreeList.Add("4"); + channelFreeList.Add("5"); + + if (listChannelStatus != null && listChannelStatus.Count > 0) + { + foreach (DeviceView device in listChannelStatus) + { + if (String.IsNullOrEmpty(device.Channel)) continue; + channelFreeList.Remove(device.Channel); + int index = Convert.ToInt32(device.Channel) - 1; + channelsTable.Rows[index]["channelNo"] = device.Channel; + channelsTable.Rows[index]["devName"] = device.DevName; + channelsTable.Rows[index]["devCode"] = device.DevCode; + channelsTable.Rows[index]["customComp"] = device.CustomerDev; + channelsTable.Rows[index]["startTime"] = device.StartTime; + channelsTable.Rows[index]["endTime"] = device.EndTime; + channelsTable.Rows[index]["channelStatus"] = "占用"; + channelsTable.Rows[index]["deviceId"] = device.Id; + channelsTable.Rows[index]["deviceItemId"] = device.DetectionItemId; + + if (device.Stability.Equals("-3")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.Stability.Equals("-2")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.Stability.Equals("-1")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + if (device.Accuracy.Equals("-3")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.Accuracy.Equals("-2")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.Accuracy.Equals("-1")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + if (device.AgeRate.Equals("-3")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.AgeRate.Equals("-2")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.AgeRate.Equals("-1")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + if (device.BootFeature.Equals("-3")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.BootFeature.Equals("-2")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.BootFeature.Equals("-1")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + + } + } + else + { + channelsTable.Rows.Clear(); + channelsTable.Rows.Add("1", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("2", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("3", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("4", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("5", "", "", "", "", "", "空闲", "", ""); + } + + foreach (string no in channelFreeList) + { + channelsTable.Rows[Convert.ToInt32(no) - 1]["channelNo"] = no; + channelsTable.Rows[Convert.ToInt32(no) - 1]["channelStatus"] = "空闲"; + } + + + dataGridView_Channel.DataSource = channelsTable; + + // width=764px + dataGridView_Channel.Columns[11].Visible = false; + dataGridView_Channel.Columns[12].Visible = false; + dataGridView_Channel.Columns[0].Width = 70; + dataGridView_Channel.Columns[1].Width = 110; + dataGridView_Channel.Columns[2].Width = 120; + dataGridView_Channel.Columns[3].Width = 120; + dataGridView_Channel.Columns[4].Width = 100; //starttime + dataGridView_Channel.Columns[5].Width = 100; //endtime + dataGridView_Channel.Columns[6].Width = 64; + dataGridView_Channel.Columns[7].Width = 75; + dataGridView_Channel.Columns[8].Width = 75; + dataGridView_Channel.Columns[9].Width = 75; + dataGridView_Channel.Columns[10].Width = 75; + + dataGridView_Channel.Columns[0].ReadOnly = true; + dataGridView_Channel.Columns[1].ReadOnly = true; + dataGridView_Channel.Columns[2].ReadOnly = true; + dataGridView_Channel.Columns[3].ReadOnly = true; + dataGridView_Channel.Columns[4].ReadOnly = true; + dataGridView_Channel.Columns[5].ReadOnly = true; + dataGridView_Channel.Columns[6].ReadOnly = true; + dataGridView_Channel.Columns[7].ReadOnly = true; + dataGridView_Channel.Columns[8].ReadOnly = true; + dataGridView_Channel.Columns[9].ReadOnly = true; + dataGridView_Channel.Columns[10].ReadOnly = true; } } - else - { - channelsTable.Rows.Clear(); - channelsTable.Rows.Add("1", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("2", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("3", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("4", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("5", "", "", "", "", "", "空闲", "", ""); - } - - foreach (string no in channelFreeList) - { - channelsTable.Rows[Convert.ToInt32(no) - 1]["channelNo"] = no; - channelsTable.Rows[Convert.ToInt32(no) - 1]["channelStatus"] = "空闲"; - } - - - dataGridView_Channel.DataSource = channelsTable; - - // width=764px - dataGridView_Channel.Columns[11].Visible = false; - dataGridView_Channel.Columns[12].Visible = false; - dataGridView_Channel.Columns[0].Width = 50; - dataGridView_Channel.Columns[1].Width = 110; - dataGridView_Channel.Columns[2].Width = 110; - dataGridView_Channel.Columns[3].Width = 110; - dataGridView_Channel.Columns[4].Width = 120; - dataGridView_Channel.Columns[5].Width = 120; - dataGridView_Channel.Columns[6].Width = 64; - dataGridView_Channel.Columns[7].Width = 75; - dataGridView_Channel.Columns[8].Width = 75; - dataGridView_Channel.Columns[9].Width = 75; - dataGridView_Channel.Columns[10].Width = 75; - - dataGridView_Channel.Columns[0].ReadOnly = true; - dataGridView_Channel.Columns[1].ReadOnly = true; - dataGridView_Channel.Columns[2].ReadOnly = true; - dataGridView_Channel.Columns[3].ReadOnly = true; - dataGridView_Channel.Columns[4].ReadOnly = true; - dataGridView_Channel.Columns[5].ReadOnly = true; - dataGridView_Channel.Columns[6].ReadOnly = true; - dataGridView_Channel.Columns[7].ReadOnly = true; - dataGridView_Channel.Columns[8].ReadOnly = true; - dataGridView_Channel.Columns[9].ReadOnly = true; - dataGridView_Channel.Columns[10].ReadOnly = true; + //})); } } catch (Exception ex) @@ -760,7 +772,6 @@ private void cellDoubleClick(int rowIndex) { - int colIndex = dataGridView_Channel.CurrentCell.ColumnIndex; if (dataGridView_Channel.Rows[rowIndex].Cells[6].Value.ToString().Equals("占用")) { if (MessageBox.Show("该通道有正在检测的仪器,确定要停止检测?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) @@ -780,30 +791,22 @@ { return; } + DialogResult dialogResult = MessageBox.Show("是否保存此次检测的数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { - detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, false); + detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, false); } else { detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, true); } - DetectionItem detectionItem0 = detectionItemService.getById(deviceItemId); - if (detectionItem0 != null) - { - if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem0.Stability1.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "0", "", "", ""); - if (detectionItem0.Stability10.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "", "0", "", ""); - if (detectionItem0.Stability20.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "", "", "0", ""); - if (detectionItem0.Stability100.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "", "", "", "0"); - if (detectionItem0.Accuracy.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "0", "", "", "", "", "", "", ""); - if (detectionItem0.BootFeature.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "0", "", "", "", "", "", ""); - if (detectionItem0.AgeRate.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "0", "", "", "", "", ""); - - } + if (stoppedItemIdTable.Contains(rowIndex + 1)) stoppedItemIdTable.Remove(rowIndex + 1); + + stoppedItemIdTable.Add(rowIndex + 1, deviceItemId); LoadChannelStatus(); + currentPage = 1; LoadDevToBeTested(); } catch(Exception ex) diff --git a/RbFreqStandMeasure/home/SetDevChannelDlg.cs b/RbFreqStandMeasure/home/SetDevChannelDlg.cs index fe3bcdd..a1d96fe 100644 --- a/RbFreqStandMeasure/home/SetDevChannelDlg.cs +++ b/RbFreqStandMeasure/home/SetDevChannelDlg.cs @@ -84,9 +84,12 @@ timePicker_startTime.MinDate = DateTime.Now; getEndTime(); List listToTest = deviceService.search("", "", "", "", "", "1"); - foreach (DeviceDto deviceDto in listToTest) + if (listToTest != null && listToTest.Count > 0) { - cbBox_toTestDevList.Items.Add(deviceDto.DevCode); + foreach (DeviceDto deviceDto in listToTest) + { + cbBox_toTestDevList.Items.Add(deviceDto.DevCode); + } } text_customerDev.Visible = true; @@ -202,7 +205,7 @@ if (checkBox10s.Checked) stability10 = "-1"; if (checkBox20s.Checked) stability20 = "-1"; if (checkBox_100s.Checked) stability100 = "-1"; - detectionHelper.detecStability(deviceId, startTime, interval, port, true ,false); + detectionHelper.detecStability(deviceId, startTime, interval, port, true, false); } else { @@ -257,8 +260,10 @@ } long detectionId0 = detectionItemService.add(deviceId, startTime, endTime, stability, accuracy, bootFeature, ageRate, interval, textBox_channelNo.Text,stability1,stability10,stability20,stability100); detectionHelper.detectionItemId = detectionId0; + this.HideMaskAction(); HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + HomeCtrlForm.homeCtrlForm.currentPage = 1; HomeCtrlForm.homeCtrlForm.LoadDevToBeTested(); } catch (Exception ex) @@ -311,18 +316,18 @@ private void getEndTime() { - if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddSeconds(30); + if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddMinutes(1).AddSeconds(30); else { - if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddSeconds(30); + if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddMinutes(1).AddSeconds(30); else { if (checkBox_stability.Checked) { - if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddSeconds(40); - else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddSeconds(40); - else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddSeconds(40); - else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddSeconds(40); + if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddMinutes(1).AddSeconds(30); + else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddMinutes(1).AddSeconds(30); + else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddMinutes(1).AddSeconds(30); + else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddMinutes(1).AddSeconds(30); } else endTimeBySystem = timePicker_startTime.Value.AddMinutes(1).AddSeconds(30); } diff --git a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs index 963b90b..a5e9368 100644 --- a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs +++ b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs @@ -29,7 +29,7 @@ + ";password=" + databasePassword + ";Charset=utf8" + ";Allow User Variables=True" - + ";Pooling=true"; + + ";Pooling=True"; mySqlConnect = new MySqlConnection(sConnection); mySqlConnect.Open(); iRetval = 0; diff --git a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs index c69559f..f19bd95 100644 --- a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs +++ b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs @@ -38,6 +38,7 @@ private string stability10; private string stability20; private string stability100; + private string isDetecting; public long Id { get @@ -161,5 +162,6 @@ public string Stability20 { get => stability20; set => stability20 = value; } public string Stability100 { get => stability100; set => stability100 = value; } public string Stability1 { get => stability1; set => stability1 = value; } + public string IsDetecting { get => isDetecting; set => isDetecting = value; } } } \ No newline at end of file diff --git a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs index 399098b..781749c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs @@ -9,7 +9,7 @@ { interface DetectionService { - int add(long deviceId, string frequency, string detecItemType, long detectionItemId); + int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time); List search(long deviceId, string detectionType, string startTime, string endTime, long detectionItemId); diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs index 0fd7b24..4df249b 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs @@ -132,7 +132,30 @@ string sQry = "SELECT * FROM r_counter_check_params"; 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) + // { + // if (row[0] != DBNull.Value) counterCheckParam.Id = Convert.ToInt32(row[0]); + // if (row[1] != DBNull.Value) counterCheckParam.SoOutDelay = row[1].ToString(); + // if (row[2] != DBNull.Value) counterCheckParam.SoEleFrequency = row[2].ToString(); + // if (row[3] != DBNull.Value) counterCheckParam.SoEleAddValue = row[3].ToString(); + // if (row[4] != DBNull.Value) counterCheckParam.SoEleAlarm = row[4].ToString(); + // if (row[5] != DBNull.Value) counterCheckParam.FreThreshold1 = row[5].ToString(); + // if (row[6] != DBNull.Value) counterCheckParam.FreThreshold2 = row[6].ToString(); + // if (row[7] != DBNull.Value) counterCheckParam.FreEleAddValue = row[7].ToString(); + // if (row[8] != DBNull.Value) counterCheckParam.CycThreshold1 = row[8].ToString(); + // if (row[9] != DBNull.Value) counterCheckParam.CycThreshold2 = row[9].ToString(); + // if (row[10] != DBNull.Value) counterCheckParam.CycEleAddValue = row[10].ToString(); + + // } + //} using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -149,10 +172,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(Exception ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs index 52b36f8..2c60ab4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs @@ -32,28 +32,29 @@ //先查询是否有历史数据 string sQry = "select ID from r_counter_data where DEVICE_ID=" + deviceId + " and OUT_VALUE = '" + outValue + "'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - - if (aReader.Read()) + bool isUpdated = false; + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - dataId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) + { + dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + + " where ID=" + dataId; + + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; + cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; + cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; + + cmd.ExecuteNonQuery(); + isUpdated = true; + } aReader.Close(); - sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + - " where ID="+ dataId; - - cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; - cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; - cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; - cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; - - cmd.ExecuteNonQuery(); - } - else - { - aReader.Close(); - + if (!isUpdated) + { sQry = "INSERT INTO r_counter_data (DEVICE_ID, OUT_VALUE, VALUE, SENSITIVITY, LOG_TIME, DETEC_TYPE)" + "values(@DEVICE_ID,@OUT_VALUE,@VALUE,@SENSITIVITY,@LOG_TIME,@DETEC_TYPE)"; @@ -70,14 +71,14 @@ sQry = "SELECT max(ID) from r_counter_data"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - - aReader = cmd.ExecuteReader(); - - if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); - + using (MySqlDataReader aReader = cmd.ExecuteReader()) + { + + if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + } } - aReader.Close(); cmd.Dispose(); iRetval = 0; @@ -144,6 +145,8 @@ cmd.ExecuteNonQuery(); } + + aReader.Close(); } @@ -282,9 +285,10 @@ if (!aReader.IsDBNull(6)) counterData.DetecType = aReader.GetString(6); counterDataList.Add(counterData); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs index 6795325..7500bd4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs @@ -47,10 +47,11 @@ counterDetecInitList.Add(counterDetecInit); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -75,29 +76,31 @@ return iRetval; } } - string sQry = "select ID from r_counter_detec_init where FREQUENCY=" + frequency +" AND CYCLE="+cycle; + string sQry = "select ID from r_counter_detec_init where FREQUENCY='" + frequency +"' AND CYCLE='"+cycle+"'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - if (aReader.Read()) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - initId = Convert.ToInt64(aReader.GetString(0)); - sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; + if (aReader.Read()) + { + initId = Convert.ToInt64(aReader.GetString(0)); + sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; - 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(); - } - else - { - 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 = 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(); + } + else + { + 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.ExecuteNonQuery(); + + } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); iRetval = 0; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs index 97b06ba..abcbaa6 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs @@ -72,26 +72,27 @@ MySqlCommand cmd = new MySqlCommand(sql, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(CommandBehavior.Default); - - if (aReader != null) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) + if (aReader != null) { - //判断门的状态 - if (!aReader.IsDBNull(0)) - counterParam.Id = Convert.ToInt32(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) - counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) - counterParam.BaudRate = aReader.GetString(2); - if (!aReader.IsDBNull(3)) - counterParam.GeneratorIp = aReader.GetString(3); - if (!aReader.IsDBNull(4)) - counterParam.SignalSourceIp = aReader.GetString(4); + if (aReader.Read()) + { + //判断门的状态 + if (!aReader.IsDBNull(0)) + counterParam.Id = Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(1)) + counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); + if (!aReader.IsDBNull(2)) + counterParam.BaudRate = aReader.GetString(2); + if (!aReader.IsDBNull(3)) + counterParam.GeneratorIp = aReader.GetString(3); + if (!aReader.IsDBNull(4)) + counterParam.SignalSourceIp = aReader.GetString(4); + } } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs index cca90fb..1578937 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs @@ -33,8 +33,8 @@ MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@DEVICE_ID", MySqlDbType.Int64, 20).Value = deviceId; - cmd.Parameters.Add("@START_TIME", MySqlDbType.String, 50).Value = startTime; - cmd.Parameters.Add("@END_TIME", MySqlDbType.String, 50).Value = endTime; + cmd.Parameters.Add("@START_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(startTime); + cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(endTime); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 50).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 50).Value = accuracy; cmd.Parameters.Add("@BOOT_FEATURE", MySqlDbType.String, 50).Value = bootFeature; @@ -58,11 +58,11 @@ sQry = "SELECT max(ID) from r_detection_item"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = cmd.ExecuteReader()) { if (aReader.Read()) detectionId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); iRetval = 0; @@ -203,8 +203,9 @@ if (!stability100.Equals("")) sQry = sQry + " STABILITY_100=@STABILITY_100,"; sQry = sQry + " COUNTER_DETEC=@COUNTER_DETEC where ID = " + detectionId; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry: " + sQry); - + MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 10).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 10).Value = accuracy; @@ -283,7 +284,8 @@ return iRetval; } } - + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "停止检测 detectionItemId=======" + detectionItemId); + string sQry = "UPDATE r_device SET STATUSID="+"1"+", CHANNEL=@CHANNEL where ID=" + deviceId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@CHANNEL", MySqlDbType.String, 20).Value = ""; @@ -292,19 +294,21 @@ if (isDeleteData) { - sQry = "DELETE FROM r_detection_item WHERE DEVICE_ID = " + deviceId + " AND START_TIME='" + startTime + "' AND END_TIME='" + endTime + "'"; + sQry = "DELETE FROM r_detection_item WHERE ID=" + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); - sQry = "DELETE FROM r_detection WHERE DEVICE_ID = " + deviceId + " AND (LOG_TIME between'" + startTime + "' and '" + endTime + "')"; + sQry = "DELETE FROM r_detection WHERE DETECTION_ITEM_ID = " + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); } else { - sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME WHERE ID="+ detectionItemId; + sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME, IS_DETECTING=@IS_DETECTING WHERE ID=" + detectionItemId; + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 20).Value = DateTime.Now; + cmd.Parameters.Add("@IS_DETECTING", MySqlDbType.String, 1).Value = "0"; //0-否,1-是 cmd.ExecuteNonQuery(); } @@ -322,8 +326,7 @@ { DetectionItem detectionItem = null; try - { - + { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getById : 数据库链接断开"); @@ -337,6 +340,7 @@ string sQry = "select * from r_detection_item WHERE ID = "+ detectionItemId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + using (MySqlDataReader aReader = cmd.ExecuteReader()) { while (aReader.Read()) @@ -356,11 +360,13 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(15)) detectionItem.IsDetecting = aReader.GetString(15); } - } - + aReader.Close(); + } cmd.Dispose(); + } catch (MySqlException e) { @@ -400,7 +406,7 @@ { DetectionItem detectionItem = new DetectionItem(); //姓名 - if (!aReader.IsDBNull(0)) detectionItem.Id=Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(0)) detectionItem.Id = Convert.ToInt32(aReader.GetString(0)); if (!aReader.IsDBNull(1)) detectionItem.DeviceId = Convert.ToInt64(aReader.GetString(1)); if (!aReader.IsDBNull(2)) detectionItem.StartTime = aReader.GetString(2); if (!aReader.IsDBNull(3)) detectionItem.EndTime = aReader.GetString(3); @@ -416,9 +422,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -468,9 +475,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -498,7 +506,6 @@ string sQry = "SELECT * FROM r_detection_item where ID = " + detectionId; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -518,15 +525,43 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); + //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) + // { + // detectionItem = new DetectionItem(); + // if (row[0] != DBNull.Value) detectionItem.Id = Convert.ToInt64(row[0]); + // if (row[1] != DBNull.Value) detectionItem.DeviceId = Convert.ToInt64(row[1]); + // if (row[2] != DBNull.Value) detectionItem.StartTime = Convert.ToDateTime(row[2]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[3] != DBNull.Value) detectionItem.EndTime = Convert.ToDateTime(row[3]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[4] != DBNull.Value) detectionItem.Stability = row[4].ToString(); + // if (row[5] != DBNull.Value) detectionItem.Accuracy = row[5].ToString(); + // if (row[6] != DBNull.Value) detectionItem.BootFeature = row[6].ToString(); + // if (row[7] != DBNull.Value) detectionItem.AgeRate = row[7].ToString(); + // if (row[8] != DBNull.Value) detectionItem.Interval = row[8].ToString(); + // if (row[10] != DBNull.Value) detectionItem.Channel = row[10].ToString(); + // if (row[11] != DBNull.Value) detectionItem.Stability1 = row[11].ToString(); + // if (row[12] != DBNull.Value) detectionItem.Stability10 = row[12].ToString(); + // if (row[13] != DBNull.Value) detectionItem.Stability20 = row[13].ToString(); + // if (row[14] != DBNull.Value) detectionItem.Stability100 = row[14].ToString(); + + // } + //} } catch (MySqlException ex) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDetectionItem: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchById: " + ex.Message); } return detectionItem; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs index e2a5893..5b3deb0 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs @@ -14,7 +14,7 @@ { class DetectionServiceImpl : DetectionService { - public int add(long deviceId, string frequency, string detecItemType, long detectionItemId) + public int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time) { int iRetval = -1; try @@ -36,7 +36,7 @@ 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 = DateTime.Now; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.DateTime, 0).Value = time; cmd.Parameters.Add("@DETECTION_ITEM", MySqlDbType.String, 0).Value = detecItemType; cmd.Parameters.Add("@DETECTION_ITEM_ID", MySqlDbType.Int64, 0).Value = detectionItemId; @@ -108,24 +108,26 @@ string sQry = "SELECT * FROM r_detection where DEVICE_ID = " + deviceId +" and DETECTION_ITEM='" + detectionType + "' and (LOG_TIME BETWEEN '" + startTime + "' and '"+ endTime + "') and DETECTION_ITEM_ID="+detectionItemId+" order by LOG_TIME"; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) { - Model.Detection detection = new Model.Detection(); - //姓名 - if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) detection.LogTime = Convert.ToDateTime(aReader.GetString(2)).ToString("yyyy-MM-dd HH:mm:ss"); - if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); - if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); + Detection detection = new Detection(); + + if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); // id + if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); // devName + if (!aReader.IsDBNull(2)) detection.LogTime = aReader.GetString(2); // devCode + if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); // devType + if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); // devModel detectionDtoList.Add(detection); } + aReader.Close(); + - aCommand.Dispose(); } + aCommand.Dispose(); + } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs index 9413e2f..b224bc1 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs @@ -53,7 +53,8 @@ using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); @@ -87,8 +88,7 @@ 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; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry : "+ sQry + "; statusId="+ statusId); - + 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; @@ -183,7 +183,7 @@ } MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -208,10 +208,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -254,7 +255,30 @@ 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()) @@ -279,10 +303,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -342,7 +367,30 @@ 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()) @@ -372,10 +420,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -442,9 +491,10 @@ { totalCount = aReader.GetInt32(0); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -477,89 +527,45 @@ return null; } } - - string sQry = "SELECT * FROM r_deviceview where ACTIVE = 0 and STATUSID = 2 " + "and ('" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' <= END_TIME)"; - - 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) + //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))"; + MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { - foreach (DataRow row in dt.Rows) + while (aReader.Read()) { DeviceView deviceView = new DeviceView(); - if (row[0] != DBNull.Value) deviceView.Id = Convert.ToInt64(row[0]); - if (row[1] != DBNull.Value) deviceView.DevName = row[1].ToString(); - if (row[2] != DBNull.Value) deviceView.DevCode = row[2].ToString(); - if (row[3] != DBNull.Value) deviceView.DevTypeId = row[3].ToString(); - if (row[4] != DBNull.Value) deviceView.DevModel = row[4].ToString(); - if (row[5] != DBNull.Value) deviceView.RegTime = row[5].ToString(); - if (row[6] != DBNull.Value) deviceView.CustomerName = row[6].ToString(); - if (row[7] != DBNull.Value) deviceView.CustomerDev = row[7].ToString(); - if (row[8] != DBNull.Value) deviceView.Channel = row[8].ToString(); - if (row[9] != DBNull.Value) deviceView.Active = Convert.ToInt32(row[9]); - if (row[10] != DBNull.Value) deviceView.StartTime = Convert.ToDateTime(row[10]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[11] != DBNull.Value) deviceView.EndTime = Convert.ToDateTime(row[11]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[12] != DBNull.Value) deviceView.StatusId = row[12].ToString(); - if (row[13] != DBNull.Value) deviceView.Stability = row[13].ToString(); - if (row[14] != DBNull.Value) deviceView.Accuracy = row[14].ToString(); - if (row[15] != DBNull.Value) deviceView.BootFeature = row[15].ToString(); - if (row[16] != DBNull.Value) deviceView.AgeRate = row[16].ToString(); - if (row[17] != DBNull.Value) deviceView.DetectionItemId = Convert.ToInt64(row[17]); + 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(); + + } - //using (MySqlDataReader aReader = aCommand.ExecuteReader()) - //{ - // while (aReader.Read()) - // { - // DeviceView deviceView = new DeviceView(); + aCommand.Dispose(); - // 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 - // //deviceView.DevTypeName = dictService.getNameByCode("devType", aReader.GetString(3)); - // } - // if (!aReader.IsDBNull(4)) deviceView.DevModel = aReader.GetString(4); // devModel - // if (!aReader.IsDBNull(5)) - // { - // DateTime reg = aReader.GetDateTime(5); // regTime - // deviceView.RegTime = reg.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); - // if (!aReader.IsDBNull(9)) deviceView.Active = Convert.ToInt32(aReader.GetString(9)); - // if (!aReader.IsDBNull(10)) - // { - // DateTime reg = aReader.GetDateTime(10); // regTime - // deviceView.StartTime = reg.ToString("yyyy-MM-dd HH:mm:ss"); - // } - // if (!aReader.IsDBNull(11)) - // { - // DateTime reg = aReader.GetDateTime(11); // regTime - // deviceView.EndTime = reg.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 = Convert.ToInt64(aReader.GetString(17)); - - // deviceViewList.Add(deviceView); - - // aCommand.Dispose(); - // } - //} - if (deviceViewList.Count > 0) { foreach (DeviceView deviceView in deviceViewList) @@ -568,9 +574,15 @@ } } } + + 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()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getDeviceByChannel: " + ex.Message + " ; " + ex.ToString()); deviceViewList = null; } finally diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs index 1626aa5..42ca83c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs @@ -92,10 +92,11 @@ if (!aReader.IsDBNull(3)) dict.Code = aReader.GetString(3); nameList.Add(dict); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(MySqlException ex) { @@ -139,10 +140,11 @@ if (!aReader.IsDBNull(3)) counterParam.GeneratorIp = aReader.GetString(3); if (!aReader.IsDBNull(4)) counterParam.SignalSourceIp = aReader.GetString(4); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -220,10 +222,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/RbFreqStdMeas.cs b/RbFreqStandMeasure/RbFreqStdMeas.cs index beae3dc..8d74572 100644 --- a/RbFreqStandMeasure/RbFreqStdMeas.cs +++ b/RbFreqStandMeasure/RbFreqStdMeas.cs @@ -363,24 +363,7 @@ detectionItemService.stopDetection(deviceId, device.DetectionItemId, startTime, endTime, true); } } - deviceService.clearChannel(); - List detectionItemList = detectionItemService.getAll(); - if (detectionItemList != null && detectionItemList.Count > 0) - { - foreach (DetectionItem detectionItem in detectionItemList) - { - long detectionItemId = detectionItem.Id; - if (detectionItem.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem.Stability1.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "0", "", "", ""); - if (detectionItem.Stability10.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "0", "", ""); - if (detectionItem.Stability20.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "0", ""); - if (detectionItem.Stability100.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "", "0"); - if (detectionItem.Accuracy.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "0", "", "", "", "", "", "", ""); - if (detectionItem.BootFeature.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "0", "", "", "", "", "", ""); - if (detectionItem.AgeRate.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "0", "", "", "", "", ""); - } - } - + deviceService.clearChannel(); } else { @@ -590,7 +573,7 @@ break; case 3: // 频率计数器范围 - CounterCtrlForm counterForm = CounterCtrlForm.GetInstance(); + CounterCtrlForm counterForm = new CounterCtrlForm(); counterForm.Show(); panelMain.Controls.Add(counterForm); break; diff --git a/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe b/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe index 70dc261..11271b0 100644 --- a/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe +++ b/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe Binary files differ diff --git a/RbFreqStandMeasure/counter/CounterCtrlForm.cs b/RbFreqStandMeasure/counter/CounterCtrlForm.cs index 951a19c..e45f17b 100644 --- a/RbFreqStandMeasure/counter/CounterCtrlForm.cs +++ b/RbFreqStandMeasure/counter/CounterCtrlForm.cs @@ -39,6 +39,9 @@ GPIBService tcpService = new TCPServiceImpl(); string valueOld = ""; + string valueOldBack = ""; + string valueOldSensi = ""; + string valueOldTime = ""; #region 样式常量定影 private readonly Color titleBackColor = Color.FromArgb(63, 132, 215); // #3F64D7 @@ -55,8 +58,8 @@ return _counterCtrlForm; } - - private CounterCtrlForm() + + public CounterCtrlForm() { InitializeComponent(); @@ -69,7 +72,7 @@ comboBox_detecModel.SelectedIndex = 0; InitTableCounter(); - LoadCounterDetecInitList(); + //LoadCounterDetecInitList(); if (list != null && list.Count > 0) { @@ -221,12 +224,12 @@ table_counterDetecInit.Columns.Add("initId", Type.GetType("System.Int32")); table_counterDetecInit.Columns.Add("counterDataId", Type.GetType("System.Int64")); - if (comboBox_counters.Text != "") + if (((DeviceDto)comboBox_counters.SelectedItem).DevName != "") { - List list = deviceService.search(comboBox_counters.Text, "", "", "", "", ""); + List list = deviceService.search(((DeviceDto)comboBox_counters.SelectedItem).DevName, "", "", "", "", ""); if (null != list && list.Count > 0) { - devType = list[0].DevTypeName; + devType = list[0].DevModel; devCode = list[0].DevCode; } @@ -344,6 +347,18 @@ { valueOld = dataGridView_CounterResult.CurrentCell.Value.ToString(); } + else if (e.ColumnIndex == 5) + { + valueOldBack = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } + else if (e.ColumnIndex == 6) + { + valueOldSensi = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } + else if (e.ColumnIndex == 7) + { + valueOldTime = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } } @@ -522,7 +537,10 @@ dataGridView_CounterResult.ReadOnly = true; btn_add.Enabled = false; benDelete.Enabled = false; - ///btn_dropDetecModel.Enabled = false; + comboBox_counters.Enabled = false; + comboBox_detecModel.Enabled = false; + text_counterIp.ReadOnly = true; + text_signal.ReadOnly = true; string[] arr = text_counterIp.Text.Split('.'); if (arr.Length != 4) @@ -643,11 +661,11 @@ Invoke(new MethodInvoker(delegate () { SetDevTestDlg.inDetecCounterId = -1; - //text_devName.ReadOnly = false; - //btn_downCounterList.Enabled = true; btnStart.Enabled = true; - //btn_dropDetecModel.Enabled = true; - //textBox_detecModel.ReadOnly = false; + comboBox_counters.Enabled = true; + comboBox_detecModel.Enabled = true; + text_counterIp.ReadOnly = false; + text_signal.ReadOnly = false; })); dataGridView_CounterResult.ReadOnly = false; @@ -736,6 +754,8 @@ if (!checkFreq(value)) { MessageBox.Show("请输入格式正确的测量频率值!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldBack; + valueOldBack = ""; return; } } @@ -744,6 +764,8 @@ if (!checkCyc(value)) { MessageBox.Show("请输入格式正确的测量周期值!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldBack; + valueOldBack = ""; return; } } @@ -753,11 +775,21 @@ { if (!String.IsNullOrEmpty(value)) { + if (value.Contains(".") && ((value.IndexOf('.') != value.LastIndexOf('.')) || value.IndexOf('.') == 0 || value.LastIndexOf('.') == value.Length)) + { + MessageBox.Show("请输入格式正确的灵敏度!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldSensi; + valueOldSensi = ""; + return; + } + string pattern = @"^[0-9.]+$"; Regex regex = new Regex(pattern); if (!regex.IsMatch(value)) { MessageBox.Show("请输入格式正确的灵敏度!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldSensi; + valueOldSensi = ""; return; } } @@ -772,7 +804,8 @@ } catch { - dataGridView_CounterResult.Rows[e.RowIndex].Cells[7].Value = ""; + dataGridView_CounterResult.CurrentCell.Value = valueOldTime; + valueOldTime = ""; MessageBox.Show("请输入格式正确的时间!"); return; } diff --git a/RbFreqStandMeasure/home/HomeCtrlForm.cs b/RbFreqStandMeasure/home/HomeCtrlForm.cs index b2568f7..586334d 100644 --- a/RbFreqStandMeasure/home/HomeCtrlForm.cs +++ b/RbFreqStandMeasure/home/HomeCtrlForm.cs @@ -7,6 +7,7 @@ using Casic.Birmm.RbFreqStandMeasure.Tools; using DevComponents.DotNetBar.Controls; using System; +using System.Collections; using System.Collections.Generic; using System.Data; using System.Drawing; @@ -23,16 +24,16 @@ public partial class HomeCtrlForm : UserControl { public static HomeCtrlForm homeCtrlForm; - int totalCount = 0; - int currentPage = 1; - int pageCount = 0; - int limitCount = 4; + public int totalCount = 0; + public int currentPage = 1; + public int pageCount = 0; + public int limitCount = 4; DataTable devToBeTestedTable = null; DataTable channelsTable = null; DeviceService deviceService = new DeviceServiceImpl(); List listChannelStatus = new List(); DetectionItemService detectionItemService = new DetectionItemServiceImpl(); - + public static Hashtable stoppedItemIdTable = new Hashtable(); public static List channelFreeList = new List(); private readonly object obj = new object(); @@ -166,10 +167,7 @@ Size = new Size(120, 32) }; tableToBeTested.Controls.Add(colCustomComp); - colCustomComp.BringToFront(); - - - + colCustomComp.BringToFront(); totalCount = 0; currentPage = 1; @@ -332,7 +330,7 @@ AutoSize = false, Text = "通道", Location = new Point(0, 0), - Size = new Size(50, 30) + Size = new Size(70, 30) }; dataGridView_Channel.Controls.Add(colChannelNo); colChannelNo.BringToFront(); @@ -346,7 +344,7 @@ BackColor = titleBackColor, AutoSize = false, Text = "仪器名称", - Location = new Point(50, 0), + Location = new Point(70, 0), Size = new Size(110, 30) }; dataGridView_Channel.Controls.Add(colDevName); @@ -361,8 +359,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "仪器编号", - Location = new Point(160, 0), - Size = new Size(110, 30) + Location = new Point(180, 0), + Size = new Size(120, 30) }; dataGridView_Channel.Controls.Add(colDevNo); colDevNo.BringToFront(); @@ -376,8 +374,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "送检单位", - Location = new Point(270, 0), - Size = new Size(110, 30) + Location = new Point(300, 0), + Size = new Size(120, 30) }; dataGridView_Channel.Controls.Add(colCustomName); colCustomName.BringToFront(); @@ -391,8 +389,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "开始时间", - Location = new Point(380, 0), - Size = new Size(120, 30) + Location = new Point(420, 0), + Size = new Size(100, 30) }; dataGridView_Channel.Controls.Add(colStartTime); colStartTime.BringToFront(); @@ -406,8 +404,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "结束时间", - Location = new Point(500, 0), - Size = new Size(120, 30) + Location = new Point(520, 0), + Size = new Size(100, 30) }; dataGridView_Channel.Controls.Add(colEndTime); colEndTime.BringToFront(); @@ -492,6 +490,11 @@ dataGridView_Channel.Controls.Add(colAgingRate); colAgingRate.BringToFront(); } + + + + + } catch (Exception ex) { @@ -506,19 +509,22 @@ { lock (obj) { - channelFreeList.Clear(); - channelFreeList.Add("1"); - channelFreeList.Add("2"); - channelFreeList.Add("3"); - channelFreeList.Add("4"); - channelFreeList.Add("5"); - - listChannelStatus = deviceService.getDeviceByChannel(); - if (listChannelStatus != null && listChannelStatus.Count > 0) + // lock (channelFreeList) { - foreach (DeviceView device in listChannelStatus) + channelFreeList.Clear(); + channelFreeList.Add("1"); + channelFreeList.Add("2"); + channelFreeList.Add("3"); + channelFreeList.Add("4"); + channelFreeList.Add("5"); + + listChannelStatus = deviceService.getDeviceByChannel(); + if (listChannelStatus != null && listChannelStatus.Count > 0) { - channelFreeList.Remove(device.Channel); + foreach (DeviceView device in listChannelStatus) + { + channelFreeList.Remove(device.Channel); + } } } } @@ -533,125 +539,131 @@ { try { - lock (obj) + //Invoke(new MethodInvoker(delegate () { - channelsTable = new DataTable(); - - channelsTable.Columns.Add("channelNo", Type.GetType("System.String")); - channelsTable.Columns.Add("devName", Type.GetType("System.String")); - channelsTable.Columns.Add("devCode", Type.GetType("System.String")); - channelsTable.Columns.Add("customComp", Type.GetType("System.String")); - channelsTable.Columns.Add("startTime", Type.GetType("System.String")); - channelsTable.Columns.Add("endTime", Type.GetType("System.String")); - channelsTable.Columns.Add("channelStatus", Type.GetType("System.String")); - channelsTable.Columns.Add("stablility", Type.GetType("System.String")); - channelsTable.Columns.Add("accuracy", Type.GetType("System.String")); - channelsTable.Columns.Add("startup", Type.GetType("System.String")); - channelsTable.Columns.Add("agingRate", Type.GetType("System.String")); - channelsTable.Columns.Add("deviceId", Type.GetType("System.Int64")); - channelsTable.Columns.Add("deviceItemId", Type.GetType("System.Int64")); - //channelsTable.Columns.Add("devType", Type.GetType("System.String")); - //channelsTable.Columns.Add("devModel", Type.GetType("System.String")); - //channelsTable.Columns.Add("customCom", Type.GetType("System.String")); - - listChannelStatus = deviceService.getDeviceByChannel(); - - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelFreeList.Clear(); - channelFreeList.Add("1"); - channelFreeList.Add("2"); - channelFreeList.Add("3"); - channelFreeList.Add("4"); - channelFreeList.Add("5"); - - if (listChannelStatus != null && listChannelStatus.Count > 0) + lock (obj) { - foreach (DeviceView device in listChannelStatus) + //lock(channelFreeList) { - channelFreeList.Remove(device.Channel); - int index = Convert.ToInt32(device.Channel) - 1; - channelsTable.Rows[index]["channelNo"] = device.Channel; - channelsTable.Rows[index]["devName"] = device.DevName; - channelsTable.Rows[index]["devCode"] = device.DevCode; - channelsTable.Rows[index]["customComp"] = device.CustomerDev; - channelsTable.Rows[index]["startTime"] = device.StartTime; - channelsTable.Rows[index]["endTime"] = device.EndTime; - channelsTable.Rows[index]["channelStatus"] = "占用"; - channelsTable.Rows[index]["deviceId"] = device.Id; - channelsTable.Rows[index]["deviceItemId"] = device.DetectionItemId; + channelsTable = new DataTable(); - if (device.Stability.Equals("-3")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.Stability.Equals("-2")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.Stability.Equals("-1")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + channelsTable.Columns.Add("channelNo", Type.GetType("System.String")); + channelsTable.Columns.Add("devName", Type.GetType("System.String")); + channelsTable.Columns.Add("devCode", Type.GetType("System.String")); + channelsTable.Columns.Add("customComp", Type.GetType("System.String")); + channelsTable.Columns.Add("startTime", Type.GetType("System.String")); + channelsTable.Columns.Add("endTime", Type.GetType("System.String")); + channelsTable.Columns.Add("channelStatus", Type.GetType("System.String")); + channelsTable.Columns.Add("stablility", Type.GetType("System.String")); + channelsTable.Columns.Add("accuracy", Type.GetType("System.String")); + channelsTable.Columns.Add("startup", Type.GetType("System.String")); + channelsTable.Columns.Add("agingRate", Type.GetType("System.String")); + channelsTable.Columns.Add("deviceId", Type.GetType("System.Int64")); + channelsTable.Columns.Add("deviceItemId", Type.GetType("System.Int64")); - if (device.Accuracy.Equals("-3")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.Accuracy.Equals("-2")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.Accuracy.Equals("-1")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; - - if (device.AgeRate.Equals("-3")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.AgeRate.Equals("-2")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.AgeRate.Equals("-1")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; - - if (device.BootFeature.Equals("-3")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.BootFeature.Equals("-2")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.BootFeature.Equals("-1")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + listChannelStatus = deviceService.getDeviceByChannel(); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelFreeList.Clear(); + channelFreeList.Add("1"); + channelFreeList.Add("2"); + channelFreeList.Add("3"); + channelFreeList.Add("4"); + channelFreeList.Add("5"); + + if (listChannelStatus != null && listChannelStatus.Count > 0) + { + foreach (DeviceView device in listChannelStatus) + { + if (String.IsNullOrEmpty(device.Channel)) continue; + channelFreeList.Remove(device.Channel); + int index = Convert.ToInt32(device.Channel) - 1; + channelsTable.Rows[index]["channelNo"] = device.Channel; + channelsTable.Rows[index]["devName"] = device.DevName; + channelsTable.Rows[index]["devCode"] = device.DevCode; + channelsTable.Rows[index]["customComp"] = device.CustomerDev; + channelsTable.Rows[index]["startTime"] = device.StartTime; + channelsTable.Rows[index]["endTime"] = device.EndTime; + channelsTable.Rows[index]["channelStatus"] = "占用"; + channelsTable.Rows[index]["deviceId"] = device.Id; + channelsTable.Rows[index]["deviceItemId"] = device.DetectionItemId; + + if (device.Stability.Equals("-3")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.Stability.Equals("-2")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.Stability.Equals("-1")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + if (device.Accuracy.Equals("-3")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.Accuracy.Equals("-2")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.Accuracy.Equals("-1")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + if (device.AgeRate.Equals("-3")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.AgeRate.Equals("-2")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.AgeRate.Equals("-1")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + if (device.BootFeature.Equals("-3")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.BootFeature.Equals("-2")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.BootFeature.Equals("-1")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + + } + } + else + { + channelsTable.Rows.Clear(); + channelsTable.Rows.Add("1", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("2", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("3", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("4", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("5", "", "", "", "", "", "空闲", "", ""); + } + + foreach (string no in channelFreeList) + { + channelsTable.Rows[Convert.ToInt32(no) - 1]["channelNo"] = no; + channelsTable.Rows[Convert.ToInt32(no) - 1]["channelStatus"] = "空闲"; + } + + + dataGridView_Channel.DataSource = channelsTable; + + // width=764px + dataGridView_Channel.Columns[11].Visible = false; + dataGridView_Channel.Columns[12].Visible = false; + dataGridView_Channel.Columns[0].Width = 70; + dataGridView_Channel.Columns[1].Width = 110; + dataGridView_Channel.Columns[2].Width = 120; + dataGridView_Channel.Columns[3].Width = 120; + dataGridView_Channel.Columns[4].Width = 100; //starttime + dataGridView_Channel.Columns[5].Width = 100; //endtime + dataGridView_Channel.Columns[6].Width = 64; + dataGridView_Channel.Columns[7].Width = 75; + dataGridView_Channel.Columns[8].Width = 75; + dataGridView_Channel.Columns[9].Width = 75; + dataGridView_Channel.Columns[10].Width = 75; + + dataGridView_Channel.Columns[0].ReadOnly = true; + dataGridView_Channel.Columns[1].ReadOnly = true; + dataGridView_Channel.Columns[2].ReadOnly = true; + dataGridView_Channel.Columns[3].ReadOnly = true; + dataGridView_Channel.Columns[4].ReadOnly = true; + dataGridView_Channel.Columns[5].ReadOnly = true; + dataGridView_Channel.Columns[6].ReadOnly = true; + dataGridView_Channel.Columns[7].ReadOnly = true; + dataGridView_Channel.Columns[8].ReadOnly = true; + dataGridView_Channel.Columns[9].ReadOnly = true; + dataGridView_Channel.Columns[10].ReadOnly = true; } } - else - { - channelsTable.Rows.Clear(); - channelsTable.Rows.Add("1", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("2", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("3", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("4", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("5", "", "", "", "", "", "空闲", "", ""); - } - - foreach (string no in channelFreeList) - { - channelsTable.Rows[Convert.ToInt32(no) - 1]["channelNo"] = no; - channelsTable.Rows[Convert.ToInt32(no) - 1]["channelStatus"] = "空闲"; - } - - - dataGridView_Channel.DataSource = channelsTable; - - // width=764px - dataGridView_Channel.Columns[11].Visible = false; - dataGridView_Channel.Columns[12].Visible = false; - dataGridView_Channel.Columns[0].Width = 50; - dataGridView_Channel.Columns[1].Width = 110; - dataGridView_Channel.Columns[2].Width = 110; - dataGridView_Channel.Columns[3].Width = 110; - dataGridView_Channel.Columns[4].Width = 120; - dataGridView_Channel.Columns[5].Width = 120; - dataGridView_Channel.Columns[6].Width = 64; - dataGridView_Channel.Columns[7].Width = 75; - dataGridView_Channel.Columns[8].Width = 75; - dataGridView_Channel.Columns[9].Width = 75; - dataGridView_Channel.Columns[10].Width = 75; - - dataGridView_Channel.Columns[0].ReadOnly = true; - dataGridView_Channel.Columns[1].ReadOnly = true; - dataGridView_Channel.Columns[2].ReadOnly = true; - dataGridView_Channel.Columns[3].ReadOnly = true; - dataGridView_Channel.Columns[4].ReadOnly = true; - dataGridView_Channel.Columns[5].ReadOnly = true; - dataGridView_Channel.Columns[6].ReadOnly = true; - dataGridView_Channel.Columns[7].ReadOnly = true; - dataGridView_Channel.Columns[8].ReadOnly = true; - dataGridView_Channel.Columns[9].ReadOnly = true; - dataGridView_Channel.Columns[10].ReadOnly = true; + //})); } } catch (Exception ex) @@ -760,7 +772,6 @@ private void cellDoubleClick(int rowIndex) { - int colIndex = dataGridView_Channel.CurrentCell.ColumnIndex; if (dataGridView_Channel.Rows[rowIndex].Cells[6].Value.ToString().Equals("占用")) { if (MessageBox.Show("该通道有正在检测的仪器,确定要停止检测?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) @@ -780,30 +791,22 @@ { return; } + DialogResult dialogResult = MessageBox.Show("是否保存此次检测的数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { - detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, false); + detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, false); } else { detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, true); } - DetectionItem detectionItem0 = detectionItemService.getById(deviceItemId); - if (detectionItem0 != null) - { - if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem0.Stability1.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "0", "", "", ""); - if (detectionItem0.Stability10.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "", "0", "", ""); - if (detectionItem0.Stability20.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "", "", "0", ""); - if (detectionItem0.Stability100.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "", "", "", "0"); - if (detectionItem0.Accuracy.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "0", "", "", "", "", "", "", ""); - if (detectionItem0.BootFeature.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "0", "", "", "", "", "", ""); - if (detectionItem0.AgeRate.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "0", "", "", "", "", ""); - - } + if (stoppedItemIdTable.Contains(rowIndex + 1)) stoppedItemIdTable.Remove(rowIndex + 1); + + stoppedItemIdTable.Add(rowIndex + 1, deviceItemId); LoadChannelStatus(); + currentPage = 1; LoadDevToBeTested(); } catch(Exception ex) diff --git a/RbFreqStandMeasure/home/SetDevChannelDlg.cs b/RbFreqStandMeasure/home/SetDevChannelDlg.cs index fe3bcdd..a1d96fe 100644 --- a/RbFreqStandMeasure/home/SetDevChannelDlg.cs +++ b/RbFreqStandMeasure/home/SetDevChannelDlg.cs @@ -84,9 +84,12 @@ timePicker_startTime.MinDate = DateTime.Now; getEndTime(); List listToTest = deviceService.search("", "", "", "", "", "1"); - foreach (DeviceDto deviceDto in listToTest) + if (listToTest != null && listToTest.Count > 0) { - cbBox_toTestDevList.Items.Add(deviceDto.DevCode); + foreach (DeviceDto deviceDto in listToTest) + { + cbBox_toTestDevList.Items.Add(deviceDto.DevCode); + } } text_customerDev.Visible = true; @@ -202,7 +205,7 @@ if (checkBox10s.Checked) stability10 = "-1"; if (checkBox20s.Checked) stability20 = "-1"; if (checkBox_100s.Checked) stability100 = "-1"; - detectionHelper.detecStability(deviceId, startTime, interval, port, true ,false); + detectionHelper.detecStability(deviceId, startTime, interval, port, true, false); } else { @@ -257,8 +260,10 @@ } long detectionId0 = detectionItemService.add(deviceId, startTime, endTime, stability, accuracy, bootFeature, ageRate, interval, textBox_channelNo.Text,stability1,stability10,stability20,stability100); detectionHelper.detectionItemId = detectionId0; + this.HideMaskAction(); HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + HomeCtrlForm.homeCtrlForm.currentPage = 1; HomeCtrlForm.homeCtrlForm.LoadDevToBeTested(); } catch (Exception ex) @@ -311,18 +316,18 @@ private void getEndTime() { - if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddSeconds(30); + if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddMinutes(1).AddSeconds(30); else { - if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddSeconds(30); + if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddMinutes(1).AddSeconds(30); else { if (checkBox_stability.Checked) { - if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddSeconds(40); - else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddSeconds(40); - else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddSeconds(40); - else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddSeconds(40); + if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddMinutes(1).AddSeconds(30); + else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddMinutes(1).AddSeconds(30); + else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddMinutes(1).AddSeconds(30); + else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddMinutes(1).AddSeconds(30); } else endTimeBySystem = timePicker_startTime.Value.AddMinutes(1).AddSeconds(30); } diff --git a/RbFreqStandMeasure/home/SetDevTestDlg.cs b/RbFreqStandMeasure/home/SetDevTestDlg.cs index f1027ba..6e9d272 100644 --- a/RbFreqStandMeasure/home/SetDevTestDlg.cs +++ b/RbFreqStandMeasure/home/SetDevTestDlg.cs @@ -23,11 +23,7 @@ public static long inDetecCounterId = -1;// 正在检测灵敏度的计数器id DateTime endTimeBySystem = new DateTime(); - CounterDataService CounterDataService = new CounterDataServiceImpl(); - CounterDetecInitService counterDetecInitService = new CounterDetecInitServiceImpl(); DictService dictService = new DictServiceImpl(); - SensitivityService sensitivityService = new SensitivityServiceImpl(); - CounterDataService counterDataService = new CounterDataServiceImpl(); DeviceService deviceService = new DeviceServiceImpl(); @@ -221,6 +217,7 @@ this.HideMaskAction(); HomeCtrlForm.homeCtrlForm.refreshChannelList(); HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + HomeCtrlForm.homeCtrlForm.currentPage = 1; HomeCtrlForm.homeCtrlForm.LoadDevToBeTested(); } @@ -280,18 +277,18 @@ private void getEndTime() { - if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddSeconds(30); + if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddMinutes(1).AddSeconds(30); else { - if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddSeconds(30); + if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddMinutes(1).AddSeconds(30); else { if (checkBox_stability.Checked) { - if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddSeconds(40); - else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddSeconds(40); - else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddSeconds(40); - else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddSeconds(40); + if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddMinutes(1).AddSeconds(30); + else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddMinutes(1).AddSeconds(30); + else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddMinutes(1).AddSeconds(30); + else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddMinutes(1).AddSeconds(30); } else endTimeBySystem = timePicker_startTime.Value.AddMinutes(1).AddSeconds(30); } diff --git a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs index 963b90b..a5e9368 100644 --- a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs +++ b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs @@ -29,7 +29,7 @@ + ";password=" + databasePassword + ";Charset=utf8" + ";Allow User Variables=True" - + ";Pooling=true"; + + ";Pooling=True"; mySqlConnect = new MySqlConnection(sConnection); mySqlConnect.Open(); iRetval = 0; diff --git a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs index c69559f..f19bd95 100644 --- a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs +++ b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs @@ -38,6 +38,7 @@ private string stability10; private string stability20; private string stability100; + private string isDetecting; public long Id { get @@ -161,5 +162,6 @@ public string Stability20 { get => stability20; set => stability20 = value; } public string Stability100 { get => stability100; set => stability100 = value; } public string Stability1 { get => stability1; set => stability1 = value; } + public string IsDetecting { get => isDetecting; set => isDetecting = value; } } } \ No newline at end of file diff --git a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs index 399098b..781749c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs @@ -9,7 +9,7 @@ { interface DetectionService { - int add(long deviceId, string frequency, string detecItemType, long detectionItemId); + int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time); List search(long deviceId, string detectionType, string startTime, string endTime, long detectionItemId); diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs index 0fd7b24..4df249b 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs @@ -132,7 +132,30 @@ string sQry = "SELECT * FROM r_counter_check_params"; 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) + // { + // if (row[0] != DBNull.Value) counterCheckParam.Id = Convert.ToInt32(row[0]); + // if (row[1] != DBNull.Value) counterCheckParam.SoOutDelay = row[1].ToString(); + // if (row[2] != DBNull.Value) counterCheckParam.SoEleFrequency = row[2].ToString(); + // if (row[3] != DBNull.Value) counterCheckParam.SoEleAddValue = row[3].ToString(); + // if (row[4] != DBNull.Value) counterCheckParam.SoEleAlarm = row[4].ToString(); + // if (row[5] != DBNull.Value) counterCheckParam.FreThreshold1 = row[5].ToString(); + // if (row[6] != DBNull.Value) counterCheckParam.FreThreshold2 = row[6].ToString(); + // if (row[7] != DBNull.Value) counterCheckParam.FreEleAddValue = row[7].ToString(); + // if (row[8] != DBNull.Value) counterCheckParam.CycThreshold1 = row[8].ToString(); + // if (row[9] != DBNull.Value) counterCheckParam.CycThreshold2 = row[9].ToString(); + // if (row[10] != DBNull.Value) counterCheckParam.CycEleAddValue = row[10].ToString(); + + // } + //} using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -149,10 +172,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(Exception ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs index 52b36f8..2c60ab4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs @@ -32,28 +32,29 @@ //先查询是否有历史数据 string sQry = "select ID from r_counter_data where DEVICE_ID=" + deviceId + " and OUT_VALUE = '" + outValue + "'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - - if (aReader.Read()) + bool isUpdated = false; + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - dataId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) + { + dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + + " where ID=" + dataId; + + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; + cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; + cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; + + cmd.ExecuteNonQuery(); + isUpdated = true; + } aReader.Close(); - sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + - " where ID="+ dataId; - - cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; - cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; - cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; - cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; - - cmd.ExecuteNonQuery(); - } - else - { - aReader.Close(); - + if (!isUpdated) + { sQry = "INSERT INTO r_counter_data (DEVICE_ID, OUT_VALUE, VALUE, SENSITIVITY, LOG_TIME, DETEC_TYPE)" + "values(@DEVICE_ID,@OUT_VALUE,@VALUE,@SENSITIVITY,@LOG_TIME,@DETEC_TYPE)"; @@ -70,14 +71,14 @@ sQry = "SELECT max(ID) from r_counter_data"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - - aReader = cmd.ExecuteReader(); - - if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); - + using (MySqlDataReader aReader = cmd.ExecuteReader()) + { + + if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + } } - aReader.Close(); cmd.Dispose(); iRetval = 0; @@ -144,6 +145,8 @@ cmd.ExecuteNonQuery(); } + + aReader.Close(); } @@ -282,9 +285,10 @@ if (!aReader.IsDBNull(6)) counterData.DetecType = aReader.GetString(6); counterDataList.Add(counterData); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs index 6795325..7500bd4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs @@ -47,10 +47,11 @@ counterDetecInitList.Add(counterDetecInit); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -75,29 +76,31 @@ return iRetval; } } - string sQry = "select ID from r_counter_detec_init where FREQUENCY=" + frequency +" AND CYCLE="+cycle; + string sQry = "select ID from r_counter_detec_init where FREQUENCY='" + frequency +"' AND CYCLE='"+cycle+"'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - if (aReader.Read()) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - initId = Convert.ToInt64(aReader.GetString(0)); - sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; + if (aReader.Read()) + { + initId = Convert.ToInt64(aReader.GetString(0)); + sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; - 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(); - } - else - { - 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 = 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(); + } + else + { + 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.ExecuteNonQuery(); + + } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); iRetval = 0; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs index 97b06ba..abcbaa6 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs @@ -72,26 +72,27 @@ MySqlCommand cmd = new MySqlCommand(sql, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(CommandBehavior.Default); - - if (aReader != null) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) + if (aReader != null) { - //判断门的状态 - if (!aReader.IsDBNull(0)) - counterParam.Id = Convert.ToInt32(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) - counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) - counterParam.BaudRate = aReader.GetString(2); - if (!aReader.IsDBNull(3)) - counterParam.GeneratorIp = aReader.GetString(3); - if (!aReader.IsDBNull(4)) - counterParam.SignalSourceIp = aReader.GetString(4); + if (aReader.Read()) + { + //判断门的状态 + if (!aReader.IsDBNull(0)) + counterParam.Id = Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(1)) + counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); + if (!aReader.IsDBNull(2)) + counterParam.BaudRate = aReader.GetString(2); + if (!aReader.IsDBNull(3)) + counterParam.GeneratorIp = aReader.GetString(3); + if (!aReader.IsDBNull(4)) + counterParam.SignalSourceIp = aReader.GetString(4); + } } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs index cca90fb..1578937 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs @@ -33,8 +33,8 @@ MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@DEVICE_ID", MySqlDbType.Int64, 20).Value = deviceId; - cmd.Parameters.Add("@START_TIME", MySqlDbType.String, 50).Value = startTime; - cmd.Parameters.Add("@END_TIME", MySqlDbType.String, 50).Value = endTime; + cmd.Parameters.Add("@START_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(startTime); + cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(endTime); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 50).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 50).Value = accuracy; cmd.Parameters.Add("@BOOT_FEATURE", MySqlDbType.String, 50).Value = bootFeature; @@ -58,11 +58,11 @@ sQry = "SELECT max(ID) from r_detection_item"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = cmd.ExecuteReader()) { if (aReader.Read()) detectionId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); iRetval = 0; @@ -203,8 +203,9 @@ if (!stability100.Equals("")) sQry = sQry + " STABILITY_100=@STABILITY_100,"; sQry = sQry + " COUNTER_DETEC=@COUNTER_DETEC where ID = " + detectionId; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry: " + sQry); - + MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 10).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 10).Value = accuracy; @@ -283,7 +284,8 @@ return iRetval; } } - + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "停止检测 detectionItemId=======" + detectionItemId); + string sQry = "UPDATE r_device SET STATUSID="+"1"+", CHANNEL=@CHANNEL where ID=" + deviceId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@CHANNEL", MySqlDbType.String, 20).Value = ""; @@ -292,19 +294,21 @@ if (isDeleteData) { - sQry = "DELETE FROM r_detection_item WHERE DEVICE_ID = " + deviceId + " AND START_TIME='" + startTime + "' AND END_TIME='" + endTime + "'"; + sQry = "DELETE FROM r_detection_item WHERE ID=" + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); - sQry = "DELETE FROM r_detection WHERE DEVICE_ID = " + deviceId + " AND (LOG_TIME between'" + startTime + "' and '" + endTime + "')"; + sQry = "DELETE FROM r_detection WHERE DETECTION_ITEM_ID = " + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); } else { - sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME WHERE ID="+ detectionItemId; + sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME, IS_DETECTING=@IS_DETECTING WHERE ID=" + detectionItemId; + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 20).Value = DateTime.Now; + cmd.Parameters.Add("@IS_DETECTING", MySqlDbType.String, 1).Value = "0"; //0-否,1-是 cmd.ExecuteNonQuery(); } @@ -322,8 +326,7 @@ { DetectionItem detectionItem = null; try - { - + { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getById : 数据库链接断开"); @@ -337,6 +340,7 @@ string sQry = "select * from r_detection_item WHERE ID = "+ detectionItemId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + using (MySqlDataReader aReader = cmd.ExecuteReader()) { while (aReader.Read()) @@ -356,11 +360,13 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(15)) detectionItem.IsDetecting = aReader.GetString(15); } - } - + aReader.Close(); + } cmd.Dispose(); + } catch (MySqlException e) { @@ -400,7 +406,7 @@ { DetectionItem detectionItem = new DetectionItem(); //姓名 - if (!aReader.IsDBNull(0)) detectionItem.Id=Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(0)) detectionItem.Id = Convert.ToInt32(aReader.GetString(0)); if (!aReader.IsDBNull(1)) detectionItem.DeviceId = Convert.ToInt64(aReader.GetString(1)); if (!aReader.IsDBNull(2)) detectionItem.StartTime = aReader.GetString(2); if (!aReader.IsDBNull(3)) detectionItem.EndTime = aReader.GetString(3); @@ -416,9 +422,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -468,9 +475,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -498,7 +506,6 @@ string sQry = "SELECT * FROM r_detection_item where ID = " + detectionId; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -518,15 +525,43 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); + //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) + // { + // detectionItem = new DetectionItem(); + // if (row[0] != DBNull.Value) detectionItem.Id = Convert.ToInt64(row[0]); + // if (row[1] != DBNull.Value) detectionItem.DeviceId = Convert.ToInt64(row[1]); + // if (row[2] != DBNull.Value) detectionItem.StartTime = Convert.ToDateTime(row[2]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[3] != DBNull.Value) detectionItem.EndTime = Convert.ToDateTime(row[3]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[4] != DBNull.Value) detectionItem.Stability = row[4].ToString(); + // if (row[5] != DBNull.Value) detectionItem.Accuracy = row[5].ToString(); + // if (row[6] != DBNull.Value) detectionItem.BootFeature = row[6].ToString(); + // if (row[7] != DBNull.Value) detectionItem.AgeRate = row[7].ToString(); + // if (row[8] != DBNull.Value) detectionItem.Interval = row[8].ToString(); + // if (row[10] != DBNull.Value) detectionItem.Channel = row[10].ToString(); + // if (row[11] != DBNull.Value) detectionItem.Stability1 = row[11].ToString(); + // if (row[12] != DBNull.Value) detectionItem.Stability10 = row[12].ToString(); + // if (row[13] != DBNull.Value) detectionItem.Stability20 = row[13].ToString(); + // if (row[14] != DBNull.Value) detectionItem.Stability100 = row[14].ToString(); + + // } + //} } catch (MySqlException ex) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDetectionItem: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchById: " + ex.Message); } return detectionItem; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs index e2a5893..5b3deb0 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs @@ -14,7 +14,7 @@ { class DetectionServiceImpl : DetectionService { - public int add(long deviceId, string frequency, string detecItemType, long detectionItemId) + public int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time) { int iRetval = -1; try @@ -36,7 +36,7 @@ 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 = DateTime.Now; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.DateTime, 0).Value = time; cmd.Parameters.Add("@DETECTION_ITEM", MySqlDbType.String, 0).Value = detecItemType; cmd.Parameters.Add("@DETECTION_ITEM_ID", MySqlDbType.Int64, 0).Value = detectionItemId; @@ -108,24 +108,26 @@ string sQry = "SELECT * FROM r_detection where DEVICE_ID = " + deviceId +" and DETECTION_ITEM='" + detectionType + "' and (LOG_TIME BETWEEN '" + startTime + "' and '"+ endTime + "') and DETECTION_ITEM_ID="+detectionItemId+" order by LOG_TIME"; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) { - Model.Detection detection = new Model.Detection(); - //姓名 - if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) detection.LogTime = Convert.ToDateTime(aReader.GetString(2)).ToString("yyyy-MM-dd HH:mm:ss"); - if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); - if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); + Detection detection = new Detection(); + + if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); // id + if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); // devName + if (!aReader.IsDBNull(2)) detection.LogTime = aReader.GetString(2); // devCode + if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); // devType + if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); // devModel detectionDtoList.Add(detection); } + aReader.Close(); + - aCommand.Dispose(); } + aCommand.Dispose(); + } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs index 9413e2f..b224bc1 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs @@ -53,7 +53,8 @@ using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); @@ -87,8 +88,7 @@ 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; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry : "+ sQry + "; statusId="+ statusId); - + 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; @@ -183,7 +183,7 @@ } MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -208,10 +208,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -254,7 +255,30 @@ 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()) @@ -279,10 +303,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -342,7 +367,30 @@ 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()) @@ -372,10 +420,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -442,9 +491,10 @@ { totalCount = aReader.GetInt32(0); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -477,89 +527,45 @@ return null; } } - - string sQry = "SELECT * FROM r_deviceview where ACTIVE = 0 and STATUSID = 2 " + "and ('" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' <= END_TIME)"; - - 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) + //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))"; + MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { - foreach (DataRow row in dt.Rows) + while (aReader.Read()) { DeviceView deviceView = new DeviceView(); - if (row[0] != DBNull.Value) deviceView.Id = Convert.ToInt64(row[0]); - if (row[1] != DBNull.Value) deviceView.DevName = row[1].ToString(); - if (row[2] != DBNull.Value) deviceView.DevCode = row[2].ToString(); - if (row[3] != DBNull.Value) deviceView.DevTypeId = row[3].ToString(); - if (row[4] != DBNull.Value) deviceView.DevModel = row[4].ToString(); - if (row[5] != DBNull.Value) deviceView.RegTime = row[5].ToString(); - if (row[6] != DBNull.Value) deviceView.CustomerName = row[6].ToString(); - if (row[7] != DBNull.Value) deviceView.CustomerDev = row[7].ToString(); - if (row[8] != DBNull.Value) deviceView.Channel = row[8].ToString(); - if (row[9] != DBNull.Value) deviceView.Active = Convert.ToInt32(row[9]); - if (row[10] != DBNull.Value) deviceView.StartTime = Convert.ToDateTime(row[10]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[11] != DBNull.Value) deviceView.EndTime = Convert.ToDateTime(row[11]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[12] != DBNull.Value) deviceView.StatusId = row[12].ToString(); - if (row[13] != DBNull.Value) deviceView.Stability = row[13].ToString(); - if (row[14] != DBNull.Value) deviceView.Accuracy = row[14].ToString(); - if (row[15] != DBNull.Value) deviceView.BootFeature = row[15].ToString(); - if (row[16] != DBNull.Value) deviceView.AgeRate = row[16].ToString(); - if (row[17] != DBNull.Value) deviceView.DetectionItemId = Convert.ToInt64(row[17]); + 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(); + + } - //using (MySqlDataReader aReader = aCommand.ExecuteReader()) - //{ - // while (aReader.Read()) - // { - // DeviceView deviceView = new DeviceView(); + aCommand.Dispose(); - // 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 - // //deviceView.DevTypeName = dictService.getNameByCode("devType", aReader.GetString(3)); - // } - // if (!aReader.IsDBNull(4)) deviceView.DevModel = aReader.GetString(4); // devModel - // if (!aReader.IsDBNull(5)) - // { - // DateTime reg = aReader.GetDateTime(5); // regTime - // deviceView.RegTime = reg.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); - // if (!aReader.IsDBNull(9)) deviceView.Active = Convert.ToInt32(aReader.GetString(9)); - // if (!aReader.IsDBNull(10)) - // { - // DateTime reg = aReader.GetDateTime(10); // regTime - // deviceView.StartTime = reg.ToString("yyyy-MM-dd HH:mm:ss"); - // } - // if (!aReader.IsDBNull(11)) - // { - // DateTime reg = aReader.GetDateTime(11); // regTime - // deviceView.EndTime = reg.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 = Convert.ToInt64(aReader.GetString(17)); - - // deviceViewList.Add(deviceView); - - // aCommand.Dispose(); - // } - //} - if (deviceViewList.Count > 0) { foreach (DeviceView deviceView in deviceViewList) @@ -568,9 +574,15 @@ } } } + + 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()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getDeviceByChannel: " + ex.Message + " ; " + ex.ToString()); deviceViewList = null; } finally diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs index 1626aa5..42ca83c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs @@ -92,10 +92,11 @@ if (!aReader.IsDBNull(3)) dict.Code = aReader.GetString(3); nameList.Add(dict); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(MySqlException ex) { @@ -139,10 +140,11 @@ if (!aReader.IsDBNull(3)) counterParam.GeneratorIp = aReader.GetString(3); if (!aReader.IsDBNull(4)) counterParam.SignalSourceIp = aReader.GetString(4); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -220,10 +222,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/RbFreqStdMeas.cs b/RbFreqStandMeasure/RbFreqStdMeas.cs index beae3dc..8d74572 100644 --- a/RbFreqStandMeasure/RbFreqStdMeas.cs +++ b/RbFreqStandMeasure/RbFreqStdMeas.cs @@ -363,24 +363,7 @@ detectionItemService.stopDetection(deviceId, device.DetectionItemId, startTime, endTime, true); } } - deviceService.clearChannel(); - List detectionItemList = detectionItemService.getAll(); - if (detectionItemList != null && detectionItemList.Count > 0) - { - foreach (DetectionItem detectionItem in detectionItemList) - { - long detectionItemId = detectionItem.Id; - if (detectionItem.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem.Stability1.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "0", "", "", ""); - if (detectionItem.Stability10.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "0", "", ""); - if (detectionItem.Stability20.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "0", ""); - if (detectionItem.Stability100.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "", "0"); - if (detectionItem.Accuracy.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "0", "", "", "", "", "", "", ""); - if (detectionItem.BootFeature.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "0", "", "", "", "", "", ""); - if (detectionItem.AgeRate.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "0", "", "", "", "", ""); - } - } - + deviceService.clearChannel(); } else { @@ -590,7 +573,7 @@ break; case 3: // 频率计数器范围 - CounterCtrlForm counterForm = CounterCtrlForm.GetInstance(); + CounterCtrlForm counterForm = new CounterCtrlForm(); counterForm.Show(); panelMain.Controls.Add(counterForm); break; diff --git a/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe b/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe index 70dc261..11271b0 100644 --- a/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe +++ b/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe Binary files differ diff --git a/RbFreqStandMeasure/counter/CounterCtrlForm.cs b/RbFreqStandMeasure/counter/CounterCtrlForm.cs index 951a19c..e45f17b 100644 --- a/RbFreqStandMeasure/counter/CounterCtrlForm.cs +++ b/RbFreqStandMeasure/counter/CounterCtrlForm.cs @@ -39,6 +39,9 @@ GPIBService tcpService = new TCPServiceImpl(); string valueOld = ""; + string valueOldBack = ""; + string valueOldSensi = ""; + string valueOldTime = ""; #region 样式常量定影 private readonly Color titleBackColor = Color.FromArgb(63, 132, 215); // #3F64D7 @@ -55,8 +58,8 @@ return _counterCtrlForm; } - - private CounterCtrlForm() + + public CounterCtrlForm() { InitializeComponent(); @@ -69,7 +72,7 @@ comboBox_detecModel.SelectedIndex = 0; InitTableCounter(); - LoadCounterDetecInitList(); + //LoadCounterDetecInitList(); if (list != null && list.Count > 0) { @@ -221,12 +224,12 @@ table_counterDetecInit.Columns.Add("initId", Type.GetType("System.Int32")); table_counterDetecInit.Columns.Add("counterDataId", Type.GetType("System.Int64")); - if (comboBox_counters.Text != "") + if (((DeviceDto)comboBox_counters.SelectedItem).DevName != "") { - List list = deviceService.search(comboBox_counters.Text, "", "", "", "", ""); + List list = deviceService.search(((DeviceDto)comboBox_counters.SelectedItem).DevName, "", "", "", "", ""); if (null != list && list.Count > 0) { - devType = list[0].DevTypeName; + devType = list[0].DevModel; devCode = list[0].DevCode; } @@ -344,6 +347,18 @@ { valueOld = dataGridView_CounterResult.CurrentCell.Value.ToString(); } + else if (e.ColumnIndex == 5) + { + valueOldBack = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } + else if (e.ColumnIndex == 6) + { + valueOldSensi = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } + else if (e.ColumnIndex == 7) + { + valueOldTime = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } } @@ -522,7 +537,10 @@ dataGridView_CounterResult.ReadOnly = true; btn_add.Enabled = false; benDelete.Enabled = false; - ///btn_dropDetecModel.Enabled = false; + comboBox_counters.Enabled = false; + comboBox_detecModel.Enabled = false; + text_counterIp.ReadOnly = true; + text_signal.ReadOnly = true; string[] arr = text_counterIp.Text.Split('.'); if (arr.Length != 4) @@ -643,11 +661,11 @@ Invoke(new MethodInvoker(delegate () { SetDevTestDlg.inDetecCounterId = -1; - //text_devName.ReadOnly = false; - //btn_downCounterList.Enabled = true; btnStart.Enabled = true; - //btn_dropDetecModel.Enabled = true; - //textBox_detecModel.ReadOnly = false; + comboBox_counters.Enabled = true; + comboBox_detecModel.Enabled = true; + text_counterIp.ReadOnly = false; + text_signal.ReadOnly = false; })); dataGridView_CounterResult.ReadOnly = false; @@ -736,6 +754,8 @@ if (!checkFreq(value)) { MessageBox.Show("请输入格式正确的测量频率值!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldBack; + valueOldBack = ""; return; } } @@ -744,6 +764,8 @@ if (!checkCyc(value)) { MessageBox.Show("请输入格式正确的测量周期值!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldBack; + valueOldBack = ""; return; } } @@ -753,11 +775,21 @@ { if (!String.IsNullOrEmpty(value)) { + if (value.Contains(".") && ((value.IndexOf('.') != value.LastIndexOf('.')) || value.IndexOf('.') == 0 || value.LastIndexOf('.') == value.Length)) + { + MessageBox.Show("请输入格式正确的灵敏度!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldSensi; + valueOldSensi = ""; + return; + } + string pattern = @"^[0-9.]+$"; Regex regex = new Regex(pattern); if (!regex.IsMatch(value)) { MessageBox.Show("请输入格式正确的灵敏度!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldSensi; + valueOldSensi = ""; return; } } @@ -772,7 +804,8 @@ } catch { - dataGridView_CounterResult.Rows[e.RowIndex].Cells[7].Value = ""; + dataGridView_CounterResult.CurrentCell.Value = valueOldTime; + valueOldTime = ""; MessageBox.Show("请输入格式正确的时间!"); return; } diff --git a/RbFreqStandMeasure/home/HomeCtrlForm.cs b/RbFreqStandMeasure/home/HomeCtrlForm.cs index b2568f7..586334d 100644 --- a/RbFreqStandMeasure/home/HomeCtrlForm.cs +++ b/RbFreqStandMeasure/home/HomeCtrlForm.cs @@ -7,6 +7,7 @@ using Casic.Birmm.RbFreqStandMeasure.Tools; using DevComponents.DotNetBar.Controls; using System; +using System.Collections; using System.Collections.Generic; using System.Data; using System.Drawing; @@ -23,16 +24,16 @@ public partial class HomeCtrlForm : UserControl { public static HomeCtrlForm homeCtrlForm; - int totalCount = 0; - int currentPage = 1; - int pageCount = 0; - int limitCount = 4; + public int totalCount = 0; + public int currentPage = 1; + public int pageCount = 0; + public int limitCount = 4; DataTable devToBeTestedTable = null; DataTable channelsTable = null; DeviceService deviceService = new DeviceServiceImpl(); List listChannelStatus = new List(); DetectionItemService detectionItemService = new DetectionItemServiceImpl(); - + public static Hashtable stoppedItemIdTable = new Hashtable(); public static List channelFreeList = new List(); private readonly object obj = new object(); @@ -166,10 +167,7 @@ Size = new Size(120, 32) }; tableToBeTested.Controls.Add(colCustomComp); - colCustomComp.BringToFront(); - - - + colCustomComp.BringToFront(); totalCount = 0; currentPage = 1; @@ -332,7 +330,7 @@ AutoSize = false, Text = "通道", Location = new Point(0, 0), - Size = new Size(50, 30) + Size = new Size(70, 30) }; dataGridView_Channel.Controls.Add(colChannelNo); colChannelNo.BringToFront(); @@ -346,7 +344,7 @@ BackColor = titleBackColor, AutoSize = false, Text = "仪器名称", - Location = new Point(50, 0), + Location = new Point(70, 0), Size = new Size(110, 30) }; dataGridView_Channel.Controls.Add(colDevName); @@ -361,8 +359,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "仪器编号", - Location = new Point(160, 0), - Size = new Size(110, 30) + Location = new Point(180, 0), + Size = new Size(120, 30) }; dataGridView_Channel.Controls.Add(colDevNo); colDevNo.BringToFront(); @@ -376,8 +374,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "送检单位", - Location = new Point(270, 0), - Size = new Size(110, 30) + Location = new Point(300, 0), + Size = new Size(120, 30) }; dataGridView_Channel.Controls.Add(colCustomName); colCustomName.BringToFront(); @@ -391,8 +389,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "开始时间", - Location = new Point(380, 0), - Size = new Size(120, 30) + Location = new Point(420, 0), + Size = new Size(100, 30) }; dataGridView_Channel.Controls.Add(colStartTime); colStartTime.BringToFront(); @@ -406,8 +404,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "结束时间", - Location = new Point(500, 0), - Size = new Size(120, 30) + Location = new Point(520, 0), + Size = new Size(100, 30) }; dataGridView_Channel.Controls.Add(colEndTime); colEndTime.BringToFront(); @@ -492,6 +490,11 @@ dataGridView_Channel.Controls.Add(colAgingRate); colAgingRate.BringToFront(); } + + + + + } catch (Exception ex) { @@ -506,19 +509,22 @@ { lock (obj) { - channelFreeList.Clear(); - channelFreeList.Add("1"); - channelFreeList.Add("2"); - channelFreeList.Add("3"); - channelFreeList.Add("4"); - channelFreeList.Add("5"); - - listChannelStatus = deviceService.getDeviceByChannel(); - if (listChannelStatus != null && listChannelStatus.Count > 0) + // lock (channelFreeList) { - foreach (DeviceView device in listChannelStatus) + channelFreeList.Clear(); + channelFreeList.Add("1"); + channelFreeList.Add("2"); + channelFreeList.Add("3"); + channelFreeList.Add("4"); + channelFreeList.Add("5"); + + listChannelStatus = deviceService.getDeviceByChannel(); + if (listChannelStatus != null && listChannelStatus.Count > 0) { - channelFreeList.Remove(device.Channel); + foreach (DeviceView device in listChannelStatus) + { + channelFreeList.Remove(device.Channel); + } } } } @@ -533,125 +539,131 @@ { try { - lock (obj) + //Invoke(new MethodInvoker(delegate () { - channelsTable = new DataTable(); - - channelsTable.Columns.Add("channelNo", Type.GetType("System.String")); - channelsTable.Columns.Add("devName", Type.GetType("System.String")); - channelsTable.Columns.Add("devCode", Type.GetType("System.String")); - channelsTable.Columns.Add("customComp", Type.GetType("System.String")); - channelsTable.Columns.Add("startTime", Type.GetType("System.String")); - channelsTable.Columns.Add("endTime", Type.GetType("System.String")); - channelsTable.Columns.Add("channelStatus", Type.GetType("System.String")); - channelsTable.Columns.Add("stablility", Type.GetType("System.String")); - channelsTable.Columns.Add("accuracy", Type.GetType("System.String")); - channelsTable.Columns.Add("startup", Type.GetType("System.String")); - channelsTable.Columns.Add("agingRate", Type.GetType("System.String")); - channelsTable.Columns.Add("deviceId", Type.GetType("System.Int64")); - channelsTable.Columns.Add("deviceItemId", Type.GetType("System.Int64")); - //channelsTable.Columns.Add("devType", Type.GetType("System.String")); - //channelsTable.Columns.Add("devModel", Type.GetType("System.String")); - //channelsTable.Columns.Add("customCom", Type.GetType("System.String")); - - listChannelStatus = deviceService.getDeviceByChannel(); - - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelFreeList.Clear(); - channelFreeList.Add("1"); - channelFreeList.Add("2"); - channelFreeList.Add("3"); - channelFreeList.Add("4"); - channelFreeList.Add("5"); - - if (listChannelStatus != null && listChannelStatus.Count > 0) + lock (obj) { - foreach (DeviceView device in listChannelStatus) + //lock(channelFreeList) { - channelFreeList.Remove(device.Channel); - int index = Convert.ToInt32(device.Channel) - 1; - channelsTable.Rows[index]["channelNo"] = device.Channel; - channelsTable.Rows[index]["devName"] = device.DevName; - channelsTable.Rows[index]["devCode"] = device.DevCode; - channelsTable.Rows[index]["customComp"] = device.CustomerDev; - channelsTable.Rows[index]["startTime"] = device.StartTime; - channelsTable.Rows[index]["endTime"] = device.EndTime; - channelsTable.Rows[index]["channelStatus"] = "占用"; - channelsTable.Rows[index]["deviceId"] = device.Id; - channelsTable.Rows[index]["deviceItemId"] = device.DetectionItemId; + channelsTable = new DataTable(); - if (device.Stability.Equals("-3")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.Stability.Equals("-2")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.Stability.Equals("-1")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + channelsTable.Columns.Add("channelNo", Type.GetType("System.String")); + channelsTable.Columns.Add("devName", Type.GetType("System.String")); + channelsTable.Columns.Add("devCode", Type.GetType("System.String")); + channelsTable.Columns.Add("customComp", Type.GetType("System.String")); + channelsTable.Columns.Add("startTime", Type.GetType("System.String")); + channelsTable.Columns.Add("endTime", Type.GetType("System.String")); + channelsTable.Columns.Add("channelStatus", Type.GetType("System.String")); + channelsTable.Columns.Add("stablility", Type.GetType("System.String")); + channelsTable.Columns.Add("accuracy", Type.GetType("System.String")); + channelsTable.Columns.Add("startup", Type.GetType("System.String")); + channelsTable.Columns.Add("agingRate", Type.GetType("System.String")); + channelsTable.Columns.Add("deviceId", Type.GetType("System.Int64")); + channelsTable.Columns.Add("deviceItemId", Type.GetType("System.Int64")); - if (device.Accuracy.Equals("-3")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.Accuracy.Equals("-2")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.Accuracy.Equals("-1")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; - - if (device.AgeRate.Equals("-3")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.AgeRate.Equals("-2")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.AgeRate.Equals("-1")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; - - if (device.BootFeature.Equals("-3")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.BootFeature.Equals("-2")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.BootFeature.Equals("-1")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + listChannelStatus = deviceService.getDeviceByChannel(); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelFreeList.Clear(); + channelFreeList.Add("1"); + channelFreeList.Add("2"); + channelFreeList.Add("3"); + channelFreeList.Add("4"); + channelFreeList.Add("5"); + + if (listChannelStatus != null && listChannelStatus.Count > 0) + { + foreach (DeviceView device in listChannelStatus) + { + if (String.IsNullOrEmpty(device.Channel)) continue; + channelFreeList.Remove(device.Channel); + int index = Convert.ToInt32(device.Channel) - 1; + channelsTable.Rows[index]["channelNo"] = device.Channel; + channelsTable.Rows[index]["devName"] = device.DevName; + channelsTable.Rows[index]["devCode"] = device.DevCode; + channelsTable.Rows[index]["customComp"] = device.CustomerDev; + channelsTable.Rows[index]["startTime"] = device.StartTime; + channelsTable.Rows[index]["endTime"] = device.EndTime; + channelsTable.Rows[index]["channelStatus"] = "占用"; + channelsTable.Rows[index]["deviceId"] = device.Id; + channelsTable.Rows[index]["deviceItemId"] = device.DetectionItemId; + + if (device.Stability.Equals("-3")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.Stability.Equals("-2")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.Stability.Equals("-1")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + if (device.Accuracy.Equals("-3")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.Accuracy.Equals("-2")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.Accuracy.Equals("-1")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + if (device.AgeRate.Equals("-3")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.AgeRate.Equals("-2")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.AgeRate.Equals("-1")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + if (device.BootFeature.Equals("-3")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.BootFeature.Equals("-2")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.BootFeature.Equals("-1")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + + } + } + else + { + channelsTable.Rows.Clear(); + channelsTable.Rows.Add("1", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("2", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("3", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("4", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("5", "", "", "", "", "", "空闲", "", ""); + } + + foreach (string no in channelFreeList) + { + channelsTable.Rows[Convert.ToInt32(no) - 1]["channelNo"] = no; + channelsTable.Rows[Convert.ToInt32(no) - 1]["channelStatus"] = "空闲"; + } + + + dataGridView_Channel.DataSource = channelsTable; + + // width=764px + dataGridView_Channel.Columns[11].Visible = false; + dataGridView_Channel.Columns[12].Visible = false; + dataGridView_Channel.Columns[0].Width = 70; + dataGridView_Channel.Columns[1].Width = 110; + dataGridView_Channel.Columns[2].Width = 120; + dataGridView_Channel.Columns[3].Width = 120; + dataGridView_Channel.Columns[4].Width = 100; //starttime + dataGridView_Channel.Columns[5].Width = 100; //endtime + dataGridView_Channel.Columns[6].Width = 64; + dataGridView_Channel.Columns[7].Width = 75; + dataGridView_Channel.Columns[8].Width = 75; + dataGridView_Channel.Columns[9].Width = 75; + dataGridView_Channel.Columns[10].Width = 75; + + dataGridView_Channel.Columns[0].ReadOnly = true; + dataGridView_Channel.Columns[1].ReadOnly = true; + dataGridView_Channel.Columns[2].ReadOnly = true; + dataGridView_Channel.Columns[3].ReadOnly = true; + dataGridView_Channel.Columns[4].ReadOnly = true; + dataGridView_Channel.Columns[5].ReadOnly = true; + dataGridView_Channel.Columns[6].ReadOnly = true; + dataGridView_Channel.Columns[7].ReadOnly = true; + dataGridView_Channel.Columns[8].ReadOnly = true; + dataGridView_Channel.Columns[9].ReadOnly = true; + dataGridView_Channel.Columns[10].ReadOnly = true; } } - else - { - channelsTable.Rows.Clear(); - channelsTable.Rows.Add("1", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("2", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("3", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("4", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("5", "", "", "", "", "", "空闲", "", ""); - } - - foreach (string no in channelFreeList) - { - channelsTable.Rows[Convert.ToInt32(no) - 1]["channelNo"] = no; - channelsTable.Rows[Convert.ToInt32(no) - 1]["channelStatus"] = "空闲"; - } - - - dataGridView_Channel.DataSource = channelsTable; - - // width=764px - dataGridView_Channel.Columns[11].Visible = false; - dataGridView_Channel.Columns[12].Visible = false; - dataGridView_Channel.Columns[0].Width = 50; - dataGridView_Channel.Columns[1].Width = 110; - dataGridView_Channel.Columns[2].Width = 110; - dataGridView_Channel.Columns[3].Width = 110; - dataGridView_Channel.Columns[4].Width = 120; - dataGridView_Channel.Columns[5].Width = 120; - dataGridView_Channel.Columns[6].Width = 64; - dataGridView_Channel.Columns[7].Width = 75; - dataGridView_Channel.Columns[8].Width = 75; - dataGridView_Channel.Columns[9].Width = 75; - dataGridView_Channel.Columns[10].Width = 75; - - dataGridView_Channel.Columns[0].ReadOnly = true; - dataGridView_Channel.Columns[1].ReadOnly = true; - dataGridView_Channel.Columns[2].ReadOnly = true; - dataGridView_Channel.Columns[3].ReadOnly = true; - dataGridView_Channel.Columns[4].ReadOnly = true; - dataGridView_Channel.Columns[5].ReadOnly = true; - dataGridView_Channel.Columns[6].ReadOnly = true; - dataGridView_Channel.Columns[7].ReadOnly = true; - dataGridView_Channel.Columns[8].ReadOnly = true; - dataGridView_Channel.Columns[9].ReadOnly = true; - dataGridView_Channel.Columns[10].ReadOnly = true; + //})); } } catch (Exception ex) @@ -760,7 +772,6 @@ private void cellDoubleClick(int rowIndex) { - int colIndex = dataGridView_Channel.CurrentCell.ColumnIndex; if (dataGridView_Channel.Rows[rowIndex].Cells[6].Value.ToString().Equals("占用")) { if (MessageBox.Show("该通道有正在检测的仪器,确定要停止检测?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) @@ -780,30 +791,22 @@ { return; } + DialogResult dialogResult = MessageBox.Show("是否保存此次检测的数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { - detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, false); + detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, false); } else { detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, true); } - DetectionItem detectionItem0 = detectionItemService.getById(deviceItemId); - if (detectionItem0 != null) - { - if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem0.Stability1.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "0", "", "", ""); - if (detectionItem0.Stability10.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "", "0", "", ""); - if (detectionItem0.Stability20.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "", "", "0", ""); - if (detectionItem0.Stability100.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "", "", "", "0"); - if (detectionItem0.Accuracy.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "0", "", "", "", "", "", "", ""); - if (detectionItem0.BootFeature.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "0", "", "", "", "", "", ""); - if (detectionItem0.AgeRate.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "0", "", "", "", "", ""); - - } + if (stoppedItemIdTable.Contains(rowIndex + 1)) stoppedItemIdTable.Remove(rowIndex + 1); + + stoppedItemIdTable.Add(rowIndex + 1, deviceItemId); LoadChannelStatus(); + currentPage = 1; LoadDevToBeTested(); } catch(Exception ex) diff --git a/RbFreqStandMeasure/home/SetDevChannelDlg.cs b/RbFreqStandMeasure/home/SetDevChannelDlg.cs index fe3bcdd..a1d96fe 100644 --- a/RbFreqStandMeasure/home/SetDevChannelDlg.cs +++ b/RbFreqStandMeasure/home/SetDevChannelDlg.cs @@ -84,9 +84,12 @@ timePicker_startTime.MinDate = DateTime.Now; getEndTime(); List listToTest = deviceService.search("", "", "", "", "", "1"); - foreach (DeviceDto deviceDto in listToTest) + if (listToTest != null && listToTest.Count > 0) { - cbBox_toTestDevList.Items.Add(deviceDto.DevCode); + foreach (DeviceDto deviceDto in listToTest) + { + cbBox_toTestDevList.Items.Add(deviceDto.DevCode); + } } text_customerDev.Visible = true; @@ -202,7 +205,7 @@ if (checkBox10s.Checked) stability10 = "-1"; if (checkBox20s.Checked) stability20 = "-1"; if (checkBox_100s.Checked) stability100 = "-1"; - detectionHelper.detecStability(deviceId, startTime, interval, port, true ,false); + detectionHelper.detecStability(deviceId, startTime, interval, port, true, false); } else { @@ -257,8 +260,10 @@ } long detectionId0 = detectionItemService.add(deviceId, startTime, endTime, stability, accuracy, bootFeature, ageRate, interval, textBox_channelNo.Text,stability1,stability10,stability20,stability100); detectionHelper.detectionItemId = detectionId0; + this.HideMaskAction(); HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + HomeCtrlForm.homeCtrlForm.currentPage = 1; HomeCtrlForm.homeCtrlForm.LoadDevToBeTested(); } catch (Exception ex) @@ -311,18 +316,18 @@ private void getEndTime() { - if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddSeconds(30); + if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddMinutes(1).AddSeconds(30); else { - if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddSeconds(30); + if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddMinutes(1).AddSeconds(30); else { if (checkBox_stability.Checked) { - if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddSeconds(40); - else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddSeconds(40); - else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddSeconds(40); - else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddSeconds(40); + if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddMinutes(1).AddSeconds(30); + else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddMinutes(1).AddSeconds(30); + else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddMinutes(1).AddSeconds(30); + else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddMinutes(1).AddSeconds(30); } else endTimeBySystem = timePicker_startTime.Value.AddMinutes(1).AddSeconds(30); } diff --git a/RbFreqStandMeasure/home/SetDevTestDlg.cs b/RbFreqStandMeasure/home/SetDevTestDlg.cs index f1027ba..6e9d272 100644 --- a/RbFreqStandMeasure/home/SetDevTestDlg.cs +++ b/RbFreqStandMeasure/home/SetDevTestDlg.cs @@ -23,11 +23,7 @@ public static long inDetecCounterId = -1;// 正在检测灵敏度的计数器id DateTime endTimeBySystem = new DateTime(); - CounterDataService CounterDataService = new CounterDataServiceImpl(); - CounterDetecInitService counterDetecInitService = new CounterDetecInitServiceImpl(); DictService dictService = new DictServiceImpl(); - SensitivityService sensitivityService = new SensitivityServiceImpl(); - CounterDataService counterDataService = new CounterDataServiceImpl(); DeviceService deviceService = new DeviceServiceImpl(); @@ -221,6 +217,7 @@ this.HideMaskAction(); HomeCtrlForm.homeCtrlForm.refreshChannelList(); HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + HomeCtrlForm.homeCtrlForm.currentPage = 1; HomeCtrlForm.homeCtrlForm.LoadDevToBeTested(); } @@ -280,18 +277,18 @@ private void getEndTime() { - if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddSeconds(30); + if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddMinutes(1).AddSeconds(30); else { - if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddSeconds(30); + if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddMinutes(1).AddSeconds(30); else { if (checkBox_stability.Checked) { - if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddSeconds(40); - else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddSeconds(40); - else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddSeconds(40); - else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddSeconds(40); + if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddMinutes(1).AddSeconds(30); + else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddMinutes(1).AddSeconds(30); + else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddMinutes(1).AddSeconds(30); + else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddMinutes(1).AddSeconds(30); } else endTimeBySystem = timePicker_startTime.Value.AddMinutes(1).AddSeconds(30); } diff --git a/RbFreqStandMeasure/info/AddDevDlg.cs b/RbFreqStandMeasure/info/AddDevDlg.cs index 46d4778..6abc5b0 100644 --- a/RbFreqStandMeasure/info/AddDevDlg.cs +++ b/RbFreqStandMeasure/info/AddDevDlg.cs @@ -254,16 +254,13 @@ { if (needDetec) statusId = "2"; devService.update(deviceId, devName, devCode, devTypeCode, devModel, devCustomComp, devCustomName, channelNo,statusId); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "update 完成"); - + } //添加检测 if (deviceId != -1 && needDetec) - { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "各项检测开始。。。。"); - + { //开始检测 //稳定度 @@ -337,9 +334,7 @@ detectionHelper.detecAgeRate(deviceId, startTime, port, false); } } - - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "更新检测记录表" + deviceId); - + //开始检测 long detectionId0 = detectionItemService.add(deviceId, startTime, endTime, stability, accuracy, bootFeature, ageRate, interval, text_channelNo.Text, stability1, stability10, stability20, stability100); detectionHelper.detectionItemId = detectionId0; @@ -439,18 +434,18 @@ private void getEndTime() { - if (checkBox_ageRate.Checked) endTimeBySystem = picker_startTime.Value.AddDays(7).AddSeconds(30); + if (checkBox_ageRate.Checked) endTimeBySystem = picker_startTime.Value.AddDays(7).AddMinutes(1).AddSeconds(30); else { - if (checkBox_bootFeature.Checked) endTimeBySystem = picker_startTime.Value.AddHours(7).AddSeconds(30); + if (checkBox_bootFeature.Checked) endTimeBySystem = picker_startTime.Value.AddHours(7).AddMinutes(1).AddSeconds(30); else { if (checkBox_stability.Checked) { - if (checkBox100s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 100).AddSeconds(40); - else if (checkBox20s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 20).AddSeconds(40); - else if (checkBox10s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 10).AddSeconds(40); - else if (checkBox1s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101).AddSeconds(40); + if (checkBox100s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 100).AddMinutes(1).AddSeconds(30); + else if (checkBox20s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 20).AddMinutes(1).AddSeconds(30); + else if (checkBox10s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 10).AddMinutes(1).AddSeconds(30); + else if (checkBox1s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101).AddMinutes(1).AddSeconds(30); } else endTimeBySystem = picker_startTime.Value.AddMinutes(1).AddSeconds(30); } diff --git a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs index 963b90b..a5e9368 100644 --- a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs +++ b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs @@ -29,7 +29,7 @@ + ";password=" + databasePassword + ";Charset=utf8" + ";Allow User Variables=True" - + ";Pooling=true"; + + ";Pooling=True"; mySqlConnect = new MySqlConnection(sConnection); mySqlConnect.Open(); iRetval = 0; diff --git a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs index c69559f..f19bd95 100644 --- a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs +++ b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs @@ -38,6 +38,7 @@ private string stability10; private string stability20; private string stability100; + private string isDetecting; public long Id { get @@ -161,5 +162,6 @@ public string Stability20 { get => stability20; set => stability20 = value; } public string Stability100 { get => stability100; set => stability100 = value; } public string Stability1 { get => stability1; set => stability1 = value; } + public string IsDetecting { get => isDetecting; set => isDetecting = value; } } } \ No newline at end of file diff --git a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs index 399098b..781749c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs @@ -9,7 +9,7 @@ { interface DetectionService { - int add(long deviceId, string frequency, string detecItemType, long detectionItemId); + int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time); List search(long deviceId, string detectionType, string startTime, string endTime, long detectionItemId); diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs index 0fd7b24..4df249b 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs @@ -132,7 +132,30 @@ string sQry = "SELECT * FROM r_counter_check_params"; 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) + // { + // if (row[0] != DBNull.Value) counterCheckParam.Id = Convert.ToInt32(row[0]); + // if (row[1] != DBNull.Value) counterCheckParam.SoOutDelay = row[1].ToString(); + // if (row[2] != DBNull.Value) counterCheckParam.SoEleFrequency = row[2].ToString(); + // if (row[3] != DBNull.Value) counterCheckParam.SoEleAddValue = row[3].ToString(); + // if (row[4] != DBNull.Value) counterCheckParam.SoEleAlarm = row[4].ToString(); + // if (row[5] != DBNull.Value) counterCheckParam.FreThreshold1 = row[5].ToString(); + // if (row[6] != DBNull.Value) counterCheckParam.FreThreshold2 = row[6].ToString(); + // if (row[7] != DBNull.Value) counterCheckParam.FreEleAddValue = row[7].ToString(); + // if (row[8] != DBNull.Value) counterCheckParam.CycThreshold1 = row[8].ToString(); + // if (row[9] != DBNull.Value) counterCheckParam.CycThreshold2 = row[9].ToString(); + // if (row[10] != DBNull.Value) counterCheckParam.CycEleAddValue = row[10].ToString(); + + // } + //} using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -149,10 +172,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(Exception ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs index 52b36f8..2c60ab4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs @@ -32,28 +32,29 @@ //先查询是否有历史数据 string sQry = "select ID from r_counter_data where DEVICE_ID=" + deviceId + " and OUT_VALUE = '" + outValue + "'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - - if (aReader.Read()) + bool isUpdated = false; + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - dataId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) + { + dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + + " where ID=" + dataId; + + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; + cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; + cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; + + cmd.ExecuteNonQuery(); + isUpdated = true; + } aReader.Close(); - sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + - " where ID="+ dataId; - - cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; - cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; - cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; - cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; - - cmd.ExecuteNonQuery(); - } - else - { - aReader.Close(); - + if (!isUpdated) + { sQry = "INSERT INTO r_counter_data (DEVICE_ID, OUT_VALUE, VALUE, SENSITIVITY, LOG_TIME, DETEC_TYPE)" + "values(@DEVICE_ID,@OUT_VALUE,@VALUE,@SENSITIVITY,@LOG_TIME,@DETEC_TYPE)"; @@ -70,14 +71,14 @@ sQry = "SELECT max(ID) from r_counter_data"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - - aReader = cmd.ExecuteReader(); - - if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); - + using (MySqlDataReader aReader = cmd.ExecuteReader()) + { + + if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + } } - aReader.Close(); cmd.Dispose(); iRetval = 0; @@ -144,6 +145,8 @@ cmd.ExecuteNonQuery(); } + + aReader.Close(); } @@ -282,9 +285,10 @@ if (!aReader.IsDBNull(6)) counterData.DetecType = aReader.GetString(6); counterDataList.Add(counterData); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs index 6795325..7500bd4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs @@ -47,10 +47,11 @@ counterDetecInitList.Add(counterDetecInit); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -75,29 +76,31 @@ return iRetval; } } - string sQry = "select ID from r_counter_detec_init where FREQUENCY=" + frequency +" AND CYCLE="+cycle; + string sQry = "select ID from r_counter_detec_init where FREQUENCY='" + frequency +"' AND CYCLE='"+cycle+"'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - if (aReader.Read()) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - initId = Convert.ToInt64(aReader.GetString(0)); - sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; + if (aReader.Read()) + { + initId = Convert.ToInt64(aReader.GetString(0)); + sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; - 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(); - } - else - { - 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 = 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(); + } + else + { + 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.ExecuteNonQuery(); + + } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); iRetval = 0; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs index 97b06ba..abcbaa6 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs @@ -72,26 +72,27 @@ MySqlCommand cmd = new MySqlCommand(sql, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(CommandBehavior.Default); - - if (aReader != null) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) + if (aReader != null) { - //判断门的状态 - if (!aReader.IsDBNull(0)) - counterParam.Id = Convert.ToInt32(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) - counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) - counterParam.BaudRate = aReader.GetString(2); - if (!aReader.IsDBNull(3)) - counterParam.GeneratorIp = aReader.GetString(3); - if (!aReader.IsDBNull(4)) - counterParam.SignalSourceIp = aReader.GetString(4); + if (aReader.Read()) + { + //判断门的状态 + if (!aReader.IsDBNull(0)) + counterParam.Id = Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(1)) + counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); + if (!aReader.IsDBNull(2)) + counterParam.BaudRate = aReader.GetString(2); + if (!aReader.IsDBNull(3)) + counterParam.GeneratorIp = aReader.GetString(3); + if (!aReader.IsDBNull(4)) + counterParam.SignalSourceIp = aReader.GetString(4); + } } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs index cca90fb..1578937 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs @@ -33,8 +33,8 @@ MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@DEVICE_ID", MySqlDbType.Int64, 20).Value = deviceId; - cmd.Parameters.Add("@START_TIME", MySqlDbType.String, 50).Value = startTime; - cmd.Parameters.Add("@END_TIME", MySqlDbType.String, 50).Value = endTime; + cmd.Parameters.Add("@START_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(startTime); + cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(endTime); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 50).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 50).Value = accuracy; cmd.Parameters.Add("@BOOT_FEATURE", MySqlDbType.String, 50).Value = bootFeature; @@ -58,11 +58,11 @@ sQry = "SELECT max(ID) from r_detection_item"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = cmd.ExecuteReader()) { if (aReader.Read()) detectionId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); iRetval = 0; @@ -203,8 +203,9 @@ if (!stability100.Equals("")) sQry = sQry + " STABILITY_100=@STABILITY_100,"; sQry = sQry + " COUNTER_DETEC=@COUNTER_DETEC where ID = " + detectionId; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry: " + sQry); - + MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 10).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 10).Value = accuracy; @@ -283,7 +284,8 @@ return iRetval; } } - + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "停止检测 detectionItemId=======" + detectionItemId); + string sQry = "UPDATE r_device SET STATUSID="+"1"+", CHANNEL=@CHANNEL where ID=" + deviceId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@CHANNEL", MySqlDbType.String, 20).Value = ""; @@ -292,19 +294,21 @@ if (isDeleteData) { - sQry = "DELETE FROM r_detection_item WHERE DEVICE_ID = " + deviceId + " AND START_TIME='" + startTime + "' AND END_TIME='" + endTime + "'"; + sQry = "DELETE FROM r_detection_item WHERE ID=" + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); - sQry = "DELETE FROM r_detection WHERE DEVICE_ID = " + deviceId + " AND (LOG_TIME between'" + startTime + "' and '" + endTime + "')"; + sQry = "DELETE FROM r_detection WHERE DETECTION_ITEM_ID = " + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); } else { - sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME WHERE ID="+ detectionItemId; + sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME, IS_DETECTING=@IS_DETECTING WHERE ID=" + detectionItemId; + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 20).Value = DateTime.Now; + cmd.Parameters.Add("@IS_DETECTING", MySqlDbType.String, 1).Value = "0"; //0-否,1-是 cmd.ExecuteNonQuery(); } @@ -322,8 +326,7 @@ { DetectionItem detectionItem = null; try - { - + { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getById : 数据库链接断开"); @@ -337,6 +340,7 @@ string sQry = "select * from r_detection_item WHERE ID = "+ detectionItemId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + using (MySqlDataReader aReader = cmd.ExecuteReader()) { while (aReader.Read()) @@ -356,11 +360,13 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(15)) detectionItem.IsDetecting = aReader.GetString(15); } - } - + aReader.Close(); + } cmd.Dispose(); + } catch (MySqlException e) { @@ -400,7 +406,7 @@ { DetectionItem detectionItem = new DetectionItem(); //姓名 - if (!aReader.IsDBNull(0)) detectionItem.Id=Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(0)) detectionItem.Id = Convert.ToInt32(aReader.GetString(0)); if (!aReader.IsDBNull(1)) detectionItem.DeviceId = Convert.ToInt64(aReader.GetString(1)); if (!aReader.IsDBNull(2)) detectionItem.StartTime = aReader.GetString(2); if (!aReader.IsDBNull(3)) detectionItem.EndTime = aReader.GetString(3); @@ -416,9 +422,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -468,9 +475,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -498,7 +506,6 @@ string sQry = "SELECT * FROM r_detection_item where ID = " + detectionId; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -518,15 +525,43 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); + //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) + // { + // detectionItem = new DetectionItem(); + // if (row[0] != DBNull.Value) detectionItem.Id = Convert.ToInt64(row[0]); + // if (row[1] != DBNull.Value) detectionItem.DeviceId = Convert.ToInt64(row[1]); + // if (row[2] != DBNull.Value) detectionItem.StartTime = Convert.ToDateTime(row[2]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[3] != DBNull.Value) detectionItem.EndTime = Convert.ToDateTime(row[3]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[4] != DBNull.Value) detectionItem.Stability = row[4].ToString(); + // if (row[5] != DBNull.Value) detectionItem.Accuracy = row[5].ToString(); + // if (row[6] != DBNull.Value) detectionItem.BootFeature = row[6].ToString(); + // if (row[7] != DBNull.Value) detectionItem.AgeRate = row[7].ToString(); + // if (row[8] != DBNull.Value) detectionItem.Interval = row[8].ToString(); + // if (row[10] != DBNull.Value) detectionItem.Channel = row[10].ToString(); + // if (row[11] != DBNull.Value) detectionItem.Stability1 = row[11].ToString(); + // if (row[12] != DBNull.Value) detectionItem.Stability10 = row[12].ToString(); + // if (row[13] != DBNull.Value) detectionItem.Stability20 = row[13].ToString(); + // if (row[14] != DBNull.Value) detectionItem.Stability100 = row[14].ToString(); + + // } + //} } catch (MySqlException ex) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDetectionItem: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchById: " + ex.Message); } return detectionItem; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs index e2a5893..5b3deb0 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs @@ -14,7 +14,7 @@ { class DetectionServiceImpl : DetectionService { - public int add(long deviceId, string frequency, string detecItemType, long detectionItemId) + public int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time) { int iRetval = -1; try @@ -36,7 +36,7 @@ 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 = DateTime.Now; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.DateTime, 0).Value = time; cmd.Parameters.Add("@DETECTION_ITEM", MySqlDbType.String, 0).Value = detecItemType; cmd.Parameters.Add("@DETECTION_ITEM_ID", MySqlDbType.Int64, 0).Value = detectionItemId; @@ -108,24 +108,26 @@ string sQry = "SELECT * FROM r_detection where DEVICE_ID = " + deviceId +" and DETECTION_ITEM='" + detectionType + "' and (LOG_TIME BETWEEN '" + startTime + "' and '"+ endTime + "') and DETECTION_ITEM_ID="+detectionItemId+" order by LOG_TIME"; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) { - Model.Detection detection = new Model.Detection(); - //姓名 - if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) detection.LogTime = Convert.ToDateTime(aReader.GetString(2)).ToString("yyyy-MM-dd HH:mm:ss"); - if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); - if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); + Detection detection = new Detection(); + + if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); // id + if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); // devName + if (!aReader.IsDBNull(2)) detection.LogTime = aReader.GetString(2); // devCode + if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); // devType + if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); // devModel detectionDtoList.Add(detection); } + aReader.Close(); + - aCommand.Dispose(); } + aCommand.Dispose(); + } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs index 9413e2f..b224bc1 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs @@ -53,7 +53,8 @@ using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); @@ -87,8 +88,7 @@ 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; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry : "+ sQry + "; statusId="+ statusId); - + 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; @@ -183,7 +183,7 @@ } MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -208,10 +208,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -254,7 +255,30 @@ 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()) @@ -279,10 +303,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -342,7 +367,30 @@ 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()) @@ -372,10 +420,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -442,9 +491,10 @@ { totalCount = aReader.GetInt32(0); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -477,89 +527,45 @@ return null; } } - - string sQry = "SELECT * FROM r_deviceview where ACTIVE = 0 and STATUSID = 2 " + "and ('" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' <= END_TIME)"; - - 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) + //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))"; + MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { - foreach (DataRow row in dt.Rows) + while (aReader.Read()) { DeviceView deviceView = new DeviceView(); - if (row[0] != DBNull.Value) deviceView.Id = Convert.ToInt64(row[0]); - if (row[1] != DBNull.Value) deviceView.DevName = row[1].ToString(); - if (row[2] != DBNull.Value) deviceView.DevCode = row[2].ToString(); - if (row[3] != DBNull.Value) deviceView.DevTypeId = row[3].ToString(); - if (row[4] != DBNull.Value) deviceView.DevModel = row[4].ToString(); - if (row[5] != DBNull.Value) deviceView.RegTime = row[5].ToString(); - if (row[6] != DBNull.Value) deviceView.CustomerName = row[6].ToString(); - if (row[7] != DBNull.Value) deviceView.CustomerDev = row[7].ToString(); - if (row[8] != DBNull.Value) deviceView.Channel = row[8].ToString(); - if (row[9] != DBNull.Value) deviceView.Active = Convert.ToInt32(row[9]); - if (row[10] != DBNull.Value) deviceView.StartTime = Convert.ToDateTime(row[10]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[11] != DBNull.Value) deviceView.EndTime = Convert.ToDateTime(row[11]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[12] != DBNull.Value) deviceView.StatusId = row[12].ToString(); - if (row[13] != DBNull.Value) deviceView.Stability = row[13].ToString(); - if (row[14] != DBNull.Value) deviceView.Accuracy = row[14].ToString(); - if (row[15] != DBNull.Value) deviceView.BootFeature = row[15].ToString(); - if (row[16] != DBNull.Value) deviceView.AgeRate = row[16].ToString(); - if (row[17] != DBNull.Value) deviceView.DetectionItemId = Convert.ToInt64(row[17]); + 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(); + + } - //using (MySqlDataReader aReader = aCommand.ExecuteReader()) - //{ - // while (aReader.Read()) - // { - // DeviceView deviceView = new DeviceView(); + aCommand.Dispose(); - // 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 - // //deviceView.DevTypeName = dictService.getNameByCode("devType", aReader.GetString(3)); - // } - // if (!aReader.IsDBNull(4)) deviceView.DevModel = aReader.GetString(4); // devModel - // if (!aReader.IsDBNull(5)) - // { - // DateTime reg = aReader.GetDateTime(5); // regTime - // deviceView.RegTime = reg.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); - // if (!aReader.IsDBNull(9)) deviceView.Active = Convert.ToInt32(aReader.GetString(9)); - // if (!aReader.IsDBNull(10)) - // { - // DateTime reg = aReader.GetDateTime(10); // regTime - // deviceView.StartTime = reg.ToString("yyyy-MM-dd HH:mm:ss"); - // } - // if (!aReader.IsDBNull(11)) - // { - // DateTime reg = aReader.GetDateTime(11); // regTime - // deviceView.EndTime = reg.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 = Convert.ToInt64(aReader.GetString(17)); - - // deviceViewList.Add(deviceView); - - // aCommand.Dispose(); - // } - //} - if (deviceViewList.Count > 0) { foreach (DeviceView deviceView in deviceViewList) @@ -568,9 +574,15 @@ } } } + + 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()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getDeviceByChannel: " + ex.Message + " ; " + ex.ToString()); deviceViewList = null; } finally diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs index 1626aa5..42ca83c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs @@ -92,10 +92,11 @@ if (!aReader.IsDBNull(3)) dict.Code = aReader.GetString(3); nameList.Add(dict); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(MySqlException ex) { @@ -139,10 +140,11 @@ if (!aReader.IsDBNull(3)) counterParam.GeneratorIp = aReader.GetString(3); if (!aReader.IsDBNull(4)) counterParam.SignalSourceIp = aReader.GetString(4); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -220,10 +222,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/RbFreqStdMeas.cs b/RbFreqStandMeasure/RbFreqStdMeas.cs index beae3dc..8d74572 100644 --- a/RbFreqStandMeasure/RbFreqStdMeas.cs +++ b/RbFreqStandMeasure/RbFreqStdMeas.cs @@ -363,24 +363,7 @@ detectionItemService.stopDetection(deviceId, device.DetectionItemId, startTime, endTime, true); } } - deviceService.clearChannel(); - List detectionItemList = detectionItemService.getAll(); - if (detectionItemList != null && detectionItemList.Count > 0) - { - foreach (DetectionItem detectionItem in detectionItemList) - { - long detectionItemId = detectionItem.Id; - if (detectionItem.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem.Stability1.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "0", "", "", ""); - if (detectionItem.Stability10.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "0", "", ""); - if (detectionItem.Stability20.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "0", ""); - if (detectionItem.Stability100.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "", "0"); - if (detectionItem.Accuracy.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "0", "", "", "", "", "", "", ""); - if (detectionItem.BootFeature.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "0", "", "", "", "", "", ""); - if (detectionItem.AgeRate.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "0", "", "", "", "", ""); - } - } - + deviceService.clearChannel(); } else { @@ -590,7 +573,7 @@ break; case 3: // 频率计数器范围 - CounterCtrlForm counterForm = CounterCtrlForm.GetInstance(); + CounterCtrlForm counterForm = new CounterCtrlForm(); counterForm.Show(); panelMain.Controls.Add(counterForm); break; diff --git a/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe b/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe index 70dc261..11271b0 100644 --- a/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe +++ b/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe Binary files differ diff --git a/RbFreqStandMeasure/counter/CounterCtrlForm.cs b/RbFreqStandMeasure/counter/CounterCtrlForm.cs index 951a19c..e45f17b 100644 --- a/RbFreqStandMeasure/counter/CounterCtrlForm.cs +++ b/RbFreqStandMeasure/counter/CounterCtrlForm.cs @@ -39,6 +39,9 @@ GPIBService tcpService = new TCPServiceImpl(); string valueOld = ""; + string valueOldBack = ""; + string valueOldSensi = ""; + string valueOldTime = ""; #region 样式常量定影 private readonly Color titleBackColor = Color.FromArgb(63, 132, 215); // #3F64D7 @@ -55,8 +58,8 @@ return _counterCtrlForm; } - - private CounterCtrlForm() + + public CounterCtrlForm() { InitializeComponent(); @@ -69,7 +72,7 @@ comboBox_detecModel.SelectedIndex = 0; InitTableCounter(); - LoadCounterDetecInitList(); + //LoadCounterDetecInitList(); if (list != null && list.Count > 0) { @@ -221,12 +224,12 @@ table_counterDetecInit.Columns.Add("initId", Type.GetType("System.Int32")); table_counterDetecInit.Columns.Add("counterDataId", Type.GetType("System.Int64")); - if (comboBox_counters.Text != "") + if (((DeviceDto)comboBox_counters.SelectedItem).DevName != "") { - List list = deviceService.search(comboBox_counters.Text, "", "", "", "", ""); + List list = deviceService.search(((DeviceDto)comboBox_counters.SelectedItem).DevName, "", "", "", "", ""); if (null != list && list.Count > 0) { - devType = list[0].DevTypeName; + devType = list[0].DevModel; devCode = list[0].DevCode; } @@ -344,6 +347,18 @@ { valueOld = dataGridView_CounterResult.CurrentCell.Value.ToString(); } + else if (e.ColumnIndex == 5) + { + valueOldBack = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } + else if (e.ColumnIndex == 6) + { + valueOldSensi = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } + else if (e.ColumnIndex == 7) + { + valueOldTime = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } } @@ -522,7 +537,10 @@ dataGridView_CounterResult.ReadOnly = true; btn_add.Enabled = false; benDelete.Enabled = false; - ///btn_dropDetecModel.Enabled = false; + comboBox_counters.Enabled = false; + comboBox_detecModel.Enabled = false; + text_counterIp.ReadOnly = true; + text_signal.ReadOnly = true; string[] arr = text_counterIp.Text.Split('.'); if (arr.Length != 4) @@ -643,11 +661,11 @@ Invoke(new MethodInvoker(delegate () { SetDevTestDlg.inDetecCounterId = -1; - //text_devName.ReadOnly = false; - //btn_downCounterList.Enabled = true; btnStart.Enabled = true; - //btn_dropDetecModel.Enabled = true; - //textBox_detecModel.ReadOnly = false; + comboBox_counters.Enabled = true; + comboBox_detecModel.Enabled = true; + text_counterIp.ReadOnly = false; + text_signal.ReadOnly = false; })); dataGridView_CounterResult.ReadOnly = false; @@ -736,6 +754,8 @@ if (!checkFreq(value)) { MessageBox.Show("请输入格式正确的测量频率值!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldBack; + valueOldBack = ""; return; } } @@ -744,6 +764,8 @@ if (!checkCyc(value)) { MessageBox.Show("请输入格式正确的测量周期值!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldBack; + valueOldBack = ""; return; } } @@ -753,11 +775,21 @@ { if (!String.IsNullOrEmpty(value)) { + if (value.Contains(".") && ((value.IndexOf('.') != value.LastIndexOf('.')) || value.IndexOf('.') == 0 || value.LastIndexOf('.') == value.Length)) + { + MessageBox.Show("请输入格式正确的灵敏度!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldSensi; + valueOldSensi = ""; + return; + } + string pattern = @"^[0-9.]+$"; Regex regex = new Regex(pattern); if (!regex.IsMatch(value)) { MessageBox.Show("请输入格式正确的灵敏度!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldSensi; + valueOldSensi = ""; return; } } @@ -772,7 +804,8 @@ } catch { - dataGridView_CounterResult.Rows[e.RowIndex].Cells[7].Value = ""; + dataGridView_CounterResult.CurrentCell.Value = valueOldTime; + valueOldTime = ""; MessageBox.Show("请输入格式正确的时间!"); return; } diff --git a/RbFreqStandMeasure/home/HomeCtrlForm.cs b/RbFreqStandMeasure/home/HomeCtrlForm.cs index b2568f7..586334d 100644 --- a/RbFreqStandMeasure/home/HomeCtrlForm.cs +++ b/RbFreqStandMeasure/home/HomeCtrlForm.cs @@ -7,6 +7,7 @@ using Casic.Birmm.RbFreqStandMeasure.Tools; using DevComponents.DotNetBar.Controls; using System; +using System.Collections; using System.Collections.Generic; using System.Data; using System.Drawing; @@ -23,16 +24,16 @@ public partial class HomeCtrlForm : UserControl { public static HomeCtrlForm homeCtrlForm; - int totalCount = 0; - int currentPage = 1; - int pageCount = 0; - int limitCount = 4; + public int totalCount = 0; + public int currentPage = 1; + public int pageCount = 0; + public int limitCount = 4; DataTable devToBeTestedTable = null; DataTable channelsTable = null; DeviceService deviceService = new DeviceServiceImpl(); List listChannelStatus = new List(); DetectionItemService detectionItemService = new DetectionItemServiceImpl(); - + public static Hashtable stoppedItemIdTable = new Hashtable(); public static List channelFreeList = new List(); private readonly object obj = new object(); @@ -166,10 +167,7 @@ Size = new Size(120, 32) }; tableToBeTested.Controls.Add(colCustomComp); - colCustomComp.BringToFront(); - - - + colCustomComp.BringToFront(); totalCount = 0; currentPage = 1; @@ -332,7 +330,7 @@ AutoSize = false, Text = "通道", Location = new Point(0, 0), - Size = new Size(50, 30) + Size = new Size(70, 30) }; dataGridView_Channel.Controls.Add(colChannelNo); colChannelNo.BringToFront(); @@ -346,7 +344,7 @@ BackColor = titleBackColor, AutoSize = false, Text = "仪器名称", - Location = new Point(50, 0), + Location = new Point(70, 0), Size = new Size(110, 30) }; dataGridView_Channel.Controls.Add(colDevName); @@ -361,8 +359,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "仪器编号", - Location = new Point(160, 0), - Size = new Size(110, 30) + Location = new Point(180, 0), + Size = new Size(120, 30) }; dataGridView_Channel.Controls.Add(colDevNo); colDevNo.BringToFront(); @@ -376,8 +374,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "送检单位", - Location = new Point(270, 0), - Size = new Size(110, 30) + Location = new Point(300, 0), + Size = new Size(120, 30) }; dataGridView_Channel.Controls.Add(colCustomName); colCustomName.BringToFront(); @@ -391,8 +389,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "开始时间", - Location = new Point(380, 0), - Size = new Size(120, 30) + Location = new Point(420, 0), + Size = new Size(100, 30) }; dataGridView_Channel.Controls.Add(colStartTime); colStartTime.BringToFront(); @@ -406,8 +404,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "结束时间", - Location = new Point(500, 0), - Size = new Size(120, 30) + Location = new Point(520, 0), + Size = new Size(100, 30) }; dataGridView_Channel.Controls.Add(colEndTime); colEndTime.BringToFront(); @@ -492,6 +490,11 @@ dataGridView_Channel.Controls.Add(colAgingRate); colAgingRate.BringToFront(); } + + + + + } catch (Exception ex) { @@ -506,19 +509,22 @@ { lock (obj) { - channelFreeList.Clear(); - channelFreeList.Add("1"); - channelFreeList.Add("2"); - channelFreeList.Add("3"); - channelFreeList.Add("4"); - channelFreeList.Add("5"); - - listChannelStatus = deviceService.getDeviceByChannel(); - if (listChannelStatus != null && listChannelStatus.Count > 0) + // lock (channelFreeList) { - foreach (DeviceView device in listChannelStatus) + channelFreeList.Clear(); + channelFreeList.Add("1"); + channelFreeList.Add("2"); + channelFreeList.Add("3"); + channelFreeList.Add("4"); + channelFreeList.Add("5"); + + listChannelStatus = deviceService.getDeviceByChannel(); + if (listChannelStatus != null && listChannelStatus.Count > 0) { - channelFreeList.Remove(device.Channel); + foreach (DeviceView device in listChannelStatus) + { + channelFreeList.Remove(device.Channel); + } } } } @@ -533,125 +539,131 @@ { try { - lock (obj) + //Invoke(new MethodInvoker(delegate () { - channelsTable = new DataTable(); - - channelsTable.Columns.Add("channelNo", Type.GetType("System.String")); - channelsTable.Columns.Add("devName", Type.GetType("System.String")); - channelsTable.Columns.Add("devCode", Type.GetType("System.String")); - channelsTable.Columns.Add("customComp", Type.GetType("System.String")); - channelsTable.Columns.Add("startTime", Type.GetType("System.String")); - channelsTable.Columns.Add("endTime", Type.GetType("System.String")); - channelsTable.Columns.Add("channelStatus", Type.GetType("System.String")); - channelsTable.Columns.Add("stablility", Type.GetType("System.String")); - channelsTable.Columns.Add("accuracy", Type.GetType("System.String")); - channelsTable.Columns.Add("startup", Type.GetType("System.String")); - channelsTable.Columns.Add("agingRate", Type.GetType("System.String")); - channelsTable.Columns.Add("deviceId", Type.GetType("System.Int64")); - channelsTable.Columns.Add("deviceItemId", Type.GetType("System.Int64")); - //channelsTable.Columns.Add("devType", Type.GetType("System.String")); - //channelsTable.Columns.Add("devModel", Type.GetType("System.String")); - //channelsTable.Columns.Add("customCom", Type.GetType("System.String")); - - listChannelStatus = deviceService.getDeviceByChannel(); - - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelFreeList.Clear(); - channelFreeList.Add("1"); - channelFreeList.Add("2"); - channelFreeList.Add("3"); - channelFreeList.Add("4"); - channelFreeList.Add("5"); - - if (listChannelStatus != null && listChannelStatus.Count > 0) + lock (obj) { - foreach (DeviceView device in listChannelStatus) + //lock(channelFreeList) { - channelFreeList.Remove(device.Channel); - int index = Convert.ToInt32(device.Channel) - 1; - channelsTable.Rows[index]["channelNo"] = device.Channel; - channelsTable.Rows[index]["devName"] = device.DevName; - channelsTable.Rows[index]["devCode"] = device.DevCode; - channelsTable.Rows[index]["customComp"] = device.CustomerDev; - channelsTable.Rows[index]["startTime"] = device.StartTime; - channelsTable.Rows[index]["endTime"] = device.EndTime; - channelsTable.Rows[index]["channelStatus"] = "占用"; - channelsTable.Rows[index]["deviceId"] = device.Id; - channelsTable.Rows[index]["deviceItemId"] = device.DetectionItemId; + channelsTable = new DataTable(); - if (device.Stability.Equals("-3")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.Stability.Equals("-2")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.Stability.Equals("-1")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + channelsTable.Columns.Add("channelNo", Type.GetType("System.String")); + channelsTable.Columns.Add("devName", Type.GetType("System.String")); + channelsTable.Columns.Add("devCode", Type.GetType("System.String")); + channelsTable.Columns.Add("customComp", Type.GetType("System.String")); + channelsTable.Columns.Add("startTime", Type.GetType("System.String")); + channelsTable.Columns.Add("endTime", Type.GetType("System.String")); + channelsTable.Columns.Add("channelStatus", Type.GetType("System.String")); + channelsTable.Columns.Add("stablility", Type.GetType("System.String")); + channelsTable.Columns.Add("accuracy", Type.GetType("System.String")); + channelsTable.Columns.Add("startup", Type.GetType("System.String")); + channelsTable.Columns.Add("agingRate", Type.GetType("System.String")); + channelsTable.Columns.Add("deviceId", Type.GetType("System.Int64")); + channelsTable.Columns.Add("deviceItemId", Type.GetType("System.Int64")); - if (device.Accuracy.Equals("-3")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.Accuracy.Equals("-2")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.Accuracy.Equals("-1")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; - - if (device.AgeRate.Equals("-3")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.AgeRate.Equals("-2")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.AgeRate.Equals("-1")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; - - if (device.BootFeature.Equals("-3")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.BootFeature.Equals("-2")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.BootFeature.Equals("-1")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + listChannelStatus = deviceService.getDeviceByChannel(); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelFreeList.Clear(); + channelFreeList.Add("1"); + channelFreeList.Add("2"); + channelFreeList.Add("3"); + channelFreeList.Add("4"); + channelFreeList.Add("5"); + + if (listChannelStatus != null && listChannelStatus.Count > 0) + { + foreach (DeviceView device in listChannelStatus) + { + if (String.IsNullOrEmpty(device.Channel)) continue; + channelFreeList.Remove(device.Channel); + int index = Convert.ToInt32(device.Channel) - 1; + channelsTable.Rows[index]["channelNo"] = device.Channel; + channelsTable.Rows[index]["devName"] = device.DevName; + channelsTable.Rows[index]["devCode"] = device.DevCode; + channelsTable.Rows[index]["customComp"] = device.CustomerDev; + channelsTable.Rows[index]["startTime"] = device.StartTime; + channelsTable.Rows[index]["endTime"] = device.EndTime; + channelsTable.Rows[index]["channelStatus"] = "占用"; + channelsTable.Rows[index]["deviceId"] = device.Id; + channelsTable.Rows[index]["deviceItemId"] = device.DetectionItemId; + + if (device.Stability.Equals("-3")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.Stability.Equals("-2")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.Stability.Equals("-1")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + if (device.Accuracy.Equals("-3")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.Accuracy.Equals("-2")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.Accuracy.Equals("-1")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + if (device.AgeRate.Equals("-3")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.AgeRate.Equals("-2")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.AgeRate.Equals("-1")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + if (device.BootFeature.Equals("-3")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.BootFeature.Equals("-2")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.BootFeature.Equals("-1")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + + } + } + else + { + channelsTable.Rows.Clear(); + channelsTable.Rows.Add("1", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("2", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("3", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("4", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("5", "", "", "", "", "", "空闲", "", ""); + } + + foreach (string no in channelFreeList) + { + channelsTable.Rows[Convert.ToInt32(no) - 1]["channelNo"] = no; + channelsTable.Rows[Convert.ToInt32(no) - 1]["channelStatus"] = "空闲"; + } + + + dataGridView_Channel.DataSource = channelsTable; + + // width=764px + dataGridView_Channel.Columns[11].Visible = false; + dataGridView_Channel.Columns[12].Visible = false; + dataGridView_Channel.Columns[0].Width = 70; + dataGridView_Channel.Columns[1].Width = 110; + dataGridView_Channel.Columns[2].Width = 120; + dataGridView_Channel.Columns[3].Width = 120; + dataGridView_Channel.Columns[4].Width = 100; //starttime + dataGridView_Channel.Columns[5].Width = 100; //endtime + dataGridView_Channel.Columns[6].Width = 64; + dataGridView_Channel.Columns[7].Width = 75; + dataGridView_Channel.Columns[8].Width = 75; + dataGridView_Channel.Columns[9].Width = 75; + dataGridView_Channel.Columns[10].Width = 75; + + dataGridView_Channel.Columns[0].ReadOnly = true; + dataGridView_Channel.Columns[1].ReadOnly = true; + dataGridView_Channel.Columns[2].ReadOnly = true; + dataGridView_Channel.Columns[3].ReadOnly = true; + dataGridView_Channel.Columns[4].ReadOnly = true; + dataGridView_Channel.Columns[5].ReadOnly = true; + dataGridView_Channel.Columns[6].ReadOnly = true; + dataGridView_Channel.Columns[7].ReadOnly = true; + dataGridView_Channel.Columns[8].ReadOnly = true; + dataGridView_Channel.Columns[9].ReadOnly = true; + dataGridView_Channel.Columns[10].ReadOnly = true; } } - else - { - channelsTable.Rows.Clear(); - channelsTable.Rows.Add("1", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("2", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("3", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("4", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("5", "", "", "", "", "", "空闲", "", ""); - } - - foreach (string no in channelFreeList) - { - channelsTable.Rows[Convert.ToInt32(no) - 1]["channelNo"] = no; - channelsTable.Rows[Convert.ToInt32(no) - 1]["channelStatus"] = "空闲"; - } - - - dataGridView_Channel.DataSource = channelsTable; - - // width=764px - dataGridView_Channel.Columns[11].Visible = false; - dataGridView_Channel.Columns[12].Visible = false; - dataGridView_Channel.Columns[0].Width = 50; - dataGridView_Channel.Columns[1].Width = 110; - dataGridView_Channel.Columns[2].Width = 110; - dataGridView_Channel.Columns[3].Width = 110; - dataGridView_Channel.Columns[4].Width = 120; - dataGridView_Channel.Columns[5].Width = 120; - dataGridView_Channel.Columns[6].Width = 64; - dataGridView_Channel.Columns[7].Width = 75; - dataGridView_Channel.Columns[8].Width = 75; - dataGridView_Channel.Columns[9].Width = 75; - dataGridView_Channel.Columns[10].Width = 75; - - dataGridView_Channel.Columns[0].ReadOnly = true; - dataGridView_Channel.Columns[1].ReadOnly = true; - dataGridView_Channel.Columns[2].ReadOnly = true; - dataGridView_Channel.Columns[3].ReadOnly = true; - dataGridView_Channel.Columns[4].ReadOnly = true; - dataGridView_Channel.Columns[5].ReadOnly = true; - dataGridView_Channel.Columns[6].ReadOnly = true; - dataGridView_Channel.Columns[7].ReadOnly = true; - dataGridView_Channel.Columns[8].ReadOnly = true; - dataGridView_Channel.Columns[9].ReadOnly = true; - dataGridView_Channel.Columns[10].ReadOnly = true; + //})); } } catch (Exception ex) @@ -760,7 +772,6 @@ private void cellDoubleClick(int rowIndex) { - int colIndex = dataGridView_Channel.CurrentCell.ColumnIndex; if (dataGridView_Channel.Rows[rowIndex].Cells[6].Value.ToString().Equals("占用")) { if (MessageBox.Show("该通道有正在检测的仪器,确定要停止检测?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) @@ -780,30 +791,22 @@ { return; } + DialogResult dialogResult = MessageBox.Show("是否保存此次检测的数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { - detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, false); + detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, false); } else { detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, true); } - DetectionItem detectionItem0 = detectionItemService.getById(deviceItemId); - if (detectionItem0 != null) - { - if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem0.Stability1.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "0", "", "", ""); - if (detectionItem0.Stability10.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "", "0", "", ""); - if (detectionItem0.Stability20.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "", "", "0", ""); - if (detectionItem0.Stability100.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "", "", "", "0"); - if (detectionItem0.Accuracy.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "0", "", "", "", "", "", "", ""); - if (detectionItem0.BootFeature.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "0", "", "", "", "", "", ""); - if (detectionItem0.AgeRate.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "0", "", "", "", "", ""); - - } + if (stoppedItemIdTable.Contains(rowIndex + 1)) stoppedItemIdTable.Remove(rowIndex + 1); + + stoppedItemIdTable.Add(rowIndex + 1, deviceItemId); LoadChannelStatus(); + currentPage = 1; LoadDevToBeTested(); } catch(Exception ex) diff --git a/RbFreqStandMeasure/home/SetDevChannelDlg.cs b/RbFreqStandMeasure/home/SetDevChannelDlg.cs index fe3bcdd..a1d96fe 100644 --- a/RbFreqStandMeasure/home/SetDevChannelDlg.cs +++ b/RbFreqStandMeasure/home/SetDevChannelDlg.cs @@ -84,9 +84,12 @@ timePicker_startTime.MinDate = DateTime.Now; getEndTime(); List listToTest = deviceService.search("", "", "", "", "", "1"); - foreach (DeviceDto deviceDto in listToTest) + if (listToTest != null && listToTest.Count > 0) { - cbBox_toTestDevList.Items.Add(deviceDto.DevCode); + foreach (DeviceDto deviceDto in listToTest) + { + cbBox_toTestDevList.Items.Add(deviceDto.DevCode); + } } text_customerDev.Visible = true; @@ -202,7 +205,7 @@ if (checkBox10s.Checked) stability10 = "-1"; if (checkBox20s.Checked) stability20 = "-1"; if (checkBox_100s.Checked) stability100 = "-1"; - detectionHelper.detecStability(deviceId, startTime, interval, port, true ,false); + detectionHelper.detecStability(deviceId, startTime, interval, port, true, false); } else { @@ -257,8 +260,10 @@ } long detectionId0 = detectionItemService.add(deviceId, startTime, endTime, stability, accuracy, bootFeature, ageRate, interval, textBox_channelNo.Text,stability1,stability10,stability20,stability100); detectionHelper.detectionItemId = detectionId0; + this.HideMaskAction(); HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + HomeCtrlForm.homeCtrlForm.currentPage = 1; HomeCtrlForm.homeCtrlForm.LoadDevToBeTested(); } catch (Exception ex) @@ -311,18 +316,18 @@ private void getEndTime() { - if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddSeconds(30); + if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddMinutes(1).AddSeconds(30); else { - if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddSeconds(30); + if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddMinutes(1).AddSeconds(30); else { if (checkBox_stability.Checked) { - if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddSeconds(40); - else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddSeconds(40); - else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddSeconds(40); - else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddSeconds(40); + if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddMinutes(1).AddSeconds(30); + else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddMinutes(1).AddSeconds(30); + else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddMinutes(1).AddSeconds(30); + else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddMinutes(1).AddSeconds(30); } else endTimeBySystem = timePicker_startTime.Value.AddMinutes(1).AddSeconds(30); } diff --git a/RbFreqStandMeasure/home/SetDevTestDlg.cs b/RbFreqStandMeasure/home/SetDevTestDlg.cs index f1027ba..6e9d272 100644 --- a/RbFreqStandMeasure/home/SetDevTestDlg.cs +++ b/RbFreqStandMeasure/home/SetDevTestDlg.cs @@ -23,11 +23,7 @@ public static long inDetecCounterId = -1;// 正在检测灵敏度的计数器id DateTime endTimeBySystem = new DateTime(); - CounterDataService CounterDataService = new CounterDataServiceImpl(); - CounterDetecInitService counterDetecInitService = new CounterDetecInitServiceImpl(); DictService dictService = new DictServiceImpl(); - SensitivityService sensitivityService = new SensitivityServiceImpl(); - CounterDataService counterDataService = new CounterDataServiceImpl(); DeviceService deviceService = new DeviceServiceImpl(); @@ -221,6 +217,7 @@ this.HideMaskAction(); HomeCtrlForm.homeCtrlForm.refreshChannelList(); HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + HomeCtrlForm.homeCtrlForm.currentPage = 1; HomeCtrlForm.homeCtrlForm.LoadDevToBeTested(); } @@ -280,18 +277,18 @@ private void getEndTime() { - if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddSeconds(30); + if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddMinutes(1).AddSeconds(30); else { - if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddSeconds(30); + if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddMinutes(1).AddSeconds(30); else { if (checkBox_stability.Checked) { - if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddSeconds(40); - else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddSeconds(40); - else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddSeconds(40); - else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddSeconds(40); + if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddMinutes(1).AddSeconds(30); + else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddMinutes(1).AddSeconds(30); + else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddMinutes(1).AddSeconds(30); + else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddMinutes(1).AddSeconds(30); } else endTimeBySystem = timePicker_startTime.Value.AddMinutes(1).AddSeconds(30); } diff --git a/RbFreqStandMeasure/info/AddDevDlg.cs b/RbFreqStandMeasure/info/AddDevDlg.cs index 46d4778..6abc5b0 100644 --- a/RbFreqStandMeasure/info/AddDevDlg.cs +++ b/RbFreqStandMeasure/info/AddDevDlg.cs @@ -254,16 +254,13 @@ { if (needDetec) statusId = "2"; devService.update(deviceId, devName, devCode, devTypeCode, devModel, devCustomComp, devCustomName, channelNo,statusId); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "update 完成"); - + } //添加检测 if (deviceId != -1 && needDetec) - { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "各项检测开始。。。。"); - + { //开始检测 //稳定度 @@ -337,9 +334,7 @@ detectionHelper.detecAgeRate(deviceId, startTime, port, false); } } - - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "更新检测记录表" + deviceId); - + //开始检测 long detectionId0 = detectionItemService.add(deviceId, startTime, endTime, stability, accuracy, bootFeature, ageRate, interval, text_channelNo.Text, stability1, stability10, stability20, stability100); detectionHelper.detectionItemId = detectionId0; @@ -439,18 +434,18 @@ private void getEndTime() { - if (checkBox_ageRate.Checked) endTimeBySystem = picker_startTime.Value.AddDays(7).AddSeconds(30); + if (checkBox_ageRate.Checked) endTimeBySystem = picker_startTime.Value.AddDays(7).AddMinutes(1).AddSeconds(30); else { - if (checkBox_bootFeature.Checked) endTimeBySystem = picker_startTime.Value.AddHours(7).AddSeconds(30); + if (checkBox_bootFeature.Checked) endTimeBySystem = picker_startTime.Value.AddHours(7).AddMinutes(1).AddSeconds(30); else { if (checkBox_stability.Checked) { - if (checkBox100s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 100).AddSeconds(40); - else if (checkBox20s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 20).AddSeconds(40); - else if (checkBox10s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 10).AddSeconds(40); - else if (checkBox1s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101).AddSeconds(40); + if (checkBox100s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 100).AddMinutes(1).AddSeconds(30); + else if (checkBox20s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 20).AddMinutes(1).AddSeconds(30); + else if (checkBox10s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 10).AddMinutes(1).AddSeconds(30); + else if (checkBox1s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101).AddMinutes(1).AddSeconds(30); } else endTimeBySystem = picker_startTime.Value.AddMinutes(1).AddSeconds(30); } diff --git a/RbFreqStandMeasure/info/DetailDlg.cs b/RbFreqStandMeasure/info/DetailDlg.cs index ad05a32..cc05eac 100644 --- a/RbFreqStandMeasure/info/DetailDlg.cs +++ b/RbFreqStandMeasure/info/DetailDlg.cs @@ -86,17 +86,17 @@ resultBootStr = dataGridView_times.Rows[0].Cells[5].Value.ToString(); resultAgeStr = dataGridView_times.Rows[0].Cells[6].Value.ToString(); - if (!resultAccStr.Equals("-1") && !resultAccStr.Equals("-2") && !resultAccStr.Equals("-3")) tabPageEvent("tab_accuracy"); - if ((!resultStaStr1.Equals("-1")&& !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3")) || (!resultStaStr10.Equals("-1")&& !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3")) ||( !resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3"))) + if (!resultAccStr.Equals("-1") && !resultAccStr.Equals("-2") && !resultAccStr.Equals("-3") && !resultAccStr.Equals("0")) tabPageEvent("tab_accuracy"); + if ((!resultStaStr1.Equals("-1")&& !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3") && !resultStaStr1.Equals("0")) || (!resultStaStr10.Equals("-1")&& !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3") && !resultStaStr10.Equals("0")) ||( !resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3") && !resultStaStr100.Equals("0"))) { tabPageEvent("tab_stability"); - if (!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3")) radio_1s.Checked = true; - else if (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3")) radio_10s.Checked = true; - else if(!resultStaStr20.Equals("-1") && !resultStaStr20.Equals("-2") && !resultStaStr20.Equals("-3")) radio_20s.Checked = true; - else if (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3")) radio_100s.Checked = true; + if (!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3") && !resultStaStr1.Equals("0")) loadStability1(); + else if (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3") && !resultStaStr10.Equals("0")) loadStability10(); + else if(!resultStaStr20.Equals("-1") && !resultStaStr20.Equals("-2") && !resultStaStr20.Equals("-3") && !resultStaStr20.Equals("0")) loadStability20(); + else if (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3") && !resultStaStr100.Equals("0")) loadStability100(); } - if (!resultBootStr.Equals("-1")&& !resultBootStr.Equals("-2")&& !resultBootStr.Equals("-3")) tabPageEvent("tab_bootFeature"); - if (!resultAgeStr.Equals("-1")&&!resultAgeStr.Equals("-2")&& !resultAgeStr.Equals("-3")) tabPageEvent("tab_ageRate"); + if (!resultBootStr.Equals("-1")&& !resultBootStr.Equals("-2")&& !resultBootStr.Equals("-3") && !resultBootStr.Equals("0")) tabPageEvent("tab_bootFeature"); + if (!resultAgeStr.Equals("-1")&&!resultAgeStr.Equals("-2")&& !resultAgeStr.Equals("-3") && !resultAgeStr.Equals("0")) tabPageEvent("tab_ageRate"); } if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; @@ -305,17 +305,17 @@ resultBootStr = dataGridView_times.Rows[rowIndex].Cells[5].Value.ToString(); resultAgeStr = dataGridView_times.Rows[rowIndex].Cells[6].Value.ToString(); - if (!resultAccStr.Equals("-1") && !resultAccStr.Equals("-2") && !resultAccStr.Equals("-3")) tabPageEvent("tab_accuracy"); - else if ((!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3")) || (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3")) || (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3"))) + if (!resultAccStr.Equals("-1") && !resultAccStr.Equals("-2") && !resultAccStr.Equals("-3") && !resultAccStr.Equals("0")) tabPageEvent("tab_accuracy"); + else if ((!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3") && !resultStaStr1.Equals("0")) || (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3") && !resultStaStr10.Equals("0")) || (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3") && !resultStaStr100.Equals("0"))) { tabPageEvent("tab_stability"); - if (!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3")) radio_1s.Checked = true; - else if (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3")) radio_10s.Checked = true; - else if (!resultStaStr20.Equals("-1") && !resultStaStr20.Equals("-2") && !resultStaStr20.Equals("-3")) radio_20s.Checked = true; - else if (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3")) radio_100s.Checked = true; + if (!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3") && !resultStaStr1.Equals("0")) loadStability1(); + else if (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3") && !resultStaStr10.Equals("0")) loadStability10(); + else if (!resultStaStr20.Equals("-1") && !resultStaStr20.Equals("-2") && !resultStaStr20.Equals("-3") && !resultStaStr20.Equals("0")) loadStability20(); + else if (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3") && !resultStaStr100.Equals("0")) loadStability100(); } - else if (!resultBootStr.Equals("-1") && !resultBootStr.Equals("-2") && !resultBootStr.Equals("-3")) tabPageEvent("tab_bootFeature"); - else if (!resultAgeStr.Equals("-1") && !resultAgeStr.Equals("-2") && !resultAgeStr.Equals("-3")) tabPageEvent("tab_ageRate"); + else if (!resultBootStr.Equals("-1") && !resultBootStr.Equals("-2") && !resultBootStr.Equals("-3") && !resultBootStr.Equals("0")) tabPageEvent("tab_bootFeature"); + else if (!resultAgeStr.Equals("-1") && !resultAgeStr.Equals("-2") && !resultAgeStr.Equals("-3") && !resultAgeStr.Equals("0")) tabPageEvent("tab_ageRate"); } } @@ -362,6 +362,7 @@ groupBox3.Text = "频率准确度"; accuracy result = new accuracy(); result.label_accuracy.Text = ""; + if (!resultAccStr.Equals("-1") && !resultAccStr.Equals("-2") && !resultAccStr.Equals("-3")) result.label_accuracy.Text = resultAccStr; result.Show(); panel_result.Controls.Add(result); @@ -476,70 +477,106 @@ private void radio_10s_CheckedChanged(object sender, EventArgs e) { if (radio_10s.Checked) - { - LoadData(deviceId, "1-10", startTime, endTime); - groupBox3.Text = "10s频率稳定度"; - panel_result.Controls.Clear(); - stability result = new stability(); - result.label_stability.Text = ""; - if (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3")) result.label_stability.Text = resultStaStr10; - result.Show(); - panel_result.Controls.Add(result); - btn_reDetec.Enabled = true; - if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + { + loadStability10(); } } + private void loadStability10() + { + radio_10s.Checked = true; + LoadData(deviceId, "1-10", startTime, endTime); + groupBox3.Text = "10s频率稳定度"; + panel_result.Controls.Clear(); + stability result = new stability(); + result.label_stability.Text = ""; + if (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3")) + { + result.label_stability.Text = resultStaStr10; + result.label_count.Text = "101"; + } + result.Show(); + panel_result.Controls.Add(result); + btn_reDetec.Enabled = true; + if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + } private void radio_1s_CheckedChanged(object sender, EventArgs e) { if (radio_1s.Checked) { - LoadData(deviceId, "1-1", startTime, endTime); - groupBox3.Text = "1s频率稳定度"; - panel_result.Controls.Clear(); - stability result = new stability(); - result.label_stability.Text = ""; - if (!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3")) result.label_stability.Text = resultStaStr1; - result.Show(); - btn_reDetec.Enabled = true; - panel_result.Controls.Add(result); - if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + loadStability1(); } } + private void loadStability1() + { + radio_1s.Checked = true; + LoadData(deviceId, "1-1", startTime, endTime); + groupBox3.Text = "1s频率稳定度"; + panel_result.Controls.Clear(); + stability result = new stability(); + result.label_stability.Text = ""; + if (!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3")) + { + result.label_stability.Text = resultStaStr1; + result.label_count.Text = "101"; + } + result.Show(); + btn_reDetec.Enabled = true; + panel_result.Controls.Add(result); + if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + } private void radio_20s_CheckedChanged(object sender, EventArgs e) { if (radio_20s.Checked) { - LoadData(deviceId, "1-20", startTime, endTime); - groupBox3.Text = "20s频率稳定度"; - panel_result.Controls.Clear(); - stability result = new stability(); - result.label_stability.Text = ""; - if (!resultStaStr20.Equals("-1")&& !resultStaStr20.Equals("-2")&&!resultStaStr20.Equals("-3")) result.label_stability.Text = resultStaStr20; - result.Show(); - panel_result.Controls.Add(result); - btn_reDetec.Enabled = true; - if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + loadStability20(); } } + private void loadStability20() + { + radio_20s.Checked = true; + LoadData(deviceId, "1-20", startTime, endTime); + groupBox3.Text = "20s频率稳定度"; + panel_result.Controls.Clear(); + stability result = new stability(); + result.label_stability.Text = ""; + if (!resultStaStr20.Equals("-1") && !resultStaStr20.Equals("-2") && !resultStaStr20.Equals("-3")) + { + result.label_stability.Text = resultStaStr20; + result.label_count.Text = "101"; + } + result.Show(); + panel_result.Controls.Add(result); + btn_reDetec.Enabled = true; + if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + } private void radio_100s_CheckedChanged(object sender, EventArgs e) { if (radio_100s.Checked) { - LoadData(deviceId, "1-100", startTime, endTime); - groupBox3.Text = "100s频率稳定度"; - panel_result.Controls.Clear(); - stability result = new stability(); - result.label_stability.Text = ""; - if (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3")) result.label_stability.Text = resultStaStr100; - result.Show(); - panel_result.Controls.Add(result); - btn_reDetec.Enabled = true; - if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + loadStability100(); } } + private void loadStability100() + { + radio_100s.Checked = true; + LoadData(deviceId, "1-100", startTime, endTime); + groupBox3.Text = "100s频率稳定度"; + panel_result.Controls.Clear(); + stability result = new stability(); + result.label_stability.Text = ""; + if (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3")) + { + result.label_stability.Text = resultStaStr100; + result.label_count.Text = "101"; + } + result.Show(); + panel_result.Controls.Add(result); + btn_reDetec.Enabled = true; + if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + } public void updateChannelNoRedetec() { diff --git a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs index 963b90b..a5e9368 100644 --- a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs +++ b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs @@ -29,7 +29,7 @@ + ";password=" + databasePassword + ";Charset=utf8" + ";Allow User Variables=True" - + ";Pooling=true"; + + ";Pooling=True"; mySqlConnect = new MySqlConnection(sConnection); mySqlConnect.Open(); iRetval = 0; diff --git a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs index c69559f..f19bd95 100644 --- a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs +++ b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs @@ -38,6 +38,7 @@ private string stability10; private string stability20; private string stability100; + private string isDetecting; public long Id { get @@ -161,5 +162,6 @@ public string Stability20 { get => stability20; set => stability20 = value; } public string Stability100 { get => stability100; set => stability100 = value; } public string Stability1 { get => stability1; set => stability1 = value; } + public string IsDetecting { get => isDetecting; set => isDetecting = value; } } } \ No newline at end of file diff --git a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs index 399098b..781749c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs @@ -9,7 +9,7 @@ { interface DetectionService { - int add(long deviceId, string frequency, string detecItemType, long detectionItemId); + int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time); List search(long deviceId, string detectionType, string startTime, string endTime, long detectionItemId); diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs index 0fd7b24..4df249b 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs @@ -132,7 +132,30 @@ string sQry = "SELECT * FROM r_counter_check_params"; 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) + // { + // if (row[0] != DBNull.Value) counterCheckParam.Id = Convert.ToInt32(row[0]); + // if (row[1] != DBNull.Value) counterCheckParam.SoOutDelay = row[1].ToString(); + // if (row[2] != DBNull.Value) counterCheckParam.SoEleFrequency = row[2].ToString(); + // if (row[3] != DBNull.Value) counterCheckParam.SoEleAddValue = row[3].ToString(); + // if (row[4] != DBNull.Value) counterCheckParam.SoEleAlarm = row[4].ToString(); + // if (row[5] != DBNull.Value) counterCheckParam.FreThreshold1 = row[5].ToString(); + // if (row[6] != DBNull.Value) counterCheckParam.FreThreshold2 = row[6].ToString(); + // if (row[7] != DBNull.Value) counterCheckParam.FreEleAddValue = row[7].ToString(); + // if (row[8] != DBNull.Value) counterCheckParam.CycThreshold1 = row[8].ToString(); + // if (row[9] != DBNull.Value) counterCheckParam.CycThreshold2 = row[9].ToString(); + // if (row[10] != DBNull.Value) counterCheckParam.CycEleAddValue = row[10].ToString(); + + // } + //} using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -149,10 +172,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(Exception ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs index 52b36f8..2c60ab4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs @@ -32,28 +32,29 @@ //先查询是否有历史数据 string sQry = "select ID from r_counter_data where DEVICE_ID=" + deviceId + " and OUT_VALUE = '" + outValue + "'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - - if (aReader.Read()) + bool isUpdated = false; + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - dataId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) + { + dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + + " where ID=" + dataId; + + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; + cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; + cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; + + cmd.ExecuteNonQuery(); + isUpdated = true; + } aReader.Close(); - sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + - " where ID="+ dataId; - - cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; - cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; - cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; - cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; - - cmd.ExecuteNonQuery(); - } - else - { - aReader.Close(); - + if (!isUpdated) + { sQry = "INSERT INTO r_counter_data (DEVICE_ID, OUT_VALUE, VALUE, SENSITIVITY, LOG_TIME, DETEC_TYPE)" + "values(@DEVICE_ID,@OUT_VALUE,@VALUE,@SENSITIVITY,@LOG_TIME,@DETEC_TYPE)"; @@ -70,14 +71,14 @@ sQry = "SELECT max(ID) from r_counter_data"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - - aReader = cmd.ExecuteReader(); - - if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); - + using (MySqlDataReader aReader = cmd.ExecuteReader()) + { + + if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + } } - aReader.Close(); cmd.Dispose(); iRetval = 0; @@ -144,6 +145,8 @@ cmd.ExecuteNonQuery(); } + + aReader.Close(); } @@ -282,9 +285,10 @@ if (!aReader.IsDBNull(6)) counterData.DetecType = aReader.GetString(6); counterDataList.Add(counterData); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs index 6795325..7500bd4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs @@ -47,10 +47,11 @@ counterDetecInitList.Add(counterDetecInit); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -75,29 +76,31 @@ return iRetval; } } - string sQry = "select ID from r_counter_detec_init where FREQUENCY=" + frequency +" AND CYCLE="+cycle; + string sQry = "select ID from r_counter_detec_init where FREQUENCY='" + frequency +"' AND CYCLE='"+cycle+"'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - if (aReader.Read()) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - initId = Convert.ToInt64(aReader.GetString(0)); - sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; + if (aReader.Read()) + { + initId = Convert.ToInt64(aReader.GetString(0)); + sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; - 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(); - } - else - { - 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 = 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(); + } + else + { + 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.ExecuteNonQuery(); + + } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); iRetval = 0; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs index 97b06ba..abcbaa6 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs @@ -72,26 +72,27 @@ MySqlCommand cmd = new MySqlCommand(sql, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(CommandBehavior.Default); - - if (aReader != null) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) + if (aReader != null) { - //判断门的状态 - if (!aReader.IsDBNull(0)) - counterParam.Id = Convert.ToInt32(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) - counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) - counterParam.BaudRate = aReader.GetString(2); - if (!aReader.IsDBNull(3)) - counterParam.GeneratorIp = aReader.GetString(3); - if (!aReader.IsDBNull(4)) - counterParam.SignalSourceIp = aReader.GetString(4); + if (aReader.Read()) + { + //判断门的状态 + if (!aReader.IsDBNull(0)) + counterParam.Id = Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(1)) + counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); + if (!aReader.IsDBNull(2)) + counterParam.BaudRate = aReader.GetString(2); + if (!aReader.IsDBNull(3)) + counterParam.GeneratorIp = aReader.GetString(3); + if (!aReader.IsDBNull(4)) + counterParam.SignalSourceIp = aReader.GetString(4); + } } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs index cca90fb..1578937 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs @@ -33,8 +33,8 @@ MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@DEVICE_ID", MySqlDbType.Int64, 20).Value = deviceId; - cmd.Parameters.Add("@START_TIME", MySqlDbType.String, 50).Value = startTime; - cmd.Parameters.Add("@END_TIME", MySqlDbType.String, 50).Value = endTime; + cmd.Parameters.Add("@START_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(startTime); + cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(endTime); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 50).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 50).Value = accuracy; cmd.Parameters.Add("@BOOT_FEATURE", MySqlDbType.String, 50).Value = bootFeature; @@ -58,11 +58,11 @@ sQry = "SELECT max(ID) from r_detection_item"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = cmd.ExecuteReader()) { if (aReader.Read()) detectionId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); iRetval = 0; @@ -203,8 +203,9 @@ if (!stability100.Equals("")) sQry = sQry + " STABILITY_100=@STABILITY_100,"; sQry = sQry + " COUNTER_DETEC=@COUNTER_DETEC where ID = " + detectionId; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry: " + sQry); - + MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 10).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 10).Value = accuracy; @@ -283,7 +284,8 @@ return iRetval; } } - + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "停止检测 detectionItemId=======" + detectionItemId); + string sQry = "UPDATE r_device SET STATUSID="+"1"+", CHANNEL=@CHANNEL where ID=" + deviceId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@CHANNEL", MySqlDbType.String, 20).Value = ""; @@ -292,19 +294,21 @@ if (isDeleteData) { - sQry = "DELETE FROM r_detection_item WHERE DEVICE_ID = " + deviceId + " AND START_TIME='" + startTime + "' AND END_TIME='" + endTime + "'"; + sQry = "DELETE FROM r_detection_item WHERE ID=" + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); - sQry = "DELETE FROM r_detection WHERE DEVICE_ID = " + deviceId + " AND (LOG_TIME between'" + startTime + "' and '" + endTime + "')"; + sQry = "DELETE FROM r_detection WHERE DETECTION_ITEM_ID = " + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); } else { - sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME WHERE ID="+ detectionItemId; + sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME, IS_DETECTING=@IS_DETECTING WHERE ID=" + detectionItemId; + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 20).Value = DateTime.Now; + cmd.Parameters.Add("@IS_DETECTING", MySqlDbType.String, 1).Value = "0"; //0-否,1-是 cmd.ExecuteNonQuery(); } @@ -322,8 +326,7 @@ { DetectionItem detectionItem = null; try - { - + { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getById : 数据库链接断开"); @@ -337,6 +340,7 @@ string sQry = "select * from r_detection_item WHERE ID = "+ detectionItemId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + using (MySqlDataReader aReader = cmd.ExecuteReader()) { while (aReader.Read()) @@ -356,11 +360,13 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(15)) detectionItem.IsDetecting = aReader.GetString(15); } - } - + aReader.Close(); + } cmd.Dispose(); + } catch (MySqlException e) { @@ -400,7 +406,7 @@ { DetectionItem detectionItem = new DetectionItem(); //姓名 - if (!aReader.IsDBNull(0)) detectionItem.Id=Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(0)) detectionItem.Id = Convert.ToInt32(aReader.GetString(0)); if (!aReader.IsDBNull(1)) detectionItem.DeviceId = Convert.ToInt64(aReader.GetString(1)); if (!aReader.IsDBNull(2)) detectionItem.StartTime = aReader.GetString(2); if (!aReader.IsDBNull(3)) detectionItem.EndTime = aReader.GetString(3); @@ -416,9 +422,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -468,9 +475,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -498,7 +506,6 @@ string sQry = "SELECT * FROM r_detection_item where ID = " + detectionId; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -518,15 +525,43 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); + //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) + // { + // detectionItem = new DetectionItem(); + // if (row[0] != DBNull.Value) detectionItem.Id = Convert.ToInt64(row[0]); + // if (row[1] != DBNull.Value) detectionItem.DeviceId = Convert.ToInt64(row[1]); + // if (row[2] != DBNull.Value) detectionItem.StartTime = Convert.ToDateTime(row[2]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[3] != DBNull.Value) detectionItem.EndTime = Convert.ToDateTime(row[3]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[4] != DBNull.Value) detectionItem.Stability = row[4].ToString(); + // if (row[5] != DBNull.Value) detectionItem.Accuracy = row[5].ToString(); + // if (row[6] != DBNull.Value) detectionItem.BootFeature = row[6].ToString(); + // if (row[7] != DBNull.Value) detectionItem.AgeRate = row[7].ToString(); + // if (row[8] != DBNull.Value) detectionItem.Interval = row[8].ToString(); + // if (row[10] != DBNull.Value) detectionItem.Channel = row[10].ToString(); + // if (row[11] != DBNull.Value) detectionItem.Stability1 = row[11].ToString(); + // if (row[12] != DBNull.Value) detectionItem.Stability10 = row[12].ToString(); + // if (row[13] != DBNull.Value) detectionItem.Stability20 = row[13].ToString(); + // if (row[14] != DBNull.Value) detectionItem.Stability100 = row[14].ToString(); + + // } + //} } catch (MySqlException ex) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDetectionItem: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchById: " + ex.Message); } return detectionItem; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs index e2a5893..5b3deb0 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs @@ -14,7 +14,7 @@ { class DetectionServiceImpl : DetectionService { - public int add(long deviceId, string frequency, string detecItemType, long detectionItemId) + public int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time) { int iRetval = -1; try @@ -36,7 +36,7 @@ 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 = DateTime.Now; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.DateTime, 0).Value = time; cmd.Parameters.Add("@DETECTION_ITEM", MySqlDbType.String, 0).Value = detecItemType; cmd.Parameters.Add("@DETECTION_ITEM_ID", MySqlDbType.Int64, 0).Value = detectionItemId; @@ -108,24 +108,26 @@ string sQry = "SELECT * FROM r_detection where DEVICE_ID = " + deviceId +" and DETECTION_ITEM='" + detectionType + "' and (LOG_TIME BETWEEN '" + startTime + "' and '"+ endTime + "') and DETECTION_ITEM_ID="+detectionItemId+" order by LOG_TIME"; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) { - Model.Detection detection = new Model.Detection(); - //姓名 - if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) detection.LogTime = Convert.ToDateTime(aReader.GetString(2)).ToString("yyyy-MM-dd HH:mm:ss"); - if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); - if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); + Detection detection = new Detection(); + + if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); // id + if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); // devName + if (!aReader.IsDBNull(2)) detection.LogTime = aReader.GetString(2); // devCode + if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); // devType + if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); // devModel detectionDtoList.Add(detection); } + aReader.Close(); + - aCommand.Dispose(); } + aCommand.Dispose(); + } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs index 9413e2f..b224bc1 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs @@ -53,7 +53,8 @@ using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); @@ -87,8 +88,7 @@ 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; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry : "+ sQry + "; statusId="+ statusId); - + 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; @@ -183,7 +183,7 @@ } MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -208,10 +208,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -254,7 +255,30 @@ 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()) @@ -279,10 +303,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -342,7 +367,30 @@ 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()) @@ -372,10 +420,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -442,9 +491,10 @@ { totalCount = aReader.GetInt32(0); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -477,89 +527,45 @@ return null; } } - - string sQry = "SELECT * FROM r_deviceview where ACTIVE = 0 and STATUSID = 2 " + "and ('" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' <= END_TIME)"; - - 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) + //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))"; + MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { - foreach (DataRow row in dt.Rows) + while (aReader.Read()) { DeviceView deviceView = new DeviceView(); - if (row[0] != DBNull.Value) deviceView.Id = Convert.ToInt64(row[0]); - if (row[1] != DBNull.Value) deviceView.DevName = row[1].ToString(); - if (row[2] != DBNull.Value) deviceView.DevCode = row[2].ToString(); - if (row[3] != DBNull.Value) deviceView.DevTypeId = row[3].ToString(); - if (row[4] != DBNull.Value) deviceView.DevModel = row[4].ToString(); - if (row[5] != DBNull.Value) deviceView.RegTime = row[5].ToString(); - if (row[6] != DBNull.Value) deviceView.CustomerName = row[6].ToString(); - if (row[7] != DBNull.Value) deviceView.CustomerDev = row[7].ToString(); - if (row[8] != DBNull.Value) deviceView.Channel = row[8].ToString(); - if (row[9] != DBNull.Value) deviceView.Active = Convert.ToInt32(row[9]); - if (row[10] != DBNull.Value) deviceView.StartTime = Convert.ToDateTime(row[10]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[11] != DBNull.Value) deviceView.EndTime = Convert.ToDateTime(row[11]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[12] != DBNull.Value) deviceView.StatusId = row[12].ToString(); - if (row[13] != DBNull.Value) deviceView.Stability = row[13].ToString(); - if (row[14] != DBNull.Value) deviceView.Accuracy = row[14].ToString(); - if (row[15] != DBNull.Value) deviceView.BootFeature = row[15].ToString(); - if (row[16] != DBNull.Value) deviceView.AgeRate = row[16].ToString(); - if (row[17] != DBNull.Value) deviceView.DetectionItemId = Convert.ToInt64(row[17]); + 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(); + + } - //using (MySqlDataReader aReader = aCommand.ExecuteReader()) - //{ - // while (aReader.Read()) - // { - // DeviceView deviceView = new DeviceView(); + aCommand.Dispose(); - // 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 - // //deviceView.DevTypeName = dictService.getNameByCode("devType", aReader.GetString(3)); - // } - // if (!aReader.IsDBNull(4)) deviceView.DevModel = aReader.GetString(4); // devModel - // if (!aReader.IsDBNull(5)) - // { - // DateTime reg = aReader.GetDateTime(5); // regTime - // deviceView.RegTime = reg.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); - // if (!aReader.IsDBNull(9)) deviceView.Active = Convert.ToInt32(aReader.GetString(9)); - // if (!aReader.IsDBNull(10)) - // { - // DateTime reg = aReader.GetDateTime(10); // regTime - // deviceView.StartTime = reg.ToString("yyyy-MM-dd HH:mm:ss"); - // } - // if (!aReader.IsDBNull(11)) - // { - // DateTime reg = aReader.GetDateTime(11); // regTime - // deviceView.EndTime = reg.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 = Convert.ToInt64(aReader.GetString(17)); - - // deviceViewList.Add(deviceView); - - // aCommand.Dispose(); - // } - //} - if (deviceViewList.Count > 0) { foreach (DeviceView deviceView in deviceViewList) @@ -568,9 +574,15 @@ } } } + + 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()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getDeviceByChannel: " + ex.Message + " ; " + ex.ToString()); deviceViewList = null; } finally diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs index 1626aa5..42ca83c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs @@ -92,10 +92,11 @@ if (!aReader.IsDBNull(3)) dict.Code = aReader.GetString(3); nameList.Add(dict); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(MySqlException ex) { @@ -139,10 +140,11 @@ if (!aReader.IsDBNull(3)) counterParam.GeneratorIp = aReader.GetString(3); if (!aReader.IsDBNull(4)) counterParam.SignalSourceIp = aReader.GetString(4); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -220,10 +222,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/RbFreqStdMeas.cs b/RbFreqStandMeasure/RbFreqStdMeas.cs index beae3dc..8d74572 100644 --- a/RbFreqStandMeasure/RbFreqStdMeas.cs +++ b/RbFreqStandMeasure/RbFreqStdMeas.cs @@ -363,24 +363,7 @@ detectionItemService.stopDetection(deviceId, device.DetectionItemId, startTime, endTime, true); } } - deviceService.clearChannel(); - List detectionItemList = detectionItemService.getAll(); - if (detectionItemList != null && detectionItemList.Count > 0) - { - foreach (DetectionItem detectionItem in detectionItemList) - { - long detectionItemId = detectionItem.Id; - if (detectionItem.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem.Stability1.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "0", "", "", ""); - if (detectionItem.Stability10.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "0", "", ""); - if (detectionItem.Stability20.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "0", ""); - if (detectionItem.Stability100.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "", "0"); - if (detectionItem.Accuracy.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "0", "", "", "", "", "", "", ""); - if (detectionItem.BootFeature.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "0", "", "", "", "", "", ""); - if (detectionItem.AgeRate.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "0", "", "", "", "", ""); - } - } - + deviceService.clearChannel(); } else { @@ -590,7 +573,7 @@ break; case 3: // 频率计数器范围 - CounterCtrlForm counterForm = CounterCtrlForm.GetInstance(); + CounterCtrlForm counterForm = new CounterCtrlForm(); counterForm.Show(); panelMain.Controls.Add(counterForm); break; diff --git a/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe b/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe index 70dc261..11271b0 100644 --- a/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe +++ b/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe Binary files differ diff --git a/RbFreqStandMeasure/counter/CounterCtrlForm.cs b/RbFreqStandMeasure/counter/CounterCtrlForm.cs index 951a19c..e45f17b 100644 --- a/RbFreqStandMeasure/counter/CounterCtrlForm.cs +++ b/RbFreqStandMeasure/counter/CounterCtrlForm.cs @@ -39,6 +39,9 @@ GPIBService tcpService = new TCPServiceImpl(); string valueOld = ""; + string valueOldBack = ""; + string valueOldSensi = ""; + string valueOldTime = ""; #region 样式常量定影 private readonly Color titleBackColor = Color.FromArgb(63, 132, 215); // #3F64D7 @@ -55,8 +58,8 @@ return _counterCtrlForm; } - - private CounterCtrlForm() + + public CounterCtrlForm() { InitializeComponent(); @@ -69,7 +72,7 @@ comboBox_detecModel.SelectedIndex = 0; InitTableCounter(); - LoadCounterDetecInitList(); + //LoadCounterDetecInitList(); if (list != null && list.Count > 0) { @@ -221,12 +224,12 @@ table_counterDetecInit.Columns.Add("initId", Type.GetType("System.Int32")); table_counterDetecInit.Columns.Add("counterDataId", Type.GetType("System.Int64")); - if (comboBox_counters.Text != "") + if (((DeviceDto)comboBox_counters.SelectedItem).DevName != "") { - List list = deviceService.search(comboBox_counters.Text, "", "", "", "", ""); + List list = deviceService.search(((DeviceDto)comboBox_counters.SelectedItem).DevName, "", "", "", "", ""); if (null != list && list.Count > 0) { - devType = list[0].DevTypeName; + devType = list[0].DevModel; devCode = list[0].DevCode; } @@ -344,6 +347,18 @@ { valueOld = dataGridView_CounterResult.CurrentCell.Value.ToString(); } + else if (e.ColumnIndex == 5) + { + valueOldBack = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } + else if (e.ColumnIndex == 6) + { + valueOldSensi = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } + else if (e.ColumnIndex == 7) + { + valueOldTime = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } } @@ -522,7 +537,10 @@ dataGridView_CounterResult.ReadOnly = true; btn_add.Enabled = false; benDelete.Enabled = false; - ///btn_dropDetecModel.Enabled = false; + comboBox_counters.Enabled = false; + comboBox_detecModel.Enabled = false; + text_counterIp.ReadOnly = true; + text_signal.ReadOnly = true; string[] arr = text_counterIp.Text.Split('.'); if (arr.Length != 4) @@ -643,11 +661,11 @@ Invoke(new MethodInvoker(delegate () { SetDevTestDlg.inDetecCounterId = -1; - //text_devName.ReadOnly = false; - //btn_downCounterList.Enabled = true; btnStart.Enabled = true; - //btn_dropDetecModel.Enabled = true; - //textBox_detecModel.ReadOnly = false; + comboBox_counters.Enabled = true; + comboBox_detecModel.Enabled = true; + text_counterIp.ReadOnly = false; + text_signal.ReadOnly = false; })); dataGridView_CounterResult.ReadOnly = false; @@ -736,6 +754,8 @@ if (!checkFreq(value)) { MessageBox.Show("请输入格式正确的测量频率值!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldBack; + valueOldBack = ""; return; } } @@ -744,6 +764,8 @@ if (!checkCyc(value)) { MessageBox.Show("请输入格式正确的测量周期值!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldBack; + valueOldBack = ""; return; } } @@ -753,11 +775,21 @@ { if (!String.IsNullOrEmpty(value)) { + if (value.Contains(".") && ((value.IndexOf('.') != value.LastIndexOf('.')) || value.IndexOf('.') == 0 || value.LastIndexOf('.') == value.Length)) + { + MessageBox.Show("请输入格式正确的灵敏度!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldSensi; + valueOldSensi = ""; + return; + } + string pattern = @"^[0-9.]+$"; Regex regex = new Regex(pattern); if (!regex.IsMatch(value)) { MessageBox.Show("请输入格式正确的灵敏度!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldSensi; + valueOldSensi = ""; return; } } @@ -772,7 +804,8 @@ } catch { - dataGridView_CounterResult.Rows[e.RowIndex].Cells[7].Value = ""; + dataGridView_CounterResult.CurrentCell.Value = valueOldTime; + valueOldTime = ""; MessageBox.Show("请输入格式正确的时间!"); return; } diff --git a/RbFreqStandMeasure/home/HomeCtrlForm.cs b/RbFreqStandMeasure/home/HomeCtrlForm.cs index b2568f7..586334d 100644 --- a/RbFreqStandMeasure/home/HomeCtrlForm.cs +++ b/RbFreqStandMeasure/home/HomeCtrlForm.cs @@ -7,6 +7,7 @@ using Casic.Birmm.RbFreqStandMeasure.Tools; using DevComponents.DotNetBar.Controls; using System; +using System.Collections; using System.Collections.Generic; using System.Data; using System.Drawing; @@ -23,16 +24,16 @@ public partial class HomeCtrlForm : UserControl { public static HomeCtrlForm homeCtrlForm; - int totalCount = 0; - int currentPage = 1; - int pageCount = 0; - int limitCount = 4; + public int totalCount = 0; + public int currentPage = 1; + public int pageCount = 0; + public int limitCount = 4; DataTable devToBeTestedTable = null; DataTable channelsTable = null; DeviceService deviceService = new DeviceServiceImpl(); List listChannelStatus = new List(); DetectionItemService detectionItemService = new DetectionItemServiceImpl(); - + public static Hashtable stoppedItemIdTable = new Hashtable(); public static List channelFreeList = new List(); private readonly object obj = new object(); @@ -166,10 +167,7 @@ Size = new Size(120, 32) }; tableToBeTested.Controls.Add(colCustomComp); - colCustomComp.BringToFront(); - - - + colCustomComp.BringToFront(); totalCount = 0; currentPage = 1; @@ -332,7 +330,7 @@ AutoSize = false, Text = "通道", Location = new Point(0, 0), - Size = new Size(50, 30) + Size = new Size(70, 30) }; dataGridView_Channel.Controls.Add(colChannelNo); colChannelNo.BringToFront(); @@ -346,7 +344,7 @@ BackColor = titleBackColor, AutoSize = false, Text = "仪器名称", - Location = new Point(50, 0), + Location = new Point(70, 0), Size = new Size(110, 30) }; dataGridView_Channel.Controls.Add(colDevName); @@ -361,8 +359,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "仪器编号", - Location = new Point(160, 0), - Size = new Size(110, 30) + Location = new Point(180, 0), + Size = new Size(120, 30) }; dataGridView_Channel.Controls.Add(colDevNo); colDevNo.BringToFront(); @@ -376,8 +374,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "送检单位", - Location = new Point(270, 0), - Size = new Size(110, 30) + Location = new Point(300, 0), + Size = new Size(120, 30) }; dataGridView_Channel.Controls.Add(colCustomName); colCustomName.BringToFront(); @@ -391,8 +389,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "开始时间", - Location = new Point(380, 0), - Size = new Size(120, 30) + Location = new Point(420, 0), + Size = new Size(100, 30) }; dataGridView_Channel.Controls.Add(colStartTime); colStartTime.BringToFront(); @@ -406,8 +404,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "结束时间", - Location = new Point(500, 0), - Size = new Size(120, 30) + Location = new Point(520, 0), + Size = new Size(100, 30) }; dataGridView_Channel.Controls.Add(colEndTime); colEndTime.BringToFront(); @@ -492,6 +490,11 @@ dataGridView_Channel.Controls.Add(colAgingRate); colAgingRate.BringToFront(); } + + + + + } catch (Exception ex) { @@ -506,19 +509,22 @@ { lock (obj) { - channelFreeList.Clear(); - channelFreeList.Add("1"); - channelFreeList.Add("2"); - channelFreeList.Add("3"); - channelFreeList.Add("4"); - channelFreeList.Add("5"); - - listChannelStatus = deviceService.getDeviceByChannel(); - if (listChannelStatus != null && listChannelStatus.Count > 0) + // lock (channelFreeList) { - foreach (DeviceView device in listChannelStatus) + channelFreeList.Clear(); + channelFreeList.Add("1"); + channelFreeList.Add("2"); + channelFreeList.Add("3"); + channelFreeList.Add("4"); + channelFreeList.Add("5"); + + listChannelStatus = deviceService.getDeviceByChannel(); + if (listChannelStatus != null && listChannelStatus.Count > 0) { - channelFreeList.Remove(device.Channel); + foreach (DeviceView device in listChannelStatus) + { + channelFreeList.Remove(device.Channel); + } } } } @@ -533,125 +539,131 @@ { try { - lock (obj) + //Invoke(new MethodInvoker(delegate () { - channelsTable = new DataTable(); - - channelsTable.Columns.Add("channelNo", Type.GetType("System.String")); - channelsTable.Columns.Add("devName", Type.GetType("System.String")); - channelsTable.Columns.Add("devCode", Type.GetType("System.String")); - channelsTable.Columns.Add("customComp", Type.GetType("System.String")); - channelsTable.Columns.Add("startTime", Type.GetType("System.String")); - channelsTable.Columns.Add("endTime", Type.GetType("System.String")); - channelsTable.Columns.Add("channelStatus", Type.GetType("System.String")); - channelsTable.Columns.Add("stablility", Type.GetType("System.String")); - channelsTable.Columns.Add("accuracy", Type.GetType("System.String")); - channelsTable.Columns.Add("startup", Type.GetType("System.String")); - channelsTable.Columns.Add("agingRate", Type.GetType("System.String")); - channelsTable.Columns.Add("deviceId", Type.GetType("System.Int64")); - channelsTable.Columns.Add("deviceItemId", Type.GetType("System.Int64")); - //channelsTable.Columns.Add("devType", Type.GetType("System.String")); - //channelsTable.Columns.Add("devModel", Type.GetType("System.String")); - //channelsTable.Columns.Add("customCom", Type.GetType("System.String")); - - listChannelStatus = deviceService.getDeviceByChannel(); - - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelFreeList.Clear(); - channelFreeList.Add("1"); - channelFreeList.Add("2"); - channelFreeList.Add("3"); - channelFreeList.Add("4"); - channelFreeList.Add("5"); - - if (listChannelStatus != null && listChannelStatus.Count > 0) + lock (obj) { - foreach (DeviceView device in listChannelStatus) + //lock(channelFreeList) { - channelFreeList.Remove(device.Channel); - int index = Convert.ToInt32(device.Channel) - 1; - channelsTable.Rows[index]["channelNo"] = device.Channel; - channelsTable.Rows[index]["devName"] = device.DevName; - channelsTable.Rows[index]["devCode"] = device.DevCode; - channelsTable.Rows[index]["customComp"] = device.CustomerDev; - channelsTable.Rows[index]["startTime"] = device.StartTime; - channelsTable.Rows[index]["endTime"] = device.EndTime; - channelsTable.Rows[index]["channelStatus"] = "占用"; - channelsTable.Rows[index]["deviceId"] = device.Id; - channelsTable.Rows[index]["deviceItemId"] = device.DetectionItemId; + channelsTable = new DataTable(); - if (device.Stability.Equals("-3")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.Stability.Equals("-2")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.Stability.Equals("-1")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + channelsTable.Columns.Add("channelNo", Type.GetType("System.String")); + channelsTable.Columns.Add("devName", Type.GetType("System.String")); + channelsTable.Columns.Add("devCode", Type.GetType("System.String")); + channelsTable.Columns.Add("customComp", Type.GetType("System.String")); + channelsTable.Columns.Add("startTime", Type.GetType("System.String")); + channelsTable.Columns.Add("endTime", Type.GetType("System.String")); + channelsTable.Columns.Add("channelStatus", Type.GetType("System.String")); + channelsTable.Columns.Add("stablility", Type.GetType("System.String")); + channelsTable.Columns.Add("accuracy", Type.GetType("System.String")); + channelsTable.Columns.Add("startup", Type.GetType("System.String")); + channelsTable.Columns.Add("agingRate", Type.GetType("System.String")); + channelsTable.Columns.Add("deviceId", Type.GetType("System.Int64")); + channelsTable.Columns.Add("deviceItemId", Type.GetType("System.Int64")); - if (device.Accuracy.Equals("-3")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.Accuracy.Equals("-2")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.Accuracy.Equals("-1")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; - - if (device.AgeRate.Equals("-3")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.AgeRate.Equals("-2")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.AgeRate.Equals("-1")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; - - if (device.BootFeature.Equals("-3")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.BootFeature.Equals("-2")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.BootFeature.Equals("-1")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + listChannelStatus = deviceService.getDeviceByChannel(); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelFreeList.Clear(); + channelFreeList.Add("1"); + channelFreeList.Add("2"); + channelFreeList.Add("3"); + channelFreeList.Add("4"); + channelFreeList.Add("5"); + + if (listChannelStatus != null && listChannelStatus.Count > 0) + { + foreach (DeviceView device in listChannelStatus) + { + if (String.IsNullOrEmpty(device.Channel)) continue; + channelFreeList.Remove(device.Channel); + int index = Convert.ToInt32(device.Channel) - 1; + channelsTable.Rows[index]["channelNo"] = device.Channel; + channelsTable.Rows[index]["devName"] = device.DevName; + channelsTable.Rows[index]["devCode"] = device.DevCode; + channelsTable.Rows[index]["customComp"] = device.CustomerDev; + channelsTable.Rows[index]["startTime"] = device.StartTime; + channelsTable.Rows[index]["endTime"] = device.EndTime; + channelsTable.Rows[index]["channelStatus"] = "占用"; + channelsTable.Rows[index]["deviceId"] = device.Id; + channelsTable.Rows[index]["deviceItemId"] = device.DetectionItemId; + + if (device.Stability.Equals("-3")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.Stability.Equals("-2")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.Stability.Equals("-1")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + if (device.Accuracy.Equals("-3")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.Accuracy.Equals("-2")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.Accuracy.Equals("-1")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + if (device.AgeRate.Equals("-3")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.AgeRate.Equals("-2")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.AgeRate.Equals("-1")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + if (device.BootFeature.Equals("-3")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.BootFeature.Equals("-2")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.BootFeature.Equals("-1")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + + } + } + else + { + channelsTable.Rows.Clear(); + channelsTable.Rows.Add("1", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("2", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("3", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("4", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("5", "", "", "", "", "", "空闲", "", ""); + } + + foreach (string no in channelFreeList) + { + channelsTable.Rows[Convert.ToInt32(no) - 1]["channelNo"] = no; + channelsTable.Rows[Convert.ToInt32(no) - 1]["channelStatus"] = "空闲"; + } + + + dataGridView_Channel.DataSource = channelsTable; + + // width=764px + dataGridView_Channel.Columns[11].Visible = false; + dataGridView_Channel.Columns[12].Visible = false; + dataGridView_Channel.Columns[0].Width = 70; + dataGridView_Channel.Columns[1].Width = 110; + dataGridView_Channel.Columns[2].Width = 120; + dataGridView_Channel.Columns[3].Width = 120; + dataGridView_Channel.Columns[4].Width = 100; //starttime + dataGridView_Channel.Columns[5].Width = 100; //endtime + dataGridView_Channel.Columns[6].Width = 64; + dataGridView_Channel.Columns[7].Width = 75; + dataGridView_Channel.Columns[8].Width = 75; + dataGridView_Channel.Columns[9].Width = 75; + dataGridView_Channel.Columns[10].Width = 75; + + dataGridView_Channel.Columns[0].ReadOnly = true; + dataGridView_Channel.Columns[1].ReadOnly = true; + dataGridView_Channel.Columns[2].ReadOnly = true; + dataGridView_Channel.Columns[3].ReadOnly = true; + dataGridView_Channel.Columns[4].ReadOnly = true; + dataGridView_Channel.Columns[5].ReadOnly = true; + dataGridView_Channel.Columns[6].ReadOnly = true; + dataGridView_Channel.Columns[7].ReadOnly = true; + dataGridView_Channel.Columns[8].ReadOnly = true; + dataGridView_Channel.Columns[9].ReadOnly = true; + dataGridView_Channel.Columns[10].ReadOnly = true; } } - else - { - channelsTable.Rows.Clear(); - channelsTable.Rows.Add("1", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("2", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("3", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("4", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("5", "", "", "", "", "", "空闲", "", ""); - } - - foreach (string no in channelFreeList) - { - channelsTable.Rows[Convert.ToInt32(no) - 1]["channelNo"] = no; - channelsTable.Rows[Convert.ToInt32(no) - 1]["channelStatus"] = "空闲"; - } - - - dataGridView_Channel.DataSource = channelsTable; - - // width=764px - dataGridView_Channel.Columns[11].Visible = false; - dataGridView_Channel.Columns[12].Visible = false; - dataGridView_Channel.Columns[0].Width = 50; - dataGridView_Channel.Columns[1].Width = 110; - dataGridView_Channel.Columns[2].Width = 110; - dataGridView_Channel.Columns[3].Width = 110; - dataGridView_Channel.Columns[4].Width = 120; - dataGridView_Channel.Columns[5].Width = 120; - dataGridView_Channel.Columns[6].Width = 64; - dataGridView_Channel.Columns[7].Width = 75; - dataGridView_Channel.Columns[8].Width = 75; - dataGridView_Channel.Columns[9].Width = 75; - dataGridView_Channel.Columns[10].Width = 75; - - dataGridView_Channel.Columns[0].ReadOnly = true; - dataGridView_Channel.Columns[1].ReadOnly = true; - dataGridView_Channel.Columns[2].ReadOnly = true; - dataGridView_Channel.Columns[3].ReadOnly = true; - dataGridView_Channel.Columns[4].ReadOnly = true; - dataGridView_Channel.Columns[5].ReadOnly = true; - dataGridView_Channel.Columns[6].ReadOnly = true; - dataGridView_Channel.Columns[7].ReadOnly = true; - dataGridView_Channel.Columns[8].ReadOnly = true; - dataGridView_Channel.Columns[9].ReadOnly = true; - dataGridView_Channel.Columns[10].ReadOnly = true; + //})); } } catch (Exception ex) @@ -760,7 +772,6 @@ private void cellDoubleClick(int rowIndex) { - int colIndex = dataGridView_Channel.CurrentCell.ColumnIndex; if (dataGridView_Channel.Rows[rowIndex].Cells[6].Value.ToString().Equals("占用")) { if (MessageBox.Show("该通道有正在检测的仪器,确定要停止检测?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) @@ -780,30 +791,22 @@ { return; } + DialogResult dialogResult = MessageBox.Show("是否保存此次检测的数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { - detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, false); + detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, false); } else { detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, true); } - DetectionItem detectionItem0 = detectionItemService.getById(deviceItemId); - if (detectionItem0 != null) - { - if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem0.Stability1.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "0", "", "", ""); - if (detectionItem0.Stability10.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "", "0", "", ""); - if (detectionItem0.Stability20.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "", "", "0", ""); - if (detectionItem0.Stability100.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "", "", "", "0"); - if (detectionItem0.Accuracy.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "0", "", "", "", "", "", "", ""); - if (detectionItem0.BootFeature.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "0", "", "", "", "", "", ""); - if (detectionItem0.AgeRate.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "0", "", "", "", "", ""); - - } + if (stoppedItemIdTable.Contains(rowIndex + 1)) stoppedItemIdTable.Remove(rowIndex + 1); + + stoppedItemIdTable.Add(rowIndex + 1, deviceItemId); LoadChannelStatus(); + currentPage = 1; LoadDevToBeTested(); } catch(Exception ex) diff --git a/RbFreqStandMeasure/home/SetDevChannelDlg.cs b/RbFreqStandMeasure/home/SetDevChannelDlg.cs index fe3bcdd..a1d96fe 100644 --- a/RbFreqStandMeasure/home/SetDevChannelDlg.cs +++ b/RbFreqStandMeasure/home/SetDevChannelDlg.cs @@ -84,9 +84,12 @@ timePicker_startTime.MinDate = DateTime.Now; getEndTime(); List listToTest = deviceService.search("", "", "", "", "", "1"); - foreach (DeviceDto deviceDto in listToTest) + if (listToTest != null && listToTest.Count > 0) { - cbBox_toTestDevList.Items.Add(deviceDto.DevCode); + foreach (DeviceDto deviceDto in listToTest) + { + cbBox_toTestDevList.Items.Add(deviceDto.DevCode); + } } text_customerDev.Visible = true; @@ -202,7 +205,7 @@ if (checkBox10s.Checked) stability10 = "-1"; if (checkBox20s.Checked) stability20 = "-1"; if (checkBox_100s.Checked) stability100 = "-1"; - detectionHelper.detecStability(deviceId, startTime, interval, port, true ,false); + detectionHelper.detecStability(deviceId, startTime, interval, port, true, false); } else { @@ -257,8 +260,10 @@ } long detectionId0 = detectionItemService.add(deviceId, startTime, endTime, stability, accuracy, bootFeature, ageRate, interval, textBox_channelNo.Text,stability1,stability10,stability20,stability100); detectionHelper.detectionItemId = detectionId0; + this.HideMaskAction(); HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + HomeCtrlForm.homeCtrlForm.currentPage = 1; HomeCtrlForm.homeCtrlForm.LoadDevToBeTested(); } catch (Exception ex) @@ -311,18 +316,18 @@ private void getEndTime() { - if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddSeconds(30); + if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddMinutes(1).AddSeconds(30); else { - if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddSeconds(30); + if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddMinutes(1).AddSeconds(30); else { if (checkBox_stability.Checked) { - if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddSeconds(40); - else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddSeconds(40); - else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddSeconds(40); - else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddSeconds(40); + if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddMinutes(1).AddSeconds(30); + else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddMinutes(1).AddSeconds(30); + else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddMinutes(1).AddSeconds(30); + else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddMinutes(1).AddSeconds(30); } else endTimeBySystem = timePicker_startTime.Value.AddMinutes(1).AddSeconds(30); } diff --git a/RbFreqStandMeasure/home/SetDevTestDlg.cs b/RbFreqStandMeasure/home/SetDevTestDlg.cs index f1027ba..6e9d272 100644 --- a/RbFreqStandMeasure/home/SetDevTestDlg.cs +++ b/RbFreqStandMeasure/home/SetDevTestDlg.cs @@ -23,11 +23,7 @@ public static long inDetecCounterId = -1;// 正在检测灵敏度的计数器id DateTime endTimeBySystem = new DateTime(); - CounterDataService CounterDataService = new CounterDataServiceImpl(); - CounterDetecInitService counterDetecInitService = new CounterDetecInitServiceImpl(); DictService dictService = new DictServiceImpl(); - SensitivityService sensitivityService = new SensitivityServiceImpl(); - CounterDataService counterDataService = new CounterDataServiceImpl(); DeviceService deviceService = new DeviceServiceImpl(); @@ -221,6 +217,7 @@ this.HideMaskAction(); HomeCtrlForm.homeCtrlForm.refreshChannelList(); HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + HomeCtrlForm.homeCtrlForm.currentPage = 1; HomeCtrlForm.homeCtrlForm.LoadDevToBeTested(); } @@ -280,18 +277,18 @@ private void getEndTime() { - if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddSeconds(30); + if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddMinutes(1).AddSeconds(30); else { - if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddSeconds(30); + if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddMinutes(1).AddSeconds(30); else { if (checkBox_stability.Checked) { - if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddSeconds(40); - else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddSeconds(40); - else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddSeconds(40); - else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddSeconds(40); + if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddMinutes(1).AddSeconds(30); + else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddMinutes(1).AddSeconds(30); + else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddMinutes(1).AddSeconds(30); + else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddMinutes(1).AddSeconds(30); } else endTimeBySystem = timePicker_startTime.Value.AddMinutes(1).AddSeconds(30); } diff --git a/RbFreqStandMeasure/info/AddDevDlg.cs b/RbFreqStandMeasure/info/AddDevDlg.cs index 46d4778..6abc5b0 100644 --- a/RbFreqStandMeasure/info/AddDevDlg.cs +++ b/RbFreqStandMeasure/info/AddDevDlg.cs @@ -254,16 +254,13 @@ { if (needDetec) statusId = "2"; devService.update(deviceId, devName, devCode, devTypeCode, devModel, devCustomComp, devCustomName, channelNo,statusId); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "update 完成"); - + } //添加检测 if (deviceId != -1 && needDetec) - { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "各项检测开始。。。。"); - + { //开始检测 //稳定度 @@ -337,9 +334,7 @@ detectionHelper.detecAgeRate(deviceId, startTime, port, false); } } - - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "更新检测记录表" + deviceId); - + //开始检测 long detectionId0 = detectionItemService.add(deviceId, startTime, endTime, stability, accuracy, bootFeature, ageRate, interval, text_channelNo.Text, stability1, stability10, stability20, stability100); detectionHelper.detectionItemId = detectionId0; @@ -439,18 +434,18 @@ private void getEndTime() { - if (checkBox_ageRate.Checked) endTimeBySystem = picker_startTime.Value.AddDays(7).AddSeconds(30); + if (checkBox_ageRate.Checked) endTimeBySystem = picker_startTime.Value.AddDays(7).AddMinutes(1).AddSeconds(30); else { - if (checkBox_bootFeature.Checked) endTimeBySystem = picker_startTime.Value.AddHours(7).AddSeconds(30); + if (checkBox_bootFeature.Checked) endTimeBySystem = picker_startTime.Value.AddHours(7).AddMinutes(1).AddSeconds(30); else { if (checkBox_stability.Checked) { - if (checkBox100s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 100).AddSeconds(40); - else if (checkBox20s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 20).AddSeconds(40); - else if (checkBox10s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 10).AddSeconds(40); - else if (checkBox1s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101).AddSeconds(40); + if (checkBox100s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 100).AddMinutes(1).AddSeconds(30); + else if (checkBox20s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 20).AddMinutes(1).AddSeconds(30); + else if (checkBox10s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 10).AddMinutes(1).AddSeconds(30); + else if (checkBox1s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101).AddMinutes(1).AddSeconds(30); } else endTimeBySystem = picker_startTime.Value.AddMinutes(1).AddSeconds(30); } diff --git a/RbFreqStandMeasure/info/DetailDlg.cs b/RbFreqStandMeasure/info/DetailDlg.cs index ad05a32..cc05eac 100644 --- a/RbFreqStandMeasure/info/DetailDlg.cs +++ b/RbFreqStandMeasure/info/DetailDlg.cs @@ -86,17 +86,17 @@ resultBootStr = dataGridView_times.Rows[0].Cells[5].Value.ToString(); resultAgeStr = dataGridView_times.Rows[0].Cells[6].Value.ToString(); - if (!resultAccStr.Equals("-1") && !resultAccStr.Equals("-2") && !resultAccStr.Equals("-3")) tabPageEvent("tab_accuracy"); - if ((!resultStaStr1.Equals("-1")&& !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3")) || (!resultStaStr10.Equals("-1")&& !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3")) ||( !resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3"))) + if (!resultAccStr.Equals("-1") && !resultAccStr.Equals("-2") && !resultAccStr.Equals("-3") && !resultAccStr.Equals("0")) tabPageEvent("tab_accuracy"); + if ((!resultStaStr1.Equals("-1")&& !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3") && !resultStaStr1.Equals("0")) || (!resultStaStr10.Equals("-1")&& !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3") && !resultStaStr10.Equals("0")) ||( !resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3") && !resultStaStr100.Equals("0"))) { tabPageEvent("tab_stability"); - if (!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3")) radio_1s.Checked = true; - else if (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3")) radio_10s.Checked = true; - else if(!resultStaStr20.Equals("-1") && !resultStaStr20.Equals("-2") && !resultStaStr20.Equals("-3")) radio_20s.Checked = true; - else if (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3")) radio_100s.Checked = true; + if (!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3") && !resultStaStr1.Equals("0")) loadStability1(); + else if (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3") && !resultStaStr10.Equals("0")) loadStability10(); + else if(!resultStaStr20.Equals("-1") && !resultStaStr20.Equals("-2") && !resultStaStr20.Equals("-3") && !resultStaStr20.Equals("0")) loadStability20(); + else if (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3") && !resultStaStr100.Equals("0")) loadStability100(); } - if (!resultBootStr.Equals("-1")&& !resultBootStr.Equals("-2")&& !resultBootStr.Equals("-3")) tabPageEvent("tab_bootFeature"); - if (!resultAgeStr.Equals("-1")&&!resultAgeStr.Equals("-2")&& !resultAgeStr.Equals("-3")) tabPageEvent("tab_ageRate"); + if (!resultBootStr.Equals("-1")&& !resultBootStr.Equals("-2")&& !resultBootStr.Equals("-3") && !resultBootStr.Equals("0")) tabPageEvent("tab_bootFeature"); + if (!resultAgeStr.Equals("-1")&&!resultAgeStr.Equals("-2")&& !resultAgeStr.Equals("-3") && !resultAgeStr.Equals("0")) tabPageEvent("tab_ageRate"); } if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; @@ -305,17 +305,17 @@ resultBootStr = dataGridView_times.Rows[rowIndex].Cells[5].Value.ToString(); resultAgeStr = dataGridView_times.Rows[rowIndex].Cells[6].Value.ToString(); - if (!resultAccStr.Equals("-1") && !resultAccStr.Equals("-2") && !resultAccStr.Equals("-3")) tabPageEvent("tab_accuracy"); - else if ((!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3")) || (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3")) || (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3"))) + if (!resultAccStr.Equals("-1") && !resultAccStr.Equals("-2") && !resultAccStr.Equals("-3") && !resultAccStr.Equals("0")) tabPageEvent("tab_accuracy"); + else if ((!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3") && !resultStaStr1.Equals("0")) || (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3") && !resultStaStr10.Equals("0")) || (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3") && !resultStaStr100.Equals("0"))) { tabPageEvent("tab_stability"); - if (!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3")) radio_1s.Checked = true; - else if (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3")) radio_10s.Checked = true; - else if (!resultStaStr20.Equals("-1") && !resultStaStr20.Equals("-2") && !resultStaStr20.Equals("-3")) radio_20s.Checked = true; - else if (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3")) radio_100s.Checked = true; + if (!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3") && !resultStaStr1.Equals("0")) loadStability1(); + else if (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3") && !resultStaStr10.Equals("0")) loadStability10(); + else if (!resultStaStr20.Equals("-1") && !resultStaStr20.Equals("-2") && !resultStaStr20.Equals("-3") && !resultStaStr20.Equals("0")) loadStability20(); + else if (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3") && !resultStaStr100.Equals("0")) loadStability100(); } - else if (!resultBootStr.Equals("-1") && !resultBootStr.Equals("-2") && !resultBootStr.Equals("-3")) tabPageEvent("tab_bootFeature"); - else if (!resultAgeStr.Equals("-1") && !resultAgeStr.Equals("-2") && !resultAgeStr.Equals("-3")) tabPageEvent("tab_ageRate"); + else if (!resultBootStr.Equals("-1") && !resultBootStr.Equals("-2") && !resultBootStr.Equals("-3") && !resultBootStr.Equals("0")) tabPageEvent("tab_bootFeature"); + else if (!resultAgeStr.Equals("-1") && !resultAgeStr.Equals("-2") && !resultAgeStr.Equals("-3") && !resultAgeStr.Equals("0")) tabPageEvent("tab_ageRate"); } } @@ -362,6 +362,7 @@ groupBox3.Text = "频率准确度"; accuracy result = new accuracy(); result.label_accuracy.Text = ""; + if (!resultAccStr.Equals("-1") && !resultAccStr.Equals("-2") && !resultAccStr.Equals("-3")) result.label_accuracy.Text = resultAccStr; result.Show(); panel_result.Controls.Add(result); @@ -476,70 +477,106 @@ private void radio_10s_CheckedChanged(object sender, EventArgs e) { if (radio_10s.Checked) - { - LoadData(deviceId, "1-10", startTime, endTime); - groupBox3.Text = "10s频率稳定度"; - panel_result.Controls.Clear(); - stability result = new stability(); - result.label_stability.Text = ""; - if (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3")) result.label_stability.Text = resultStaStr10; - result.Show(); - panel_result.Controls.Add(result); - btn_reDetec.Enabled = true; - if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + { + loadStability10(); } } + private void loadStability10() + { + radio_10s.Checked = true; + LoadData(deviceId, "1-10", startTime, endTime); + groupBox3.Text = "10s频率稳定度"; + panel_result.Controls.Clear(); + stability result = new stability(); + result.label_stability.Text = ""; + if (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3")) + { + result.label_stability.Text = resultStaStr10; + result.label_count.Text = "101"; + } + result.Show(); + panel_result.Controls.Add(result); + btn_reDetec.Enabled = true; + if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + } private void radio_1s_CheckedChanged(object sender, EventArgs e) { if (radio_1s.Checked) { - LoadData(deviceId, "1-1", startTime, endTime); - groupBox3.Text = "1s频率稳定度"; - panel_result.Controls.Clear(); - stability result = new stability(); - result.label_stability.Text = ""; - if (!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3")) result.label_stability.Text = resultStaStr1; - result.Show(); - btn_reDetec.Enabled = true; - panel_result.Controls.Add(result); - if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + loadStability1(); } } + private void loadStability1() + { + radio_1s.Checked = true; + LoadData(deviceId, "1-1", startTime, endTime); + groupBox3.Text = "1s频率稳定度"; + panel_result.Controls.Clear(); + stability result = new stability(); + result.label_stability.Text = ""; + if (!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3")) + { + result.label_stability.Text = resultStaStr1; + result.label_count.Text = "101"; + } + result.Show(); + btn_reDetec.Enabled = true; + panel_result.Controls.Add(result); + if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + } private void radio_20s_CheckedChanged(object sender, EventArgs e) { if (radio_20s.Checked) { - LoadData(deviceId, "1-20", startTime, endTime); - groupBox3.Text = "20s频率稳定度"; - panel_result.Controls.Clear(); - stability result = new stability(); - result.label_stability.Text = ""; - if (!resultStaStr20.Equals("-1")&& !resultStaStr20.Equals("-2")&&!resultStaStr20.Equals("-3")) result.label_stability.Text = resultStaStr20; - result.Show(); - panel_result.Controls.Add(result); - btn_reDetec.Enabled = true; - if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + loadStability20(); } } + private void loadStability20() + { + radio_20s.Checked = true; + LoadData(deviceId, "1-20", startTime, endTime); + groupBox3.Text = "20s频率稳定度"; + panel_result.Controls.Clear(); + stability result = new stability(); + result.label_stability.Text = ""; + if (!resultStaStr20.Equals("-1") && !resultStaStr20.Equals("-2") && !resultStaStr20.Equals("-3")) + { + result.label_stability.Text = resultStaStr20; + result.label_count.Text = "101"; + } + result.Show(); + panel_result.Controls.Add(result); + btn_reDetec.Enabled = true; + if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + } private void radio_100s_CheckedChanged(object sender, EventArgs e) { if (radio_100s.Checked) { - LoadData(deviceId, "1-100", startTime, endTime); - groupBox3.Text = "100s频率稳定度"; - panel_result.Controls.Clear(); - stability result = new stability(); - result.label_stability.Text = ""; - if (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3")) result.label_stability.Text = resultStaStr100; - result.Show(); - panel_result.Controls.Add(result); - btn_reDetec.Enabled = true; - if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + loadStability100(); } } + private void loadStability100() + { + radio_100s.Checked = true; + LoadData(deviceId, "1-100", startTime, endTime); + groupBox3.Text = "100s频率稳定度"; + panel_result.Controls.Clear(); + stability result = new stability(); + result.label_stability.Text = ""; + if (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3")) + { + result.label_stability.Text = resultStaStr100; + result.label_count.Text = "101"; + } + result.Show(); + panel_result.Controls.Add(result); + btn_reDetec.Enabled = true; + if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + } public void updateChannelNoRedetec() { diff --git a/RbFreqStandMeasure/tools/DetectionHelper.cs b/RbFreqStandMeasure/tools/DetectionHelper.cs index 2070bac..3faf914 100644 --- a/RbFreqStandMeasure/tools/DetectionHelper.cs +++ b/RbFreqStandMeasure/tools/DetectionHelper.cs @@ -1,18 +1,14 @@ using Casic.Birmm.RbFreqStandMeasure.info; -using Casic.Birmm.RbFreqStandMeasure.Properties; using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Model; using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Service; using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Service.Impl; using Casic.Birmm.RbFreqStandMeasure.Tools; using System; +using System.Collections; using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Drawing2D; using System.IO.Ports; -using System.Linq; using System.Reflection; using System.Text; -using System.Text.RegularExpressions; using System.Threading; using System.Windows.Forms; @@ -37,12 +33,12 @@ private System.Threading.Timer timerStability10; private System.Threading.Timer timerStability20; private System.Threading.Timer timerStability100; - private long devIdStability = -1; - private SerialPort portStability; - private List resultStability1 = new List(); - private List resultStability10 = new List(); - private List resultStability20 = new List(); - private List resultStability100 = new List(); + private long devIdStability = -1; + private SerialPort portStability; + private Hashtable resultStability1 = new Hashtable(); + private Hashtable resultStability10 = new Hashtable(); + private Hashtable resultStability20 = new Hashtable(); + private Hashtable resultStability100 = new Hashtable(); private System.Threading.Timer timerBootFeature; private long devIdBootFeature = -1; @@ -61,6 +57,7 @@ private int count10s = 0; private int count20s = 0; private bool isStarted = true; + private DetectionItem item=null; //1-STABILITY,2-ACCURACY,3-BOOT_FEATURE,4-AGE_RATE @@ -74,36 +71,44 @@ #region 稳定度 public void detecStability(long deviceId, string startTime, string interval, SerialPort port,bool isNow, bool isUpdates) { - resultStability1 = new List(); - resultStability10 = new List(); - resultStability20 = new List(); - resultStability100 = new List(); - count1s = 0; - count10s = 0; - count20s = 0; - if (isUpdates) + try { - isUpdate = true; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测稳定度 interval =" + interval + ";detectionItemId="+detectionItemId); + resultStability1 = new Hashtable(); + resultStability10 = new Hashtable(); + resultStability20 = new Hashtable(); + resultStability100 = new Hashtable(); + count1s = 0; + count10s = 0; + count20s = 0; + if (isUpdates) + { + isUpdate = true; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测稳定度 interval =" + interval + ";detectionItemId=" + detectionItemId); + } + portStability = port; + devIdStability = deviceId; + int delay = 0; + if (Convert.ToDateTime(startTime) > DateTime.Now) + { + isStarted = false; + TimeSpan secondSpan = new TimeSpan(Convert.ToDateTime(startTime).Ticks - DateTime.Now.Ticks); + delay = (int)secondSpan.TotalMilliseconds; + } + string[] arr = interval.Split(','); + + foreach (string inter in arr) + { + if (inter.Equals("1")) timerStability1 = new System.Threading.Timer(exeStability1, null, delay + 100, 1000); + if (inter.Equals("10")) timerStability10 = new System.Threading.Timer(exeStability10, null, delay + 100, 10 * 1000); + if (inter.Equals("20")) timerStability20 = new System.Threading.Timer(exeStability20, null, delay + 100, 20 * 1000); + if (inter.Equals("100")) timerStability100 = new System.Threading.Timer(exeStability100, null, delay + 100, 100 * 1000); + } } - portStability = port; - devIdStability = deviceId; - int delay = 0; - if (Convert.ToDateTime(startTime) > DateTime.Now) + catch (Exception ex) { - isStarted = false; - TimeSpan secondSpan = new TimeSpan(Convert.ToDateTime(startTime).Ticks - DateTime.Now.Ticks); - delay = (int)secondSpan.TotalMilliseconds; - } - string[] arr = interval.Split(','); - - foreach (string inter in arr) - { - if (inter.Equals("1")) timerStability1 = new System.Threading.Timer(exeStability1, null, delay + 100, 1000); - if (inter.Equals("10")) timerStability10 = new System.Threading.Timer(exeStability10, null, delay + 100, 10 * 1000); - if (inter.Equals("20")) timerStability20 = new System.Threading.Timer(exeStability20, null, delay + 100, 20 * 1000); - if (inter.Equals("100")) timerStability100 = new System.Threading.Timer(exeStability100, null, delay + 100, 100 * 1000); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "detecStability error: "+ ex.Message + ex.ToString()); + } } private void exeStability1(Object State) @@ -116,75 +121,104 @@ { while (true) { - if (detectionItemId != -1) - { - DetectionItem item = detectionItemService.getById(detectionItemId); - if (item==null||(item!=null&&Convert.ToDateTime(item.EndTime) < DateTime.Now)) + try + { + if (detectionItemId != -1) { - timerStability1.Dispose(); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,稳定度1s,devId="+ devIdStability+";detectionItemId="+ detectionItemId); - - return; - } - if (!isStarted) - { - isStarted = true; - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); - if (detectionItem0.Stability10.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); - if (detectionItem0.Stability20.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); - if (detectionItem0.Stability100.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); - if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); - if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); - if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); + //if (item == null || (item != null && item.IsDetecting.Equals("0"))) + if(HomeCtrlForm.stoppedItemIdTable.ContainsValue(detectionItemId)) + { + timerStability1.Dispose(); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,稳定度1s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + return; + } + if (!isStarted) + { + isStarted = true; + DetectionItem item = detectionItemService.getById(detectionItemId); + + if (item.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); + if (item.Stability10.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); + if (item.Stability20.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); + if (item.Stability100.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); + if (item.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); + if (item.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); + if (item.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "更新通道列表; detectionItemId=" + detectionItemId); + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + } + break; } - break; } - + catch(Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "检测错误1:"+ex.ToString()); + } + } string result = ""; string fre = getFrequencyData(portStability,false); - if (fre.Equals("close")) + try { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,稳定度1s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); - - timerStability1.Dispose(); - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem0.Stability1.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "0", "", "", ""); - - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - deviceService.updateStatus(devIdStability, "1", ""); - return; - } - if (!fre.Equals("") && resultStability1.Count<101) - { - resultStability1.Add(fre); - if (resultStability1.Count == 101) timerStability1.Dispose(); - if (!isUpdate && count1s < 101) + if (fre.Equals("close")) { - detectionService.add(devIdStability, fre, "1-1",detectionItemId); - count1s++; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,1s稳定度,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,稳定度1s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + + timerStability1.Dispose(); + //DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); + //if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); + //if (detectionItem0.Stability1.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "0", "", "", ""); + deviceService.updateStatus(devIdStability, "1", ""); + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + + return; } - } + } + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "检测错误2:" + ex.ToString()); + } + try + { + if (!fre.Equals("") && resultStability1.Count < 101) + { + if (resultStability1.Count == 101) timerStability1.Dispose(); + if (!isUpdate && count1s < 101) + { + resultStability1.Add(DateTime.Now, fre); + count1s++; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,1s稳定度,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + } + } + } + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "检测错误3:" + ex.ToString()); + } if (!isUpdate) { if (resultStability1.Count == 101) - { - result = FreMath.Stable(resultStability1) + ""; - resultStability1.Clear(); + { + List resultList = new List(); + foreach (DictionaryEntry de in resultStability1) + { + resultList.Add(de.Value.ToString()); + detectionService.add(devIdStability,de.Value.ToString(), "1-1",detectionItemId, Convert.ToDateTime(de.Key)); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "1s稳定度测量结果:" + result + ", devId =" + devIdStability + ";detectionItemId=" + detectionItemId); + } + resultStability1.Clear(); + result = FreMath.Stable(resultList) + ""; + + + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "1s稳定度测量结果:" + result + ", devId =" + devIdStability + ";detectionItemId=" + detectionItemId); // 更新检测结果 - detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", result, "", "", ""); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "detectionId :" + detectionItemId); - + detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", result, "", "", ""); + DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); if (detectionItem != null) { @@ -212,11 +246,18 @@ LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测稳定度1s得到结果,detectionItemId="+ detectionItemId); timerStability1.Dispose(); - - string result1 = FreMath.Stable(resultStability1) + ""; + List resultList = new List(); + foreach (DictionaryEntry de in resultStability1) + { + resultList.Add(de.Value.ToString()); + } + resultStability1.Clear(); + result = FreMath.Stable(resultList) + ""; + + string result1 = FreMath.Stable(resultList) + ""; detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", result1, "", "", ""); - updateView(resultStability1); + updateView(resultList); stability.label_result.Text = result1; DetailDlg.detailDlg.resultStaStr1 = result1; resultStability1.Clear(); @@ -228,365 +269,431 @@ } catch (Exception ex) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "稳定度检测错误:" + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "稳定度检测错误:" + ex.Message + ex.ToString()); } } private void exeStability10(Object State) - { - lock (obj) + { + try { - while (true) + lock (obj) { - if (detectionItemId != -1) + while (true) { - DetectionItem item = detectionItemService.getById(detectionItemId); - if (item == null || (item != null && Convert.ToDateTime(item.EndTime) < DateTime.Now)) + if (detectionItemId != -1) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,稳定度10s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + //if (item == null || (item != null && item.IsDetecting.Equals("0"))) + if (HomeCtrlForm.stoppedItemIdTable.ContainsValue(detectionItemId)) + { + + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,稳定度10s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + + timerStability10.Dispose(); + return; + } + if (!isStarted) + { + isStarted = true; + + DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); + if (detectionItem0.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); + detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); + if (detectionItem0.Stability20.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); + if (detectionItem0.Stability100.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); + if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); + if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); + if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + + } + break; + } + + } + + string result = ""; + + string fre = getFrequencyData(portStability, false); + if (fre.Equals("close")) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,稳定度10s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + + timerStability10.Dispose(); + DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); + if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); + if (detectionItem0.Stability10.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "0", "", ""); + deviceService.updateStatus(devIdStability, "1", ""); + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + return; + } + + if (!fre.Equals("") && resultStability10.Count < 101) + { + resultStability10.Add(DateTime.Now, fre); + if (resultStability10.Count == 101) timerStability10.Dispose(); + if (!isUpdate && count10s < 101) + { + count10s++; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,10s稳定度,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + + } + } + + if (!isUpdate) + { + if (resultStability10.Count == 101) + { + timerStability10.Dispose(); + + List resultList = new List(); + foreach (DictionaryEntry de in resultStability10) + { + resultList.Add(de.Value.ToString()); + detectionService.add(devIdStability, de.Value.ToString(), "1-10", detectionItemId, Convert.ToDateTime(de.Key)); + + } + resultStability10.Clear(); + result = FreMath.Stable(resultList) + ""; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "10s稳定度检测结果:" + result + ", devId =" + devIdStability + ";detectionItemId=" + detectionItemId); + + detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", result, "", ""); + + + DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); + if (detectionItem != null) + { + //更新稳定度检测状态 + if (!detectionItem.Stability1.Equals("-1") && !detectionItem.Stability10.Equals("-1") && !detectionItem.Stability20.Equals("-1") && !detectionItem.Stability100.Equals("-1")) + { + detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); + } + + detectionItem = detectionItemService.searchById(detectionItemId); + //更新整个仪器检测状态 + if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1")) + { + deviceService.updateStatus(devIdStability, "3", ""); + } + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + } + } + } + else + { + if (resultStability10.Count == 101) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测稳定度10s得到结果,detectionItemId=" + detectionItemId); timerStability10.Dispose(); - return; - } - if (!isStarted) - { - isStarted = true; - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); - detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); - if (detectionItem0.Stability20.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); - if (detectionItem0.Stability100.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); - if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); - if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); - if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); - - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + List resultList = new List(); + foreach (DictionaryEntry de in resultStability10) + { + resultList.Add(de.Value.ToString()); + } + resultStability10.Clear(); + string result1 = FreMath.Stable(resultList) + ""; - } - break; - } + detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", result1, "", ""); - } - - string result = ""; - - string fre = getFrequencyData(portStability, false); - if (fre.Equals("close")) - { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,稳定度10s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); - - timerStability10.Dispose(); - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem0.Stability10.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "0", "", ""); - - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - deviceService.updateStatus(devIdStability, "1", ""); - return; - } - - if (!fre.Equals("") && resultStability10.Count < 101) - { - resultStability10.Add(fre); - if (resultStability10.Count == 101) timerStability10.Dispose(); - if (!isUpdate && count10s < 101) - { - detectionService.add(devIdStability, fre, "1-10", detectionItemId); - count10s++; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,10s稳定度,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); - - } - } - - if (!isUpdate) - { - if (resultStability10.Count == 101) - { - timerStability10.Dispose(); - result = FreMath.Stable(resultStability10) + ""; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "10s稳定度检测结果:" + result +", devId =" + devIdStability + ";detectionItemId=" + detectionItemId); - - detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", result, "", ""); - - - DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); - if (detectionItem != null) - { - //更新稳定度检测状态 - if (!detectionItem.Stability1.Equals("-1") && !detectionItem.Stability10.Equals("-1") && !detectionItem.Stability20.Equals("-1") && !detectionItem.Stability100.Equals("-1")) - { - detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - } - - detectionItem = detectionItemService.searchById(detectionItemId); - //更新整个仪器检测状态 - if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1")) - { - deviceService.updateStatus(devIdStability, "3", ""); - } - - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + updateView(resultList); + stability.label_result.Text = result1; + DetailDlg.detailDlg.resultStaStr10 = result1; } } } - else - { - if (resultStability10.Count == 101) - { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测稳定度10s得到结果,detectionItemId=" + detectionItemId); + } + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "exeStability10 error: " + ex.Message + ex.ToString()); - timerStability10.Dispose(); - - - string result1 = FreMath.Stable(resultStability10) + ""; - detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", result1, "", ""); - - updateView(resultStability10); - stability.label_result.Text = result1; - DetailDlg.detailDlg.resultStaStr10 = result1; - } - } } } private void exeStability20(Object State) - { - lock (obj) + { + try { - while (true) + lock (obj) { - if (detectionItemId != -1) + while (true) { - DetectionItem item = detectionItemService.getById(detectionItemId); - if (item == null || (item != null && Convert.ToDateTime(item.EndTime) < DateTime.Now)) + if (detectionItemId != -1) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,稳定度20s, devId = " + devIdStability + "; detectionItemId = " + detectionItemId); + if (HomeCtrlForm.stoppedItemIdTable.ContainsValue(detectionItemId)) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,稳定度20s, devId = " + devIdStability + "; detectionItemId = " + detectionItemId); + + timerStability20.Dispose(); + return; + } + if (!isStarted) + { + isStarted = true; + DetectionItem item = detectionItemService.getById(detectionItemId); + + DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); + if (detectionItem0.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); + if (detectionItem0.Stability10.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); + detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); + if (detectionItem0.Stability100.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); + if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); + if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); + if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + + } + break; + } + + } + string result = ""; + + string fre = getFrequencyData(portStability, false); + if (fre.Equals("close")) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,稳定度20s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + + timerStability20.Dispose(); + DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); + if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); + if (detectionItem0.Stability20.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "0", ""); + deviceService.updateStatus(devIdStability, "1", ""); + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + return; + } + if (!fre.Equals("") && resultStability20.Count < 101) + { + resultStability20.Add(DateTime.Now, fre); + if (!isUpdate && count20s < 101) + { + count20s++; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,20s稳定度,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + + } + } + + + if (!isUpdate) + { + if (resultStability20.Count == 101) + { + timerStability20.Dispose(); + List resultList = new List(); + foreach (DictionaryEntry de in resultStability20) + { + resultList.Add(de.Value.ToString()); + detectionService.add(devIdStability, de.Value.ToString(), "1-20", detectionItemId, Convert.ToDateTime(de.Key)); + + } + resultStability20.Clear(); + result = FreMath.Stable(resultList) + ""; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "20s稳定度检测结果:" + result + ", devId =" + devIdStability + ";detectionItemId=" + detectionItemId); + + detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", result, ""); + + + DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); + if (detectionItem != null) + { + //更新稳定度检测状态 + if (!detectionItem.Stability1.Equals("-1") && !detectionItem.Stability10.Equals("-1") && !detectionItem.Stability20.Equals("-1") && !detectionItem.Stability100.Equals("-1")) + { + detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); + + } + detectionItem = detectionItemService.searchById(detectionItemId); + //更新整个仪器检测状态 + if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1")) + { + deviceService.updateStatus(devIdStability, "3", ""); + } + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + } + + + } + + } + else + { + if (resultStability20.Count == 101) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测稳定度20s得到结果,detectionItemId=" + detectionItemId); timerStability20.Dispose(); - return; - } - if (!isStarted) - { - isStarted = true; - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); - if (detectionItem0.Stability10.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); - detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); - if (detectionItem0.Stability100.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); - if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); - if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); - if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - - } - break; - } - - } - string result = ""; - - string fre = getFrequencyData(portStability, false); - if (fre.Equals("close")) - { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,稳定度20s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); - - timerStability20.Dispose(); - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem0.Stability20.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "0", ""); - - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - deviceService.updateStatus(devIdStability, "1", ""); - return; - } - if (!fre.Equals("") && resultStability20.Count < 101) - { - resultStability20.Add(fre); - if (!isUpdate && count20s < 101) - { - detectionService.add(devIdStability, fre, "1-20", detectionItemId); - count20s++; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,20s稳定度,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); - - } - } - - - if (!isUpdate) - { - if (resultStability20.Count == 101) - { - timerStability20.Dispose(); - - result = FreMath.Stable(resultStability20) + ""; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "20s稳定度检测结果:" + result + ", devId =" + devIdStability + ";detectionItemId=" + detectionItemId); - - detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", result, ""); - - - DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); - if (detectionItem != null) - { - //更新稳定度检测状态 - if (!detectionItem.Stability1.Equals("-1") && !detectionItem.Stability10.Equals("-1") && !detectionItem.Stability20.Equals("-1") && !detectionItem.Stability100.Equals("-1")) + List resultList = new List(); + foreach (DictionaryEntry de in resultStability20) { - detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - + resultList.Add(de.Value.ToString()); } - detectionItem = detectionItemService.searchById(detectionItemId); - //更新整个仪器检测状态 - if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1")) - { - deviceService.updateStatus(devIdStability, "3", ""); - } + resultStability20.Clear(); + string result1 = FreMath.Stable(resultList) + ""; + detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", result1, ""); - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - } - - resultStability20.Clear(); - } + updateView(resultList); + stability.label_result.Text = result1; + DetailDlg.detailDlg.resultStaStr20 = result1; - } - else - { - if (resultStability20.Count == 101) - { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测稳定度20s得到结果,detectionItemId=" + detectionItemId); - timerStability20.Dispose(); - - - string result1 = FreMath.Stable(resultStability20) + ""; - detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", result1, ""); - - updateView(resultStability20); - stability.label_result.Text = result1; - DetailDlg.detailDlg.resultStaStr20 = result1; - resultStability20.Clear(); - + } } - } + } } + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "exeStability20 error: " + ex.Message + ex.ToString()); + + } + } private void exeStability100(Object State) - { - lock (obj) + { + try { - if (!isStarted) + lock (obj) { - while (true) + if (!isStarted) { - DetectionItem item = detectionItemService.getById(detectionItemId); - if (item == null || (item != null && Convert.ToDateTime(item.EndTime) < DateTime.Now)) + while (true) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,稳定度100s, devId = " + devIdStability + "; detectionItemId = " + detectionItemId); + if (HomeCtrlForm.stoppedItemIdTable.ContainsValue(detectionItemId)) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,稳定度100s, devId = " + devIdStability + "; detectionItemId = " + detectionItemId); - timerStability100.Dispose(); - return; - } - - if (detectionItemId != -1) - { - isStarted = true; - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); - if (detectionItem0.Stability10.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); - if (detectionItem0.Stability20.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); - detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); - if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); - if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); - if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); + timerStability100.Dispose(); + return; + } - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - + if (detectionItemId != -1) + { + isStarted = true; + DetectionItem item = detectionItemService.getById(detectionItemId); + + DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); + if (detectionItem0.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); + if (detectionItem0.Stability10.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); + if (detectionItem0.Stability20.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); + detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); + if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); + if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); + if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + + } + break; } - break; + + } + string result = ""; + + string fre = getFrequencyData(portStability, false); + if (fre.Equals("close")) + { + timerStability100.Dispose(); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,稳定度100s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + + + DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); + if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); + if (detectionItem0.Stability100.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", "0"); + deviceService.updateStatus(devIdStability, "1", ""); + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + return; + } + if (!fre.Equals("") && resultStability100.Count < 101) + { + resultStability100.Add(DateTime.Now, fre); + if (!isUpdate) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,100s稳定度,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + } } - } - string result = ""; - string fre = getFrequencyData(portStability, false); - if (fre.Equals("close")) - { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,稳定度100s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); - - timerStability100.Dispose(); - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem0.Stability100.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", "0"); - - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - deviceService.updateStatus(devIdStability, "1", ""); - return; - } - if (!fre.Equals("") && resultStability100.Count < 101) - { - resultStability100.Add(fre); if (!isUpdate) { - detectionService.add(devIdStability, fre, "1-100", detectionItemId); - - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,100s稳定度,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); - } - } - - - if (!isUpdate) - { - if (resultStability100.Count == 101) - { - timerStability100.Dispose(); - - result = FreMath.Stable(resultStability100) + ""; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "100s稳定度检测结果:" + result + ", devId =" + devIdStability + ";detectionItemId=" + detectionItemId); - - detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "", result); - - - DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); - if (detectionItem != null) + if (resultStability100.Count == 101) { - //更新稳定度检测状态 - if (!detectionItem.Stability1.Equals("-1") && !detectionItem.Stability10.Equals("-1") && !detectionItem.Stability20.Equals("-1") && !detectionItem.Stability100.Equals("-1")) + timerStability100.Dispose(); + List resultList = new List(); + foreach (DictionaryEntry de in resultStability100) { - detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - + resultList.Add(de.Value.ToString()); + detectionService.add(devIdStability, de.Value.ToString(), "1-100", detectionItemId, Convert.ToDateTime(de.Key)); + } - detectionItem = detectionItemService.searchById(detectionItemId); - //更新整个仪器检测状态 - if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1")) + resultStability100.Clear(); + result = FreMath.Stable(resultList) + ""; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "100s稳定度检测结果:" + result + ", devId =" + devIdStability + ";detectionItemId=" + detectionItemId); + + detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "", result); + + + DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); + if (detectionItem != null) { - deviceService.updateStatus(devIdStability, "3", ""); + //更新稳定度检测状态 + if (!detectionItem.Stability1.Equals("-1") && !detectionItem.Stability10.Equals("-1") && !detectionItem.Stability20.Equals("-1") && !detectionItem.Stability100.Equals("-1")) + { + detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); + + } + detectionItem = detectionItemService.searchById(detectionItemId); + //更新整个仪器检测状态 + if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1")) + { + deviceService.updateStatus(devIdStability, "3", ""); + } + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); } - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + } - resultStability100.Clear(); } - } - else - { - if (resultStability100.Count == 101) + else { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测稳定度100s得到结果,detectionItemId=" + detectionItemId); + if (resultStability100.Count == 101) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测稳定度100s得到结果,detectionItemId=" + detectionItemId); - timerStability100.Dispose(); + timerStability100.Dispose(); + + List resultList = new List(); + foreach (DictionaryEntry de in resultStability100) + { + resultList.Add(de.Value.ToString()); - string result1 = FreMath.Stable(resultStability100) + ""; - detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "", result1); + } + resultStability100.Clear(); + string result1 = FreMath.Stable(resultList) + ""; + detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "", result1); - updateView(resultStability100); - stability.label_result.Text = result1; - DetailDlg.detailDlg.resultStaStr100 = result1; - resultStability100.Clear(); + updateView(resultList); + stability.label_result.Text = result1; + DetailDlg.detailDlg.resultStaStr100 = result1; + resultStability100.Clear(); + } } } - } + } + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "exeStability100 error: " + ex.Message + ex.ToString()); + + } } #endregion @@ -594,23 +701,31 @@ #region 准确度 public void detecAccuracy(long deviceId, SerialPort port, string endTime, bool isStartNow, bool isUpdates) { - portAccuracy = port; - devIdAccuracy = deviceId; - if (isUpdates) + try { - isUpdate = true; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测准确度"); + portAccuracy = port; + devIdAccuracy = deviceId; + if (isUpdates) + { + isUpdate = true; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测准确度"); + + } + int delay = 0; + if (Convert.ToDateTime(endTime) > DateTime.Now) + { + isStarted = false; + TimeSpan secondSpan = new TimeSpan(Convert.ToDateTime(endTime).Ticks - DateTime.Now.Ticks); + delay = (int)secondSpan.TotalMilliseconds - 20 * 1000; + } + + timerAccuracy = new System.Threading.Timer(exeAccuracy, null, delay + 200, 5 * 60 * 1000); + } + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "detecAccuracy error: " + ex.Message + ex.ToString()); } - int delay = 0; - if (Convert.ToDateTime(endTime)>DateTime.Now) - { - isStarted = false; - TimeSpan secondSpan = new TimeSpan(Convert.ToDateTime(endTime).Ticks - DateTime.Now.Ticks); - delay = (int)secondSpan.TotalMilliseconds - 20*1000; - } - - timerAccuracy = new System.Threading.Timer(exeAccuracy, null, delay + 200 ,5*60*1000); } private void exeAccuracy(Object State) { @@ -622,8 +737,7 @@ { if (detectionItemId != -1) { - DetectionItem item = detectionItemService.getById(detectionItemId); - if (item == null || (item != null && Convert.ToDateTime(item.EndTime) < DateTime.Now)) + if (HomeCtrlForm.stoppedItemIdTable.ContainsValue(detectionItemId)) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,准确度, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); @@ -632,7 +746,8 @@ } if (!isStarted) { - + DetectionItem item = detectionItemService.getById(detectionItemId); + isStarted = true; DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); if (detectionItem0.Stability.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", ""); @@ -656,7 +771,7 @@ double sum = 0.0; List resultList = new List(); - for (int i = 0; i < 500; i++) + for (int i = 0; i < 200; i++) { string fre = getFrequencyData(portAccuracy, false); if (fre.Equals("close")) @@ -666,21 +781,21 @@ timerAccuracy.Dispose(); DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); if (detectionItem0.Accuracy.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "0", "", "", "", "", "", "", ""); - - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); deviceService.updateStatus(devIdStability, "1", ""); + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); return; } if (fre.Equals("")) continue; resultList.Add(fre); if (!isUpdate) { - detectionService.add(devIdAccuracy, fre, "2", detectionItemId); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,准确度, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); + detectionService.add(devIdAccuracy, fre, "2", detectionItemId, DateTime.Now); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,准确度, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); } if (resultList.Count == 3) - { + { sum = sum + Convert.ToDouble(fre); break; } @@ -737,116 +852,130 @@ #region 开机特性 public void detecBootFeature(long deviceId, string startTime, SerialPort port, bool isStartNow) { - resultBootFeature = new List(); - portBootFeature = port; - devIdBootFeature = deviceId; - int delay = 0; - if (!isStartNow && Convert.ToDateTime(startTime) > DateTime.Now) + try { - isStarted = false; - TimeSpan secondSpan = new TimeSpan(Convert.ToDateTime(startTime).Ticks - DateTime.Now.Ticks); - delay = (int)secondSpan.TotalMilliseconds; + resultBootFeature = new List(); + portBootFeature = port; + devIdBootFeature = deviceId; + int delay = 0; + if (Convert.ToDateTime(startTime) > DateTime.Now) + { + isStarted = false; + TimeSpan secondSpan = new TimeSpan(Convert.ToDateTime(startTime).Ticks - DateTime.Now.Ticks); + delay = (int)secondSpan.TotalMilliseconds; + } + timerBootFeature = new System.Threading.Timer(exeBootFeature, null, delay + 100, 60 * 60 * 1000); } - timerBootFeature = new System.Threading.Timer(exeBootFeature, null, delay + 100, 60 * 60 * 1000); + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "detecBootFeature error: " + ex.Message + ex.ToString()); + + } } private void exeBootFeature(Object State) - { - lock (obj) + { + try { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "isStarted:"+ isStarted); - DetectionItem item = detectionItemService.getById(detectionItemId); - if (item == null || (item != null && Convert.ToDateTime(item.EndTime) < DateTime.Now)) + lock (obj) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,开机特性, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); - - timerBootFeature.Dispose(); - return; - } - if (!isStarted) - { - while (true) + if (HomeCtrlForm.stoppedItemIdTable.ContainsValue(detectionItemId)) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "detectionItemId:" + detectionItemId); - - if (detectionItemId != -1) - { - isStarted = true; - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.Stability.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", ""); - if (detectionItem0.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); - if (detectionItem0.Stability10.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); - if (detectionItem0.Stability20.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); - if (detectionItem0.Stability100.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); - if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); - if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); - if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); - - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - break; - } - } - - } - - string result = ""; - double sum = 0.0; - int count = 0; - for (int i = 0; i < 50; i++) - { - string fre = getFrequencyData(portBootFeature, false); - if (fre.Equals("close")) - { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,开机特性,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,开机特性, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); timerBootFeature.Dispose(); - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.BootFeature.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "0", "", "", "", "", "", ""); - - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - deviceService.updateStatus(devIdStability, "1", ""); return; } - if (!fre.Equals("")) + if (!isStarted) { - count++; - sum = sum + Convert.ToDouble(fre); - - if (count == 3) break; - } - } - detectionService.add(devIdBootFeature, sum / 3 + "", "3", detectionItemId); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,开机特性, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); + + while (true) + { + if (detectionItemId != -1) + { + isStarted = true; + DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); + if (detectionItem0.Stability.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", ""); + if (detectionItem0.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); + if (detectionItem0.Stability10.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); + if (detectionItem0.Stability20.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); + if (detectionItem0.Stability100.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); + if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); + if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); + if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); - resultBootFeature.Add(sum / 3 + ""); + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + break; + } + } - if (resultBootFeature.Count == 8) - { - timerBootFeature.Dispose(); - string max = "0.0"; - string min = "0.0"; - foreach (string fre in resultBootFeature) - { - if (Convert.ToDouble(fre) > Convert.ToDouble(max)) max = fre; - if (Convert.ToDouble(fre) < Convert.ToDouble(min) || min.Equals("0.0")) min = fre; } - result = (Convert.ToDouble(max) - Convert.ToDouble(min)) + ""; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "开机特性检测结果result=" + result + ",detectionItemId=" + detectionItemId); - detectionItemService.updateDetecStatus(detectionItemId, "", "", result, "", "", "", "", "", ""); - - DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); - if (detectionItem != null) + string result = ""; + double sum = 0.0; + int count = 0; + for (int i = 0; i < 50; i++) { - if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1")) + string fre = getFrequencyData(portBootFeature, false); + if (fre.Equals("close")) { - deviceService.updateStatus(devIdBootFeature, "3", ""); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,开机特性,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + + timerBootFeature.Dispose(); + DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); + if (detectionItem0.BootFeature.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "0", "", "", "", "", "", ""); + deviceService.updateStatus(devIdStability, "1", ""); + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + return; + } + if (!fre.Equals("")) + { + count++; + sum = sum + Convert.ToDouble(fre); + + if (count == 3) break; } } - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - - resultBootFeature.Clear(); + detectionService.add(devIdBootFeature, sum / 3 + "", "3", detectionItemId,DateTime.Now); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,开机特性, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); + + resultBootFeature.Add(sum / 3 + ""); + + if (resultBootFeature.Count == 8) + { + timerBootFeature.Dispose(); + string max = "0.0"; + string min = "0.0"; + foreach (string fre in resultBootFeature) + { + if (Convert.ToDouble(fre) > Convert.ToDouble(max)) max = fre; + if (Convert.ToDouble(fre) < Convert.ToDouble(min) || min.Equals("0.0")) min = fre; + } + result = (Convert.ToDouble(max) - Convert.ToDouble(min)) + ""; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "开机特性检测结果result=" + result + ",detectionItemId=" + detectionItemId); + + detectionItemService.updateDetecStatus(detectionItemId, "", "", result, "", "", "", "", "", ""); + + DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); + if (detectionItem != null) + { + if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1")) + { + deviceService.updateStatus(devIdBootFeature, "3", ""); + } + } + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + + resultBootFeature.Clear(); + } } - } + } + + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "exeBootFeature error: " + ex.Message + ex.ToString()); + + } } #endregion @@ -857,111 +986,126 @@ #region 日老化率 public void detecAgeRate(long deviceId, string startTime, SerialPort port, bool isStartNow) { - resultAgeRate = new List(); - portAgeRate = port; - devIdAgeRate = deviceId; - int delay = 0; - if (!isStartNow && Convert.ToDateTime(startTime) > DateTime.Now) + try { - isStarted = false; - TimeSpan secondSpan = new TimeSpan(Convert.ToDateTime(startTime).Ticks - DateTime.Now.Ticks); - delay = (int)secondSpan.TotalMilliseconds; + resultAgeRate = new List(); + portAgeRate = port; + devIdAgeRate = deviceId; + int delay = 0; + if (Convert.ToDateTime(startTime) > DateTime.Now) + { + isStarted = false; + TimeSpan secondSpan = new TimeSpan(Convert.ToDateTime(startTime).Ticks - DateTime.Now.Ticks); + delay = (int)secondSpan.TotalMilliseconds; + } + timerAgeRate = new System.Threading.Timer(exeAgeRate, null, delay + 100, 12 * 60 * 60 * 1000); } - timerAgeRate = new System.Threading.Timer(exeAgeRate, null, delay + 100, 12* 60* 60 * 1000); + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "detecAgeRate error: " + ex.Message + ex.ToString()); + + } } private void exeAgeRate(Object State) - { - lock (obj) + { + try { - while (true) + lock (obj) { - if (detectionItemId != -1) + while (true) { - DetectionItem item = detectionItemService.getById(detectionItemId); - if (item == null || (item != null && Convert.ToDateTime(item.EndTime) < DateTime.Now)) + if (detectionItemId != -1) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,日老化率, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); + if (HomeCtrlForm.stoppedItemIdTable.ContainsValue(detectionItemId)) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,日老化率, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); + + timerAgeRate.Dispose(); + return; + } + if (!isStarted) + { + isStarted = true; + DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); + if (detectionItem0.Stability.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", ""); + if (detectionItem0.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); + if (detectionItem0.Stability10.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); + if (detectionItem0.Stability20.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); + if (detectionItem0.Stability100.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); + if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); + if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); + if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + + } + break; + } + + } + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "开始检测日老化率"); + + string result = ""; + double sum = 0.0; + int count = 0; + for (int i = 0; i < 50; i++) + { + string fre = getFrequencyData(portAgeRate, false); + if (fre.Equals("close")) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,日老化率,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); timerAgeRate.Dispose(); - return; - } - if (!isStarted) - { - - isStarted = true; DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.Stability.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", ""); - if (detectionItem0.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); - if (detectionItem0.Stability10.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); - if (detectionItem0.Stability20.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); - if (detectionItem0.Stability100.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); - if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); - if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); - if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); + if (detectionItem0.AgeRate.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "0", "", "", "", "", ""); + deviceService.updateStatus(devIdStability, "1", ""); HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - + return; } - break; - } - - } - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "开始检测日老化率"); - - string result = ""; - double sum = 0.0; - int count = 0; - for (int i = 0; i < 50; i++) - { - string fre = getFrequencyData(portAgeRate, false); - if (fre.Equals("close")) - { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,日老化率,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); - - timerAgeRate.Dispose(); - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.AgeRate.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "0", "", "", "", "", ""); - - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - deviceService.updateStatus(devIdStability, "1", ""); - return; - } - if (!fre.Equals("")) - { - count++; - sum = sum + Convert.ToDouble(fre); - - if (count == 3) break; - } - } - detectionService.add(devIdAgeRate, sum / 3+"", "4", detectionItemId); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,日老化率, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); - - resultAgeRate.Add(sum / 3 + ""); - - if (resultAgeRate.Count == 15) - { - timerAgeRate.Dispose(); - double r = 0.0; - double k = FreMath.DriftRate(resultAgeRate, out r); - result = k + "," + r.ToString().Substring(0,5); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "日老化率检测结果result=" + result + ",detectionItemId=" + detectionItemId); - - detectionItemService.updateDetecStatus(detectionItemId, "", "", "", result, "", "", "", "", ""); - - DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); - if (detectionItem != null) - { - if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1")) + if (!fre.Equals("")) { - deviceService.updateStatus(devIdAgeRate, "3", ""); + count++; + sum = sum + Convert.ToDouble(fre); + + if (count == 3) break; } } - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - - resultAgeRate.Clear(); + detectionService.add(devIdAgeRate, sum / 3 + "", "4", detectionItemId,DateTime.Now); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,日老化率, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); + + resultAgeRate.Add(sum / 3 + ""); + + if (resultAgeRate.Count == 15) + { + timerAgeRate.Dispose(); + double r = 0.0; + double k = FreMath.DriftRate(resultAgeRate, out r); + result = k + "," + r.ToString().Substring(0, 5); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "日老化率检测结果result=" + result + ",detectionItemId=" + detectionItemId); + + detectionItemService.updateDetecStatus(detectionItemId, "", "", "", result, "", "", "", "", ""); + + DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); + if (detectionItem != null) + { + if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1")) + { + deviceService.updateStatus(devIdAgeRate, "3", ""); + } + } + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + + resultAgeRate.Clear(); + } } - } + } + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "exeAgeRate error: " + ex.Message + ex.ToString()); + + } + } #endregion @@ -990,7 +1134,7 @@ if (ConfigHelper.GetAppConfig("deviceType").ToString().Equals("1")) { int count = 0; - while (count < 600) + while (count < 200) { int readLen = port.BytesToRead; @@ -1005,9 +1149,8 @@ string[] dataArray = data.Split('$')[1].Split(' '); if (dataArray.Length < 2) continue; string s1 = dataArray[0].Replace("$", ""); - string s2 = "0." + dataArray[1].Replace(".", "").Replace("-", "").TrimEnd('0'); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, port.PortName + "s1=" + s1 + ";s2="+s2); - + string s2 = (Convert.ToDouble(dataArray[1]) / 1000000).ToString();// "0." + dataArray[1].Replace(".", "").Replace("-", "").TrimEnd('0'); + if (dataArray[1].Contains("-")) { received = (Convert.ToDouble(s1) - Convert.ToDouble(s2)) + ""; @@ -1028,7 +1171,7 @@ { int count = 0; - while (count < 600) + while (count < 200) { int readLen = port.BytesToRead; @@ -1093,19 +1236,21 @@ } private void updateView(List result) - { - isUpdate = false; - //new Thread(() => - //{ + { + try + { + isUpdate = false; + //new Thread(() => + //{ int index = 0; - + foreach (DataGridViewRow row in DetailDlg.dataGridView.Rows) { if (index < result.Count) { row.Cells[2].Value = result[index].ToString(); int re = detectionService.updateFrequency(Convert.ToInt64(row.Cells[3].Value), result[index].ToString()); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "updateFrequency re=" + re + ";id="+ row.Cells[3].Value + "; fre=" + result[index].ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "updateFrequency re=" + re + ";id=" + row.Cells[3].Value + "; fre=" + result[index].ToString()); } index++; @@ -1113,8 +1258,14 @@ DetailDlg.detailDlg.updateChannelNoRedetec(); DetailDlg.label_redetecting.Visible = false; + } + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "updateView error: " + ex.Message + ex.ToString()); + + } //}).Start(); - + } diff --git a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs index 963b90b..a5e9368 100644 --- a/RbFreqStandMeasure/R_DataBase/DbConnectService.cs +++ b/RbFreqStandMeasure/R_DataBase/DbConnectService.cs @@ -29,7 +29,7 @@ + ";password=" + databasePassword + ";Charset=utf8" + ";Allow User Variables=True" - + ";Pooling=true"; + + ";Pooling=True"; mySqlConnect = new MySqlConnection(sConnection); mySqlConnect.Open(); iRetval = 0; diff --git a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs index c69559f..f19bd95 100644 --- a/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs +++ b/RbFreqStandMeasure/R_DataBase/Model/DetectionItem.cs @@ -38,6 +38,7 @@ private string stability10; private string stability20; private string stability100; + private string isDetecting; public long Id { get @@ -161,5 +162,6 @@ public string Stability20 { get => stability20; set => stability20 = value; } public string Stability100 { get => stability100; set => stability100 = value; } public string Stability1 { get => stability1; set => stability1 = value; } + public string IsDetecting { get => isDetecting; set => isDetecting = value; } } } \ No newline at end of file diff --git a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs index 399098b..781749c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/DetectionService.cs @@ -9,7 +9,7 @@ { interface DetectionService { - int add(long deviceId, string frequency, string detecItemType, long detectionItemId); + int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time); List search(long deviceId, string detectionType, string startTime, string endTime, long detectionItemId); diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs index 0fd7b24..4df249b 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterCheckParamServiceImpl.cs @@ -132,7 +132,30 @@ string sQry = "SELECT * FROM r_counter_check_params"; 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) + // { + // if (row[0] != DBNull.Value) counterCheckParam.Id = Convert.ToInt32(row[0]); + // if (row[1] != DBNull.Value) counterCheckParam.SoOutDelay = row[1].ToString(); + // if (row[2] != DBNull.Value) counterCheckParam.SoEleFrequency = row[2].ToString(); + // if (row[3] != DBNull.Value) counterCheckParam.SoEleAddValue = row[3].ToString(); + // if (row[4] != DBNull.Value) counterCheckParam.SoEleAlarm = row[4].ToString(); + // if (row[5] != DBNull.Value) counterCheckParam.FreThreshold1 = row[5].ToString(); + // if (row[6] != DBNull.Value) counterCheckParam.FreThreshold2 = row[6].ToString(); + // if (row[7] != DBNull.Value) counterCheckParam.FreEleAddValue = row[7].ToString(); + // if (row[8] != DBNull.Value) counterCheckParam.CycThreshold1 = row[8].ToString(); + // if (row[9] != DBNull.Value) counterCheckParam.CycThreshold2 = row[9].ToString(); + // if (row[10] != DBNull.Value) counterCheckParam.CycEleAddValue = row[10].ToString(); + + // } + //} using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -149,10 +172,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(Exception ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs index 52b36f8..2c60ab4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDataServiceImpl.cs @@ -32,28 +32,29 @@ //先查询是否有历史数据 string sQry = "select ID from r_counter_data where DEVICE_ID=" + deviceId + " and OUT_VALUE = '" + outValue + "'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - - if (aReader.Read()) + bool isUpdated = false; + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - dataId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) + { + dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + + " where ID=" + dataId; + + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; + cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; + cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; + + cmd.ExecuteNonQuery(); + isUpdated = true; + } aReader.Close(); - sQry = "update r_counter_data set VALUE=@VALUE, SENSITIVITY=@SENSITIVITY, LOG_TIME=@LOG_TIME, DETEC_TYPE=@DETEC_TYPE " + - " where ID="+ dataId; - - cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - cmd.Parameters.Add("@VALUE", MySqlDbType.String, 255).Value = value; - cmd.Parameters.Add("@SENSITIVITY", MySqlDbType.String, 255).Value = sensitivity; - cmd.Parameters.Add("@LOG_TIME", MySqlDbType.String, 20).Value = logTime; - cmd.Parameters.Add("@DETEC_TYPE", MySqlDbType.String, 5).Value = detecType; - - cmd.ExecuteNonQuery(); - } - else - { - aReader.Close(); - + if (!isUpdated) + { sQry = "INSERT INTO r_counter_data (DEVICE_ID, OUT_VALUE, VALUE, SENSITIVITY, LOG_TIME, DETEC_TYPE)" + "values(@DEVICE_ID,@OUT_VALUE,@VALUE,@SENSITIVITY,@LOG_TIME,@DETEC_TYPE)"; @@ -70,14 +71,14 @@ sQry = "SELECT max(ID) from r_counter_data"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - - aReader = cmd.ExecuteReader(); - - if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); - + using (MySqlDataReader aReader = cmd.ExecuteReader()) + { + + if (aReader.Read()) dataId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); + } } - aReader.Close(); cmd.Dispose(); iRetval = 0; @@ -144,6 +145,8 @@ cmd.ExecuteNonQuery(); } + + aReader.Close(); } @@ -282,9 +285,10 @@ if (!aReader.IsDBNull(6)) counterData.DetecType = aReader.GetString(6); counterDataList.Add(counterData); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs index 6795325..7500bd4 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterDetecInitServiceImpl.cs @@ -47,10 +47,11 @@ counterDetecInitList.Add(counterDetecInit); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -75,29 +76,31 @@ return iRetval; } } - string sQry = "select ID from r_counter_detec_init where FREQUENCY=" + frequency +" AND CYCLE="+cycle; + string sQry = "select ID from r_counter_detec_init where FREQUENCY='" + frequency +"' AND CYCLE='"+cycle+"'"; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(); - if (aReader.Read()) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - initId = Convert.ToInt64(aReader.GetString(0)); - sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; + if (aReader.Read()) + { + initId = Convert.ToInt64(aReader.GetString(0)); + sQry = "UPDATE r_counter_detec_init SET FREQUENCY=@FREQUENCY, CYCLE=@CYCLE WHERE ID = " + initId; - 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(); - } - else - { - 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 = 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(); + } + else + { + 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.ExecuteNonQuery(); + + } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); iRetval = 0; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs index 97b06ba..abcbaa6 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/CounterParamServiceImpl.cs @@ -72,26 +72,27 @@ MySqlCommand cmd = new MySqlCommand(sql, DbConnectService.mySqlConnect); - MySqlDataReader aReader = cmd.ExecuteReader(CommandBehavior.Default); - - if (aReader != null) + using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) + if (aReader != null) { - //判断门的状态 - if (!aReader.IsDBNull(0)) - counterParam.Id = Convert.ToInt32(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) - counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) - counterParam.BaudRate = aReader.GetString(2); - if (!aReader.IsDBNull(3)) - counterParam.GeneratorIp = aReader.GetString(3); - if (!aReader.IsDBNull(4)) - counterParam.SignalSourceIp = aReader.GetString(4); + if (aReader.Read()) + { + //判断门的状态 + if (!aReader.IsDBNull(0)) + counterParam.Id = Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(1)) + counterParam.DeviceId = Convert.ToInt32(aReader.GetString(1)); + if (!aReader.IsDBNull(2)) + counterParam.BaudRate = aReader.GetString(2); + if (!aReader.IsDBNull(3)) + counterParam.GeneratorIp = aReader.GetString(3); + if (!aReader.IsDBNull(4)) + counterParam.SignalSourceIp = aReader.GetString(4); + } } + aReader.Close(); } - aReader.Close(); cmd.Dispose(); } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs index cca90fb..1578937 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionItemServiceImpl.cs @@ -33,8 +33,8 @@ MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@DEVICE_ID", MySqlDbType.Int64, 20).Value = deviceId; - cmd.Parameters.Add("@START_TIME", MySqlDbType.String, 50).Value = startTime; - cmd.Parameters.Add("@END_TIME", MySqlDbType.String, 50).Value = endTime; + cmd.Parameters.Add("@START_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(startTime); + cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 50).Value = Convert.ToDateTime(endTime); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 50).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 50).Value = accuracy; cmd.Parameters.Add("@BOOT_FEATURE", MySqlDbType.String, 50).Value = bootFeature; @@ -58,11 +58,11 @@ sQry = "SELECT max(ID) from r_detection_item"; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = cmd.ExecuteReader()) { if (aReader.Read()) detectionId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); iRetval = 0; @@ -203,8 +203,9 @@ if (!stability100.Equals("")) sQry = sQry + " STABILITY_100=@STABILITY_100,"; sQry = sQry + " COUNTER_DETEC=@COUNTER_DETEC where ID = " + detectionId; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry: " + sQry); - + MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@STABILITY", MySqlDbType.String, 10).Value = stability; cmd.Parameters.Add("@ACCURACY", MySqlDbType.String, 10).Value = accuracy; @@ -283,7 +284,8 @@ return iRetval; } } - + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "停止检测 detectionItemId=======" + detectionItemId); + string sQry = "UPDATE r_device SET STATUSID="+"1"+", CHANNEL=@CHANNEL where ID=" + deviceId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@CHANNEL", MySqlDbType.String, 20).Value = ""; @@ -292,19 +294,21 @@ if (isDeleteData) { - sQry = "DELETE FROM r_detection_item WHERE DEVICE_ID = " + deviceId + " AND START_TIME='" + startTime + "' AND END_TIME='" + endTime + "'"; + sQry = "DELETE FROM r_detection_item WHERE ID=" + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); - sQry = "DELETE FROM r_detection WHERE DEVICE_ID = " + deviceId + " AND (LOG_TIME between'" + startTime + "' and '" + endTime + "')"; + sQry = "DELETE FROM r_detection WHERE DETECTION_ITEM_ID = " + detectionItemId; cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.ExecuteNonQuery(); } else { - sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME WHERE ID="+ detectionItemId; + sQry = "UPDATE r_detection_item SET END_TIME=@END_TIME, IS_DETECTING=@IS_DETECTING WHERE ID=" + detectionItemId; + cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); cmd.Parameters.Add("@END_TIME", MySqlDbType.DateTime, 20).Value = DateTime.Now; + cmd.Parameters.Add("@IS_DETECTING", MySqlDbType.String, 1).Value = "0"; //0-否,1-是 cmd.ExecuteNonQuery(); } @@ -322,8 +326,7 @@ { DetectionItem detectionItem = null; try - { - + { if (DbConnectService.mySqlConnect.State == ConnectionState.Closed) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getById : 数据库链接断开"); @@ -337,6 +340,7 @@ string sQry = "select * from r_detection_item WHERE ID = "+ detectionItemId; MySqlCommand cmd = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + using (MySqlDataReader aReader = cmd.ExecuteReader()) { while (aReader.Read()) @@ -356,11 +360,13 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(15)) detectionItem.IsDetecting = aReader.GetString(15); } - } - + aReader.Close(); + } cmd.Dispose(); + } catch (MySqlException e) { @@ -400,7 +406,7 @@ { DetectionItem detectionItem = new DetectionItem(); //姓名 - if (!aReader.IsDBNull(0)) detectionItem.Id=Convert.ToInt32(aReader.GetString(0)); + if (!aReader.IsDBNull(0)) detectionItem.Id = Convert.ToInt32(aReader.GetString(0)); if (!aReader.IsDBNull(1)) detectionItem.DeviceId = Convert.ToInt64(aReader.GetString(1)); if (!aReader.IsDBNull(2)) detectionItem.StartTime = aReader.GetString(2); if (!aReader.IsDBNull(3)) detectionItem.EndTime = aReader.GetString(3); @@ -416,9 +422,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -468,9 +475,10 @@ if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); detectionItemList.Add(detectionItem); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -498,7 +506,6 @@ string sQry = "SELECT * FROM r_detection_item where ID = " + detectionId; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -518,15 +525,43 @@ if (!aReader.IsDBNull(11)) detectionItem.Stability1 = aReader.GetString(11); if (!aReader.IsDBNull(12)) detectionItem.Stability10 = aReader.GetString(12); if (!aReader.IsDBNull(13)) detectionItem.Stability20 = aReader.GetString(13); - if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); + if (!aReader.IsDBNull(14)) detectionItem.Stability100 = aReader.GetString(14); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); + //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) + // { + // detectionItem = new DetectionItem(); + // if (row[0] != DBNull.Value) detectionItem.Id = Convert.ToInt64(row[0]); + // if (row[1] != DBNull.Value) detectionItem.DeviceId = Convert.ToInt64(row[1]); + // if (row[2] != DBNull.Value) detectionItem.StartTime = Convert.ToDateTime(row[2]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[3] != DBNull.Value) detectionItem.EndTime = Convert.ToDateTime(row[3]).ToString("yyyy-MM-dd HH:mm:ss"); + // if (row[4] != DBNull.Value) detectionItem.Stability = row[4].ToString(); + // if (row[5] != DBNull.Value) detectionItem.Accuracy = row[5].ToString(); + // if (row[6] != DBNull.Value) detectionItem.BootFeature = row[6].ToString(); + // if (row[7] != DBNull.Value) detectionItem.AgeRate = row[7].ToString(); + // if (row[8] != DBNull.Value) detectionItem.Interval = row[8].ToString(); + // if (row[10] != DBNull.Value) detectionItem.Channel = row[10].ToString(); + // if (row[11] != DBNull.Value) detectionItem.Stability1 = row[11].ToString(); + // if (row[12] != DBNull.Value) detectionItem.Stability10 = row[12].ToString(); + // if (row[13] != DBNull.Value) detectionItem.Stability20 = row[13].ToString(); + // if (row[14] != DBNull.Value) detectionItem.Stability100 = row[14].ToString(); + + // } + //} } catch (MySqlException ex) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchDetectionItem: " + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "searchById: " + ex.Message); } return detectionItem; } diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs index e2a5893..5b3deb0 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DetectionServiceImpl.cs @@ -14,7 +14,7 @@ { class DetectionServiceImpl : DetectionService { - public int add(long deviceId, string frequency, string detecItemType, long detectionItemId) + public int add(long deviceId, string frequency, string detecItemType, long detectionItemId, DateTime time) { int iRetval = -1; try @@ -36,7 +36,7 @@ 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 = DateTime.Now; + cmd.Parameters.Add("@LOG_TIME", MySqlDbType.DateTime, 0).Value = time; cmd.Parameters.Add("@DETECTION_ITEM", MySqlDbType.String, 0).Value = detecItemType; cmd.Parameters.Add("@DETECTION_ITEM_ID", MySqlDbType.Int64, 0).Value = detectionItemId; @@ -108,24 +108,26 @@ string sQry = "SELECT * FROM r_detection where DEVICE_ID = " + deviceId +" and DETECTION_ITEM='" + detectionType + "' and (LOG_TIME BETWEEN '" + startTime + "' and '"+ endTime + "') and DETECTION_ITEM_ID="+detectionItemId+" order by LOG_TIME"; MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) { - Model.Detection detection = new Model.Detection(); - //姓名 - if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); - if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); - if (!aReader.IsDBNull(2)) detection.LogTime = Convert.ToDateTime(aReader.GetString(2)).ToString("yyyy-MM-dd HH:mm:ss"); - if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); - if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); + Detection detection = new Detection(); + + if (!aReader.IsDBNull(0)) detection.Id = Convert.ToInt64(aReader.GetString(0)); // id + if (!aReader.IsDBNull(1)) detection.DeviceId = Convert.ToInt64(aReader.GetString(1)); // devName + if (!aReader.IsDBNull(2)) detection.LogTime = aReader.GetString(2); // devCode + if (!aReader.IsDBNull(3)) detection.Frequency = aReader.GetString(3); // devType + if (!aReader.IsDBNull(4)) detection.DetectionItem = aReader.GetString(4); // devModel detectionDtoList.Add(detection); } + aReader.Close(); + - aCommand.Dispose(); } + aCommand.Dispose(); + } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs index 9413e2f..b224bc1 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DeviceServiceImpl.cs @@ -53,7 +53,8 @@ using (MySqlDataReader aReader = cmd.ExecuteReader()) { - if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + if (aReader.Read()) deviceId = Convert.ToInt64(aReader.GetString(0)); + aReader.Close(); } cmd.Dispose(); @@ -87,8 +88,7 @@ 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; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "sQry : "+ sQry + "; statusId="+ statusId); - + 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; @@ -183,7 +183,7 @@ } MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); - + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { while (aReader.Read()) @@ -208,10 +208,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -254,7 +255,30 @@ 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()) @@ -279,10 +303,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -342,7 +367,30 @@ 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()) @@ -372,10 +420,11 @@ deviceDtoList.Add(deviceDto); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); if (deviceDtoList.Count > 0) { foreach (DeviceDto deviceDto in deviceDtoList) @@ -442,9 +491,10 @@ { totalCount = aReader.GetInt32(0); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -477,89 +527,45 @@ return null; } } - - string sQry = "SELECT * FROM r_deviceview where ACTIVE = 0 and STATUSID = 2 " + "and ('" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' <= END_TIME)"; - - 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) + //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))"; + MySqlCommand aCommand = new MySqlCommand(sQry, DbConnectService.mySqlConnect); + + using (MySqlDataReader aReader = aCommand.ExecuteReader()) { - foreach (DataRow row in dt.Rows) + while (aReader.Read()) { DeviceView deviceView = new DeviceView(); - if (row[0] != DBNull.Value) deviceView.Id = Convert.ToInt64(row[0]); - if (row[1] != DBNull.Value) deviceView.DevName = row[1].ToString(); - if (row[2] != DBNull.Value) deviceView.DevCode = row[2].ToString(); - if (row[3] != DBNull.Value) deviceView.DevTypeId = row[3].ToString(); - if (row[4] != DBNull.Value) deviceView.DevModel = row[4].ToString(); - if (row[5] != DBNull.Value) deviceView.RegTime = row[5].ToString(); - if (row[6] != DBNull.Value) deviceView.CustomerName = row[6].ToString(); - if (row[7] != DBNull.Value) deviceView.CustomerDev = row[7].ToString(); - if (row[8] != DBNull.Value) deviceView.Channel = row[8].ToString(); - if (row[9] != DBNull.Value) deviceView.Active = Convert.ToInt32(row[9]); - if (row[10] != DBNull.Value) deviceView.StartTime = Convert.ToDateTime(row[10]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[11] != DBNull.Value) deviceView.EndTime = Convert.ToDateTime(row[11]).ToString("yyyy - MM - dd HH: mm:ss"); - if (row[12] != DBNull.Value) deviceView.StatusId = row[12].ToString(); - if (row[13] != DBNull.Value) deviceView.Stability = row[13].ToString(); - if (row[14] != DBNull.Value) deviceView.Accuracy = row[14].ToString(); - if (row[15] != DBNull.Value) deviceView.BootFeature = row[15].ToString(); - if (row[16] != DBNull.Value) deviceView.AgeRate = row[16].ToString(); - if (row[17] != DBNull.Value) deviceView.DetectionItemId = Convert.ToInt64(row[17]); + 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(); + + } - //using (MySqlDataReader aReader = aCommand.ExecuteReader()) - //{ - // while (aReader.Read()) - // { - // DeviceView deviceView = new DeviceView(); + aCommand.Dispose(); - // 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 - // //deviceView.DevTypeName = dictService.getNameByCode("devType", aReader.GetString(3)); - // } - // if (!aReader.IsDBNull(4)) deviceView.DevModel = aReader.GetString(4); // devModel - // if (!aReader.IsDBNull(5)) - // { - // DateTime reg = aReader.GetDateTime(5); // regTime - // deviceView.RegTime = reg.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); - // if (!aReader.IsDBNull(9)) deviceView.Active = Convert.ToInt32(aReader.GetString(9)); - // if (!aReader.IsDBNull(10)) - // { - // DateTime reg = aReader.GetDateTime(10); // regTime - // deviceView.StartTime = reg.ToString("yyyy-MM-dd HH:mm:ss"); - // } - // if (!aReader.IsDBNull(11)) - // { - // DateTime reg = aReader.GetDateTime(11); // regTime - // deviceView.EndTime = reg.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 = Convert.ToInt64(aReader.GetString(17)); - - // deviceViewList.Add(deviceView); - - // aCommand.Dispose(); - // } - //} - if (deviceViewList.Count > 0) { foreach (DeviceView deviceView in deviceViewList) @@ -568,9 +574,15 @@ } } } + + 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()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "getDeviceByChannel: " + ex.Message + " ; " + ex.ToString()); deviceViewList = null; } finally diff --git a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs index 1626aa5..42ca83c 100644 --- a/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs +++ b/RbFreqStandMeasure/R_DataBase/Service/Impl/DictServiceImpl.cs @@ -92,10 +92,11 @@ if (!aReader.IsDBNull(3)) dict.Code = aReader.GetString(3); nameList.Add(dict); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch(MySqlException ex) { @@ -139,10 +140,11 @@ if (!aReader.IsDBNull(3)) counterParam.GeneratorIp = aReader.GetString(3); if (!aReader.IsDBNull(4)) counterParam.SignalSourceIp = aReader.GetString(4); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { @@ -220,10 +222,11 @@ if (!aReader.IsDBNull(9)) counterCheckParam.CycThreshold2 = aReader.GetString(9); if (!aReader.IsDBNull(10)) counterCheckParam.CycEleAddValue = aReader.GetString(10); } - - aCommand.Dispose(); + aReader.Close(); + } + aCommand.Dispose(); } catch (MySqlException ex) { diff --git a/RbFreqStandMeasure/RbFreqStdMeas.cs b/RbFreqStandMeasure/RbFreqStdMeas.cs index beae3dc..8d74572 100644 --- a/RbFreqStandMeasure/RbFreqStdMeas.cs +++ b/RbFreqStandMeasure/RbFreqStdMeas.cs @@ -363,24 +363,7 @@ detectionItemService.stopDetection(deviceId, device.DetectionItemId, startTime, endTime, true); } } - deviceService.clearChannel(); - List detectionItemList = detectionItemService.getAll(); - if (detectionItemList != null && detectionItemList.Count > 0) - { - foreach (DetectionItem detectionItem in detectionItemList) - { - long detectionItemId = detectionItem.Id; - if (detectionItem.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem.Stability1.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "0", "", "", ""); - if (detectionItem.Stability10.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "0", "", ""); - if (detectionItem.Stability20.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "0", ""); - if (detectionItem.Stability100.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "", "0"); - if (detectionItem.Accuracy.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "0", "", "", "", "", "", "", ""); - if (detectionItem.BootFeature.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "0", "", "", "", "", "", ""); - if (detectionItem.AgeRate.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "0", "", "", "", "", ""); - } - } - + deviceService.clearChannel(); } else { @@ -590,7 +573,7 @@ break; case 3: // 频率计数器范围 - CounterCtrlForm counterForm = CounterCtrlForm.GetInstance(); + CounterCtrlForm counterForm = new CounterCtrlForm(); counterForm.Show(); panelMain.Controls.Add(counterForm); break; diff --git a/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe b/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe index 70dc261..11271b0 100644 --- a/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe +++ b/RbFreqStandMeasure/bin/Debug/RbFreqStandMeasure.exe Binary files differ diff --git a/RbFreqStandMeasure/counter/CounterCtrlForm.cs b/RbFreqStandMeasure/counter/CounterCtrlForm.cs index 951a19c..e45f17b 100644 --- a/RbFreqStandMeasure/counter/CounterCtrlForm.cs +++ b/RbFreqStandMeasure/counter/CounterCtrlForm.cs @@ -39,6 +39,9 @@ GPIBService tcpService = new TCPServiceImpl(); string valueOld = ""; + string valueOldBack = ""; + string valueOldSensi = ""; + string valueOldTime = ""; #region 样式常量定影 private readonly Color titleBackColor = Color.FromArgb(63, 132, 215); // #3F64D7 @@ -55,8 +58,8 @@ return _counterCtrlForm; } - - private CounterCtrlForm() + + public CounterCtrlForm() { InitializeComponent(); @@ -69,7 +72,7 @@ comboBox_detecModel.SelectedIndex = 0; InitTableCounter(); - LoadCounterDetecInitList(); + //LoadCounterDetecInitList(); if (list != null && list.Count > 0) { @@ -221,12 +224,12 @@ table_counterDetecInit.Columns.Add("initId", Type.GetType("System.Int32")); table_counterDetecInit.Columns.Add("counterDataId", Type.GetType("System.Int64")); - if (comboBox_counters.Text != "") + if (((DeviceDto)comboBox_counters.SelectedItem).DevName != "") { - List list = deviceService.search(comboBox_counters.Text, "", "", "", "", ""); + List list = deviceService.search(((DeviceDto)comboBox_counters.SelectedItem).DevName, "", "", "", "", ""); if (null != list && list.Count > 0) { - devType = list[0].DevTypeName; + devType = list[0].DevModel; devCode = list[0].DevCode; } @@ -344,6 +347,18 @@ { valueOld = dataGridView_CounterResult.CurrentCell.Value.ToString(); } + else if (e.ColumnIndex == 5) + { + valueOldBack = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } + else if (e.ColumnIndex == 6) + { + valueOldSensi = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } + else if (e.ColumnIndex == 7) + { + valueOldTime = dataGridView_CounterResult.CurrentCell.Value.ToString(); + } } @@ -522,7 +537,10 @@ dataGridView_CounterResult.ReadOnly = true; btn_add.Enabled = false; benDelete.Enabled = false; - ///btn_dropDetecModel.Enabled = false; + comboBox_counters.Enabled = false; + comboBox_detecModel.Enabled = false; + text_counterIp.ReadOnly = true; + text_signal.ReadOnly = true; string[] arr = text_counterIp.Text.Split('.'); if (arr.Length != 4) @@ -643,11 +661,11 @@ Invoke(new MethodInvoker(delegate () { SetDevTestDlg.inDetecCounterId = -1; - //text_devName.ReadOnly = false; - //btn_downCounterList.Enabled = true; btnStart.Enabled = true; - //btn_dropDetecModel.Enabled = true; - //textBox_detecModel.ReadOnly = false; + comboBox_counters.Enabled = true; + comboBox_detecModel.Enabled = true; + text_counterIp.ReadOnly = false; + text_signal.ReadOnly = false; })); dataGridView_CounterResult.ReadOnly = false; @@ -736,6 +754,8 @@ if (!checkFreq(value)) { MessageBox.Show("请输入格式正确的测量频率值!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldBack; + valueOldBack = ""; return; } } @@ -744,6 +764,8 @@ if (!checkCyc(value)) { MessageBox.Show("请输入格式正确的测量周期值!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldBack; + valueOldBack = ""; return; } } @@ -753,11 +775,21 @@ { if (!String.IsNullOrEmpty(value)) { + if (value.Contains(".") && ((value.IndexOf('.') != value.LastIndexOf('.')) || value.IndexOf('.') == 0 || value.LastIndexOf('.') == value.Length)) + { + MessageBox.Show("请输入格式正确的灵敏度!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldSensi; + valueOldSensi = ""; + return; + } + string pattern = @"^[0-9.]+$"; Regex regex = new Regex(pattern); if (!regex.IsMatch(value)) { MessageBox.Show("请输入格式正确的灵敏度!"); + dataGridView_CounterResult.CurrentCell.Value = valueOldSensi; + valueOldSensi = ""; return; } } @@ -772,7 +804,8 @@ } catch { - dataGridView_CounterResult.Rows[e.RowIndex].Cells[7].Value = ""; + dataGridView_CounterResult.CurrentCell.Value = valueOldTime; + valueOldTime = ""; MessageBox.Show("请输入格式正确的时间!"); return; } diff --git a/RbFreqStandMeasure/home/HomeCtrlForm.cs b/RbFreqStandMeasure/home/HomeCtrlForm.cs index b2568f7..586334d 100644 --- a/RbFreqStandMeasure/home/HomeCtrlForm.cs +++ b/RbFreqStandMeasure/home/HomeCtrlForm.cs @@ -7,6 +7,7 @@ using Casic.Birmm.RbFreqStandMeasure.Tools; using DevComponents.DotNetBar.Controls; using System; +using System.Collections; using System.Collections.Generic; using System.Data; using System.Drawing; @@ -23,16 +24,16 @@ public partial class HomeCtrlForm : UserControl { public static HomeCtrlForm homeCtrlForm; - int totalCount = 0; - int currentPage = 1; - int pageCount = 0; - int limitCount = 4; + public int totalCount = 0; + public int currentPage = 1; + public int pageCount = 0; + public int limitCount = 4; DataTable devToBeTestedTable = null; DataTable channelsTable = null; DeviceService deviceService = new DeviceServiceImpl(); List listChannelStatus = new List(); DetectionItemService detectionItemService = new DetectionItemServiceImpl(); - + public static Hashtable stoppedItemIdTable = new Hashtable(); public static List channelFreeList = new List(); private readonly object obj = new object(); @@ -166,10 +167,7 @@ Size = new Size(120, 32) }; tableToBeTested.Controls.Add(colCustomComp); - colCustomComp.BringToFront(); - - - + colCustomComp.BringToFront(); totalCount = 0; currentPage = 1; @@ -332,7 +330,7 @@ AutoSize = false, Text = "通道", Location = new Point(0, 0), - Size = new Size(50, 30) + Size = new Size(70, 30) }; dataGridView_Channel.Controls.Add(colChannelNo); colChannelNo.BringToFront(); @@ -346,7 +344,7 @@ BackColor = titleBackColor, AutoSize = false, Text = "仪器名称", - Location = new Point(50, 0), + Location = new Point(70, 0), Size = new Size(110, 30) }; dataGridView_Channel.Controls.Add(colDevName); @@ -361,8 +359,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "仪器编号", - Location = new Point(160, 0), - Size = new Size(110, 30) + Location = new Point(180, 0), + Size = new Size(120, 30) }; dataGridView_Channel.Controls.Add(colDevNo); colDevNo.BringToFront(); @@ -376,8 +374,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "送检单位", - Location = new Point(270, 0), - Size = new Size(110, 30) + Location = new Point(300, 0), + Size = new Size(120, 30) }; dataGridView_Channel.Controls.Add(colCustomName); colCustomName.BringToFront(); @@ -391,8 +389,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "开始时间", - Location = new Point(380, 0), - Size = new Size(120, 30) + Location = new Point(420, 0), + Size = new Size(100, 30) }; dataGridView_Channel.Controls.Add(colStartTime); colStartTime.BringToFront(); @@ -406,8 +404,8 @@ BackColor = titleBackColor, AutoSize = false, Text = "结束时间", - Location = new Point(500, 0), - Size = new Size(120, 30) + Location = new Point(520, 0), + Size = new Size(100, 30) }; dataGridView_Channel.Controls.Add(colEndTime); colEndTime.BringToFront(); @@ -492,6 +490,11 @@ dataGridView_Channel.Controls.Add(colAgingRate); colAgingRate.BringToFront(); } + + + + + } catch (Exception ex) { @@ -506,19 +509,22 @@ { lock (obj) { - channelFreeList.Clear(); - channelFreeList.Add("1"); - channelFreeList.Add("2"); - channelFreeList.Add("3"); - channelFreeList.Add("4"); - channelFreeList.Add("5"); - - listChannelStatus = deviceService.getDeviceByChannel(); - if (listChannelStatus != null && listChannelStatus.Count > 0) + // lock (channelFreeList) { - foreach (DeviceView device in listChannelStatus) + channelFreeList.Clear(); + channelFreeList.Add("1"); + channelFreeList.Add("2"); + channelFreeList.Add("3"); + channelFreeList.Add("4"); + channelFreeList.Add("5"); + + listChannelStatus = deviceService.getDeviceByChannel(); + if (listChannelStatus != null && listChannelStatus.Count > 0) { - channelFreeList.Remove(device.Channel); + foreach (DeviceView device in listChannelStatus) + { + channelFreeList.Remove(device.Channel); + } } } } @@ -533,125 +539,131 @@ { try { - lock (obj) + //Invoke(new MethodInvoker(delegate () { - channelsTable = new DataTable(); - - channelsTable.Columns.Add("channelNo", Type.GetType("System.String")); - channelsTable.Columns.Add("devName", Type.GetType("System.String")); - channelsTable.Columns.Add("devCode", Type.GetType("System.String")); - channelsTable.Columns.Add("customComp", Type.GetType("System.String")); - channelsTable.Columns.Add("startTime", Type.GetType("System.String")); - channelsTable.Columns.Add("endTime", Type.GetType("System.String")); - channelsTable.Columns.Add("channelStatus", Type.GetType("System.String")); - channelsTable.Columns.Add("stablility", Type.GetType("System.String")); - channelsTable.Columns.Add("accuracy", Type.GetType("System.String")); - channelsTable.Columns.Add("startup", Type.GetType("System.String")); - channelsTable.Columns.Add("agingRate", Type.GetType("System.String")); - channelsTable.Columns.Add("deviceId", Type.GetType("System.Int64")); - channelsTable.Columns.Add("deviceItemId", Type.GetType("System.Int64")); - //channelsTable.Columns.Add("devType", Type.GetType("System.String")); - //channelsTable.Columns.Add("devModel", Type.GetType("System.String")); - //channelsTable.Columns.Add("customCom", Type.GetType("System.String")); - - listChannelStatus = deviceService.getDeviceByChannel(); - - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelsTable.Rows.Add(channelsTable.NewRow()); - channelFreeList.Clear(); - channelFreeList.Add("1"); - channelFreeList.Add("2"); - channelFreeList.Add("3"); - channelFreeList.Add("4"); - channelFreeList.Add("5"); - - if (listChannelStatus != null && listChannelStatus.Count > 0) + lock (obj) { - foreach (DeviceView device in listChannelStatus) + //lock(channelFreeList) { - channelFreeList.Remove(device.Channel); - int index = Convert.ToInt32(device.Channel) - 1; - channelsTable.Rows[index]["channelNo"] = device.Channel; - channelsTable.Rows[index]["devName"] = device.DevName; - channelsTable.Rows[index]["devCode"] = device.DevCode; - channelsTable.Rows[index]["customComp"] = device.CustomerDev; - channelsTable.Rows[index]["startTime"] = device.StartTime; - channelsTable.Rows[index]["endTime"] = device.EndTime; - channelsTable.Rows[index]["channelStatus"] = "占用"; - channelsTable.Rows[index]["deviceId"] = device.Id; - channelsTable.Rows[index]["deviceItemId"] = device.DetectionItemId; + channelsTable = new DataTable(); - if (device.Stability.Equals("-3")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.Stability.Equals("-2")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.Stability.Equals("-1")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + channelsTable.Columns.Add("channelNo", Type.GetType("System.String")); + channelsTable.Columns.Add("devName", Type.GetType("System.String")); + channelsTable.Columns.Add("devCode", Type.GetType("System.String")); + channelsTable.Columns.Add("customComp", Type.GetType("System.String")); + channelsTable.Columns.Add("startTime", Type.GetType("System.String")); + channelsTable.Columns.Add("endTime", Type.GetType("System.String")); + channelsTable.Columns.Add("channelStatus", Type.GetType("System.String")); + channelsTable.Columns.Add("stablility", Type.GetType("System.String")); + channelsTable.Columns.Add("accuracy", Type.GetType("System.String")); + channelsTable.Columns.Add("startup", Type.GetType("System.String")); + channelsTable.Columns.Add("agingRate", Type.GetType("System.String")); + channelsTable.Columns.Add("deviceId", Type.GetType("System.Int64")); + channelsTable.Columns.Add("deviceItemId", Type.GetType("System.Int64")); - if (device.Accuracy.Equals("-3")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.Accuracy.Equals("-2")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.Accuracy.Equals("-1")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; - - if (device.AgeRate.Equals("-3")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.AgeRate.Equals("-2")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.AgeRate.Equals("-1")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; - - if (device.BootFeature.Equals("-3")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; - else if (device.BootFeature.Equals("-2")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; - else if (device.BootFeature.Equals("-1")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; - else this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + listChannelStatus = deviceService.getDeviceByChannel(); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelsTable.Rows.Add(channelsTable.NewRow()); + channelFreeList.Clear(); + channelFreeList.Add("1"); + channelFreeList.Add("2"); + channelFreeList.Add("3"); + channelFreeList.Add("4"); + channelFreeList.Add("5"); + + if (listChannelStatus != null && listChannelStatus.Count > 0) + { + foreach (DeviceView device in listChannelStatus) + { + if (String.IsNullOrEmpty(device.Channel)) continue; + channelFreeList.Remove(device.Channel); + int index = Convert.ToInt32(device.Channel) - 1; + channelsTable.Rows[index]["channelNo"] = device.Channel; + channelsTable.Rows[index]["devName"] = device.DevName; + channelsTable.Rows[index]["devCode"] = device.DevCode; + channelsTable.Rows[index]["customComp"] = device.CustomerDev; + channelsTable.Rows[index]["startTime"] = device.StartTime; + channelsTable.Rows[index]["endTime"] = device.EndTime; + channelsTable.Rows[index]["channelStatus"] = "占用"; + channelsTable.Rows[index]["deviceId"] = device.Id; + channelsTable.Rows[index]["deviceItemId"] = device.DetectionItemId; + + if (device.Stability.Equals("-3")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.Stability.Equals("-2")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.Stability.Equals("-1")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + if (device.Accuracy.Equals("-3")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.Accuracy.Equals("-2")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.Accuracy.Equals("-1")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + if (device.AgeRate.Equals("-3")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.AgeRate.Equals("-2")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.AgeRate.Equals("-1")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + if (device.BootFeature.Equals("-3")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line; + else if (device.BootFeature.Equals("-2")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray; + else if (device.BootFeature.Equals("-1")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange; + else this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green; + + + } + } + else + { + channelsTable.Rows.Clear(); + channelsTable.Rows.Add("1", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("2", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("3", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("4", "", "", "", "", "", "空闲", "", ""); + channelsTable.Rows.Add("5", "", "", "", "", "", "空闲", "", ""); + } + + foreach (string no in channelFreeList) + { + channelsTable.Rows[Convert.ToInt32(no) - 1]["channelNo"] = no; + channelsTable.Rows[Convert.ToInt32(no) - 1]["channelStatus"] = "空闲"; + } + + + dataGridView_Channel.DataSource = channelsTable; + + // width=764px + dataGridView_Channel.Columns[11].Visible = false; + dataGridView_Channel.Columns[12].Visible = false; + dataGridView_Channel.Columns[0].Width = 70; + dataGridView_Channel.Columns[1].Width = 110; + dataGridView_Channel.Columns[2].Width = 120; + dataGridView_Channel.Columns[3].Width = 120; + dataGridView_Channel.Columns[4].Width = 100; //starttime + dataGridView_Channel.Columns[5].Width = 100; //endtime + dataGridView_Channel.Columns[6].Width = 64; + dataGridView_Channel.Columns[7].Width = 75; + dataGridView_Channel.Columns[8].Width = 75; + dataGridView_Channel.Columns[9].Width = 75; + dataGridView_Channel.Columns[10].Width = 75; + + dataGridView_Channel.Columns[0].ReadOnly = true; + dataGridView_Channel.Columns[1].ReadOnly = true; + dataGridView_Channel.Columns[2].ReadOnly = true; + dataGridView_Channel.Columns[3].ReadOnly = true; + dataGridView_Channel.Columns[4].ReadOnly = true; + dataGridView_Channel.Columns[5].ReadOnly = true; + dataGridView_Channel.Columns[6].ReadOnly = true; + dataGridView_Channel.Columns[7].ReadOnly = true; + dataGridView_Channel.Columns[8].ReadOnly = true; + dataGridView_Channel.Columns[9].ReadOnly = true; + dataGridView_Channel.Columns[10].ReadOnly = true; } } - else - { - channelsTable.Rows.Clear(); - channelsTable.Rows.Add("1", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("2", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("3", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("4", "", "", "", "", "", "空闲", "", ""); - channelsTable.Rows.Add("5", "", "", "", "", "", "空闲", "", ""); - } - - foreach (string no in channelFreeList) - { - channelsTable.Rows[Convert.ToInt32(no) - 1]["channelNo"] = no; - channelsTable.Rows[Convert.ToInt32(no) - 1]["channelStatus"] = "空闲"; - } - - - dataGridView_Channel.DataSource = channelsTable; - - // width=764px - dataGridView_Channel.Columns[11].Visible = false; - dataGridView_Channel.Columns[12].Visible = false; - dataGridView_Channel.Columns[0].Width = 50; - dataGridView_Channel.Columns[1].Width = 110; - dataGridView_Channel.Columns[2].Width = 110; - dataGridView_Channel.Columns[3].Width = 110; - dataGridView_Channel.Columns[4].Width = 120; - dataGridView_Channel.Columns[5].Width = 120; - dataGridView_Channel.Columns[6].Width = 64; - dataGridView_Channel.Columns[7].Width = 75; - dataGridView_Channel.Columns[8].Width = 75; - dataGridView_Channel.Columns[9].Width = 75; - dataGridView_Channel.Columns[10].Width = 75; - - dataGridView_Channel.Columns[0].ReadOnly = true; - dataGridView_Channel.Columns[1].ReadOnly = true; - dataGridView_Channel.Columns[2].ReadOnly = true; - dataGridView_Channel.Columns[3].ReadOnly = true; - dataGridView_Channel.Columns[4].ReadOnly = true; - dataGridView_Channel.Columns[5].ReadOnly = true; - dataGridView_Channel.Columns[6].ReadOnly = true; - dataGridView_Channel.Columns[7].ReadOnly = true; - dataGridView_Channel.Columns[8].ReadOnly = true; - dataGridView_Channel.Columns[9].ReadOnly = true; - dataGridView_Channel.Columns[10].ReadOnly = true; + //})); } } catch (Exception ex) @@ -760,7 +772,6 @@ private void cellDoubleClick(int rowIndex) { - int colIndex = dataGridView_Channel.CurrentCell.ColumnIndex; if (dataGridView_Channel.Rows[rowIndex].Cells[6].Value.ToString().Equals("占用")) { if (MessageBox.Show("该通道有正在检测的仪器,确定要停止检测?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) @@ -780,30 +791,22 @@ { return; } + DialogResult dialogResult = MessageBox.Show("是否保存此次检测的数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { - detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, false); + detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, false); } else { detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, true); } - DetectionItem detectionItem0 = detectionItemService.getById(deviceItemId); - if (detectionItem0 != null) - { - if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem0.Stability1.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "0", "", "", ""); - if (detectionItem0.Stability10.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "", "0", "", ""); - if (detectionItem0.Stability20.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "", "", "0", ""); - if (detectionItem0.Stability100.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "", "", "", "", "", "0"); - if (detectionItem0.Accuracy.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "0", "", "", "", "", "", "", ""); - if (detectionItem0.BootFeature.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "0", "", "", "", "", "", ""); - if (detectionItem0.AgeRate.Equals("-1")) detectionItemService.updateDetecStatus(deviceItemId, "", "", "", "0", "", "", "", "", ""); - - } + if (stoppedItemIdTable.Contains(rowIndex + 1)) stoppedItemIdTable.Remove(rowIndex + 1); + + stoppedItemIdTable.Add(rowIndex + 1, deviceItemId); LoadChannelStatus(); + currentPage = 1; LoadDevToBeTested(); } catch(Exception ex) diff --git a/RbFreqStandMeasure/home/SetDevChannelDlg.cs b/RbFreqStandMeasure/home/SetDevChannelDlg.cs index fe3bcdd..a1d96fe 100644 --- a/RbFreqStandMeasure/home/SetDevChannelDlg.cs +++ b/RbFreqStandMeasure/home/SetDevChannelDlg.cs @@ -84,9 +84,12 @@ timePicker_startTime.MinDate = DateTime.Now; getEndTime(); List listToTest = deviceService.search("", "", "", "", "", "1"); - foreach (DeviceDto deviceDto in listToTest) + if (listToTest != null && listToTest.Count > 0) { - cbBox_toTestDevList.Items.Add(deviceDto.DevCode); + foreach (DeviceDto deviceDto in listToTest) + { + cbBox_toTestDevList.Items.Add(deviceDto.DevCode); + } } text_customerDev.Visible = true; @@ -202,7 +205,7 @@ if (checkBox10s.Checked) stability10 = "-1"; if (checkBox20s.Checked) stability20 = "-1"; if (checkBox_100s.Checked) stability100 = "-1"; - detectionHelper.detecStability(deviceId, startTime, interval, port, true ,false); + detectionHelper.detecStability(deviceId, startTime, interval, port, true, false); } else { @@ -257,8 +260,10 @@ } long detectionId0 = detectionItemService.add(deviceId, startTime, endTime, stability, accuracy, bootFeature, ageRate, interval, textBox_channelNo.Text,stability1,stability10,stability20,stability100); detectionHelper.detectionItemId = detectionId0; + this.HideMaskAction(); HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + HomeCtrlForm.homeCtrlForm.currentPage = 1; HomeCtrlForm.homeCtrlForm.LoadDevToBeTested(); } catch (Exception ex) @@ -311,18 +316,18 @@ private void getEndTime() { - if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddSeconds(30); + if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddMinutes(1).AddSeconds(30); else { - if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddSeconds(30); + if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddMinutes(1).AddSeconds(30); else { if (checkBox_stability.Checked) { - if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddSeconds(40); - else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddSeconds(40); - else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddSeconds(40); - else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddSeconds(40); + if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddMinutes(1).AddSeconds(30); + else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddMinutes(1).AddSeconds(30); + else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddMinutes(1).AddSeconds(30); + else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddMinutes(1).AddSeconds(30); } else endTimeBySystem = timePicker_startTime.Value.AddMinutes(1).AddSeconds(30); } diff --git a/RbFreqStandMeasure/home/SetDevTestDlg.cs b/RbFreqStandMeasure/home/SetDevTestDlg.cs index f1027ba..6e9d272 100644 --- a/RbFreqStandMeasure/home/SetDevTestDlg.cs +++ b/RbFreqStandMeasure/home/SetDevTestDlg.cs @@ -23,11 +23,7 @@ public static long inDetecCounterId = -1;// 正在检测灵敏度的计数器id DateTime endTimeBySystem = new DateTime(); - CounterDataService CounterDataService = new CounterDataServiceImpl(); - CounterDetecInitService counterDetecInitService = new CounterDetecInitServiceImpl(); DictService dictService = new DictServiceImpl(); - SensitivityService sensitivityService = new SensitivityServiceImpl(); - CounterDataService counterDataService = new CounterDataServiceImpl(); DeviceService deviceService = new DeviceServiceImpl(); @@ -221,6 +217,7 @@ this.HideMaskAction(); HomeCtrlForm.homeCtrlForm.refreshChannelList(); HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + HomeCtrlForm.homeCtrlForm.currentPage = 1; HomeCtrlForm.homeCtrlForm.LoadDevToBeTested(); } @@ -280,18 +277,18 @@ private void getEndTime() { - if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddSeconds(30); + if (checkBox_ageRate.Checked) endTimeBySystem = timePicker_startTime.Value.AddDays(7).AddMinutes(1).AddSeconds(30); else { - if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddSeconds(30); + if (checkBox_bootFeature.Checked) endTimeBySystem = timePicker_startTime.Value.AddHours(7).AddMinutes(1).AddSeconds(30); else { if (checkBox_stability.Checked) { - if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddSeconds(40); - else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddSeconds(40); - else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddSeconds(40); - else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddSeconds(40); + if (checkBox_100s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 100).AddMinutes(1).AddSeconds(30); + else if (checkBox20s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 20).AddMinutes(1).AddSeconds(30); + else if (checkBox10s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101 * 10).AddMinutes(1).AddSeconds(30); + else if (checkBox1s.Checked) endTimeBySystem = timePicker_startTime.Value.AddSeconds(101).AddMinutes(1).AddSeconds(30); } else endTimeBySystem = timePicker_startTime.Value.AddMinutes(1).AddSeconds(30); } diff --git a/RbFreqStandMeasure/info/AddDevDlg.cs b/RbFreqStandMeasure/info/AddDevDlg.cs index 46d4778..6abc5b0 100644 --- a/RbFreqStandMeasure/info/AddDevDlg.cs +++ b/RbFreqStandMeasure/info/AddDevDlg.cs @@ -254,16 +254,13 @@ { if (needDetec) statusId = "2"; devService.update(deviceId, devName, devCode, devTypeCode, devModel, devCustomComp, devCustomName, channelNo,statusId); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "update 完成"); - + } //添加检测 if (deviceId != -1 && needDetec) - { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "各项检测开始。。。。"); - + { //开始检测 //稳定度 @@ -337,9 +334,7 @@ detectionHelper.detecAgeRate(deviceId, startTime, port, false); } } - - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "更新检测记录表" + deviceId); - + //开始检测 long detectionId0 = detectionItemService.add(deviceId, startTime, endTime, stability, accuracy, bootFeature, ageRate, interval, text_channelNo.Text, stability1, stability10, stability20, stability100); detectionHelper.detectionItemId = detectionId0; @@ -439,18 +434,18 @@ private void getEndTime() { - if (checkBox_ageRate.Checked) endTimeBySystem = picker_startTime.Value.AddDays(7).AddSeconds(30); + if (checkBox_ageRate.Checked) endTimeBySystem = picker_startTime.Value.AddDays(7).AddMinutes(1).AddSeconds(30); else { - if (checkBox_bootFeature.Checked) endTimeBySystem = picker_startTime.Value.AddHours(7).AddSeconds(30); + if (checkBox_bootFeature.Checked) endTimeBySystem = picker_startTime.Value.AddHours(7).AddMinutes(1).AddSeconds(30); else { if (checkBox_stability.Checked) { - if (checkBox100s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 100).AddSeconds(40); - else if (checkBox20s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 20).AddSeconds(40); - else if (checkBox10s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 10).AddSeconds(40); - else if (checkBox1s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101).AddSeconds(40); + if (checkBox100s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 100).AddMinutes(1).AddSeconds(30); + else if (checkBox20s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 20).AddMinutes(1).AddSeconds(30); + else if (checkBox10s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101 * 10).AddMinutes(1).AddSeconds(30); + else if (checkBox1s.Checked) endTimeBySystem = picker_startTime.Value.AddSeconds(101).AddMinutes(1).AddSeconds(30); } else endTimeBySystem = picker_startTime.Value.AddMinutes(1).AddSeconds(30); } diff --git a/RbFreqStandMeasure/info/DetailDlg.cs b/RbFreqStandMeasure/info/DetailDlg.cs index ad05a32..cc05eac 100644 --- a/RbFreqStandMeasure/info/DetailDlg.cs +++ b/RbFreqStandMeasure/info/DetailDlg.cs @@ -86,17 +86,17 @@ resultBootStr = dataGridView_times.Rows[0].Cells[5].Value.ToString(); resultAgeStr = dataGridView_times.Rows[0].Cells[6].Value.ToString(); - if (!resultAccStr.Equals("-1") && !resultAccStr.Equals("-2") && !resultAccStr.Equals("-3")) tabPageEvent("tab_accuracy"); - if ((!resultStaStr1.Equals("-1")&& !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3")) || (!resultStaStr10.Equals("-1")&& !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3")) ||( !resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3"))) + if (!resultAccStr.Equals("-1") && !resultAccStr.Equals("-2") && !resultAccStr.Equals("-3") && !resultAccStr.Equals("0")) tabPageEvent("tab_accuracy"); + if ((!resultStaStr1.Equals("-1")&& !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3") && !resultStaStr1.Equals("0")) || (!resultStaStr10.Equals("-1")&& !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3") && !resultStaStr10.Equals("0")) ||( !resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3") && !resultStaStr100.Equals("0"))) { tabPageEvent("tab_stability"); - if (!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3")) radio_1s.Checked = true; - else if (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3")) radio_10s.Checked = true; - else if(!resultStaStr20.Equals("-1") && !resultStaStr20.Equals("-2") && !resultStaStr20.Equals("-3")) radio_20s.Checked = true; - else if (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3")) radio_100s.Checked = true; + if (!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3") && !resultStaStr1.Equals("0")) loadStability1(); + else if (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3") && !resultStaStr10.Equals("0")) loadStability10(); + else if(!resultStaStr20.Equals("-1") && !resultStaStr20.Equals("-2") && !resultStaStr20.Equals("-3") && !resultStaStr20.Equals("0")) loadStability20(); + else if (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3") && !resultStaStr100.Equals("0")) loadStability100(); } - if (!resultBootStr.Equals("-1")&& !resultBootStr.Equals("-2")&& !resultBootStr.Equals("-3")) tabPageEvent("tab_bootFeature"); - if (!resultAgeStr.Equals("-1")&&!resultAgeStr.Equals("-2")&& !resultAgeStr.Equals("-3")) tabPageEvent("tab_ageRate"); + if (!resultBootStr.Equals("-1")&& !resultBootStr.Equals("-2")&& !resultBootStr.Equals("-3") && !resultBootStr.Equals("0")) tabPageEvent("tab_bootFeature"); + if (!resultAgeStr.Equals("-1")&&!resultAgeStr.Equals("-2")&& !resultAgeStr.Equals("-3") && !resultAgeStr.Equals("0")) tabPageEvent("tab_ageRate"); } if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; @@ -305,17 +305,17 @@ resultBootStr = dataGridView_times.Rows[rowIndex].Cells[5].Value.ToString(); resultAgeStr = dataGridView_times.Rows[rowIndex].Cells[6].Value.ToString(); - if (!resultAccStr.Equals("-1") && !resultAccStr.Equals("-2") && !resultAccStr.Equals("-3")) tabPageEvent("tab_accuracy"); - else if ((!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3")) || (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3")) || (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3"))) + if (!resultAccStr.Equals("-1") && !resultAccStr.Equals("-2") && !resultAccStr.Equals("-3") && !resultAccStr.Equals("0")) tabPageEvent("tab_accuracy"); + else if ((!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3") && !resultStaStr1.Equals("0")) || (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3") && !resultStaStr10.Equals("0")) || (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3") && !resultStaStr100.Equals("0"))) { tabPageEvent("tab_stability"); - if (!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3")) radio_1s.Checked = true; - else if (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3")) radio_10s.Checked = true; - else if (!resultStaStr20.Equals("-1") && !resultStaStr20.Equals("-2") && !resultStaStr20.Equals("-3")) radio_20s.Checked = true; - else if (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3")) radio_100s.Checked = true; + if (!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3") && !resultStaStr1.Equals("0")) loadStability1(); + else if (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3") && !resultStaStr10.Equals("0")) loadStability10(); + else if (!resultStaStr20.Equals("-1") && !resultStaStr20.Equals("-2") && !resultStaStr20.Equals("-3") && !resultStaStr20.Equals("0")) loadStability20(); + else if (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3") && !resultStaStr100.Equals("0")) loadStability100(); } - else if (!resultBootStr.Equals("-1") && !resultBootStr.Equals("-2") && !resultBootStr.Equals("-3")) tabPageEvent("tab_bootFeature"); - else if (!resultAgeStr.Equals("-1") && !resultAgeStr.Equals("-2") && !resultAgeStr.Equals("-3")) tabPageEvent("tab_ageRate"); + else if (!resultBootStr.Equals("-1") && !resultBootStr.Equals("-2") && !resultBootStr.Equals("-3") && !resultBootStr.Equals("0")) tabPageEvent("tab_bootFeature"); + else if (!resultAgeStr.Equals("-1") && !resultAgeStr.Equals("-2") && !resultAgeStr.Equals("-3") && !resultAgeStr.Equals("0")) tabPageEvent("tab_ageRate"); } } @@ -362,6 +362,7 @@ groupBox3.Text = "频率准确度"; accuracy result = new accuracy(); result.label_accuracy.Text = ""; + if (!resultAccStr.Equals("-1") && !resultAccStr.Equals("-2") && !resultAccStr.Equals("-3")) result.label_accuracy.Text = resultAccStr; result.Show(); panel_result.Controls.Add(result); @@ -476,70 +477,106 @@ private void radio_10s_CheckedChanged(object sender, EventArgs e) { if (radio_10s.Checked) - { - LoadData(deviceId, "1-10", startTime, endTime); - groupBox3.Text = "10s频率稳定度"; - panel_result.Controls.Clear(); - stability result = new stability(); - result.label_stability.Text = ""; - if (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3")) result.label_stability.Text = resultStaStr10; - result.Show(); - panel_result.Controls.Add(result); - btn_reDetec.Enabled = true; - if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + { + loadStability10(); } } + private void loadStability10() + { + radio_10s.Checked = true; + LoadData(deviceId, "1-10", startTime, endTime); + groupBox3.Text = "10s频率稳定度"; + panel_result.Controls.Clear(); + stability result = new stability(); + result.label_stability.Text = ""; + if (!resultStaStr10.Equals("-1") && !resultStaStr10.Equals("-2") && !resultStaStr10.Equals("-3")) + { + result.label_stability.Text = resultStaStr10; + result.label_count.Text = "101"; + } + result.Show(); + panel_result.Controls.Add(result); + btn_reDetec.Enabled = true; + if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + } private void radio_1s_CheckedChanged(object sender, EventArgs e) { if (radio_1s.Checked) { - LoadData(deviceId, "1-1", startTime, endTime); - groupBox3.Text = "1s频率稳定度"; - panel_result.Controls.Clear(); - stability result = new stability(); - result.label_stability.Text = ""; - if (!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3")) result.label_stability.Text = resultStaStr1; - result.Show(); - btn_reDetec.Enabled = true; - panel_result.Controls.Add(result); - if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + loadStability1(); } } + private void loadStability1() + { + radio_1s.Checked = true; + LoadData(deviceId, "1-1", startTime, endTime); + groupBox3.Text = "1s频率稳定度"; + panel_result.Controls.Clear(); + stability result = new stability(); + result.label_stability.Text = ""; + if (!resultStaStr1.Equals("-1") && !resultStaStr1.Equals("-2") && !resultStaStr1.Equals("-3")) + { + result.label_stability.Text = resultStaStr1; + result.label_count.Text = "101"; + } + result.Show(); + btn_reDetec.Enabled = true; + panel_result.Controls.Add(result); + if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + } private void radio_20s_CheckedChanged(object sender, EventArgs e) { if (radio_20s.Checked) { - LoadData(deviceId, "1-20", startTime, endTime); - groupBox3.Text = "20s频率稳定度"; - panel_result.Controls.Clear(); - stability result = new stability(); - result.label_stability.Text = ""; - if (!resultStaStr20.Equals("-1")&& !resultStaStr20.Equals("-2")&&!resultStaStr20.Equals("-3")) result.label_stability.Text = resultStaStr20; - result.Show(); - panel_result.Controls.Add(result); - btn_reDetec.Enabled = true; - if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + loadStability20(); } } + private void loadStability20() + { + radio_20s.Checked = true; + LoadData(deviceId, "1-20", startTime, endTime); + groupBox3.Text = "20s频率稳定度"; + panel_result.Controls.Clear(); + stability result = new stability(); + result.label_stability.Text = ""; + if (!resultStaStr20.Equals("-1") && !resultStaStr20.Equals("-2") && !resultStaStr20.Equals("-3")) + { + result.label_stability.Text = resultStaStr20; + result.label_count.Text = "101"; + } + result.Show(); + panel_result.Controls.Add(result); + btn_reDetec.Enabled = true; + if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + } private void radio_100s_CheckedChanged(object sender, EventArgs e) { if (radio_100s.Checked) { - LoadData(deviceId, "1-100", startTime, endTime); - groupBox3.Text = "100s频率稳定度"; - panel_result.Controls.Clear(); - stability result = new stability(); - result.label_stability.Text = ""; - if (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3")) result.label_stability.Text = resultStaStr100; - result.Show(); - panel_result.Controls.Add(result); - btn_reDetec.Enabled = true; - if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + loadStability100(); } } + private void loadStability100() + { + radio_100s.Checked = true; + LoadData(deviceId, "1-100", startTime, endTime); + groupBox3.Text = "100s频率稳定度"; + panel_result.Controls.Clear(); + stability result = new stability(); + result.label_stability.Text = ""; + if (!resultStaStr100.Equals("-1") && !resultStaStr100.Equals("-2") && !resultStaStr100.Equals("-3")) + { + result.label_stability.Text = resultStaStr100; + result.label_count.Text = "101"; + } + result.Show(); + panel_result.Controls.Add(result); + btn_reDetec.Enabled = true; + if (dataGridView_Data.Rows.Count == 0) btn_reDetec.Enabled = false; + } public void updateChannelNoRedetec() { diff --git a/RbFreqStandMeasure/tools/DetectionHelper.cs b/RbFreqStandMeasure/tools/DetectionHelper.cs index 2070bac..3faf914 100644 --- a/RbFreqStandMeasure/tools/DetectionHelper.cs +++ b/RbFreqStandMeasure/tools/DetectionHelper.cs @@ -1,18 +1,14 @@ using Casic.Birmm.RbFreqStandMeasure.info; -using Casic.Birmm.RbFreqStandMeasure.Properties; using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Model; using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Service; using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Service.Impl; using Casic.Birmm.RbFreqStandMeasure.Tools; using System; +using System.Collections; using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Drawing2D; using System.IO.Ports; -using System.Linq; using System.Reflection; using System.Text; -using System.Text.RegularExpressions; using System.Threading; using System.Windows.Forms; @@ -37,12 +33,12 @@ private System.Threading.Timer timerStability10; private System.Threading.Timer timerStability20; private System.Threading.Timer timerStability100; - private long devIdStability = -1; - private SerialPort portStability; - private List resultStability1 = new List(); - private List resultStability10 = new List(); - private List resultStability20 = new List(); - private List resultStability100 = new List(); + private long devIdStability = -1; + private SerialPort portStability; + private Hashtable resultStability1 = new Hashtable(); + private Hashtable resultStability10 = new Hashtable(); + private Hashtable resultStability20 = new Hashtable(); + private Hashtable resultStability100 = new Hashtable(); private System.Threading.Timer timerBootFeature; private long devIdBootFeature = -1; @@ -61,6 +57,7 @@ private int count10s = 0; private int count20s = 0; private bool isStarted = true; + private DetectionItem item=null; //1-STABILITY,2-ACCURACY,3-BOOT_FEATURE,4-AGE_RATE @@ -74,36 +71,44 @@ #region 稳定度 public void detecStability(long deviceId, string startTime, string interval, SerialPort port,bool isNow, bool isUpdates) { - resultStability1 = new List(); - resultStability10 = new List(); - resultStability20 = new List(); - resultStability100 = new List(); - count1s = 0; - count10s = 0; - count20s = 0; - if (isUpdates) + try { - isUpdate = true; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测稳定度 interval =" + interval + ";detectionItemId="+detectionItemId); + resultStability1 = new Hashtable(); + resultStability10 = new Hashtable(); + resultStability20 = new Hashtable(); + resultStability100 = new Hashtable(); + count1s = 0; + count10s = 0; + count20s = 0; + if (isUpdates) + { + isUpdate = true; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测稳定度 interval =" + interval + ";detectionItemId=" + detectionItemId); + } + portStability = port; + devIdStability = deviceId; + int delay = 0; + if (Convert.ToDateTime(startTime) > DateTime.Now) + { + isStarted = false; + TimeSpan secondSpan = new TimeSpan(Convert.ToDateTime(startTime).Ticks - DateTime.Now.Ticks); + delay = (int)secondSpan.TotalMilliseconds; + } + string[] arr = interval.Split(','); + + foreach (string inter in arr) + { + if (inter.Equals("1")) timerStability1 = new System.Threading.Timer(exeStability1, null, delay + 100, 1000); + if (inter.Equals("10")) timerStability10 = new System.Threading.Timer(exeStability10, null, delay + 100, 10 * 1000); + if (inter.Equals("20")) timerStability20 = new System.Threading.Timer(exeStability20, null, delay + 100, 20 * 1000); + if (inter.Equals("100")) timerStability100 = new System.Threading.Timer(exeStability100, null, delay + 100, 100 * 1000); + } } - portStability = port; - devIdStability = deviceId; - int delay = 0; - if (Convert.ToDateTime(startTime) > DateTime.Now) + catch (Exception ex) { - isStarted = false; - TimeSpan secondSpan = new TimeSpan(Convert.ToDateTime(startTime).Ticks - DateTime.Now.Ticks); - delay = (int)secondSpan.TotalMilliseconds; - } - string[] arr = interval.Split(','); - - foreach (string inter in arr) - { - if (inter.Equals("1")) timerStability1 = new System.Threading.Timer(exeStability1, null, delay + 100, 1000); - if (inter.Equals("10")) timerStability10 = new System.Threading.Timer(exeStability10, null, delay + 100, 10 * 1000); - if (inter.Equals("20")) timerStability20 = new System.Threading.Timer(exeStability20, null, delay + 100, 20 * 1000); - if (inter.Equals("100")) timerStability100 = new System.Threading.Timer(exeStability100, null, delay + 100, 100 * 1000); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "detecStability error: "+ ex.Message + ex.ToString()); + } } private void exeStability1(Object State) @@ -116,75 +121,104 @@ { while (true) { - if (detectionItemId != -1) - { - DetectionItem item = detectionItemService.getById(detectionItemId); - if (item==null||(item!=null&&Convert.ToDateTime(item.EndTime) < DateTime.Now)) + try + { + if (detectionItemId != -1) { - timerStability1.Dispose(); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,稳定度1s,devId="+ devIdStability+";detectionItemId="+ detectionItemId); - - return; - } - if (!isStarted) - { - isStarted = true; - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); - if (detectionItem0.Stability10.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); - if (detectionItem0.Stability20.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); - if (detectionItem0.Stability100.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); - if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); - if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); - if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); + //if (item == null || (item != null && item.IsDetecting.Equals("0"))) + if(HomeCtrlForm.stoppedItemIdTable.ContainsValue(detectionItemId)) + { + timerStability1.Dispose(); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,稳定度1s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + return; + } + if (!isStarted) + { + isStarted = true; + DetectionItem item = detectionItemService.getById(detectionItemId); + + if (item.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); + if (item.Stability10.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); + if (item.Stability20.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); + if (item.Stability100.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); + if (item.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); + if (item.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); + if (item.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "更新通道列表; detectionItemId=" + detectionItemId); + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + } + break; } - break; } - + catch(Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "检测错误1:"+ex.ToString()); + } + } string result = ""; string fre = getFrequencyData(portStability,false); - if (fre.Equals("close")) + try { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,稳定度1s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); - - timerStability1.Dispose(); - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem0.Stability1.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "0", "", "", ""); - - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - deviceService.updateStatus(devIdStability, "1", ""); - return; - } - if (!fre.Equals("") && resultStability1.Count<101) - { - resultStability1.Add(fre); - if (resultStability1.Count == 101) timerStability1.Dispose(); - if (!isUpdate && count1s < 101) + if (fre.Equals("close")) { - detectionService.add(devIdStability, fre, "1-1",detectionItemId); - count1s++; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,1s稳定度,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,稳定度1s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + + timerStability1.Dispose(); + //DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); + //if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); + //if (detectionItem0.Stability1.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "0", "", "", ""); + deviceService.updateStatus(devIdStability, "1", ""); + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + + return; } - } + } + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "检测错误2:" + ex.ToString()); + } + try + { + if (!fre.Equals("") && resultStability1.Count < 101) + { + if (resultStability1.Count == 101) timerStability1.Dispose(); + if (!isUpdate && count1s < 101) + { + resultStability1.Add(DateTime.Now, fre); + count1s++; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,1s稳定度,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + } + } + } + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "检测错误3:" + ex.ToString()); + } if (!isUpdate) { if (resultStability1.Count == 101) - { - result = FreMath.Stable(resultStability1) + ""; - resultStability1.Clear(); + { + List resultList = new List(); + foreach (DictionaryEntry de in resultStability1) + { + resultList.Add(de.Value.ToString()); + detectionService.add(devIdStability,de.Value.ToString(), "1-1",detectionItemId, Convert.ToDateTime(de.Key)); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "1s稳定度测量结果:" + result + ", devId =" + devIdStability + ";detectionItemId=" + detectionItemId); + } + resultStability1.Clear(); + result = FreMath.Stable(resultList) + ""; + + + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "1s稳定度测量结果:" + result + ", devId =" + devIdStability + ";detectionItemId=" + detectionItemId); // 更新检测结果 - detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", result, "", "", ""); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "detectionId :" + detectionItemId); - + detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", result, "", "", ""); + DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); if (detectionItem != null) { @@ -212,11 +246,18 @@ LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测稳定度1s得到结果,detectionItemId="+ detectionItemId); timerStability1.Dispose(); - - string result1 = FreMath.Stable(resultStability1) + ""; + List resultList = new List(); + foreach (DictionaryEntry de in resultStability1) + { + resultList.Add(de.Value.ToString()); + } + resultStability1.Clear(); + result = FreMath.Stable(resultList) + ""; + + string result1 = FreMath.Stable(resultList) + ""; detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", result1, "", "", ""); - updateView(resultStability1); + updateView(resultList); stability.label_result.Text = result1; DetailDlg.detailDlg.resultStaStr1 = result1; resultStability1.Clear(); @@ -228,365 +269,431 @@ } catch (Exception ex) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "稳定度检测错误:" + ex.Message); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "稳定度检测错误:" + ex.Message + ex.ToString()); } } private void exeStability10(Object State) - { - lock (obj) + { + try { - while (true) + lock (obj) { - if (detectionItemId != -1) + while (true) { - DetectionItem item = detectionItemService.getById(detectionItemId); - if (item == null || (item != null && Convert.ToDateTime(item.EndTime) < DateTime.Now)) + if (detectionItemId != -1) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,稳定度10s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + //if (item == null || (item != null && item.IsDetecting.Equals("0"))) + if (HomeCtrlForm.stoppedItemIdTable.ContainsValue(detectionItemId)) + { + + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,稳定度10s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + + timerStability10.Dispose(); + return; + } + if (!isStarted) + { + isStarted = true; + + DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); + if (detectionItem0.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); + detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); + if (detectionItem0.Stability20.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); + if (detectionItem0.Stability100.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); + if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); + if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); + if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + + } + break; + } + + } + + string result = ""; + + string fre = getFrequencyData(portStability, false); + if (fre.Equals("close")) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,稳定度10s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + + timerStability10.Dispose(); + DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); + if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); + if (detectionItem0.Stability10.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "0", "", ""); + deviceService.updateStatus(devIdStability, "1", ""); + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + return; + } + + if (!fre.Equals("") && resultStability10.Count < 101) + { + resultStability10.Add(DateTime.Now, fre); + if (resultStability10.Count == 101) timerStability10.Dispose(); + if (!isUpdate && count10s < 101) + { + count10s++; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,10s稳定度,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + + } + } + + if (!isUpdate) + { + if (resultStability10.Count == 101) + { + timerStability10.Dispose(); + + List resultList = new List(); + foreach (DictionaryEntry de in resultStability10) + { + resultList.Add(de.Value.ToString()); + detectionService.add(devIdStability, de.Value.ToString(), "1-10", detectionItemId, Convert.ToDateTime(de.Key)); + + } + resultStability10.Clear(); + result = FreMath.Stable(resultList) + ""; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "10s稳定度检测结果:" + result + ", devId =" + devIdStability + ";detectionItemId=" + detectionItemId); + + detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", result, "", ""); + + + DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); + if (detectionItem != null) + { + //更新稳定度检测状态 + if (!detectionItem.Stability1.Equals("-1") && !detectionItem.Stability10.Equals("-1") && !detectionItem.Stability20.Equals("-1") && !detectionItem.Stability100.Equals("-1")) + { + detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); + } + + detectionItem = detectionItemService.searchById(detectionItemId); + //更新整个仪器检测状态 + if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1")) + { + deviceService.updateStatus(devIdStability, "3", ""); + } + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + } + } + } + else + { + if (resultStability10.Count == 101) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测稳定度10s得到结果,detectionItemId=" + detectionItemId); timerStability10.Dispose(); - return; - } - if (!isStarted) - { - isStarted = true; - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); - detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); - if (detectionItem0.Stability20.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); - if (detectionItem0.Stability100.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); - if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); - if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); - if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); - - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + List resultList = new List(); + foreach (DictionaryEntry de in resultStability10) + { + resultList.Add(de.Value.ToString()); + } + resultStability10.Clear(); + string result1 = FreMath.Stable(resultList) + ""; - } - break; - } + detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", result1, "", ""); - } - - string result = ""; - - string fre = getFrequencyData(portStability, false); - if (fre.Equals("close")) - { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,稳定度10s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); - - timerStability10.Dispose(); - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem0.Stability10.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "0", "", ""); - - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - deviceService.updateStatus(devIdStability, "1", ""); - return; - } - - if (!fre.Equals("") && resultStability10.Count < 101) - { - resultStability10.Add(fre); - if (resultStability10.Count == 101) timerStability10.Dispose(); - if (!isUpdate && count10s < 101) - { - detectionService.add(devIdStability, fre, "1-10", detectionItemId); - count10s++; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,10s稳定度,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); - - } - } - - if (!isUpdate) - { - if (resultStability10.Count == 101) - { - timerStability10.Dispose(); - result = FreMath.Stable(resultStability10) + ""; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "10s稳定度检测结果:" + result +", devId =" + devIdStability + ";detectionItemId=" + detectionItemId); - - detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", result, "", ""); - - - DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); - if (detectionItem != null) - { - //更新稳定度检测状态 - if (!detectionItem.Stability1.Equals("-1") && !detectionItem.Stability10.Equals("-1") && !detectionItem.Stability20.Equals("-1") && !detectionItem.Stability100.Equals("-1")) - { - detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - } - - detectionItem = detectionItemService.searchById(detectionItemId); - //更新整个仪器检测状态 - if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1")) - { - deviceService.updateStatus(devIdStability, "3", ""); - } - - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + updateView(resultList); + stability.label_result.Text = result1; + DetailDlg.detailDlg.resultStaStr10 = result1; } } } - else - { - if (resultStability10.Count == 101) - { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测稳定度10s得到结果,detectionItemId=" + detectionItemId); + } + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "exeStability10 error: " + ex.Message + ex.ToString()); - timerStability10.Dispose(); - - - string result1 = FreMath.Stable(resultStability10) + ""; - detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", result1, "", ""); - - updateView(resultStability10); - stability.label_result.Text = result1; - DetailDlg.detailDlg.resultStaStr10 = result1; - } - } } } private void exeStability20(Object State) - { - lock (obj) + { + try { - while (true) + lock (obj) { - if (detectionItemId != -1) + while (true) { - DetectionItem item = detectionItemService.getById(detectionItemId); - if (item == null || (item != null && Convert.ToDateTime(item.EndTime) < DateTime.Now)) + if (detectionItemId != -1) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,稳定度20s, devId = " + devIdStability + "; detectionItemId = " + detectionItemId); + if (HomeCtrlForm.stoppedItemIdTable.ContainsValue(detectionItemId)) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,稳定度20s, devId = " + devIdStability + "; detectionItemId = " + detectionItemId); + + timerStability20.Dispose(); + return; + } + if (!isStarted) + { + isStarted = true; + DetectionItem item = detectionItemService.getById(detectionItemId); + + DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); + if (detectionItem0.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); + if (detectionItem0.Stability10.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); + detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); + if (detectionItem0.Stability100.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); + if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); + if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); + if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + + } + break; + } + + } + string result = ""; + + string fre = getFrequencyData(portStability, false); + if (fre.Equals("close")) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,稳定度20s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + + timerStability20.Dispose(); + DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); + if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); + if (detectionItem0.Stability20.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "0", ""); + deviceService.updateStatus(devIdStability, "1", ""); + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + return; + } + if (!fre.Equals("") && resultStability20.Count < 101) + { + resultStability20.Add(DateTime.Now, fre); + if (!isUpdate && count20s < 101) + { + count20s++; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,20s稳定度,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + + } + } + + + if (!isUpdate) + { + if (resultStability20.Count == 101) + { + timerStability20.Dispose(); + List resultList = new List(); + foreach (DictionaryEntry de in resultStability20) + { + resultList.Add(de.Value.ToString()); + detectionService.add(devIdStability, de.Value.ToString(), "1-20", detectionItemId, Convert.ToDateTime(de.Key)); + + } + resultStability20.Clear(); + result = FreMath.Stable(resultList) + ""; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "20s稳定度检测结果:" + result + ", devId =" + devIdStability + ";detectionItemId=" + detectionItemId); + + detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", result, ""); + + + DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); + if (detectionItem != null) + { + //更新稳定度检测状态 + if (!detectionItem.Stability1.Equals("-1") && !detectionItem.Stability10.Equals("-1") && !detectionItem.Stability20.Equals("-1") && !detectionItem.Stability100.Equals("-1")) + { + detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); + + } + detectionItem = detectionItemService.searchById(detectionItemId); + //更新整个仪器检测状态 + if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1")) + { + deviceService.updateStatus(devIdStability, "3", ""); + } + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + } + + + } + + } + else + { + if (resultStability20.Count == 101) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测稳定度20s得到结果,detectionItemId=" + detectionItemId); timerStability20.Dispose(); - return; - } - if (!isStarted) - { - isStarted = true; - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); - if (detectionItem0.Stability10.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); - detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); - if (detectionItem0.Stability100.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); - if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); - if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); - if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - - } - break; - } - - } - string result = ""; - - string fre = getFrequencyData(portStability, false); - if (fre.Equals("close")) - { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,稳定度20s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); - - timerStability20.Dispose(); - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem0.Stability20.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "0", ""); - - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - deviceService.updateStatus(devIdStability, "1", ""); - return; - } - if (!fre.Equals("") && resultStability20.Count < 101) - { - resultStability20.Add(fre); - if (!isUpdate && count20s < 101) - { - detectionService.add(devIdStability, fre, "1-20", detectionItemId); - count20s++; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,20s稳定度,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); - - } - } - - - if (!isUpdate) - { - if (resultStability20.Count == 101) - { - timerStability20.Dispose(); - - result = FreMath.Stable(resultStability20) + ""; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "20s稳定度检测结果:" + result + ", devId =" + devIdStability + ";detectionItemId=" + detectionItemId); - - detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", result, ""); - - - DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); - if (detectionItem != null) - { - //更新稳定度检测状态 - if (!detectionItem.Stability1.Equals("-1") && !detectionItem.Stability10.Equals("-1") && !detectionItem.Stability20.Equals("-1") && !detectionItem.Stability100.Equals("-1")) + List resultList = new List(); + foreach (DictionaryEntry de in resultStability20) { - detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - + resultList.Add(de.Value.ToString()); } - detectionItem = detectionItemService.searchById(detectionItemId); - //更新整个仪器检测状态 - if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1")) - { - deviceService.updateStatus(devIdStability, "3", ""); - } + resultStability20.Clear(); + string result1 = FreMath.Stable(resultList) + ""; + detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", result1, ""); - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - } - - resultStability20.Clear(); - } + updateView(resultList); + stability.label_result.Text = result1; + DetailDlg.detailDlg.resultStaStr20 = result1; - } - else - { - if (resultStability20.Count == 101) - { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测稳定度20s得到结果,detectionItemId=" + detectionItemId); - timerStability20.Dispose(); - - - string result1 = FreMath.Stable(resultStability20) + ""; - detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", result1, ""); - - updateView(resultStability20); - stability.label_result.Text = result1; - DetailDlg.detailDlg.resultStaStr20 = result1; - resultStability20.Clear(); - + } } - } + } } + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "exeStability20 error: " + ex.Message + ex.ToString()); + + } + } private void exeStability100(Object State) - { - lock (obj) + { + try { - if (!isStarted) + lock (obj) { - while (true) + if (!isStarted) { - DetectionItem item = detectionItemService.getById(detectionItemId); - if (item == null || (item != null && Convert.ToDateTime(item.EndTime) < DateTime.Now)) + while (true) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,稳定度100s, devId = " + devIdStability + "; detectionItemId = " + detectionItemId); + if (HomeCtrlForm.stoppedItemIdTable.ContainsValue(detectionItemId)) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,稳定度100s, devId = " + devIdStability + "; detectionItemId = " + detectionItemId); - timerStability100.Dispose(); - return; - } - - if (detectionItemId != -1) - { - isStarted = true; - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); - if (detectionItem0.Stability10.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); - if (detectionItem0.Stability20.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); - detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); - if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); - if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); - if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); + timerStability100.Dispose(); + return; + } - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - + if (detectionItemId != -1) + { + isStarted = true; + DetectionItem item = detectionItemService.getById(detectionItemId); + + DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); + if (detectionItem0.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); + if (detectionItem0.Stability10.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); + if (detectionItem0.Stability20.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); + detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); + if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); + if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); + if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + + } + break; } - break; + + } + string result = ""; + + string fre = getFrequencyData(portStability, false); + if (fre.Equals("close")) + { + timerStability100.Dispose(); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,稳定度100s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + + + DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); + if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); + if (detectionItem0.Stability100.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", "0"); + deviceService.updateStatus(devIdStability, "1", ""); + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + return; + } + if (!fre.Equals("") && resultStability100.Count < 101) + { + resultStability100.Add(DateTime.Now, fre); + if (!isUpdate) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,100s稳定度,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + } } - } - string result = ""; - string fre = getFrequencyData(portStability, false); - if (fre.Equals("close")) - { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,稳定度100s,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); - - timerStability100.Dispose(); - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.Stability.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - if (detectionItem0.Stability100.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", "0"); - - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - deviceService.updateStatus(devIdStability, "1", ""); - return; - } - if (!fre.Equals("") && resultStability100.Count < 101) - { - resultStability100.Add(fre); if (!isUpdate) { - detectionService.add(devIdStability, fre, "1-100", detectionItemId); - - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,100s稳定度,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); - } - } - - - if (!isUpdate) - { - if (resultStability100.Count == 101) - { - timerStability100.Dispose(); - - result = FreMath.Stable(resultStability100) + ""; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "100s稳定度检测结果:" + result + ", devId =" + devIdStability + ";detectionItemId=" + detectionItemId); - - detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "", result); - - - DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); - if (detectionItem != null) + if (resultStability100.Count == 101) { - //更新稳定度检测状态 - if (!detectionItem.Stability1.Equals("-1") && !detectionItem.Stability10.Equals("-1") && !detectionItem.Stability20.Equals("-1") && !detectionItem.Stability100.Equals("-1")) + timerStability100.Dispose(); + List resultList = new List(); + foreach (DictionaryEntry de in resultStability100) { - detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); - + resultList.Add(de.Value.ToString()); + detectionService.add(devIdStability, de.Value.ToString(), "1-100", detectionItemId, Convert.ToDateTime(de.Key)); + } - detectionItem = detectionItemService.searchById(detectionItemId); - //更新整个仪器检测状态 - if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1")) + resultStability100.Clear(); + result = FreMath.Stable(resultList) + ""; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "100s稳定度检测结果:" + result + ", devId =" + devIdStability + ";detectionItemId=" + detectionItemId); + + detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "", result); + + + DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); + if (detectionItem != null) { - deviceService.updateStatus(devIdStability, "3", ""); + //更新稳定度检测状态 + if (!detectionItem.Stability1.Equals("-1") && !detectionItem.Stability10.Equals("-1") && !detectionItem.Stability20.Equals("-1") && !detectionItem.Stability100.Equals("-1")) + { + detectionItemService.updateDetecStatus(detectionItemId, "0", "", "", "", "", "", "", "", ""); + + } + detectionItem = detectionItemService.searchById(detectionItemId); + //更新整个仪器检测状态 + if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1")) + { + deviceService.updateStatus(devIdStability, "3", ""); + } + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); } - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + } - resultStability100.Clear(); } - } - else - { - if (resultStability100.Count == 101) + else { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测稳定度100s得到结果,detectionItemId=" + detectionItemId); + if (resultStability100.Count == 101) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测稳定度100s得到结果,detectionItemId=" + detectionItemId); - timerStability100.Dispose(); + timerStability100.Dispose(); + + List resultList = new List(); + foreach (DictionaryEntry de in resultStability100) + { + resultList.Add(de.Value.ToString()); - string result1 = FreMath.Stable(resultStability100) + ""; - detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "", result1); + } + resultStability100.Clear(); + string result1 = FreMath.Stable(resultList) + ""; + detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "", "", "", "", "", result1); - updateView(resultStability100); - stability.label_result.Text = result1; - DetailDlg.detailDlg.resultStaStr100 = result1; - resultStability100.Clear(); + updateView(resultList); + stability.label_result.Text = result1; + DetailDlg.detailDlg.resultStaStr100 = result1; + resultStability100.Clear(); + } } } - } + } + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "exeStability100 error: " + ex.Message + ex.ToString()); + + } } #endregion @@ -594,23 +701,31 @@ #region 准确度 public void detecAccuracy(long deviceId, SerialPort port, string endTime, bool isStartNow, bool isUpdates) { - portAccuracy = port; - devIdAccuracy = deviceId; - if (isUpdates) + try { - isUpdate = true; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测准确度"); + portAccuracy = port; + devIdAccuracy = deviceId; + if (isUpdates) + { + isUpdate = true; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "重新检测准确度"); + + } + int delay = 0; + if (Convert.ToDateTime(endTime) > DateTime.Now) + { + isStarted = false; + TimeSpan secondSpan = new TimeSpan(Convert.ToDateTime(endTime).Ticks - DateTime.Now.Ticks); + delay = (int)secondSpan.TotalMilliseconds - 20 * 1000; + } + + timerAccuracy = new System.Threading.Timer(exeAccuracy, null, delay + 200, 5 * 60 * 1000); + } + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "detecAccuracy error: " + ex.Message + ex.ToString()); } - int delay = 0; - if (Convert.ToDateTime(endTime)>DateTime.Now) - { - isStarted = false; - TimeSpan secondSpan = new TimeSpan(Convert.ToDateTime(endTime).Ticks - DateTime.Now.Ticks); - delay = (int)secondSpan.TotalMilliseconds - 20*1000; - } - - timerAccuracy = new System.Threading.Timer(exeAccuracy, null, delay + 200 ,5*60*1000); } private void exeAccuracy(Object State) { @@ -622,8 +737,7 @@ { if (detectionItemId != -1) { - DetectionItem item = detectionItemService.getById(detectionItemId); - if (item == null || (item != null && Convert.ToDateTime(item.EndTime) < DateTime.Now)) + if (HomeCtrlForm.stoppedItemIdTable.ContainsValue(detectionItemId)) { LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,准确度, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); @@ -632,7 +746,8 @@ } if (!isStarted) { - + DetectionItem item = detectionItemService.getById(detectionItemId); + isStarted = true; DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); if (detectionItem0.Stability.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", ""); @@ -656,7 +771,7 @@ double sum = 0.0; List resultList = new List(); - for (int i = 0; i < 500; i++) + for (int i = 0; i < 200; i++) { string fre = getFrequencyData(portAccuracy, false); if (fre.Equals("close")) @@ -666,21 +781,21 @@ timerAccuracy.Dispose(); DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); if (detectionItem0.Accuracy.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "0", "", "", "", "", "", "", ""); - - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); deviceService.updateStatus(devIdStability, "1", ""); + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); return; } if (fre.Equals("")) continue; resultList.Add(fre); if (!isUpdate) { - detectionService.add(devIdAccuracy, fre, "2", detectionItemId); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,准确度, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); + detectionService.add(devIdAccuracy, fre, "2", detectionItemId, DateTime.Now); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,准确度, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); } if (resultList.Count == 3) - { + { sum = sum + Convert.ToDouble(fre); break; } @@ -737,116 +852,130 @@ #region 开机特性 public void detecBootFeature(long deviceId, string startTime, SerialPort port, bool isStartNow) { - resultBootFeature = new List(); - portBootFeature = port; - devIdBootFeature = deviceId; - int delay = 0; - if (!isStartNow && Convert.ToDateTime(startTime) > DateTime.Now) + try { - isStarted = false; - TimeSpan secondSpan = new TimeSpan(Convert.ToDateTime(startTime).Ticks - DateTime.Now.Ticks); - delay = (int)secondSpan.TotalMilliseconds; + resultBootFeature = new List(); + portBootFeature = port; + devIdBootFeature = deviceId; + int delay = 0; + if (Convert.ToDateTime(startTime) > DateTime.Now) + { + isStarted = false; + TimeSpan secondSpan = new TimeSpan(Convert.ToDateTime(startTime).Ticks - DateTime.Now.Ticks); + delay = (int)secondSpan.TotalMilliseconds; + } + timerBootFeature = new System.Threading.Timer(exeBootFeature, null, delay + 100, 60 * 60 * 1000); } - timerBootFeature = new System.Threading.Timer(exeBootFeature, null, delay + 100, 60 * 60 * 1000); + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "detecBootFeature error: " + ex.Message + ex.ToString()); + + } } private void exeBootFeature(Object State) - { - lock (obj) + { + try { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "isStarted:"+ isStarted); - DetectionItem item = detectionItemService.getById(detectionItemId); - if (item == null || (item != null && Convert.ToDateTime(item.EndTime) < DateTime.Now)) + lock (obj) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,开机特性, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); - - timerBootFeature.Dispose(); - return; - } - if (!isStarted) - { - while (true) + if (HomeCtrlForm.stoppedItemIdTable.ContainsValue(detectionItemId)) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "detectionItemId:" + detectionItemId); - - if (detectionItemId != -1) - { - isStarted = true; - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.Stability.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", ""); - if (detectionItem0.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); - if (detectionItem0.Stability10.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); - if (detectionItem0.Stability20.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); - if (detectionItem0.Stability100.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); - if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); - if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); - if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); - - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - break; - } - } - - } - - string result = ""; - double sum = 0.0; - int count = 0; - for (int i = 0; i < 50; i++) - { - string fre = getFrequencyData(portBootFeature, false); - if (fre.Equals("close")) - { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,开机特性,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,开机特性, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); timerBootFeature.Dispose(); - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.BootFeature.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "0", "", "", "", "", "", ""); - - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - deviceService.updateStatus(devIdStability, "1", ""); return; } - if (!fre.Equals("")) + if (!isStarted) { - count++; - sum = sum + Convert.ToDouble(fre); - - if (count == 3) break; - } - } - detectionService.add(devIdBootFeature, sum / 3 + "", "3", detectionItemId); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,开机特性, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); + + while (true) + { + if (detectionItemId != -1) + { + isStarted = true; + DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); + if (detectionItem0.Stability.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", ""); + if (detectionItem0.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); + if (detectionItem0.Stability10.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); + if (detectionItem0.Stability20.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); + if (detectionItem0.Stability100.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); + if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); + if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); + if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); - resultBootFeature.Add(sum / 3 + ""); + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + break; + } + } - if (resultBootFeature.Count == 8) - { - timerBootFeature.Dispose(); - string max = "0.0"; - string min = "0.0"; - foreach (string fre in resultBootFeature) - { - if (Convert.ToDouble(fre) > Convert.ToDouble(max)) max = fre; - if (Convert.ToDouble(fre) < Convert.ToDouble(min) || min.Equals("0.0")) min = fre; } - result = (Convert.ToDouble(max) - Convert.ToDouble(min)) + ""; - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "开机特性检测结果result=" + result + ",detectionItemId=" + detectionItemId); - detectionItemService.updateDetecStatus(detectionItemId, "", "", result, "", "", "", "", "", ""); - - DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); - if (detectionItem != null) + string result = ""; + double sum = 0.0; + int count = 0; + for (int i = 0; i < 50; i++) { - if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1")) + string fre = getFrequencyData(portBootFeature, false); + if (fre.Equals("close")) { - deviceService.updateStatus(devIdBootFeature, "3", ""); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,开机特性,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); + + timerBootFeature.Dispose(); + DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); + if (detectionItem0.BootFeature.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "0", "", "", "", "", "", ""); + deviceService.updateStatus(devIdStability, "1", ""); + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + return; + } + if (!fre.Equals("")) + { + count++; + sum = sum + Convert.ToDouble(fre); + + if (count == 3) break; } } - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - - resultBootFeature.Clear(); + detectionService.add(devIdBootFeature, sum / 3 + "", "3", detectionItemId,DateTime.Now); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,开机特性, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); + + resultBootFeature.Add(sum / 3 + ""); + + if (resultBootFeature.Count == 8) + { + timerBootFeature.Dispose(); + string max = "0.0"; + string min = "0.0"; + foreach (string fre in resultBootFeature) + { + if (Convert.ToDouble(fre) > Convert.ToDouble(max)) max = fre; + if (Convert.ToDouble(fre) < Convert.ToDouble(min) || min.Equals("0.0")) min = fre; + } + result = (Convert.ToDouble(max) - Convert.ToDouble(min)) + ""; + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "开机特性检测结果result=" + result + ",detectionItemId=" + detectionItemId); + + detectionItemService.updateDetecStatus(detectionItemId, "", "", result, "", "", "", "", "", ""); + + DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); + if (detectionItem != null) + { + if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1")) + { + deviceService.updateStatus(devIdBootFeature, "3", ""); + } + } + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + + resultBootFeature.Clear(); + } } - } + } + + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "exeBootFeature error: " + ex.Message + ex.ToString()); + + } } #endregion @@ -857,111 +986,126 @@ #region 日老化率 public void detecAgeRate(long deviceId, string startTime, SerialPort port, bool isStartNow) { - resultAgeRate = new List(); - portAgeRate = port; - devIdAgeRate = deviceId; - int delay = 0; - if (!isStartNow && Convert.ToDateTime(startTime) > DateTime.Now) + try { - isStarted = false; - TimeSpan secondSpan = new TimeSpan(Convert.ToDateTime(startTime).Ticks - DateTime.Now.Ticks); - delay = (int)secondSpan.TotalMilliseconds; + resultAgeRate = new List(); + portAgeRate = port; + devIdAgeRate = deviceId; + int delay = 0; + if (Convert.ToDateTime(startTime) > DateTime.Now) + { + isStarted = false; + TimeSpan secondSpan = new TimeSpan(Convert.ToDateTime(startTime).Ticks - DateTime.Now.Ticks); + delay = (int)secondSpan.TotalMilliseconds; + } + timerAgeRate = new System.Threading.Timer(exeAgeRate, null, delay + 100, 12 * 60 * 60 * 1000); } - timerAgeRate = new System.Threading.Timer(exeAgeRate, null, delay + 100, 12* 60* 60 * 1000); + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "detecAgeRate error: " + ex.Message + ex.ToString()); + + } } private void exeAgeRate(Object State) - { - lock (obj) + { + try { - while (true) + lock (obj) { - if (detectionItemId != -1) + while (true) { - DetectionItem item = detectionItemService.getById(detectionItemId); - if (item == null || (item != null && Convert.ToDateTime(item.EndTime) < DateTime.Now)) + if (detectionItemId != -1) { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,日老化率, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); + if (HomeCtrlForm.stoppedItemIdTable.ContainsValue(detectionItemId)) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "已停止检测,日老化率, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); + + timerAgeRate.Dispose(); + return; + } + if (!isStarted) + { + isStarted = true; + DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); + if (detectionItem0.Stability.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", ""); + if (detectionItem0.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); + if (detectionItem0.Stability10.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); + if (detectionItem0.Stability20.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); + if (detectionItem0.Stability100.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); + if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); + if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); + if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); + + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + + } + break; + } + + } + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "开始检测日老化率"); + + string result = ""; + double sum = 0.0; + int count = 0; + for (int i = 0; i < 50; i++) + { + string fre = getFrequencyData(portAgeRate, false); + if (fre.Equals("close")) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,日老化率,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); timerAgeRate.Dispose(); - return; - } - if (!isStarted) - { - - isStarted = true; DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.Stability.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", ""); - if (detectionItem0.Stability1.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "-1", "", "", ""); - if (detectionItem0.Stability10.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "-1", "", ""); - if (detectionItem0.Stability20.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "-1", ""); - if (detectionItem0.Stability100.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "-1", "", "", "", "", "", "", "", "-1"); - if (detectionItem0.Accuracy.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "-1", "", "", "", "", "", "", ""); - if (detectionItem0.BootFeature.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "-1", "", "", "", "", "", ""); - if (detectionItem0.AgeRate.Equals("-2")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "-1", "", "", "", "", ""); + if (detectionItem0.AgeRate.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "0", "", "", "", "", ""); + deviceService.updateStatus(devIdStability, "1", ""); HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - + return; } - break; - } - - } - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "开始检测日老化率"); - - string result = ""; - double sum = 0.0; - int count = 0; - for (int i = 0; i < 50; i++) - { - string fre = getFrequencyData(portAgeRate, false); - if (fre.Equals("close")) - { - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "端口异常关闭,日老化率,devId=" + devIdStability + ";detectionItemId=" + detectionItemId); - - timerAgeRate.Dispose(); - DetectionItem detectionItem0 = detectionItemService.searchById(detectionItemId); - if (detectionItem0.AgeRate.Equals("-1")) detectionItemService.updateDetecStatus(detectionItemId, "", "", "", "0", "", "", "", "", ""); - - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - deviceService.updateStatus(devIdStability, "1", ""); - return; - } - if (!fre.Equals("")) - { - count++; - sum = sum + Convert.ToDouble(fre); - - if (count == 3) break; - } - } - detectionService.add(devIdAgeRate, sum / 3+"", "4", detectionItemId); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,日老化率, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); - - resultAgeRate.Add(sum / 3 + ""); - - if (resultAgeRate.Count == 15) - { - timerAgeRate.Dispose(); - double r = 0.0; - double k = FreMath.DriftRate(resultAgeRate, out r); - result = k + "," + r.ToString().Substring(0,5); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "日老化率检测结果result=" + result + ",detectionItemId=" + detectionItemId); - - detectionItemService.updateDetecStatus(detectionItemId, "", "", "", result, "", "", "", "", ""); - - DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); - if (detectionItem != null) - { - if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1")) + if (!fre.Equals("")) { - deviceService.updateStatus(devIdAgeRate, "3", ""); + count++; + sum = sum + Convert.ToDouble(fre); + + if (count == 3) break; } } - HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); - - resultAgeRate.Clear(); + detectionService.add(devIdAgeRate, sum / 3 + "", "4", detectionItemId,DateTime.Now); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取到频率值,日老化率, devId=" + devIdAccuracy + ";detectionItemId=" + detectionItemId); + + resultAgeRate.Add(sum / 3 + ""); + + if (resultAgeRate.Count == 15) + { + timerAgeRate.Dispose(); + double r = 0.0; + double k = FreMath.DriftRate(resultAgeRate, out r); + result = k + "," + r.ToString().Substring(0, 5); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "日老化率检测结果result=" + result + ",detectionItemId=" + detectionItemId); + + detectionItemService.updateDetecStatus(detectionItemId, "", "", "", result, "", "", "", "", ""); + + DetectionItem detectionItem = detectionItemService.searchById(detectionItemId); + if (detectionItem != null) + { + if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1")) + { + deviceService.updateStatus(devIdAgeRate, "3", ""); + } + } + HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); + + resultAgeRate.Clear(); + } } - } + } + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "exeAgeRate error: " + ex.Message + ex.ToString()); + + } + } #endregion @@ -990,7 +1134,7 @@ if (ConfigHelper.GetAppConfig("deviceType").ToString().Equals("1")) { int count = 0; - while (count < 600) + while (count < 200) { int readLen = port.BytesToRead; @@ -1005,9 +1149,8 @@ string[] dataArray = data.Split('$')[1].Split(' '); if (dataArray.Length < 2) continue; string s1 = dataArray[0].Replace("$", ""); - string s2 = "0." + dataArray[1].Replace(".", "").Replace("-", "").TrimEnd('0'); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, port.PortName + "s1=" + s1 + ";s2="+s2); - + string s2 = (Convert.ToDouble(dataArray[1]) / 1000000).ToString();// "0." + dataArray[1].Replace(".", "").Replace("-", "").TrimEnd('0'); + if (dataArray[1].Contains("-")) { received = (Convert.ToDouble(s1) - Convert.ToDouble(s2)) + ""; @@ -1028,7 +1171,7 @@ { int count = 0; - while (count < 600) + while (count < 200) { int readLen = port.BytesToRead; @@ -1093,19 +1236,21 @@ } private void updateView(List result) - { - isUpdate = false; - //new Thread(() => - //{ + { + try + { + isUpdate = false; + //new Thread(() => + //{ int index = 0; - + foreach (DataGridViewRow row in DetailDlg.dataGridView.Rows) { if (index < result.Count) { row.Cells[2].Value = result[index].ToString(); int re = detectionService.updateFrequency(Convert.ToInt64(row.Cells[3].Value), result[index].ToString()); - LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "updateFrequency re=" + re + ";id="+ row.Cells[3].Value + "; fre=" + result[index].ToString()); + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "updateFrequency re=" + re + ";id=" + row.Cells[3].Value + "; fre=" + result[index].ToString()); } index++; @@ -1113,8 +1258,14 @@ DetailDlg.detailDlg.updateChannelNoRedetec(); DetailDlg.label_redetecting.Visible = false; + } + catch (Exception ex) + { + LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "updateView error: " + ex.Message + ex.ToString()); + + } //}).Start(); - + } diff --git a/RbFreqStandMeasure/tools/UnitConvertHelper.cs b/RbFreqStandMeasure/tools/UnitConvertHelper.cs index 77c3d4e..fe7e5c8 100644 --- a/RbFreqStandMeasure/tools/UnitConvertHelper.cs +++ b/RbFreqStandMeasure/tools/UnitConvertHelper.cs @@ -80,7 +80,7 @@ switch (unit) { case "uHz": - return _freValue * 1000 * 1000 + "μHz"; + return _freValue * 1000 * 1000 + "uHz"; case "mHz": return _freValue * 1000 + "mHz"; case "Hz": @@ -106,7 +106,7 @@ case "ns": return _periodValue * 1000 * 1000 * 1000 + "ns"; case "us": - return _periodValue * 1000 * 1000 + "μs"; + return _periodValue * 1000 * 1000 + "us"; case "ms": return _periodValue * 1000 + "ms"; case "s":